http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java index a4c6390..7728840 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java @@ -15,24 +15,32 @@ package org.apache.karaf.cellar.config.shell; import org.apache.karaf.cellar.config.ClusterConfigurationEvent; import org.apache.karaf.cellar.config.Constants; +import org.apache.karaf.cellar.config.shell.completers.ClusterConfigCompleter; import org.apache.karaf.cellar.core.Configurations; 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.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; import org.apache.karaf.cellar.core.event.EventType; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; +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.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; import java.util.Map; import java.util.Properties; @Command(scope = "cluster", name = "config-property-append", description = "Append to the property value for a configuration PID in a cluster group") +@Service public class PropAppendCommand extends ConfigCommandSupport { @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false) + @Completion(AllGroupsCompleter.class) String groupName; @Argument(index = 1, name = "pid", description = "The configuration PID", required = true, multiValued = false) + @Completion(ClusterConfigCompleter.class) String pid; @Argument(index = 2, name = "key", description = "The property key", required = true, multiValued = false) @@ -41,6 +49,7 @@ public class PropAppendCommand extends ConfigCommandSupport { @Argument(index = 3, name = "value", description = "The property value", required = true, multiValued = false) String value; + @Reference private EventProducer eventProducer; @Override
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java index 059a882..daa87f5 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java @@ -13,31 +13,40 @@ */ package org.apache.karaf.cellar.config.shell; -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; import org.apache.karaf.cellar.config.Constants; import org.apache.karaf.cellar.config.ClusterConfigurationEvent; +import org.apache.karaf.cellar.config.shell.completers.ClusterConfigCompleter; import org.apache.karaf.cellar.core.Configurations; 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.event.EventType; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; +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.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; import java.util.Map; import java.util.Properties; @Command(scope = "cluster", name = "config-property-delete", description = "Delete a property from a configuration in a cluster group") +@Service public class PropDelCommand extends ConfigCommandSupport { @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false) + @Completion(AllGroupsCompleter.class) String groupName; @Argument(index = 1, name = "pid", description = "The configuration PID", required = true, multiValued = false) + @Completion(ClusterConfigCompleter.class) String pid; @Argument(index = 2, name = "key", description = "The property key to delete", required = true, multiValued = false) String key; + @Reference private EventProducer eventProducer; @Override http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java index 1065965..53b08dd 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java @@ -15,8 +15,10 @@ package org.apache.karaf.cellar.config.shell; import org.apache.karaf.cellar.core.Configurations; import org.apache.karaf.cellar.core.shell.CellarCommandSupport; -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; @@ -24,11 +26,13 @@ import java.util.Dictionary; import java.util.Properties; @Command(scope = "cluster", name = "config-property-excluded", description = "Display or set the config properties excluded from the cluster sync") +@Service public class PropExcludedCommand extends CellarCommandSupport { @Argument(index = 0, name = "excluded-properties", description = "A list of comma separated properties excluded from the cluster sync", required = false, multiValued = false) String excludedProperties; + @Reference private ConfigurationAdmin configurationAdmin; @Override @@ -59,4 +63,5 @@ public class PropExcludedCommand extends CellarCommandSupport { public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) { this.configurationAdmin = configurationAdmin; } + } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java index f1bf513..23d99b1 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java @@ -14,22 +14,29 @@ package org.apache.karaf.cellar.config.shell; import org.apache.karaf.cellar.config.Constants; +import org.apache.karaf.cellar.config.shell.completers.ClusterConfigCompleter; 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.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; +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.lifecycle.Service; import java.util.Map; import java.util.Properties; @Command(scope = "cluster", name = "config-property-list", description = "List the configurations in a cluster group") +@Service public class PropListCommand 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 = "pid", description = "The configuration PID", required = true, multiValued = false) + @Completion(ClusterConfigCompleter.class) String pid; @Override http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java index a8da140..ac25f9c 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java @@ -15,24 +15,32 @@ package org.apache.karaf.cellar.config.shell; import org.apache.karaf.cellar.config.ClusterConfigurationEvent; import org.apache.karaf.cellar.config.Constants; +import org.apache.karaf.cellar.config.shell.completers.ClusterConfigCompleter; import org.apache.karaf.cellar.core.Configurations; 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.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; import org.apache.karaf.cellar.core.event.EventType; +import org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter; +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.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; import java.util.Map; import java.util.Properties; @Command(scope = "cluster", name = "config-property-set", description = "Set a property value for a configuration in a cluster group") +@Service public class PropSetCommand extends ConfigCommandSupport { @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false) + @Completion(AllGroupsCompleter.class) String groupName; @Argument(index = 1, name = "pid", description = "The configuration PID", required = true, multiValued = false) + @Completion(ClusterConfigCompleter.class) String pid; @Argument(index = 2, name = "key", description = "The property key", required = true, multiValued = false) @@ -41,6 +49,7 @@ public class PropSetCommand extends ConfigCommandSupport { @Argument(index = 3, name = "value", description = "The property value", required = true, multiValued = false) String value; + @Reference private EventProducer eventProducer; @Override http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java index 6481149..ee549a4 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java @@ -18,8 +18,12 @@ import org.apache.karaf.cellar.core.ClusterManager; import org.apache.karaf.cellar.core.Configurations; import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.GroupManager; -import org.apache.karaf.shell.console.Completer; -import org.apache.karaf.shell.console.completer.StringsCompleter; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; +import org.apache.karaf.shell.api.console.CommandLine; +import org.apache.karaf.shell.api.console.Completer; +import org.apache.karaf.shell.api.console.Session; +import org.apache.karaf.shell.support.completers.StringsCompleter; import java.util.List; import java.util.Map; @@ -28,13 +32,17 @@ import java.util.Properties; /** * Command completer for the configuration from the cluster. */ +@Service public class ClusterConfigCompleter implements Completer { + @Reference protected ClusterManager clusterManager; + + @Reference protected GroupManager groupManager; @Override - public int complete(String buffer, int cursor, List<String> candidates) { + public int complete(Session session, CommandLine commandLine, List<String> candidates) { StringsCompleter delegate = new StringsCompleter(); try { Map<String, Group> groups = groupManager.listGroups(); @@ -54,7 +62,7 @@ public class ClusterConfigCompleter implements Completer { } catch (Exception e) { // nothing to do } - return delegate.complete(buffer, cursor, candidates); + return delegate.complete(session, commandLine, candidates); } public ClusterManager getClusterManager() { http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 1baf760..0000000 --- a/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,81 +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" - xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" - xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.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.1.0 - http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd - http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0 - http://aries.apache.org/schemas/blueprint-ext/blueprint-ext.xsd - "> - - <!-- Local Configuration Listener --> - <bean id="localListener" class="org.apache.karaf.cellar.config.LocalConfigurationListener" init-method="init" - destroy-method="destroy"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="eventProducer" ref="eventProducer"/> - </bean> - <service ref="localListener" interface="org.osgi.service.cm.ConfigurationListener"/> - - <!-- Configuration Synchronizer --> - <bean id="synchronizer" class="org.apache.karaf.cellar.config.ConfigurationSynchronizer" - init-method="init" destroy-method="destroy" depends-on="eventHandler"> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="groupManager" ref="groupManager"/> - <property name="clusterManager" ref="clusterManager"/> - <property name="storage" value="${storage}"/> - </bean> - <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"> - <service-properties> - <entry key="resource" value="config"/> - </service-properties> - </service> - - <!-- Cluster Event Handler --> - <bean id="eventHandler" class="org.apache.karaf.cellar.config.ConfigurationEventHandler" - init-method="init" destroy-method="destroy"> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="groupManager" ref="groupManager"/> - <property name="clusterManager" ref="clusterManager"/> - <property name="storage" value="${storage}"/> - </bean> - <service ref="eventHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"> - <service-properties> - <entry key="managed" value="true"/> - </service-properties> - </service> - - <reference id="clusterManager" interface="org.apache.karaf.cellar.core.ClusterManager"/> - <reference id="groupManager" interface="org.apache.karaf.cellar.core.GroupManager"/> - <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/> - <reference id="eventProducer" interface="org.apache.karaf.cellar.core.event.EventProducer"/> - - <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" /> - - <cm:property-placeholder persistent-id="org.apache.karaf.shell.config"> - <cm:default-properties> - <cm:property name="storage" value="$[karaf.base]/etc/"/> - </cm:default-properties> - </cm:property-placeholder> - -</blueprint> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/config/src/main/resources/OSGI-INF/blueprint/management.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/OSGI-INF/blueprint/management.xml b/config/src/main/resources/OSGI-INF/blueprint/management.xml deleted file mode 100644 index 2888a32..0000000 --- a/config/src/main/resources/OSGI-INF/blueprint/management.xml +++ /dev/null @@ -1,31 +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"> - - <!-- Cellar Config MBean --> - <bean id="cellarConfigMBean" class="org.apache.karaf.cellar.config.management.internal.CellarConfigMBeanImpl"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </bean> - <service ref="cellarConfigMBean" auto-export="interfaces"> - <service-properties> - <entry key="jmx.objectname" value="org.apache.karaf.cellar:type=config,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/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml deleted file mode 100644 index 82ad3c3..0000000 --- a/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml +++ /dev/null @@ -1,115 +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.config.shell.ListCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.config.shell.PropListCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - <ref component-id="clusterConfigCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.config.shell.PropSetCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - <ref component-id="clusterConfigCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.config.shell.PropAppendCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - <ref component-id="clusterConfigCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.config.shell.PropDelCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - <ref component-id="clusterConfigCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.config.shell.DeleteCommand"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="eventProducer" ref="eventProducer"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - </action> - <completers> - <ref component-id="allGroupsCompleter"/> - <ref component-id="clusterConfigCompleter"/> - </completers> - </command> - <command> - <action class="org.apache.karaf.cellar.config.shell.PropExcludedCommand"> - <property name="configurationAdmin" ref="configurationAdmin"/> - </action> - </command> - <command> - <action class="org.apache.karaf.cellar.config.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="clusterConfigCompleter"/> - </completers> - </command> - </command-bundle> - - <bean id="allGroupsCompleter" class="org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter"> - <property name="groupManager" ref="groupManager"/> - </bean> - - <bean id="clusterConfigCompleter" class="org.apache.karaf.cellar.config.shell.completers.ClusterConfigCompleter"> - <property name="groupManager" ref="groupManager"/> - <property name="clusterManager" ref="clusterManager"/> - </bean> - -</blueprint> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/NOTICE ---------------------------------------------------------------------- diff --git a/core/NOTICE b/core/NOTICE index addb35c..64cb235 100644 --- a/core/NOTICE +++ b/core/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/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index 499d543..acb9cb2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -49,13 +49,16 @@ <!-- Core dependencies --> <dependency> <groupId>org.apache.karaf.shell</groupId> - <artifactId>org.apache.karaf.shell.console</artifactId> + <artifactId>org.apache.karaf.shell.core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.util</artifactId> </dependency> <dependency> <groupId>org.apache.aries.proxy</groupId> <artifactId>org.apache.aries.proxy.api</artifactId> <version>1.0.1</version> - <scope>provided</scope> </dependency> <!-- Logging Dependencies --> @@ -86,19 +89,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.core*;version="${project.version}" + !org.apache.karaf.cellar.core.internal.osgi, + org.apache.karaf.cellar.core* </Export-Package> <Import-Package> - org.apache.aries.proxy, - org.apache.karaf.shell.console*;version="[3,5)", - org.osgi*, - org.slf4j;version="[1.6,2)";resolution:=optional + org.slf4j;version="[1.6,2)";resolution:=optional, + org.apache.karaf.shell*;resolution:=optional, + * </Import-Package> + <Private-Package> + org.apache.karaf.cellar.core.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/core/src/main/java/org/apache/karaf/cellar/core/internal/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/karaf/cellar/core/internal/osgi/Activator.java b/core/src/main/java/org/apache/karaf/cellar/core/internal/osgi/Activator.java new file mode 100644 index 0000000..7514c66 --- /dev/null +++ b/core/src/main/java/org/apache/karaf/cellar/core/internal/osgi/Activator.java @@ -0,0 +1,76 @@ +/* + * 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.core.internal.osgi; + +import org.apache.karaf.cellar.core.event.EventHandler; +import org.apache.karaf.cellar.core.event.EventHandlerRegistry; +import org.apache.karaf.cellar.core.event.EventHandlerServiceRegistry; +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.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; +import org.osgi.util.tracker.ServiceTrackerCustomizer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Services( + provides = { @ProvideService(EventHandlerRegistry.class) } +) +public class Activator extends BaseActivator { + + private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class); + + private EventHandlerServiceRegistry registry; + private ServiceTracker<EventHandler, EventHandler> eventHandlerServiceTracker; + + @Override + public void doStart() throws Exception { + + LOGGER.debug("[CELLAR CORE] Registering event handler service registry"); + registry = new EventHandlerServiceRegistry(); + register(EventHandlerRegistry.class, registry); + + LOGGER.debug("[CELLAR CORE] Starting event handler service tracker"); + eventHandlerServiceTracker = new ServiceTracker<EventHandler, EventHandler>(bundleContext, EventHandler.class, new ServiceTrackerCustomizer<EventHandler, EventHandler>() { + @Override + public EventHandler addingService(ServiceReference<EventHandler> serviceReference) { + EventHandler eventHandler = bundleContext.getService(serviceReference); + registry.bind(eventHandler); + return eventHandler; + } + + @Override + public void modifiedService(ServiceReference<EventHandler> serviceReference, EventHandler eventHandler) { + // nothing to do + } + + @Override + public void removedService(ServiceReference<EventHandler> serviceReference, EventHandler eventHandler) { + registry.unbind(eventHandler); + bundleContext.ungetService(serviceReference); + } + }); + eventHandlerServiceTracker.open(); + } + + @Override + public void doStop() { + if (eventHandlerServiceTracker != null) { + eventHandlerServiceTracker.close(); + eventHandlerServiceTracker = null; + } + } + +} http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/src/main/java/org/apache/karaf/cellar/core/shell/CellarCommandSupport.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/karaf/cellar/core/shell/CellarCommandSupport.java b/core/src/main/java/org/apache/karaf/cellar/core/shell/CellarCommandSupport.java index 6ff9191..9341334 100644 --- a/core/src/main/java/org/apache/karaf/cellar/core/shell/CellarCommandSupport.java +++ b/core/src/main/java/org/apache/karaf/cellar/core/shell/CellarCommandSupport.java @@ -15,16 +15,22 @@ package org.apache.karaf.cellar.core.shell; import org.apache.karaf.cellar.core.ClusterManager; import org.apache.karaf.cellar.core.GroupManager; -import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.apache.karaf.shell.api.action.Action; +import org.apache.karaf.shell.api.action.lifecycle.Reference; import org.osgi.service.cm.ConfigurationAdmin; /** * Abstract Cellar command. */ -public abstract class CellarCommandSupport extends OsgiCommandSupport { +public abstract class CellarCommandSupport implements Action { + @Reference protected ClusterManager clusterManager; + + @Reference protected GroupManager groupManager; + + @Reference protected ConfigurationAdmin configurationAdmin; public ClusterManager getClusterManager() { @@ -51,4 +57,11 @@ public abstract class CellarCommandSupport extends OsgiCommandSupport { this.configurationAdmin = configurationAdmin; } + @Override + public Object execute() throws Exception { + return doExecute(); + } + + protected abstract Object doExecute() throws Exception; + } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllGroupsCompleter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllGroupsCompleter.java b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllGroupsCompleter.java index b5e776c..d8d4f5b 100644 --- a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllGroupsCompleter.java +++ b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllGroupsCompleter.java @@ -14,10 +14,12 @@ package org.apache.karaf.cellar.core.shell.completer; import org.apache.karaf.cellar.core.Group; +import org.apache.karaf.shell.api.action.lifecycle.Service; /** * Completer for all cluster groups. */ +@Service public class AllGroupsCompleter extends GroupCompleterSupport { /** http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllNodeCompleter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllNodeCompleter.java b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllNodeCompleter.java index be7f26f..a2b85a5 100644 --- a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllNodeCompleter.java +++ b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/AllNodeCompleter.java @@ -14,10 +14,12 @@ package org.apache.karaf.cellar.core.shell.completer; import org.apache.karaf.cellar.core.Node; +import org.apache.karaf.shell.api.action.lifecycle.Service; /** * A completer which includes all nodes. */ +@Service public class AllNodeCompleter extends NodeCompleterSupport { /** http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/GroupCompleterSupport.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/GroupCompleterSupport.java b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/GroupCompleterSupport.java index bd172ef..058f1e8 100644 --- a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/GroupCompleterSupport.java +++ b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/GroupCompleterSupport.java @@ -15,8 +15,11 @@ package org.apache.karaf.cellar.core.shell.completer; import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.GroupManager; -import org.apache.karaf.shell.console.Completer; -import org.apache.karaf.shell.console.completer.StringsCompleter; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.console.CommandLine; +import org.apache.karaf.shell.api.console.Completer; +import org.apache.karaf.shell.api.console.Session; +import org.apache.karaf.shell.support.completers.StringsCompleter; import java.util.List; @@ -25,6 +28,7 @@ import java.util.List; */ public abstract class GroupCompleterSupport implements Completer { + @Reference protected GroupManager groupManager; /** @@ -36,7 +40,7 @@ public abstract class GroupCompleterSupport implements Completer { protected abstract boolean acceptsGroup(Group group); @Override - public int complete(String buffer, int cursor, List<String> candidates) { + public int complete(Session session, CommandLine commandLine, List<String> candidates) { StringsCompleter delegate = new StringsCompleter(); try { for (Group group : groupManager.listAllGroups()) { @@ -50,7 +54,7 @@ public abstract class GroupCompleterSupport implements Completer { } catch (Exception e) { // ignore } - return delegate.complete(buffer, cursor, candidates); + return delegate.complete(session, commandLine, candidates); } public GroupManager getGroupManager() { http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/LocalGroupsCompleter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/LocalGroupsCompleter.java b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/LocalGroupsCompleter.java index 16b42d5..61dd223 100644 --- a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/LocalGroupsCompleter.java +++ b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/LocalGroupsCompleter.java @@ -15,10 +15,12 @@ package org.apache.karaf.cellar.core.shell.completer; import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.Node; +import org.apache.karaf.shell.api.action.lifecycle.Service; /** * Local cluster groups completer. */ +@Service public class LocalGroupsCompleter extends GroupCompleterSupport { /** http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/NodeCompleterSupport.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/NodeCompleterSupport.java b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/NodeCompleterSupport.java index 815a658..2269315 100644 --- a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/NodeCompleterSupport.java +++ b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/NodeCompleterSupport.java @@ -15,8 +15,11 @@ package org.apache.karaf.cellar.core.shell.completer; import org.apache.karaf.cellar.core.ClusterManager; import org.apache.karaf.cellar.core.Node; -import org.apache.karaf.shell.console.Completer; -import org.apache.karaf.shell.console.completer.StringsCompleter; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.apache.karaf.shell.api.console.CommandLine; +import org.apache.karaf.shell.api.console.Completer; +import org.apache.karaf.shell.api.console.Session; +import org.apache.karaf.shell.support.completers.StringsCompleter; import java.util.List; @@ -25,10 +28,11 @@ import java.util.List; */ public abstract class NodeCompleterSupport implements Completer { + @Reference private ClusterManager clusterManager; @Override - public int complete(String buffer, int cursor, List<String> candidates) { + public int complete(Session session, CommandLine commandLine, List<String> candidates) { StringsCompleter delegate = new StringsCompleter(); try { for (Node node : clusterManager.listNodes()) { @@ -42,7 +46,7 @@ public abstract class NodeCompleterSupport implements Completer { } catch (Exception e) { // Ignore } - return delegate.complete(buffer, cursor, candidates); + return delegate.complete(session, commandLine, candidates); } protected abstract boolean acceptsNode(Node node); http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/OtherGroupsCompleter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/OtherGroupsCompleter.java b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/OtherGroupsCompleter.java index 1098bea..dd9c495 100644 --- a/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/OtherGroupsCompleter.java +++ b/core/src/main/java/org/apache/karaf/cellar/core/shell/completer/OtherGroupsCompleter.java @@ -15,10 +15,12 @@ package org.apache.karaf.cellar.core.shell.completer; import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.Node; +import org.apache.karaf.shell.api.action.lifecycle.Service; /** * Other groups completer. */ +@Service public class OtherGroupsCompleter extends GroupCompleterSupport { /** http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 851da4e..0000000 --- a/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,27 +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"> - - <!-- Handlers Registry --> - <bean id="registry" class="org.apache.karaf.cellar.core.event.EventHandlerServiceRegistry"/> - <service ref="registry" interface="org.apache.karaf.cellar.core.event.EventHandlerRegistry"/> - - <reference-list id="eventHandlers" interface="org.apache.karaf.cellar.core.event.EventHandler" availability="optional"> - <reference-listener bind-method="bind" unbind-method="unbind"> - <ref component-id="registry"/> - </reference-listener> - </reference-list> - -</blueprint> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/dosgi/NOTICE ---------------------------------------------------------------------- diff --git a/dosgi/NOTICE b/dosgi/NOTICE index addb35c..64cb235 100644 --- a/dosgi/NOTICE +++ b/dosgi/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/dosgi/pom.xml ---------------------------------------------------------------------- diff --git a/dosgi/pom.xml b/dosgi/pom.xml index 0bfde3b..43f8f71 100644 --- a/dosgi/pom.xml +++ b/dosgi/pom.xml @@ -40,8 +40,12 @@ <artifactId>org.apache.karaf.cellar.core</artifactId> </dependency> <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.util</artifactId> + </dependency> + <dependency> <groupId>org.apache.karaf.shell</groupId> - <artifactId>org.apache.karaf.shell.table</artifactId> + <artifactId>org.apache.karaf.shell.core</artifactId> </dependency> <dependency> <groupId>org.osgi</groupId> @@ -72,27 +76,28 @@ <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.dosgi*;version="${project.version}" + !org.apache.karaf.cellar.dosgi.internal.osgi, + org.apache.karaf.cellar.dosgi* </Export-Package> <Import-Package> - javax.management*, - org.apache.karaf.cellar.core*;version="${project.version}", - org.apache.felix.service.command, - org.apache.felix.gogo.commands, - org.apache.karaf.shell.console;version="[3,5)", - org.apache.karaf.shell.console.commands;version="[3,5)", - org.apache.karaf.shell.console.completer;version="[3,5)", - org.apache.karaf.shell.commands;version="[3,5)", - org.apache.karaf.shell.table;version="[3,5)", - org.osgi*, - org.slf4j;version="[1.6,2)";resolution:=optional + org.slf4j;version="[1.6,2)";resolution:=optional, + org.apache.karaf.shell*;resolution:=optional, + * </Import-Package> <DynamicImport-Package>javax.*,org.w3c.*,org.xml.*,org.apache.karaf.cellar.*</DynamicImport-Package> + <Private-Package> + org.apache.karaf.cellar.dosgi.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/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/internal/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/internal/osgi/Activator.java b/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/internal/osgi/Activator.java new file mode 100644 index 0000000..2a17db2 --- /dev/null +++ b/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/internal/osgi/Activator.java @@ -0,0 +1,117 @@ +/* + * 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.dosgi.internal.osgi; + +import org.apache.karaf.cellar.core.ClusterManager; +import org.apache.karaf.cellar.core.command.CommandStore; +import org.apache.karaf.cellar.core.event.EventHandler; +import org.apache.karaf.cellar.core.event.EventTransportFactory; +import org.apache.karaf.cellar.dosgi.*; +import org.apache.karaf.cellar.dosgi.management.internal.ServiceMBeanImpl; +import org.apache.karaf.util.tracker.BaseActivator; +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.ServiceRegistration; +import org.osgi.framework.hooks.service.ListenerHook; +import org.osgi.service.cm.ConfigurationAdmin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Hashtable; + +@Services( + provides = { + @ProvideService(ListenerHook.class), + @ProvideService(EventHandler.class) + }, + requires = { + @RequireService(ClusterManager.class), + @RequireService(EventTransportFactory.class), + @RequireService(CommandStore.class), + @RequireService(ConfigurationAdmin.class) + } +) +public class Activator extends BaseActivator { + + private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class); + + private ImportServiceListener importServiceListener; + private ExportServiceListener exportServiceListener; + private ServiceRegistration mbeanRegistration; + + @Override + public void doStart() throws Exception { + + ClusterManager clusterManager = getTrackedService(ClusterManager.class); + EventTransportFactory eventTransportFactory = getTrackedService(EventTransportFactory.class); + CommandStore commandStore = getTrackedService(CommandStore.class); + ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class); + + LOGGER.debug("[CELLAR DOSGi] Init remote service call handler"); + RemoteServiceCallHandler remoteServiceCallHandler = new RemoteServiceCallHandler(); + remoteServiceCallHandler.setEventTransportFactory(eventTransportFactory); + remoteServiceCallHandler.setClusterManager(clusterManager); + remoteServiceCallHandler.setBundleContext(bundleContext); + remoteServiceCallHandler.setConfigurationAdmin(configurationAdmin); + Hashtable props = new Hashtable(); + props.put("managed", "true"); + register(EventHandler.class, remoteServiceCallHandler, props); + + LOGGER.debug("[CELLAR DOSGi] Init remote service result handler"); + RemoteServiceResultHandler remoteServiceResultHandler = new RemoteServiceResultHandler(); + remoteServiceResultHandler.setCommandStore(commandStore); + register(EventHandler.class, remoteServiceCallHandler); + + LOGGER.debug("[CELLAR DOSGi] Init import service listener"); + importServiceListener = new ImportServiceListener(); + importServiceListener.setClusterManager(clusterManager); + importServiceListener.setEventTransportFactory(eventTransportFactory); + importServiceListener.setCommandStore(commandStore); + importServiceListener.setBundleContext(bundleContext); + importServiceListener.init(); + register(ListenerHook.class, importServiceListener); + + LOGGER.debug("[CELLAR DOSGi] Init export service listener"); + exportServiceListener = new ExportServiceListener(); + exportServiceListener.setClusterManager(clusterManager); + exportServiceListener.setEventTransportFactory(eventTransportFactory); + exportServiceListener.setBundleContext(bundleContext); + exportServiceListener.init(); + + LOGGER.debug("[CELLAR DOSGi] Register MBean"); + ServiceMBeanImpl mbean = new ServiceMBeanImpl(); + mbean.setClusterManager(clusterManager); + props = new Hashtable(); + props.put("jmx.objectname", "org.apache.karaf.cellar:type=service,name=" + System.getProperty("karaf.name")); + mbeanRegistration = bundleContext.registerService(getInterfaceNames(mbean), mbean, props); + } + + @Override + public void doStop() { + if (mbeanRegistration != null) { + mbeanRegistration.unregister(); + mbeanRegistration = null; + } + if (exportServiceListener != null) { + exportServiceListener.destroy(); + exportServiceListener = null; + } + if (importServiceListener != null) { + importServiceListener.destroy(); + importServiceListener = null; + } + } + +} http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java ---------------------------------------------------------------------- diff --git a/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java b/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java index c3bf6e4..d5ad96b 100644 --- a/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java +++ b/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java @@ -17,13 +17,15 @@ import org.apache.karaf.cellar.core.Node; import org.apache.karaf.cellar.core.shell.CellarCommandSupport; import org.apache.karaf.cellar.dosgi.Constants; import org.apache.karaf.cellar.dosgi.EndpointDescription; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.table.ShellTable; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.lifecycle.Service; +import org.apache.karaf.shell.support.table.ShellTable; import java.util.Map; import java.util.Set; @Command(scope = "cluster", name = "service-list", description = "List the services available on the cluster") +@Service public class ListDistributedServicesCommand extends CellarCommandSupport { @Override http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/dosgi/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/dosgi/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/dosgi/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 51171fc..0000000 --- a/dosgi/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,58 +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"> - - <!-- Import Service Listener --> - <bean id="importServiceListener" class="org.apache.karaf.cellar.dosgi.ImportServiceListener" init-method="init" destroy-method="destroy"> - <property name="clusterManager" ref="clusterManager"/> - <property name="commandStore" ref="commandStore"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - <property name="eventTransportFactory" ref="eventTransportFactory"/> - </bean> - <service ref="importServiceListener" interface="org.osgi.framework.hooks.service.ListenerHook"/> - - <!-- Export Service Listener --> - <bean id="exportServiceListener" class="org.apache.karaf.cellar.dosgi.ExportServiceListener" init-method="init" destroy-method="destroy"> - <property name="clusterManager" ref="clusterManager"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - <property name="eventTransportFactory" ref="eventTransportFactory"/> - </bean> - - <!-- Remote Service Call Event Handler --> - <bean id="remoteServiceCallHandler" class="org.apache.karaf.cellar.dosgi.RemoteServiceCallHandler"> - <property name="clusterManager" ref="clusterManager"/> - <property name="eventTransportFactory" ref="eventTransportFactory"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - <property name="configurationAdmin" ref="configurationAdmin" /> - </bean> - <service ref="remoteServiceCallHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"> - <service-properties> - <entry key="managed" value="true"/> - </service-properties> - </service> - - <!-- Remote Service Result Event Handler --> - <bean id="remoteServiceResultHandler" class="org.apache.karaf.cellar.dosgi.RemoteServiceResultHandler"> - <property name="commandStore" ref="commandStore"/> - </bean> - <service ref="remoteServiceResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> - - <reference id="clusterManager" interface="org.apache.karaf.cellar.core.ClusterManager"/> - <reference id="eventTransportFactory" interface="org.apache.karaf.cellar.core.event.EventTransportFactory"/> - <reference id="commandStore" interface="org.apache.karaf.cellar.core.command.CommandStore"/> - <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/> - -</blueprint> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/dosgi/src/main/resources/OSGI-INF/blueprint/management.xml ---------------------------------------------------------------------- diff --git a/dosgi/src/main/resources/OSGI-INF/blueprint/management.xml b/dosgi/src/main/resources/OSGI-INF/blueprint/management.xml deleted file mode 100644 index 3b52c9a..0000000 --- a/dosgi/src/main/resources/OSGI-INF/blueprint/management.xml +++ /dev/null @@ -1,32 +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 Service MBean --> - <bean id="cellarServiceMBean" class="org.apache.karaf.cellar.dosgi.management.internal.ServiceMBeanImpl"> - <property name="clusterManager" ref="clusterManager"/> - </bean> - <service ref="cellarServiceMBean" auto-export="interfaces"> - <service-properties> - <entry key="jmx.objectname" value="org.apache.karaf.cellar:type=service,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/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml ---------------------------------------------------------------------- diff --git a/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml b/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml deleted file mode 100644 index c365313..0000000 --- a/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml +++ /dev/null @@ -1,25 +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 xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> - <command> - <action class="org.apache.karaf.cellar.dosgi.shell.ListDistributedServicesCommand"> - <property name="clusterManager" ref="clusterManager"/> - </action> - </command> - </command-bundle> - -</blueprint> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/event/NOTICE ---------------------------------------------------------------------- diff --git a/event/NOTICE b/event/NOTICE index addb35c..64cb235 100644 --- a/event/NOTICE +++ b/event/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/event/pom.xml ---------------------------------------------------------------------- diff --git a/event/pom.xml b/event/pom.xml index 5c01fb2..3ad8b67 100644 --- a/event/pom.xml +++ b/event/pom.xml @@ -40,6 +40,15 @@ <artifactId>org.apache.karaf.cellar.core</artifactId> </dependency> <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> + </dependency> + <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> <scope>provided</scope> @@ -56,18 +65,26 @@ <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.event*;version="${project.version}" + !org.apache.karaf.cellar.event.internal.osgi, + org.apache.karaf.cellar.event* </Export-Package> <Import-Package> - 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> + <Private-Package> + org.apache.karaf.cellar.event.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/event/src/main/java/org/apache/karaf/cellar/event/internal/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/event/src/main/java/org/apache/karaf/cellar/event/internal/osgi/Activator.java b/event/src/main/java/org/apache/karaf/cellar/event/internal/osgi/Activator.java new file mode 100644 index 0000000..e4810f1 --- /dev/null +++ b/event/src/main/java/org/apache/karaf/cellar/event/internal/osgi/Activator.java @@ -0,0 +1,97 @@ +/* + * 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.event.internal.osgi; + +import org.apache.karaf.cellar.core.ClusterManager; +import org.apache.karaf.cellar.core.GroupManager; +import org.apache.karaf.cellar.core.event.EventHandler; +import org.apache.karaf.cellar.core.event.EventProducer; +import org.apache.karaf.cellar.event.ClusterEventHandler; +import org.apache.karaf.cellar.event.LocalEventListener; +import org.apache.karaf.util.tracker.BaseActivator; +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.service.cm.ConfigurationAdmin; +import org.osgi.service.event.EventAdmin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Hashtable; + +@Services( + provides = { + @ProvideService(EventHandler.class), + @ProvideService(org.osgi.service.event.EventHandler.class) + }, + requires = { + @RequireService(ClusterManager.class), + @RequireService(GroupManager.class), + @RequireService(ConfigurationAdmin.class), + @RequireService(EventAdmin.class), + @RequireService(EventProducer.class) + } +) +public class Activator extends BaseActivator { + + private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class); + + private LocalEventListener localEventListener; + private ClusterEventHandler clusterEventHandler; + + @Override + public void doStart() throws Exception { + + ClusterManager clusterManager = getTrackedService(ClusterManager.class); + GroupManager groupManager = getTrackedService(GroupManager.class); + ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class); + EventAdmin eventAdmin = getTrackedService(EventAdmin.class); + EventProducer eventProducer = getTrackedService(EventProducer.class); + + LOGGER.debug("[CELLAR EVENTADMIN] Init event handler"); + clusterEventHandler = new ClusterEventHandler(); + clusterEventHandler.setConfigurationAdmin(configurationAdmin); + clusterEventHandler.setGroupManager(groupManager); + clusterEventHandler.setClusterManager(clusterManager); + clusterEventHandler.setEventAdmin(eventAdmin); + clusterEventHandler.init(); + Hashtable props = new Hashtable(); + props.put("managed", "true"); + register(EventHandler.class, clusterEventHandler, props); + + LOGGER.debug("[CELLAR EVENTADMIN] Init local event listener"); + localEventListener = new LocalEventListener(); + localEventListener.setClusterManager(clusterManager); + localEventListener.setGroupManager(groupManager); + localEventListener.setConfigurationAdmin(configurationAdmin); + localEventListener.setEventProducer(eventProducer); + localEventListener.init(); + props = new Hashtable(); + props.put("event.topics", "*"); + register(org.osgi.service.event.EventHandler.class, localEventListener, props); + } + + @Override + public void doStop() { + if (localEventListener != null) { + localEventListener.destroy(); + localEventListener = null; + } + if (clusterEventHandler != null) { + clusterEventHandler.destroy(); + clusterEventHandler = null; + } + } + +} http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 577b34c..0000000 --- a/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,60 +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 Event Listener --> - <bean id="localEventListener" class="org.apache.karaf.cellar.event.LocalEventListener" init-method="init" destroy-method="destroy"> - <property name="clusterManager" ref="clusterManager"/> - <property name="groupManager" ref="groupManager"/> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="eventProducer" ref="eventProducer"/> - </bean> - <service ref="localEventListener"> - <interfaces> - <value>org.osgi.service.event.EventHandler</value> - </interfaces> - <service-properties> - <entry key="event.topics"> - <array value-type="java.lang.String"> - <value>*</value> - </array> - </entry> - </service-properties> - </service> - - <!-- Cluster Event Handler --> - <bean id="clusterEventHandler" class="org.apache.karaf.cellar.event.ClusterEventHandler" init-method="init" destroy-method="destroy"> - <property name="configurationAdmin" ref="configurationAdmin"/> - <property name="groupManager" ref="groupManager"/> - <property name="clusterManager" ref="clusterManager"/> - <property name="eventAdmin" ref="eventAdmin"/> - </bean> - <service ref="clusterEventHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"> - <service-properties> - <entry key="managed" value="true"/> - </service-properties> - </service> - - <reference id="clusterManager" interface="org.apache.karaf.cellar.core.ClusterManager"/> - <reference id="groupManager" interface="org.apache.karaf.cellar.core.GroupManager"/> - <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/> - <reference id="eventAdmin" interface="org.osgi.service.event.EventAdmin" /> - <reference id="eventProducer" interface="org.apache.karaf.cellar.core.event.EventProducer"/> - -</blueprint> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/NOTICE ---------------------------------------------------------------------- diff --git a/features/NOTICE b/features/NOTICE index addb35c..64cb235 100644 --- a/features/NOTICE +++ b/features/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/features/pom.xml ---------------------------------------------------------------------- diff --git a/features/pom.xml b/features/pom.xml index ed3f00a..075e79f 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -40,8 +40,12 @@ <artifactId>org.apache.karaf.cellar.core</artifactId> </dependency> <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.util</artifactId> + </dependency> + <dependency> <groupId>org.apache.karaf.shell</groupId> - <artifactId>org.apache.karaf.shell.table</artifactId> + <artifactId>org.apache.karaf.shell.core</artifactId> </dependency> <dependency> <groupId>org.osgi</groupId> @@ -59,10 +63,6 @@ <groupId>org.apache.karaf.features</groupId> <artifactId>org.apache.karaf.features.core</artifactId> </dependency> - <dependency> - <groupId>org.apache.karaf.features</groupId> - <artifactId>org.apache.karaf.features.command</artifactId> - </dependency> <!-- Logging --> <dependency> @@ -92,29 +92,28 @@ <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.features*;version="${project.version}" + !org.apache.karaf.cellar.features.management.internal, + !org.apache.karaf.cellar.features.internal.osgi, + org.apache.karaf.cellar.features* </Export-Package> <Import-Package> - javax.management*, - org.apache.karaf.cellar.core*;version="${project.version}", - org.apache.felix.service.command, - org.apache.felix.gogo.commands, - org.apache.karaf.shell.console;version="[3,5)", - org.apache.karaf.shell.console.commands;version="[3,5)", - org.apache.karaf.shell.console.completer;version="[3,5)", - org.apache.karaf.shell.table;version="[3,5)", - org.apache.karaf.shell.commands;version="[3,5)", - org.apache.karaf.features*;version="[3,5)", - org.osgi*, - org.slf4j;version="[1.6,2)";resolution:=optional + org.slf4j;version="[1.6,2)";resolution:=optional, + org.apache.karaf.shell*;resolution:=optional, + * </Import-Package> <Private-Package> - org.apache.karaf.cellar.features.management.internal + org.apache.karaf.cellar.features.management.internal, + org.apache.karaf.cellar.features.internal.osgi, + 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/features/src/main/java/org/apache/karaf/cellar/features/internal/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/internal/osgi/Activator.java b/features/src/main/java/org/apache/karaf/cellar/features/internal/osgi/Activator.java new file mode 100644 index 0000000..e8ea14a --- /dev/null +++ b/features/src/main/java/org/apache/karaf/cellar/features/internal/osgi/Activator.java @@ -0,0 +1,150 @@ +/* + * 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.features.internal.osgi; + +import org.apache.karaf.cellar.core.ClusterManager; +import org.apache.karaf.cellar.core.GroupManager; +import org.apache.karaf.cellar.core.Synchronizer; +import org.apache.karaf.cellar.core.event.EventProducer; +import org.apache.karaf.cellar.features.FeaturesEventHandler; +import org.apache.karaf.cellar.features.FeaturesSynchronizer; +import org.apache.karaf.cellar.features.LocalFeaturesListener; +import org.apache.karaf.cellar.features.RepositoryEventHandler; +import org.apache.karaf.cellar.features.management.internal.CellarFeaturesMBeanImpl; +import org.apache.karaf.features.FeaturesListener; +import org.apache.karaf.features.FeaturesService; +import org.apache.karaf.util.tracker.BaseActivator; +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.ServiceRegistration; +import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.service.event.EventHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Hashtable; + +@Services( + provides = { + @ProvideService(FeaturesListener.class), + @ProvideService(Synchronizer.class), + @ProvideService(EventHandler.class) + }, + requires = { + @RequireService(ClusterManager.class), + @RequireService(GroupManager.class), + @RequireService(EventProducer.class), + @RequireService(ConfigurationAdmin.class), + @RequireService(FeaturesService.class) + } +) +public class Activator extends BaseActivator { + + private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class); + + private LocalFeaturesListener localFeaturesListener; + private FeaturesSynchronizer featuresSynchronizer; + private FeaturesEventHandler featuresEventHandler; + private RepositoryEventHandler repositoryEventHandler; + private ServiceRegistration mbeanRegistration; + + @Override + public void doStart() throws Exception { + + ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class); + ClusterManager clusterManager = getTrackedService(ClusterManager.class); + GroupManager groupManager = getTrackedService(GroupManager.class); + EventProducer eventProducer = getTrackedService(EventProducer.class); + FeaturesService featuresService = getTrackedService(FeaturesService.class); + + LOGGER.debug("[CELLAR FEATURES] Init repository event handler"); + repositoryEventHandler = new RepositoryEventHandler(); + repositoryEventHandler.setConfigurationAdmin(configurationAdmin); + repositoryEventHandler.setFeaturesService(featuresService); + repositoryEventHandler.setClusterManager(clusterManager); + repositoryEventHandler.setGroupManager(groupManager); + repositoryEventHandler.init(); + Hashtable props = new Hashtable(); + props.put("managed", "true"); + register(new Class[]{ EventHandler.class }, repositoryEventHandler, props); + + LOGGER.debug("[CELLAR FEATURES] Init features event handler"); + featuresEventHandler = new FeaturesEventHandler(); + featuresEventHandler.setFeaturesService(featuresService); + featuresEventHandler.setClusterManager(clusterManager); + featuresEventHandler.setGroupManager(groupManager); + featuresEventHandler.setConfigurationAdmin(configurationAdmin); + featuresEventHandler.init(); + register(new Class[]{ EventHandler.class }, featuresEventHandler, props); + + LOGGER.debug("[CELLAR FEATURES] Init local features listener"); + localFeaturesListener = new LocalFeaturesListener(); + localFeaturesListener.setClusterManager(clusterManager); + localFeaturesListener.setGroupManager(groupManager); + localFeaturesListener.setEventProducer(eventProducer); + localFeaturesListener.setConfigurationAdmin(configurationAdmin); + localFeaturesListener.setFeaturesService(featuresService); + localFeaturesListener.init(); + register(FeaturesListener.class, localFeaturesListener); + + LOGGER.debug("[CELLAR FEATURES] Init features synchronizer"); + featuresSynchronizer = new FeaturesSynchronizer(); + featuresSynchronizer.setClusterManager(clusterManager); + featuresSynchronizer.setGroupManager(groupManager); + featuresSynchronizer.setConfigurationAdmin(configurationAdmin); + featuresSynchronizer.setFeaturesService(featuresService); + featuresSynchronizer.init(); + props = new Hashtable(); + props.put("resource", "feature"); + register(Synchronizer.class, featuresSynchronizer, props); + + LOGGER.debug("[CELLAR FEATURES] Register MBean"); + CellarFeaturesMBeanImpl mbean = new CellarFeaturesMBeanImpl(); + mbean.setClusterManager(clusterManager); + mbean.setGroupManager(groupManager); + mbean.setConfigurationAdmin(configurationAdmin); + mbean.setFeaturesService(featuresService); + mbean.setEventProducer(eventProducer); + props = new Hashtable(); + props.put("jmx.objectname", "org.apache.karaf.cellar:type=feature,name=" + System.getProperty("karaf.name")); + mbeanRegistration = bundleContext.registerService(getInterfaceNames(mbean), mbean, props); + + } + + @Override + public void doStop() { + if (mbeanRegistration != null) { + mbeanRegistration.unregister(); + mbeanRegistration = null; + } + if (featuresSynchronizer != null) { + featuresSynchronizer.destroy(); + featuresSynchronizer = null; + } + if (localFeaturesListener != null) { + localFeaturesListener.destroy(); + localFeaturesListener = null; + } + if (featuresEventHandler != null) { + featuresEventHandler.destroy(); + featuresEventHandler = null; + } + if (repositoryEventHandler != null) { + repositoryEventHandler.destroy(); + repositoryEventHandler = null; + } + } + +} http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/java/org/apache/karaf/cellar/features/shell/BlockCommand.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/BlockCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/BlockCommand.java index cf9143d..eb246e7 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/shell/BlockCommand.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/BlockCommand.java @@ -18,17 +18,22 @@ 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.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.Service; import java.util.Set; @Command(scope = "cluster", name = "feature-block", description = "Change the blocking policy for a feature") +@Service public class BlockCommand 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 = "featurePattern", description = "The feature pattern to block.", required = false, multiValued = false) http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/3e5e7c33/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java index 9c36e7e..2a43ed6 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java @@ -20,19 +20,24 @@ 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.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.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-install", description = "Install a feature in a cluster group") +@Service public class InstallFeatureCommand extends CellarCommandSupport { @Option(name = "-c", aliases = {"--no-clean"}, description = "Do not uninstall bundles on failure", required = false, multiValued = false) @@ -45,12 +50,16 @@ public class InstallFeatureCommand extends CellarCommandSupport { boolean noStart; @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 install. A feature id looks like name/version. The version is optional.", required = true, multiValued = true) List<String> features; + @Reference private EventProducer eventProducer; + + @Reference private FeaturesService featuresService; @Override
