summaryrefslogtreecommitdiffstats
path: root/standalone-container/src/main/scala
diff options
context:
space:
mode:
Diffstat (limited to 'standalone-container/src/main/scala')
-rw-r--r--standalone-container/src/main/scala/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.scala206
-rw-r--r--standalone-container/src/main/scala/com/yahoo/application/container/impl/StandaloneContainerRunner.scala27
-rw-r--r--standalone-container/src/main/scala/com/yahoo/container/standalone/Converter.scala26
-rw-r--r--standalone-container/src/main/scala/com/yahoo/container/standalone/Environment.scala23
-rw-r--r--standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala75
-rw-r--r--standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneContainerApplication.scala231
-rw-r--r--standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneSubscriberFactory.scala81
7 files changed, 0 insertions, 669 deletions
diff --git a/standalone-container/src/main/scala/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.scala b/standalone-container/src/main/scala/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.scala
deleted file mode 100644
index ac8636de2cb..00000000000
--- a/standalone-container/src/main/scala/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.scala
+++ /dev/null
@@ -1,206 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.application.container.impl
-
-import java.io.InputStream
-import java.net.{URL, URLClassLoader}
-import java.util
-import java.util.concurrent.atomic.AtomicInteger
-import java.util.jar.JarFile
-import java.util.{Collections, Dictionary, Hashtable}
-
-import com.yahoo.container.standalone.StandaloneContainerApplication
-import com.yahoo.jdisc.application.{OsgiFramework, OsgiHeader}
-import org.osgi.framework._
-import org.osgi.framework.wiring._
-import org.osgi.resource.{Capability, Requirement, Wire}
-
-import scala.collection.JavaConverters._
-import scala.collection.mutable.ArrayBuffer
-
-/**
- * A (mock) OSGI implementation which loads classes from the system classpath
- *
- * @author tonytv
- */
-final class ClassLoaderOsgiFramework extends OsgiFramework {
- private val bundleLocations = new ArrayBuffer[URL]
- private val bundleList = ArrayBuffer[Bundle](SystemBundleImpl)
- private var classLoader: ClassLoader = null
-
- private val nextBundleId = new AtomicInteger(1)
-
- override def installBundle(bundleLocation: String) = {
- if (bundleLocation != "") {
- val url = new URL(bundleLocation)
- bundleLocations += url
- bundleList += new JarBundleImpl(url)
- }
-
- bundles()
- }
-
- def getClassLoader = {
- if (bundleLocations.isEmpty) {
- getClass.getClassLoader
- } else {
- if(classLoader == null)
- classLoader = new URLClassLoader(bundleLocations.toArray, getClass.getClassLoader)
-
- classLoader
- }
- }
-
- override def startBundles(bundles: util.List[Bundle], privileged: Boolean) {}
-
- override def refreshPackages() {}
-
- override def bundleContext():BundleContext = BundleContextImpl
-
- override def bundles() = bundleList.asJava
-
- override def start() {}
-
- override def stop() {}
-
- private abstract class BundleImpl extends Bundle {
- override def getState = Bundle.ACTIVE
-
- override def start(options: Int) {}
- override def start() {}
- override def stop(options: Int) {}
- override def stop() {}
- override def update(input: InputStream) {}
- override def update() {}
- override def uninstall() {}
-
- override def getHeaders(locale: String) = getHeaders
-
- override def getSymbolicName = ClassLoaderOsgiFramework.this.getClass.getName
- override def getLocation = getSymbolicName
-
- override def getRegisteredServices = Array[ServiceReference[_]]()
- override def getServicesInUse = getRegisteredServices
-
- override def hasPermission(permission: Any) = true
-
- override def getResource(name: String) = getClassLoader.getResource(name)
- override def loadClass(name: String) = getClassLoader.loadClass(name)
- override def getResources(name: String) = getClassLoader.getResources(name)
-
- override def getEntryPaths(path: String) = throw new UnsupportedOperationException
- override def getEntry(path: String) = throw new UnsupportedOperationException
- override def findEntries(path: String, filePattern: String, recurse: Boolean) = throw new UnsupportedOperationException
-
- override def getLastModified = 1L
-
- override def getBundleContext = throw new UnsupportedOperationException
- override def getSignerCertificates(signersType: Int) = Collections.emptyMap()
-
- override def adapt[A](`type`: Class[A]): A = {
- if (`type` == classOf[BundleRevision]) BundleRevisionImpl.asInstanceOf[A]
- else if (`type` == classOf[BundleWiring]) BundleWiringImpl.asInstanceOf[A]
- else null.asInstanceOf[A]
- }
-
- override def getDataFile(filename: String) = null
- override def compareTo(o: Bundle) = getBundleId compareTo o.getBundleId
- }
-
- private object BundleRevisionImpl extends BundleRevision {
- override def getSymbolicName: String = this.getClass.getName
- override def getDeclaredRequirements(p1: String): util.List[BundleRequirement] = throw new UnsupportedOperationException
- override def getVersion: Version = Version.emptyVersion
- override def getWiring: BundleWiring = BundleWiringImpl
- override def getDeclaredCapabilities(p1: String): util.List[BundleCapability] = throw new UnsupportedOperationException
- override def getTypes: Int = 0
- override def getBundle: Bundle = throw new UnsupportedOperationException
- override def getCapabilities(p1: String): util.List[Capability] = throw new UnsupportedOperationException
- override def getRequirements(p1: String): util.List[Requirement] = throw new UnsupportedOperationException
- }
-
- private object BundleWiringImpl extends BundleWiring {
- override def findEntries(p1: String, p2: String, p3: Int): util.List[URL] = ???
- override def getRequiredResourceWires(p1: String): util.List[Wire] = ???
- override def getResourceCapabilities(p1: String): util.List[Capability] = ???
- override def isCurrent: Boolean = ???
- override def getRequiredWires(p1: String): util.List[BundleWire] = ???
- override def getCapabilities(p1: String): util.List[BundleCapability] = ???
- override def getProvidedResourceWires(p1: String): util.List[Wire] = ???
- override def getProvidedWires(p1: String): util.List[BundleWire] = ???
- override def getRevision: BundleRevision = ???
- override def getResourceRequirements(p1: String): util.List[Requirement] = ???
- override def isInUse: Boolean = ???
- override def listResources(p1: String, p2: String, p3: Int): util.Collection[String] = ???
- override def getClassLoader: ClassLoader = ClassLoaderOsgiFramework.this.getClassLoader
- override def getRequirements(p1: String): util.List[BundleRequirement] = ???
- override def getResource: BundleRevision = ???
- override def getBundle: Bundle = ???
- }
-
- private object SystemBundleImpl extends BundleImpl {
- override val getBundleId = 0L
- override def getVersion = Version.emptyVersion
- override def getHeaders: Dictionary[String, String] = new Hashtable[String, String](Map(OsgiHeader.APPLICATION -> classOf[StandaloneContainerApplication].getName).asJava)
- }
-
-
- private class JarBundleImpl(location: URL) extends BundleImpl {
- override val getBundleId = nextBundleId.getAndIncrement.asInstanceOf[Long]
-
- private val headers = retrieveHeaders(location)
-
- override def getHeaders: Dictionary[String, String] = headers
- override val getSymbolicName = headers.get("Bundle-SymbolicName")
- override val getVersion = Version.parseVersion(headers.get("Bundle-Version"))
-
-
- private def retrieveHeaders(location: URL) = {
- val jarFile = new JarFile(location.getFile)
- try {
- val attributes = jarFile.getManifest.getMainAttributes
- new Hashtable[String, String](attributes.entrySet().asScala.map( entry => entry.getKey.toString -> entry.getValue.toString).toMap.asJava)
- } finally {
- jarFile.close()
- }
- }
- }
-
- private object BundleContextImpl extends BundleContext {
- private val bundleImpl = SystemBundleImpl
-
- override def getProperty(key: String) = null
- override def getBundle = bundleImpl
- override def installBundle(location: String, input: InputStream) = throw new UnsupportedOperationException
- override def installBundle(location: String) = throw new UnsupportedOperationException
-
- override def getBundle(id: Long) = bundleImpl
- override def getBundles = Array(bundleImpl)
- override def getBundle(location: String) = bundleImpl
-
- override def addServiceListener(listener: ServiceListener, filter: String) {}
- override def addServiceListener(listener: ServiceListener) {}
- override def removeServiceListener(listener: ServiceListener) {}
- override def addBundleListener(listener: BundleListener) {}
- override def removeBundleListener(listener: BundleListener) {}
-
- override def addFrameworkListener(listener: FrameworkListener) {}
- override def removeFrameworkListener(listener: FrameworkListener) {}
-
- override def registerService(clazzes: Array[String], service: Any, properties: Dictionary[String, _]) = throw new UnsupportedOperationException
- override def registerService(clazz: String, service: Any, properties: Dictionary[String, _]) = null
- override def registerService[S](clazz: Class[S], service: S, properties: Dictionary[String, _]) = throw new UnsupportedOperationException
- override def getServiceReferences(clazz: String, filter: String) = throw new UnsupportedOperationException
- override def getAllServiceReferences(clazz: String, filter: String) = throw new UnsupportedOperationException
- override def getServiceReference(clazz: String) = throw new UnsupportedOperationException
- override def getServiceReference[S](clazz: Class[S]) = throw new UnsupportedOperationException
- override def getServiceReferences[S](clazz: Class[S], filter: String) = Collections.emptyList()
- override def getService[S](reference: ServiceReference[S]) = throw new UnsupportedOperationException
- override def ungetService(reference: ServiceReference[_]) = throw new UnsupportedOperationException
- override def getDataFile(filename: String) = throw new UnsupportedOperationException
- override def createFilter(filter: String) = throw new UnsupportedOperationException
-
- override def registerService[S](aClass: Class[S], serviceFactory: ServiceFactory[S], dictionary: Dictionary[String, _]): ServiceRegistration[S] = throw new UnsupportedOperationException
- override def getServiceObjects[S](serviceReference: ServiceReference[S]): ServiceObjects[S] = throw new UnsupportedOperationException
- }
-
-}
diff --git a/standalone-container/src/main/scala/com/yahoo/application/container/impl/StandaloneContainerRunner.scala b/standalone-container/src/main/scala/com/yahoo/application/container/impl/StandaloneContainerRunner.scala
deleted file mode 100644
index 91634250fc5..00000000000
--- a/standalone-container/src/main/scala/com/yahoo/application/container/impl/StandaloneContainerRunner.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.application.container.impl
-
-import java.nio.file.Files
-import com.yahoo.text.Utf8
-
-/**
- * @author tonytv
- */
-final class StandaloneContainerRunner {
-
-
-
-}
-
-object StandaloneContainerRunner {
- def createApplicationPackage(servicesXml: String) = {
- val applicationDir = Files.createTempDirectory("application")
-
- val servicesXmlFile = applicationDir.resolve("services.xml");
- var content = servicesXml;
- if ( ! servicesXml.startsWith("<?xml"))
- content = """<?xml version="1.0" encoding="utf-8" ?>""" + '\n' + servicesXml
- Files.write(servicesXmlFile, Utf8.toBytes(content))
- applicationDir
- }
-}
diff --git a/standalone-container/src/main/scala/com/yahoo/container/standalone/Converter.scala b/standalone-container/src/main/scala/com/yahoo/container/standalone/Converter.scala
deleted file mode 100644
index 61128347319..00000000000
--- a/standalone-container/src/main/scala/com/yahoo/container/standalone/Converter.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.container.standalone
-
-/**
- * @author tonytv
- */
-trait Converter[T] {
- def convert(s: String): T
-}
-
-object Converter {
- def toConverter[T](f: String => T) = new Converter[T] {
- override def convert(s: String) = f(s)
- }
-
- implicit val intConverter = toConverter(_.toInt)
- implicit val longConverter = toConverter(_.toLong)
- implicit val boolConverter = toConverter(_.toBoolean)
- implicit val stringConverter = toConverter(identity)
-
- implicit val javaIntegerConverter:Converter[Integer] = toConverter(_.toInt)
- implicit val javaLongConverter:Converter[java.lang.Long] = toConverter(_.toLong)
- implicit val javaBooleanConverter:Converter[java.lang.Boolean] = toConverter(_.toBoolean)
-
-
-}
diff --git a/standalone-container/src/main/scala/com/yahoo/container/standalone/Environment.scala b/standalone-container/src/main/scala/com/yahoo/container/standalone/Environment.scala
deleted file mode 100644
index 2aab88d8319..00000000000
--- a/standalone-container/src/main/scala/com/yahoo/container/standalone/Environment.scala
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.container.standalone
-
-/**
- * @author tonytv
- * TODO: copied from standalone-container. Move to separate lib module instead.
- */
-object Environment {
- def optionalInstallVariable(name: String) = {
- env(name.replace(".", "__")).
- orElse(systemProperty(name)) //for unit testing
- }
-
- def installVariable(name: String) = {
- optionalInstallVariable(name).
- getOrElse {
- throw new IllegalStateException("Environment variable not set: " + name)
- }
- }
-
- def env(name: String) = Option(System.getenv(name))
- def systemProperty(name: String) = Option(System.getProperty(name))
-}
diff --git a/standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala b/standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala
deleted file mode 100644
index 6507b4c72f0..00000000000
--- a/standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.container.standalone
-
-import java.io.File
-import java.lang.reflect.Constructor
-import java.nio.file.Path
-import java.util
-import java.util.concurrent.TimeUnit
-
-import com.yahoo.config.FileReference
-import com.yahoo.config.application.api.FileRegistry
-import com.yahoo.config.application.api.FileRegistry.Entry
-import com.yahoo.container.standalone.LocalFileDb._
-import com.yahoo.filedistribution.fileacquirer.FileAcquirer
-import com.yahoo.net.HostName
-
-import scala.collection.JavaConverters._
-import scala.collection.mutable
-
-
-/**
- * FileAcquirer and FileRegistry working on a local directory.
- * @author tonytv
- */
-class LocalFileDb(appPath: Path) extends FileAcquirer with FileRegistry {
- private val fileReferenceToFile = mutable.Map[FileReference, File]()
-
- /** *** FileAcquirer overrides *****/
- def waitFor(reference: FileReference, l: Long, timeUnit: TimeUnit): File = {
- synchronized {
- fileReferenceToFile.get(reference).getOrElse {
- throw new RuntimeException("Invalid file reference " + reference)
- }
- }
- }
-
- override def shutdown() {}
-
- /** *** FileRegistry overrides *****/
- def addFile(relativePath: String): FileReference = {
- val file = appPath.resolve(relativePath).toFile
- if (!file.exists) {
- throw new RuntimeException("The file does not exist: " + file.getPath)
- }
-
- val fileReference: FileReference = fileReferenceConstructor.newInstance("LocalFileDb:" + relativePath)
- fileReferenceToFile.put(fileReference, file)
- fileReference
- }
-
- def fileSourceHost: String =
- HostName.getLocalhost
-
- def allRelativePaths: java.util.Set[String] = {
- new java.util.HashSet(fileReferenceToFile.values.map(_.getPath).asJavaCollection)
- }
-
- override def export(): util.List[Entry] = {
- new java.util.ArrayList(fileReferenceToFile.keys.map{ (ref: FileReference) => new Entry(fileReferenceToFile.get(ref).get.getPath, ref)}.asJavaCollection)
- }
-
- override def addUri(uri: String): FileReference = {
- throw new RuntimeException("addUri(uri: String) is not implemented here.");
- }
-}
-
-object LocalFileDb {
- private def createFileReferenceConstructor: Constructor[FileReference] = {
- val method: Constructor[FileReference] = classOf[FileReference].getDeclaredConstructor(classOf[String])
- method.setAccessible(true)
- method
- }
-
- private val fileReferenceConstructor: Constructor[FileReference] = createFileReferenceConstructor
-}
diff --git a/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneContainerApplication.scala b/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneContainerApplication.scala
deleted file mode 100644
index 5271cd400d4..00000000000
--- a/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneContainerApplication.scala
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.container.standalone
-
-import java.io.{File, IOException}
-import java.lang.{Boolean => JBoolean}
-import java.nio.file.{FileSystems, Files, Path, Paths}
-
-import com.google.inject.name.Names
-import com.google.inject.{AbstractModule, Inject, Injector, Key}
-import com.yahoo.collections.CollectionUtil.first
-import com.yahoo.config.application.api.{ApplicationPackage, FileRegistry}
-import com.yahoo.config.model.application.provider._
-import com.yahoo.config.model.builder.xml.XmlHelper
-import com.yahoo.config.model.deploy.DeployState
-import com.yahoo.config.model.{ApplicationConfigProducerRoot, ConfigModelRepo}
-import com.yahoo.config.provision.Zone
-import com.yahoo.container.di.config.SubscriberFactory
-import com.yahoo.container.jdisc.ConfiguredApplication
-import com.yahoo.container.standalone.Environment._
-import com.yahoo.container.standalone.StandaloneContainerApplication._
-import com.yahoo.io.IOUtils
-import com.yahoo.jdisc.application.Application
-import com.yahoo.text.XML
-import com.yahoo.vespa.defaults.Defaults
-import com.yahoo.vespa.model.VespaModel
-import com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder
-import com.yahoo.vespa.model.container.{Container, ContainerModel}
-import com.yahoo.vespa.model.container.xml.ContainerModelBuilder.Networking
-import com.yahoo.vespa.model.container.xml.{ConfigServerContainerModelBuilder, ContainerModelBuilder}
-import org.w3c.dom.Element
-
-import scala.collection.JavaConverters._
-import scala.util.Try
-
-/**
- * @author Tony Vaagenes
- * @author gjoranv
- */
-class StandaloneContainerApplication @Inject()(injector: Injector) extends Application {
-
- ConfiguredApplication.ensureVespaLoggingInitialized()
-
- val applicationPath: Path = injectedApplicationPath.getOrElse(installApplicationPath)
-
- val distributedFiles = new LocalFileDb(applicationPath)
-
- val configModelRepo = Try { injector.getInstance(Key.get(classOf[ConfigModelRepo], configModelRepoName))}.getOrElse(new ConfigModelRepo)
-
- val networkingOption = Try {
- injector.getInstance(Key.get(classOf[JBoolean], Names.named(disableNetworkingAnnotation)))
- }.map {
- case JBoolean.TRUE => Networking.disable
- case JBoolean.FALSE => Networking.enable
- }.getOrElse(Networking.enable)
-
- val (modelRoot, container) = withTempDir(
- preprocessedApplicationDir => createContainerModel(applicationPath, distributedFiles, preprocessedApplicationDir, networkingOption, configModelRepo))
-
- val configuredApplication = createConfiguredApplication(container)
-
- def createConfiguredApplication(container: Container): Application = {
- val augmentedInjector = injector.createChildInjector(new AbstractModule {
- def configure() {
- bind(classOf[SubscriberFactory]).toInstance(new StandaloneSubscriberFactory(modelRoot))
- }
- })
-
- System.setProperty("config.id", container.getConfigId) //TODO: DRY
- augmentedInjector.getInstance(classOf[ConfiguredApplication])
- }
-
- def injectedApplicationPath = Try {
- injector.getInstance(Key.get(classOf[Path], applicationPathName))
- }.toOption
-
- def installApplicationPath = path(installVariable(applicationLocationInstallVariable))
-
- override def start() {
- try {
- com.yahoo.container.Container.get().setCustomFileAcquirer(distributedFiles)
- configuredApplication.start()
- }
- catch {
- case e: Exception => { com.yahoo.container.Container.resetInstance(); throw e; }
- }
- }
-
- override def stop() {
- configuredApplication.stop()
- }
-
- override def destroy() {
- com.yahoo.container.Container.resetInstance()
- configuredApplication.destroy()
- }
-}
-
-object StandaloneContainerApplication {
- val packageName = "standalone_jdisc_container"
- val applicationLocationInstallVariable = s"$packageName.app_location"
- val deploymentProfileInstallVariable = s"$packageName.deployment_profile"
-
- val applicationPathName = Names.named(applicationLocationInstallVariable)
-
- val disableNetworkingAnnotation = "JDisc.disableNetworking"
- val configModelRepoName = Names.named("ConfigModelRepo")
- val configDefinitionRepo = new StaticConfigDefinitionRepo()
-
- val defaultTmpBaseDir = Defaults.getDefaults().underVespaHome("tmp")
- val tmpDirName = "standalone_container"
-
- private def withTempDir[T](f: File => T): T = {
- val tmpDir = createTempDir()
- try {
- f(tmpDir)
- } finally {
- IOUtils.recursiveDeleteDir(tmpDir)
- }
- }
-
- private def createTempDir(): File = {
- def getBaseDir: Path = {
- val tmpBaseDir =
- if (new File(defaultTmpBaseDir).exists())
- defaultTmpBaseDir
- else
- System.getProperty("java.io.tmpdir")
-
- Paths.get(tmpBaseDir)
- }
-
- val basePath: Path = getBaseDir
- val tmpDir = Files.createTempDirectory(basePath, tmpDirName)
- tmpDir.toFile
- }
-
- private def validateApplication(applicationPackage: ApplicationPackage) = {
- try {
- applicationPackage.validateXML()
- } catch {
- case e: IOException => throw new IllegalArgumentException(e)
- }
- }
-
- def newContainerModelBuilder(networkingOption: Networking): ContainerModelBuilder = {
- optionalInstallVariable(deploymentProfileInstallVariable) match {
- case None => new ContainerModelBuilder(true, networkingOption)
- case Some("configserver") => new ConfigServerContainerModelBuilder(new CloudConfigInstallVariables)
- case profileName => throw new RuntimeException(s"Invalid deployment profile '$profileName'")
- }
- }
-
- def createContainerModel(applicationPath: Path,
- fileRegistry: FileRegistry,
- preprocessedApplicationDir: File,
- networkingOption: Networking,
- configModelRepo: ConfigModelRepo = new ConfigModelRepo): (VespaModel, Container) = {
- val logger = new BaseDeployLogger
- val rawApplicationPackage = new FilesApplicationPackage.Builder(applicationPath.toFile).includeSourceFiles(true).preprocessedDir(preprocessedApplicationDir).build()
- val applicationPackage = rawApplicationPackage.preprocess(Zone.defaultZone(), logger)
- validateApplication(applicationPackage)
- val deployState = new DeployState.Builder().
- applicationPackage(applicationPackage).
- fileRegistry(fileRegistry).
- deployLogger(logger).
- configDefinitionRepo(configDefinitionRepo).
- build(true)
-
- val root = VespaModel.createIncomplete(deployState)
- val vespaRoot = new ApplicationConfigProducerRoot(root,
- "vespa",
- deployState.getDocumentModel,
- deployState.getProperties.vespaVersion(),
- deployState.getProperties.applicationId())
-
- val spec = containerRootElement(applicationPackage)
- val containerModel = newContainerModelBuilder(networkingOption).build(deployState, configModelRepo, vespaRoot, spec)
- containerModel.getCluster().prepare()
- DeprecationSuppressor.initializeContainerModel(containerModel, configModelRepo)
- val container = first(containerModel.getCluster().getContainers)
-
- // TODO: Separate out model finalization from the VespaModel constructor,
- // such that the above and below code to finalize the container can be
- // replaced by root.finalize();
-
- initializeContainer(container, spec)
-
- root.freezeModelTopology()
- (root, container)
- }
-
- def initializeContainer(container: Container, spec: Element) {
- val host = container.getRoot.getHostSystem.getHost(Container.SINGLENODE_CONTAINER_SERVICESPEC)
-
- container.setBasePort(VespaDomBuilder.getXmlWantedPort(spec))
- container.setHostResource(host)
- container.initService()
- }
-
- def getJDiscInServices(element: Element): Element = {
- def nameAndId(elements: List[Element]): List[String] = {
- elements map { e => s"${e.getNodeName} id='${e.getAttribute("id")}'" }
- }
-
- val jDiscElements = ContainerModelBuilder.configModelIds.asScala flatMap { name => XML.getChildren(element, name.getName).asScala }
- jDiscElements.toList match {
- case List(e) => e
- case Nil => throw new RuntimeException("No jdisc element found under services.")
- case multipleElements: List[Element] => throw new RuntimeException("Found multiple JDisc elements: " + nameAndId(multipleElements).mkString(", "))
- }
- }
-
- def containerRootElement(applicationPackage: ApplicationPackage) : Element = {
- val element = XmlHelper.getDocument(applicationPackage.getServices).getDocumentElement
- val nodeName = element.getNodeName
-
- if (ContainerModelBuilder.configModelIds.asScala.map(_.getName).contains(nodeName)) element
- else getJDiscInServices(element)
- }
-
- def path(s: String) = FileSystems.getDefault.getPath(s)
-
- // Ugly hack required since Scala cannot suppress warnings. https://issues.scala-lang.org/browse/SI-7934
- private object DeprecationSuppressor extends DeprecationSuppressor
- @deprecated("", "")
- private class DeprecationSuppressor {
- def initializeContainerModel(containerModel: ContainerModel, configModelRepo: ConfigModelRepo): Unit = {
- containerModel.initialize(configModelRepo)
- }
- }
-}
diff --git a/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneSubscriberFactory.scala b/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneSubscriberFactory.scala
deleted file mode 100644
index 1bc95f52313..00000000000
--- a/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneSubscriberFactory.scala
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.container.standalone
-
-import com.yahoo.config.{ConfigBuilder, ConfigInstance}
-import com.yahoo.container.di.ConfigKeyT
-import com.yahoo.container.di.config.{Subscriber, SubscriberFactory}
-import com.yahoo.container.standalone.StandaloneSubscriberFactory._
-import com.yahoo.vespa.config.ConfigKey
-import com.yahoo.vespa.model.VespaModel
-
-import scala.collection.JavaConverters._
-
-/**
- * @author tonytv
- * @author gjoranv
- */
-class StandaloneSubscriberFactory(root: VespaModel) extends SubscriberFactory {
- class StandaloneSubscriber(configKeys: Set[ConfigKeyT]) extends Subscriber {
- override def configChanged =
- generation == 0
-
- override def close() {}
-
- override def internalRedeploy() = { false }
-
- override def config = {
-
- def getConfig(key: ConfigKeyT) = {
- val builderWithModelConfig = root.getConfig(newBuilderInstance(key), key.getConfigId)
-
- require(builderWithModelConfig != null, "Invalid config id " + key.getConfigId )
- (key.asInstanceOf[ConfigKey[ConfigInstance]], newConfigInstance(builderWithModelConfig))
- }
-
- (configKeys map getConfig).toMap.asJava
- }
-
- override def waitNextGeneration() = {
- generation += 1
-
- if (generation != 0) {
- while (!Thread.interrupted())
- Thread.sleep(10000)
- }
-
- generation
- }
-
- //if waitNextGeneration has not yet been called, -1 should be returned
- var generation = -1L
-
- }
-
- override def getSubscriber(configKeys: java.util.Set[_ <: ConfigKey[_]]) =
- new StandaloneSubscriber(configKeys.asScala.toSet.asInstanceOf[Set[ConfigKeyT]])
-
- def reloadActiveSubscribers(generation: Long) {
- throw new RuntimeException("unsupported")
- }
-}
-
-object StandaloneSubscriberFactory {
-
- private def newBuilderInstance(key: ConfigKeyT) =
- builderClass(key).getDeclaredConstructor().newInstance()
-
- private def builderClass(key: ConfigKeyT) = {
- val nestedClasses = key.getConfigClass.getClasses
- nestedClasses.
- filter {_.getName.equals(key.getConfigClass.getName + "$Builder")}.
- head.
- asInstanceOf[Class[ConfigInstance.Builder]]
- }
-
- private def newConfigInstance(builder: ConfigBuilder) =
- configClass(builder).getConstructor(builder.getClass).newInstance(builder)
-
- private def configClass(builder: ConfigBuilder) =
- builder.getClass.getEnclosingClass.asInstanceOf[Class[ConfigInstance]]
-
-}