Examples of DeploymentManager


Examples of javax.enterprise.deploy.spi.DeploymentManager

    private static String save(PortletRequest request, ActionResponse response, PoolData data, boolean planOnly) {
        ImportStatus status = getImportStatus(request);
        if (data.abstractName == null || data.abstractName.equals("")) { // we're creating a new pool
            data.name = data.name.replaceAll("\\s", "");
            DeploymentManager mgr = ManagementHelper.getManagementHelper(request).getDeploymentManager();
            try {
                File rarFile = getRAR(request, data.getRarPath());
                ConnectorDeployable deployable = new ConnectorDeployable(rarFile.toURL());
                DeploymentConfiguration config = mgr.createConfiguration(deployable);
                final DDBeanRoot ddBeanRoot = deployable.getDDBeanRoot();
                Connector15DCBRoot root = (Connector15DCBRoot) config.getDConfigBeanRoot(ddBeanRoot);
                ConnectorDCB connector = (ConnectorDCB) root.getDConfigBean(
                        ddBeanRoot.getChildBean(root.getXpaths()[0])[0]);

                EnvironmentData environment = new EnvironmentData();
                connector.setEnvironment(environment);
                org.apache.geronimo.deployment.service.jsr88.Artifact configId = new org.apache.geronimo.deployment.service.jsr88.Artifact();
                environment.setConfigId(configId);
                configId.setGroupId("console.dbpool");
                String artifactId = data.name;
                if (artifactId.indexOf('/') != -1) {
                    // slash in artifact-id results in invalid configuration-id and leads to deployment errors
                    artifactId = artifactId.replaceAll("/", "%2F");
                }
                configId.setArtifactId(artifactId);
                configId.setVersion("1.0");
                configId.setType("rar");

                String[] jars = data.getJars();
                int length = jars[jars.length - 1].length() == 0 ? jars.length - 1 : jars.length;
                org.apache.geronimo.deployment.service.jsr88.Artifact[] dependencies = new org.apache.geronimo.deployment.service.jsr88.Artifact[length];
                for (int i = 0; i < dependencies.length; i++) {
                    dependencies[i] = new org.apache.geronimo.deployment.service.jsr88.Artifact();
                }
                environment.setDependencies(dependencies);
                for (int i = 0; i < dependencies.length; i++) {
                    Artifact tmp = Artifact.create(jars[i]);
                    dependencies[i].setGroupId(tmp.getGroupId());
                    dependencies[i].setArtifactId(tmp.getArtifactId());
                    dependencies[i].setVersion(tmp.getVersion().toString());
                    dependencies[i].setType(tmp.getType());
                }

                ResourceAdapter adapter = connector.getResourceAdapter()[0];
                ConnectionDefinition definition = new ConnectionDefinition();
                adapter.setConnectionDefinition(new ConnectionDefinition[]{definition});
                definition.setConnectionFactoryInterface("javax.sql.DataSource");
                ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
                definition.setConnectionInstance(new ConnectionDefinitionInstance[]{instance});
                instance.setName(data.getName());
                ConfigPropertySetting[] settings = instance.getConfigPropertySetting();
                if (data.isGeneric()) { // it's a generic TranQL JDBC pool
                    for (ConfigPropertySetting setting : settings) {
                        if (setting.getName().equals("UserName")) {
                            setting.setValue(data.user);
                        } else if (setting.getName().equals("Password")) {
                            setting.setValue(data.password);
                        } else if (setting.getName().equals("ConnectionURL")) {
                            setting.setValue(data.url);
                        } else if (setting.getName().equals("Driver")) {
                            setting.setValue(data.driverClass);
                        }
                    }
                } else { // it's an XA driver or non-TranQL RA
                    for (ConfigPropertySetting setting : settings) {
                        String value = data.properties.get("property-" + setting.getName());
                        setting.setValue(value == null ? "" : value);
                    }
                }
                ConnectionManager manager = instance.getConnectionManager();
                manager.setTransactionLocal(true);
                SinglePool pool = new SinglePool();
                manager.setPoolSingle(pool);
                pool.setMatchOne(true);
                // Max Size needs to be set before the minimum.  This is because
                // the connection manager will constrain the minimum based on the
                // current maximum value in the pool.  We might consider adding a 
                // setPoolConstraints method to allow specifying both at the same time.
                if (data.maxSize != null && !data.maxSize.equals("")) {
                    pool.setMaxSize(new Integer(data.maxSize));
                }
                if (data.minSize != null && !data.minSize.equals("")) {
                    pool.setMinSize(new Integer(data.minSize));
                }
                if (data.blockingTimeout != null && !data.blockingTimeout.equals("")) {
                    pool.setBlockingTimeoutMillis(new Integer(data.blockingTimeout));
                }
                if (data.idleTimeout != null && !data.idleTimeout.equals("")) {
                    pool.setIdleTimeoutMinutes(new Integer(data.idleTimeout));
                }

                if (planOnly) {
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    config.save(out);
                    out.close();
                    return new String(out.toByteArray(), "US-ASCII");
                } else {
                    File tempFile = File.createTempFile("console-deployment", ".xml");
                    tempFile.deleteOnExit();
                    log.debug("Writing database pool deployment plan to " + tempFile.getAbsolutePath());
                    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
                    config.save(out);
                    out.flush();
                    out.close();
                    Target[] targets = mgr.getTargets();
                    if (null == targets) {
                        throw new IllegalStateException("No target to distribute to");
                    }
                    targets = new Target[] {targets[0]};
                   
                    ProgressObject po = mgr.distribute(targets, rarFile, tempFile);
                    waitForProgress(po);
                    if (po.getDeploymentStatus().isCompleted()) {
                        TargetModuleID[] ids = po.getResultTargetModuleIDs();
                        po = mgr.start(ids);
                        waitForProgress(po);
                        if (po.getDeploymentStatus().isCompleted()) {
                            ids = po.getResultTargetModuleIDs();
                            if (status != null) {
                                status.getCurrentPool().setName(data.getName());
                                status.getCurrentPool().setConfigurationName(ids[0].getModuleID());
                                status.getCurrentPool().setFinished(true);
                                response.setRenderParameter(MODE_KEY, IMPORT_STATUS_MODE);
                            }

                            log.info("Deployment completed successfully!");
                        }
                    } else if (po.getDeploymentStatus().isFailed()) {
                        data.deployError = "Unable to deploy: " + data.name;
                        response.setRenderParameter(MODE_KEY, EDIT_MODE);
                        log.info("Deployment Failed!");
                    }
                }
            } catch (Exception e) {
                log.error("Unable to save connection pool", e);
            } finally {
                if (mgr != null) mgr.release();
            }
        } else { // We're saving updates to an existing pool
            if (planOnly) {
                throw new UnsupportedOperationException("Can't update a plan for an existing deployment");
            }
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

                throw new IllegalStateException("Hot deploy directory " + dir.getAbsolutePath() + " does not exist and cannot be created!");
            }
        } else if (!dir.canRead() || !dir.isDirectory()) {
            throw new IllegalStateException("Hot deploy directory " + dir.getAbsolutePath() + " is not a readable directory!");
        }
        DeploymentManager mgr = null;
        try {
            mgr = getDeploymentManager();
            Target[] targets = mgr.getTargets();
            startupModules = mgr.getAvailableModules(null, targets);
            mgr.release();
            mgr = null;
            monitor = new DirectoryMonitor(dir, this, pollIntervalMillis);
            log.debug("Hot deploy scanner intialized; starting main loop.");
            Thread t = new Thread(monitor, "Geronimo hot deploy scanner");
            t.setDaemon(true);
            t.start();
        } finally {
            if (mgr != null) mgr.release();
        }
    }
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

            monitor.close();
        }
    }

    public boolean isFileDeployed(File file, String configId) {
        DeploymentManager mgr = null;
        try {
            if (startupModules != null) {
                DeployUtils.identifyTargetModuleIDs(startupModules, configId, true).toArray(new TargetModuleID[0]);
            }
            else {
                mgr = getDeploymentManager();
                Target[] targets = mgr.getTargets();
                TargetModuleID[] ids = mgr.getAvailableModules(null, targets);
                DeployUtils.identifyTargetModuleIDs(ids, configId, true).toArray(new TargetModuleID[0]);
                mgr.release();
                mgr = null;
            }
            return true;
        } catch (DeploymentException e) {
            log.debug("Found new file in deploy directory on startup with ID " + configId);
        } catch (Exception e) {
            log.error("Unable to check status", e);
        } finally {
            if (mgr != null) {
                mgr.release();
                mgr = null;
            }
        }
        return false;
    }
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

        return true;
    }

    public String fileAdded(File file) {
        log.info("Deploying " + file.getName());
        DeploymentManager mgr = null;
        TargetModuleID[] modules = null;
        boolean completed = false;
        try {
            mgr = getDeploymentManager();
            Target[] targets = mgr.getTargets();
            if (null == targets) {
                throw new IllegalStateException("No target to distribute to");
            }
            targets = new Target[] {targets[0]};

            ProgressObject po;
            if (DeployUtils.isJarFile(file) || file.isDirectory()) {
                po = mgr.distribute(targets, file, null);
            } else {
                po = mgr.distribute(targets, null, file);
            }
            waitForProgress(po);
            if (po.getDeploymentStatus().isCompleted()) {
                modules = po.getResultTargetModuleIDs();
                po = mgr.start(modules);
                waitForProgress(po);
                if (po.getDeploymentStatus().isCompleted()) {
                    completed = true;
                } else {
                    log.warn("Unable to start some modules for " + file.getAbsolutePath());
                }
                modules = po.getResultTargetModuleIDs();
                for (int i = 0; i < modules.length; i++) {
                    TargetModuleID result = modules[i];
                    log.info(DeployUtils.reformat("Deployed " + result.getModuleID() + (targets.length > 1 ? " to " + result.getTarget().getName() : "") + (result.getWebURL() == null ? "" : " @ " + result.getWebURL()), 4, 72));
                    if (result.getChildTargetModuleID() != null) {
                        for (int j = 0; j < result.getChildTargetModuleID().length; j++) {
                            TargetModuleID child = result.getChildTargetModuleID()[j];
                            log.info(DeployUtils.reformat("  `-> " + child.getModuleID() + (child.getWebURL() == null ? "" : " @ " + child.getWebURL()), 4, 72));
                        }
                    }
                }
            } else {
               //Try to delete the module , that failed to successfully hot-deploy 
              log.error("Unable to deploy: " + po.getDeploymentStatus().getMessage());
              String delfile=file.getAbsolutePath();
                File fd = new File(delfile);
                if(fd.isDirectory()){
                     log.info("Deleting the Directory: "+delfile);
                     if(DeploymentUtil.recursiveDelete(fd))
                       log.debug("Successfully deleted the Directory: "+delfile);
                     else
                       log.error("Couldn't delete the hot deployed directory"+delfile);
                }else if(fd.isFile()){
                     log.info("Deleting the File: "+delfile);
                     if(fd.delete()){
                   log.debug("Successfully deleted the File: "+delfile);
                 }else
                   log.error("Couldn't delete the hot deployed directory"+delfile);
                }
                           
                return null;
            }
        } catch (DeploymentManagerCreationException e) {
            log.error("Unable to open deployer", e);
            return null;
        } catch (DeploymentException e) {
            log.error("Unable to determine if file is a jar", e);
        } finally {
            if (mgr != null) mgr.release();
        }
        if (completed && modules != null) {
            if (modules.length == 1) {
                return modules[0].getModuleID();
            } else {
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

public class CommandListConfigurations extends AbstractCommand {

    //todo: provide a way to handle a username and password for the remote repo?

    public void execute(ConsoleReader consoleReader, ServerConnection connection, CommandArgs commandArgs) throws DeploymentException {
        DeploymentManager dmgr = connection.getDeploymentManager();
        if (dmgr instanceof GeronimoDeploymentManager) {
            GeronimoDeploymentManager mgr = (GeronimoDeploymentManager) dmgr;
            try {
                String repo;
                if (commandArgs.getArgs().length == 1) {
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

            return null;
        }
    }
   
    private DeploymentManager getDeploymentManager() throws DeploymentManagerCreationException {
        DeploymentManager manager = factory.getDeploymentManager(deploymentURI, deploymentUser, deploymentPassword);
        if (manager instanceof JMXDeploymentManager) {
            ((JMXDeploymentManager) manager).setLogConfiguration(false, true);
        }
        return manager;
    }
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

        return manager;
    }

    public boolean fileRemoved(File file, String configId) {
        log.info("Undeploying " + file.getName());
        DeploymentManager mgr = null;
        try {
            mgr = getDeploymentManager();
            Target[] targets = mgr.getTargets();
            TargetModuleID[] ids = mgr.getAvailableModules(null, targets);
            ids = (TargetModuleID[]) DeployUtils.identifyTargetModuleIDs(ids, configId, true).toArray(new TargetModuleID[0]);
            ProgressObject po = mgr.undeploy(ids);
            waitForProgress(po);
            if (po.getDeploymentStatus().isCompleted()) {
                TargetModuleID[] modules = po.getResultTargetModuleIDs();
                for (int i = 0; i < modules.length; i++) {
                    TargetModuleID result = modules[i];
                    log.info(DeployUtils.reformat("Undeployed " + result.getModuleID() + (targets.length > 1 ? " to " + result.getTarget().getName() : ""), 4, 72));
                }
            } else {
                log.error("Unable to undeploy " + file.getAbsolutePath() + "(" + configId + ")" + po.getDeploymentStatus().getMessage());
                return false;
            }
        } catch (DeploymentManagerCreationException e) {
            log.error("Unable to open deployer", e);
            return false;
        } catch (Exception e) {
            log.error("Unable to undeploy", e);
            return false;
        } finally {
            if (mgr != null) mgr.release();
        }
        return true;
    }
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

        }
        return true;
    }

    public String getModuleId(String config) {
        DeploymentManager mgr = null;
        TargetModuleID[] modules = null;
        try {
            mgr = getDeploymentManager();
            Target[] targets = mgr.getTargets();
            TargetModuleID[] ids = mgr.getAvailableModules(null, targets);
            for(int j=0;j<ids.length;j++) {
                String moduleId=ids[j].getModuleID();
                String[] parts = moduleId.split("/", -1);
                if (parts.length != 4) {
                    continue;
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

    protected TargetModuleID[] getNonRunningModules(final TargetModuleID[] moduleIds) throws Exception {
        assert moduleIds != null;

        List modulesList = new ArrayList();

        DeploymentManager manager = getDeploymentManager();

        Target[] targets = manager.getTargets();
        TargetModuleID runningModuleIds[] = manager.getRunningModules(null, targets);

        for (int j = 0; j < moduleIds.length; j++) {
            String moduleId = moduleIds[j].getModuleID();
            log.debug("Checking if module is running: " + moduleId);
View Full Code Here

Examples of javax.enterprise.deploy.spi.DeploymentManager

    protected boolean isModuleStarted(final String moduleId) throws Exception {
        assert moduleId != null;

        log.debug("Checking if module is started: " + moduleId);
       
        DeploymentManager manager = getDeploymentManager();

        Target[] targets = manager.getTargets();
        TargetModuleID targetIds[] = manager.getRunningModules(null, targets);

        for (int i = 0; i < targetIds.length; i++) {
            if (moduleId.equals(targetIds[i].getModuleID())) {
                return true;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.