Example usage for javax.enterprise.deploy.spi DeploymentManager redeploy

List of usage examples for javax.enterprise.deploy.spi DeploymentManager redeploy

Introduction

In this page you can find the example usage for javax.enterprise.deploy.spi DeploymentManager redeploy.

Prototype


public ProgressObject redeploy(TargetModuleID[] moduleIDList, InputStream moduleArchive,
        InputStream deploymentPlan) throws java.lang.UnsupportedOperationException, IllegalStateException;

Source Link

Document

(optional) The redeploy method provides a means for updating currently deployed Java EE applications.

Usage

From source file:org.apache.geronimo.console.configmanager.DeploymentPortlet.java

public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws PortletException, IOException {
    if (!PortletFileUpload.isMultipartContent(actionRequest)) {
        throw new PortletException("Expected file upload");
    }//from   ww w .  j  a  v a  2s  .  c o m

    File rootDir = new File(System.getProperty("java.io.tmpdir"));
    PortletFileUpload uploader = new PortletFileUpload(new DiskFileItemFactory(10240, rootDir));
    File moduleFile = null;
    File planFile = null;
    String startApp = null;
    String redeploy = null;
    try {
        List items = uploader.parseRequest(actionRequest);
        for (Iterator i = items.iterator(); i.hasNext();) {
            FileItem item = (FileItem) i.next();
            if (!item.isFormField()) {
                String fieldName = item.getFieldName();
                String name = item.getName().trim();
                File file;
                if (name.length() == 0) {
                    file = null;
                } else {
                    // Firefox sends basename, IE sends full path
                    int index = name.lastIndexOf('\\');
                    if (index != -1) {
                        name = name.substring(index + 1);
                    }
                    file = new File(rootDir, name);
                }
                if ("module".equals(fieldName)) {
                    moduleFile = file;
                } else if ("plan".equals(fieldName)) {
                    planFile = file;
                }
                if (file != null) {
                    try {
                        item.write(file);
                    } catch (Exception e) {
                        throw new PortletException(e);
                    }
                }
            } else {
                // retrieve 'startApp' form field value
                if ("startApp".equalsIgnoreCase(item.getFieldName())) {
                    startApp = item.getString();
                } else if ("redeploy".equalsIgnoreCase(item.getFieldName())) {
                    redeploy = item.getString();
                }
            }
        }
    } catch (FileUploadException e) {
        throw new PortletException(e);
    }
    DeploymentFactoryManager dfm = DeploymentFactoryManager.getInstance();
    FileInputStream fis = null;
    try {
        DeploymentManager mgr = dfm.getDeploymentManager("deployer:geronimo:inVM", null, null);
        try {
            boolean isRedeploy = redeploy != null && !redeploy.equals("");
            if (mgr instanceof JMXDeploymentManager) {
                ((JMXDeploymentManager) mgr).setLogConfiguration(false, true);
            }
            Target[] all = mgr.getTargets();
            if (null == all) {
                throw new IllegalStateException("No target to distribute to");
            }

            ProgressObject progress;
            if (isRedeploy) {
                TargetModuleID[] targets = identifyTargets(moduleFile, planFile,
                        mgr.getAvailableModules(null, all));
                if (targets.length == 0) {
                    addErrorMessage(actionRequest, getLocalizedString(actionRequest, "plugin.errorMsg04"),
                            null);
                    log.error(getLocalizedString(actionRequest, "plugin.errorMsg04"));
                    return;
                }
                progress = mgr.redeploy(targets, moduleFile, planFile);
            } else {
                progress = mgr.distribute(new Target[] { all[0] }, moduleFile, planFile);
            }
            while (progress.getDeploymentStatus().isRunning()) {
                Thread.sleep(100);
            }

            String abbrStatusMessage;
            String fullStatusMessage = null;
            if (progress.getDeploymentStatus().isCompleted()) {
                abbrStatusMessage = getLocalizedString(actionRequest,
                        !isRedeploy ? "plugin.infoMsg01" : "plugin.infoMsg02");
                addInfoMessage(actionRequest, abbrStatusMessage);
                // start installed app/s
                if (!isRedeploy && startApp != null && !startApp.equals("")) {
                    progress = mgr.start(progress.getResultTargetModuleIDs());
                    while (progress.getDeploymentStatus().isRunning()) {
                        Thread.sleep(100);
                    }
                    if (progress.getDeploymentStatus().isCompleted()) {
                        abbrStatusMessage = getLocalizedString(actionRequest, "plugin.infoMsg03");
                        addInfoMessage(actionRequest, abbrStatusMessage);
                    } else {
                        abbrStatusMessage = getLocalizedString(actionRequest, "plugin.errorMsg02");
                        fullStatusMessage = progress.getDeploymentStatus().getMessage();
                        addErrorMessage(actionRequest, abbrStatusMessage, fullStatusMessage);
                        log.error(abbrStatusMessage + "\n" + fullStatusMessage);
                    }
                }
            } else {
                fullStatusMessage = progress.getDeploymentStatus().getMessage();
                // for the abbreviated status message clip off everything
                // after the first line, which in most cases means the gnarly stacktrace
                abbrStatusMessage = getLocalizedString(actionRequest, "plugin.errorMsg01");
                addErrorMessage(actionRequest, abbrStatusMessage, fullStatusMessage);
                log.error(abbrStatusMessage + "\n" + fullStatusMessage);
            }
        } finally {
            mgr.release();
            if (fis != null)
                fis.close();
            if (moduleFile != null && moduleFile.exists()) {
                if (!moduleFile.delete()) {
                    log.debug("Unable to delete temporary file " + moduleFile);
                    moduleFile.deleteOnExit();
                }
            }
            if (planFile != null && planFile.exists()) {
                if (!planFile.delete()) {
                    log.debug("Unable to delete temporary file " + planFile);
                    planFile.deleteOnExit();
                }
            }
        }
    } catch (Exception e) {
        throw new PortletException(e);
    }
}