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 ada66eb commit 915e4df
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 56 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ 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.ui.config.DesignerConfigLoader
import pl.touk.nussknacker.ui.config.processingtype.ProcessingTypeConfigsLoaderFactoryServiceLoader.{getClass, logger}
import pl.touk.nussknacker.ui.config.processingtype.{
EachTimeLoadingDesignerConfigProcessingTypeConfigsLoader,
ProcessingTypeConfigsLoaderFactoryServiceLoader
}
import pl.touk.nussknacker.ui.configloader.{
DesignerConfig,
ProcessingTypeConfigsLoader,
Expand Down Expand Up @@ -83,7 +78,7 @@ class NussknackerAppFactory(
designerConfig: DesignerConfig,
executionContextWithIORuntime: ActorSystemBasedExecutionContextWithIORuntime,
sttpBackend: SttpBackend[Future, Any]
) = {
): ProcessingTypeConfigsLoader = {
processingTypeConfigsLoaderFactoryOpt
.map { factory =>
logger.debug(
Expand All @@ -98,7 +93,7 @@ class NussknackerAppFactory(
logger.debug(
s"No custom ${classOf[ProcessingTypeConfigsLoaderFactory].getSimpleName} found. Using the default implementation of loader"
)
new EachTimeLoadingDesignerConfigProcessingTypeConfigsLoader(designerConfigLoader)
() => designerConfigLoader.loadDesignerConfig().map(_.processingTypeConfigs)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@ import pl.touk.nussknacker.ui.process.processingtype.loader.ProcessingTypeDataLo
import pl.touk.nussknacker.ui.process.processingtype.provider.ProcessingTypeDataState

class ProcessingTypesConfigBasedProcessingTypeDataLoader(processingTypeConfigsLoader: ProcessingTypeConfigsLoader)
extends ProcessingTypeDataLoader {
extends ProcessingTypeDataLoader
with LazyLogging {

override def loadProcessingTypeData(
getModelDependencies: ProcessingType => ModelDependencies,
getDeploymentManagerDependencies: ProcessingType => DeploymentManagerDependencies,
): IO[ProcessingTypeDataState[ProcessingTypeData, CombinedProcessingTypeData]] = {
processingTypeConfigsLoader
.loadProcessingTypeConfigs()
.map(
ProcessingTypesConfigBasedProcessingTypeDataLoader
.loadProcessingTypeData(_, getModelDependencies, getDeploymentManagerDependencies)
)
.map(createProcessingTypeData(_, getModelDependencies, getDeploymentManagerDependencies))
}

}

object ProcessingTypesConfigBasedProcessingTypeDataLoader extends LazyLogging {

def loadProcessingTypeData(
private def createProcessingTypeData(
processingTypesConfig: Map[String, ProcessingTypeConfig],
getModelDependencies: ProcessingType => ModelDependencies,
getDeploymentManagerDependencies: ProcessingType => DeploymentManagerDependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import akka.http.scaladsl.model.{ContentTypes, HttpEntity, StatusCode, StatusCod
import akka.http.scaladsl.server.{Directives, Route}
import akka.http.scaladsl.testkit.ScalatestRouteTest
import akka.http.scaladsl.unmarshalling.FromEntityUnmarshaller
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import com.typesafe.config.Config
import com.typesafe.scalalogging.LazyLogging
import db.util.DBIOActionInstances.DB
Expand Down Expand Up @@ -39,7 +41,7 @@ import pl.touk.nussknacker.test.utils.scalas.AkkaHttpExtensions.toRequestEntity
import pl.touk.nussknacker.ui.api._
import pl.touk.nussknacker.ui.config.scenariotoolbar.CategoriesScenarioToolbarsConfigParser
import pl.touk.nussknacker.ui.config.FeatureTogglesConfig
import pl.touk.nussknacker.ui.configloader.{DesignerConfig, ProcessingTypeConfigsLoader}
import pl.touk.nussknacker.ui.configloader.DesignerConfig
import pl.touk.nussknacker.ui.process.ProcessService.{CreateScenarioCommand, UpdateScenarioCommand}
import pl.touk.nussknacker.ui.process._
import pl.touk.nussknacker.ui.process.deployment._
Expand Down Expand Up @@ -147,12 +149,12 @@ trait NuResourcesTest
protected val typeToConfig: ProcessingTypeDataProvider[ProcessingTypeData, CombinedProcessingTypeData] = {
val designerConfig = DesignerConfig.from(testConfig)
ProcessingTypeDataProvider(
ProcessingTypesConfigBasedProcessingTypeDataLoader
new ProcessingTypesConfigBasedProcessingTypeDataLoader(() => IO.pure(designerConfig.processingTypeConfigs))
.loadProcessingTypeData(
designerConfig.processingTypeConfigs,
_ => modelDependencies,
_ => deploymentManagerDependencies
)
.unsafeRunSync()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.scalatest.matchers.should.Matchers.{convertToAnyShouldWrapper, includ
import pl.touk.nussknacker.ui.config.DesignerConfigLoader
import pl.touk.nussknacker.ui.configloader.{DesignerConfig, ProcessingTypeConfigsLoader}

class EachTimeLoadingDesignerConfigProcessingTypeConfigsLoaderSpec extends AnyFunSuite {
class ProcessingTypeDataLoaderSpec extends AnyFunSuite {

test("should throw when required configuration is missing") {
val config = ConfigFactory
Expand Down Expand Up @@ -118,9 +118,7 @@ class EachTimeLoadingDesignerConfigProcessingTypeConfigsLoaderSpec extends AnyFu
}

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

private def loadDifferentConfigPerInvocationProcessingTypeConfigsLoader(
Expand All @@ -130,13 +128,13 @@ class EachTimeLoadingDesignerConfigProcessingTypeConfigsLoaderSpec extends AnyFu
): ProcessingTypeConfigsLoader = {
val ref = Ref.unsafe[IO, Int](0)
val allConfigs = config1 :: config2 :: configs.toList
val loadConfig = ref.getAndUpdate(_ + 1).flatMap { idx =>
val loadDesignerConfig = ref.getAndUpdate(_ + 1).flatMap { idx =>
allConfigs.lift(idx) match {
case Some(config) => IO.pure(DesignerConfig.from(config))
case None => IO.raiseError(throw new IllegalStateException(s"Cannot load the config more than [$idx]"))
}
}
new EachTimeLoadingDesignerConfigProcessingTypeConfigsLoader(() => loadConfig)
() => loadDesignerConfig.map(_.processingTypeConfigs)
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package pl.touk.nussknacker.ui.process.processingtype

import cats.data.Validated.Invalid
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.LazyLogging
import org.scalatest.Inside.inside
import org.scalatest.OptionValues
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import pl.touk.nussknacker.engine.ModelDependencies
import pl.touk.nussknacker.engine.{ModelDependencies, ProcessingTypeConfig}
import pl.touk.nussknacker.engine.api.component.{ComponentProvider, DesignerWideComponentId, ProcessingMode}
import pl.touk.nussknacker.engine.api.process.ProcessingType
import pl.touk.nussknacker.engine.definition.component.Components.ComponentDefinitionExtractionMode
Expand Down Expand Up @@ -282,19 +284,20 @@ class ScenarioParametersServiceTest

val designerConfig =
DesignerConfig.from(ConfigFactory.parseFile(devApplicationConfFile).withFallback(fallbackConfig))
val processingTypeData = ProcessingTypesConfigBasedProcessingTypeDataLoader
.loadProcessingTypeData(
designerConfig.processingTypeConfigs,
processingType =>
ModelDependencies(
Map.empty,
componentId => DesignerWideComponentId(componentId.toString),
Some(workPath),
shouldIncludeComponentProvider(processingType, _),
ComponentDefinitionExtractionMode.FinalDefinition
),
_ => TestFactory.deploymentManagerDependencies,
)
val processingTypeData =
new ProcessingTypesConfigBasedProcessingTypeDataLoader(() => IO.pure(designerConfig.processingTypeConfigs))
.loadProcessingTypeData(
processingType =>
ModelDependencies(
Map.empty,
componentId => DesignerWideComponentId(componentId.toString),
Some(workPath),
shouldIncludeComponentProvider(processingType, _),
ComponentDefinitionExtractionMode.FinalDefinition
),
_ => TestFactory.deploymentManagerDependencies,
)
.unsafeRunSync()
val parametersService = processingTypeData.getCombined().parametersService

parametersService.scenarioParametersCombinationsWithWritePermission(TestFactory.adminUser()) shouldEqual List(
Expand Down

0 comments on commit 915e4df

Please sign in to comment.