geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r693451 - in /geronimo/server/trunk/plugins/clustering: ./ geronimo-deploy-farm/ geronimo-farm/ geronimo-farm/src/main/java/org/apache/geronimo/farm/config/ geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/ geronimo-plugin-far...
Date Tue, 09 Sep 2008 12:44:38 GMT
Author: djencks
Date: Tue Sep  9 05:44:36 2008
New Revision: 693451

URL: http://svn.apache.org/viewvc?rev=693451&view=rev
Log:
GERONIMO-4284 add discovery based on code from activemq via openejb

Added:
    geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/
      - copied from r692989, openejb/trunk/openejb3/server/openejb-discovery/src/main/java/org/apache/openejb/server/discovery/
    geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/JmxDiscoveryPublisher.java   (with props)
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmDiscoveryListener.java   (with props)
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/NodeListener.java   (with props)
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/ListenerTest.java   (with props)
    geronimo/server/trunk/plugins/clustering/plugin-farm-member/
      - copied from r692915, geronimo/server/trunk/plugins/clustering/plugin-farm/
Modified:
    geronimo/server/trunk/plugins/clustering/geronimo-deploy-farm/pom.xml
    geronimo/server/trunk/plugins/clustering/geronimo-farm/pom.xml
    geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/config/BasicExtendedJMXConnectorInfo.java
    geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryAgent.java
    geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryListener.java
    geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastDiscoveryAgent.java
    geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastSearch.java
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/pom.xml
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmGBean.java
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaClusterInfo.java
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaNodeInfo.java
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaPluginList.java
    geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/TestGBean.java
    geronimo/server/trunk/plugins/clustering/plugin-farm-it/pom.xml
    geronimo/server/trunk/plugins/clustering/plugin-farm-member/pom.xml
    geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/history/dependencies.xml
    geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/plan/plan.xml
    geronimo/server/trunk/plugins/clustering/plugin-farm/src/main/plan/plan.xml
    geronimo/server/trunk/plugins/clustering/pom.xml

