0 Replies Latest reply on Jul 17, 2013 9:51 PM by john.sanda

    how to detect archive deployment error

    john.sanda

      I am deploying an EAR to a remote JBoss AS 7 instance. I recently spent some time debugging some test failures. The failures turned out to be in the deployment of the EAR itself, and not in any tests. This is in no way obvious from the output. I am not terribly familiar with Arquillian so my apologies in advance if I am missing something obvious. We are using a custom deployment extension so that we only deploy the EAR once. The code for it looks like,

       

       

      public class CCMSuiteDeploymentExtension implements LoadableExtension {

       

          public void register(ExtensionBuilder builder) {

              builder.observer(SuiteDeployer.class);

          }

       

          public static class SuiteDeployer {

       

              private Class<?> deploymentClass;

              private DeploymentScenario suiteDeploymentScenario;

              private CassandraClusterManager ccm;

       

              @Inject

              @ClassScoped

              private InstanceProducer<DeploymentScenario> classDeploymentScenario;

       

              @Inject

              private Event<DeploymentEvent> deploymentEvent;

       

              @Inject

              private Event<GenerateDeployment> generateDeploymentEvent;

       

              @Inject

              // Active some form of ClassContext around our deployments due to assumption bug in AS7 extension.

              private Instance<ClassContext> classContext;

       

              public void startup(@Observes(precedence = -100)

              ManagerStarted event, ArquillianDescriptor descriptor) {

                  deploymentClass = getDeploymentClass(descriptor);

       

                  executeInClassScope(new Callable<Void>() {

                      public Void call() throws Exception {

                          generateDeploymentEvent.fire(new GenerateDeployment(new TestClass(deploymentClass)));

                          suiteDeploymentScenario = classDeploymentScenario.get();

                          return null;

                      }

                  });

              }

       

              public void initCassandra(@Observes(precedence = -100)

              final BeforeStart event, ArquillianDescriptor descriptor) {

                  executeInClassScope(new Callable<Void>() {

                      public Void call() throws Exception {

                          SchemaManager schemaManager;

                          ClusterInitService clusterInitService = new ClusterInitService();

                          List<StorageNode> nodes = Collections.emptyList();

       

                          if (!Boolean.valueOf(System.getProperty("itest.use-external-storage-node", "false"))) {

                              DeploymentOptionsFactory factory = new DeploymentOptionsFactory();

                              DeploymentOptions options = factory.newDeploymentOptions();

                              File basedir = new File("target");

                              File clusterDir = new File(basedir, "cassandra");

       

                              options.setUsername("rhqadmin");

                              options.setPassword("rhqadmin");

                              options.setClusterDir(clusterDir.getAbsolutePath());

                              options.setHeapSize("256M");

                              options.setHeapNewSize("64M");

                              options.setStartRpc(true);

       

                              ccm = new CassandraClusterManager(options);

                              nodes = ccm.createCluster();

                              ccm.startCluster(false);

       

                              try {

                                  clusterInitService.waitForClusterToStart(nodes, nodes.size(), 1500, 20, 5);

                                  schemaManager = new SchemaManager("rhqadmin", "rhqadmin", nodes);

                              } catch (Exception e) {

                                  if (null != ccm) {

                                      ccm.shutdownCluster();

                                  }

                                  throw new RuntimeException("Cassandra cluster initialization failed", e);

                              }

                          } else {

                              try {

                                  String seed = System.getProperty("rhq.cassandra.seeds", "127.0.0.1|7199|9042");

                                  schemaManager = new SchemaManager("rhqadmin", "rhqadmin", seed);

       

       

                              } catch (Exception e) {

                                  throw new RuntimeException("External Cassandra initialization failed", e);

                              }

                          }

       

                          try {

                              schemaManager.install();

                              clusterInitService.waitForSchemaAgreement(nodes);

                              schemaManager.updateTopology(true);

                          } catch (Exception e) {

                              if (null != ccm) {

                                  ccm.shutdownCluster();

                              }

                              throw new RuntimeException("Cassandra schema initialization failed", e);

                          }

                          return null;

                      }

                  });

              }

       

              public void deploy(@Observes final AfterStart event, final ContainerRegistry registry) {

                  executeInClassScope(new Callable<Void>() {

                      public Void call() throws Exception {

                          for (Deployment d : suiteDeploymentScenario.deployments()) {

                              deploymentEvent.fire(new DeployDeployment(findContainer(registry,

                                  event.getDeployableContainer()), d));

                          }

                          return null;

                      }

                  });

              }

       

              public void undeploy(@Observes final BeforeStop event, final ContainerRegistry registry) {

                  executeInClassScope(new Callable<Void>() {

                      public Void call() throws Exception {

                          for (Deployment d : suiteDeploymentScenario.deployments()) {

                              deploymentEvent.fire(new UnDeployDeployment(findContainer(registry,

                                  event.getDeployableContainer()), d));

                          }

                          return null;

                      }

                  });

              }

       

       

              public void shutdownCassandra(@Observes final AfterStop event, ArquillianDescriptor descriptor) {

                  executeInClassScope(new Callable<Void>() {

                      public Void call() throws Exception {

                          if (null != ccm) {

                              ccm.shutdownCluster();

                          }

                          return null;

                      }

                  });

              }

       

              public void overrideBefore(@Observes EventContext<BeforeClass> event) {

                  // Don't continue TestClass's BeforeClass context as normal.

                  // No DeploymentGeneration or Deploy will take place.

                  classDeploymentScenario.set(suiteDeploymentScenario);

              }

       

              public void overrideAfter(@Observes EventContext<AfterClass> event) {

                  // Don't continue TestClass's AfterClass context as normal.

                  // No UnDeploy will take place.

              }

       

              private void executeInClassScope(Callable<Void> call) {

                  try {

                      classContext.get().activate(deploymentClass);

                      call.call();

                  } catch (Exception e) {

                      throw new RuntimeException("Could not invoke operation", e);

                  } finally {

                      classContext.get().deactivate();

                  }

              }

       

              private Container findContainer(ContainerRegistry registry, DeployableContainer<?> deployable) {

                  for (Container container : registry.getContainers()) {

                      if (container.getDeployableContainer() == deployable) {

                          return container;

                      }

                  }

                  return null;

              }

       

              private Class<?> getDeploymentClass(ArquillianDescriptor descriptor) {

                  if (descriptor == null) {

                      throw new IllegalArgumentException("Descriptor must be specified");

                  }

                  String className = descriptor.extension("suite").getExtensionProperties().get("deploymentClass");

                  if (className == null) {

                      throw new IllegalArgumentException(

                          "A extension element with property deploymentClass must be specified in arquillian.xml");

                  }

                  try {

                      return Class.forName(className);

                  } catch (ClassNotFoundException e) {

                      throw new RuntimeException("Could not load defined deploymentClass: " + className, e);

                  }

              }

          }

      }

       

       

      The deployment error was due in part to a renaming of an EJB jar. There are other times when I hit deployment errors for one reason or another, and I always have to scroll through lots of output (from maven/surefire) to find out if it is a deployment error. Is there a way to detect deployment errors and report it in such a way to make it obvious?

       

      Thanks

       

      John