Package com.caucho.j2ee.deployclient

Examples of com.caucho.j2ee.deployclient.ProgressObjectImpl


  public ProgressObject distribute(TargetImpl []hostTargets,
                                   InputStream archiveIs,
                                   DeploymentPlan plan)
    throws IllegalStateException
  {
    ProgressObjectImpl progress;
   
    if (hostTargets == null || hostTargets.length != 1) {
      String msg = L.l("jsr88 can only support single-host deploy");
     
      log.warning(msg);

      progress = new ProgressObjectImpl(new TargetModuleID[0]);
   
      progress.failed(msg);

      return progress;
    }

    String hostName = hostTargets[0].getName();

    String name = plan.getName();
    String moduleID;

    ArchiveDeployMXBean mxbean = null;

    try {
      if ("ear".equals(plan.getArchiveType())) {
        moduleID = "resin:name=" + name + ",type=EApp,Host=" + hostName;
     
        String jmxName = "resin:type=EarDeploy,Host=" + hostName + ",*";
        mxbean = loadArchiveMXBean(jmxName);
      }
      else if ("war".equals(plan.getArchiveType())) {
        moduleID = "resin:name=/" + name + ",type=WebApp,Host=" + hostName;
     
        String jmxName = "resin:type=WebAppDeploy,Host=" + hostName + ",*";
        mxbean = loadArchiveMXBean(jmxName);
      }
      else if ("rar".equals(plan.getArchiveType())) {
        moduleID = "resin:name=" + name + ",type=Resource,Host=" + hostName;
     
        String jmxName = "resin:type=ResourceDeploy,Host=" + hostName + ",*";
        mxbean = loadArchiveMXBean(jmxName);
      }
      else
        throw new UnsupportedOperationException(plan.getArchiveType());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }


    boolean failed = false;
    StringBuilder message = new StringBuilder();

    Path archivePath = null;

    Throwable exception = null;

    TargetImpl childTarget = new TargetImpl(moduleID, "");
   
    TargetModuleIDImpl childModuleID
      = new TargetModuleIDImpl(childTarget, moduleID);
   
    if (mxbean != null) {
      try {
        Path deployPath = Vfs.lookup(mxbean.getArchivePath(name));

        deployPath.getParent().mkdirs();

        if (archivePath == null) {
          createArchive(deployPath, plan, archiveIs);
          archivePath = deployPath;
        }
        else {
          WriteStream deployStream = deployPath.openWrite();

          try {
            deployStream.writeFile(archivePath);
          }
          finally {
            deployStream.close();
          }
        }

        mxbean.update();

        exception = mxbean.getConfigException(name);
      }
      catch (Exception e) {
        if (log.isLoggable(Level.INFO))
          log.log(Level.INFO, e.toString(), e);

        exception = e;
      }

      if (exception != null) {
        failed = true;
        describe(message, childModuleID, false, getExceptionMessage(exception));

        /*
          if (mxbean != null) {
          try {
          mxbean.undeploy(moduleID);
          }
          catch (Throwable t) {
          log.log(Level.FINE, t.toString(), t);
          }
          }
        */
      }
      else {
        if ("ear".equals(plan.getArchiveType())) {
          try {
            EAppMXBean eApp = (EAppMXBean) Jmx.find(moduleID);

            if (eApp != null)
              childTarget.setClientRefs(eApp.getClientRefs());
          } catch (Exception e) {
            log.log(Level.FINEST, e.toString(), e);
          }
        }

        describe(message, childModuleID, true);
      }
    }
    else {
      failed = true;
      log.warning(L.l("jsr88 cannot deploy '{0}', can't find deployment resource (e.g. web-app-deploy, ear-deploy).", moduleID));
    }
   
    TargetModuleID []targetModuleIDs
      = new TargetModuleID[] { childModuleID };

    progress = new ProgressObjectImpl(targetModuleIDs);
   
    if (failed)
      progress.failed(message.toString());
    else
      progress.completed(message.toString());

    return progress;
  }
