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 915e4df commit 7ade2aa
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 61 deletions.
30 changes: 15 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1997,21 +1997,21 @@ lazy val designer = (project in file("designer/server"))
assembly / assemblyMergeStrategy := designerMergeStrategy,
libraryDependencies ++= {
Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
"com.typesafe.akka" %% "akka-slf4j" % akkaV,
"com.typesafe.akka" %% "akka-stream" % akkaV,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaV % Test,
"de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirceV,
"com.softwaremill.sttp.client3" %% "akka-http-backend" % sttpV,
"ch.qos.logback" % "logback-core" % logbackV,
"ch.qos.logback" % "logback-classic" % logbackV,
"ch.qos.logback.contrib" % "logback-json-classic" % logbackJsonV,
"ch.qos.logback.contrib" % "logback-jackson" % logbackJsonV,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonV,
"org.slf4j" % "log4j-over-slf4j" % slf4jV,
"com.carrotsearch" % "java-sizeof" % "0.0.5",
"org.typelevel" %% "case-insensitive" % "1.4.0",
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
"com.typesafe.akka" %% "akka-slf4j" % akkaV,
"com.typesafe.akka" %% "akka-stream" % akkaV,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaV % Test,
"de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirceV,
"com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % sttpV,
"ch.qos.logback" % "logback-core" % logbackV,
"ch.qos.logback" % "logback-classic" % logbackV,
"ch.qos.logback.contrib" % "logback-json-classic" % logbackJsonV,
"ch.qos.logback.contrib" % "logback-jackson" % logbackJsonV,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonV,
"org.slf4j" % "log4j-over-slf4j" % slf4jV,
"com.carrotsearch" % "java-sizeof" % "0.0.5",
"org.typelevel" %% "case-insensitive" % "1.4.0",

// It's needed by flinkDeploymentManager which has disabled includingScala
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package pl.touk.nussknacker.ui.configloader

import cats.effect.IO
import com.typesafe.config.Config
import sttp.client3.SttpBackend

import scala.concurrent.{ExecutionContext, Future}

trait ProcessingTypeConfigsLoaderFactory {

def create(
designerConfigLoadedAtStart: DesignerConfig,
sttpBackend: SttpBackend[Future, Any],
configLoaderConfig: Config,
sttpBackend: SttpBackend[IO, Any],
)(implicit ec: ExecutionContext): ProcessingTypeConfigsLoader

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

Expand Down Expand Up @@ -58,7 +54,7 @@ object LocalNussknackerWithSingleModel {
)
val designerConfigLoader = DesignerConfigLoader.fromConfig(appConfig)
val processingTypeConfigsLoaderFactory = new ProcessingTypeConfigsLoaderFactory {
override def create(designerConfigLoadedAtStart: DesignerConfig, sttpBackend: SttpBackend[Future, Any])(
override def create(configLoaderConfig: Config, sttpBackend: SttpBackend[IO, Any])(
implicit ec: ExecutionContext
): ProcessingTypeConfigsLoader = { () =>
IO.pure(Map.empty)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.touk.nussknacker.ui.configloader
package pl.touk.nussknacker.ui.config

import com.typesafe.config.Config
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,46 @@ package pl.touk.nussknacker.ui.factory
import akka.actor.ActorSystem
import akka.stream.Materializer
import cats.effect.{IO, Resource}
import com.typesafe.config.{Config, ConfigFactory}
import com.typesafe.scalalogging.LazyLogging
import io.dropwizard.metrics5.MetricRegistry
import io.dropwizard.metrics5.jmx.JmxReporter
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.configloader.{
DesignerConfig,
ProcessingTypeConfigsLoader,
ProcessingTypeConfigsLoaderFactory
}
import pl.touk.nussknacker.ui.config.{DesignerConfig, DesignerConfigLoader}
import pl.touk.nussknacker.ui.configloader.{ProcessingTypeConfigsLoader, ProcessingTypeConfigsLoaderFactory}
import pl.touk.nussknacker.ui.db.DbRef
import pl.touk.nussknacker.ui.db.timeseries.questdb.QuestDbFEStatisticsRepository
import pl.touk.nussknacker.ui.process.processingtype.loader.{
ProcessingTypeDataLoader,
ProcessingTypesConfigBasedProcessingTypeDataLoader
}
import pl.touk.nussknacker.ui.server.{AkkaHttpBasedRouteProvider, NussknackerHttpServer}
import pl.touk.nussknacker.ui.util.ActorSystemBasedExecutionContextWithIORuntime
import pl.touk.nussknacker.ui.util.{ActorSystemBasedExecutionContextWithIORuntime, IOToFutureSttpBackendConverter}
import sttp.client3.SttpBackend
import sttp.client3.asynchttpclient.future.AsyncHttpClientFutureBackend
import sttp.client3.asynchttpclient.cats.AsyncHttpClientCatsBackend

import java.time.Clock
import scala.concurrent.Future

class NussknackerAppFactory(
designerConfigLoader: DesignerConfigLoader,
processingTypeConfigsLoaderFactoryOpt: Option[ProcessingTypeConfigsLoaderFactory],
createProcessingTypeDataLoader: ProcessingTypeConfigsLoader => ProcessingTypeDataLoader
) extends LazyLogging {

import net.ceedubs.ficus.Ficus._

def createApp(clock: Clock = Clock.systemUTC()): Resource[IO, Unit] = {
for {
designerConfig <- Resource.eval(designerConfigLoader.loadDesignerConfig())
system <- createActorSystem(designerConfig.rawConfig)
executionContextWithIORuntime = ActorSystemBasedExecutionContextWithIORuntime.createFrom(system)
sttpBackend <- createSttpBackend
ioSttpBackend <- AsyncHttpClientCatsBackend.resource[IO]()
processingTypeConfigsLoader = createProcessingTypeConfigsLoader(
designerConfig,
executionContextWithIORuntime,
sttpBackend
ioSttpBackend
)
processingTypeDataLoader = createProcessingTypeDataLoader(processingTypeConfigsLoader)
materializer = Materializer(system)
Expand All @@ -57,7 +55,7 @@ class NussknackerAppFactory(
new AkkaHttpBasedRouteProvider(
db,
metricsRegistry,
sttpBackend,
IOToFutureSttpBackendConverter.convert(ioSttpBackend)(executionContextWithIORuntime),
processingTypeDataLoader,
feStatisticsRepository,
clock
Expand All @@ -77,15 +75,15 @@ class NussknackerAppFactory(
private def createProcessingTypeConfigsLoader(
designerConfig: DesignerConfig,
executionContextWithIORuntime: ActorSystemBasedExecutionContextWithIORuntime,
sttpBackend: SttpBackend[Future, Any]
sttpBackend: SttpBackend[IO, Any]
): ProcessingTypeConfigsLoader = {
processingTypeConfigsLoaderFactoryOpt
.map { factory =>
logger.debug(
s"Found custom ${classOf[ProcessingTypeConfigsLoaderFactory].getSimpleName}: ${factory.getClass.getName}. Using it for configuration loading"
)
factory.create(
designerConfig,
designerConfig.rawConfig.resolved.getAs[Config]("configLoader").getOrElse(ConfigFactory.empty()),
sttpBackend,
)(executionContextWithIORuntime)
}
Expand All @@ -97,15 +95,6 @@ class NussknackerAppFactory(
}
}

private def createSttpBackend = {
Resource
.make(
acquire = IO(AsyncHttpClientFutureBackend.usingConfigBuilder(identity))
)(
release = backend => IO.fromFuture(IO(backend.close()))
)
}

private def createActorSystem(config: ConfigWithUnresolvedVersion) = {
Resource
.make(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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.configloader.DesignerConfig
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 @@ -28,7 +28,7 @@ import pl.touk.nussknacker.ui.config.{
FeatureTogglesConfig,
UsageStatisticsReportsConfig
}
import pl.touk.nussknacker.ui.configloader.DesignerConfig
import pl.touk.nussknacker.ui.config.DesignerConfig
import pl.touk.nussknacker.ui.db.DbRef
import pl.touk.nussknacker.ui.db.timeseries.FEStatisticsRepository
import pl.touk.nussknacker.ui.definition.component.{ComponentServiceProcessingTypeData, DefaultComponentService}
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.configloader.DesignerConfig
import pl.touk.nussknacker.ui.config.DesignerConfig
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.configloader.DesignerConfig
import pl.touk.nussknacker.ui.config.DesignerConfig

trait RouteProvider[R <: Route] {

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

import cats.arrow.FunctionK
import cats.effect.IO
import sttp.client3.SttpBackend
import sttp.client3.impl.cats.implicits.sttpBackendToCatsMappableSttpBackend
import sttp.monad.FutureMonad

import scala.concurrent.Future

object IOToFutureSttpBackendConverter {

def convert(
ioBackend: SttpBackend[IO, Any]
)(implicit executionContextWithIORuntime: ExecutionContextWithIORuntime): SttpBackend[Future, Any] = {
import executionContextWithIORuntime.ioRuntime
ioBackend.mapK(
new FunctionK[IO, Future] {
override def apply[A](io: IO[A]): Future[A] = io.unsafeToFuture()
},
new FunctionK[Future, IO] {
override def apply[A](future: Future[A]): IO[A] = IO.fromFuture(IO.pure(future))
}
)(new FutureMonad)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,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
import pl.touk.nussknacker.ui.config.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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.scalatest.matchers.should.Matchers
import pl.touk.nussknacker.test.config.ConfigWithScalaVersion
import pl.touk.nussknacker.test.utils.scalas.CatsTestExtensions._
import pl.touk.nussknacker.test.{DefaultUniquePortProvider, WithTestHttpClientCreator}
import pl.touk.nussknacker.ui.configloader.DesignerConfig
import pl.touk.nussknacker.ui.config.DesignerConfig
import pl.touk.nussknacker.ui.security.ssl.HttpsConnectionContextFactory.prepareSSLContext
import pl.touk.nussknacker.ui.security.ssl.KeyStoreConfig
import pl.touk.nussknacker.ui.server.{NussknackerHttpServer, RouteProvider}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.typesafe
import com.typesafe.config.{Config, ConfigFactory}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers.{convertToAnyShouldWrapper, include}
import pl.touk.nussknacker.ui.config.DesignerConfigLoader
import pl.touk.nussknacker.ui.configloader.{DesignerConfig, ProcessingTypeConfigsLoader}
import pl.touk.nussknacker.ui.config.{DesignerConfig, DesignerConfigLoader}
import pl.touk.nussknacker.ui.configloader.ProcessingTypeConfigsLoader

class ProcessingTypeDataLoaderSpec extends AnyFunSuite {

Expand Down Expand Up @@ -117,8 +117,8 @@ class ProcessingTypeDataLoaderSpec extends AnyFunSuite {
processingTypes2.keys.toSet shouldBe Set("streaming", "streaming2")
}

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

private def loadDifferentConfigPerInvocationProcessingTypeConfigsLoader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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, ProcessingTypeConfig}
import pl.touk.nussknacker.engine.ModelDependencies
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 All @@ -18,7 +18,7 @@ import pl.touk.nussknacker.restmodel.scenariodetails.ScenarioParameters
import pl.touk.nussknacker.security.Permission
import pl.touk.nussknacker.test.ValidatedValuesDetailedMessage
import pl.touk.nussknacker.test.utils.domain.TestFactory
import pl.touk.nussknacker.ui.configloader.{DesignerConfig, ProcessingTypeConfigsLoader}
import pl.touk.nussknacker.ui.config.DesignerConfig
import pl.touk.nussknacker.ui.process.processingtype.loader.ProcessingTypesConfigBasedProcessingTypeDataLoader
import pl.touk.nussknacker.ui.security.api.{LoggedUser, RealLoggedUser}

Expand Down

0 comments on commit 7ade2aa

Please sign in to comment.