You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2016/06/23 12:49:20 UTC
aries-rsa git commit: [ARIES-1583] RSA discovery commands
Repository: aries-rsa
Updated Branches:
refs/heads/master 69c4d82ae -> 28b402195
[ARIES-1583] RSA discovery commands
Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/28b40219
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/28b40219
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/28b40219
Branch: refs/heads/master
Commit: 28b402195fe02ce2204cabf12021f8544190a280
Parents: 69c4d82
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Thu Jun 23 14:49:13 2016 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Thu Jun 23 14:49:13 2016 +0200
----------------------------------------------------------------------
discovery/command/Readme.md | 15 +++
discovery/command/bnd.bnd | 3 +
discovery/command/pom.xml | 47 ++++++++
.../rsa/discovery/command/EndpointsCommand.java | 115 +++++++++++++++++++
discovery/pom.xml | 1 +
features/src/main/resources/features.xml | 2 +
6 files changed, 183 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/28b40219/discovery/command/Readme.md
----------------------------------------------------------------------
diff --git a/discovery/command/Readme.md b/discovery/command/Readme.md
new file mode 100644
index 0000000..622e6ff
--- /dev/null
+++ b/discovery/command/Readme.md
@@ -0,0 +1,15 @@
+# Discovery Gogo Commands
+
+
+## endpoints
+
+Lists all discovered endpoints
+
+ endpoints
+
+## endpoint
+
+Shows the properties of an endpoint identified by its id
+
+
+ endpoint <id>
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/28b40219/discovery/command/bnd.bnd
----------------------------------------------------------------------
diff --git a/discovery/command/bnd.bnd b/discovery/command/bnd.bnd
new file mode 100644
index 0000000..129d0df
--- /dev/null
+++ b/discovery/command/bnd.bnd
@@ -0,0 +1,3 @@
+Private-Package: \
+ org.apache.karaf.shell.table,\
+ org.apache.aries.rsa.discovery.command
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/28b40219/discovery/command/pom.xml
----------------------------------------------------------------------
diff --git a/discovery/command/pom.xml b/discovery/command/pom.xml
new file mode 100644
index 0000000..9d2c077
--- /dev/null
+++ b/discovery/command/pom.xml
@@ -0,0 +1,47 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ you under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.aries.rsa</groupId>
+ <artifactId>org.apache.aries.rsa.parent</artifactId>
+ <version>1.9-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.aries.rsa.discovery</groupId>
+ <artifactId>org.apache.aries.rsa.discovery.command</artifactId>
+ <packaging>bundle</packaging>
+ <name>Aries Remote Service Admin Discovery Gogo Commands</name>
+
+ <properties>
+ <topDirectoryLocation>../..</topDirectoryLocation>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.rsa</groupId>
+ <artifactId>org.apache.aries.rsa.spi</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.table</artifactId>
+ <version>4.0.5</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/28b40219/discovery/command/src/main/java/org/apache/aries/rsa/discovery/command/EndpointsCommand.java
----------------------------------------------------------------------
diff --git a/discovery/command/src/main/java/org/apache/aries/rsa/discovery/command/EndpointsCommand.java b/discovery/command/src/main/java/org/apache/aries/rsa/discovery/command/EndpointsCommand.java
new file mode 100644
index 0000000..7a8580f
--- /dev/null
+++ b/discovery/command/src/main/java/org/apache/aries/rsa/discovery/command/EndpointsCommand.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.rsa.discovery.command;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.karaf.shell.table.ShellTable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.EndpointListener;
+
+@Component(//
+ property = {
+ "osgi.command.scope=rsa", //
+ "osgi.command.function=endpoints",
+ "osgi.command.function=endpoint",
+ "endpoint.listener.scope=(endpoint.framework.uuid=*)"
+
+ })
+public class EndpointsCommand implements EndpointListener {
+ Set<EndpointDescription> endpoints = new HashSet<>();
+ private String frameworkId;
+
+ @Activate
+ public void activate(BundleContext context) {
+ this.frameworkId = context.getProperty(Constants.FRAMEWORK_UUID);
+ }
+
+ public void endpoint(String id) {
+ EndpointDescription epd = getEndpoint(id);
+ ShellTable table = new ShellTable();
+ table.column("key");
+ table.column("value");
+
+ for (String key : epd.getProperties().keySet()) {
+ Object value = epd.getProperties().get(key);
+ table.addRow().addContent(key, toString(value));
+ }
+ table.print(System.out);
+ }
+
+ private Object toString(Object value) {
+ if (value == null) {
+ return "null";
+ }
+ if (value.getClass().isArray()) {
+ return Arrays.toString((Object[])value);
+ }
+ return value.toString();
+ }
+
+ private EndpointDescription getEndpoint(String id) {
+ for (EndpointDescription epd : endpoints) {
+ if (epd.getId().equals(id)) {
+ return epd;
+ }
+ }
+ throw new IllegalArgumentException("No endpoint found for id " + id);
+ }
+
+ public void endpoints() {
+ System.out.println("Endpoints for framework " + frameworkId);
+ ShellTable table = new ShellTable();
+ table.column("id");
+ table.column("interfaces");
+ table.column("framework");
+ table.column("comp name");
+ for (EndpointDescription epd : endpoints) {
+ print(table, epd);
+ }
+ table.print(System.out);
+ }
+
+ private void print(ShellTable table, EndpointDescription ep) {
+ String compName = getProp(ep, "component.name");
+ table.addRow().addContent(ep.getId(), ep.getInterfaces(), ep.getFrameworkUUID(), compName);
+ }
+
+ private String getProp(EndpointDescription ep, String key) {
+ Object value = ep.getProperties().get(key);
+ return value == null ? "" : value.toString();
+ }
+
+ @Override
+ public void endpointAdded(EndpointDescription endpoint, String matchedFilter) {
+ endpoints.add(endpoint);
+ }
+
+ @Override
+ public void endpointRemoved(EndpointDescription endpoint, String matchedFilter) {
+ endpoints.remove(endpoint);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/28b40219/discovery/pom.xml
----------------------------------------------------------------------
diff --git a/discovery/pom.xml b/discovery/pom.xml
index bd9a940..c370ee5 100644
--- a/discovery/pom.xml
+++ b/discovery/pom.xml
@@ -35,5 +35,6 @@
<module>local</module>
<module>zookeeper</module>
<module>config</module>
+ <module>command</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/28b40219/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/features/src/main/resources/features.xml b/features/src/main/resources/features.xml
index a109ce0..5a1e2fb 100644
--- a/features/src/main/resources/features.xml
+++ b/features/src/main/resources/features.xml
@@ -2,9 +2,11 @@
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="aries-rsa-${project.version}">
<feature name="aries-rsa-core" version="${project.version}">
+ <feature>scr</feature>
<bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.spi/${project.version}</bundle>
<bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.core/${project.version}</bundle>
<bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.topology-manager/${project.version}</bundle>
+ <bundle>mvn:org.apache.aries.rsa.discovery/org.apache.aries.rsa.discovery.command/${project.version}</bundle>
<conditional>
<condition>eventadmin</condition>
<bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.eapub/${project.version}</bundle>