Repository: brooklyn-server Updated Branches: refs/heads/master 06c9f621c -> a26e8f569
BROOKLYN-532: karaf separate mgmt init and start Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/6a37ead3 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/6a37ead3 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/6a37ead3 Branch: refs/heads/master Commit: 6a37ead3f16ee8e372482c430eb3698068f120aa Parents: 06c9f62 Author: Aled Sage <[email protected]> Authored: Mon Sep 11 15:00:21 2017 +0100 Committer: Aled Sage <[email protected]> Committed: Mon Sep 11 16:05:27 2017 +0100 ---------------------------------------------------------------------- .../internal/AbstractManagementContext.java | 2 +- karaf/features/src/main/feature/feature.xml | 1 + .../brooklyn/launcher/osgi/OsgiLauncher.java | 259 ++++--------------- .../launcher/osgi/OsgiLauncherImpl.java | 225 ++++++++++++++++ .../resources/OSGI-INF/blueprint/blueprint.xml | 12 +- karaf/pom.xml | 1 + karaf/start/pom.xml | 75 ++++++ .../osgi/start/OsgiLauncherCompleter.java | 42 +++ .../resources/OSGI-INF/blueprint/blueprint.xml | 36 +++ .../brooklyn/launcher/common/BasicLauncher.java | 35 ++- 10 files changed, 476 insertions(+), 212 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java index b04cea4..322d60e 100644 --- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java +++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java @@ -162,7 +162,7 @@ public abstract class AbstractManagementContext implements ManagementContextInte protected final List<Throwable> errors = Collections.synchronizedList(MutableList.<Throwable>of()); protected Maybe<URI> uri = Maybe.absent(); - protected CatalogInitialization catalogInitialization; + private CatalogInitialization catalogInitialization; public AbstractManagementContext(BrooklynProperties brooklynProperties) { this.managementNodeId = Strings.makeRandomId(8); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/karaf/features/src/main/feature/feature.xml ---------------------------------------------------------------------- diff --git a/karaf/features/src/main/feature/feature.xml b/karaf/features/src/main/feature/feature.xml index 39d74b7..4878ef5 100644 --- a/karaf/features/src/main/feature/feature.xml +++ b/karaf/features/src/main/feature/feature.xml @@ -341,6 +341,7 @@ <feature>brooklyn-container-service</feature> <bundle dependency="true">mvn:org.apache.brooklyn/brooklyn-launcher-common/${project.version}</bundle> <bundle start-level="90">mvn:org.apache.brooklyn/brooklyn-karaf-init/${project.version}</bundle> + <bundle start-level="90">mvn:org.apache.brooklyn/brooklyn-karaf-start/${project.version}</bundle> </feature> </features> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncher.java ---------------------------------------------------------------------- diff --git a/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncher.java b/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncher.java index 20e20fe..6c5794c 100644 --- a/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncher.java +++ b/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncher.java @@ -1,214 +1,63 @@ /* - * Copyright 2016 The Apache Software Foundation. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.brooklyn.launcher.osgi; -import com.google.common.base.Stopwatch; -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode; -import org.apache.brooklyn.core.BrooklynVersionService; -import org.apache.brooklyn.core.catalog.internal.CatalogInitialization; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.internal.BrooklynShutdownHooks; -import org.apache.brooklyn.core.mgmt.persist.PersistMode; -import org.apache.brooklyn.launcher.common.BasicLauncher; -import org.apache.brooklyn.launcher.common.BrooklynPropertiesFactoryHelper; -import org.apache.brooklyn.rest.BrooklynWebConfig; -import org.apache.brooklyn.rest.security.provider.BrooklynUserWithRandomPasswordSecurityProvider; -import org.apache.brooklyn.util.exceptions.Exceptions; -import org.apache.brooklyn.util.javalang.Threads; -import org.apache.brooklyn.util.text.Strings; -import org.apache.brooklyn.util.time.Duration; -import org.osgi.framework.Constants; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.service.cm.Configuration; -import org.osgi.service.cm.ConfigurationAdmin; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.util.Map; - /** - * Initializer for brooklyn-core when running in an OSGi environment. + * For use in Karaf, Brooklyn Launcher's startup is split into two parts: + * <ol> + * <li>Part one (by {@code brooklyn-karaf-init}) creates the management context etc, + * and advertises the {@link OsgiLauncher} as a service. + * <li>Part two (by {@code brooklyn-karaf-start}) actually starts things up (binding to + * persisted state, etc). + * + * </ol> + * + * This separation allows the other bundles, such as the {@code brooklyn-rest-resources}, to + * satisfy their dependencies earlier and thus to start up. + * + * This gives us the same behaviour as we have in classic, where the web-apps would be + * started in the middle of {@link org.apache.brooklyn.launcher.common.BasicLauncher#start()}, + * in the overridden {@link org.apache.brooklyn.launcher.common.BasicLauncher#startingUp()}. + * + * The web-console can thus show "starting", and the rest-api respond, when rebind() is taking + * a long time. */ -public class OsgiLauncher extends BasicLauncher<OsgiLauncher> { - - private static final Logger LOG = LoggerFactory.getLogger(OsgiLauncher.class); - public static final String BROOKLYN_CONFIG_PID = "brooklyn"; - - private Object reloadLock = new Object(); - - private BrooklynVersionService brooklynVersion; - - private String globalBrooklynProperties; - private String localBrooklynProperties; - private String defaultCatalogLocation; - - private ConfigurationAdmin configAdmin; - private ConfigSupplier configSupplier; - - - @Override - public OsgiLauncher start() { - // make sure brooklyn-core bundle is started - brooklynVersion.getVersion(); - - Configuration brooklynConfig = getConfiguration(configAdmin, BROOKLYN_CONFIG_PID); - // Note that this doesn't check whether the files exist, just that there are potential alternative sources for configuration. - if (brooklynConfig == null && Strings.isEmpty(globalBrooklynProperties) && Strings.isEmpty(localBrooklynProperties)) { - LOG.warn("Config Admin PID '" + BROOKLYN_CONFIG_PID + "' not found, not using external configuration. Create a brooklyn.cfg file in etc folder."); - } - configSupplier = new ConfigSupplier(brooklynConfig); - BrooklynPropertiesFactoryHelper helper = new BrooklynPropertiesFactoryHelper( - globalBrooklynProperties, localBrooklynProperties, configSupplier); - setBrooklynPropertiesBuilder(helper.createPropertiesBuilder()); - return super.start(); - } - - private Configuration getConfiguration(ConfigurationAdmin configAdmin, String brooklynConfigPid) { - String filter = '(' + Constants.SERVICE_PID + '=' + brooklynConfigPid + ')'; - Configuration[] configs; - try { - configs = configAdmin.listConfigurations(filter); - } catch (InvalidSyntaxException | IOException e) { - throw Exceptions.propagate(e); - } - if (configs != null && configs.length > 0) { - return configs[0]; - } else { - return null; - } - } - - // Called by blueprint container - // init-method can't find the start method for some reason, provide an alternative - public void init() { - synchronized (reloadLock) { - final Stopwatch startupTimer = Stopwatch.createStarted(); - BrooklynShutdownHooks.resetShutdownFlag(); - LOG.debug("OsgiLauncher init, catalog "+defaultCatalogLocation); - catalogInitialization(new CatalogInitialization(String.format("file:%s", defaultCatalogLocation), false, null, false)); - start(); - startupTimer.stop(); - LOG.info("Brooklyn initialisation complete after {}", startupTimer.toString()); - } - } - - // Called by blueprint container - public void destroy() { - LOG.debug("Notified of system shutdown, calling shutdown hooks"); - Threads.runShutdownHooks(); - } - - @Override - protected void startingUp() { - super.startingUp(); - ManagementContext managementContext = getManagementContext(); - BrooklynProperties brooklynProperties = (BrooklynProperties) managementContext.getConfig(); - if (BrooklynWebConfig.hasNoSecurityOptions(brooklynProperties)) { - LOG.info("No security provider options specified. Define a security provider or users to prevent a random password being created and logged."); - // Deprecated in 0.11.0. Add to release notes and remove in next release. - brooklynProperties.put( - BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, - new BrooklynUserWithRandomPasswordSecurityProvider(managementContext)); - managementContext.getScratchpad().put( - BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, - new BrooklynUserWithRandomPasswordSecurityProvider(managementContext)); - } - } - - public void updateProperties(Map<?, ?> props) { - synchronized (reloadLock) { - LOG.info("Updating brooklyn config because of config admin changes."); - configSupplier.update(props); - getManagementContext().reloadBrooklynProperties(); - } - } - - public void setBrooklynVersion(BrooklynVersionService brooklynVersion) { - this.brooklynVersion = brooklynVersion; - } - - public void setPersistenceLocation(@Nullable String persistenceLocationSpec) { - persistenceLocation(persistenceLocationSpec); - } - - - public void setBrooklynProperties(BrooklynProperties brooklynProperties) { - brooklynProperties(brooklynProperties); - } - - public void setIgnorePersistenceErrors(boolean ignorePersistenceErrors) { - ignorePersistenceErrors(ignorePersistenceErrors); - } - - public void setIgnoreCatalogErrors(boolean ignoreCatalogErrors) { - ignoreCatalogErrors(ignoreCatalogErrors); - } - - public void setIgnoreAppErrors(boolean ignoreAppErrors) { - ignoreAppErrors(ignoreAppErrors); - } - - public void setPersistMode(PersistMode persistMode) { - persistMode(persistMode); - } - - public void setHighAvailabilityMode(HighAvailabilityMode highAvailabilityMode) { - highAvailabilityMode(highAvailabilityMode); - } - - public void setPersistenceDir(@Nullable String persistenceDir) { - persistenceDir(persistenceDir); - } - - public void setPersistPeriod(String persistPeriod) { - persistPeriod(Duration.parse(persistPeriod)); - } - - public void setHaHeartbeatTimeout(String val) { - haHeartbeatTimeout(Duration.parse(val)); - } - - public void setStartBrooklynNode(boolean val) { - startBrooklynNode(val); - } - - public void setHaHeartbeatPeriod(String val) { - haHeartbeatPeriod(Duration.parse(val)); - } - - public void setCopyPersistedState(String destinationDir) { - copyPersistedState(destinationDir); - } - - public void setConfigAdmin(ConfigurationAdmin configAdmin) { - this.configAdmin = configAdmin; - } - - public void setGlobalBrooklynProperties(String globalBrooklynProperties) { - this.globalBrooklynProperties = globalBrooklynProperties; - } - - public void setLocalBrooklynProperties(String localBrooklynProperties) { - this.localBrooklynProperties = localBrooklynProperties; - } - - public void setDefaultCatalogLocation(String defaultCatalogLocation) { - this.defaultCatalogLocation = defaultCatalogLocation; - } +public interface OsgiLauncher { + + /** + * Called by blueprint container of brooklyn-karaf-init. + * + * Creates the management context, etc. + */ + public void initOsgi(); + + /** + * Called by blueprint container of brooklyn-karaf-start. + * + * Starts the management context properly ()binding to persisted state, etc). + */ + public void startOsgi(); + + /** + * Called by blueprint container brooklyn-karaf-init. + * + * Destroys the management context. + */ + public void destroyOsgi(); } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java ---------------------------------------------------------------------- diff --git a/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java b/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java new file mode 100644 index 0000000..821a8c2 --- /dev/null +++ b/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java @@ -0,0 +1,225 @@ +/* + * Copyright 2016 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.brooklyn.launcher.osgi; + +import com.google.common.base.Stopwatch; +import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode; +import org.apache.brooklyn.core.BrooklynVersionService; +import org.apache.brooklyn.core.catalog.internal.CatalogInitialization; +import org.apache.brooklyn.core.internal.BrooklynProperties; +import org.apache.brooklyn.core.mgmt.internal.BrooklynShutdownHooks; +import org.apache.brooklyn.core.mgmt.persist.PersistMode; +import org.apache.brooklyn.launcher.common.BasicLauncher; +import org.apache.brooklyn.launcher.common.BrooklynPropertiesFactoryHelper; +import org.apache.brooklyn.rest.BrooklynWebConfig; +import org.apache.brooklyn.rest.security.provider.BrooklynUserWithRandomPasswordSecurityProvider; +import org.apache.brooklyn.util.exceptions.Exceptions; +import org.apache.brooklyn.util.javalang.Threads; +import org.apache.brooklyn.util.text.Strings; +import org.apache.brooklyn.util.time.Duration; +import org.osgi.framework.Constants; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.util.Map; + +/** + * Initializer for brooklyn-core when running in an OSGi environment. + */ +public class OsgiLauncherImpl extends BasicLauncher<OsgiLauncherImpl> implements OsgiLauncher { + + private static final Logger LOG = LoggerFactory.getLogger(OsgiLauncherImpl.class); + public static final String BROOKLYN_CONFIG_PID = "brooklyn"; + + private Object reloadLock = new Object(); + + private BrooklynVersionService brooklynVersion; + + private String globalBrooklynProperties; + private String localBrooklynProperties; + private String defaultCatalogLocation; + + private ConfigurationAdmin configAdmin; + private ConfigSupplier configSupplier; + + + @Override + public OsgiLauncherImpl startPartOne() { + // make sure brooklyn-core bundle is started + brooklynVersion.getVersion(); + + Configuration brooklynConfig = getConfiguration(configAdmin, BROOKLYN_CONFIG_PID); + // Note that this doesn't check whether the files exist, just that there are potential alternative sources for configuration. + if (brooklynConfig == null && Strings.isEmpty(globalBrooklynProperties) && Strings.isEmpty(localBrooklynProperties)) { + LOG.warn("Config Admin PID '" + BROOKLYN_CONFIG_PID + "' not found, not using external configuration. Create a brooklyn.cfg file in etc folder."); + } + configSupplier = new ConfigSupplier(brooklynConfig); + BrooklynPropertiesFactoryHelper helper = new BrooklynPropertiesFactoryHelper( + globalBrooklynProperties, localBrooklynProperties, configSupplier); + setBrooklynPropertiesBuilder(helper.createPropertiesBuilder()); + return super.startPartOne(); + } + + private Configuration getConfiguration(ConfigurationAdmin configAdmin, String brooklynConfigPid) { + String filter = '(' + Constants.SERVICE_PID + '=' + brooklynConfigPid + ')'; + Configuration[] configs; + try { + configs = configAdmin.listConfigurations(filter); + } catch (InvalidSyntaxException | IOException e) { + throw Exceptions.propagate(e); + } + if (configs != null && configs.length > 0) { + return configs[0]; + } else { + return null; + } + } + + // init-method can't find the start method for some reason, provide an alternative. + @Override + public void initOsgi() { + synchronized (reloadLock) { + final Stopwatch startupTimer = Stopwatch.createStarted(); + BrooklynShutdownHooks.resetShutdownFlag(); + LOG.debug("OsgiLauncher init, catalog "+defaultCatalogLocation); + catalogInitialization(new CatalogInitialization(String.format("file:%s", defaultCatalogLocation), false, null, false)); + startPartOne(); + startupTimer.stop(); + LOG.info("Brooklyn initialisation (part one) complete after {}", startupTimer.toString()); + } + } + + @Override + public void startOsgi() { + synchronized (reloadLock) { + final Stopwatch startupTimer = Stopwatch.createStarted(); + LOG.debug("OsgiLauncher start"); + startPartTwo(); + startupTimer.stop(); + LOG.info("Brooklyn initialisation (part two) complete after {}", startupTimer.toString()); + } + } + + @Override + public void destroyOsgi() { + LOG.debug("Notified of system shutdown, calling shutdown hooks"); + Threads.runShutdownHooks(); + } + + @Override + protected void startingUp() { + super.startingUp(); + ManagementContext managementContext = getManagementContext(); + BrooklynProperties brooklynProperties = (BrooklynProperties) managementContext.getConfig(); + if (BrooklynWebConfig.hasNoSecurityOptions(brooklynProperties)) { + LOG.info("No security provider options specified. Define a security provider or users to prevent a random password being created and logged."); + // Deprecated in 0.11.0. Add to release notes and remove in next release. + brooklynProperties.put( + BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, + new BrooklynUserWithRandomPasswordSecurityProvider(managementContext)); + managementContext.getScratchpad().put( + BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, + new BrooklynUserWithRandomPasswordSecurityProvider(managementContext)); + } + } + + public void updateProperties(Map<?, ?> props) { + synchronized (reloadLock) { + LOG.info("Updating brooklyn config because of config admin changes."); + configSupplier.update(props); + getManagementContext().reloadBrooklynProperties(); + } + } + + public void setBrooklynVersion(BrooklynVersionService brooklynVersion) { + this.brooklynVersion = brooklynVersion; + } + + public void setPersistenceLocation(@Nullable String persistenceLocationSpec) { + persistenceLocation(persistenceLocationSpec); + } + + + public void setBrooklynProperties(BrooklynProperties brooklynProperties) { + brooklynProperties(brooklynProperties); + } + + public void setIgnorePersistenceErrors(boolean ignorePersistenceErrors) { + ignorePersistenceErrors(ignorePersistenceErrors); + } + + public void setIgnoreCatalogErrors(boolean ignoreCatalogErrors) { + ignoreCatalogErrors(ignoreCatalogErrors); + } + + public void setIgnoreAppErrors(boolean ignoreAppErrors) { + ignoreAppErrors(ignoreAppErrors); + } + + public void setPersistMode(PersistMode persistMode) { + persistMode(persistMode); + } + + public void setHighAvailabilityMode(HighAvailabilityMode highAvailabilityMode) { + highAvailabilityMode(highAvailabilityMode); + } + + public void setPersistenceDir(@Nullable String persistenceDir) { + persistenceDir(persistenceDir); + } + + public void setPersistPeriod(String persistPeriod) { + persistPeriod(Duration.parse(persistPeriod)); + } + + public void setHaHeartbeatTimeout(String val) { + haHeartbeatTimeout(Duration.parse(val)); + } + + public void setStartBrooklynNode(boolean val) { + startBrooklynNode(val); + } + + public void setHaHeartbeatPeriod(String val) { + haHeartbeatPeriod(Duration.parse(val)); + } + + public void setCopyPersistedState(String destinationDir) { + copyPersistedState(destinationDir); + } + + public void setConfigAdmin(ConfigurationAdmin configAdmin) { + this.configAdmin = configAdmin; + } + + public void setGlobalBrooklynProperties(String globalBrooklynProperties) { + this.globalBrooklynProperties = globalBrooklynProperties; + } + + public void setLocalBrooklynProperties(String localBrooklynProperties) { + this.localBrooklynProperties = localBrooklynProperties; + } + + public void setDefaultCatalogLocation(String defaultCatalogLocation) { + this.defaultCatalogLocation = defaultCatalogLocation; + } +} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/karaf/init/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/karaf/init/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/karaf/init/src/main/resources/OSGI-INF/blueprint/blueprint.xml index ed6a0cb..b4de9a0 100644 --- a/karaf/init/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/karaf/init/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -74,9 +74,9 @@ limitations under the License. </bean> <bean id="launcher" - class="org.apache.brooklyn.launcher.osgi.OsgiLauncher" - init-method="init" - destroy-method="destroy" + class="org.apache.brooklyn.launcher.osgi.OsgiLauncherImpl" + init-method="initOsgi" + destroy-method="destroyOsgi" depends-on="deserializingClassRenamesProvider deserializingJcloudsRenamesProvider"> <property name="brooklynVersion" ref="brooklynVersion" /> @@ -119,4 +119,10 @@ limitations under the License. </interfaces> </service> + <service ref="launcher"> + <interfaces> + <value>org.apache.brooklyn.launcher.osgi.OsgiLauncher</value> + </interfaces> + </service> + </blueprint> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/karaf/pom.xml ---------------------------------------------------------------------- diff --git a/karaf/pom.xml b/karaf/pom.xml index e545d6e..407c2d7 100644 --- a/karaf/pom.xml +++ b/karaf/pom.xml @@ -61,6 +61,7 @@ <modules> <module>init</module> + <module>start</module> <module>jetty-config</module> <module>httpcomponent-extension</module> <module>features</module> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/karaf/start/pom.xml ---------------------------------------------------------------------- diff --git a/karaf/start/pom.xml b/karaf/start/pom.xml new file mode 100644 index 0000000..bed017c --- /dev/null +++ b/karaf/start/pom.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>brooklyn-karaf-start</artifactId> + <packaging>jar</packaging> + <name>Brooklyn OSGi start</name> + <description> + OSGi launcher - starts the ManagementContext + </description> + + <parent> + <groupId>org.apache.brooklyn</groupId> + <artifactId>brooklyn-parent</artifactId> + <version>0.12.0-SNAPSHOT</version> <!-- BROOKLYN_VERSION --> + <relativePath>../../parent/pom.xml</relativePath> + </parent> + + <dependencies> + <dependency> + <groupId>org.apache.brooklyn</groupId> + <artifactId>brooklyn-karaf-init</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.karaf.system</groupId> + <artifactId>org.apache.karaf.system.core</artifactId> + <version>${karaf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.osgi.compendium</artifactId> + <version>${felix-osgi-compendium.version}</version> + </dependency> + + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package>!*</Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/karaf/start/src/main/java/org/apache/brooklyn/launcher/osgi/start/OsgiLauncherCompleter.java ---------------------------------------------------------------------- diff --git a/karaf/start/src/main/java/org/apache/brooklyn/launcher/osgi/start/OsgiLauncherCompleter.java b/karaf/start/src/main/java/org/apache/brooklyn/launcher/osgi/start/OsgiLauncherCompleter.java new file mode 100644 index 0000000..0991754 --- /dev/null +++ b/karaf/start/src/main/java/org/apache/brooklyn/launcher/osgi/start/OsgiLauncherCompleter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.launcher.osgi.start; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.apache.brooklyn.launcher.osgi.OsgiLauncher; + +/** + * See {@link OsgiLauncher} for explanation. + */ +public class OsgiLauncherCompleter { + private OsgiLauncher launcher; + + public void setLauncher(OsgiLauncher val) { + launcher = checkNotNull(val, "launcher"); + } + + public void init() { + launcher.startOsgi(); + } + + public void destroy() { + // no-op; rely on karaf-init to call launcher.destroy() + } +} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/karaf/start/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/karaf/start/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/karaf/start/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000..b278ddb --- /dev/null +++ b/karaf/start/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Copyright 2015 The Apache Software Foundation. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0" + xsi:schemaLocation=" + http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd + http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.2.0.xsd + "> + + <!-- From brooklyn-karaf-init --> + <reference id="localLauncher" + interface="org.apache.brooklyn.launcher.osgi.OsgiLauncher" /> + + <bean class="org.apache.brooklyn.launcher.osgi.start.OsgiLauncherCompleter" + init-method="init" + destroy-method="destroy"> + <property name="launcher" ref="localLauncher"/> + </bean> + +</blueprint> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6a37ead3/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java ---------------------------------------------------------------------- diff --git a/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java b/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java index 04a127b..ec82d45 100644 --- a/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java +++ b/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java @@ -125,6 +125,7 @@ public class BasicLauncher<T extends BasicLauncher<T>> { private Duration haHeartbeatTimeoutOverride = null; private Duration haHeartbeatPeriodOverride = null; + protected boolean startedPartTwo; protected boolean started; private BrooklynProperties.Factory.Builder brooklynPropertiesBuilder; @@ -243,6 +244,8 @@ public class BasicLauncher<T extends BasicLauncher<T>> { @Beta public T catalogInitialization(CatalogInitialization catInit) { + if (started) + throw new IllegalStateException("Cannot set catalog customization after start()"); if (this.catalogInitialization!=null) throw new IllegalStateException("Initial catalog customization already set."); this.catalogInitialization = catInit; @@ -373,12 +376,26 @@ public class BasicLauncher<T extends BasicLauncher<T>> { * @return An object containing details of the web server and the management context. */ public T start() { + startPartOne(); + startPartTwo(); + return self(); + } + + /** + * Starts the web server (with web console) and Brooklyn applications, as per the specifications configured. + * @return An object containing details of the web server and the management context. + */ + protected T startPartOne() { if (started) throw new IllegalStateException("Cannot start() or launch() multiple times"); started = true; initManagementContext(); CatalogInitialization catInit = ((ManagementContextInternal)managementContext).getCatalogInitialization(); + if (catalogInitialization != null && catalogInitialization != catInit) { + throw new IllegalStateException("Unexpected catalog initialization: " + catInit + " != " + catalogInitialization); + } + catalogInitialization = catInit; markCatalogStartingUp(catInit); @@ -386,9 +403,21 @@ public class BasicLauncher<T extends BasicLauncher<T>> { startingUp(); initCamp(); + + return self(); + } + + /** + * Starts the web server (with web console) and Brooklyn applications, as per the specifications configured. + * @return An object containing details of the web server and the management context. + */ + protected T startPartTwo() { + if (startedPartTwo) throw new IllegalStateException("Cannot start() or launch() multiple times"); + startedPartTwo = true; + handlePersistence(); - populateCatalog(catInit); - markCatalogStarted(catInit); + populateCatalog(catalogInitialization); + markCatalogStarted(catalogInitialization); addLocations(); markStartupComplete(); initApps(); @@ -398,6 +427,7 @@ public class BasicLauncher<T extends BasicLauncher<T>> { return self(); } + protected void persist() { if (persistMode != PersistMode.DISABLED) { // Make sure the new apps are persisted in case process exits immediately. @@ -507,7 +537,6 @@ public class BasicLauncher<T extends BasicLauncher<T>> { if (catalogInitialization!=null) { ((ManagementContextInternal)managementContext).setCatalogInitialization(catalogInitialization); } - } protected void handleSubsystemStartupError(boolean ignoreSuchErrors, String system, Exception e) {
