[Core] [Executor] Split executor spi

This commit is contained in:
qianmoQ 2024-01-16 00:07:43 +08:00
parent 21233d9875
commit 16601ae489
16 changed files with 202 additions and 0 deletions

View 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>

View File

@ -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
}

View File

@ -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 ================")
}
}

View File

@ -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")
}
}

View File

@ -0,0 +1,6 @@
package io.edurt.datacap.executor.common
enum class Protocol {
NONE,
JDBC
}

View File

@ -0,0 +1,6 @@
package io.edurt.datacap.executor.common
enum class RunMode {
CLIENT,
CLUSTER
}

View File

@ -0,0 +1,6 @@
package io.edurt.datacap.executor.common
enum class RunWay {
LOCAL,
YARN
}

View File

@ -0,0 +1,11 @@
package io.edurt.datacap.executor.common
enum class State {
CREATED,
TIMEOUT,
QUEUE,
RUNNING,
FAILURE,
SUCCESS,
STOPPED
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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?>?>() {})))
}
}

View File

@ -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")
}
}

View File

@ -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)
}
}

View File

@ -0,0 +1 @@
io.edurt.datacap.executor.TestExecutorModule

View File

@ -82,6 +82,7 @@
<module>parser/datacap-parser-mysql</module> <module>parser/datacap-parser-mysql</module>
<module>scheduler/datacap-scheduler-spi</module> <module>scheduler/datacap-scheduler-spi</module>
<module>scheduler/datacap-scheduler-local</module> <module>scheduler/datacap-scheduler-local</module>
<module>executor/datacap-executor-spi</module>
</modules> </modules>
<name>datacap</name> <name>datacap</name>