View Full Code Here


    }
  }

  public ProgressObject start(TargetModuleID[] ids)
  {
    ProgressObjectImpl progress =  new ProgressObjectImpl(ids);

    boolean failed = false;
    StringBuilder message = new StringBuilder();

    for (TargetModuleID targetModuleID : ids) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, L.l("jsr88 starting {0}", targetModuleID.getModuleID()));

      Throwable exception = null;
      DeployControllerMXBean mxbean = null;

      try {
        ObjectName objectName = new ObjectName(targetModuleID.getModuleID());
        mxbean = (DeployControllerMXBean) Jmx.find(objectName);
        if (mxbean != null)
          mxbean.start();
        else {
          log.finer("Jsr88[] " + objectName + " is an unknown module");
          failed = true;
        }
      }
      catch (Exception t) {
        log.log(Level.INFO, t.toString(), t);
        // XXX: need to handle depending on type
        exception = t;
      }

      /*
      if (exception == null && mxbean != null) {
        // XXX: temp for types
        exception = null;
      }
      */

      if (exception != null) {
        failed  = true;
        describe(message, targetModuleID, false, getExceptionMessage(exception));
      }
      else
        describe(message, targetModuleID, true);
    }

    if (failed)
      progress.failed(L.l("start {0}", message));
    else
      progress.completed(L.l("start {0}", message));

    return progress;
  }
View Full Code Here

    return progress;
  }

  public ProgressObject stop(TargetModuleID[] ids)
  {
    ProgressObjectImpl progress =  new ProgressObjectImpl(ids);

    boolean failed = false;
    StringBuilder message = new StringBuilder();

    for (TargetModuleID targetModuleID : ids) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, L.l("jsr88 stopping {0}", targetModuleID.getModuleID()));

      Throwable exception = null;
      DeployControllerMXBean mxbean = null;

      try {
        ObjectName objectName = new ObjectName(targetModuleID.getModuleID());
        mxbean = (DeployControllerMXBean) Jmx.find(objectName);
        if (mxbean != null)
          mxbean.stop();
        else {
          log.finer("Jsr88[] " + objectName + " is an unknown module");
          failed = true;
        }
      }
      catch (Exception t) {
        log.log(Level.INFO, t.toString(), t);
        // XXX: need to handle depending on type
        exception = t;
      }

      /*
      if (exception == null && mxbean != null) {
        // XXX: temp for types
        exception = null;
      }
      */

      if (exception != null) {
        failed  = true;
        describe(message, targetModuleID, false, getExceptionMessage(exception));
      }
      else
        describe(message, targetModuleID, true);
    }

    if (failed)
      progress.failed(L.l("stop {0}", message));
    else
      progress.completed(L.l("stop {0}", message));

    return progress;
  }
View Full Code Here

  }

  public ProgressObject undeploy(TargetModuleID []ids)
    throws IllegalStateException
  {
    ProgressObjectImpl progress =  new ProgressObjectImpl(ids);

    boolean failed = false;
    StringBuilder message = new StringBuilder();

    for (TargetModuleID targetModuleID : ids) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, L.l("undeploying {0}", targetModuleID.getModuleID()));

      ArchiveDeployMXBean mxbean = null;
      Throwable exception = null;

      try {
        ObjectName objectName
          = new ObjectName(targetModuleID.getModuleID());
        mxbean = getMXBean(objectName);
        if (mxbean != null)
          mxbean.undeploy(objectName.getKeyProperty("name"));
      }
      catch (Throwable t) {
        log.log(Level.INFO, t.toString(), t);
        exception = t;
      }

      if (exception != null) {
        failed  = true;
        describe(message, targetModuleID, false, getExceptionMessage(exception));
      }
      else
        describe(message, targetModuleID, true);
    }

    if (failed)
      progress.failed(L.l("undeploy {0}", message));
    else
      progress.completed(L.l("undeploy {0}", message));

    return progress;
  }
