geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject cvs commit: incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment ModuleTypeWrapper.java AdminServer.java TargetImpl2.java DeploymentReplacerResolver.java ManagedServer.java
Date Thu, 27 May 2004 14:45:59 GMT
gdamour     2004/05/27 07:45:59

  Added:       sandbox/messaging/src/test/org/apache/geronimo/messaging/admin/deployment
                        DeploymentReplacerResolverTest.java MockServer.java
                        AdminServerTest.java
               sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment
                        ModuleTypeWrapper.java AdminServer.java
                        TargetImpl2.java DeploymentReplacerResolver.java
                        ManagedServer.java
  Log:
  Implements two kinds of DeploymentServer EndPoints: AdminServer and
  ManagedServer.
  AdminServer filters and dispatchs deployment operations to its
  ManagedServers.
  ManagedServers execute locally the forwarded deployment operations.
  Their results are consolidated by the AdminServer.
  
  The goal is to have a DeploymentManager, which pushes deployments
  to an AdminServer. Then this latter consolidate on the server-side the
  operations and returns to the DeploymentManager a consolidated view.
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/admin/deployment/DeploymentReplacerResolverTest.java
  
  Index: DeploymentReplacerResolverTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.admin.deployment;
  
  import javax.enterprise.deploy.shared.ModuleType;
  
  import org.apache.geronimo.deployment.plugin.TargetImpl;
  import org.apache.geronimo.messaging.io.ReplacerResolver;
  
  import junit.framework.TestCase;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:45:58 $
   */
  public class DeploymentReplacerResolverTest extends TestCase
  {
  
      public void testCustomReplaceObject1() throws Exception {
          TargetImpl target = new TargetImpl("test", "description");
          ReplacerResolver replacerResolver = new DeploymentReplacerResolver();
          TargetImpl2 result = (TargetImpl2) replacerResolver.replaceObject(target);
          assertEquals(target.getName(), result.getName());
          assertEquals(target.getDescription(), result.getDescription());
      }
      
      public void testCustomReplaceObject2() throws Exception {
          ModuleType type = ModuleType.CAR;
          ReplacerResolver replacerResolver = new DeploymentReplacerResolver();
          ModuleTypeWrapper result =
              (ModuleTypeWrapper) replacerResolver.replaceObject(type);
          assertEquals(type, result.getModuleType());
      }
      
      public void testCustomResolveObject1() throws Exception {
          TargetImpl target = new TargetImpl("test", "description");
          ReplacerResolver replacerResolver = new DeploymentReplacerResolver();
          TargetImpl2 tmp = (TargetImpl2) replacerResolver.replaceObject(target);
          
          TargetImpl result = (TargetImpl) replacerResolver.resolveObject(tmp);
          assertEquals(target.getName(), result.getName());
          assertEquals(target.getDescription(), result.getDescription());
      }
      
      public void testCustomResolveObject2() throws Exception {
          ModuleType type = ModuleType.CAR;
          ReplacerResolver replacerResolver = new DeploymentReplacerResolver();
          ModuleTypeWrapper tmp =
              (ModuleTypeWrapper) replacerResolver.replaceObject(type);
          ModuleType result = (ModuleType) replacerResolver.resolveObject(tmp);
          assertEquals(type, result);
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/admin/deployment/MockServer.java
  
  Index: MockServer.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.admin.deployment;
  
  import java.io.InputStream;
  
  import javax.enterprise.deploy.shared.ModuleType;
  import javax.enterprise.deploy.spi.Target;
  import javax.enterprise.deploy.spi.TargetModuleID;
  import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
  import javax.enterprise.deploy.spi.exceptions.TargetException;
  import javax.enterprise.deploy.spi.status.ClientConfiguration;
  import javax.enterprise.deploy.spi.status.DeploymentStatus;
  import javax.enterprise.deploy.spi.status.ProgressListener;
  import javax.enterprise.deploy.spi.status.ProgressObject;
  
  import org.apache.geronimo.deployment.ConfigurationBuilder;
  import org.apache.geronimo.deployment.plugin.DeploymentServer;
  import org.apache.xmlbeans.XmlObject;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:45:58 $
   */
  public class MockServer implements DeploymentServer {
  
      private final int id;
      private TargetModuleID[] runningIDs;
      private TargetModuleID[] nonRunningIDs;
      private TargetModuleID[] availableIDs;
      private boolean distribute;
      private boolean start;
      private boolean stop;
      private boolean undeploy;
      private boolean redeploy;
      
      public MockServer(int anID) {
          id = anID;
      }
      
      public int getMockID() {
          return id;
      }
      
      public boolean isLocal() {
          return false;
      }
  
      public Target[] getTargets() throws IllegalStateException {
          return null;
      }
  
      public void setMockGetRunningModules(TargetModuleID[] anIDs) {
          runningIDs = anIDs;
      }
      
      public TargetModuleID[] getRunningModules(
          ModuleType moduleType,
          Target[] targetList)
          throws TargetException, IllegalStateException {
          return runningIDs;
      }
  
      public void setMockGetNonRunningModules(TargetModuleID[] anIDs) {
          nonRunningIDs = anIDs;
      }
      
      public TargetModuleID[] getNonRunningModules(
          ModuleType moduleType,
          Target[] targetList)
          throws TargetException, IllegalStateException {
          return nonRunningIDs;
      }
  
      public void setMockGetAvailableModules(TargetModuleID[] anIDs) {
          availableIDs = anIDs;
      }
      
      public TargetModuleID[] getAvailableModules(
          ModuleType moduleType,
          Target[] targetList)
          throws TargetException, IllegalStateException {
          return availableIDs;
      }
  
      public boolean getMockIsDistributed() {
          return distribute;
      }
      
      public ProgressObject distribute(
          Target[] targetList,
          ConfigurationBuilder builder,
          InputStream jis,
          XmlObject plan)
          throws IllegalStateException {
          distribute = true;
          return new MockProgressObject();
      }
  
      public boolean getMockIsStarted() {
          return start;
      }
      
      public ProgressObject start(TargetModuleID[] moduleIDList)
          throws IllegalStateException {
          start = true;
          return new MockProgressObject();
      }
  
      public boolean getMockIsStopped() {
          return stop;
      }
      
      public ProgressObject stop(TargetModuleID[] moduleIDList)
          throws IllegalStateException {
          stop = true;
          return new MockProgressObject();
      }
      
      public boolean getMockIsUndeploy() {
          return undeploy;
      }
      
      public ProgressObject undeploy(TargetModuleID[] moduleIDList)
          throws IllegalStateException {
          undeploy = true;
          return new MockProgressObject();
      }
      
      public boolean isRedeploySupported() {
          return false;
      }
  
      public boolean getMockIsRedeploy() {
          redeploy = true;
          return redeploy;
      }
      
      public ProgressObject redeploy(
          TargetModuleID[] moduleIDList,
          InputStream moduleArchive,
          InputStream deploymentPlan)
          throws UnsupportedOperationException, IllegalStateException {
          return new MockProgressObject();
      }
  
      public void release() {
      }
      
      public class MockProgressObject implements ProgressObject {
  
          public DeploymentStatus getDeploymentStatus() {
              return null;
          }
  
          public TargetModuleID[] getResultTargetModuleIDs() {
              return null;
          }
  
          public ClientConfiguration getClientConfiguration(TargetModuleID id) {
              return null;
          }
  
          public boolean isCancelSupported() {
              return false;
          }
  
          public void cancel() throws OperationUnsupportedException {
          }
  
          public boolean isStopSupported() {
              return false;
          }
  
          public void stop() throws OperationUnsupportedException {
          }
  
          public void addProgressListener(ProgressListener pol) {
          }
  
          public void removeProgressListener(ProgressListener pol) {
          }
          
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/admin/deployment/AdminServerTest.java
  
  Index: AdminServerTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.admin.deployment;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.InetAddress;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Map;
  import java.util.Set;
  import java.util.jar.Manifest;
  
  import javax.enterprise.deploy.shared.ModuleType;
  import javax.enterprise.deploy.spi.Target;
  import javax.enterprise.deploy.spi.TargetModuleID;
  
  import junit.framework.TestCase;
  
  import org.apache.geronimo.deployment.ConfigurationBuilder;
  import org.apache.geronimo.deployment.DeploymentException;
  import org.apache.geronimo.messaging.MockNode;
  import org.apache.geronimo.messaging.NodeInfo;
  import org.apache.xmlbeans.SchemaTypeLoader;
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.XmlObject;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:45:58 $
   */
  public class AdminServerTest
      extends TestCase
  {
  
      private MockNode node;
      private AdminServer server;
      private NodeInfo nodeInfo1;
      private MockServer server1;
      private TargetModuleID[] runningID1;
      private TargetModuleID[] nonRunningID1;
      private NodeInfo nodeInfo2;
      private MockServer server2;
      private TargetModuleID[] nonRunningID2;
      private TargetModuleID[] availableID2;
      
      protected void setUp() throws Exception {
          node = new MockNode();
          Set nodes = node.getMockGetRemoteNodeInfos();
          InetAddress address = InetAddress.getLocalHost();
          nodeInfo1 = new NodeInfo("node1", address, 1234);
          nodes.add(nodeInfo1);
          nodeInfo2 = new NodeInfo("node2", address, 1234);
          nodes.add(nodeInfo2);
          
          Map factories = node.getMockFactoryEndPointProxy();
          server1 = new MockServer(1);
          
          runningID1 = new TargetModuleID[] {new MockID()};
          nonRunningID1 = new TargetModuleID[] {new MockID()};
          server1.setMockGetRunningModules(runningID1);
          server1.setMockGetNonRunningModules(nonRunningID1);
          factories.put(nodeInfo1, server1);
          
          server2 = new MockServer(2);
          nonRunningID2 = new TargetModuleID[] {new MockID()};
          availableID2 = new TargetModuleID[] {new MockID()};
          server2.setMockGetNonRunningModules(nonRunningID2);
          server2.setMockGetAvailableModules(availableID2);
          
          factories.put(nodeInfo2, server2);
          
          server = new AdminServer(node, "DUMMY");
      }
      
      public void testGetTargets() throws Exception {
          Target[] targets = server.getTargets();
          assertEquals(2, targets.length);
          Collection names = new ArrayList();
          names.add(nodeInfo1.getName());
          names.add(nodeInfo2.getName());
          for (int i = 0; i < targets.length; i++) {
              assertTrue(names.contains(targets[i].getName()));
          }
      }
      
      public void testGetRunningModules() throws Exception {
          Target[] targets = server.getTargets();
          TargetModuleID[] ids = server.getRunningModules(ModuleType.WAR, targets);
          assertEquals(runningID1.length, ids.length);
      }
  
      public void testGetNonRunningModules() throws Exception {
          Target[] targets = server.getTargets();
          TargetModuleID[] ids = server.getNonRunningModules(ModuleType.WAR, targets);
          assertEquals(nonRunningID1.length + nonRunningID2.length, ids.length);
      }
  
      public void testGetAvailableModules() throws Exception {
          Target[] targets = server.getTargets();
          TargetModuleID[] ids = server.getAvailableModules(ModuleType.WAR, targets);
          assertEquals(availableID2.length, ids.length);
      }
  
      public void testDistribute() throws Exception {
          Target[] targets = server.getTargets();
          for (int i = 0; i < targets.length; i++) {
              if ( targets[i].getName().equals(nodeInfo1.getName()) ) {
                  server.distribute(new Target[] {targets[i]}, new MockBuilder(), null, null);
              }
          }
          assertTrue(server1.getMockIsDistributed());
          assertFalse(server2.getMockIsDistributed());
      }
  
      public void testStart() throws Exception {
          Target[] targets = server.getTargets();
          for (int i = 0; i < targets.length; i++) {
              if ( targets[i].getName().equals(nodeInfo2.getName()) ) {
                  MockID mockID = new MockID();
                  mockID.target = targets[i]; 
                  server.start(new TargetModuleID[] {mockID});
              }
          }
          assertFalse(server1.getMockIsStarted());
          assertTrue(server2.getMockIsStarted());
      }
  
      public void testStop() throws Exception {
          Target[] targets = server.getTargets();
          for (int i = 0; i < targets.length; i++) {
              if ( targets[i].getName().equals(nodeInfo2.getName()) ) {
                  MockID mockID = new MockID();
                  mockID.target = targets[i]; 
                  server.stop(new TargetModuleID[] {mockID});
              }
          }
          assertFalse(server1.getMockIsStopped());
          assertTrue(server2.getMockIsStopped());
      }
  
      public void testUndeploy() throws Exception {
          Target[] targets = server.getTargets();
          for (int i = 0; i < targets.length; i++) {
              if ( targets[i].getName().equals(nodeInfo2.getName()) ) {
                  MockID mockID = new MockID();
                  mockID.target = targets[i]; 
                  server.undeploy(new TargetModuleID[] {mockID});
              }
          }
          assertFalse(server1.getMockIsUndeploy());
          assertTrue(server2.getMockIsUndeploy());
      }
      
      private static class MockID implements TargetModuleID {
          private Target target;
          public Target getTarget() {
              return target;
          }
          public String getModuleID() {
              return null;
          }
          public String getWebURL() {
              return null;
          }
          public TargetModuleID getParentTargetModuleID() {
              return null;
          }
          public TargetModuleID[] getChildTargetModuleID() {
              return null;
          }
      }
  
      private static class MockBuilder implements ConfigurationBuilder {
          public SchemaTypeLoader[] getTypeLoaders() {
              return null;
          }
          public boolean canConfigure(XmlObject plan) {
              return false;
          }
          public XmlObject getDeploymentPlan(URL module) throws XmlException {
              return null;
          }
          public void buildConfiguration(File outfile, Manifest manifest, File module, XmlObject
plan) throws IOException, DeploymentException {
          }
          public void buildConfiguration(File outfile, Manifest manifest, InputStream module,
XmlObject plan) throws IOException, DeploymentException {
          }
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/ModuleTypeWrapper.java
  
  Index: ModuleTypeWrapper.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.admin.deployment;
  
  import java.io.Serializable;
  
  import javax.enterprise.deploy.shared.ModuleType;
  
  /**
   * ModuleType wrapper which is serializable.
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:45:59 $
   */
  public class ModuleTypeWrapper
      implements Serializable
  {
  
      /**
       * ModuleType ordinal 
       */
      private final int code;
      
      public ModuleTypeWrapper(ModuleType aType) {
          if ( null == aType ) {
              throw new IllegalArgumentException("Type is required");
          }
          code = aType.getValue();
      }
      
      public ModuleType getModuleType() {
          return ModuleType.getModuleType(code);
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/AdminServer.java
  
  Index: AdminServer.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.admin.deployment;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import javax.enterprise.deploy.shared.CommandType;
  import javax.enterprise.deploy.shared.ModuleType;
  import javax.enterprise.deploy.spi.Target;
  import javax.enterprise.deploy.spi.TargetModuleID;
  import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
  import javax.enterprise.deploy.spi.exceptions.TargetException;
  import javax.enterprise.deploy.spi.status.ClientConfiguration;
  import javax.enterprise.deploy.spi.status.DeploymentStatus;
  import javax.enterprise.deploy.spi.status.ProgressListener;
  import javax.enterprise.deploy.spi.status.ProgressObject;
  
  import org.apache.geronimo.deployment.ConfigurationBuilder;
  import org.apache.geronimo.deployment.plugin.DeploymentServer;
  import org.apache.geronimo.deployment.plugin.FailedProgressObject;
  import org.apache.geronimo.deployment.plugin.TargetImpl;
  import org.apache.geronimo.messaging.AbstractEndPoint;
  import org.apache.geronimo.messaging.Node;
  import org.apache.geronimo.messaging.NodeInfo;
  import org.apache.geronimo.messaging.proxy.EndPointProxyInfo;
  import org.apache.xmlbeans.XmlObject;
  
  /**
   * Administration DeploymentServer.
   * <BR>
   * It is in charge of:
   * <UL>
   * <LI>dispatching DeploymentServer operations to deployment Targets; and
   * <LI>consolidating their results.
   * </UL>
   *
   * TODO This implementation assumes that the set of Targets is static.
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:45:59 $
   */
  public class AdminServer
      extends AbstractEndPoint
      implements DeploymentServer
  {
  
      /**
       * Target name to ServerInfo map.
       */
      private final Map nameToInfo;
      
      /**
       * Creates an administration server mounted by the specified node and
       * having the provided identifier. 
       * 
       * @param aNode Hosting Node.
       * @param anID EndPoint identifier.
       */
      public AdminServer(Node aNode, Object anID) {
          super(aNode, anID);
          
          node.getReplacerResolver().append(new DeploymentReplacerResolver());
          
          nameToInfo = new HashMap();
          NodeInfo[] nodes =
              (NodeInfo[]) node.getRemoteNodeInfos().toArray(new NodeInfo[0]);
          for (int i = 0; i < nodes.length; i++) {
              NodeInfo nodeInfo = nodes[i];
              EndPointProxyInfo proxyInfo =
                  new EndPointProxyInfo(ManagedServer.END_POINT_ID,
                      DeploymentServer.class, nodeInfo);
              ServerInfo info = new ServerInfo();
              info.server =
                  (DeploymentServer) node.factoryEndPointProxy(proxyInfo);
              info.target = new TargetImpl(nodeInfo.getName(), null);
              nameToInfo.put(nodeInfo.getName(), info);
          }
      }
      
      public boolean isLocal() {
          return false;
      }
  
      public Target[] getTargets() throws IllegalStateException {
          ServerInfo[] info;
          synchronized(nameToInfo) {
              info = (ServerInfo[]) nameToInfo.values().toArray(new ServerInfo[0]);
          }
          Target[] targets = new Target[info.length];
          for (int i = 0; i < targets.length; i++) {
              targets[i] = info[i].target;
          }
          return targets;
      }
  
      public TargetModuleID[] getRunningModules(final ModuleType moduleType,
          Target[] targetList) throws TargetException {
          ArrayAggregator aggregator = new ArrayAggregator();
          aggregator.setArrayType(new TargetModuleID[0]);
          aggregator.aggregate(targetList, new TargetCommand() {
              public Object execute(
                  DeploymentServer aServer, Target[] aTargets)
                  throws TargetException {
                  return aServer.getRunningModules(moduleType, aTargets);
              }
          });
          return (TargetModuleID[]) aggregator.getAggregatedResult();
      }
  
      public TargetModuleID[] getNonRunningModules(final ModuleType moduleType,
          Target[] targetList) throws TargetException {
          ArrayAggregator aggregator = new ArrayAggregator();
          aggregator.setArrayType(new TargetModuleID[0]);
          aggregator.aggregate(targetList, new TargetCommand() {
              public Object execute(
                  DeploymentServer aServer, Target[] aTargets)
                  throws TargetException {
                  return aServer.getNonRunningModules(moduleType, aTargets);
              }
          });
          return (TargetModuleID[]) aggregator.getAggregatedResult();
      }
  
      public TargetModuleID[] getAvailableModules(final ModuleType moduleType,
          Target[] targetList) throws TargetException {
          ArrayAggregator aggregator = new ArrayAggregator();
          aggregator.setArrayType(new TargetModuleID[0]);
          aggregator.aggregate(targetList, new TargetCommand() {
              public Object execute(
                  DeploymentServer aServer, Target[] aTargets)
                  throws TargetException {
                  return aServer.getAvailableModules(moduleType, aTargets);
              }
          });
          return (TargetModuleID[]) aggregator.getAggregatedResult();
      }
  
      public ProgressObject distribute(Target[] targetList,
          ConfigurationBuilder builder, InputStream jis, XmlObject plan) {
          // validates the deployment configuration data, generates all
          // container specific classes and interfaces.
          final File configFile;
          try {
              configFile = File.createTempFile("deploy", ".car");
              builder.buildConfiguration(configFile, null, jis, plan);
          } catch (Exception e) {
              return new FailedProgressObject(CommandType.DISTRIBUTE,
                  e.getMessage());
          }
          // moves the fully baked archive to the designated deployment targets.
          ProgressObjectAggregator aggregator = new ProgressObjectAggregator();
          try {
              aggregator.aggregate(targetList, new TargetCommand() {
                  public Object execute(
                      DeploymentServer aServer, Target[] aTargets)
                      throws TargetException {
                      try {
                          return aServer.distribute(aTargets, null,
                              new FileInputStream(configFile), null);
                      } catch (FileNotFoundException e) {
                          IllegalStateException exc = new IllegalStateException();
                          exc.initCause(e);
                          throw exc;
                      }
                  }
              });
          } catch (TargetException e) {
              // Never thrown.
              throw new AssertionError(e);
          }
          return (ProgressObject) aggregator.getAggregatedResult();
      }
  
      public ProgressObject start(TargetModuleID[] moduleIDList) {
          TargetModuleIDAggregator aggregator = new TargetModuleIDAggregator();
          aggregator.aggregate(moduleIDList, new TargetModuleIDCommand() {
              public ProgressObject execute(DeploymentServer aServer,
                  TargetModuleID[] anIDst) {
                  return aServer.start(anIDst);
              }
          });
          return aggregator.getAggregatedResult();
      }
  
      public ProgressObject stop(TargetModuleID[] moduleIDList) {
          TargetModuleIDAggregator aggregator = new TargetModuleIDAggregator();
          aggregator.aggregate(moduleIDList, new TargetModuleIDCommand() {
              public ProgressObject execute(DeploymentServer aServer,
                  TargetModuleID[] anIDst) {
                  return aServer.stop(anIDst);
              }
          });
          return aggregator.getAggregatedResult();
      }
  
      public ProgressObject undeploy(TargetModuleID[] moduleIDList) {
          TargetModuleIDAggregator aggregator = new TargetModuleIDAggregator();
          aggregator.aggregate(moduleIDList, new TargetModuleIDCommand() {
              public ProgressObject execute(DeploymentServer aServer,
                  TargetModuleID[] anIDst) {
                  return aServer.undeploy(anIDst);
              }
          });
          return aggregator.getAggregatedResult();
      }
  
      public boolean isRedeploySupported() {
          return false;
      }
  
      public ProgressObject redeploy(TargetModuleID[] moduleIDList, InputStream moduleArchive,
InputStream deploymentPlan) throws UnsupportedOperationException, IllegalStateException {
          throw new UnsupportedOperationException();
      }
  
      public void release() {
          synchronized(nameToInfo) {
              Collection info = nameToInfo.values(); 
              for (Iterator iter = info.iterator(); iter.hasNext();) {
                  ServerInfo curInfo = (ServerInfo) iter.next();
                  node.releaseEndPointProxy(curInfo.server);
                  iter.remove();
              }
          }
      }
  
      private interface TargetCommand {
          public Object execute(DeploymentServer aServer, Target[] aTargets)
              throws TargetException;
      }
   
      private abstract class TargetAggregator {
          
          public abstract Object getAggregatedResult();
          public abstract void addResult(Object anOpaque);
          
          public void aggregate(Target[] targetList, TargetCommand aCommand)
              throws TargetException {
              Map tmpMap = new HashMap();
              synchronized(nameToInfo) {
                  tmpMap.putAll(nameToInfo);
              }
              for (int i = 0; i < targetList.length; i++) {
                  if ( null == nameToInfo.get(targetList[i].getName()) ) {
                      throw new IllegalArgumentException(targetList[i] +
                          " does not exist.");
                  }
              }
              for (int i = 0; i < targetList.length; i++) {
                  ServerInfo info =
                      (ServerInfo) nameToInfo.get(targetList[i].getName());
                  Object opaque =
                      aCommand.execute(info.server, new Target[] {targetList[i]});
                  addResult(opaque);
              }
          }
          
      }
      
      private class ArrayAggregator extends TargetAggregator {
  
          private final Collection result = new ArrayList();
          private Object[] arrayType;
          
          public void setArrayType(Object[] anArrayType) {
              arrayType = anArrayType;
          }
          
          public Object getAggregatedResult() {
              return result.toArray(arrayType);
          }
  
          public void addResult(Object anOpaque) {
              if ( null == anOpaque ) {
                  return;
              }
              TargetModuleID[] ids = (TargetModuleID[]) anOpaque;
              for (int i = 0; i < ids.length; i++) {
                  result.add(ids[i]);
              }
          }
  
      }
  
      private class ProgressObjectAggregator extends TargetAggregator {
  
          private final MultiProgressObject result = new MultiProgressObject();
          
          public Object getAggregatedResult() {
              result.consolidate();
              return result;
          }
  
          public void addResult(Object anOpaque) {
              ProgressObject progress = (ProgressObject) anOpaque;
              result.addProgressObject(progress);
          }
          
      }
      
      private interface TargetModuleIDCommand {
          public ProgressObject execute(
              DeploymentServer aServer, TargetModuleID[] anIDst);
      }
      
      private class TargetModuleIDAggregator {
          
          private final MultiProgressObject result = new MultiProgressObject();
          
          public ProgressObject getAggregatedResult() {
              return result;
          }
  
          public void addResult(ProgressObject aProgress) {
              result.addProgressObject(aProgress);
          }
          
          public void aggregate(TargetModuleID[] moduleIDList,
              TargetModuleIDCommand aCommand) {
              Map tmpMap = new HashMap();
              synchronized(nameToInfo) {
                  tmpMap.putAll(nameToInfo);
              }
              for (int i = 0; i < moduleIDList.length; i++) {
                  Target target= moduleIDList[i].getTarget();
                  if ( null == nameToInfo.get(target.getName()) ) {
                      throw new IllegalArgumentException(
                          target + " does not exist.");
                  }
              }
              for (int i = 0; i < moduleIDList.length; i++) {
                  Target target= moduleIDList[i].getTarget();
                  ServerInfo info =
                      (ServerInfo) tmpMap.get(target.getName());
                  ProgressObject progress =
                      aCommand.execute(info.server,
                          new TargetModuleID[] {moduleIDList[i]});
                  addResult(progress);
              }
          }
          
      }
      
  
      private static class MultiProgressObject implements ProgressObject {
  
          private final Collection progressObjects = new ArrayList();        
  
          private void consolidate() {
              
          }
          
          private void addProgressObject(ProgressObject aProgObject) {
              synchronized(progressObjects) {
                  progressObjects.add(aProgObject);
              }
          }
  
          public DeploymentStatus getDeploymentStatus() {
              return null;
          }
  
          public TargetModuleID[] getResultTargetModuleIDs() {
              return null;
          }
  
          public ClientConfiguration getClientConfiguration(TargetModuleID id) {
              return null;
          }
  
          public boolean isCancelSupported() {
              return false;
          }
  
          public void cancel() throws OperationUnsupportedException {
              throw new OperationUnsupportedException("Not supported");
          }
  
          public boolean isStopSupported() {
              return false;
          }
  
          public void stop() throws OperationUnsupportedException {
              throw new OperationUnsupportedException("Not supported");
          }
  
          public void addProgressListener(ProgressListener pol) {
          }
  
          public void removeProgressListener(ProgressListener pol) {
          }
          
      }
      
      private static class ServerInfo {
          private DeploymentServer server;
          private Target target;
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/TargetImpl2.java
  
  Index: TargetImpl2.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.admin.deployment;
  
  import java.io.Serializable;
  
  import javax.enterprise.deploy.spi.Target;
  
  import org.apache.geronimo.deployment.plugin.TargetImpl;
  
  /**
   * A serializable Target. Should replace TargetImpl.
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:45:59 $
   */
  public class TargetImpl2
      implements Target, Serializable
  {
  
      private final String name;
      private final String description;
      
      public TargetImpl2(TargetImpl aTarget) {
          name = aTarget.getName();
          description = aTarget.getDescription();
      }
  
      public String getName() {
          return name;
      }
  
      public String getDescription() {
          return description;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/DeploymentReplacerResolver.java
  
  Index: DeploymentReplacerResolver.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.admin.deployment;
  
  import java.io.IOException;
  
  import javax.enterprise.deploy.shared.ModuleType;
  
  import org.apache.geronimo.deployment.plugin.TargetImpl;
  import org.apache.geronimo.messaging.io.AbstractReplacerResolver;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:45:59 $
   */
  public class DeploymentReplacerResolver
      extends AbstractReplacerResolver
  {
  
      protected Object customReplaceObject(Object obj) throws IOException {
          if ( obj instanceof TargetImpl ) {
              return new TargetImpl2((TargetImpl) obj);
          } else if ( obj instanceof ModuleType ) {
              return new ModuleTypeWrapper((ModuleType) obj);
          }
          return null;
      }
  
      protected Object customResolveObject(Object obj) throws IOException {
          if ( obj instanceof TargetImpl2 ) {
              TargetImpl2 target = (TargetImpl2) obj; 
              return new TargetImpl(target.getName(), target.getDescription());
          } else if ( obj instanceof ModuleTypeWrapper ) {
              return ((ModuleTypeWrapper)obj).getModuleType();
          }
          return null;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/ManagedServer.java
  
  Index: ManagedServer.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.admin.deployment;
  
  import java.io.BufferedOutputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.net.URL;
  import java.util.jar.Manifest;
  
  import javax.enterprise.deploy.shared.ModuleType;
  import javax.enterprise.deploy.spi.Target;
  import javax.enterprise.deploy.spi.TargetModuleID;
  import javax.enterprise.deploy.spi.exceptions.TargetException;
  import javax.enterprise.deploy.spi.status.ProgressObject;
  
  import org.apache.geronimo.deployment.ConfigurationBuilder;
  import org.apache.geronimo.deployment.DeploymentException;
  import org.apache.geronimo.deployment.plugin.DeploymentServer;
  import org.apache.geronimo.deployment.plugin.TargetImpl;
  import org.apache.geronimo.deployment.plugin.local.DistributeCommand;
  import org.apache.geronimo.deployment.plugin.local.StartCommand;
  import org.apache.geronimo.deployment.plugin.local.StopCommand;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.kernel.KernelMBean;
  import org.apache.geronimo.kernel.config.ConfigurationStore;
  import org.apache.geronimo.messaging.AbstractEndPoint;
  import org.apache.geronimo.messaging.Node;
  import org.apache.geronimo.messaging.reference.ReferenceableEnhancer;
  import org.apache.xmlbeans.SchemaTypeLoader;
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.XmlObject;
  
  /**
   * Managed DeploymentServer.
   * <BR>
   * It is a DeploymentServer managed by an AdminServer. Deployments
   * operations are filtered and forwarded to managed DeploymentServers. These
   * latter perform the operations locally and return to the admin server a
   * result. Results are consolidated by the admin server, which provides a 
   * consistent view of the deployment operations.
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:45:59 $
   */
  public class ManagedServer
      extends AbstractEndPoint
      implements DeploymentServer
  {
  
      /**
       * EndPoint identifier of a ManagedDeploymentServer.
       */
      public static final Object END_POINT_ID = "DeploymentServerWrapper";
  
      private final Target target;
      private final ConfigurationStore store;
      private final Kernel kernel;
      
      /**
       * Creates a managed deployment server for the specified node.
       * 
       * @param aNode Hosting Node.
       * @param aStore Where the deployment are distributed.
       * @param aKernel Used to control - start, stop et cetera - and query
       * deployments.
       */
      public ManagedServer(Node aNode, ConfigurationStore aStore,
          KernelMBean aKernel) {
          super(aNode, END_POINT_ID);
          if ( null == aStore ) {
              throw new IllegalArgumentException("Store is required");
          } else if ( null == aKernel ) {
              throw new IllegalArgumentException("Kernel is required");
          }
          
          target = new TargetImpl(aNode.getNodeInfo().getName(), null);
          store = aStore;
          // TODO why the various CommandSupports take as parameter a Kernel?
          // Should be a KernelMBean
          kernel = (Kernel) aKernel;
          
          node.getReplacerResolver().append(new DeploymentReplacerResolver());
      }
      
      public ProgressObject distribute(
          Target[] targetList,
          ConfigurationBuilder builder,
          InputStream jis,
          XmlObject plan)
          throws IllegalStateException {
          // The administration server has already built the module configuration.
          // Provides a No-op ConfigurationBuilder such that the provided
          // module is saved "as-is" in the data-store.
          // Injects the Referenceable interface such that the ProgressObject
          // is not marshalled.
          DistributeCommand command =
              new DistributeCommand(
                  store,
                  new NoOpConfigurationBuilder(),
                  jis,
                  null);
          new Thread(command).start();
          return (ProgressObject) ReferenceableEnhancer.enhance(command);
      }
  
      public TargetModuleID[] getAvailableModules(
          ModuleType moduleType,
          Target[] targetList)
          throws TargetException, IllegalStateException {
          return null;
      }
  
      public TargetModuleID[] getNonRunningModules(
          ModuleType moduleType,
          Target[] targetList)
          throws TargetException, IllegalStateException {
          return null;
      }
  
      public TargetModuleID[] getRunningModules(
          ModuleType moduleType,
          Target[] targetList)
          throws TargetException, IllegalStateException {
          return null;
      }
  
      public Target[] getTargets() throws IllegalStateException {
          return new Target[] {target};
      }
  
      public boolean isLocal() {
          return true;
      }
  
      public boolean isRedeploySupported() {
          return false;
      }
  
      public ProgressObject redeploy(
          TargetModuleID[] moduleIDList,
          InputStream moduleArchive,
          InputStream deploymentPlan)
          throws UnsupportedOperationException, IllegalStateException {
          throw new UnsupportedOperationException("Not yet supported.");
      }
  
      public void release() {
      }
  
      public ProgressObject start(TargetModuleID[] moduleIDList)
          throws IllegalStateException {
          StartCommand command = new StartCommand(kernel, moduleIDList);
          new Thread(command).start();
          return (ProgressObject) ReferenceableEnhancer.enhance(command);
      }
  
      public ProgressObject stop(TargetModuleID[] moduleIDList)
          throws IllegalStateException {
          StopCommand command = new StopCommand(kernel, moduleIDList);
          new Thread(command).start();
          return (ProgressObject) ReferenceableEnhancer.enhance(command);
      }
  
      public ProgressObject undeploy(TargetModuleID[] moduleIDList)
          throws IllegalStateException {
          throw new UnsupportedOperationException();
      }
  
      private class NoOpConfigurationBuilder implements ConfigurationBuilder {
  
          public SchemaTypeLoader[] getTypeLoaders() {
              throw new UnsupportedOperationException();
          }
  
          public boolean canConfigure(XmlObject plan) {
              throw new UnsupportedOperationException();
          }
  
          public XmlObject getDeploymentPlan(URL module) throws XmlException {
              throw new UnsupportedOperationException();
          }
  
          public void buildConfiguration(File outfile, Manifest manifest,
              File module, XmlObject plan)
              throws IOException, DeploymentException {
              throw new UnsupportedOperationException();
          }
  
          public void buildConfiguration(File outfile, Manifest manifest,
              InputStream module, XmlObject plan)
              throws IOException, DeploymentException {
              FileOutputStream output = new FileOutputStream(outfile);
              try {
                  OutputStream bufOut = new BufferedOutputStream(output);
                  byte[] buffer = new byte[1024];
                  int nbRead;
                  while ( -1 != (nbRead = module.read(buffer)) ) {
                      bufOut.write(buffer);
                  }
                  bufOut.flush();
              } finally {
                  output.close();
              }
          }
          
      }
      
  }
  
  
  

Mime
View raw message