summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/domain-node/src/main/java/org
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-05-19 12:21:55 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-05-19 12:21:55 +0000
commitc737cb99bcd1c364fe5f7f66c3662dee75ea7ae9 (patch)
tree85aa143c894131b294ce2f22c1ab722ab93bba6f /sca-java-2.x/trunk/modules/domain-node/src/main/java/org
parenta5707c170d3ce4aaecd9956cb1935305709b91d1 (diff)
Add a way to run commands on remote nodes and add Node API and Shell commands to start and stop composites on remote nodes. Initial code so a little prototypy but it does work so committing it now for review
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1124705 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/domain-node/src/main/java/org')
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java3
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java17
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java83
3 files changed, 102 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
index 89eeb09c2c..8889e369bf 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
@@ -243,6 +243,9 @@ public interface Node {
List<String> getMembers();
String getLocalMember();
String getRunningMember(String contributionURI, String compositeURI);
+
+ String remoteStart(String member, String contributionURI, String compositeURI);
+ String remoteStop(String member, String contributionURI, String compositeURI);
// TODO: Add methods to get:
// start and stop composites on remote members
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
index 2c15a4464b..7cfe60a543 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
@@ -46,10 +46,12 @@ import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.deployment.Deployer;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.ValidationException;
import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.ActiveNodes;
import org.apache.tuscany.sca.runtime.CompositeActivator;
import org.apache.tuscany.sca.runtime.ContributionListener;
import org.apache.tuscany.sca.runtime.DomainRegistry;
@@ -82,7 +84,9 @@ public class NodeImpl implements Node {
this.domainRegistry = domainRegistry;
this.extensionPointRegistry = extensionPointRegistry;
this.tuscanyRuntime = tuscanyRuntime;
-
+
+ extensionPointRegistry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(ActiveNodes.class).getActiveNodes().add(this);
+
domainRegistry.addContributionListener(new ContributionListener() {
public void contributionUpdated(String uri) {
loadedContributions.remove(uri);
@@ -384,6 +388,7 @@ public class NodeImpl implements Node {
}
startedComposites.clear();
stoppedComposites.clear();
+ extensionPointRegistry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(ActiveNodes.class).getActiveNodes().remove(this);
if (tuscanyRuntime != null) {
tuscanyRuntime.stop();
}
@@ -404,4 +409,14 @@ public class NodeImpl implements Node {
return domainRegistry.getRunningMember(contributionURI, compositeURI);
}
+ @Override
+ public String remoteStart(String memberName, String contributionURI, String compositeURI) {
+ return domainRegistry.remoteCommand(memberName, new RemoteCommand(domainName, "start", contributionURI, compositeURI));
+ }
+
+ @Override
+ public String remoteStop(String memberName, String contributionURI, String compositeURI) {
+ return domainRegistry.remoteCommand(memberName, new RemoteCommand(domainName, "stop", contributionURI, compositeURI));
+ }
+
}
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java
new file mode 100644
index 0000000000..5e150dba02
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java
@@ -0,0 +1,83 @@
+/*
+ * 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.tuscany.sca.impl;
+
+import java.io.Serializable;
+import java.util.concurrent.Callable;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistryLocator;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.runtime.ActiveNodes;
+
+public class RemoteCommand implements Callable<String>, Serializable {
+ private static final long serialVersionUID = 1L;
+
+ // all fields MUST be Serializable
+ private String domainName;
+ private String command;
+ private String contributionURI;
+ private String compositeURI;
+
+ public RemoteCommand(String domainName, String command, String contributionURI, String compositeURI) {
+ this.domainName = domainName;
+ this.command = command;
+ this.contributionURI = contributionURI;
+ this.compositeURI = compositeURI;
+ }
+
+ public String call() throws Exception {
+ String response;
+ try {
+ Node node = getNode();
+
+ if ("start".equals(command)) {
+ node.startComposite(contributionURI, compositeURI);
+ response = "Started.";
+ } else if ("stop".equals(command)) {
+ node.stopComposite(contributionURI, compositeURI);
+ response = "Stopped.";
+ } else {
+ response = "Unknown command: " + command;
+ }
+ } catch (Exception e) {
+ response = "REMOTE EXCEPTION: " + e.getClass() + ":" + e.getMessage();
+ }
+ return response;
+ }
+
+ private Node getNode() {
+ // TODO Several places in Tuscany need to do this type of thing, for example, processing
+ // async responses, so we need to design a "proper" way to do it
+
+ for (ExtensionPointRegistry xpr : ExtensionPointRegistryLocator.getExtensionPointRegistries()) {
+ ActiveNodes activeNodes = xpr.getExtensionPoint(UtilityExtensionPoint.class).getUtility(ActiveNodes.class);
+ for (Object o : activeNodes.getActiveNodes()) {
+ Node node = (Node)o;
+ if (node.getDomainName().equals(domainName)) {
+ return node;
+ }
+ }
+ }
+ throw new IllegalStateException("No remote Node found for domain: " + domainName);
+ }
+
+}