View Full Code Here

  public ProgressObject distribute(TargetImpl []hostTargets,
                                   InputStream archiveIs,
                                   DeploymentPlan plan)
    throws IllegalStateException
  {
    ProgressObjectImpl progress;
   
    if (hostTargets == null || hostTargets.length != 1) {
      String msg = L.l("jsr88 can only support single-host deploy");
     
      log.warning(msg);

      progress = new ProgressObjectImpl(new TargetModuleID[0]);
   
      progress.failed(msg);

      return progress;
    }

    String hostName = hostTargets[0].getName();

    String name = plan.getName();
    String moduleID;

    ArchiveDeployMXBean mxbean = null;

    try {
      if ("ear".equals(plan.getArchiveType())) {
        moduleID = "resin:name=" + name + ",type=EApp,Host=" + hostName;
     
        String jmxName = "resin:type=EarDeploy,Host=" + hostName + ",*";
        mxbean = loadArchiveMXBean(jmxName);
      }
      else if ("war".equals(plan.getArchiveType())) {
        moduleID = "resin:name=/" + name + ",type=WebApp,Host=" + hostName;
     
        String jmxName = "resin:type=WebAppDeploy,Host=" + hostName + ",*";
        mxbean = loadArchiveMXBean(jmxName);
      }
      else if ("rar".equals(plan.getArchiveType())) {
        moduleID = "resin:name=" + name + ",type=Resource,Host=" + hostName;
     
        String jmxName = "resin:type=ResourceDeploy,Host=" + hostName + ",*";
        mxbean = loadArchiveMXBean(jmxName);
      }
      else
        throw new UnsupportedOperationException(plan.getArchiveType());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }


    boolean failed = false;
    StringBuilder message = new StringBuilder();

    Path archivePath = null;

    Throwable exception = null;

    TargetImpl childTarget = new TargetImpl(moduleID, "");
   
    TargetModuleIDImpl childModuleID
      = new TargetModuleIDImpl(childTarget, moduleID);
   
    if (mxbean != null) {
      try {
  Path deployPath = Vfs.lookup(mxbean.getArchivePath(name));

  deployPath.getParent().mkdirs();

  if (archivePath == null) {
    createArchive(deployPath, plan, archiveIs);
    archivePath = deployPath;
  }
  else {
    WriteStream deployStream = deployPath.openWrite();

    try {
      deployStream.writeFile(archivePath);
    }
    finally {
      deployStream.close();
    }
  }

  mxbean.update();

  exception = mxbean.getConfigException(name);
      }
      catch (Exception e) {
  if (log.isLoggable(Level.INFO))
    log.log(Level.INFO, e.toString(), e);

  exception = e;
      }

      if (exception != null) {
  failed = true;
  describe(message, childModuleID, false, getExceptionMessage(exception));

  /*
    if (mxbean != null) {
    try {
    mxbean.undeploy(moduleID);
    }
    catch (Throwable t) {
    log.log(Level.FINE, t.toString(), t);
    }
    }
  */
      }
      else {
  if ("ear".equals(plan.getArchiveType())) {
    try {
      EAppMXBean eApp = (EAppMXBean) Jmx.find(moduleID);

      if (eApp != null)
        childTarget.setClientRefs(eApp.getClientRefs());
    } catch (Exception e) {
      log.log(Level.FINEST, e.toString(), e);
    }
  }

  describe(message, childModuleID, true);
      }
    }
    else {
      failed = true;
      log.warning(L.l("jsr88 cannot deploy '{0}', can't find deployment resource (e.g. web-app-deploy, ear-deploy).", moduleID));
    }
   
    TargetModuleID []targetModuleIDs
      = new TargetModuleID[] { childModuleID };

    progress = new ProgressObjectImpl(targetModuleIDs);
   
    if (failed)
      progress.failed(message.toString());
    else
      progress.completed(message.toString());

    return progress;
  }
