Search in sources :

Example 1 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class SunDeploymentManager method deploy.

/**
 * Deploy the specified module to the list of targets.
 * The deployment plan archive can be null.
 *
 * @param targetList the targets to which to deploy the module
 * @param moduleArchive the archive file to be deployed
 * @param deploymentPlan the (optional) deployment plan file
 * @param options set by the caller to override and augment any settings made here
 * @return ProgressObject to communicate progress and results of the deployment
 * @throws IllegalStateException if the DeploymentManager has disconnected
 * @throws IOException if there are problems opening the archive files
 */
private ProgressObject deploy(Target[] targetList, File moduleArchive, File deploymentPlan, Properties options) throws IllegalStateException {
    /*
         *Create archives for the module file and, if present, the deployment plan file, and
         *then delegate to the variant of deploy that accepts archives as arguments.
         */
    ReadableArchive appArchive = null;
    ReadableArchive planArchive = null;
    ArchiveFactory archiveFactory = getArchiveFactory();
    try {
        appArchive = archiveFactory.openArchive(moduleArchive);
        if (deploymentPlan != null && deploymentPlan.length() != 0) {
            planArchive = archiveFactory.openArchive(deploymentPlan);
            if (planArchive == null) {
                throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployapi.spi.noarchivisthandlesplan", "No archivist is able to handle the deployment plan {0}", new Object[] { deploymentPlan.getAbsolutePath() }));
            }
        }
        ProgressObject po = deploy(targetList, appArchive, planArchive, options);
        return po;
    } catch (Exception se) {
        String msg = localStrings.getLocalString("enterprise.deployapi.spi.errpreparearchfile", "Could not prepare archives for module and/or deployment plan files");
        IllegalArgumentException ex = new IllegalArgumentException(msg);
        ex.initCause(se);
        return prepareErrorProgressObject(CommandType.DISTRIBUTE, ex);
    } finally {
        closeArchives(CommandType.DISTRIBUTE, appArchive, moduleArchive.getAbsolutePath(), planArchive, (deploymentPlan != null) ? deploymentPlan.getAbsolutePath() : null);
    }
}
Also used : ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) DeployableObject(javax.enterprise.deploy.model.DeployableObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) DConfigBeanVersionUnsupportedException(javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException) TargetException(javax.enterprise.deploy.spi.exceptions.TargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidModuleException(javax.enterprise.deploy.spi.exceptions.InvalidModuleException)

Example 2 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class SunDeploymentManager method redeploy.

@Override
public ProgressObject redeploy(TargetModuleID[] moduleIDList, File moduleArchive, File deploymentPlan) throws UnsupportedOperationException, IllegalStateException {
    try {
        /*
             *To support multiple different modules in the module ID list, use a TargetModuleIDCollection to
             *organize them and work on each module one at a time.
             */
        TargetModuleIDCollection coll = new TargetModuleIDCollection(moduleIDList);
        for (Iterator<DeploymentFacilityModuleWork> it = coll.iterator(); it.hasNext(); ) {
            DeploymentFacilityModuleWork work = it.next();
            /*
                 *Set the name in the properties according to the moduleID.  The module is the same for all the
                 *targets represented by this single work object.
                 */
            DFDeploymentProperties options = getRedeployOptions(work.getModuleID());
            ProgressObject progress = deploy(work.targets(), moduleArchive, deploymentPlan, options);
            /*
                 *The work instance needs to know about its own progress object, and the
                 *aggregate progress object needs to also.
                 */
            work.setProgressObject(progress);
            coll.getProgressObjectSink().sinkProgressObject(progress);
        }
        return coll.getProgressObjectSink();
    } catch (Throwable e) {
        return prepareErrorProgressObject(CommandType.REDEPLOY, e);
    }
}
Also used : ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) DFDeploymentProperties(org.glassfish.deployment.client.DFDeploymentProperties)

Example 3 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class SunDeploymentManager method closeArchives.

