Package org.glassfish.deployapi

Examples of org.glassfish.deployapi.ProgressObjectImpl


     * @return DFProgressObject the caller can use to monitor progress and query final status
     */
    protected DFProgressObject changeState(Target[] targets, String moduleID, String commandName, String action) {
        ensureConnected();
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();
        try {
            for (Target target : targets) {
                Map commandParams = new HashMap();
                commandParams.put(DFDeploymentProperties.TARGET, target.getName());
                DFCommandRunner commandRunner = getDFCommandRunner(commandName, commandParams, new String[]{moduleID});
                DFDeploymentStatus ds = commandRunner.run();
                DFDeploymentStatus mainStatus = ds.getMainStatus();
                if(!po.checkStatusAndAddStage((TargetImpl)target, localStrings.getLocalString("enterprise.deployment.client.change_state", "{0} of {1} in target {2}", action, moduleID, target.getName()), mainStatus)) {
                    return po;
                } else {
                    TargetModuleIDImpl targetModuleID =
                        new TargetModuleIDImpl((TargetImpl)target, moduleID);
                    targetModuleIDList.add(targetModuleID);
                }
            }
            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.change_state_all", "{0} of application in all targets", action), (TargetImpl)targets[0],  targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.state_change_failed", "Attempt to change the state of the application {0} failed - {1}", moduleID, ioex.toString()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here


    protected DFProgressObject changeAppRef(Target[] targets, String moduleID, String commandName, String action, Map options) {
        ensureConnected();
        Throwable commandExecutionException = null;
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();
        try {
            for (Target target : targets) {
                options.put(DFDeploymentProperties.TARGET, target.getName());
                String[] operands = new String[] {moduleID};
                DFDeploymentStatus mainStatus = null;
                DFCommandRunner commandRunner = getDFCommandRunner(commandName, options, operands);
                DFDeploymentStatus ds = commandRunner.run();
                mainStatus = ds.getMainStatus();
                if(!po.checkStatusAndAddStage((TargetImpl)target, localStrings.getLocalString("enterprise.deployment.client.create_reference", "Creation of reference for application in target {0}", target.getName()),  mainStatus)) {
                    return po;
                } else {
                    TargetModuleIDImpl targetModuleID =
                        new TargetModuleIDImpl((TargetImpl)target, moduleID);
                    targetModuleIDList.add(targetModuleID);
                }
            }
            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.change_reference_application", "{0} of application reference in all targets", action), (TargetImpl)targets[0], targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
           po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.change_reference_application_failed", "{0} of application reference failed - {1}", action, ioex.getMessage()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

     * @return DFProgressObject the caller can use to monitor progress and query status
     */
    public DFProgressObject deploy(Target[] targets, URI source, URI deploymentPlan, Map deploymentOptions) {
        ensureConnected();
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();

        //Make sure the file permission is correct when deploying a file
        if (source == null) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.archive_not_specified", "Archive to be deployed is not specified at all."), (TargetImpl)targets[0]);
            return po;
        }
        File tmpFile = new File(source.getSchemeSpecificPart());
        if (!tmpFile.exists()) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.archive_not_in_location", "Unable to find the archive to be deployed in specified location."), domain);
            return po;
        }
        if (!tmpFile.canRead()) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.archive_no_read_permission", "Archive to be deployed does not have read permission."), domain);
            return po;
        }
        try {
            if (deploymentPlan != null) {
                File dp = new File(deploymentPlan.getSchemeSpecificPart());
                if (!dp.exists()) {
                    po.setupForAbnormalExit(localStrings.getLocalString(
                            "enterprise.deployment.client.plan_not_in_location",
                            "Unable to find the deployment plan in specified location."), domain);
                    return po;
                }
                if (!dp.canRead()) {
                    po.setupForAbnormalExit(localStrings.getLocalString(
                            "enterprise.deployment.client.plan_no_read_permission",
                            "Deployment plan does not have read permission."), domain);
                    return po;
                }
                deploymentOptions.put(DFDeploymentProperties.DEPLOYMENT_PLAN, dp.getAbsolutePath());
            }

            // it's redeploy, set the enable attribute accordingly
            boolean isRedeploy = Boolean.valueOf((String)deploymentOptions.remove(DFDeploymentProperties.REDEPLOY));
            if (isRedeploy) {
                String appName = (String)deploymentOptions.get(
                    DFDeploymentProperties.NAME);
                if (!isTargetsMatched(appName, targets)) {
                    po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.specifyAllTargets", "Application {0} is already deployed on other targets. Please remove all references or specify all targets (or domain target if using asadmin command line) before attempting {1} operation", appName, "redeploy"), domain);
                }
                // set the enable attribute accordingly
                String enabledAttr = getAppRefEnabledAttr(
                    targets[0].getName(), appName);
                deploymentOptions.put(DFDeploymentProperties.ENABLED,
                    enabledAttr);
            }

            Target[] origTargets = targets;

            // first deploy to first target
            if (isRedeploy && targets.length > 1) {
                // if it's redeploy and having more than one target,
                // we should just redeploy with the special domain target
                targets = createTargets(new String[] {"domain"});
            }
            deploymentOptions.put(DFDeploymentProperties.TARGET, targets[0].getName());   
            DFCommandRunner commandRunner = getDFCommandRunner(
                "deploy", deploymentOptions, new String[]{tmpFile.getAbsolutePath()});
            DFDeploymentStatus ds = commandRunner.run();
            DFDeploymentStatus mainStatus = ds.getMainStatus();
            String moduleID;
            if (!po.checkStatusAndAddStage((TargetImpl)targets[0], localStrings.getLocalString("enterprise.deployment.client.deploy_to_first_target", "Deploying application to target {0}", targets[0].getName()),  mainStatus)) {
                return po;
            } else {
                moduleID = mainStatus.getProperty(DFDeploymentProperties.NAME);
                if (moduleID == null) {
                    moduleID = (String)deploymentOptions.get(DFDeploymentProperties.NAME);
                }
                po.setModuleID(moduleID);
            }

            Map createAppRefOptions = new HashMap();
            if (deploymentOptions.get(DFDeploymentProperties.ENABLED) != null) {
                createAppRefOptions.put(DFDeploymentProperties.ENABLED, deploymentOptions.get(DFDeploymentProperties.ENABLED));
            }
            if (deploymentOptions.get(DFDeploymentProperties.VIRTUAL_SERVERS) != null) {
                createAppRefOptions.put(DFDeploymentProperties.VIRTUAL_SERVERS, deploymentOptions.get(DFDeploymentProperties.VIRTUAL_SERVERS));
            }
            // then create application references to the rest of the targets
            for (int i = 1; i < targets.length; i++) {
                createAppRefOptions.put(DFDeploymentProperties.TARGET, targets[i].getName());   
                DFCommandRunner commandRunner2 = getDFCommandRunner(
                    "create-application-ref", createAppRefOptions, new String[] {moduleID});
                DFDeploymentStatus ds2 = commandRunner2.run();
                DFDeploymentStatus mainStatus2 = ds2.getMainStatus();
                if (!po.checkStatusAndAddStage((TargetImpl)targets[i],
"create app ref", mainStatus2)) {
                    return po;
                }
            }
            // we use origTargets to populate the targetModuleIDList
            // so it takes care of the redeploy using domain target case too
            for (int i = 0; i < origTargets.length; i++) {
                TargetModuleIDImpl targetModuleID = new TargetModuleIDImpl((TargetImpl)origTargets[i], moduleID);
                targetModuleIDList.add(targetModuleID);
            }

            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.deploy_application", "Deployment of application {0}", moduleID), (TargetImpl)targets[0], targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.deploy_application_failed", "Deployment of application failed - {0} ", ioex.toString()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

     * @return DFProgressObject for monitoring progress and querying status
     */
    public DFProgressObject undeploy(Target[] targets, String moduleID, Map undeploymentOptions) {
        ensureConnected();
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();
        try {
            if (!isTargetsMatched(moduleID, targets)) {
                po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.specifyAllTargets", "Application {0} is already deployed on other targets. Please remove all references or specify all targets (or domain target if using asadmin command line) before attempting {1} operation", moduleID, "undeploy"), domain);
            }

            // first remove the application references from targets except
            // last one
            Map deleteAppRefOptions = new HashMap();
            if (undeploymentOptions.get(DFDeploymentProperties.CASCADE) != null) {
                deleteAppRefOptions.put(DFDeploymentProperties.CASCADE, undeploymentOptions.get(DFDeploymentProperties.CASCADE));
            }
            for (int i = 0 ; i < targets.length - 1 ; i++) {
                deleteAppRefOptions.put(DFDeploymentProperties.TARGET, targets[i].getName());
                DFCommandRunner commandRunner = getDFCommandRunner(
                    "delete-application-ref", deleteAppRefOptions, new String[] {moduleID});
                DFDeploymentStatus ds = commandRunner.run();
                DFDeploymentStatus mainStatus = ds.getMainStatus();
                if (!po.checkStatusAndAddStage((TargetImpl)targets[i], localStrings.getLocalString("enterprise.deployment.client.undeploy_remove_ref", "While undeploying, trying to remove reference for application in target {0}", targets[i].getName()), mainStatus)) {
                    return po;
                } else {
                    TargetModuleIDImpl targetModuleID =
                       new TargetModuleIDImpl((TargetImpl)targets[i], moduleID);
                    targetModuleIDList.add(targetModuleID);
                }
            }

            // then undeploy from last target
            Target lastTarget = targets[targets.length -1];
            undeploymentOptions.put(DFDeploymentProperties.TARGET, lastTarget.getName());
            DFCommandRunner commandRunner2 = getDFCommandRunner(
                    "undeploy",
                    undeploymentOptions,
                    new String[]{moduleID});
            DFDeploymentStatus ds2 = commandRunner2.run();
            DFDeploymentStatus mainStatus2 = ds2.getMainStatus();
            if (!po.checkStatusAndAddStage((TargetImpl)lastTarget, localStrings.getLocalString("enterprise.deployment.client.undeploy_from_target", "Trying to undeploy application from target {0}", lastTarget.getName()), mainStatus2)) {
                return po;
            }

            TargetModuleIDImpl targetModuleID =
                new TargetModuleIDImpl((TargetImpl)lastTarget, moduleID);
            targetModuleIDList.add(targetModuleID);

            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);

            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.undeploy_application", "Undeployment of application {0}", moduleID), (TargetImpl)targets[0], targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.undeploy_application_failed", "Undeployment failed - {0}", ioex.toString()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

     * @return DFProgressObject the caller can use to monitor progress and query final status
     */
    protected DFProgressObject changeState(Target[] targets, String moduleID, String commandName, String action) {
        ensureConnected();
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();
        try {
            for (Target target : targets) {
                Map commandParams = new HashMap();
                commandParams.put(DFDeploymentProperties.TARGET, target.getName());
                DFCommandRunner commandRunner = getDFCommandRunner(commandName, commandParams, new String[]{moduleID});
                DFDeploymentStatus ds = commandRunner.run();
                DFDeploymentStatus mainStatus = ds.getMainStatus();
                if(!po.checkStatusAndAddStage((TargetImpl)target, localStrings.getLocalString("enterprise.deployment.client.change_state", "{0} of {1} in target {2}", action, moduleID, target.getName()), mainStatus)) {
                    return po;
                } else {
                    TargetModuleIDImpl targetModuleID =
                        new TargetModuleIDImpl((TargetImpl)target, moduleID);
                    targetModuleIDList.add(targetModuleID);
                }
            }
            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.change_state_all", "{0} of application in all targets", action), (TargetImpl)targets[0],  targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.state_change_failed", "Attempt to change the state of the application {0} failed - {1}", moduleID, ioex.toString()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

    protected DFProgressObject changeAppRef(Target[] targets, String moduleID, String commandName, String action, Map options) {
        ensureConnected();
        Throwable commandExecutionException = null;
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();
        try {
            for (Target target : targets) {
                options.put(DFDeploymentProperties.TARGET, target.getName());
                String[] operands = new String[] {moduleID};
                DFDeploymentStatus mainStatus = null;
                DFCommandRunner commandRunner = getDFCommandRunner(commandName, options, operands);
                DFDeploymentStatus ds = commandRunner.run();
                mainStatus = ds.getMainStatus();
                if(!po.checkStatusAndAddStage((TargetImpl)target, localStrings.getLocalString("enterprise.deployment.client.create_reference", "Creation of reference for application in target {0}", target.getName()),  mainStatus)) {
                    return po;
                } else {
                    TargetModuleIDImpl targetModuleID =
                        new TargetModuleIDImpl((TargetImpl)target, moduleID);
                    targetModuleIDList.add(targetModuleID);
                }
            }
            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.change_reference_application", "{0} of application reference in all targets", action), (TargetImpl)targets[0], targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
           po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.change_reference_application_failed", "{0} of application reference failed - {1}", action, ioex.getMessage()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

     * @return DFProgressObject the caller can use to monitor progress and query status
     */
    public DFProgressObject deploy(Target[] targets, URI source, URI deploymentPlan, Map deploymentOptions) {
        ensureConnected();
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();

        //Make sure the file permission is correct when deploying a file
        if (source == null) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.archive_not_specified", "Archive to be deployed is not specified at all."), (TargetImpl)targets[0]);
            return po;
        }
        File tmpFile = new File(source.getSchemeSpecificPart());
        if (!tmpFile.exists()) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.archive_not_in_location", "Unable to find the archive to be deployed in specified location."), domain);
            return po;
        }
        if (!tmpFile.canRead()) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.archive_no_read_permission", "Archive to be deployed does not have read permission."), domain);
            return po;
        }
        try {
            if (deploymentPlan != null) {
                File dp = new File(deploymentPlan.getSchemeSpecificPart());
                if (!dp.exists()) {
                    po.setupForAbnormalExit(localStrings.getLocalString(
                            "enterprise.deployment.client.plan_not_in_location",
                            "Unable to find the deployment plan in specified location."), domain);
                    return po;
                }
                if (!dp.canRead()) {
                    po.setupForAbnormalExit(localStrings.getLocalString(
                            "enterprise.deployment.client.plan_no_read_permission",
                            "Deployment plan does not have read permission."), domain);
                    return po;
                }
                deploymentOptions.put(DFDeploymentProperties.DEPLOYMENT_PLAN, dp.getAbsolutePath());
            }

            // it's redeploy, set the enable attribute accordingly
            boolean isRedeploy = Boolean.valueOf((String)deploymentOptions.remove(DFDeploymentProperties.REDEPLOY));
            if (isRedeploy) {
                String appName = (String)deploymentOptions.get(
                    DFDeploymentProperties.NAME);
                if (!isTargetsMatched(appName, targets)) {
                    po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.specifyAllTargets", "Application {0} is already deployed on other targets. Please remove all references or specify all targets (or domain target if using asadmin command line) before attempting {1} operation", appName, "redeploy"), domain);
                }
                // set the enable attribute accordingly
                String enabledAttr = getAppRefEnabledAttr(
                    targets[0].getName(), appName);
                deploymentOptions.put(DFDeploymentProperties.ENABLED,
                    enabledAttr);
            }

            Target[] origTargets = targets;

            // first deploy to first target
            if (isRedeploy && targets.length > 1) {
                // if it's redeploy and having more than one target,
                // we should just redeploy with the special domain target
                targets = createTargets(new String[] {"domain"});
            }
            deploymentOptions.put(DFDeploymentProperties.TARGET, targets[0].getName());   
            DFCommandRunner commandRunner = getDFCommandRunner(
                "deploy", deploymentOptions, new String[]{tmpFile.getAbsolutePath()});
            DFDeploymentStatus ds = commandRunner.run();
            DFDeploymentStatus mainStatus = ds.getMainStatus();
            String moduleID;
            if (!po.checkStatusAndAddStage((TargetImpl)targets[0], localStrings.getLocalString("enterprise.deployment.client.deploy_to_first_target", "Deploying application to target {0}", targets[0].getName()),  mainStatus)) {
                return po;
            } else {
                moduleID = mainStatus.getProperty(DFDeploymentProperties.NAME);
                if (moduleID == null) {
                    moduleID = (String)deploymentOptions.get(DFDeploymentProperties.NAME);
                }
                po.setModuleID(moduleID);
            }

            Map createAppRefOptions = new HashMap();
            if (deploymentOptions.get(DFDeploymentProperties.ENABLED) != null) {
                createAppRefOptions.put(DFDeploymentProperties.ENABLED, deploymentOptions.get(DFDeploymentProperties.ENABLED));
            }
            if (deploymentOptions.get(DFDeploymentProperties.VIRTUAL_SERVERS) != null) {
                createAppRefOptions.put(DFDeploymentProperties.VIRTUAL_SERVERS, deploymentOptions.get(DFDeploymentProperties.VIRTUAL_SERVERS));
            }
            // then create application references to the rest of the targets
            for (int i = 1; i < targets.length; i++) {
                createAppRefOptions.put(DFDeploymentProperties.TARGET, targets[i].getName());   
                DFCommandRunner commandRunner2 = getDFCommandRunner(
                    "create-application-ref", createAppRefOptions, new String[] {moduleID});
                DFDeploymentStatus ds2 = commandRunner2.run();
                DFDeploymentStatus mainStatus2 = ds2.getMainStatus();
                if (!po.checkStatusAndAddStage((TargetImpl)targets[i],
"create app ref", mainStatus2)) {
                    return po;
                }
            }
            // we use origTargets to populate the targetModuleIDList
            // so it takes care of the redeploy using domain target case too
            for (int i = 0; i < origTargets.length; i++) {
                TargetModuleIDImpl targetModuleID = new TargetModuleIDImpl((TargetImpl)origTargets[i], moduleID);
                targetModuleIDList.add(targetModuleID);
            }

            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.deploy_application", "Deployment of application {0}", moduleID), (TargetImpl)targets[0], targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.deploy_application_failed", "Deployment of application failed - {0} ", ioex.toString()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

     * @return DFProgressObject for monitoring progress and querying status
     */
    public DFProgressObject undeploy(Target[] targets, String moduleID, Map undeploymentOptions) {
        ensureConnected();
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();
        try {
            if (!isTargetsMatched(moduleID, targets)) {
                po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.specifyAllTargets", "Application {0} is already deployed on other targets. Please remove all references or specify all targets (or domain target if using asadmin command line) before attempting {1} operation", moduleID, "undeploy"), domain);
            }

            // first remove the application references from targets except
            // last one
            Map deleteAppRefOptions = new HashMap();
            if (undeploymentOptions.get(DFDeploymentProperties.CASCADE) != null) {
                deleteAppRefOptions.put(DFDeploymentProperties.CASCADE, undeploymentOptions.get(DFDeploymentProperties.CASCADE));
            }
            for (int i = 0 ; i < targets.length - 1 ; i++) {
                deleteAppRefOptions.put(DFDeploymentProperties.TARGET, targets[i].getName());
                DFCommandRunner commandRunner = getDFCommandRunner(
                    "delete-application-ref", deleteAppRefOptions, new String[] {moduleID});
                DFDeploymentStatus ds = commandRunner.run();
                DFDeploymentStatus mainStatus = ds.getMainStatus();
                if (!po.checkStatusAndAddStage((TargetImpl)targets[i], localStrings.getLocalString("enterprise.deployment.client.undeploy_remove_ref", "While undeploying, trying to remove reference for application in target {0}", targets[i].getName()), mainStatus)) {
                    return po;
                } else {
                    TargetModuleIDImpl targetModuleID =
                       new TargetModuleIDImpl((TargetImpl)targets[i], moduleID);
                    targetModuleIDList.add(targetModuleID);
                }
            }

            // then undeploy from last target
            Target lastTarget = targets[targets.length -1];
            undeploymentOptions.put(DFDeploymentProperties.TARGET, lastTarget.getName());
            DFCommandRunner commandRunner2 = getDFCommandRunner(
                    "undeploy",
                    undeploymentOptions,
                    new String[]{moduleID});
            DFDeploymentStatus ds2 = commandRunner2.run();
            DFDeploymentStatus mainStatus2 = ds2.getMainStatus();
            if (!po.checkStatusAndAddStage((TargetImpl)lastTarget, localStrings.getLocalString("enterprise.deployment.client.undeploy_from_target", "Trying to undeploy application from target {0}", lastTarget.getName()), mainStatus2)) {
                return po;
            }

            TargetModuleIDImpl targetModuleID =
                new TargetModuleIDImpl((TargetImpl)lastTarget, moduleID);
            targetModuleIDList.add(targetModuleID);

            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);

            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.undeploy_application", "Undeployment of application {0}", moduleID), (TargetImpl)targets[0], targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.undeploy_application_failed", "Undeployment failed - {0}", ioex.toString()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

     * @return DFProgressObject the caller can use to monitor progress and query final status
     */
    protected DFProgressObject changeState(Target[] targets, String moduleID, String commandName, String action) {
        ensureConnected();
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();
        try {
            for (Target target : targets) {
                Map commandParams = new HashMap();
                commandParams.put(DFDeploymentProperties.TARGET, target.getName());
                DFCommandRunner commandRunner = getDFCommandRunner(commandName, commandParams, new String[]{moduleID});
                DFDeploymentStatus ds = commandRunner.run();
                DFDeploymentStatus mainStatus = ds.getMainStatus();
                if(!po.checkStatusAndAddStage((TargetImpl)target, localStrings.getLocalString("enterprise.deployment.client.change_state", "{0} of {1} in target {2}", action, moduleID, target.getName()), mainStatus)) {
                    return po;
                } else {
                    TargetModuleIDImpl targetModuleID =
                        new TargetModuleIDImpl((TargetImpl)target, moduleID);
                    targetModuleIDList.add(targetModuleID);
                }
            }
            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.change_state_all", "{0} of application in all targets", action), (TargetImpl)targets[0],  targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
            po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.state_change_failed", "Attempt to change the state of the application {0} failed - {1}", moduleID, ioex.toString()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

    protected DFProgressObject changeAppRef(Target[] targets, String moduleID, String commandName, String action, Map options) {
        ensureConnected();
        Throwable commandExecutionException = null;
        targets = prepareTargets(targets);
        ProgressObjectImpl po = new ProgressObjectImpl(targets);
        List<TargetModuleIDImpl> targetModuleIDList =
            new ArrayList<TargetModuleIDImpl>();
        try {
            for (Target target : targets) {
                options.put(DFDeploymentProperties.TARGET, target.getName());
                String[] operands = new String[] {moduleID};
                DFDeploymentStatus mainStatus = null;
                DFCommandRunner commandRunner = getDFCommandRunner(commandName, options, operands);
                DFDeploymentStatus ds = commandRunner.run();
                mainStatus = ds.getMainStatus();
                if(!po.checkStatusAndAddStage((TargetImpl)target, localStrings.getLocalString("enterprise.deployment.client.create_reference", "Creation of reference for application in target {0}", target.getName()),  mainStatus)) {
                    return po;
                } else {
                    TargetModuleIDImpl targetModuleID =
                        new TargetModuleIDImpl((TargetImpl)target, moduleID);
                    targetModuleIDList.add(targetModuleID);
                }
            }
            TargetModuleIDImpl[] targetModuleIDs =
                new TargetModuleIDImpl[targetModuleIDList.size()];
            targetModuleIDs = (TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
            po.setupForNormalExit(localStrings.getLocalString("enterprise.deployment.client.change_reference_application", "{0} of application reference in all targets", action), (TargetImpl)targets[0], targetModuleIDs);
            return po;
        } catch (Throwable ioex) {
           po.setupForAbnormalExit(localStrings.getLocalString("enterprise.deployment.client.change_reference_application_failed", "{0} of application reference failed - {1}", action, ioex.getMessage()), (TargetImpl)targets[0]);
            return po;
        }
    }
View Full Code Here

TOP

Related Classes of org.glassfish.deployapi.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.