Modified: geronimo/server/trunk/plugins/clustering/geronimo-deploy-farm/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-deploy-farm/pom.xml?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-deploy-farm/pom.xml (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-deploy-farm/pom.xml Tue Sep  9 05:44:36 2008
@@ -30,7 +30,7 @@
     
     <groupId>org.apache.geronimo.modules</groupId>
     <artifactId>geronimo-deploy-farm</artifactId>
-    <name>Geronimo Plugins, Clustering :: Farm</name>
+    <name>Geronimo Plugins, Clustering :: Farm using Deployment</name>
     
     <dependencies>
         <dependency>

Modified: geronimo/server/trunk/plugins/clustering/geronimo-farm/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-farm/pom.xml?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-farm/pom.xml (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-farm/pom.xml Tue Sep  9 05:44:36 2008
@@ -30,7 +30,7 @@
     
     <groupId>org.apache.geronimo.modules</groupId>
     <artifactId>geronimo-farm</artifactId>
-    <name>Geronimo Plugins, Clustering :: Farm</name>
+    <name>Geronimo Plugins, Clustering :: Farm core</name>
     
     <dependencies>
 

Modified: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/config/BasicExtendedJMXConnectorInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/config/BasicExtendedJMXConnectorInfo.java?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/config/BasicExtendedJMXConnectorInfo.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/config/BasicExtendedJMXConnectorInfo.java Tue Sep  9 05:44:36 2008
@@ -35,12 +35,16 @@
 import org.apache.geronimo.deployment.service.EncryptOnPersist;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.system.jmx.KernelDelegate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  *
  * @version $Rev:$ $Date:$
  */
 public class BasicExtendedJMXConnectorInfo implements ExtendedJMXConnectorInfo, Serializable {
+
+    private static Logger log = LoggerFactory.getLogger(BasicExtendedJMXConnectorInfo.class);
     private String username;
     private String password;
     private String protocol;
@@ -66,6 +70,13 @@
         return host;
     }
 
+    public String getUsableHost() {
+        if ("0.0.0.0".equals(host)) {
+            return "localhost";
+        }
+        return host;
+    }
+
     @DoNotPersist
     public InetSocketAddress getListenAddress() {
         return new InetSocketAddress(host, port);
@@ -126,7 +137,7 @@
 
     public JMXConnector connect() throws IOException {
         String url = getJmxURI();
-
+        log.info("Attempting to connect to " + url + " with username " + getUsername() + " and password " + getPassword());
         Map<String, ?> environment = Collections.singletonMap("jmx.remote.credentials",
             new String[] {getUsername(), getPassword()});
 
@@ -139,8 +150,8 @@
     }
 
     protected String getJmxURI() {
-        return "service:jmx:rmi://" + getHost() + "/jndi/"
-                        + getProtocol() + "://" + getHost() + ":"
+        return "service:jmx:rmi://" + getUsableHost() + "/jndi/"
+                        + getProtocol() + "://" + getUsableHost() + ":"
                         + getPort() + "/" + getUrlPath();
 
     }

Modified: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryAgent.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryAgent.java?rev=693451&r1=692989&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryAgent.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryAgent.java Tue Sep  9 05:44:36 2008
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.openejb.server.discovery;
+package org.apache.geronimo.farm.discovery;
 
 import java.net.URI;
 import java.io.IOException;
@@ -25,21 +25,21 @@
 public interface DiscoveryAgent {
     /**
      * Sets the discovery listener
-     * @param listener
+     * @param listener listener for addeed/removed services
      */
     void setDiscoveryListener(DiscoveryListener listener);
 
     /**
      * register a service
-     * @param serviceUri
-     * @param details
+     * @param serviceUri uri for new service
+     * @throws java.io.IOException on error
      */
     void registerService(URI serviceUri) throws IOException;
 
     /**
      * register a service
-     * @param serviceUri
-     * @param details
+     * @param serviceUri uri for removed service
+     * @throws java.io.IOException on error
      */
     void unregisterService(URI serviceUri) throws IOException;
 
@@ -47,6 +47,8 @@
      * A process actively using a service may see it go down before the DiscoveryAgent notices the
      * service's failure.  That process can use this method to notify the DiscoveryAgent of the failure
      * so that other listeners of this DiscoveryAgent can also be made aware of the failure.
+     * @param serviceUri uri for failed service
+     * @throws java.io.IOException on error
      */
     void reportFailed(URI serviceUri) throws IOException;
 

Modified: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryListener.java?rev=693451&r1=692989&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryListener.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/DiscoveryListener.java Tue Sep  9 05:44:36 2008
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.openejb.server.discovery;
+package org.apache.geronimo.farm.discovery;
 
 
 import java.net.URI;

Added: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/JmxDiscoveryPublisher.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/JmxDiscoveryPublisher.java?rev=693451&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/JmxDiscoveryPublisher.java (added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/JmxDiscoveryPublisher.java Tue Sep  9 05:44:36 2008
@@ -0,0 +1,89 @@
+/*
+ * 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.geronimo.farm.discovery;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.io.IOException;
+
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.annotation.ParamReference;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.kernel.rmi.RMIRegistryService;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+@GBean
+public class JmxDiscoveryPublisher implements GBeanLifecycle {
+
+    private final URI service;
+    private final DiscoveryAgent discoveryAgent;
+
+    public JmxDiscoveryPublisher(@ParamAttribute(name = "nodeName")String nodeName,
+                                 @ParamAttribute(name = "clusterName")String clusterName,
+                                 @ParamAttribute(name = "protocol")String protocol,
+                                 @ParamAttribute(name = "urlPath")String urlPath,
+                                 @ParamAttribute(name = "discoveryType")String discoveryType,
+                                 @ParamReference(name = "DiscoveryAgent")DiscoveryAgent discoveryAgent,
+                                 @ParamReference(name = "RMIRegistryService")RMIRegistryService rmiRegistryService
+    ) throws URISyntaxException, IOException {
+        this.discoveryAgent = discoveryAgent;
+        String query = null;
+        if (nodeName != null) {
+            query = "node=" + nodeName;
+        }
+        if (clusterName != null) {
+            query = (query == null? "": query + "&") + "cluster=" + clusterName;
+        }
+        service = new URI(discoveryType + ":" + protocol, null,  rmiRegistryService.getHost(), rmiRegistryService.getPort(), "/" + urlPath , query, null);
+        discoveryAgent.registerService(service);
+    }
+
+    /**
+     * Starts the GBean.  This informs the GBean that it is about to transition to the running state.
+     *
+     * @throws Exception if the target failed to start; this will cause a transition to the failed state
+     */
+    public void doStart() throws Exception {
+    }
+
+    /**
+     * Stops the target.  This informs the GBean that it is about to transition to the stopped state.
+     *
+     * @throws Exception if the target failed to stop; this will cause a transition to the failed state
+     */
+    public void doStop() throws Exception {
+        discoveryAgent.unregisterService(service);
+    }
+
+    /**
+     * Fails the GBean.  This informs the GBean that it is about to transition to the failed state.
+     */
+    public void doFail() {
+        try {
+            doStop();
+        } catch (Exception e) {
+            //ignore
+        }
+    }
+}

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/JmxDiscoveryPublisher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/JmxDiscoveryPublisher.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/JmxDiscoveryPublisher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastDiscoveryAgent.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastDiscoveryAgent.java?rev=693451&r1=692989&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastDiscoveryAgent.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastDiscoveryAgent.java Tue Sep  9 05:44:36 2008
@@ -14,32 +14,18 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.openejb.server.discovery;
-
-import static org.apache.openejb.server.ServiceDaemon.getBoolean;
-import static org.apache.openejb.server.ServiceDaemon.getLong;
-import static org.apache.openejb.server.ServiceDaemon.getInt;
-import org.apache.openejb.server.SelfManaging;
-import org.apache.openejb.server.ServerService;
-import org.apache.openejb.server.ServiceException;
-import org.apache.openejb.server.ServiceDaemon;
-import org.apache.openejb.util.LogCategory;
-import org.apache.openejb.util.Logger;
+package org.apache.geronimo.farm.discovery;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.DatagramPacket;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.MulticastSocket;
-import java.net.Socket;
 import java.net.SocketAddress;
 import java.net.SocketTimeoutException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.ConcurrentHashMap;
@@ -50,12 +36,19 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+
 /**
  * @version $Rev$ $Date$
  */
-public class MulticastDiscoveryAgent implements DiscoveryAgent, ServerService, SelfManaging {
+@GBean
+public class MulticastDiscoveryAgent implements DiscoveryAgent, GBeanLifecycle {
 
-    private static final Logger log = Logger.getInstance(LogCategory.OPENEJB_SERVER.createChild("discovery"), MulticastDiscoveryAgent.class);
+    private static final Logger log = LoggerFactory.getLogger(MulticastDiscoveryAgent.class);
 
     private static final int BUFF_SIZE = 8192;
 
@@ -75,7 +68,7 @@
     private int maxMissedHeartbeats = 10;
     private long heartRate = 500;
 
-    private Listener listener;
+    private final Listener listener;
 
     public MulticastDiscoveryAgent() {
         listener = new Listener();
@@ -90,25 +83,30 @@
     private int maxReconnectAttempts = 10; // todo: check this out
     // ---------------------------------
 
-
-    public void init(Properties props) throws Exception {
-
-        host = props.getProperty("bind", host);
-
-        port = getInt(props, "port", port);
-
-        heartRate = getLong(props, "heart_rate", heartRate);
-        maxMissedHeartbeats = getInt(props, "max_missed_heartbeats", maxMissedHeartbeats);
-        loopbackMode = getBoolean(props, "max_missed_heartbeats", loopbackMode);
-
-        initialReconnectDelay = getLong(props, "reconnect_delay", initialReconnectDelay);
-        maxReconnectDelay = getLong(props, "max_reconnect_delay", initialReconnectDelay);
-        maxReconnectAttempts = getInt(props, "max_reconnect_attempts", maxReconnectAttempts);
-        backOffMultiplier = getLong(props, "exponential_backoff", backOffMultiplier);
-
-        useExponentialBackOff = (backOffMultiplier > 1);
+    public MulticastDiscoveryAgent(@ParamAttribute(name="host") String host,
+                                   @ParamAttribute(name="port") int port,
+                                   @ParamAttribute(name="heartRate") long heartRate,
+                                   @ParamAttribute(name="maxMissedHeartbeats") int maxMissedHeartbeats,
+                                   @ParamAttribute(name="loopbackMode")  boolean loopbackMode,
+                                   @ParamAttribute(name="initialReconnectDelay") long initialReconnectDelay,
+                                   @ParamAttribute(name="maxReconnectDelay") long maxReconnectDelay,
+                                   @ParamAttribute(name="maxReconnectAttempts") int maxReconnectAttempts,
+                                   @ParamAttribute(name="backOffMultiplier") long backOffMultiplier,
+                                   @ParamAttribute(name="useExponentialBackOff") boolean useExponentialBackOff) {
+        this.host = host;
+        this.port = port;
+        this.heartRate = heartRate;
+        this.maxMissedHeartbeats = maxMissedHeartbeats;
+        this.loopbackMode = loopbackMode;
+        this.initialReconnectDelay = initialReconnectDelay;
+        this.maxReconnectDelay = maxReconnectDelay;
+        this.maxReconnectAttempts = maxReconnectAttempts;
+        this.backOffMultiplier = backOffMultiplier;
+        this.useExponentialBackOff = useExponentialBackOff;
+        listener = new Listener();
     }
 
+
     public String getIP() {
         return host;
     }
@@ -154,10 +152,9 @@
     /**
      * start the discovery agent
      *
-     * @throws Exception
+     * @throws Exception on error
      */
-    public void start() throws ServiceException {
-        try {
+    public void doStart() throws Exception {
             if (started.compareAndSet(false, true)) {
 
                 InetAddress inetAddress = InetAddress.getByName(host);
@@ -180,27 +177,30 @@
                 Timer timer = new Timer("MulticastDiscovery: Broadcaster", true);
                 timer.scheduleAtFixedRate(broadcaster, 0, heartRate);
             }
-        } catch (Exception e) {
-            throw new ServiceException(e);
-        }
     }
 
     /**
      * stop the channel
      *
-     * @throws Exception
+     * @throws Exception pm error
      */
-    public void stop() throws ServiceException {
+    public void doStop() throws Exception {
         if (started.compareAndSet(true, false)) {
             multicast.close();
         }
     }
 
-    public void service(InputStream in, OutputStream out) throws ServiceException, IOException {
+    /**
+     * Fails the GBean.  This informs the GBean that it is about to transition to the failed state.
+     */
+    public void doFail() {
+        try {
+            doStop();
+        } catch (Exception e) {
+            //ignore
+        }
     }
 
-    public void service(Socket socket) throws ServiceException, IOException {
-    }
 
     class Service {
         private final URI uri;

Modified: geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastSearch.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastSearch.java?rev=693451&r1=692989&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastSearch.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-farm/src/main/java/org/apache/geronimo/farm/discovery/MulticastSearch.java Tue Sep  9 05:44:36 2008
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.openejb.server.discovery;
+package org.apache.geronimo.farm.discovery;
 
 import java.net.URI;
 import java.net.MulticastSocket;

Modified: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/pom.xml?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/pom.xml (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/pom.xml Tue Sep  9 05:44:36 2008
@@ -30,7 +30,7 @@
 
     <groupId>org.apache.geronimo.modules</groupId>
     <artifactId>geronimo-plugin-farm</artifactId>
-    <name>Geronimo Plugins, Clustering :: Farm</name>
+    <name>Geronimo Plugins, Clustering :: Farm using Plugins</name>
 
     <dependencies>
         <dependency>

Added: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmDiscoveryListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmDiscoveryListener.java?rev=693451&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmDiscoveryListener.java (added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmDiscoveryListener.java Tue Sep  9 05:44:36 2008
@@ -0,0 +1,171 @@
+/*
+ * 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.geronimo.farm.plugin;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+
+import org.apache.geronimo.farm.config.NodeInfo;
+import org.apache.geronimo.farm.discovery.DiscoveryAgent;
+import org.apache.geronimo.farm.discovery.DiscoveryListener;
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.annotation.ParamReference;
+import org.apache.geronimo.system.plugin.DownloadResults;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+@GBean
+public class FarmDiscoveryListener implements DiscoveryListener {
+
+    private static final Logger log = LoggerFactory.getLogger(FarmDiscoveryListener.class);
+    private DiscoveryAgent discoveryAgent;
+    private NodeListener nodeListener;
+    private String defaultClusterName;
+    private String discoveryType;
+    private String userName;
+    private String password;
+
+
+    public FarmDiscoveryListener(@ParamAttribute(name = "defaultClusterName")String defaultClusterName,
+                                 @ParamAttribute(name = "discoveryType")String discoveryType,
+                                 @ParamAttribute(name = "userName")String userName,
+                                 @ParamAttribute(name = "password")String password,
+                                 @ParamReference(name = "DiscoveryAgent")DiscoveryAgent discoveryAgent,
+                                 @ParamReference(name = "NodeListener")NodeListener nodeListener) {
+        discoveryAgent.setDiscoveryListener(this);
+        this.discoveryAgent = discoveryAgent;
+        this.nodeListener = nodeListener;
+        this.defaultClusterName = defaultClusterName;
+        this.discoveryType = discoveryType;
+        this.userName = userName;
+        this.password = password;
+    }
+
+    /**
+     * Starts the GBean.  This informs the GBean that it is about to transition to the running state.
+     *
+     * @throws Exception if the target failed to start; this will cause a transition to the failed state
+     */
+    public void doStart() throws Exception {
+    }
+
+    /**
+     * Stops the target.  This informs the GBean that it is about to transition to the stopped state.
+     *
+     * @throws Exception if the target failed to stop; this will cause a transition to the failed state
+     */
+    public void doStop() throws Exception {
+        doFail();
+    }
+
+    /**
+     * Fails the GBean.  This informs the GBean that it is about to transition to the failed state.
+     */
+    public void doFail() {
+        discoveryAgent.setDiscoveryListener(null);
+    }
+
+    public void serviceAdded(URI service) {
+        NodeInfo nodeInfo = toNodeInfo(service);
+        if (nodeInfo != null) {
+            String clusterName = toClusterName(service);
+            Map<String, DownloadResults> results = nodeListener.addNode(clusterName, nodeInfo);
+            log(nodeInfo, results);
+        }
+    }
+
+    public void serviceRemoved(URI service) {
+        NodeInfo nodeInfo = toNodeInfo(service);
+        if (nodeInfo != null) {
+            String clusterName = toClusterName(service);
+            nodeListener.removeNode(clusterName, nodeInfo.getName());
+        }
+    }
+
+    NodeInfo toNodeInfo(URI service) {
+        String typeScheme = service.getScheme();
+        if (!discoveryType.equals(typeScheme)) {
+            return null;
+        }
+        try {
+            URI jmxService = new URI(service.getSchemeSpecificPart());
+            JpaNodeInfo nodeInfo = new JpaNodeInfo();
+            String host = jmxService.getHost();
+            int port = jmxService.getPort();
+            String urlPath = jmxService.getPath().substring(1);
+            //TODO not sure about this one
+            String protocol = jmxService.getScheme();
+            String name = getValue("node", jmxService.getQuery(), host + ":" + port);
+            nodeInfo.setName(name);
+            nodeInfo.setConnectorInfo(userName, password, protocol, host, port, urlPath, false);
+            return nodeInfo;
+        } catch (URISyntaxException e) {
+            //TODO log error
+            return null;
+        }
+    }
+
+    String toClusterName(URI service) {
+        String typeScheme = service.getScheme();
+        if (!discoveryType.equals(typeScheme)) {
+            return null;
+        }
+        try {
+            URI jmxService = new URI(service.getSchemeSpecificPart());
+            return getValue("cluster", jmxService.getQuery(), defaultClusterName);
+        } catch (URISyntaxException e) {
+            //TODO log error
+            return null;
+        }
+    }
+
+    private String getValue(String key, String query, String defaultValue) {
+        String[] bits = query.split("[&=]");
+        if (bits.length % 2 != 0) {
+            throw new IllegalArgumentException("Can't parse query string: " + query);
+        }
+        for (int i = 0; i < bits.length; i = i + 2) {
+            if (key.equals(bits[i])) {
+                return bits[i + 1];
+            }
+        }
+        return defaultValue;
+    }
+
+    private void log(NodeInfo nodeInfo, Map<String, DownloadResults> results) {
+        log.info("installing to node: " + nodeInfo.getName());
+        for (Map.Entry<String, DownloadResults> entry: results.entrySet()) {
+            log.info("installation results for plugin list: " + entry.getKey());
+            DownloadResults downloadResults = entry.getValue();
+            log.info("installed: " + downloadResults.getInstalledConfigIDs());
+            if (downloadResults.isFailed()) {
+                log.info("failure: ", downloadResults.getFailure());
+            }
+        }
+
+    }
+
+}

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmDiscoveryListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmDiscoveryListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmDiscoveryListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmGBean.java?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmGBean.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/FarmGBean.java Tue Sep  9 05:44:36 2008
@@ -32,8 +32,8 @@
 
 import org.apache.geronimo.farm.config.NodeInfo;
 import org.apache.geronimo.gbean.annotation.GBean;
-import org.apache.geronimo.gbean.annotation.ParamReference;
 import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.annotation.ParamReference;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.persistence.PersistenceUnitGBean;
 import org.apache.geronimo.system.plugin.DownloadResults;
@@ -44,10 +44,10 @@
  * //need interface for operations
  * // need gshell commands
  *
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 @GBean
-public class FarmGBean {
+public class FarmGBean implements NodeListener {
     private String defaultRepository;
     private EntityManagerFactory emf;
 
@@ -56,19 +56,22 @@
         this.emf = emf;
     }
 
-    public FarmGBean(@ParamAttribute(name="defaultPluginRepository") String defaultPluginRepository,
-            @ParamReference(name = "PersistenceUnit", namingType = NameFactory.PERSISTENCE_UNIT)PersistenceUnitGBean persistenceUnitGBean) {
+    public FarmGBean(@ParamAttribute(name = "defaultPluginRepository")String defaultPluginRepository,
+                     @ParamReference(name = "PersistenceUnit", namingType = NameFactory.PERSISTENCE_UNIT)PersistenceUnitGBean persistenceUnitGBean) {
         this.defaultRepository = defaultPluginRepository;
         this.emf = persistenceUnitGBean.getEntityManagerFactory();
     }
 
+
     public Map<String, DownloadResults> addNode(String clusterName, NodeInfo nodeInfo) {
-        JpaContext clusterContext = new JpaContext(emf);
-        JpaClusterInfo cluster = clusterContext.getClusterInfo(clusterName);
-        JpaNodeInfo jpaNodeInfo = new JpaNodeInfo(nodeInfo);
-        cluster.getJpaNodeInfos().add(jpaNodeInfo);
-        //persist node info?
-        clusterContext.close();
+        JpaClusterInfo cluster;
+        JpaNodeInfo jpaNodeInfo;
+        synchronized (this) {
+            JpaContext clusterContext = new JpaContext(emf);
+            cluster = clusterContext.getClusterInfo(clusterName);
+            jpaNodeInfo = clusterContext.getNodeInfo(cluster, nodeInfo);
+            clusterContext.close();
+        }
         Map<String, DownloadResults> installedPluginLists = new HashMap<String, DownloadResults>();
         for (JpaPluginList pluginList : cluster.getPluginLists()) {
             DownloadResults downloadResults = installToNode(pluginList, jpaNodeInfo);
@@ -82,36 +85,49 @@
     }
 
     public Map<String, DownloadResults> addPluginList(String clusterName, JpaPluginList pluginList) {
-        JpaContext clusterContext = new JpaContext(emf);
-        JpaClusterInfo cluster = clusterContext.getClusterInfo(clusterName);
-        cluster.getPluginLists().add(pluginList);
-        clusterContext.close();
+        JpaClusterInfo cluster;
+        synchronized (this) {
+            JpaContext clusterContext = new JpaContext(emf);
+            cluster = clusterContext.getClusterInfo(clusterName);
+            cluster.getPluginLists().add(pluginList);
+            clusterContext.close();
+        }
         return installToCluster(pluginList, cluster);
     }
 
     public Map<String, DownloadResults> addPluginList(String clusterName, String pluginListName) {
-        JpaContext clusterContext = new JpaContext(emf);
-        JpaClusterInfo cluster = clusterContext.getClusterInfo(clusterName);
-        JpaPluginList pluginList = clusterContext.getPluginList(pluginListName, defaultRepository);
-        cluster.getPluginLists().add(pluginList);
-        clusterContext.close();
+        JpaClusterInfo cluster;
+        JpaPluginList pluginList;
+        synchronized (this) {
+            JpaContext clusterContext = new JpaContext(emf);
+            cluster = clusterContext.getClusterInfo(clusterName);
+            pluginList = clusterContext.getPluginList(pluginListName, defaultRepository);
+            cluster.getPluginLists().add(pluginList);
+            clusterContext.close();
+        }
         return installToCluster(pluginList, cluster);
     }
 
     public Map<String, DownloadResults> addPlugin(String pluginListName, JpaPluginInstance pluginInstance) {
-        JpaContext pluginListContext = new JpaContext(emf);
-        JpaPluginList pluginList = pluginListContext.getPluginList(pluginListName, defaultRepository);
-        pluginList.getPlugins().add(pluginInstance);
-        pluginListContext.close();
+        JpaPluginList pluginList;
+        synchronized (this) {
+            JpaContext pluginListContext = new JpaContext(emf);
+            pluginList = pluginListContext.getPluginList(pluginListName, defaultRepository);
+            pluginList.getPlugins().add(pluginInstance);
+            pluginListContext.close();
+        }
         return installToClusters(pluginList);
     }
 
     public Map<String, DownloadResults> addPluginToCluster(String clusterName, String pluginListName, JpaPluginInstance pluginInstance) {
-        JpaContext clusterContext = new JpaContext(emf);
-        JpaClusterInfo cluster = clusterContext.getClusterInfo(clusterName);
-        JpaPluginList pluginList = getPluginList(cluster, pluginListName);
-        pluginList.getPlugins().add(pluginInstance);
-        clusterContext.close();
+        JpaPluginList pluginList;
+        synchronized (this) {
+            JpaContext clusterContext = new JpaContext(emf);
+            JpaClusterInfo cluster = clusterContext.getClusterInfo(clusterName);
+            pluginList = getPluginList(cluster, pluginListName);
+            pluginList.getPlugins().add(pluginInstance);
+            clusterContext.close();
+        }
         return installToClusters(pluginList);
     }
 
@@ -179,10 +195,25 @@
                 JpaClusterInfo clusterInfo = new JpaClusterInfo();
                 clusterInfo.setName(clusterName);
                 em.persist(clusterInfo);
+                em.flush();
                 return clusterInfo;
             }
         }
 
+        public JpaNodeInfo getNodeInfo(JpaClusterInfo cluster, NodeInfo nodeInfo) {
+            Query query = em.createNamedQuery("nodeByName");
+            query.setParameter("name", nodeInfo.getName());
+            try {
+                return (JpaNodeInfo) query.getSingleResult();
+            } catch (NoResultException e) {
+                JpaNodeInfo jpaNodeInfo = new JpaNodeInfo(nodeInfo);
+                em.persist(jpaNodeInfo);
+                cluster.getJpaNodeInfos().add(jpaNodeInfo);
+                em.flush();
+                return jpaNodeInfo;
+            }
+        }
+
         public JpaPluginList getPluginList(String name, String defaultRepository) {
             Query query = em.createNamedQuery("pluginListByName");
             query.setParameter("name", name);
@@ -193,6 +224,7 @@
                 pluginList.setName(name);
                 pluginList.setDefaultPluginRepository(defaultRepository);
                 em.persist(pluginList);
+                em.flush();
                 return pluginList;
             }
         }

Modified: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaClusterInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaClusterInfo.java?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaClusterInfo.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaClusterInfo.java Tue Sep  9 05:44:36 2008
@@ -19,18 +19,17 @@
 
 package org.apache.geronimo.farm.plugin;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.ArrayList;
 
+import javax.persistence.CascadeType;
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
 import javax.persistence.Id;
-import javax.persistence.OneToMany;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
 import javax.persistence.ManyToMany;
-import javax.persistence.CascadeType;
-import javax.persistence.FetchType;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
 
 import org.apache.geronimo.farm.config.ClusterInfo;
 import org.apache.geronimo.farm.config.NodeInfo;
@@ -38,21 +37,20 @@
 /**
  * @version $Rev:$ $Date:$
  */
-@Entity(name="cluster")
-@NamedQueries( {
-        @NamedQuery(name = "clusterByName", query = "SELECT a FROM cluster a WHERE a.name = :name")}
-)
+@Entity(name = "cluster")
+@NamedQuery(name = "clusterByName", query = "SELECT a FROM cluster a WHERE a.name = :name")
+
 public class JpaClusterInfo implements ClusterInfo {
 
     @Id
     private String name;
     @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE},
-    fetch = FetchType.EAGER)
+            fetch = FetchType.EAGER)
     private List<JpaNodeInfo> nodes = new ArrayList<JpaNodeInfo>();
 
     @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
-    mappedBy = "clusters",
-    fetch = FetchType.EAGER)
+            mappedBy = "clusters",
+            fetch = FetchType.EAGER)
     private List<JpaPluginList> pluginLists = new ArrayList<JpaPluginList>();
 
     public String getName() {
@@ -64,7 +62,7 @@
     }
 
     public Collection<NodeInfo> getNodeInfos() {
-        return new ArrayList(nodes);
+        return new ArrayList<NodeInfo>(nodes);
     }
 
     public List<JpaPluginList> getPluginLists() {

Modified: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaNodeInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaNodeInfo.java?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaNodeInfo.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaNodeInfo.java Tue Sep  9 05:44:36 2008
@@ -25,6 +25,7 @@
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Transient;
+import javax.persistence.NamedQuery;
 import javax.management.remote.JMXConnector;
 
 import org.apache.geronimo.farm.config.ExtendedJMXConnectorInfo;
@@ -39,7 +40,8 @@
 /**
  * @version $Rev:$ $Date:$
  */
-@Entity
+@Entity(name="node")
+@NamedQuery(name = "nodeByName", query = "SELECT a FROM node a WHERE a.name = :name")
 public class JpaNodeInfo implements NodeInfo {
     @Id
     private int id;

Modified: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaPluginList.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaPluginList.java?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaPluginList.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/JpaPluginList.java Tue Sep  9 05:44:36 2008
@@ -20,32 +20,29 @@
 
 package org.apache.geronimo.farm.plugin;
 
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
+import javax.persistence.CascadeType;
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
 import javax.persistence.Id;
 import javax.persistence.ManyToMany;
-import javax.persistence.CascadeType;
-import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
-import javax.persistence.FetchType;
 
 import org.apache.geronimo.system.plugin.model.PluginListType;
 import org.apache.geronimo.system.plugin.model.PluginType;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
-@Entity(name="pluginlist")
-@NamedQueries( {
-        @NamedQuery(name = "pluginListByName", query = "SELECT a FROM pluginlist a WHERE a.name = :name")}
-)
+@Entity(name = "pluginlist")
+@NamedQuery(name = "pluginListByName", query = "SELECT a FROM pluginlist a WHERE a.name = :name")
 public class JpaPluginList {
     @Id
     private String name;
     @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
-    fetch = FetchType.EAGER)
+            fetch = FetchType.EAGER)
     private List<JpaPluginInstance> plugins = new ArrayList<JpaPluginInstance>();
     @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
     private List<JpaClusterInfo> clusters = new ArrayList<JpaClusterInfo>();
@@ -86,7 +83,7 @@
     public PluginListType getPluginList() {
         PluginListType pluginList = new PluginListType();
         List<PluginType> plugins = pluginList.getPlugin();
-        for (JpaPluginInstance pluginInstance: this.plugins) {
+        for (JpaPluginInstance pluginInstance : this.plugins) {
             PluginType plugin = pluginInstance.getPlugin();
             plugins.add(plugin);
         }

Added: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/NodeListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/NodeListener.java?rev=693451&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/NodeListener.java (added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/NodeListener.java Tue Sep  9 05:44:36 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.geronimo.farm.plugin;
+
+import java.util.Map;
+
+import org.apache.geronimo.system.plugin.DownloadResults;
+import org.apache.geronimo.farm.config.NodeInfo;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface NodeListener {
+    Map<String, DownloadResults> addNode(String clusterName, NodeInfo nodeInfo);
+
+    void removeNode(String clusterName, String nodeName);
+}

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/NodeListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/NodeListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/NodeListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/TestGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/TestGBean.java?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/TestGBean.java (original)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/main/java/org/apache/geronimo/farm/plugin/TestGBean.java Tue Sep  9 05:44:36 2008
@@ -34,7 +34,7 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 @GBean
 public class TestGBean {
@@ -52,8 +52,9 @@
         this.emf = persistenceUnitGBean.getEntityManagerFactory();
         this.farmGBean = farmGBean;
         testAddPlugin();
-        testAddNode1();
-        testAddExistingPluginListToNewCluster();
+//        testAddNode1();
+//        testAddExistingPluginListToNewCluster();
+//        Thread.sleep(1000 * 60 * 2);
     }
 
     public void testAddPlugin() throws Exception {

Added: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/ListenerTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/ListenerTest.java?rev=693451&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/ListenerTest.java (added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/ListenerTest.java Tue Sep  9 05:44:36 2008
@@ -0,0 +1,163 @@
+/*
+ * 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.geronimo.farm.plugin;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.farm.config.ExtendedJMXConnectorInfo;
+import org.apache.geronimo.farm.config.NodeInfo;
+import org.apache.geronimo.farm.discovery.DiscoveryAgent;
+import org.apache.geronimo.farm.discovery.DiscoveryListener;
+import org.apache.geronimo.farm.discovery.JmxDiscoveryPublisher;
+import org.apache.geronimo.kernel.rmi.RMIRegistryService;
+import org.apache.geronimo.system.plugin.DownloadResults;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class ListenerTest extends TestCase {
+    private DiscoveryAgent agent;
+    private FarmDiscoveryListener listener;
+    private NodeListener nodeListener;
+    private String clusterName;
+    private NodeInfo nodeInfo;
+
+    protected void setUp() throws Exception {
+        agent = new DiscoveryAgent() {
+            private DiscoveryListener listener;
+
+            /**
+             * Sets the discovery listener
+             *
+             * @param listener listener for addeed/removed services
+             */
+            public void setDiscoveryListener(DiscoveryListener listener) {
+                this.listener = listener;
+            }
+
+            /**
+             * register a service
+             *
+             * @param serviceUri uri for new service
+             * @throws java.io.IOException on error
+             */
+            public void registerService(URI serviceUri) throws IOException {
+                if (listener != null) {
+                    listener.serviceAdded(serviceUri);
+                }
+            }
+
+            /**
+             * register a service
+             *
+             * @param serviceUri uri for removed service
+             * @throws java.io.IOException on error
+             */
+            public void unregisterService(URI serviceUri) throws IOException {
+                if (listener != null) {
+                    listener.serviceRemoved(serviceUri);
+                }
+            }
+
+            /**
+             * A process actively using a service may see it go down before the DiscoveryAgent notices the
+             * service's failure.  That process can use this method to notify the DiscoveryAgent of the failure
+             * so that other listeners of this DiscoveryAgent can also be made aware of the failure.
+             *
+             * @param serviceUri uri for failed service
+             * @throws java.io.IOException on error
+             */
+            public void reportFailed(URI serviceUri) throws IOException {
+                if (listener != null) {
+                    listener.serviceRemoved(serviceUri);
+                }
+            }
+        };
+        nodeListener = new NodeListener() {
+
+            public Map<String, DownloadResults> addNode(String clusterName, NodeInfo nodeInfo) {
+                ListenerTest.this.clusterName = clusterName;
+                ListenerTest.this.nodeInfo = nodeInfo;
+                return new HashMap<String, DownloadResults>();
+            }
+
+            public void removeNode(String clusterName, String nodeName) {
+                if (!clusterName.equals(ListenerTest.this.clusterName)) {
+                    throw new IllegalArgumentException("Mismatched cluster name: was: " + ListenerTest.this.clusterName + " now: " + clusterName);
+                }
+                if (!nodeName.equals(nodeInfo.getName())) {
+                    throw new IllegalArgumentException("Mismatched node name: was: " + nodeInfo.getName() + " now: " + nodeName);
+                }
+                ListenerTest.this.clusterName = null;
+                nodeInfo = null;
+            }
+        };
+        listener = new FarmDiscoveryListener("cluster1", "farm", "user", "pw",
+                agent, nodeListener);
+
+    }
+
+    public void testURIs() throws Exception {
+        URI uri = new URI("test:jmx://localhost:8080/service?key=value");
+        String scheme = uri.getScheme();
+        String schemePart = uri.getSchemeSpecificPart();
+        URI uri2 = URI.create(schemePart);
+        String scheme2 = uri2.getScheme();
+        String host = uri2.getHost();
+        int port = uri2.getPort();
+        String path = uri2.getPath();
+        String query = uri2.getQuery();
+        String fragment = uri2.getFragment();
+    }
+
+    public void testListener() throws Exception {
+        URI service = URI.create("farm:jmx://localhost:1099/JMXService?node=node1&cluster=cluster2");
+        assertEquals("cluster2", listener.toClusterName(service));
+        NodeInfo nodeInfo = listener.toNodeInfo(service);
+        checkNodeInfo(nodeInfo, "node1", "localhost", 1099, "user", "pw", "jmx", "JMXService");
+    }
+
+    private void checkNodeInfo(NodeInfo nodeInfo, String nodeName, String host, int port, String userName, String password, String protocol, String urlPath) {
+        ExtendedJMXConnectorInfo info = nodeInfo.getConnectorInfo();
+        assertEquals(nodeName, nodeInfo.getName());
+        assertEquals(host, info.getHost());
+        assertEquals(port, info.getPort());
+        assertEquals(userName, info.getUsername());
+        assertEquals(password, info.getPassword());
+        assertEquals(protocol, info.getProtocol());
+        assertEquals(urlPath, info.getUrlPath());
+    }
+
+    public void testAgent() throws Exception {
+        RMIRegistryService rmiRegistryService = new RMIRegistryService();
+        rmiRegistryService.setHost("localhost");
+        rmiRegistryService.setPort(1099);
+        JmxDiscoveryPublisher jmxDiscoveryPublisher = new JmxDiscoveryPublisher("node2", "cluster2", "rmi", "JMXService", "farm",agent, rmiRegistryService);
+        assertEquals("cluster2", clusterName);
+        checkNodeInfo(nodeInfo, "node2", "localhost", 1099, "user", "pw", "rmi", "JMXService");
+
+
+    }
+}

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/ListenerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/ListenerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/clustering/geronimo-plugin-farm/src/test/java/org/apache/geronimo/farm/plugin/ListenerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/clustering/plugin-farm-it/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/plugin-farm-it/pom.xml?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/plugin-farm-it/pom.xml (original)
+++ geronimo/server/trunk/plugins/clustering/plugin-farm-it/pom.xml Tue Sep  9 05:44:36 2008
@@ -27,7 +27,7 @@
         <artifactId>clustering</artifactId>
         <version>2.2-SNAPSHOT</version>
     </parent>
-    
+
     <groupId>org.apache.geronimo.configs</groupId>
     <artifactId>plugin-farm-it</artifactId>
     <name>Geronimo Plugins, Clustering :: Plugin Farm Integration Tests</name>
@@ -36,7 +36,7 @@
     <description>
         Basic farming support
     </description>
-    
+
     <dependencies>
         <dependency>
             <groupId>org.apache.geronimo.framework</groupId>
@@ -151,8 +151,8 @@
                                         <id>default</id>
                                         <options>
                                             <option>-XX:MaxPermSize=128m</option>
-                                            <!--<option>-Xdebug</option>-->
-                                            <!--<option>-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n</option>-->
+                                            <option>-Xdebug</option>
+                                            <option>-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n</option>
                                         </options>
                                     </optionSet>
 
@@ -214,6 +214,18 @@
                             </configuration>
                         </execution>
                         <execution>
+                            <id>install-plugin-farm-member-2</id>
+                            <phase>install</phase>
+                            <goals>
+                                <goal>install-plugin</goal>
+                            </goals>
+                            <configuration>
+                                <defaultGeronimoRepository>~/.m2/repository</defaultGeronimoRepository>
+                                <moduleId>org.apache.geronimo.configs/plugin-farm-member/${version}/car</moduleId>
+                                <port>1119</port>
+                            </configuration>
+                        </execution>
+                        <execution>
                             <id>install-plugin</id>
                             <phase>install</phase>
                             <goals>

Modified: geronimo/server/trunk/plugins/clustering/plugin-farm-member/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/plugin-farm-member/pom.xml?rev=693451&r1=692915&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/plugin-farm-member/pom.xml (original)
+++ geronimo/server/trunk/plugins/clustering/plugin-farm-member/pom.xml Tue Sep  9 05:44:36 2008
@@ -29,8 +29,8 @@
     </parent>
 
     <groupId>org.apache.geronimo.configs</groupId>
-    <artifactId>plugin-farm</artifactId>
-    <name>Geronimo Plugins, Clustering :: Plugin Farm</name>
+    <artifactId>plugin-farm-member</artifactId>
+    <name>Geronimo Plugins, Clustering :: Plugin Farm Member</name>
     <packaging>car</packaging>
 
     <description>
@@ -43,6 +43,7 @@
             <artifactId>geronimo-gbean-deployer</artifactId>
             <version>${version}</version>
             <type>car</type>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -53,22 +54,8 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.geronimo.configs</groupId>
-            <artifactId>system-database</artifactId>
-            <version>${version}</version>
-            <type>car</type>
-        </dependency>
-
-        <!--<dependency>-->
-        <!--<groupId>org.apache.geronimo.framework</groupId>-->
-        <!--<artifactId>j2ee-security</artifactId>-->
-        <!--<version>${version}</version>-->
-        <!--<type>car</type>-->
-        <!--</dependency>-->
-
-        <dependency>
             <groupId>org.apache.geronimo.modules</groupId>
-            <artifactId>geronimo-plugin-farm</artifactId>
+            <artifactId>geronimo-farm</artifactId>
             <version>${version}</version>
         </dependency>
     </dependencies>

Modified: geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/history/dependencies.xml?rev=693451&r1=692915&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/history/dependencies.xml Tue Sep  9 05:44:36 2008
@@ -2,7 +2,7 @@
 <plugin-artifact xmlns:ns2="http://geronimo.apache.org/xml/ns/attributes-1.2" xmlns="http://geronimo.apache.org/xml/ns/plugins-1.3">
     <module-id>
         <groupId>org.apache.geronimo.configs</groupId>
-        <artifactId>plugin-farm</artifactId>
+        <artifactId>plugin-farm-member</artifactId>
         <version>2.2-SNAPSHOT</version>
         <type>car</type>
     </module-id>
@@ -12,19 +12,19 @@
         <type>jar</type>
     </dependency>
     <dependency>
-        <groupId>org.apache.geronimo.modules</groupId>
-        <artifactId>geronimo-plugin-farm</artifactId>
+        <groupId>org.apache.geronimo.framework</groupId>
+        <artifactId>geronimo-deployment</artifactId>
         <type>jar</type>
     </dependency>
     <dependency>
-        <groupId>org.apache.geronimo.configs</groupId>
-        <artifactId>openjpa</artifactId>
-        <type>car</type>
+        <groupId>org.apache.geronimo.framework</groupId>
+        <artifactId>geronimo-jmx-remoting</artifactId>
+        <type>jar</type>
     </dependency>
     <dependency>
-        <groupId>org.apache.geronimo.configs</groupId>
-        <artifactId>system-database</artifactId>
-        <type>car</type>
+        <groupId>xml-resolver</groupId>
+        <artifactId>xml-resolver</artifactId>
+        <type>jar</type>
     </dependency>
     <dependency>
         <groupId>org.apache.geronimo.framework</groupId>
@@ -33,7 +33,7 @@
     </dependency>
     <dependency>
         <groupId>org.apache.geronimo.framework</groupId>
-        <artifactId>geronimo-gbean-deployer</artifactId>
-        <type>car</type>
+        <artifactId>geronimo-service-builder</artifactId>
+        <type>jar</type>
     </dependency>
 </plugin-artifact>

Modified: geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/plan/plan.xml?rev=693451&r1=692915&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/plan/plan.xml (original)
+++ geronimo/server/trunk/plugins/clustering/plugin-farm-member/src/main/plan/plan.xml Tue Sep  9 05:44:36 2008
@@ -20,37 +20,33 @@
 
 <module xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
 
-    <gbean name="FarmPersistence" class="org.apache.geronimo.persistence.PersistenceUnitGBean">
-        <attribute name="persistenceUnitName">FarmPersistence</attribute>
-        <attribute name="persistenceUnitTransactionType">RESOURCE_LOCAL</attribute>
-        <attribute name="persistenceUnitRoot"></attribute>
-        <attribute name="excludeUnlistedClasses">true</attribute>
-        <attribute name="managedClassNames">org.apache.geronimo.farm.plugin.JpaClusterInfo,
-            org.apache.geronimo.farm.plugin.JpaNodeInfo,
-            org.apache.geronimo.farm.plugin.JpaPluginInstance,
-            org.apache.geronimo.farm.plugin.JpaPluginList
-        </attribute>
-        <attribute name="properties">
-            openjpa.Log=commons
-            openjpa.jdbc.DBDictionary=org.apache.openjpa.jdbc.sql.DerbyDictionary
-            openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true)
-            openjpa.jdbc.UpdateManager=operation-order
-            openjpa.Sequence=table(Table=OPENJPASEQ, Increment=100)
-            openjpa.InverseManager=true
-        </attribute>
-        <reference name="JtaDataSourceWrapper">
-            <name>SystemDatasource</name>
+    <gbean name="DiscoveryPublisher" class="org.apache.geronimo.farm.discovery.JmxDiscoveryPublisher">
+        <!--<attribute name="nodeName">FarmPersistence</attribute>-->
+        <attribute name="clusterName">cluster1</attribute>
+        <attribute name="protocol">rmi</attribute>
+        <attribute name="urlPath">JMXConnector</attribute>
+        <attribute name="discoveryType">farm</attribute>
+        <reference name="DiscoveryAgent">
+            <name>DiscoveryAgent</name>
         </reference>
-        <reference name="NonJtaDataSourceWrapper">
-            <name>NoTxDatasource</name>
+        <reference name="RMIRegistryService">
+            <name>RMIRegistry</name>
         </reference>
+        <dependency>
+            <name>PluginInstaller</name>
+        </dependency>
     </gbean>
 
-    <gbean name="PluginFarm" class="org.apache.geronimo.farm.plugin.FarmGBean">
-        <attribute name="defaultPluginRepository">~/.m2/repository</attribute>
-        <reference name="PersistenceUnit">
-            <name>FarmPersistence</name>
-        </reference>
+    <gbean name="DiscoveryAgent" class="org.apache.geronimo.farm.discovery.MulticastDiscoveryAgent">
+        <attribute name="host">239.255.3.2</attribute>
+        <attribute name="port">6142</attribute>
+        <attribute name="heartRate">500</attribute>
+        <attribute name="maxMissedHeartbeats">10</attribute>
+        <attribute name="loopbackMode">false</attribute>
+        <attribute name="initialReconnectDelay">5000</attribute>
+        <attribute name="maxReconnectDelay">30000</attribute>
+        <attribute name="backOffMultiplier">0</attribute>
+        <attribute name="useExponentialBackOff">false</attribute>
     </gbean>
 
 </module>

Modified: geronimo/server/trunk/plugins/clustering/plugin-farm/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/plugin-farm/src/main/plan/plan.xml?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/plugin-farm/src/main/plan/plan.xml (original)
+++ geronimo/server/trunk/plugins/clustering/plugin-farm/src/main/plan/plan.xml Tue Sep  9 05:44:36 2008
@@ -53,4 +53,29 @@
         </reference>
     </gbean>
 
+    <gbean name="DiscoveryAgent" class="org.apache.geronimo.farm.discovery.MulticastDiscoveryAgent">
+        <attribute name="host">239.255.3.2</attribute>
+        <attribute name="port">6142</attribute>
+        <attribute name="heartRate">500</attribute>
+        <attribute name="maxMissedHeartbeats">10</attribute>
+        <attribute name="loopbackMode">false</attribute>
+        <attribute name="initialReconnectDelay">5000</attribute>
+        <attribute name="maxReconnectDelay">30000</attribute>
+        <attribute name="backOffMultiplier">0</attribute>
+        <attribute name="useExponentialBackOff">false</attribute>
+    </gbean>
+
+    <gbean name="FarmDiscoveryListener" class="org.apache.geronimo.farm.plugin.FarmDiscoveryListener">
+        <attribute name="defaultClusterName">cluster0</attribute>
+        <attribute name="discoveryType">farm</attribute>
+        <attribute name="userName">system</attribute>
+        <attribute name="password">manager</attribute>
+        <reference name="DiscoveryAgent">
+            <name>DiscoveryAgent</name>
+        </reference>
+        <reference name="NodeListener">
+            <name>PluginFarm</name>
+        </reference>
+    </gbean>
+
 </module>

Modified: geronimo/server/trunk/plugins/clustering/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/pom.xml?rev=693451&r1=693450&r2=693451&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/clustering/pom.xml (original)
+++ geronimo/server/trunk/plugins/clustering/pom.xml Tue Sep  9 05:44:36 2008
@@ -46,6 +46,7 @@
         <module>wadi-clustering</module>
         <module>farming</module>
         <module>plugin-farm</module>
+        <module>plugin-farm-member</module>
     </modules>
 
     <profiles>



Mime
View raw message