diff --git a/designer/server/src/main/scala/pl/touk/nussknacker/ui/config/processingtype/EachTimeLoadingDesignerConfigProcessingTypeConfigsLoader.scala b/designer/server/src/main/scala/pl/touk/nussknacker/ui/config/processingtype/EachTimeLoadingDesignerConfigProcessingTypeConfigsLoader.scala deleted file mode 100644 index 0b4888094e5..00000000000 --- a/designer/server/src/main/scala/pl/touk/nussknacker/ui/config/processingtype/EachTimeLoadingDesignerConfigProcessingTypeConfigsLoader.scala +++ /dev/null @@ -1,16 +0,0 @@ -package pl.touk.nussknacker.ui.config.processingtype - -import cats.effect.IO -import pl.touk.nussknacker.engine.ProcessingTypeConfig -import pl.touk.nussknacker.ui.config.DesignerConfigLoader -import pl.touk.nussknacker.ui.configloader.ProcessingTypeConfigsLoader - -class EachTimeLoadingDesignerConfigProcessingTypeConfigsLoader(designerConfigLoader: DesignerConfigLoader) - extends ProcessingTypeConfigsLoader { - - def loadProcessingTypeConfigs(): IO[Map[String, ProcessingTypeConfig]] = - designerConfigLoader - .loadDesignerConfig() - .map(_.processingTypeConfigs) - -} diff --git a/designer/server/src/main/scala/pl/touk/nussknacker/ui/factory/NussknackerAppFactory.scala b/designer/server/src/main/scala/pl/touk/nussknacker/ui/factory/NussknackerAppFactory.scala index affe9579690..18ef675393d 100644 --- a/designer/server/src/main/scala/pl/touk/nussknacker/ui/factory/NussknackerAppFactory.scala +++ b/designer/server/src/main/scala/pl/touk/nussknacker/ui/factory/NussknackerAppFactory.scala @@ -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, @@ -83,7 +78,7 @@ class NussknackerAppFactory( designerConfig: DesignerConfig, executionContextWithIORuntime: ActorSystemBasedExecutionContextWithIORuntime, sttpBackend: SttpBackend[Future, Any] - ) = { + ): ProcessingTypeConfigsLoader = { processingTypeConfigsLoaderFactoryOpt .map { factory => logger.debug( @@ -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) } } diff --git a/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/processingtype/loader/ProcessingTypesConfigBasedProcessingTypeDataLoader.scala b/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/processingtype/loader/ProcessingTypesConfigBasedProcessingTypeDataLoader.scala index e3ee1a24e2b..1d1c57d0df9 100644 --- a/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/processingtype/loader/ProcessingTypesConfigBasedProcessingTypeDataLoader.scala +++ b/designer/server/src/main/scala/pl/touk/nussknacker/ui/process/processingtype/loader/ProcessingTypesConfigBasedProcessingTypeDataLoader.scala @@ -12,7 +12,8 @@ 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, @@ -20,17 +21,10 @@ class ProcessingTypesConfigBasedProcessingTypeDataLoader(processingTypeConfigsLo ): 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 diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala b/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala index 34ca3d00bce..c6711280ae1 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala @@ -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 @@ -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._ @@ -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() ) } diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/ui/config/processingtype/EachTimeLoadingDesignerConfigProcessingTypeConfigsLoaderSpec.scala b/designer/server/src/test/scala/pl/touk/nussknacker/ui/config/processingtype/ProcessingTypeDataLoaderSpec.scala similarity index 92% rename from designer/server/src/test/scala/pl/touk/nussknacker/ui/config/processingtype/EachTimeLoadingDesignerConfigProcessingTypeConfigsLoaderSpec.scala rename to designer/server/src/test/scala/pl/touk/nussknacker/ui/config/processingtype/ProcessingTypeDataLoaderSpec.scala index 170d3f3a922..42dd68337ab 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/ui/config/processingtype/EachTimeLoadingDesignerConfigProcessingTypeConfigsLoaderSpec.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/ui/config/processingtype/ProcessingTypeDataLoaderSpec.scala @@ -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 @@ -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( @@ -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) } } diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/ui/process/processingtype/ScenarioParametersServiceTest.scala b/designer/server/src/test/scala/pl/touk/nussknacker/ui/process/processingtype/ScenarioParametersServiceTest.scala index 5c3915e527d..877d7433de3 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/ui/process/processingtype/ScenarioParametersServiceTest.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/ui/process/processingtype/ScenarioParametersServiceTest.scala @@ -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 @@ -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(