mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-12-02 03:57:35 +08:00
[Core] [Executor] Split executor spi
This commit is contained in:
parent
21233d9875
commit
16601ae489
40
executor/datacap-executor-spi/pom.xml
Normal file
40
executor/datacap-executor-spi/pom.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>io.edurt.datacap</groupId>
|
||||
<artifactId>datacap</artifactId>
|
||||
<version>2024.01.1-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>datacap-executor-spi</artifactId>
|
||||
<description>DataCap - Executor spi</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.dokka</groupId>
|
||||
<artifactId>dokka-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,16 @@
|
||||
package io.edurt.datacap.executor
|
||||
|
||||
import io.edurt.datacap.executor.configure.ExecutorRequest
|
||||
import io.edurt.datacap.executor.configure.ExecutorResponse
|
||||
|
||||
interface Executor {
|
||||
fun name(): String {
|
||||
return this.javaClass
|
||||
.simpleName
|
||||
.removeSuffix("Executor")
|
||||
}
|
||||
|
||||
fun start(request: ExecutorRequest): ExecutorResponse
|
||||
|
||||
fun stop(request: ExecutorRequest): ExecutorResponse
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.edurt.datacap.executor
|
||||
|
||||
import com.google.inject.AbstractModule
|
||||
import org.slf4j.LoggerFactory.getLogger
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
|
||||
class ExecutorManager : AbstractModule {
|
||||
private val log = getLogger(this.javaClass)
|
||||
private var externalModules: Iterable<ExecutorModule>? = null
|
||||
|
||||
constructor() {
|
||||
this.externalModules = ServiceLoader.load(ExecutorModule::class.java)
|
||||
}
|
||||
|
||||
override fun configure() {
|
||||
log.info("================ Executor started ================")
|
||||
externalModules !!.forEach { module ->
|
||||
log.info("Install Executor [ {} ] Join time [ {} ]", module.name(), LocalDateTime.now())
|
||||
this.install(module)
|
||||
}
|
||||
log.info("================ Executor end ================")
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package io.edurt.datacap.executor
|
||||
|
||||
import com.google.inject.AbstractModule
|
||||
|
||||
abstract class ExecutorModule : AbstractModule() {
|
||||
open fun name(): String {
|
||||
return this.javaClass
|
||||
.simpleName
|
||||
.removeSuffix("Module")
|
||||
.removeSuffix("Executor")
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package io.edurt.datacap.executor.common
|
||||
|
||||
enum class Protocol {
|
||||
NONE,
|
||||
JDBC
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package io.edurt.datacap.executor.common
|
||||
|
||||
enum class RunMode {
|
||||
CLIENT,
|
||||
CLUSTER
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package io.edurt.datacap.executor.common
|
||||
|
||||
enum class RunWay {
|
||||
LOCAL,
|
||||
YARN
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package io.edurt.datacap.executor.common
|
||||
|
||||
enum class State {
|
||||
CREATED,
|
||||
TIMEOUT,
|
||||
QUEUE,
|
||||
RUNNING,
|
||||
FAILURE,
|
||||
SUCCESS,
|
||||
STOPPED
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package io.edurt.datacap.executor.configure
|
||||
|
||||
import io.edurt.datacap.executor.common.Protocol
|
||||
import java.util.*
|
||||
|
||||
data class ExecutorConfigure(var type: String,
|
||||
var configure: Properties,
|
||||
var supportOptions: Set<String> = mutableSetOf(),
|
||||
var protocol: Protocol = Protocol.NONE)
|
@ -0,0 +1,14 @@
|
||||
package io.edurt.datacap.executor.configure
|
||||
|
||||
import io.edurt.datacap.executor.common.RunMode
|
||||
import io.edurt.datacap.executor.common.RunWay
|
||||
|
||||
data class ExecutorRequest(var taskName: String,
|
||||
var userName: String,
|
||||
var input: ExecutorConfigure,
|
||||
var output: ExecutorConfigure,
|
||||
var executorHome: String? = null,
|
||||
var workHome: String? = null,
|
||||
var timeout: Long = 600,
|
||||
var runWay: RunWay = RunWay.LOCAL,
|
||||
var runMode: RunMode = RunMode.CLIENT)
|
@ -0,0 +1,8 @@
|
||||
package io.edurt.datacap.executor.configure
|
||||
|
||||
import io.edurt.datacap.executor.common.State
|
||||
|
||||
data class ExecutorResponse(var state: State,
|
||||
var timeout: Boolean = false,
|
||||
var successful: Boolean = false,
|
||||
var message: String? = null)
|
@ -0,0 +1,23 @@
|
||||
package io.edurt.datacap.executor
|
||||
|
||||
import com.google.inject.Guice
|
||||
import com.google.inject.Injector
|
||||
import com.google.inject.Key
|
||||
import com.google.inject.TypeLiteral
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class ExecutorManagerTest {
|
||||
private var injector: Injector? = null
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
injector = Guice.createInjector(ExecutorManager())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
assertNotNull(injector?.getInstance(Key.get(object : TypeLiteral<Set<Executor?>?>() {})))
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package io.edurt.datacap.executor
|
||||
|
||||
import io.edurt.datacap.executor.configure.ExecutorRequest
|
||||
import io.edurt.datacap.executor.configure.ExecutorResponse
|
||||
|
||||
class TestExecutor : Executor {
|
||||
override fun start(request: ExecutorRequest): ExecutorResponse {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun stop(request: ExecutorRequest): ExecutorResponse {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package io.edurt.datacap.executor
|
||||
|
||||
import com.google.inject.multibindings.Multibinder
|
||||
|
||||
class TestExecutorModule : ExecutorModule() {
|
||||
override fun configure() {
|
||||
Multibinder.newSetBinder(this.binder(), Executor::class.java)
|
||||
.addBinding()
|
||||
.to(TestExecutor::class.java)
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
io.edurt.datacap.executor.TestExecutorModule
|
Loading…
Reference in New Issue
Block a user