Skip to content

Commit

Permalink
api module extracted
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadius committed Dec 5, 2024
1 parent 093679c commit 357a1b6
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 149 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.*" />
<option name="PATTERN" value="pl.touk.nussknacker.ui.config.processingtype.*" />
<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.*" />
<option name="PATTERN" value="pl.touk.nussknacker.ui.config.processingtype.*" />
<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.*" />
<option name="PATTERN" value="pl.touk.nussknacker.ui.config.processingtype.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
</component>
24 changes: 19 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import com.typesafe.sbt.packager.SettingsHelper
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.dockerUsername
import pl.project13.scala.sbt.JmhPlugin
import pl.project13.scala.sbt.JmhPlugin._
import sbt.Keys._
import sbt._
import pl.project13.scala.sbt.JmhPlugin.*
import sbt.*
import sbt.Keys.*
import sbtassembly.AssemblyPlugin.autoImport.assembly
import sbtassembly.MergeStrategy
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations.*

import scala.language.postfixOps
import scala.sys.process._
import scala.sys.process.*
import scala.util.Try
import scala.xml.Elem
import scala.xml.transform.{RewriteRule, RuleTransformer}
Expand Down Expand Up @@ -1915,6 +1915,18 @@ lazy val listenerApi = (project in file("designer/listener-api"))
)
.dependsOn(extensionsApi)

lazy val loadableConfigApi = (project in file("designer/loadable-config-api"))
.settings(commonSettings)
.settings(
name := "nussknacker-loadable-config-api",
libraryDependencies ++= {
Seq(
"org.typelevel" %% "cats-effect" % catsEffectV
)
}
)
.dependsOn(extensionsApi)

