-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NU-1974] Initialize model classloaders only once (#7447)
initialize model classloaders only once
- Loading branch information
Showing
15 changed files
with
255 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...c/main/scala/pl/touk/nussknacker/ui/process/processingtype/ModelClassLoaderProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package pl.touk.nussknacker.ui.process.processingtype | ||
|
||
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap | ||
import pl.touk.nussknacker.engine.util.loader.ModelClassLoader | ||
|
||
import java.nio.file.Path | ||
|
||
final case class ModelClassLoaderDependencies(classpath: List[String], workingDirectoryOpt: Option[Path]) { | ||
|
||
def show(): String = { | ||
val workingDirectoryReadable = workingDirectoryOpt match { | ||
case Some(value) => value.toString | ||
case None => "None (default)" | ||
} | ||
s"classpath: ${classpath.mkString(", ")}, workingDirectoryOpt: $workingDirectoryReadable" | ||
} | ||
|
||
} | ||
|
||
class ModelClassLoaderProvider private ( | ||
processingTypeClassLoaders: Map[String, (ModelClassLoader, ModelClassLoaderDependencies)] | ||
) { | ||
|
||
def forProcessingTypeUnsafe(processingTypeName: String): ModelClassLoader = { | ||
processingTypeClassLoaders | ||
.getOrElse( | ||
processingTypeName, | ||
throw new IllegalArgumentException( | ||
s"Unknown ProcessingType: $processingTypeName, known ProcessingTypes are: ${processingTypeName.mkString(", ")}" | ||
) | ||
) | ||
._1 | ||
} | ||
|
||
def validateReloadConsistency( | ||
dependenciesFromReload: Map[String, ModelClassLoaderDependencies] | ||
): Unit = { | ||
if (dependenciesFromReload.keySet != processingTypeClassLoaders.keySet) { | ||
throw new IllegalStateException( | ||
s"""Processing types cannot be added, removed, or renamed during processing type reload. | ||
|Reloaded processing types: [${dependenciesFromReload.keySet.toList.sorted.mkString(", ")}] | ||
|Current processing types: [${processingTypeClassLoaders.keySet.toList.sorted.mkString(", ")}] | ||
|If you need to modify this, please restart the application with desired config.""".stripMargin | ||
) | ||
} | ||
dependenciesFromReload.foreach { case (processingType, reloadedConfig) => | ||
val currentConfig = processingTypeClassLoaders.mapValuesNow(_._2)(processingType) | ||
if (reloadedConfig != currentConfig) { | ||
throw new IllegalStateException( | ||
s"Error during processing types reload. Model ClassLoader dependencies such as classpath cannot be modified during reload. " + | ||
s"For processing type [$processingType], reloaded ClassLoader dependencies: [${reloadedConfig.show()}] " + | ||
s"do not match current dependencies: [${currentConfig.show()}]" | ||
) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
object ModelClassLoaderProvider { | ||
|
||
def apply(processingTypeConfig: Map[String, ModelClassLoaderDependencies]): ModelClassLoaderProvider = { | ||
val processingTypesClassloaders = processingTypeConfig.map { case (name, deps) => | ||
name -> (ModelClassLoader(deps.classpath, deps.workingDirectoryOpt) -> deps) | ||
} | ||
new ModelClassLoaderProvider(processingTypesClassloaders) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.