http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/java/org/apache/karaf/cellar/features/shell/ListFeaturesCommand.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/ListFeaturesCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/ListFeaturesCommand.java index f146360..aa67d34 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/shell/ListFeaturesCommand.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/ListFeaturesCommand.java @@ -18,21 +18,27 @@ import org.apache.karaf.cellar.core.Configurations; import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.event.EventType; import org.apache.karaf.cellar.core.shell.CellarCommandSupport; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; import org.apache.karaf.cellar.features.Constants; import org.apache.karaf.cellar.features.FeatureState; import org.apache.karaf.features.Feature; import org.apache.karaf.features.FeaturesService; -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; -import org.apache.karaf.shell.table.ShellTable; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.Option; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; +import org.apache.karaf.shell.support.table.ShellTable; import java.util.*; @Command(scope = "cluster", name = "feature-list", description = "List the features in a cluster group") +@Service public class ListFeaturesCommand extends CellarCommandSupport { @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false) + @Completion(AllGroupsCompleter.class) String groupName; @Option(name = "-i", aliases = { "--installed" }, description = "Display only installed features", required = false, multiValued = false) @@ -53,6 +59,7 @@ public class ListFeaturesCommand extends CellarCommandSupport { @Option(name = "--blocked", description = "Shows only blocked features", required = false, multiValued = false) boolean onlyBlocked; + @Reference private FeaturesService featuresService; @Override @@ -73,7 +80,7 @@ public class ListFeaturesCommand extends CellarCommandSupport { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Map<String, ExtendedFeatureState> features = gatherFeatures(); -; + if (features != null && !features.isEmpty()) { ShellTable table = new ShellTable();
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java index 0788087..0879da8 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java @@ -18,6 +18,7 @@ import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.control.SwitchStatus; import org.apache.karaf.cellar.core.event.EventProducer; import org.apache.karaf.cellar.core.shell.CellarCommandSupport; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; import org.apache.karaf.cellar.features.Constants; import org.apache.karaf.cellar.features.FeatureState; import org.apache.karaf.cellar.features.ClusterRepositoryEvent; @@ -25,18 +26,23 @@ import org.apache.karaf.features.Feature; import org.apache.karaf.features.FeaturesService; import org.apache.karaf.features.Repository; import org.apache.karaf.features.RepositoryEvent; -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.Option; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; import java.net.URI; import java.util.List; import java.util.Map; @Command(scope = "cluster", name = "feature-repo-add", description = "Add a features repository to a cluster group") +@Service public class RepoAddCommand extends CellarCommandSupport { @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false) + @Completion(AllGroupsCompleter.class) String groupName; @Argument(index = 1, name = "urls", description = "URLs of the feature repositories separated by whitespaces", required = true, multiValued = true) @@ -45,7 +51,10 @@ public class RepoAddCommand extends CellarCommandSupport { @Option(name = "-i", aliases = { "--install" }, description = "Install all features contained in the features repository", required = false, multiValued = false) boolean install; + @Reference private EventProducer eventProducer; + + @Reference private FeaturesService featuresService; @Override http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoListCommand.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoListCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoListCommand.java index 5b6f55b..5794d10 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoListCommand.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoListCommand.java @@ -16,21 +16,27 @@ package org.apache.karaf.cellar.features.shell; import org.apache.karaf.cellar.core.Configurations; import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.shell.CellarCommandSupport; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; import org.apache.karaf.cellar.features.Constants; import org.apache.karaf.features.FeaturesService; import org.apache.karaf.features.Repository; -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; -import org.apache.karaf.shell.table.ShellTable; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.Option; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; +import org.apache.karaf.shell.support.table.ShellTable; import java.util.HashMap; import java.util.Map; @Command(scope = "cluster", name = "feature-repo-list", description = "List the features repositories in a cluster group") +@Service public class RepoListCommand extends CellarCommandSupport { @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false) + @Completion(AllGroupsCompleter.class) String groupName; @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false) @@ -42,6 +48,7 @@ public class RepoListCommand extends CellarCommandSupport { @Option(name = "--cluster", description = "Shows only features repositories on the cluster", required = false, multiValued = false) boolean onlyCluster; + @Reference private FeaturesService featuresService; @Override http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRemoveCommand.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRemoveCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRemoveCommand.java index 0d3c582..4f67060 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRemoveCommand.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRemoveCommand.java @@ -18,6 +18,7 @@ import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.control.SwitchStatus; import org.apache.karaf.cellar.core.event.EventProducer; import org.apache.karaf.cellar.core.shell.CellarCommandSupport; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; import org.apache.karaf.cellar.features.Constants; import org.apache.karaf.cellar.features.FeatureState; import org.apache.karaf.cellar.features.ClusterRepositoryEvent; @@ -25,18 +26,23 @@ import org.apache.karaf.features.Feature; import org.apache.karaf.features.FeaturesService; import org.apache.karaf.features.Repository; import org.apache.karaf.features.RepositoryEvent; -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.Option; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; import java.net.URI; import java.util.List; import java.util.Map; @Command(scope = "cluster", name = "feature-repo-remove", description = "Remove features repository URLs from a cluster group") +@Service public class RepoRemoveCommand extends CellarCommandSupport { @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false) + @Completion(AllGroupsCompleter.class) String groupName; @Argument(index = 1, name = "urls", description = "The features repository URLs separated by whitespaces", required = true, multiValued = true) @@ -45,7 +51,10 @@ public class RepoRemoveCommand extends CellarCommandSupport { @Option(name = "-u", aliases = { "--uninstall-all" }, description = "Uninstall all features contained in the features repositories", required = false, multiValued = false) boolean uninstall; + @Reference private EventProducer eventProducer; + + @Reference private FeaturesService featuresService; @Override http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java index 2dfff8c..d1f3dd1 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java @@ -20,21 +20,27 @@ import org.apache.karaf.cellar.core.control.SwitchStatus; import org.apache.karaf.cellar.core.event.EventProducer; import org.apache.karaf.cellar.core.event.EventType; import org.apache.karaf.cellar.core.shell.CellarCommandSupport; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; import org.apache.karaf.cellar.features.ClusterFeaturesEvent; import org.apache.karaf.cellar.features.Constants; import org.apache.karaf.cellar.features.FeatureState; import org.apache.karaf.features.FeatureEvent; -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.Option; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; import java.util.List; import java.util.Map; @Command(scope = "cluster", name = "feature-uninstall", description = "Uninstall a feature from a cluster group") +@Service public class UninstallFeatureCommand extends CellarCommandSupport { @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false) + @Completion(AllGroupsCompleter.class) String groupName; @Argument(index = 1, name = "features", description = "The name and version of the features to uninstall. A feature id looks like name/version. The version is optional.", required = true, multiValued = true) @@ -43,6 +49,7 @@ public class UninstallFeatureCommand extends CellarCommandSupport { @Option(name = "-r", aliases = "--no-auto-refresh", description = "Do not automatically refresh bundles", required = false, multiValued = false) boolean noRefresh; + @Reference private EventProducer eventProducer; @Override http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 4f30536..0000000 --- a/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,75 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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 default-availability="mandatory" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 - http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> - - <!-- Local Features Listener --> - <bean id="localListener" class="org.apache.karaf.cellar.features.LocalFeaturesListener" init-method="init" - destroy-method="destroy"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="featuresService" ref="featuresService"/> - </bean> - <service ref="localListener" interface="org.apache.karaf.features.FeaturesListener"/> - - <!-- Features/Repositories Synchronizer --> - <bean id="synchronizer" class="org.apache.karaf.cellar.features.FeaturesSynchronizer" - init-method="init" destroy-method="destroy"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="featuresService" ref="featuresService"/> - </bean> - <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"> - <service-properties> - <entry key="resource" value="feature"/> - </service-properties> - </service> - - <!-- Cluster Features Event Handler --> - <bean id="featuresEventHandler" class="org.apache.karaf.cellar.features.FeaturesEventHandler" - init-method="init" destroy-method="destroy"> - <property name="featuresService" ref="featuresService"/> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - <service ref="featuresEventHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"> - <service-properties> - <entry key="managed" value="true"/> - </service-properties> - </service> - - <!-- Cluster Features Repositories Event Handler --> - <bean id="repositoryEventHandler" class="org.apache.karaf.cellar.features.RepositoryEventHandler" - init-method="init" destroy-method="destroy"> - <property name="featuresService" ref="featuresService"/> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - <service ref="repositoryEventHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <reference id="clusterManager" interface="org.apache.karaf.cellar.core.ClusterManager"/> - <reference id="groupManager" interface="org.apache.karaf.cellar.core.GroupManager"/> - <reference id="eventProducer" interface="org.apache.karaf.cellar.core.event.EventProducer"/> - <reference id="featuresService" interface="org.apache.karaf.features.FeaturesService"/> - <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/> - -</blueprint> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/resources/OSGI-INF/blueprint/management.xml ---------------------------------------------------------------------- diff --git a/features/src/main/resources/OSGI-INF/blueprint/management.xml b/features/src/main/resources/OSGI-INF/blueprint/management.xml deleted file mode 100644 index 2795c9a..0000000 --- a/features/src/main/resources/OSGI-INF/blueprint/management.xml +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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 default-availability="mandatory" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"> - - <!-- system properties --> - <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" /> - - <!-- Cellar Features MBean --> - <bean id="cellarFeaturesMBean" class="org.apache.karaf.cellar.features.management.internal.CellarFeaturesMBeanImpl"> - <property name="clusterManager" ref="clusterManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="featuresService" ref="featuresService"/> - </bean> - <service ref="cellarFeaturesMBean" auto-export="interfaces"> - <service-properties> - <entry key="jmx.objectname" value="org.apache.karaf.cellar:type=feature,name=$[karaf.name]"/> - </service-properties> - </service> - -</blueprint> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml ---------------------------------------------------------------------- diff --git a/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml b/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml deleted file mode 100644 index 745fea6..0000000 --- a/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml +++ /dev/null @@ -1,110 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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" default-activation="lazy"> - - <!-- Command Bundle --> - <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> - <command> - <action class="org.apache.karaf.cellar.features.shell.InstallFeatureCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="featuresService" ref="featuresService"/> - <property name="eventProducer" ref="eventProducer"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - <!-- <ref component-id="allFeaturesCompleter"/> --> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.features.shell.UninstallFeatureCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="eventProducer" ref="eventProducer"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - <!-- <ref component-id="allFeaturesCompleter"/> --> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.features.shell.ListFeaturesCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="featuresService" ref="featuresService"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.features.shell.RepoListCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="featuresService" ref="featuresService"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.features.shell.RepoAddCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="featuresService" ref="featuresService"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.features.shell.RepoRemoveCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="featuresService" ref="featuresService"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.features.shell.BlockCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - <!-- <ref component-id="allFeaturesCompleter"/> --> - </completers> - </command> - </command-bundle> - - <bean id="allGroupsCompleter" class="org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter"> - <property name="groupManager" ref="groupManager"/> - </bean> - - <!-- - <bean id="allFeaturesCompleter" class="org.apache.karaf.features.command.completers.AllFeatureCompleter"> - <property name="featuresService" ref="featuresService"/> - </bean> - --> - -</blueprint> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/hazelcast/NOTICE ---------------------------------------------------------------------- diff --git a/hazelcast/NOTICE b/hazelcast/NOTICE index addb35c..64cb235 100644 --- a/hazelcast/NOTICE +++ b/hazelcast/NOTICE @@ -1,5 +1,5 @@ Apache Karaf Cellar -Copyright 2011-2014 The Apache Software Foundation +Copyright 2011-2015 The Apache Software Foundation I. Used Software http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/hazelcast/pom.xml ---------------------------------------------------------------------- diff --git a/hazelcast/pom.xml b/hazelcast/pom.xml index 68648aa..5fb220e 100644 --- a/hazelcast/pom.xml +++ b/hazelcast/pom.xml @@ -34,17 +34,21 @@ <name>Apache Karaf :: Cellar :: Hazelcast</name> <dependencies> + <!-- Core Dependencies --> <dependency> <groupId>com.hazelcast</groupId> <artifactId>hazelcast-all</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.karaf.cellar</groupId> <artifactId>org.apache.karaf.cellar.core</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.karaf.cellar</groupId> <artifactId>org.apache.karaf.cellar.utils</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> @@ -56,6 +60,10 @@ <artifactId>org.osgi.compendium</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.util</artifactId> + </dependency> <!-- Logging Dependencies --> <dependency> @@ -75,25 +83,29 @@ <build> <plugins> <plugin> + <groupId>org.apache.karaf.tooling</groupId> + <artifactId>karaf-services-maven-plugin</artifactId> + </plugin> + <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <configuration> <instructions> <Export-Package> - org.apache.karaf.cellar.hazelcast*;version="${project.version}" + !org.apache.karaf.cellar.hazelcast.internal.osgi, + !org.apache.karaf.cellar.hazelcast.management.internal + org.apache.karaf.cellar.hazelcast* </Export-Package> <Import-Package> - com.hazelcast*, - javax.management*, - org.apache.aries.proxy, - org.apache.karaf.cellar.core*;version="${project.version}", - org.apache.karaf.cellar.utils.ping;version="${project.version}", - org.apache.karaf.features;version="[3,5)", - org.osgi*, - org.slf4j;version="[1.6,2)";resolution:=optional + !org.apache.karaf.cellar.hazelcast*, + org.slf4j;version="[1.6,2)";resolution:=optional, + org.apache.karaf.shell*;resolution:=optional, + * </Import-Package> <Private-Package> - org.apache.karaf.cellar.hazelcast.management.internal + org.apache.karaf.cellar.hazelcast.internal.osgi, + org.apache.karaf.cellar.hazelcast.management.internal, + org.apache.karaf.util.tracker;-split-package:=merge-first </Private-Package> </instructions> </configuration> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/internal/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/internal/osgi/Activator.java b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/internal/osgi/Activator.java new file mode 100644 index 0000000..c0f2dfe --- /dev/null +++ b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/internal/osgi/Activator.java @@ -0,0 +1,380 @@ +/* + * 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.karaf.cellar.hazelcast.internal.osgi; + +import com.hazelcast.core.HazelcastInstance; +import org.apache.aries.proxy.ProxyManager; +import org.apache.karaf.cellar.core.ClusterManager; +import org.apache.karaf.cellar.core.GroupManager; +import org.apache.karaf.cellar.core.Node; +import org.apache.karaf.cellar.core.Synchronizer; +import org.apache.karaf.cellar.core.command.BasicCommandStore; +import org.apache.karaf.cellar.core.command.ClusteredExecutionContext; +import org.apache.karaf.cellar.core.command.CommandStore; +import org.apache.karaf.cellar.core.command.ExecutionContext; +import org.apache.karaf.cellar.core.control.*; +import org.apache.karaf.cellar.core.discovery.Discovery; +import org.apache.karaf.cellar.core.discovery.DiscoveryService; +import org.apache.karaf.cellar.core.discovery.DiscoveryTask; +import org.apache.karaf.cellar.core.event.*; +import org.apache.karaf.cellar.core.utils.CombinedClassLoader; +import org.apache.karaf.cellar.hazelcast.*; +import org.apache.karaf.cellar.hazelcast.factory.HazelcastConfigurationManager; +import org.apache.karaf.cellar.hazelcast.factory.HazelcastServiceFactory; +import org.apache.karaf.cellar.hazelcast.management.internal.CellarGroupMBeanImpl; +import org.apache.karaf.cellar.hazelcast.management.internal.CellarMBeanImpl; +import org.apache.karaf.cellar.hazelcast.management.internal.CellarNodeMBeanImpl; +import org.apache.karaf.util.tracker.BaseActivator; +import org.apache.karaf.util.tracker.annotation.Managed; +import org.apache.karaf.util.tracker.annotation.ProvideService; +import org.apache.karaf.util.tracker.annotation.RequireService; +import org.apache.karaf.util.tracker.annotation.Services; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.service.cm.ConfigurationListener; +import org.osgi.service.cm.ManagedService; +import org.osgi.util.tracker.ServiceTracker; +import org.osgi.util.tracker.ServiceTrackerCustomizer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +@Services( + provides = { + @ProvideService(HazelcastInstance.class), + @ProvideService(ClusterManager.class), + @ProvideService(GroupManager.class), + @ProvideService(EventTransportFactory.class), + @ProvideService(EventProducer.class), + @ProvideService(ExecutionContext.class), + @ProvideService(EventHandler.class), + @ProvideService(CommandStore.class) + }, + requires = { + @RequireService(ConfigurationAdmin.class), + @RequireService(ProxyManager.class), + @RequireService(EventHandlerRegistry.class) + } +) +@Managed("org.apache.karaf.cellar.discovery") +public class Activator extends BaseActivator implements ManagedService { + + private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class); + + private CombinedClassLoader combinedClassLoader; + private HazelcastServiceFactory hazelcastServiceFactory; + private List<DiscoveryService> discoveryServices = new ArrayList<DiscoveryService>(); + private List<Synchronizer> synchronizers = new ArrayList<Synchronizer>(); + private HazelcastInstance hazelcastInstance; + private DiscoveryTask discoveryTask; + private CellarExtender extender; + private TopicProducer producer; + private TopicConsumer consumer; + private ServiceTracker<DiscoveryService, DiscoveryService> discoveryServiceTracker; + private ServiceTracker<Synchronizer, Synchronizer> synchronizerServiceTracker; + + private volatile ServiceRegistration coreMBeanRegistration; + private volatile ServiceRegistration nodeMBeanRegistration; + private volatile ServiceRegistration groupMBeanRegistration; + + @Override + public void doStart() throws Exception { + + ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class); + + LOGGER.debug("[CELLAR HAZELCAST] Init combined class loader"); + combinedClassLoader = new CombinedClassLoader(); + combinedClassLoader.init(); + + LOGGER.debug("[CELLAR HAZELCAST] Start the discovery service tracker"); + discoveryServiceTracker = new ServiceTracker<DiscoveryService, DiscoveryService>(bundleContext, DiscoveryService.class, new ServiceTrackerCustomizer<DiscoveryService, DiscoveryService>() { + @Override + public DiscoveryService addingService(ServiceReference<DiscoveryService> serviceReference) { + DiscoveryService service = bundleContext.getService(serviceReference); + discoveryServices.add(service); + return service; + } + + @Override + public void modifiedService(ServiceReference<DiscoveryService> serviceReference, DiscoveryService discoveryService) { + // nothing to do + } + + @Override + public void removedService(ServiceReference<DiscoveryService> serviceReference, DiscoveryService discoveryService) { + discoveryServices.remove(discoveryService); + bundleContext.ungetService(serviceReference); + } + }); + discoveryServiceTracker.open(); + + LOGGER.debug("[CELLAR HAZELCAST] Start the synchronizer service tracker"); + synchronizerServiceTracker = new ServiceTracker<Synchronizer, Synchronizer>(bundleContext, Synchronizer.class, new ServiceTrackerCustomizer<Synchronizer, Synchronizer>() { + @Override + public Synchronizer addingService(ServiceReference<Synchronizer> serviceReference) { + Synchronizer service = bundleContext.getService(serviceReference); + synchronizers.add(service); + return service; + } + + @Override + public void modifiedService(ServiceReference<Synchronizer> serviceReference, Synchronizer synchronizer) { + // nothing to do + } + + @Override + public void removedService(ServiceReference<Synchronizer> serviceReference, Synchronizer synchronizer) { + synchronizers.remove(synchronizer); + bundleContext.ungetService(serviceReference); + } + }); + synchronizerServiceTracker.open(); + + LOGGER.debug("[CELLAR HAZELCAST]Â Init dispatcher"); + EventHandlerRegistryDispatcher dispatcher = new EventHandlerRegistryDispatcher(); + dispatcher.setHandlerRegistry(getTrackedService(EventHandlerRegistry.class)); + dispatcher.init(); + + LOGGER.debug("[CELLAR HAZELCAST] Create Hazelcast configuration manager"); + HazelcastConfigurationManager hazelcastConfigurationManager = new HazelcastConfigurationManager(); + hazelcastConfigurationManager.setDiscoveryServices(discoveryServices); + + LOGGER.debug("[CELLAR HAZELCAST]Â Init Hazelcast service factory"); + hazelcastServiceFactory = new HazelcastServiceFactory(); + hazelcastServiceFactory.setCombinedClassLoader(combinedClassLoader); + hazelcastServiceFactory.setConfigurationManager(hazelcastConfigurationManager); + hazelcastServiceFactory.setBundleContext(bundleContext); + hazelcastServiceFactory.init(); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register Hazelcast instance"); + hazelcastInstance = hazelcastServiceFactory.getInstance(); + register(HazelcastInstance.class, hazelcastInstance); + + LOGGER.debug("[CELLAR HAZELCAST]Â Init discovery task"); + discoveryTask = new DiscoveryTask(); + discoveryTask.setDiscoveryServices(discoveryServices); + discoveryTask.setConfigurationAdmin(configurationAdmin); + discoveryTask.init(); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register Hazelcast cluster manager"); + HazelcastClusterManager clusterManager = new HazelcastClusterManager(); + clusterManager.setInstance(hazelcastInstance); + clusterManager.setConfigurationAdmin(configurationAdmin); + clusterManager.setCombinedClassLoader(combinedClassLoader); + register(ClusterManager.class, clusterManager); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create Hazelcast event transport factory"); + HazelcastEventTransportFactory eventTransportFactory = new HazelcastEventTransportFactory(); + eventTransportFactory.setCombinedClassLoader(combinedClassLoader); + eventTransportFactory.setConfigurationAdmin(configurationAdmin); + eventTransportFactory.setInstance(hazelcastInstance); + eventTransportFactory.setDispatcher(dispatcher); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register Hazelcast group manager"); + HazelcastGroupManager groupManager = new HazelcastGroupManager(); + groupManager.setInstance(hazelcastInstance); + groupManager.setCombinedClassLoader(combinedClassLoader); + groupManager.setBundleContext(bundleContext); + groupManager.setConfigurationAdmin(configurationAdmin); + groupManager.setEventTransportFactory(eventTransportFactory); + register(new Class[]{GroupManager.class, ConfigurationListener.class}, groupManager); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create Cellar membership listener"); + CellarMembershipListener membershipListener = new CellarMembershipListener(hazelcastInstance); + membershipListener.setSynchronizers(synchronizers); + membershipListener.setGroupManager(groupManager); + + LOGGER.debug("[CELLAR HAZELCAST]Â Init Cellar extender"); + extender = new CellarExtender(); + extender.setCombinedClassLoader(combinedClassLoader); + extender.setBundleContext(bundleContext); + extender.init(); + + Node node = clusterManager.getNode(); + + LOGGER.debug("[CELLAR HAZELCAST]Â Init topic consumer"); + consumer = new TopicConsumer(); + consumer.setInstance(hazelcastInstance); + consumer.setDispatcher(dispatcher); + consumer.setNode(node); + consumer.setConfigurationAdmin(configurationAdmin); + consumer.init(); + + LOGGER.debug("[CELLAR HAZELCAST]Â Init topic producer"); + producer = new TopicProducer(); + producer.setInstance(hazelcastInstance); + producer.setNode(node); + producer.setConfigurationAdmin(configurationAdmin); + producer.init(); + register(EventProducer.class, producer); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register basic command store"); + CommandStore commandStore = new BasicCommandStore(); + register(CommandStore.class, commandStore); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register clustered execution context"); + ClusteredExecutionContext executionContext = new ClusteredExecutionContext(); + executionContext.setProducer(producer); + executionContext.setCommandStore(commandStore); + register(ExecutionContext.class, executionContext); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register producer switch command handler"); + ProducerSwitchCommandHandler producerSwitchCommandHandler = new ProducerSwitchCommandHandler(); + producerSwitchCommandHandler.setProducer(producer); + producerSwitchCommandHandler.setConfigurationAdmin(configurationAdmin); + register(EventHandler.class, producerSwitchCommandHandler); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register producer switch result handler"); + ProducerSwitchResultHandler producerSwitchResultHandler = new ProducerSwitchResultHandler(); + producerSwitchResultHandler.setCommandStore(commandStore); + register(EventHandler.class, producerSwitchResultHandler); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register consumer switch command handler"); + ConsumerSwitchCommandHandler consumerSwitchCommandHandler = new ConsumerSwitchCommandHandler(); + consumerSwitchCommandHandler.setProducer(producer); + consumerSwitchCommandHandler.setConsumer(consumer); + consumerSwitchCommandHandler.setConfigurationAdmin(configurationAdmin); + register(EventHandler.class, consumerSwitchCommandHandler); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register consumer switch result handler"); + ConsumerSwitchResultHandler consumerSwitchResultHandler = new ConsumerSwitchResultHandler(); + consumerSwitchResultHandler.setCommandStore(commandStore); + register(EventHandler.class, consumerSwitchResultHandler); + + ProxyManager proxyManager = getTrackedService(ProxyManager.class); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register manage handlers command handler"); + ManageHandlersCommandHandler manageHandlersCommandHandler = new ManageHandlersCommandHandler(); + manageHandlersCommandHandler.setConfigurationAdmin(configurationAdmin); + manageHandlersCommandHandler.setProducer(producer); + manageHandlersCommandHandler.setProxyManager(proxyManager); + register(EventHandler.class, manageHandlersCommandHandler); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register manage handlers result handler"); + ManageHandlersResultHandler manageHandlersResultHandler = new ManageHandlersResultHandler(); + manageHandlersResultHandler.setCommandStore(commandStore); + register(EventHandler.class, manageHandlersResultHandler); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register manage group command handler"); + ManageGroupCommandHandler manageGroupCommandHandler = new ManageGroupCommandHandler(); + manageGroupCommandHandler.setProducer(producer); + manageGroupCommandHandler.setClusterManager(clusterManager); + manageGroupCommandHandler.setGroupManager(groupManager); + register(EventHandler.class, manageGroupCommandHandler); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register manage group result handler"); + ManageGroupResultHandler manageGroupResultHandler = new ManageGroupResultHandler(); + manageGroupResultHandler.setCommandStore(commandStore); + register(EventHandler.class, manageGroupResultHandler); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register Cellar Core MBean"); + CellarMBeanImpl cellarMBean = new CellarMBeanImpl(); + cellarMBean.setBundleContext(bundleContext); + cellarMBean.setClusterManager(clusterManager); + cellarMBean.setGroupManager(groupManager); + cellarMBean.setExecutionContext(executionContext); + Hashtable props = new Hashtable(); + props.put("jmx.objectname", "org.apache.karaf.cellar:type=core,name=" + System.getProperty("karaf.name")); + coreMBeanRegistration = bundleContext.registerService(getInterfaceNames(cellarMBean), cellarMBean, props); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register Cellar Node MBean"); + CellarNodeMBeanImpl cellarNodeMBean = new CellarNodeMBeanImpl(); + cellarNodeMBean.setClusterManager(clusterManager); + cellarNodeMBean.setExecutionContext(executionContext); + props = new Hashtable(); + props.put("jmx.objectname", "org.apache.karaf.cellar:type=node,name=" + System.getProperty("karaf.name")); + nodeMBeanRegistration = bundleContext.registerService(getInterfaceNames(cellarNodeMBean), cellarNodeMBean, props); + + LOGGER.debug("[CELLAR HAZELCAST]Â Create and register Cellar Group MBean"); + CellarGroupMBeanImpl cellarGroupMBean = new CellarGroupMBeanImpl(); + cellarGroupMBean.setClusterManager(clusterManager); + cellarGroupMBean.setExecutionContext(executionContext); + cellarGroupMBean.setGroupManager(groupManager); + props = new Hashtable(); + props.put("jmx.objectname", "org.apache.karaf.cellar:type=group,name=" + System.getProperty("karaf.name")); + groupMBeanRegistration = bundleContext.registerService(getInterfaceNames(cellarGroupMBean), cellarGroupMBean, props); + } + + @Override + public void doStop() { + if (groupMBeanRegistration != null) { + groupMBeanRegistration.unregister(); + groupMBeanRegistration = null; + } + if (nodeMBeanRegistration != null) { + nodeMBeanRegistration.unregister(); + nodeMBeanRegistration = null; + } + if (coreMBeanRegistration != null) { + coreMBeanRegistration.unregister(); + coreMBeanRegistration = null; + } + if (hazelcastServiceFactory != null) { + hazelcastServiceFactory.destroy(); + hazelcastServiceFactory = null; + } + if (hazelcastInstance != null) { + hazelcastInstance.shutdown(); + hazelcastInstance = null; + } + if (discoveryTask != null) { + discoveryTask.destroy(); + discoveryTask = null; + } + if (extender != null) { + extender.destroy(); + extender = null; + } + if (producer != null) { + producer.destroy(); + producer = null; + } + if (consumer != null) { + consumer.destroy(); + consumer = null; + } + if (synchronizerServiceTracker != null) { + synchronizerServiceTracker.close(); + synchronizerServiceTracker = null; + } + if (discoveryServiceTracker != null) { + discoveryServiceTracker.close(); + discoveryServiceTracker = null; + } + if (combinedClassLoader != null) { + combinedClassLoader.destroy(); + combinedClassLoader = null; + } + } + + @Override + public void updated(Dictionary config) { + if (config == null) { + return; + } + HashMap map = new HashMap(); + for (Enumeration keys = config.keys(); keys.hasMoreElements();) { + Object key = keys.nextElement(); + map.put(key, config.get(key)); + } + try { + hazelcastServiceFactory.update(map); + } catch (Exception e) { + LOGGER.error("Can't update Hazelcast service factory", e); + } + } + +} http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 2cae5fe..0000000 --- a/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,197 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"> - - <bean id="hazelcast" class="com.hazelcast.core.Hazelcast" factory-ref="instanceFactory" - factory-method="getInstance" destroy-method="shutdown"/> - <service ref="hazelcast" interface="com.hazelcast.core.HazelcastInstance"/> - - <bean id="instanceFactory" class="org.apache.karaf.cellar.hazelcast.factory.HazelcastServiceFactory" - init-method="init" destroy-method="destroy"> - <property name="combinedClassLoader" ref="combinedClassLoader"/> - <property name="configurationManager" ref="hazelcastConfigurationManager"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - <cm:managed-properties persistent-id="org.apache.karaf.cellar.discovery" update-strategy="component-managed" - update-method="update"/> - </bean> - - <bean id="hazelcastConfigurationManager" class="org.apache.karaf.cellar.hazelcast.factory.HazelcastConfigurationManager" > - <property name="discoveryServices" ref="discoveryServices"/> - </bean> - - <!-- Discovery Task --> - <bean id="discoveryTask" class="org.apache.karaf.cellar.core.discovery.DiscoveryTask" init-method="init" destroy-method="destroy"> - <property name="discoveryServices" ref="discoveryServices"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - - <!-- Members Listener --> - <bean id="membershipListener" class="org.apache.karaf.cellar.hazelcast.CellarMembershipListener"> - <argument index="0" ref="hazelcast"/> - <property name="synchronizers" ref="synchronizers"/> - <property name="groupManager" ref="groupManager"/> - </bean> - - <!-- Cluster Manager --> - <bean id="clusterManager" class="org.apache.karaf.cellar.hazelcast.HazelcastClusterManager"> - <property name="instance" ref="hazelcast"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="combinedClassLoader" ref="combinedClassLoader"/> - </bean> - <service ref="clusterManager" interface="org.apache.karaf.cellar.core.ClusterManager"/> - - <!-- Cluster Group Manager --> - <bean id="groupManager" class="org.apache.karaf.cellar.hazelcast.HazelcastGroupManager" init-method="init" destroy-method="destroy"> - <property name="instance" ref="hazelcast"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="eventTransportFactory" ref="eventTransportFactory"/> - <property name="combinedClassLoader" ref="combinedClassLoader"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - </bean> - <service ref="groupManager"> - <interfaces> - <value>org.apache.karaf.cellar.core.GroupManager</value> - <value>org.osgi.service.cm.ConfigurationListener</value> - </interfaces> - </service> - - <!-- Cluster Event Transport Factory --> - <bean id="eventTransportFactory" class="org.apache.karaf.cellar.hazelcast.HazelcastEventTransportFactory"> - <property name="dispatcher" ref="dispatcher"/> - <property name="instance" ref="hazelcast"/> - <property name="combinedClassLoader" ref="combinedClassLoader"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - <service ref="eventTransportFactory" interface="org.apache.karaf.cellar.core.event.EventTransportFactory"/> - - <!-- Cellar Extender --> - <bean id="cellarExtender" class="org.apache.karaf.cellar.hazelcast.CellarExtender" init-method="init" destroy-method="destroy"> - <property name="combinedClassLoader" ref="combinedClassLoader"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - </bean> - - <!-- Bundle Combined ClassLoader --> - <bean id="combinedClassLoader" class="org.apache.karaf.cellar.core.utils.CombinedClassLoader" init-method="init" destroy-method="destroy"/> - - <!-- Local Node --> - <bean id="node" factory-ref="clusterManager" factory-method="getNode"/> - - <!-- Cluster Event Topic --> - <bean id="eventTopic" factory-ref="hazelcast" factory-method="getTopic"> - <argument value="org.apache.karaf.cellar.event.topic"/> - </bean> - - <!-- Cluster Event Consumer --> - <bean id="consumer" class="org.apache.karaf.cellar.hazelcast.TopicConsumer" init-method="init" - destroy-method="destroy"> - <property name="instance" ref="hazelcast"/> - <property name="dispatcher" ref="dispatcher"/> - <property name="node" ref="node"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - - <!-- Cluster Event Producer --> - <bean id="producer" class="org.apache.karaf.cellar.hazelcast.TopicProducer" init-method="init"> - <property name="instance" ref="hazelcast"/> - <property name="node" ref="node"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - <service ref="producer" interface="org.apache.karaf.cellar.core.event.EventProducer"/> - - <!-- Execution Context --> - <bean id="executionContext" class="org.apache.karaf.cellar.core.command.ClusteredExecutionContext"> - <property name="producer" ref="producer"/> - <property name="commandStore" ref="commandStore"/> - </bean> - <service ref="executionContext" interface="org.apache.karaf.cellar.core.command.ExecutionContext"/> - - <!-- Handler For Cluster Producer Switch Command Event --> - <bean id="producerSwitchCommandHandler" class="org.apache.karaf.cellar.core.control.ProducerSwitchCommandHandler"> - <property name="producer" ref="producer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - <service ref="producerSwitchCommandHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <!-- Handler For Cluster Producer Switch Result Event --> - <bean id="producerSwitchResultHandler" class="org.apache.karaf.cellar.core.control.ProducerSwitchResultHandler"> - <property name="commandStore" ref="commandStore"/> - </bean> - <service ref="producerSwitchResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <!-- Handler For Cluster Consumer Switch Command Event --> - <bean id="consumerSwitchCommandHandler" class="org.apache.karaf.cellar.core.control.ConsumerSwitchCommandHandler"> - <property name="producer" ref="producer"/> - <property name="consumer" ref="consumer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - <service ref="consumerSwitchCommandHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <!-- Handler For Cluster Consumer Switch Result Event --> - <bean id="consumerSwitchResultHandler" class="org.apache.karaf.cellar.core.control.ConsumerSwitchResultHandler"> - <property name="commandStore" ref="commandStore"/> - </bean> - <service ref="consumerSwitchResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <!-- Handler For Cluster Manage Handlers Command Event --> - <bean id="manageHandlersCommandHandler" class="org.apache.karaf.cellar.core.control.ManageHandlersCommandHandler"> - <property name="producer" ref="producer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="proxyManager" ref="proxyManager"/> - </bean> - <service ref="manageHandlersCommandHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <!-- Handler For Cluster Manage Handlers Result Event --> - <bean id="manageHandlersResultHandler" class="org.apache.karaf.cellar.core.control.ManageHandlersResultHandler"> - <property name="commandStore" ref="commandStore"/> - </bean> - <service ref="manageHandlersResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <!-- Handler For Cluster Manager Group Command Event --> - <bean id="manageGroupCommandHandler" class="org.apache.karaf.cellar.core.control.ManageGroupCommandHandler"> - <property name="producer" ref="producer"/> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - </bean> - <service ref="manageGroupCommandHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <!-- Handlers For Cluster Manager Group Result Event --> - <bean id="manageGroupResultHandler" class="org.apache.karaf.cellar.core.control.ManageGroupResultHandler"> - <property name="commandStore" ref="commandStore"/> - </bean> - <service ref="manageGroupResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <!-- Command Store --> - <bean id="commandStore" class="org.apache.karaf.cellar.core.command.BasicCommandStore"/> - <service ref="commandStore" interface="org.apache.karaf.cellar.core.command.CommandStore"/> - - <!-- Cluster Event Dispatcher --> - <bean id="dispatcher" class="org.apache.karaf.cellar.core.event.EventHandlerRegistryDispatcher" init-method="init"> - <property name="handlerRegistry" ref="registry"/> - </bean> - - <reference id="registry" interface="org.apache.karaf.cellar.core.event.EventHandlerRegistry"/> - <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/> - <reference id="proxyManager" interface="org.apache.aries.proxy.ProxyManager"/> - - <reference-list id="discoveryServices" availability="optional" - interface="org.apache.karaf.cellar.core.discovery.DiscoveryService"/> - <reference-list id="groupEventProducers" availability="optional" interface="org.apache.karaf.cellar.core.event.EventProducer" - filter="(type = group)"/> - <reference-list id="groupEventConsumers" availability="optional" interface="org.apache.karaf.cellar.core.event.EventConsumer" - filter="(type = group)"/> - <reference-list id="synchronizers" availability="optional" interface="org.apache.karaf.cellar.core.Synchronizer"/> - -</blueprint> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/hazelcast/src/main/resources/OSGI-INF/blueprint/management.xml ---------------------------------------------------------------------- diff --git a/hazelcast/src/main/resources/OSGI-INF/blueprint/management.xml b/hazelcast/src/main/resources/OSGI-INF/blueprint/management.xml deleted file mode 100644 index 14562cf..0000000 --- a/hazelcast/src/main/resources/OSGI-INF/blueprint/management.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"> - - <!-- system properties --> - <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" /> - - <reference id="featuresService" interface="org.apache.karaf.features.FeaturesService"/> - - <!-- Core Cellar MBean --> - <bean id="cellarMBean" class="org.apache.karaf.cellar.hazelcast.management.internal.CellarMBeanImpl"> - <property name="bundleContext" ref="blueprintBundleContext"/> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="executionContext" ref="executionContext"/> - </bean> - <service ref="cellarMBean" auto-export="interfaces"> - <service-properties> - <entry key="jmx.objectname" value="org.apache.karaf.cellar:type=core,name=$[karaf.name]"/> - </service-properties> - </service> - - <!-- Cellar Node MBean --> - <bean id="cellarNodeMBean" class="org.apache.karaf.cellar.hazelcast.management.internal.CellarNodeMBeanImpl"> - <property name="clusterManager" ref="clusterManager"/> - <property name="executionContext" ref="executionContext"/> - </bean> - <service ref="cellarNodeMBean" auto-export="interfaces"> - <service-properties> - <entry key="jmx.objectname" value="org.apache.karaf.cellar:type=node,name=$[karaf.name]"/> - </service-properties> - </service> - - <!-- Cellar Cluster Group MBean --> - <bean id="cellarGroupMBean" class="org.apache.karaf.cellar.hazelcast.management.internal.CellarGroupMBeanImpl"> - <property name="clusterManager" ref="clusterManager"/> - <property name="executionContext" ref="executionContext"/> - <property name="groupManager" ref="groupManager"/> - </bean> - <service ref="cellarGroupMBean" auto-export="interfaces"> - <service-properties> - <entry key="jmx.objectname" value="org.apache.karaf.cellar:type=group,name=$[karaf.name]"/> - </service-properties> - </service> - -</blueprint> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/itests/pom.xml ---------------------------------------------------------------------- diff --git a/itests/pom.xml b/itests/pom.xml index 5b50599..8ee1062 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -40,6 +40,10 @@ <version>${karaf.version}</version> <type>tar.gz</type> </dependency> + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.core</artifactId> + </dependency> <dependency> <groupId>org.apache.karaf.cellar</groupId> @@ -64,26 +68,14 @@ <!-- pax exam --> <dependency> <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam</artifactId> - <version>4.3.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.ops4j.pax.exam</groupId> <artifactId>pax-exam-junit4</artifactId> - <version>4.3.0</version> + <version>4.5.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.ops4j.pax.exam</groupId> <artifactId>pax-exam-container-karaf</artifactId> - <version>4.3.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam-inject</artifactId> - <version>4.3.0</version> + <version>4.5.0</version> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java b/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java index 9c7d0fe..918860a 100644 --- a/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java +++ b/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java @@ -22,21 +22,21 @@ import java.io.IOException; import java.io.PrintStream; import java.net.DatagramSocket; import java.net.ServerSocket; +import java.security.Principal; +import java.security.PrivilegedExceptionAction; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Dictionary; import java.util.Enumeration; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; +import java.util.concurrent.TimeoutException; import javax.inject.Inject; +import javax.security.auth.Subject; -import org.apache.felix.service.command.CommandProcessor; -import org.apache.felix.service.command.CommandSession; +import org.apache.karaf.shell.api.console.Session; +import org.apache.karaf.shell.api.console.SessionFactory; import org.ops4j.pax.exam.*; import org.ops4j.pax.exam.karaf.options.*; import org.osgi.framework.Bundle; @@ -66,6 +66,10 @@ public class CellarTestSupport { @Inject protected BundleContext bundleContext; + @Inject + protected SessionFactory sessionFactory; + + /** * @param probe * @return @@ -94,7 +98,9 @@ public class CellarTestSupport { String propsetCmd = membersBuilder.toString(); String updateCmd = "config:update"; - executeCommands(editCmd, propsetCmd, updateCmd); + executeCommand(editCmd); + executeCommand(propsetCmd); + executeCommand(updateCmd); } /** @@ -192,98 +198,103 @@ public class CellarTestSupport { return options; } - /** - * Executes a shell command and returns output as a String. - * Commands have a default timeout of 10 seconds. - * - * @param command - * @return - */ - protected String executeCommand(final String command) { - return executeCommand(command, COMMAND_TIMEOUT, false); + protected String executeCommand(final String command, Principal ... principals) { + return executeCommand(command, COMMAND_TIMEOUT, false, principals); } - /** - * Executes a shell command and returns output as a String. - * Commands have a default timeout of 10 seconds. - * - * @param command The command to execute. - * @param timeout The amount of time in millis to wait for the command to execute. - * @param silent Specifies if the command should be displayed in the screen. - * @return - */ - protected String executeCommand(final String command, final Long timeout, final Boolean silent) { + + protected String executeCommand(final String command, final Long timeout, final Boolean silent, final Principal... principals) { + waitForCommandService(command); + String response; final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final PrintStream printStream = new PrintStream(byteArrayOutputStream); - final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class); - final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err); - FutureTask<String> commandFuture = new FutureTask<String>( - new Callable<String>() { - public String call() { - try { - if (!silent) { - System.err.println(command); - } - commandSession.execute(command); - } catch (Exception e) { - e.printStackTrace(System.err); - } - printStream.flush(); - return byteArrayOutputStream.toString(); + final SessionFactory sessionFactory = getOsgiService(SessionFactory.class); + final Session session = sessionFactory.create(System.in, printStream, System.err); + + final Callable<String> commandCallable = new Callable<String>() { + @Override + public String call() throws Exception { + try { + if (!silent) { + System.err.println(command); } - }); + session.execute(command); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + printStream.flush(); + return byteArrayOutputStream.toString(); + } + }; + + FutureTask<String> commandFuture; + if (principals.length == 0) { + commandFuture = new FutureTask<String>(commandCallable); + } else { + // If principals are defined, run the command callable via Subject.doAs() + commandFuture = new FutureTask<String>(new Callable<String>() { + @Override + public String call() throws Exception { + Subject subject = new Subject(); + subject.getPrincipals().addAll(Arrays.asList(principals)); + return Subject.doAs(subject, new PrivilegedExceptionAction<String>() { + @Override + public String run() throws Exception { + return commandCallable.call(); + } + }); + } + }); + } try { executor.submit(commandFuture); response = commandFuture.get(timeout, TimeUnit.MILLISECONDS); - } catch (Exception e) { + } catch (TimeoutException e) { e.printStackTrace(System.err); response = "SHELL COMMAND TIMED OUT: "; + } catch (ExecutionException e) { + Throwable cause = e.getCause().getCause(); + throw new RuntimeException(cause.getMessage(), cause); + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); } - return response; } - /** - * Executes multiple commands inside a Single Session. - * Commands have a default timeout of 10 seconds. - * - * @param commands - * @return - */ - protected String executeCommands(final String... commands) { - String response; - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - final PrintStream printStream = new PrintStream(byteArrayOutputStream); - final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class); - final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err); - FutureTask<String> commandFuture = new FutureTask<String>( - new Callable<String>() { - public String call() { - try { - for (String command : commands) { - System.err.println(command); - commandSession.execute(command); - } - } catch (Exception e) { - e.printStackTrace(System.err); - } - return byteArrayOutputStream.toString(); - } - }); + private void waitForCommandService(String command) { + // the commands are represented by services. Due to the asynchronous nature of services they may not be + // immediately available. This code waits the services to be available, in their secured form. It + // means that the code waits for the command service to appear with the roles defined. + if (command == null || command.length() == 0) { + return; + } + + int spaceIdx = command.indexOf(' '); + if (spaceIdx > 0) { + command = command.substring(0, spaceIdx); + } + int colonIndx = command.indexOf(':'); + String scope = (colonIndx > 0) ? command.substring(0, colonIndx) : "*"; + String name = (colonIndx > 0) ? command.substring(colonIndx + 1) : command; try { - executor.submit(commandFuture); - response = commandFuture.get(COMMAND_TIMEOUT, TimeUnit.MILLISECONDS); + long start = System.currentTimeMillis(); + long cur = start; + while (cur - start < SERVICE_TIMEOUT) { + if (sessionFactory.getRegistry().getCommand(scope, name) != null) { + return; + } + Thread.sleep(100); + cur = System.currentTimeMillis(); + } } catch (Exception e) { - e.printStackTrace(System.err); - response = "SHELL COMMAND TIMED OUT: "; + throw new RuntimeException(e); } - - return response; } + protected Bundle getInstalledBundle(String symbolicName) { for (Bundle b : bundleContext.getBundles()) { if (b.getSymbolicName().equals(symbolicName)) { http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/kubernetes/NOTICE ---------------------------------------------------------------------- diff --git a/kubernetes/NOTICE b/kubernetes/NOTICE index addb35c..64cb235 100644 --- a/kubernetes/NOTICE +++ b/kubernetes/NOTICE @@ -1,5 +1,5 @@ Apache Karaf Cellar -Copyright 2011-2014 The Apache Software Foundation +Copyright 2011-2015 The Apache Software Foundation I. Used Software http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/kubernetes/pom.xml ---------------------------------------------------------------------- diff --git a/kubernetes/pom.xml b/kubernetes/pom.xml index e6dcec7..74cf869 100644 --- a/kubernetes/pom.xml +++ b/kubernetes/pom.xml @@ -49,6 +49,10 @@ <!-- OSGi --> <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.util</artifactId> + </dependency> + <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> <scope>provided</scope> @@ -64,21 +68,27 @@ <build> <plugins> <plugin> + <groupId>org.apache.karaf.tooling</groupId> + <artifactId>karaf-services-maven-plugin</artifactId> + </plugin> + <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <configuration> <instructions> <Export-Package> - org.apache.karaf.cellar.kubernetes.*;version="${project.version}" + !org.apache.karaf.cellar.kubernetes.internal.osgi, + org.apache.karaf.cellar.kubernetes.* </Export-Package> <Import-Package> - io.fabric8.kubernetes.api;version="${fabric8.version}", - org.apache.karaf.cellar.core*;version="${project.version}", - org.osgi*, - org.slf4j;version="[1.6,2)";resolution:=optional + org.slf4j;version="[1.6,2)";resolution:=optional, + * </Import-Package> <DynamicImport-Package>io.fabric8.*</DynamicImport-Package> - <Bundle-Activator>org.apache.karaf.cellar.kubernetes.Activator</Bundle-Activator> + <Private-Package> + org.apache.karaf.cellar.kubernetes.internal.osgi, + org.apache.karaf.util.tracker;-split-package:=merge-first + </Private-Package> </instructions> </configuration> </plugin> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/Activator.java ---------------------------------------------------------------------- diff --git a/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/Activator.java b/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/Activator.java deleted file mode 100644 index c4dfbc2..0000000 --- a/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/Activator.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.karaf.cellar.kubernetes; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Constants; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.cm.ManagedServiceFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Hashtable; - -public class Activator implements BundleActivator { - - private ServiceRegistration serviceRegistration; - - private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class); - - public void start(BundleContext bundleContext) throws Exception { - Hashtable<String, Object> properties = new Hashtable<String, Object>(); - properties.put(Constants.SERVICE_PID, "org.apache.karaf.cellar.kubernetes"); - KubernetesDiscoveryServiceFactory kubernetesDiscoveryServiceFactory = new KubernetesDiscoveryServiceFactory(bundleContext); - serviceRegistration = bundleContext.registerService(ManagedServiceFactory.class.getName(), kubernetesDiscoveryServiceFactory, properties); - } - - public void stop(BundleContext bundleContext) throws Exception { - if (serviceRegistration != null) { - serviceRegistration.unregister(); - serviceRegistration = null; - } - } - -} http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/KubernetesDiscoveryService.java ---------------------------------------------------------------------- diff --git a/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/KubernetesDiscoveryService.java b/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/KubernetesDiscoveryService.java index a42e2bf..d16656b 100644 --- a/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/KubernetesDiscoveryService.java +++ b/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/KubernetesDiscoveryService.java @@ -13,10 +13,10 @@ */ package org.apache.karaf.cellar.kubernetes; -import io.fabric8.kubernetes.api.KubernetesClient; -import io.fabric8.kubernetes.api.KubernetesFactory; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.PodList; +import io.fabric8.kubernetes.client.DefaultKubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClient; import org.apache.karaf.cellar.core.discovery.DiscoveryService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,7 +47,7 @@ public class KubernetesDiscoveryService implements DiscoveryService { try { String kubernetesUrl = "http://" + kubernetesHost + ":" + kubernetesPort; LOGGER.debug("CELLAR KUBERNETES: query API at {} ...", kubernetesUrl); - kubernetesClient = new KubernetesClient(new KubernetesFactory(kubernetesUrl)); + kubernetesClient = new DefaultKubernetesClient(kubernetesUrl); LOGGER.debug("CELLAR KUBERNETES: discovery service initialized"); } catch (Exception e) { LOGGER.error("CELLAR KUBERNETES: can't init discovery service", e); @@ -67,11 +67,11 @@ public class KubernetesDiscoveryService implements DiscoveryService { LOGGER.debug("CELLAR KUBERNETES: query pods with labeled with [{}={}]", kubernetesPodLabelKey, kubernetesPodLabelValue); Set<String> members = new HashSet<String>(); try { - PodList podList = kubernetesClient.getPods(); + PodList podList = kubernetesClient.pods().list(); for (Pod pod : podList.getItems()) { - String value = pod.getLabels().get(kubernetesPodLabelKey); + String value = pod.getMetadata().getLabels().get(kubernetesPodLabelKey); if (value != null && !value.isEmpty()) { - members.add(pod.getCurrentState().getPodIP()); + members.add(pod.getStatus().getPodIP()); } } } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/internal/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/internal/osgi/Activator.java b/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/internal/osgi/Activator.java new file mode 100644 index 0000000..8d19d34 --- /dev/null +++ b/kubernetes/src/main/java/org/apache/karaf/cellar/kubernetes/internal/osgi/Activator.java @@ -0,0 +1,45 @@ +/* + * 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.karaf.cellar.kubernetes.internal.osgi; + +import org.apache.karaf.cellar.kubernetes.KubernetesDiscoveryServiceFactory; +import org.apache.karaf.util.tracker.BaseActivator; +import org.apache.karaf.util.tracker.annotation.ProvideService; +import org.apache.karaf.util.tracker.annotation.Services; +import org.osgi.framework.Constants; +import org.osgi.service.cm.ManagedServiceFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Hashtable; + +@Services( + provides = { + @ProvideService(ManagedServiceFactory.class) + } +) +public class Activator extends BaseActivator { + + private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class); + + @Override + public void doStart() throws Exception { + LOGGER.debug("[CELLAR KUBERNETES] Init discovery service factory"); + Hashtable props = new Hashtable(); + props.put(Constants.SERVICE_PID, "org.apache.karaf.cellar.kubernetes"); + KubernetesDiscoveryServiceFactory factory = new KubernetesDiscoveryServiceFactory(bundleContext); + register(ManagedServiceFactory.class, factory, props); + } + +} http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/manual/NOTICE ---------------------------------------------------------------------- diff --git a/manual/NOTICE b/manual/NOTICE index addb35c..64cb235 100644 --- a/manual/NOTICE +++ b/manual/NOTICE @@ -1,5 +1,5 @@ Apache Karaf Cellar -Copyright 2011-2014 The Apache Software Foundation +Copyright 2011-2015 The Apache Software Foundation I. Used Software http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/obr/NOTICE ---------------------------------------------------------------------- diff --git a/obr/NOTICE b/obr/NOTICE index addb35c..64cb235 100644 --- a/obr/NOTICE +++ b/obr/NOTICE @@ -1,5 +1,5 @@ Apache Karaf Cellar -Copyright 2011-2014 The Apache Software Foundation +Copyright 2011-2015 The Apache Software Foundation I. Used Software