/**
 * Closes the module archive and the plan archive, if any, preparing a ProgressObject if any
 * error occurred.
 *
 * @param commandType the CommandType in progress - used in preparing the progress object
 *            (if needed)
 * @param moduleArchive the main module archive to be closed
 * @param moduleArchiveSpec a String representation of the main module archive
 * @param planArchive the deployment plan archive (if any) to be closed
 * @param planArchiveSpec a String representation of the deployment plan archive (if any)
 *            to be closed
 * @return ProgressObject an error progress object if any error ocurred trying to close
 *         the archive(s)
 */
private ProgressObject closeArchives(CommandType commandType, ReadableArchive moduleArchive, String moduleArchiveSpec, ReadableArchive planArchive, String planArchiveSpec) {
    ProgressObject errorPO = null;
    IOException moduleIOE = closeArchive(moduleArchive);
    IOException planIOE = closeArchive(planArchive);
    IOException excForProgressObject = null;
    String errorMsg = null;
    /*
         *If the module could not be closed, record the IOException resulting from the attempt for
         *use in the error progress object returned to the caller.
         */
    if (moduleIOE != null) {
        excForProgressObject = moduleIOE;
        /*
             *If there was a problem with both the module archive and the plan archive,
             *compose an appropriate message that says both failed.
             */
        if (planIOE != null) {
            errorMsg = localStrings.getLocalString("enterprise.deployapi.spi.errclosearchs", "Could not close module archive {0} or deployment plan archive {1}", new Object[] { moduleArchiveSpec, planArchiveSpec });
        } else {
            /*
                 *Either the plan was closed or there was no plan to close.  To build
                 *a message about only the module archive.
                 */
            errorMsg = localStrings.getLocalString("enterprise.deployapi.spi.errclosemodulearch", "Could not close module archive {0}", new Object[] { moduleArchiveSpec });
        }
    } else if (planIOE != null) {
        /*
             *The module archive was closed fine.  If the plan archive exists and
             *could not be closed, compose an error message to that effect and
             *record the IOException that occurred during the attempt to close the
             *deployment plan archive for use in the error progress object returned
             *to the caller.
             */
        excForProgressObject = planIOE;
        errorMsg = localStrings.getLocalString("enterprise.deployapi.spi.errcloseplanarch", "Could not close deployment plan archive {0}", new Object[] { planArchiveSpec });
    }
    /*
         *If an error occurred trying to close either archive, build an error progress object
         *for return to the caller.
         */
    if (errorMsg != null) {
        IOException ioe = new IOException(errorMsg);
        // Only reflects the module exception if both occurred, but the msg describes both.
        ioe.initCause(excForProgressObject);
        errorPO = prepareErrorProgressObject(commandType, ioe);
    }
    return errorPO;
}
Also used : DeployableObject(javax.enterprise.deploy.model.DeployableObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) IOException(java.io.IOException) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject)

Example 4 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class SunDeploymentManager method redeploy.

@Override
public ProgressObject redeploy(TargetModuleID[] moduleIDList, InputStream moduleArchive, InputStream deploymentPlan) throws UnsupportedOperationException, IllegalStateException {
    try {
        /*
             *To support multiple different modules in the module ID list, use a TargetModuleIDCollection to
             *organize them and work on each module one at a time.
             */
        TargetModuleIDCollection coll = new TargetModuleIDCollection(moduleIDList);
        for (Iterator<DeploymentFacilityModuleWork> it = coll.iterator(); it.hasNext(); ) {
            /*
                 *The iterator returns one work instance for each module present in the collection.
                 */
            DeploymentFacilityModuleWork work = it.next();
            /*
                 *Set the name in the properties according to the moduleID.  The module is the same for all the
                 *targets represented by this single work object.
                 */
            DFDeploymentProperties options = getRedeployOptions(work.getModuleID());
            ProgressObject po = deploy(work.targets(), moduleArchive, deploymentPlan, options);
            /*
                 *The work instance needs to know about its own progress object, and the
                 *aggregate progress object needs to also.
                 */
            work.setProgressObject(po);
            coll.getProgressObjectSink().sinkProgressObject(po);
        }
        return coll.getProgressObjectSink();
    } catch (Throwable e) {
        return prepareErrorProgressObject(CommandType.REDEPLOY, e);
    }
}
Also used : ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) DFDeploymentProperties(org.glassfish.deployment.client.DFDeploymentProperties)