View Full Code Here

    }
  }

  public ProgressObject start(TargetModuleID[] ids)
  {
    ProgressObjectImpl progress =  new ProgressObjectImpl(ids);

    boolean failed = false;
    StringBuilder message = new StringBuilder();

    for (TargetModuleID targetModuleID : ids) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, L.l("jsr88 starting {0}", targetModuleID.getModuleID()));

      Throwable exception = null;
      DeployControllerMXBean mxbean = null;

      try {
        ObjectName objectName = new ObjectName(targetModuleID.getModuleID());
        mxbean = (DeployControllerMXBean) Jmx.find(objectName);
  if (mxbean != null)
    mxbean.start();
  else {
    log.finer("Jsr88[] " + objectName + " is an unknown module");
    failed = true;
  }
      }
      catch (Exception t) {
        log.log(Level.INFO, t.toString(), t);
        // XXX: need to handle depending on type
        exception = t;
      }

      /*
      if (exception == null && mxbean != null) {
        // XXX: temp for types
        exception = null;
      }
      */

      if (exception != null) {
        failed  = true;
        describe(message, targetModuleID, false, getExceptionMessage(exception));
      }
      else
        describe(message, targetModuleID, true);
    }

    if (failed)
      progress.failed(L.l("start {0}", message));
    else
      progress.completed(L.l("start {0}", message));

    return progress;
  }
View Full Code Here

    return progress;
  }

  public ProgressObject stop(TargetModuleID[] ids)
  {
    ProgressObjectImpl progress =  new ProgressObjectImpl(ids);

    boolean failed = false;
    StringBuilder message = new StringBuilder();

    for (TargetModuleID targetModuleID : ids) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, L.l("jsr88 stopping {0}", targetModuleID.getModuleID()));

      Throwable exception = null;
      DeployControllerMXBean mxbean = null;

      try {
        ObjectName objectName = new ObjectName(targetModuleID.getModuleID());
        mxbean = (DeployControllerMXBean) Jmx.find(objectName);
  if (mxbean != null)
    mxbean.stop();
  else {
    log.finer("Jsr88[] " + objectName + " is an unknown module");
    failed = true;
  }
      }
      catch (Exception t) {
        log.log(Level.INFO, t.toString(), t);
        // XXX: need to handle depending on type
        exception = t;
      }

      /*
      if (exception == null && mxbean != null) {
        // XXX: temp for types
        exception = null;
      }
      */

      if (exception != null) {
        failed  = true;
        describe(message, targetModuleID, false, getExceptionMessage(exception));
      }
      else
        describe(message, targetModuleID, true);
    }

    if (failed)
      progress.failed(L.l("stop {0}", message));
    else
      progress.completed(L.l("stop {0}", message));

    return progress;
  }
View Full Code Here

  }

  public ProgressObject undeploy(TargetModuleID []ids)
    throws IllegalStateException
  {
    ProgressObjectImpl progress =  new ProgressObjectImpl(ids);

    boolean failed = false;
    StringBuilder message = new StringBuilder();

    for (TargetModuleID targetModuleID : ids) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, L.l("undeploying {0}", targetModuleID.getModuleID()));

      ArchiveDeployMXBean mxbean = null;
      Throwable exception = null;

      try {
        ObjectName objectName
          = new ObjectName(targetModuleID.getModuleID());
        mxbean = getMXBean(objectName);
  if (mxbean != null)
    mxbean.undeploy(objectName.getKeyProperty("name"));
      }
      catch (Throwable t) {
        log.log(Level.INFO, t.toString(), t);
        exception = t;
      }

      if (exception != null) {
        failed  = true;
        describe(message, targetModuleID, false, getExceptionMessage(exception));
      }
      else
        describe(message, targetModuleID, true);
    }

    if (failed)
      progress.failed(L.l("undeploy {0}", message));
    else
      progress.completed(L.l("undeploy {0}", message));

    return progress;
  }
View Full Code Here

TOP

Related Classes of com.caucho.j2ee.deployclient.ProgressObjectImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.