lazy val deploymentManagerApi = (project in file("designer/deployment-manager-api"))
.settings(commonSettings)
.settings(
Expand Down Expand Up @@ -2055,6 +2067,7 @@ lazy val designer = (project in file("designer/server"))
deploymentManagerApi,
restmodel,
listenerApi,
loadableConfigApi,
defaultHelpers % Test,
testUtils % Test,
flinkTestUtils % Test,
Expand Down Expand Up @@ -2195,6 +2208,7 @@ lazy val modules = List[ProjectReference](
httpUtils,
restmodel,
listenerApi,
loadableConfigApi,
deploymentManagerApi,
designer,
sqlComponents,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pl.touk.nussknacker.ui.loadableconfig

import com.typesafe.config.Config
import pl.touk.nussknacker.engine.ConfigWithUnresolvedVersion

// 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 DesignerRootConfig(rawConfig: ConfigWithUnresolvedVersion)

object DesignerRootConfig {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package pl.touk.nussknacker.ui.loadableconfig

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 {

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

}

object LoadableProcessingTypeConfigs 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 @@ -4,9 +4,9 @@ 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.config.DesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig
import pl.touk.nussknacker.ui.factory.NussknackerAppFactory
import pl.touk.nussknacker.ui.loadableconfig.LoadableDesignerRootConfig
import pl.touk.nussknacker.ui.config.root.LoadableDesignerRootConfig
import pl.touk.nussknacker.ui.process.processingtype.loader.LocalProcessingTypeDataLoader

import java.io.File
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.touk.nussknacker.ui

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

object NussknackerApp extends IOApp {

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

import cats.effect.IO
import pl.touk.nussknacker.engine.ProcessingTypeConfig
import pl.touk.nussknacker.ui.config.root.LoadableDesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.{DesignerRootConfig, LoadableProcessingTypeConfigs}

class EachTimeLoadingRootConfigLoadableProcessingTypeConfigs(loadableDesignerRootConfig: LoadableDesignerRootConfig)
extends LoadableProcessingTypeConfigs {

def loadProcessingTypeConfigs(
rootConfigLoadedAtStart: DesignerRootConfig
): IO[Map[String, ProcessingTypeConfig]] =
loadableDesignerRootConfig
.loadDesignerRootConfig()
.map(LoadableProcessingTypeConfigs.extractProcessingTypeConfigs)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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.LoadableDesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.LoadableProcessingTypeConfigs

object LoadableProcessingTypeConfigsFactory extends LazyLogging {

def create(loadableDesignerRootConfig: LoadableDesignerRootConfig): LoadableProcessingTypeConfigs = {
ScalaServiceLoader.load[LoadableProcessingTypeConfigs](getClass.getClassLoader) match {
case one :: Nil =>
logger.debug(
s"Found custom ${classOf[LoadableProcessingTypeConfigs].getSimpleName}: ${one.getClass.getName}. Using it for configuration loading"
)
one
case Nil =>
logger.debug(s"No custom ${classOf[LoadableProcessingTypeConfigs].getSimpleName} found. Using the default one")
new EachTimeLoadingRootConfigLoadableProcessingTypeConfigs(loadableDesignerRootConfig)
case _ =>
throw new IllegalStateException(s"More than one ${classOf[LoadableProcessingTypeConfigs].getSimpleName} found")
}
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package pl.touk.nussknacker.ui.config
package pl.touk.nussknacker.ui.config.root

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

/**
* This class handles two parts of ui config loading:
Expand Down Expand Up @@ -35,14 +36,3 @@ object DesignerRootConfigLoader {

}

// 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 DesignerRootConfig(rawConfig: ConfigWithUnresolvedVersion)

object DesignerRootConfig {

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

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.touk.nussknacker.ui.loadableconfig
package pl.touk.nussknacker.ui.config.root

import cats.effect.IO
import pl.touk.nussknacker.ui.config.DesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig

trait LoadableDesignerRootConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import io.dropwizard.metrics5.MetricRegistry
import io.dropwizard.metrics5.jmx.JmxReporter
import pl.touk.nussknacker.engine.ConfigWithUnresolvedVersion
import pl.touk.nussknacker.engine.util.{JavaClassVersionChecker, SLF4JBridgeHandlerRegistrar}
import pl.touk.nussknacker.ui.config.root.LoadableDesignerRootConfig
import pl.touk.nussknacker.ui.config.processingtype.LoadableProcessingTypeConfigsFactory
import pl.touk.nussknacker.ui.db.DbRef
import pl.touk.nussknacker.ui.db.timeseries.questdb.QuestDbFEStatisticsRepository
import pl.touk.nussknacker.ui.loadableconfig.{
EachTimeLoadingRootConfigLoadableProcessingTypeConfigs,
LoadableDesignerRootConfig,
LoadableProcessingTypeConfigs
}
import pl.touk.nussknacker.ui.process.processingtype.loader._
import pl.touk.nussknacker.ui.server.{AkkaHttpBasedRouteProvider, NussknackerHttpServer}

Expand Down Expand Up @@ -87,7 +84,7 @@ class NussknackerAppFactory(
object NussknackerAppFactory {

def apply(loadableDesignerRootConfig: LoadableDesignerRootConfig): NussknackerAppFactory = {
val loadableProcessingTypeConfig = LoadableProcessingTypeConfigs.default(loadableDesignerRootConfig)
val loadableProcessingTypeConfig = LoadableProcessingTypeConfigsFactory.create(loadableDesignerRootConfig)
val processingTypeDataLoader = new ProcessingTypesConfigBasedProcessingTypeDataLoader(loadableProcessingTypeConfig)
new NussknackerAppFactory(loadableDesignerRootConfig, processingTypeDataLoader)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.typesafe.config.ConfigFactory
import pl.touk.nussknacker.engine._
import pl.touk.nussknacker.engine.api.process.ProcessingType
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
import pl.touk.nussknacker.ui.config.DesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig
import pl.touk.nussknacker.ui.process.processingtype.loader.ProcessingTypeDataLoader.toValueWithRestriction
import pl.touk.nussknacker.ui.process.processingtype.provider.ProcessingTypeDataState
import pl.touk.nussknacker.ui.process.processingtype.{CombinedProcessingTypeData, ProcessingTypeData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pl.touk.nussknacker.ui.process.processingtype.loader
import cats.effect.IO
import pl.touk.nussknacker.engine.api.process.ProcessingType
import pl.touk.nussknacker.engine.{DeploymentManagerDependencies, ModelDependencies}
import pl.touk.nussknacker.ui.config.DesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig
import pl.touk.nussknacker.ui.process.processingtype.provider.ProcessingTypeDataState
import pl.touk.nussknacker.ui.process.processingtype.{
CombinedProcessingTypeData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import pl.touk.nussknacker.engine._
import pl.touk.nussknacker.engine.api.process.ProcessingType
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
import pl.touk.nussknacker.engine.util.loader.ScalaServiceLoader
import pl.touk.nussknacker.ui.config.DesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.LoadableProcessingTypeConfigs
import pl.touk.nussknacker.ui.loadableconfig.{DesignerRootConfig, LoadableProcessingTypeConfigs}
import pl.touk.nussknacker.ui.process.processingtype._
import pl.touk.nussknacker.ui.process.processingtype.loader.ProcessingTypeDataLoader.toValueWithRestriction
import pl.touk.nussknacker.ui.process.processingtype.provider.ProcessingTypeDataState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import pl.touk.nussknacker.ui.config.scenariotoolbar.CategoriesScenarioToolbarsC
import pl.touk.nussknacker.ui.config.{
AttachmentsConfig,
ComponentLinksConfigExtractor,
DesignerRootConfig,
FeatureTogglesConfig,
UsageStatisticsReportsConfig
}
Expand All @@ -41,6 +40,7 @@ import pl.touk.nussknacker.ui.initialization.Initialization
import pl.touk.nussknacker.ui.initialization.Initialization.nussknackerUser
import pl.touk.nussknacker.ui.listener.ProcessChangeListenerLoader
import pl.touk.nussknacker.ui.listener.services.NussknackerServices
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig
import pl.touk.nussknacker.ui.metrics.RepositoryGauges
import pl.touk.nussknacker.ui.migrations.{MigrationApiAdapterService, MigrationService}
import pl.touk.nussknacker.ui.notifications.{NotificationConfig, NotificationServiceImpl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import fr.davit.akka.http.metrics.core.{HttpMetricsRegistry, HttpMetricsSettings
import fr.davit.akka.http.metrics.dropwizard.{DropwizardRegistry, DropwizardSettings}
import io.dropwizard.metrics5.MetricRegistry
import pl.touk.nussknacker.engine.ConfigWithUnresolvedVersion
import pl.touk.nussknacker.ui.config.DesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig
import pl.touk.nussknacker.ui.security.ssl.{HttpsConnectionContextFactory, SslConfigParser}

import java.util.concurrent.atomic.AtomicReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pl.touk.nussknacker.ui.server

import akka.http.scaladsl.server.Route
import cats.effect.{IO, Resource}
import pl.touk.nussknacker.ui.config.DesignerRootConfig
import pl.touk.nussknacker.ui.loadableconfig.DesignerRootConfig

trait RouteProvider[R <: Route] {

Expand Down
Loading

0 comments on commit 357a1b6

Please sign in to comment.