Skip to content

Commit

Permalink
loadable config -> config loader + factory
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadius committed Dec 10, 2024
1 parent fa75cc9 commit abd1cd4
Show file tree
Hide file tree
Showing 35 changed files with 215 additions and 197 deletions.
4 changes: 2 additions & 2 deletions .run/NussknackerApp-dist-config.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/designer/server/work" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pl.touk.nussknacker.ui.config.processingtype.*" />
<option name="PATTERN" value="pl.touk.nussknacker.ui.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
</component>
4 changes: 2 additions & 2 deletions .run/NussknackerApp-postgres.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/designer/server/work" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pl.touk.nussknacker.ui.config.processingtype.*" />
<option name="PATTERN" value="pl.touk.nussknacker.ui.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
</component>
4 changes: 2 additions & 2 deletions .run/NussknackerApp.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/designer/server/work" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pl.touk.nussknacker.ui.config.processingtype.*" />
<option name="PATTERN" value="pl.touk.nussknacker.ui.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
</component>
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1913,10 +1913,10 @@ lazy val listenerApi = (project in file("designer/listener-api"))
)
.dependsOn(extensionsApi)

lazy val loadableConfigApi = (project in file("designer/loadable-config-api"))
lazy val configLoaderApi = (project in file("designer/config-loader-api"))
.settings(commonSettings)
.settings(
name := "nussknacker-loadable-config-api",
name := "nussknacker-config-loader-api",
libraryDependencies ++= {
Seq(
"org.typelevel" %% "cats-effect" % catsEffectV
Expand Down Expand Up @@ -2065,7 +2065,7 @@ lazy val designer = (project in file("designer/server"))
deploymentManagerApi,
restmodel,
listenerApi,
loadableConfigApi,
configLoaderApi,
defaultHelpers % Test,
testUtils % Test,
flinkTestUtils % Test,
Expand Down Expand Up @@ -2206,7 +2206,7 @@ lazy val modules = List[ProjectReference](
httpUtils,
restmodel,
listenerApi,
loadableConfigApi,
configLoaderApi,
deploymentManagerApi,
designer,
sqlComponents,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.touk.nussknacker.ui.loadableconfig
package pl.touk.nussknacker.ui.configloader

import com.typesafe.config.Config
import pl.touk.nussknacker.engine.ConfigWithUnresolvedVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package pl.touk.nussknacker.ui.loadableconfig
package pl.touk.nussknacker.ui.configloader

import com.typesafe.scalalogging.LazyLogging
import pl.touk.nussknacker.engine.ProcessingTypeConfig
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
import cats.effect.IO

trait LoadableProcessingTypeConfigs {
trait ProcessingTypeConfigsLoader {

// rootConfigLoadedAtStart is used for external project purpose - don't remove it
def loadProcessingTypeConfigs(rootConfigLoadedAtStart: DesignerRootConfig): IO[Map[String, ProcessingTypeConfig]]
def loadProcessingTypeConfigs(): IO[Map[String, ProcessingTypeConfig]]

}

object LoadableProcessingTypeConfigs extends LazyLogging {
object ProcessingTypeConfigsLoader extends LazyLogging {

def extractProcessingTypeConfigs(rootConfig: DesignerRootConfig): Map[String, ProcessingTypeConfig] = {
rootConfig.rawConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package pl.touk.nussknacker.ui.configloader

import sttp.client3.SttpBackend

import scala.concurrent.{ExecutionContext, Future}

trait ProcessingTypeConfigsLoaderFactory {

def create(
designerRootConfigLoadedAtStart: DesignerRootConfig,
sttpBackend: SttpBackend[Future, Any],
ec: ExecutionContext
): ProcessingTypeConfigsLoader

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import cats.effect.{IO, Resource}
import com.typesafe.config.{Config, ConfigFactory}
import org.apache.commons.io.FileUtils
import pl.touk.nussknacker.engine.{DeploymentManagerProvider, ModelData}
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig
import pl.touk.nussknacker.ui.factory.NussknackerAppFactory
import pl.touk.nussknacker.ui.config.root.LoadableDesignerRootConfig
import pl.touk.nussknacker.ui.config.root.DesignerRootConfigLoader
import pl.touk.nussknacker.ui.process.processingtype.loader.LocalProcessingTypeDataLoader

import java.io.File
Expand Down Expand Up @@ -50,8 +49,12 @@ object LocalNussknackerWithSingleModel {
modelData = Map(typeName -> (category, modelData)),
deploymentManagerProvider = deploymentManagerProvider
)
val loadableDesignerConfig = LoadableDesignerRootConfig(IO.delay(DesignerRootConfig.from(appConfig)))
val appFactory = new NussknackerAppFactory(loadableDesignerConfig, local)
val designerConfigLoader = DesignerRootConfigLoader.fromConfig(appConfig)
val appFactory = new NussknackerAppFactory(
designerConfigLoader,
(_, _, _) => () => IO.pure(Map.empty),
_ => local
)
appFactory.createApp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package pl.touk.nussknacker.ui
import cats.effect.{ExitCode, IO, IOApp}
import pl.touk.nussknacker.ui.config.root.DesignerRootConfigLoader
import pl.touk.nussknacker.ui.factory.NussknackerAppFactory
import pl.touk.nussknacker.ui.config.root.LoadableDesignerRootConfig

object NussknackerApp extends IOApp {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import pl.touk.nussknacker.ui.api.description.DictApiEndpoints.DictError.{
}
import pl.touk.nussknacker.ui.api.description.DictApiEndpoints.Dtos._
import sttp.model.StatusCode.{BadRequest, NotFound, Ok}
import sttp.tapir._
import sttp.tapir.{Schema, _}
import sttp.tapir.json.circe._
import sttp.tapir.Schema

import scala.language.implicitConversions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import pl.touk.nussknacker.restmodel.BaseEndpointDefinitions
import pl.touk.nussknacker.restmodel.BaseEndpointDefinitions.SecuredEndpoint
import pl.touk.nussknacker.security.AuthCredentials
import pl.touk.nussknacker.ui.security.api.GlobalPermission.GlobalPermission
import pl.touk.nussknacker.ui.security.api.{AdminUser, CommonUser, ImpersonatedUser, LoggedUser, RealLoggedUser}
import pl.touk.nussknacker.ui.security.api._
import sttp.model.StatusCode.Ok
import sttp.tapir.EndpointIO.Example
import sttp.tapir.derevo.schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package pl.touk.nussknacker.ui.api.description.scenarioActivity
import pl.touk.nussknacker.engine.api.process.ProcessName
import pl.touk.nussknacker.ui.api.description.scenarioActivity.Dtos.ScenarioActivityError
import pl.touk.nussknacker.ui.api.description.scenarioActivity.Dtos.ScenarioActivityError.NoScenario
import sttp.model.StatusCode.{NotFound, NotImplemented}
import sttp.model.StatusCode.NotFound
import sttp.tapir.EndpointIO.Example
import sttp.tapir.{EndpointOutput, emptyOutputAs, oneOf, oneOfVariantFromMatchType, plainBody}
import sttp.tapir.{EndpointOutput, oneOf, oneOfVariantFromMatchType, plainBody}

object InputOutput {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pl.touk.nussknacker.ui.config.processingtype

import cats.effect.IO
import pl.touk.nussknacker.engine.ProcessingTypeConfig
import pl.touk.nussknacker.ui.config.root.DesignerRootConfigLoader
import pl.touk.nussknacker.ui.configloader.ProcessingTypeConfigsLoader

class EachTimeLoadingRootConfigProcessingTypeConfigsLoader(designerRootConfigLoader: DesignerRootConfigLoader)
extends ProcessingTypeConfigsLoader {

def loadProcessingTypeConfigs(): IO[Map[String, ProcessingTypeConfig]] =
designerRootConfigLoader
.loadDesignerRootConfig()
.map(ProcessingTypeConfigsLoader.extractProcessingTypeConfigs)

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package pl.touk.nussknacker.ui.config.processingtype

import com.typesafe.scalalogging.LazyLogging
import pl.touk.nussknacker.engine.util.loader.ScalaServiceLoader
import pl.touk.nussknacker.ui.config.root.DesignerRootConfigLoader
import pl.touk.nussknacker.ui.configloader.{
DesignerRootConfig,
ProcessingTypeConfigsLoader,
ProcessingTypeConfigsLoaderFactory
}
import sttp.client3.SttpBackend

import scala.concurrent.{ExecutionContext, Future}

object ProcessingTypeConfigsLoaderFactoryServiceLoader extends LazyLogging {

def loadService(designerRootConfigLoader: DesignerRootConfigLoader): ProcessingTypeConfigsLoaderFactory = {
ScalaServiceLoader.load[ProcessingTypeConfigsLoaderFactory](getClass.getClassLoader) match {
case one :: Nil =>
logger.debug(
s"Found custom ${classOf[ProcessingTypeConfigsLoaderFactory].getSimpleName}: ${one.getClass.getName}. Using it for configuration loading"
)
one
case Nil =>
logger.debug(
s"No custom ${classOf[ProcessingTypeConfigsLoaderFactory].getSimpleName} found. Using the default one"
)
(_: DesignerRootConfig, _: SttpBackend[Future, Any], _: ExecutionContext) =>
new EachTimeLoadingRootConfigProcessingTypeConfigsLoader(designerRootConfigLoader)
case _ =>
throw new IllegalStateException(s"More than one ${classOf[ProcessingTypeConfigsLoader].getSimpleName} found")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import cats.effect.IO
import com.typesafe.config.{Config, ConfigFactory}
import pl.touk.nussknacker.engine.ConfigWithUnresolvedVersion
import pl.touk.nussknacker.engine.util.config.ConfigFactoryExt
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig
import pl.touk.nussknacker.ui.configloader.DesignerRootConfig

trait DesignerRootConfigLoader {

def loadDesignerRootConfig(): IO[DesignerRootConfig]

}

/**
* This class handles two parts of ui config loading:
Expand All @@ -15,18 +21,18 @@ import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig
* Result of config loading still keep version with unresolved env variables for purpose of config loading on model side - see
* InputConfigDuringExecution and ModelConfigLoader
*/
object DesignerRootConfigLoader {
private[root] class DesignerRootConfigLoaderImpl(classLoader: ClassLoader) extends DesignerRootConfigLoader {

private val defaultConfigResource = "defaultDesignerConfig.conf"

def load(classLoader: ClassLoader): IO[DesignerRootConfig] = {
override def loadDesignerRootConfig(): IO[DesignerRootConfig] = {
for {
baseConfig <- IO.blocking(ConfigFactoryExt.parseUnresolved(classLoader = classLoader))
loadedConfig <- load(baseConfig, classLoader)
loadedConfig <- load(baseConfig)
} yield DesignerRootConfig(loadedConfig)
}

def load(baseUnresolvedConfig: Config, classLoader: ClassLoader): IO[ConfigWithUnresolvedVersion] = {
def load(baseUnresolvedConfig: Config): IO[ConfigWithUnresolvedVersion] = {
IO.blocking {
val parsedDefaultUiConfig = ConfigFactory.parseResources(classLoader, defaultConfigResource)
val unresolvedConfigWithFallbackToDefaults = baseUnresolvedConfig.withFallback(parsedDefaultUiConfig)
Expand All @@ -36,3 +42,10 @@ object DesignerRootConfigLoader {

}

object DesignerRootConfigLoader {

def apply(classLoader: ClassLoader): DesignerRootConfigLoader = new DesignerRootConfigLoaderImpl(classLoader)

def fromConfig(config: => Config): DesignerRootConfigLoader = () => IO.delay(DesignerRootConfig.from(config))

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import pl.touk.nussknacker.engine.api.deployment.{
}
import pl.touk.nussknacker.engine.api.process.{ProcessId, ProcessName, VersionId}
import pl.touk.nussknacker.engine.newdeployment.DeploymentId
import slick.ast.BaseTypedType
import slick.jdbc.{JdbcProfile, JdbcType}
import slick.jdbc.JdbcProfile

import java.util.UUID

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pl.touk.nussknacker.ui.db.entity

import pl.touk.nussknacker.engine.api.process.{ProcessId, ProcessName}
import pl.touk.nussknacker.engine.api.process.ProcessingType
import pl.touk.nussknacker.engine.api.process.{ProcessId, ProcessName, ProcessingType}
import slick.lifted.{ProvenShape, TableQuery => LTableQuery}
import slick.sql.SqlProfile.ColumnOption.NotNull

Expand Down
Loading

0 comments on commit abd1cd4

Please sign in to comment.