pl.touk.nussknacker.engine.management.FlinkStreamingDeploymentManagerProvider.scala Maven / Gradle / Ivy
package pl.touk.nussknacker.engine.management
import cats.data.ValidatedNel
import com.typesafe.config.Config
import pl.touk.nussknacker.engine._
import pl.touk.nussknacker.engine.api.StreamMetaData
import pl.touk.nussknacker.engine.api.component.ScenarioPropertyConfig
import pl.touk.nussknacker.engine.api.definition._
import pl.touk.nussknacker.engine.api.deployment.DeploymentManager
import pl.touk.nussknacker.engine.api.deployment.cache.CachingProcessStateDeploymentManager
import pl.touk.nussknacker.engine.deployment.EngineSetupName
import pl.touk.nussknacker.engine.management.FlinkConfig.RestUrlPath
import pl.touk.nussknacker.engine.management.rest.FlinkClient
import scala.concurrent.duration.FiniteDuration
import scala.util.Try
class FlinkStreamingDeploymentManagerProvider extends DeploymentManagerProvider {
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import pl.touk.nussknacker.engine.util.config.ConfigEnrichments._
override def createDeploymentManager(
modelData: BaseModelData,
dependencies: DeploymentManagerDependencies,
deploymentConfig: Config,
scenarioStateCacheTTL: Option[FiniteDuration]
): ValidatedNel[String, DeploymentManager] = {
import dependencies._
val flinkConfig = deploymentConfig.rootAs[FlinkConfig]
FlinkClient.create(flinkConfig, scenarioStateCacheTTL).map { client =>
CachingProcessStateDeploymentManager.wrapWithCachingIfNeeded(
new FlinkStreamingRestManager(client, flinkConfig, modelData, dependencies),
scenarioStateCacheTTL
)
}
}
override def name: String = "flinkStreaming"
override def metaDataInitializer(config: Config): MetaDataInitializer =
FlinkStreamingPropertiesConfig.metaDataInitializer
override def scenarioPropertiesConfig(config: Config): Map[String, ScenarioPropertyConfig] =
FlinkStreamingPropertiesConfig.properties
override def defaultEngineSetupName: EngineSetupName = EngineSetupName("Flink")
override def engineSetupIdentity(config: Config): Any = {
// We don't parse the whole config because some other properties can be unspecified and it would
// cause generation of wrong identity. We also use a Try to handle missing or invalid rest url path
Try(config.getString(RestUrlPath)).toOption
}
}
//Properties from this class should be public because implementing projects should be able to reuse them
object FlinkStreamingPropertiesConfig {
val parallelismConfig: (String, ScenarioPropertyConfig) = StreamMetaData.parallelismName ->
ScenarioPropertyConfig(
defaultValue = None,
editor = Some(StringParameterEditor),
validators = Some(List(LiteralIntegerValidator, MinimalNumberValidator(1))),
label = Some("Parallelism"),
hintText = None
)
val spillStatePossibleValues = List(
FixedExpressionValue("", "Server default"),
FixedExpressionValue("false", "False"),
FixedExpressionValue("true", "True")
)
val asyncPossibleValues = List(
FixedExpressionValue("", "Server default"),
FixedExpressionValue("false", "Synchronous"),
FixedExpressionValue("true", "Asynchronous")
)
val spillStateConfig: (String, ScenarioPropertyConfig) = StreamMetaData.spillStateToDiskName ->
ScenarioPropertyConfig(
defaultValue = None,
editor = Some(FixedValuesParameterEditor(spillStatePossibleValues)),
validators = Some(List(FixedValuesValidator(spillStatePossibleValues))),
label = Some("Spill state to disk"),
hintText = None
)
val asyncInterpretationConfig: (String, ScenarioPropertyConfig) = StreamMetaData.useAsyncInterpretationName ->
ScenarioPropertyConfig(
defaultValue = None,
editor = Some(FixedValuesParameterEditor(asyncPossibleValues)),
validators = Some(List(FixedValuesValidator(asyncPossibleValues))),
label = Some("IO mode"),
hintText = None
)
val checkpointIntervalConfig: (String, ScenarioPropertyConfig) = StreamMetaData.checkpointIntervalName ->
ScenarioPropertyConfig(
defaultValue = None,
editor = Some(StringParameterEditor),
validators = Some(List(LiteralIntegerValidator, MinimalNumberValidator(1))),
label = Some("Checkpoint interval in seconds"),
hintText = None
)
val properties: Map[String, ScenarioPropertyConfig] =
Map(parallelismConfig, spillStateConfig, asyncInterpretationConfig, checkpointIntervalConfig)
val metaDataInitializer: MetaDataInitializer = MetaDataInitializer(
metadataType = StreamMetaData.typeName,
overridingProperties = Map(StreamMetaData.parallelismName -> "1", StreamMetaData.spillStateToDiskName -> "true")
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy