Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NU-1777] Nu Runtime app related refactoring #7408

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cats.effect.{IO, Resource}
import com.typesafe.config.{Config, ConfigFactory, ConfigValue, ConfigValueFactory}
import org.apache.commons.io.FileUtils
import pl.touk.nussknacker.engine.{DeploymentManagerProvider, ModelData}
import pl.touk.nussknacker.ui.config.DesignerConfigLoader
import pl.touk.nussknacker.ui.config.{DesignerConfig, SimpleConfigLoadingDesignerConfigLoader}
import pl.touk.nussknacker.ui.factory.NussknackerAppFactory
import pl.touk.nussknacker.ui.process.processingtype.loader.LocalProcessingTypeDataLoader

Expand Down Expand Up @@ -49,12 +49,12 @@ object LocalNussknackerWithSingleModel {
modelData = Map(typeName -> (category, modelData)),
deploymentManagerProvider = deploymentManagerProvider
)
val designerConfigLoader = DesignerConfigLoader.fromConfig(
val designerConfig = DesignerConfig.from(
// This map is ignored but must exist
appConfig.withValue("scenarioTypes", ConfigValueFactory.fromMap(Map.empty[String, ConfigValue].asJava))
)
val appFactory = new NussknackerAppFactory(
designerConfigLoader,
new SimpleConfigLoadingDesignerConfigLoader(designerConfig.rawConfig.resolved),
_ => local
)
appFactory.createApp()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package pl.touk.nussknacker.ui

import cats.effect.{ExitCode, IO, IOApp}
import pl.touk.nussknacker.ui.config.{AlwaysLoadingFileBasedDesignerConfigLoader, DesignerConfigLoader}
import pl.touk.nussknacker.ui.config.AlwaysLoadingFileBasedDesignerConfigLoader
import pl.touk.nussknacker.ui.factory.NussknackerAppFactory

object NussknackerApp extends IOApp {

override def run(args: List[String]): IO[ExitCode] = {
for {
appFactory <- IO(NussknackerAppFactory(AlwaysLoadingFileBasedDesignerConfigLoader(getClass.getClassLoader)))
_ <- appFactory.createApp().use { _ => IO.never }
} yield ExitCode.Success
program.useForever.as(ExitCode.Success)
}

private def program = for {
appFactory <- NussknackerAppFactory.create(AlwaysLoadingFileBasedDesignerConfigLoader(getClass.getClassLoader))
_ <- appFactory.createApp()
} yield ()

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class AdditionalInfoProviders(typeToConfig: ProcessingTypeDataProvider[ModelData
private val nodeProviders: ProcessingTypeDataProvider[Option[NodeData => Future[Option[AdditionalInfo]]], _] =
typeToConfig.mapValues(pt =>
ScalaServiceLoader
.load[AdditionalInfoProvider](pt.modelClassLoader.classLoader)
.load[AdditionalInfoProvider](pt.modelClassLoader)
.headOption
.map(_.nodeAdditionalInfo(pt.modelConfig))
)

private val propertiesProviders: ProcessingTypeDataProvider[Option[MetaData => Future[Option[AdditionalInfo]]], _] =
typeToConfig.mapValues(pt =>
ScalaServiceLoader
.load[AdditionalInfoProvider](pt.modelClassLoader.classLoader)
.load[AdditionalInfoProvider](pt.modelClassLoader)
.headOption
.map(_.propertiesAdditionalInfo(pt.modelConfig))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.circe.parser
import pl.touk.nussknacker.engine.api.deployment.ProcessState
import pl.touk.nussknacker.engine.api.deployment.simple.SimpleStateStatus.ProblemStateStatus
import pl.touk.nussknacker.engine.api.process.{ProcessName, ProcessingType}
import pl.touk.nussknacker.engine.util.ExecutionContextWithIORuntime
import pl.touk.nussknacker.engine.util.Implicits.RichTupleList
import pl.touk.nussknacker.engine.version.BuildInfo
import pl.touk.nussknacker.ui.api.description.AppApiEndpoints
Expand All @@ -17,7 +18,6 @@ import pl.touk.nussknacker.ui.process.processingtype.provider.{
}
import pl.touk.nussknacker.ui.process.{ProcessService, ScenarioQuery}
import pl.touk.nussknacker.ui.security.api.{AuthManager, LoggedUser, NussknackerInternalUser}
import pl.touk.nussknacker.ui.util.ExecutionContextWithIORuntime

import scala.concurrent.Future
import scala.util.control.NonFatal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class NodesApiHttpService(
modelData: ModelData
): EitherT[Future, NodesError, NodeValidationRequest] = {
EitherT.fromEither(
fromNodeRequestDto(nodeValidationRequestDto)(prepareTypingResultDecoder(modelData.modelClassLoader.classLoader))
fromNodeRequestDto(nodeValidationRequestDto)(prepareTypingResultDecoder(modelData.modelClassLoader))
)
}

Expand Down Expand Up @@ -226,7 +226,7 @@ class NodesApiHttpService(
localVariables <- EitherT.fromEither[Future](
decodeVariableTypes(
request.variableTypes,
prepareTypingResultDecoder(modelData.modelClassLoader.classLoader)
prepareTypingResultDecoder(modelData.modelClassLoader)
)
)
suggestions <- EitherT.right(
Expand Down Expand Up @@ -264,7 +264,7 @@ class NodesApiHttpService(
request: ParametersValidationRequestDto,
modelData: ModelData
): Either[NodesError, ParametersValidationRequest] = {
val typingResultDecoder = prepareTypingResultDecoder(modelData.modelClassLoader.classLoader)
val typingResultDecoder = prepareTypingResultDecoder(modelData.modelClassLoader)
for {
parameters <- request.parameters.map { parameter =>
typingResultDecoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pl.touk.nussknacker.ui.config
import com.typesafe.config.{Config, ConfigFactory}
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
import pl.touk.nussknacker.engine.{ConfigWithUnresolvedVersion, ProcessingTypeConfig}
import pl.touk.nussknacker.ui.config.DesignerConfig.ConfigurationMalformedException
import pl.touk.nussknacker.ui.configloader.ProcessingTypeConfigs

// TODO: We should extract a class for all configuration options that should be available to designer instead of returning raw hocon config.
Expand All @@ -18,7 +19,7 @@ final case class DesignerConfig private (rawConfig: ConfigWithUnresolvedVersion)
rawConfig
.getConfigOpt("scenarioTypes")
.getOrElse {
throw new RuntimeException("No scenario types configuration provided")
throw ConfigurationMalformedException("No scenario types configuration provided")
}

def configLoaderConfig: Config = rawConfig.resolved.getAs[Config]("configLoader").getOrElse(ConfigFactory.empty())
Expand All @@ -31,4 +32,5 @@ object DesignerConfig {
DesignerConfig(ConfigWithUnresolvedVersion(config))
}

final case class ConfigurationMalformedException(msg: String) extends RuntimeException(msg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,3 @@ class SimpleConfigLoadingDesignerConfigLoader(loadConfig: => Config) extends Des
override def loadDesignerConfig(): IO[DesignerConfig] = IO.delay(DesignerConfig.from(loadConfig))

}

object DesignerConfigLoader {

def fromConfig(loadConfig: => Config): SimpleConfigLoadingDesignerConfigLoader =
new SimpleConfigLoadingDesignerConfigLoader(loadConfig)

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object AlignedComponentsDefinitionProvider {
new AlignedComponentsDefinitionProvider(
new BuiltInComponentsDefinitionsPreparer(designerModelData.modelData.componentsUiConfig),
new FragmentComponentDefinitionExtractor(
designerModelData.modelData.modelClassLoader.classLoader,
designerModelData.modelData.modelClassLoader,
designerModelData.modelData.modelDefinitionWithClasses.classDefinitions.all,
designerModelData.modelData.componentsUiConfig.groupName,
designerModelData.modelData.determineDesignerWideId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import io.dropwizard.metrics5.MetricRegistry
import io.dropwizard.metrics5.jmx.JmxReporter
import pl.touk.nussknacker.engine.ConfigWithUnresolvedVersion
import pl.touk.nussknacker.engine.util.loader.ScalaServiceLoader
import pl.touk.nussknacker.engine.util.{JavaClassVersionChecker, SLF4JBridgeHandlerRegistrar}
import pl.touk.nussknacker.engine.util.{
ExecutionContextWithIORuntimeAdapter,
JavaClassVersionChecker,
SLF4JBridgeHandlerRegistrar
}
import pl.touk.nussknacker.ui.config.{DesignerConfig, DesignerConfigLoader}
import pl.touk.nussknacker.ui.configloader.{ProcessingTypeConfigsLoader, ProcessingTypeConfigsLoaderFactory}
import pl.touk.nussknacker.ui.db.DbRef
Expand All @@ -19,7 +23,7 @@ import pl.touk.nussknacker.ui.process.processingtype.loader.{
ProcessingTypesConfigBasedProcessingTypeDataLoader
}
import pl.touk.nussknacker.ui.server.{AkkaHttpBasedRouteProvider, NussknackerHttpServer}
import pl.touk.nussknacker.ui.util.{ActorSystemBasedExecutionContextWithIORuntime, IOToFutureSttpBackendConverter}
import pl.touk.nussknacker.ui.util.IOToFutureSttpBackendConverter
import sttp.client3.SttpBackend
import sttp.client3.asynchttpclient.cats.AsyncHttpClientCatsBackend

Expand All @@ -32,10 +36,10 @@ class NussknackerAppFactory(

def createApp(clock: Clock = Clock.systemUTC()): Resource[IO, Unit] = {
for {
designerConfig <- Resource.eval(designerConfigLoader.loadDesignerConfig())
system <- createActorSystem(designerConfig.rawConfig)
executionContextWithIORuntime = ActorSystemBasedExecutionContextWithIORuntime.createFrom(system)
ioSttpBackend <- AsyncHttpClientCatsBackend.resource[IO]()
designerConfig <- Resource.eval(designerConfigLoader.loadDesignerConfig())
system <- createActorSystem(designerConfig.rawConfig)
executionContextWithIORuntime <- ExecutionContextWithIORuntimeAdapter.createFrom(system.dispatcher)
ioSttpBackend <- AsyncHttpClientCatsBackend.resource[IO]()
processingTypeConfigsLoader = createProcessingTypeConfigsLoader(
designerConfig,
ioSttpBackend
Expand Down Expand Up @@ -120,11 +124,13 @@ class NussknackerAppFactory(

object NussknackerAppFactory {

def apply(designerConfigLoader: DesignerConfigLoader): NussknackerAppFactory = {
new NussknackerAppFactory(
designerConfigLoader,
new ProcessingTypesConfigBasedProcessingTypeDataLoader(_)
)
def create(designerConfigLoader: DesignerConfigLoader): Resource[IO, NussknackerAppFactory] = {
Resource.pure[IO, NussknackerAppFactory] {
new NussknackerAppFactory(
designerConfigLoader,
new ProcessingTypesConfigBasedProcessingTypeDataLoader(_)
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import pl.touk.nussknacker.engine.compile.ProcessValidator
import pl.touk.nussknacker.engine.definition.component.Components.ComponentDefinitionExtractionMode
import pl.touk.nussknacker.engine.definition.test.ModelDataTestInfoProvider
import pl.touk.nussknacker.engine.dict.ProcessDictSubstitutor
import pl.touk.nussknacker.engine.util.ExecutionContextWithIORuntime
import pl.touk.nussknacker.engine.util.loader.ScalaServiceLoader
import pl.touk.nussknacker.engine.util.multiplicity.{Empty, Many, Multiplicity, One}
import pl.touk.nussknacker.engine.{DeploymentManagerDependencies, ModelDependencies}
Expand Down Expand Up @@ -430,7 +431,7 @@ class AkkaHttpBasedRouteProvider(
(
processingTypeData.designerModelData.modelData.designerDictServices.dictQueryService,
processingTypeData.designerModelData.modelData.modelDefinition.expressionConfig.dictionaries,
processingTypeData.designerModelData.modelData.modelClassLoader.classLoader
processingTypeData.designerModelData.modelData.modelClassLoader
)
}
)
Expand Down Expand Up @@ -704,7 +705,7 @@ class AkkaHttpBasedRouteProvider(
Resource
.make(
acquire = IO {
val laodProcessingTypeDataIO = processingTypeDataLoader.loadProcessingTypeData(
val loadProcessingTypeDataIO = processingTypeDataLoader.loadProcessingTypeData(
getModelDependencies(
additionalUIConfigProvider,
_,
Expand All @@ -719,7 +720,7 @@ class AkkaHttpBasedRouteProvider(
_
),
)
new ReloadableProcessingTypeDataProvider(laodProcessingTypeDataIO)
new ReloadableProcessingTypeDataProvider(loadProcessingTypeDataIO)
}
)(
release = _.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object ExpressionSuggester {
modelData.modelDefinition.expressionConfig,
modelData.modelDefinitionWithClasses.classDefinitions,
modelData.designerDictServices,
modelData.modelClassLoader.classLoader,
modelData.modelClassLoader,
scenarioPropertiesNames
)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pl.touk.nussknacker.ui.util

import cats.arrow.FunctionK
import cats.effect.IO
import pl.touk.nussknacker.engine.util.ExecutionContextWithIORuntime
import sttp.client3.SttpBackend
import sttp.client3.impl.cats.implicits.sttpBackendToCatsMappableSttpBackend
import sttp.monad.FutureMonad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.scalatest.{BeforeAndAfterAll, Suite}
import pl.touk.nussknacker.test.DefaultUniquePortProvider
import pl.touk.nussknacker.test.base.db.WithHsqlDbTesting
import pl.touk.nussknacker.test.config.WithDesignerConfig
import pl.touk.nussknacker.ui.config.DesignerConfigLoader
import pl.touk.nussknacker.ui.config.SimpleConfigLoadingDesignerConfigLoader
import pl.touk.nussknacker.ui.factory.NussknackerAppFactory

trait NuItTest extends WithHsqlDbTesting with DefaultUniquePortProvider with WithClock with BeforeAndAfterAll {
Expand All @@ -22,9 +22,10 @@ trait NuItTest extends WithHsqlDbTesting with DefaultUniquePortProvider with Wit

override protected def beforeAll(): Unit = {
super.beforeAll()
val designerConfigLoader = DesignerConfigLoader.fromConfig(adjustNuTestConfig())
releaseAppResources = NussknackerAppFactory(designerConfigLoader)
.createApp(clock = clock)
val designerConfigLoader = new SimpleConfigLoadingDesignerConfigLoader(adjustNuTestConfig())
releaseAppResources = NussknackerAppFactory
.create(designerConfigLoader)
.flatMap(_.createApp(clock = clock))
.allocated
.unsafeRunSync()
._2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.typesafe
import com.typesafe.config.{Config, ConfigFactory}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers.{convertToAnyShouldWrapper, include}
import pl.touk.nussknacker.ui.config.{DesignerConfig, DesignerConfigLoader}
import pl.touk.nussknacker.ui.config.{DesignerConfig, SimpleConfigLoadingDesignerConfigLoader}
import pl.touk.nussknacker.ui.configloader.ProcessingTypeConfigsLoader

class ProcessingTypeDataLoaderSpec extends AnyFunSuite {
Expand Down Expand Up @@ -118,7 +118,7 @@ class ProcessingTypeDataLoaderSpec extends AnyFunSuite {
}

private def staticConfigBasedProcessingTypeConfigsLoader(config: Config): ProcessingTypeConfigsLoader = { () =>
DesignerConfigLoader.fromConfig(config).loadDesignerConfig().map(_.processingTypeConfigs)
new SimpleConfigLoadingDesignerConfigLoader(config).loadDesignerConfig().map(_.processingTypeConfigs)
}

private def loadDifferentConfigPerInvocationProcessingTypeConfigsLoader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.concurrent.{ExecutionContext, Future}

class FlinkProcessTestRunner(modelData: ModelData)
extends StaticMethodRunner(
modelData.modelClassLoader.classLoader,
modelData.modelClassLoader,
"pl.touk.nussknacker.engine.process.runner.FlinkTestMain",
"run"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scala.util.control.NonFatal

class FlinkProcessVerifier(modelData: ModelData)
extends StaticMethodRunner(
modelData.modelClassLoader.classLoader,
modelData.modelClassLoader,
"pl.touk.nussknacker.engine.process.runner.FlinkVerificationMain",
"run"
)
Expand Down
Loading
Loading