Example 5 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class SunDeploymentManager method executeCommandUsingFacility.

/**
 * Perform the selected command on the DeploymentFacility using the specified target module IDs.
 * <p>
 * Several of the deployment facility methods have the same signature except for the name.
 * This method collects the pre- and post-processing around those method calls in one place,
 * then chooses which of the deployment facility methods to actually invoke based on
 * the command type provided as an argument.
 *
 * @param commandType selects which method should be invoked
 * @param moduleIDList array of TargetModuleID to be started
 * @throws IllegalArgumentException if the command type is not supported
 * @throws IllegalStateException if the deployment manager had been released previously
 */
private ProgressObject executeCommandUsingFacility(CommandType commandType, TargetModuleID[] targetModuleIDList) throws IllegalStateException {
    verifyConnected();
    try {
        /*
         *Create a temporary collection based on the target module IDs to make it easier to deal
         *with the different modules and the set of targets.
         */
        TargetModuleIDCollection coll = new TargetModuleIDCollection(targetModuleIDList);
        for (Iterator<DeploymentFacilityModuleWork> it = coll.iterator(); it.hasNext(); ) {
            /*
             *The iterator returns one work instance for each module present in the collection.
             *Each work instance reflects one invocation of a method on the DeploymentFacility.
             */
            DeploymentFacilityModuleWork work = it.next();
            ProgressObject po = null;
            if (commandType.equals(CommandType.START)) {
                po = deploymentFacility.enable(work.targets(), work.getModuleID());
            } else if (commandType.equals(CommandType.STOP)) {
                po = deploymentFacility.disable(work.targets(), work.getModuleID());
            } else if (commandType.equals(CommandType.UNDEPLOY)) {
                po = deploymentFacility.undeploy(work.targets(), work.getModuleID());
            } else {
                throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployapi.spi.unexpcommand", "Received unexpected deployment facility command ${0}", new Object[] { commandType.toString() }));
            }
            /*
             *The new work instance needs to know about its own progress object, and the
             *aggregate progress object needs to also.
             */
            work.setProgressObject(po);
            coll.getProgressObjectSink().sinkProgressObject(po);
        }
        /*
         *Return the single progress object to return to the caller.
         */
        return coll.getProgressObjectSink();
    } catch (Throwable thr) {
        return prepareErrorProgressObject(commandType, thr);
    }
}
Also used : DeployableObject(javax.enterprise.deploy.model.DeployableObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject)

Aggregations

ProgressObject (javax.enterprise.deploy.spi.status.ProgressObject)9 Iterator (java.util.Iterator)3 DeployableObject (javax.enterprise.deploy.model.DeployableObject)3 DFDeploymentProperties (org.glassfish.deployment.client.DFDeploymentProperties)3 DFProgressObject (org.glassfish.deployment.client.DFProgressObject)3 IOException (java.io.IOException)2 OperationUnsupportedException (javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 MalformedURLException (java.net.MalformedURLException)1 Collection (java.util.Collection)1 TargetModuleID (javax.enterprise.deploy.spi.TargetModuleID)1 DConfigBeanVersionUnsupportedException (javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException)1 InvalidModuleException (javax.enterprise.deploy.spi.exceptions.InvalidModuleException)1 TargetException (javax.enterprise.deploy.spi.exceptions.TargetException)1 DeploymentStatus (javax.enterprise.deploy.spi.status.DeploymentStatus)1 ProgressEvent (javax.enterprise.deploy.spi.status.ProgressEvent)1 ProgressListener (javax.enterprise.deploy.spi.status.ProgressListener)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 DFDeploymentStatus (org.glassfish.deployment.client.DFDeploymentStatus)1