Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadius committed Dec 17, 2024
1 parent 443008f commit ada66eb
Show file tree
Hide file tree
Showing 28 changed files with 301 additions and 254 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pl.touk.nussknacker.ui.configloader

import com.typesafe.config.Config
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
import pl.touk.nussknacker.engine.{ConfigWithUnresolvedVersion, ProcessingTypeConfig}

// TODO: We should extract a class for all configuration options that should be available to designer instead of returning raw hocon config.
// Thanks to that it will be easier to split processing type config from rest of configs and use this interface programmatically
final case class DesignerConfig private (rawConfig: ConfigWithUnresolvedVersion) {

def processingTypeConfigs: Map[String, ProcessingTypeConfig] = {
rawConfig
.readMap("scenarioTypes")
.getOrElse {
throw new RuntimeException("No scenario types configuration provided")
}
.mapValuesNow(ProcessingTypeConfig.read)
}

}

object DesignerConfig {

def from(config: Config): DesignerConfig = {
DesignerConfig(ConfigWithUnresolvedVersion(config))
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
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
import pl.touk.nussknacker.engine.ProcessingTypeConfig

trait ProcessingTypeConfigsLoader {

def loadProcessingTypeConfigs(): IO[Map[String, ProcessingTypeConfig]]

}

object ProcessingTypeConfigsLoader extends LazyLogging {

def extractProcessingTypeConfigs(rootConfig: DesignerRootConfig): Map[String, ProcessingTypeConfig] = {
rootConfig.rawConfig
.readMap("scenarioTypes")
.getOrElse {
throw new RuntimeException("No scenario types configuration provided")
}
.mapValuesNow(ProcessingTypeConfig.read)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import scala.concurrent.{ExecutionContext, Future}
trait ProcessingTypeConfigsLoaderFactory {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ package pl.touk.nussknacker.ui
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.engine.{DeploymentManagerProvider, ModelData, ProcessingTypeConfig}
import pl.touk.nussknacker.ui.factory.NussknackerAppFactory
import pl.touk.nussknacker.ui.config.root.DesignerRootConfigLoader
import pl.touk.nussknacker.ui.config.DesignerConfigLoader
import pl.touk.nussknacker.ui.configloader.{
DesignerConfig,
ProcessingTypeConfigsLoader,
ProcessingTypeConfigsLoaderFactory
}
import pl.touk.nussknacker.ui.process.processingtype.loader.LocalProcessingTypeDataLoader
import sttp.client3.SttpBackend

import java.io.File
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import scala.concurrent.{ExecutionContext, Future}
import scala.jdk.CollectionConverters._

//This is helper, which allows for starting UI with given model without having to build jar etc.
Expand Down Expand Up @@ -49,10 +56,17 @@ object LocalNussknackerWithSingleModel {
modelData = Map(typeName -> (category, modelData)),
deploymentManagerProvider = deploymentManagerProvider
)
val designerConfigLoader = DesignerRootConfigLoader.fromConfig(appConfig)
val designerConfigLoader = DesignerConfigLoader.fromConfig(appConfig)
val processingTypeConfigsLoaderFactory = new ProcessingTypeConfigsLoaderFactory {
override def create(designerConfigLoadedAtStart: DesignerConfig, sttpBackend: SttpBackend[Future, Any])(
implicit ec: ExecutionContext
): ProcessingTypeConfigsLoader = { () =>
IO.pure(Map.empty)
}
}
val appFactory = new NussknackerAppFactory(
designerConfigLoader,
(_, _, _) => () => IO.pure(Map.empty),
Some(processingTypeConfigsLoaderFactory),
_ => local
)
appFactory.createApp()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package pl.touk.nussknacker.ui

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

object NussknackerApp extends IOApp {

override def run(args: List[String]): IO[ExitCode] = {
for {
appFactory <- IO(NussknackerAppFactory(DesignerRootConfigLoader(getClass.getClassLoader)))
appFactory <- IO(NussknackerAppFactory(DesignerConfigLoader(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,8 +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.{Schema, _}
import sttp.tapir.json.circe._
import sttp.tapir._

import scala.language.implicitConversions

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package pl.touk.nussknacker.ui.config

import cats.effect.IO
import com.typesafe.config.{Config, ConfigFactory}
import pl.touk.nussknacker.engine.ConfigWithUnresolvedVersion
import pl.touk.nussknacker.engine.util.UriUtils
import pl.touk.nussknacker.engine.util.config.ConfigFactoryExt
import pl.touk.nussknacker.ui.configloader.DesignerConfig

trait DesignerConfigLoader {

def loadDesignerConfig(): IO[DesignerConfig]

}

/**
* This class handles two parts of ui config loading:
* 1. Parsing of "base" config passed via nussknacker.config.locations system property (without resolution)
* 2. Loading this parsed config with fallback to config inside defaultDesignerConfig.conf resource
* This process is split that way to make possible using "base" configs prepared programmatically -
* see LocalNussknackerWithSingleModel for a sample of such usage
* Result of config loading still keep version with unresolved env variables for purpose of config loading on model side - see
* InputConfigDuringExecution and ModelConfigLoader
*/
class AlwaysLoadingFileBasedDesignerConfigLoader(classLoader: ClassLoader) extends DesignerConfigLoader {

private val configLocationsProperty: String = "nussknacker.config.locations"

private val defaultConfigResource = "defaultDesignerConfig.conf"

override def loadDesignerConfig(): IO[DesignerConfig] = {
val locationsPropertyValueOpt = Option(System.getProperty(configLocationsProperty))
val locations = locationsPropertyValueOpt.map(UriUtils.extractListOfLocations).getOrElse(List.empty)
for {
baseUnresolvedConfig <- IO.blocking(new ConfigFactoryExt(classLoader).parseUnresolved(locations))
parsedDefaultUiConfig <- IO.blocking(ConfigFactory.parseResources(classLoader, defaultConfigResource))
unresolvedConfigWithFallbackToDefaults = baseUnresolvedConfig.withFallback(parsedDefaultUiConfig)
} yield DesignerConfig(ConfigWithUnresolvedVersion(classLoader, unresolvedConfigWithFallbackToDefaults))
}

}

/**
* This implementation is more straightforward - it only parse config without any property checking and fallbacks
*/
class SimpleConfigLoadingDesignerConfigLoader(loadConfig: => Config) extends DesignerConfigLoader {

override def loadDesignerConfig(): IO[DesignerConfig] = IO.delay(DesignerConfig.from(loadConfig))

}

object DesignerConfigLoader {

def apply(classLoader: ClassLoader): AlwaysLoadingFileBasedDesignerConfigLoader =
new AlwaysLoadingFileBasedDesignerConfigLoader(classLoader)

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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.config.DesignerConfigLoader
import pl.touk.nussknacker.ui.configloader.ProcessingTypeConfigsLoader

class EachTimeLoadingRootConfigProcessingTypeConfigsLoader(designerRootConfigLoader: DesignerRootConfigLoader)
class EachTimeLoadingDesignerConfigProcessingTypeConfigsLoader(designerConfigLoader: DesignerConfigLoader)
extends ProcessingTypeConfigsLoader {

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

}

This file was deleted.

This file was deleted.

Loading

0 comments on commit ada66eb

Please sign in to comment.