You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ci...@apache.org on 2016/02/09 02:15:51 UTC
[1/2] brooklyn-server git commit: Fix brooklyn shutdown while running
in karaf
Repository: brooklyn-server
Updated Branches:
refs/heads/master 2e58954e1 -> 5bb87183e
Fix brooklyn shutdown while running in karaf
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/652e2b57
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/652e2b57
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/652e2b57
Branch: refs/heads/master
Commit: 652e2b579c742ea5eba50abfd7bbe0a0d9c193b9
Parents: 1298d37
Author: Cristian Tarsoaga <ch...@192-168-0-102.rdsnet.ro>
Authored: Tue Feb 9 00:03:08 2016 +0200
Committer: Cristian Tarsoaga <ch...@192-168-0-102.rdsnet.ro>
Committed: Tue Feb 9 00:03:08 2016 +0200
----------------------------------------------------------------------
.../apache/brooklyn/core/BrooklynVersion.java | 5 ++-
.../apache/brooklyn/util/core/osgi/Osgis.java | 4 --
karaf/pom.xml | 1 -
pom.xml | 2 +
utils/common/pom.xml | 34 ++++++++++++++-
.../java/org/apache/brooklyn/util/os/Os.java | 10 ++++-
.../brooklyn/util/osgi/OsgiActivator.java | 33 +++++++++++++++
.../org/apache/brooklyn/util/osgi/OsgiUtil.java | 44 ++++++++++++++++++++
8 files changed, 122 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/652e2b57/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java b/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java
index 3e0a1a7..f18e707 100644
--- a/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java
+++ b/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java
@@ -56,6 +56,7 @@ import org.apache.brooklyn.rt.felix.ManifestHelper;
import org.apache.brooklyn.util.core.osgi.Osgis;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.osgi.OsgiUtil;
import org.apache.brooklyn.util.stream.Streams;
import org.apache.brooklyn.util.text.Strings;
import org.osgi.framework.Bundle;
@@ -178,7 +179,7 @@ public class BrooklynVersion {
* Reads main attributes properties from brooklyn-core's bundle manifest.
*/
private void readPropertiesFromOsgiResource() {
- if (Osgis.isBrooklynInsideFramework()) {
+ if (OsgiUtil.isBrooklynInsideFramework()) {
Dictionary<String, String> headers = FrameworkUtil.getBundle(BrooklynVersion.class).getHeaders();
for (Enumeration<String> keys = headers.keys(); keys.hasMoreElements();) {
String key = keys.nextElement();
@@ -288,7 +289,7 @@ public class BrooklynVersion {
* @return An iterable containing all features found in the management context's classpath and catalogue.
*/
public static Iterable<BrooklynFeature> getFeatures(ManagementContext mgmt) {
- if (Osgis.isBrooklynInsideFramework()) {
+ if (OsgiUtil.isBrooklynInsideFramework()) {
List<Bundle> bundles = Arrays.asList(
FrameworkUtil.getBundle(BrooklynVersion.class)
.getBundleContext()
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/652e2b57/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
index 7defcb6..c2598ad 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
@@ -340,10 +340,6 @@ public class Osgis {
}
- /** Tells if Brooklyn is running in an OSGi environment or not. */
- public static boolean isBrooklynInsideFramework() {
- return FrameworkUtil.getBundle(Osgis.class) != null;
- }
/** @deprecated since 0.9.0, replaced with {@link OsgiUtils#getVersionedId(org.osgi.framework.Bundle) } */
@Deprecated
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/652e2b57/karaf/pom.xml
----------------------------------------------------------------------
diff --git a/karaf/pom.xml b/karaf/pom.xml
index c09222c..c750faa 100644
--- a/karaf/pom.xml
+++ b/karaf/pom.xml
@@ -35,7 +35,6 @@
<properties>
<karaf.version>4.0.3</karaf.version>
- <org.osgi.core.version>6.0.0</org.osgi.core.version>
<org.osgi.compendium.version>5.0.0</org.osgi.compendium.version>
<lifecycle-mapping-plugin.version>1.0.0</lifecycle-mapping-plugin.version>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/652e2b57/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4e6012b..e066e13 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,6 +75,8 @@
<properties>
<brooklyn.version>0.9.0-SNAPSHOT</brooklyn.version> <!-- BROOKLYN_VERSION -->
+ <org.osgi.core.version>6.0.0</org.osgi.core.version>
+
<!-- Compilation -->
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/652e2b57/utils/common/pom.xml
----------------------------------------------------------------------
diff --git a/utils/common/pom.xml b/utils/common/pom.xml
index 037dcd9..e8b1892 100644
--- a/utils/common/pom.xml
+++ b/utils/common/pom.xml
@@ -45,7 +45,7 @@
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
- <!-- redirect java.util.logging messages to slf4j/logback -->
+ <!-- redirect java.util.logging messages to slf4j/logback -->
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
@@ -85,7 +85,7 @@
<scope>test</scope>
</dependency>
<!-- common includes are always included, but test-support logging config files above
- take precedance when running tests -->
+ take precedance when running tests -->
<dependency>
<groupId>org.apache.brooklyn</groupId>
<artifactId>brooklyn-logback-includes</artifactId>
@@ -101,6 +101,36 @@
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId> <!-- for javax.annotation.Nullable etc -->
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${org.osgi.core.version}</version>
+ <type>jar</type>
+ </dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-Activator>org.apache.brooklyn.util.osgi.OsgiActivator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/652e2b57/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java b/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java
index 2202c7b..75247ab 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java
@@ -52,6 +52,7 @@ import com.google.common.collect.Iterables;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.brooklyn.util.osgi.OsgiUtil;
public class Os {
@@ -320,7 +321,7 @@ public class Os {
private static void addShutdownFileDeletionHook(String path, FileDeletionHook hook) {
synchronized (deletions) {
if (deletions.isEmpty()) {
- Runtime.getRuntime().addShutdownHook(new Thread() {
+ Thread shutdownHook = new Thread() {
@Override
public void run() {
synchronized (deletions) {
@@ -335,7 +336,12 @@ public class Os {
}
}
}
- });
+ };
+
+ if (OsgiUtil.isBrooklynInsideFramework())
+ OsgiUtil.addShutdownHook(shutdownHook); //bundle deactivator will call OsgiUtils.shutdown() to run hooks
+ else
+ Runtime.getRuntime().addShutdownHook(shutdownHook); //jvm exit will run hooks
}
FileDeletionHook oldHook = deletions.put(path, hook);
if (oldHook!=null && oldHook.recursively)
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/652e2b57/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiActivator.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiActivator.java b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiActivator.java
new file mode 100644
index 0000000..2927ed8
--- /dev/null
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiActivator.java
@@ -0,0 +1,33 @@
+/*
+ * 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.util.osgi;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * handle bundle activation/deactivation
+ */
+public class OsgiActivator implements BundleActivator {
+
+ public void start(BundleContext context) throws Exception {
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ OsgiUtil.shutdown();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/652e2b57/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtil.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtil.java b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtil.java
new file mode 100644
index 0000000..231324b
--- /dev/null
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtil.java
@@ -0,0 +1,44 @@
+/*
+ * 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.util.osgi;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * osgi utils
+ */
+public class OsgiUtil {
+
+ /** Tells if Brooklyn is running in an OSGi environment or not. */
+ public static boolean isBrooklynInsideFramework() {
+ return FrameworkUtil.getBundle(OsgiUtil.class) != null;
+ }
+
+ /** keep a list of threads to be run when an osgi bundle is deactivated */
+ public static void addShutdownHook(Runnable shutdownHook) {
+ shutdownHooks.add(shutdownHook);
+ }
+
+ /** run all previously registered shutdown hooks */
+ public static void shutdown() {
+ for (Runnable r : shutdownHooks)
+ r.run();
+ }
+
+ private static List<Runnable> shutdownHooks = new ArrayList<Runnable>();
+}
[2/2] brooklyn-server git commit: This closes #9
Posted by ci...@apache.org.
This closes #9
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/5bb87183
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/5bb87183
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/5bb87183
Branch: refs/heads/master
Commit: 5bb87183e256cae28497b9b4c7646e694b4f7002
Parents: 2e58954 652e2b5
Author: Ciprian Ciubotariu <ch...@gmx.net>
Authored: Tue Feb 9 02:35:52 2016 +0200
Committer: Ciprian Ciubotariu <ch...@gmx.net>
Committed: Tue Feb 9 02:35:52 2016 +0200
----------------------------------------------------------------------
.../apache/brooklyn/core/BrooklynVersion.java | 5 ++-
.../apache/brooklyn/util/core/osgi/Osgis.java | 4 --
karaf/pom.xml | 1 -
pom.xml | 2 +
utils/common/pom.xml | 34 ++++++++++++++-
.../java/org/apache/brooklyn/util/os/Os.java | 10 ++++-
.../brooklyn/util/osgi/OsgiActivator.java | 33 +++++++++++++++
.../org/apache/brooklyn/util/osgi/OsgiUtil.java | 44 ++++++++++++++++++++
8 files changed, 122 insertions(+), 11 deletions(-)
----------------------------------------------------------------------