tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1124705 - in /tuscany/sca-java-2.x/trunk/modules: core-spi/src/main/java/org/apache/tuscany/sca/runtime/ core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/ domain-...
Date Thu, 19 May 2011 12:21:56 GMT
Author: antelder
Date: Thu May 19 12:21:55 2011
New Revision: 1124705

URL: http://svn.apache.org/viewvc?rev=1124705&view=rev
Log:
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

Added:
    tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java
    tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java
Modified:
    tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java
    tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
    tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
    tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
    tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
    tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java
    tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java

Added: tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java?rev=1124705&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java
(added)
+++ tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java
Thu May 19 12:21:55 2011
@@ -0,0 +1,32 @@
+/*
+ * 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.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ActiveNodes {
+
+    List<Object> activeNodes = new ArrayList<Object>();
+    
+    public  List<Object> getActiveNodes() {
+        return activeNodes;
+    }
+}

Modified: tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java?rev=1124705&r1=1124704&r2=1124705&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java
Thu May 19 12:21:55 2011
@@ -22,6 +22,7 @@ package org.apache.tuscany.sca.runtime;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.assembly.Endpoint;
@@ -96,4 +97,6 @@ public interface DomainRegistry {
     List<String> getMembers();
     String getLocalMember();
     String getRunningMember(String contributionURI, String compositeURI);
+    
+    String remoteCommand(String memberName, Callable<String> command);
 }

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java?rev=1124705&r1=1124704&r2=1124705&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java
Thu May 19 12:21:55 2011
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.Callable;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -243,4 +244,10 @@ public class DomainRegistryImpl extends 
     public String getRunningMember(String contributionURI, String compositeURI) {
         return LOCAL_MEMBER_NAME;
     }
+
+    @Override
+    public String remoteCommand(String memberName, Callable<String> command) {
+        // TODO or should it just ensure the member name is LocalOnly and the run the command
locally?
+        throw new IllegalStateException("not supportted for " + LOCAL_MEMBER_NAME);
+    }
 }

Modified: tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java?rev=1124705&r1=1124704&r2=1124705&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
Thu May 19 12:21:55 2011
@@ -30,6 +30,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.Callable;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
@@ -894,5 +895,11 @@ public class DeployerImpl implements Dep
             // TODO Auto-generated method stub
             return null;
         }
+
+        @Override
+        public String remoteCommand(String memberName, Callable<String> command) {
+            // TODO Auto-generated method stub
+            return null;
+        }
     }
 }

Modified: tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java?rev=1124705&r1=1124704&r2=1124705&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
Thu May 19 12:21:55 2011
@@ -30,7 +30,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.FutureTask;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -72,6 +74,7 @@ import com.hazelcast.config.Config;
 import com.hazelcast.config.NearCacheConfig;
 import com.hazelcast.config.TcpIpConfig;
 import com.hazelcast.config.XmlConfigBuilder;
+import com.hazelcast.core.DistributedTask;
 import com.hazelcast.core.EntryEvent;
 import com.hazelcast.core.EntryListener;
 import com.hazelcast.core.Hazelcast;
@@ -679,4 +682,20 @@ public class HazelcastDomainRegistry ext
         }
         return null;
     }
+
+    @Override
+    public String remoteCommand(String memberName, Callable<String> command) {
+        for (Member member : hazelcastInstance.getCluster().getMembers()) {
+            if (member.getInetSocketAddress().toString().equals(memberName)) {
+                FutureTask<String> task = new DistributedTask<String>(command,
member);
+                hazelcastInstance.getExecutorService().execute(task);
+                try {
+                    return task.get();
+                } catch (Exception e) {
+                    throw new ServiceRuntimeException(e);
+                }
+            }
+        }
+        throw new IllegalArgumentException("member not found: " + memberName);
+    }
 }

Modified: tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java?rev=1124705&r1=1124704&r2=1124705&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
Thu May 19 12:21:55 2011
@@ -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

Modified: tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java?rev=1124705&r1=1124704&r2=1124705&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
Thu May 19 12:21:55 2011
@@ -46,10 +46,12 @@ import org.apache.tuscany.sca.contributi
 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));
+    }
+
 }

Added: tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java?rev=1124705&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java
(added)
+++ tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java
Thu May 19 12:21:55 2011
@@ -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);
+    }
+
+}

Modified: tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java?rev=1124705&r1=1124704&r2=1124705&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java
Thu May 19 12:21:55 2011
@@ -31,6 +31,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.concurrent.Callable;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -493,4 +494,10 @@ public class ReplicatedDomainRegistry ex
         return null;
     }
 
+    @Override
+    public String remoteCommand(String memberName, Callable<String> command) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }

Modified: tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java?rev=1124705&r1=1124704&r2=1124705&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
Thu May 19 12:21:55 2011
@@ -73,7 +73,7 @@ public class Shell {
     private Map<String, Node> nodes = new HashMap<String, Node>();
 
     public static final String[] COMMANDS = new String[] {"bye", "domain", "domains", "domainComposite",
"help", "install", "installed", "invoke",
-                                                          "load", "members", "remove", "run",
"save", "services", "start", "started", "stop"};
+                                                          "load", "members", "remoteStart",
"remoteStop", "remove", "run", "save", "services", "start", "started", "stop"};
 
     public static void main(final String[] args) throws Exception {
         boolean useJline = true;
@@ -444,6 +444,17 @@ public class Shell {
         return true;
     }
 
+    boolean remoteStart(final List<String> toks) {
+        String response = getNode().remoteStart(toks.get(1), toks.get(2), toks.get(3));
+        out.println(response);
+        return true;
+    }
+    boolean remoteStop(final List<String> toks) {
+        String response = getNode().remoteStop(toks.get(1), toks.get(2), toks.get(3));
+        out.println(response);
+        return true;
+    }
+
     boolean started(final List<String> toks) {
         if (standaloneNodes.size() > 0) {
             out.println("Standalone Nodes:");
@@ -662,6 +673,18 @@ public class Shell {
                     return bye();
                 }
             };
+        if (op.equalsIgnoreCase("remoteStart"))
+            return new Callable<Boolean>() {
+                public Boolean call() throws Exception {
+                    return remoteStart(toks);
+                }
+            };
+        if (op.equalsIgnoreCase("remoteStop"))
+            return new Callable<Boolean>() {
+                public Boolean call() throws Exception {
+                    return remoteStop(toks);
+                    }
+                };
         if (op.equalsIgnoreCase("start"))
             return new Callable<Boolean>() {
                 public Boolean call() throws Exception {



Mime
View raw message