-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from yangzhiyue/master
close #162, I contributed the bml-engine-hook
- Loading branch information
Showing
13 changed files
with
271 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>linkis</artifactId> | ||
<groupId>com.webank.wedatasphere.linkis</groupId> | ||
<version>0.9.1</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>linkis-bml-hook</artifactId> | ||
<version>${linkis.version}</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.webank.wedatasphere.linkis</groupId> | ||
<artifactId>linkis-bmlclient</artifactId> | ||
<version>${linkis.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.webank.wedatasphere.linkis</groupId> | ||
<artifactId>linkis-bmlcommon</artifactId> | ||
<version>${linkis.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.webank.wedatasphere.linkis</groupId> | ||
<artifactId>linkis-ujes-engine</artifactId> | ||
<version>${linkis.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>net.alchim31.maven</groupId> | ||
<artifactId>scala-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
<resources> | ||
<resource> | ||
<directory>${basedir}/src/main/resources</directory> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
|
||
</project> |
11 changes: 11 additions & 0 deletions
11
bml/bml-engine-hook/src/main/scala/com/webank/wedatasphere/linkis/bml/conf/BmlHookConf.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.webank.wedatasphere.linkis.bml.conf | ||
|
||
import com.webank.wedatasphere.linkis.common.conf.CommonVars | ||
|
||
/** | ||
* created by cooperyang on 2019/9/23 | ||
* Description: | ||
*/ | ||
object BmlHookConf { | ||
val WORK_DIR_STR = CommonVars("wds.linkis.bml.work.dir", "user.dir") | ||
} |
9 changes: 9 additions & 0 deletions
9
...rc/main/scala/com/webank/wedatasphere/linkis/bml/exception/BmlHookDownloadException.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.webank.wedatasphere.linkis.bml.exception | ||
|
||
import com.webank.wedatasphere.linkis.common.exception.ErrorException | ||
|
||
/** | ||
* created by cooperyang on 2019/9/25 | ||
* Description: | ||
*/ | ||
case class BmlHookDownloadException(errMsg:String) extends ErrorException(50046, errMsg) |
78 changes: 78 additions & 0 deletions
78
...hook/src/main/scala/com/webank/wedatasphere/linkis/bml/hook/BmlEnginePreExecuteHook.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.webank.wedatasphere.linkis.bml.hook | ||
|
||
import java.io.File | ||
import java.util | ||
|
||
import com.webank.wedatasphere.linkis.bml.client.{BmlClient, BmlClientFactory} | ||
import com.webank.wedatasphere.linkis.bml.exception.BmlHookDownloadException | ||
import com.webank.wedatasphere.linkis.bml.utils.BmlHookUtils | ||
import com.webank.wedatasphere.linkis.common.exception.ErrorException | ||
import com.webank.wedatasphere.linkis.common.utils.{Logging, Utils} | ||
import com.webank.wedatasphere.linkis.engine.ResourceExecuteRequest | ||
import com.webank.wedatasphere.linkis.engine.execute.EngineExecutorContext | ||
import com.webank.wedatasphere.linkis.engine.extension.EnginePreExecuteHook | ||
import com.webank.wedatasphere.linkis.scheduler.executer.ExecuteRequest | ||
import org.apache.commons.lang.StringUtils | ||
|
||
import scala.collection.JavaConversions._ | ||
/** | ||
* created by cooperyang on 2019/9/23 | ||
* Description: | ||
*/ | ||
class BmlEnginePreExecuteHook extends EnginePreExecuteHook with Logging{ | ||
override val hookName: String = "BmlEnginePreExecuteHook" | ||
|
||
val RESOURCES_STR = "resources" | ||
|
||
val RESOURCE_ID_STR = "resourceId" | ||
|
||
val VERSION_STR = "version" | ||
|
||
val FILE_NAME_STR = "fileName" | ||
|
||
val processUser:String = System.getProperty("user.name") | ||
|
||
val defaultUser:String = "hadoop" | ||
|
||
val bmlClient:BmlClient = if (StringUtils.isNotEmpty(processUser)) | ||
BmlClientFactory.createBmlClient(processUser) else BmlClientFactory.createBmlClient(defaultUser) | ||
|
||
val seperator:String = File.separator | ||
|
||
val pathType:String = "file://" | ||
|
||
override def callPreExecuteHook(engineExecutorContext: EngineExecutorContext, executeRequest: ExecuteRequest): Unit = { | ||
//1.删除工作目录以前的资源文件 | ||
//2.下载资源到当前进程的工作目录 | ||
|
||
val workDir = BmlHookUtils.getCurrentWorkDir | ||
val jobId = engineExecutorContext.getJobId | ||
executeRequest match { | ||
case resourceExecuteRequest:ResourceExecuteRequest => val resources = resourceExecuteRequest.resources | ||
resources foreach { | ||
case resource:util.Map[String, Object] => val fileName = resource.get(FILE_NAME_STR).toString | ||
val resourceId = resource.get(RESOURCE_ID_STR).toString | ||
val version = resource.get(VERSION_STR).toString | ||
val fullPath = if (workDir.endsWith(seperator)) pathType + workDir + fileName else | ||
pathType + workDir + seperator + fileName | ||
val response = Utils.tryCatch{ | ||
bmlClient.downloadResource(processUser, resourceId, version, fullPath, true) | ||
}{ | ||
case error:ErrorException => logger.error("download resource for {} failed", error) | ||
throw error | ||
case t:Throwable => logger.error(s"download resource for $jobId failed", t) | ||
val e1 = BmlHookDownloadException(t.getMessage) | ||
e1.initCause(t) | ||
throw t | ||
} | ||
if (response.isSuccess){ | ||
logger.info(s"for job $jobId resourceId $resourceId version $version download to path $fullPath ok") | ||
}else{ | ||
logger.warn(s"for job $jobId resourceId $resourceId version $version download to path $fullPath Failed") | ||
} | ||
case _ => logger.warn("job resource cannot download") | ||
} | ||
case _ => | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ngine-hook/src/main/scala/com/webank/wedatasphere/linkis/bml/hook/BmlResourceParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.webank.wedatasphere.linkis.bml.hook | ||
|
||
/** | ||
* created by cooperyang on 2019/9/23 | ||
* Description: | ||
*/ | ||
|
||
case class ResourceVersion(resourceId:String, version:String) | ||
|
||
|
||
trait BmlResourceParser { | ||
/** | ||
* 通过传入的code | ||
* @param code | ||
* @return | ||
*/ | ||
def getResource(code:String):Array[ResourceVersion] | ||
} | ||
|
||
|
||
object DefaultBmlResourceParser extends BmlResourceParser{ | ||
/** | ||
* 通过传入的code | ||
* | ||
* @param code | ||
* @return | ||
*/ | ||
override def getResource(code: String): Array[ResourceVersion] = Array.empty | ||
} |
20 changes: 20 additions & 0 deletions
20
...ml-engine-hook/src/main/scala/com/webank/wedatasphere/linkis/bml/utils/BmlHookUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.webank.wedatasphere.linkis.bml.utils | ||
|
||
import com.webank.wedatasphere.linkis.common.utils.Utils | ||
|
||
/** | ||
* created by cooperyang on 2019/9/24 | ||
* Description: | ||
*/ | ||
object BmlHookUtils { | ||
val WORK_DIR_STR = "user.dir" | ||
def getCurrentWorkDir:String = System.getProperty(WORK_DIR_STR) | ||
|
||
|
||
def deleteAllFiles(workDir:String):Unit = { | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
.../engine/src/main/scala/com/webank/wedatasphere/linkis/engine/ResourceExecuteRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.webank.wedatasphere.linkis.engine | ||
|
||
/** | ||
* created by cooperyang on 2019/11/29 | ||
* Description: | ||
*/ | ||
trait ResourceExecuteRequest { | ||
val resources:java.util.List[Object] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...src/main/scala/com/webank/wedatasphere/linkis/engine/extension/EnginePreExecuteHook.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.webank.wedatasphere.linkis.engine.extension | ||
|
||
import com.webank.wedatasphere.linkis.engine.execute.EngineExecutorContext | ||
import com.webank.wedatasphere.linkis.scheduler.executer.ExecuteRequest | ||
|
||
/** | ||
* created by cooperyang on 2019/11/29 | ||
* Description: | ||
*/ | ||
trait EnginePreExecuteHook { | ||
val hookName:String | ||
def callPreExecuteHook(engineExecutorContext:EngineExecutorContext, executeRequest: ExecuteRequest) | ||
} |