Package javax.enterprise.deploy.spi

Examples of javax.enterprise.deploy.spi.DeploymentManager


        return config;
    }

    public String fileUpdated(File file, String configId) {
        log.info("Redeploying " + file.getName());
        DeploymentManager mgr = null;
        TargetModuleID[] modules = 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;
            if (DeployUtils.isJarFile(file) || file.isDirectory()) {
                po = mgr.redeploy(ids, file, null);
            } else {
                po = mgr.redeploy(ids, null, file);
            }
            waitForProgress(po);
            if (po.getDeploymentStatus().isCompleted()) {
                modules = po.getResultTargetModuleIDs();
                for (int i = 0; i < modules.length; i++) {
                    TargetModuleID result = modules[i];
                    log.info(DeployUtils.reformat("Redeployed " + 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 {
                log.error("Unable to undeploy " + file.getAbsolutePath() + "(" + configId + ")" + po.getDeploymentStatus().getMessage());
            }
        } catch (DeploymentManagerCreationException e) {
            log.error("Unable to open deployer", e);
        } catch (Exception e) {
            log.error("Unable to undeploy", e);
        } finally {
            if (mgr != null) mgr.release();
        }
        if (modules != null) {
            if (modules.length == 1) {
                return modules[0].getModuleID();
            } else {
View Full Code Here


public class CommandInstallCAR 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) {
            try {
                GeronimoDeploymentManager mgr = (GeronimoDeploymentManager) dmgr;
                if (commandArgs.getArgs().length == 0) {
                    throw new DeploymentException("Must specify Plugin CAR file");
View Full Code Here

        }
        File libFile = new File(installLibraryCommandArgs.getArgs()[0]);
        if(!libFile.exists() || !libFile.isFile() || !libFile.canRead()) {
            throw new DeploymentException("File does not exist or not a normal file or not readable. "+libFile);
        }
        DeploymentManager dmgr = connection.getDeploymentManager();
        if(dmgr instanceof GeronimoDeploymentManager) {
            GeronimoDeploymentManager mgr = (GeronimoDeploymentManager) dmgr;
            String groupId = installLibraryCommandArgs.getGroupId();
            try {
                Artifact artifact = mgr.installLibrary(libFile, groupId);
View Full Code Here

        normalize(data);
        if (data.getAbstractName() == null || data.getAbstractName().equals("")) { // we're creating a new realm
            try {
                XmlObject plan = actionGeneratePlan(request, data);
                data.name = data.name.replaceAll("\\s", "");
                DeploymentManager mgr = ManagementHelper.getManagementHelper(request).getDeploymentManager();
                File tempFile = File.createTempFile("console-deployment", ".xml");
                tempFile.deleteOnExit();
                log.debug("Writing security realm deployment plan to " + tempFile.getAbsolutePath());
                PrintWriter out = new PrintWriter(new FileWriter(tempFile));
                savePlanToStream(plan, 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, null, tempFile);
                waitForProgress(po);
                if (po.getDeploymentStatus().isCompleted()) {
                    TargetModuleID[] ids = po.getResultTargetModuleIDs();
                    po = mgr.start(ids);
                    waitForProgress(po);
                    if (po.getDeploymentStatus().isCompleted()) {
                        log.info("Deployment completed successfully!");
                    }
                }
View Full Code Here

            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) {
                        throw new PortletException("Unable to identify modules to replace.  Please include a Geronimo deployment plan or use the command-line deployment tool.");
                    }
                    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 = "The application was successfully "+(isRedeploy ? "re" : "")+"deployed.<br/>";
                    // start installed app/s
                    if (!isRedeploy && startApp != null && !startApp.equals("")) {
                        progress = mgr.start(progress.getResultTargetModuleIDs());
                        while(progress.getDeploymentStatus().isRunning()) {
                            Thread.sleep(100);
                        }
                        abbrStatusMessage+="The application was successfully started";
                    }
                } 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 = "Deployment failed:<br/>"
                                      + fullStatusMessage.substring(0, fullStatusMessage.indexOf('\n'));
                    // try to provide an upgraded version of the plan
                    try {
                        if (planFile != null && planFile.exists()) {
                            byte[] plan = new byte[(int) planFile.length()];
                            fis = new FileInputStream(planFile);
                            fis.read(plan);
                            DocumentBuilder documentBuilder = XmlUtil.newDocumentBuilderFactory().newDocumentBuilder();
                            Document doc = documentBuilder.parse(new ByteArrayInputStream(plan));
                            // v1.1 switched from configId to moduleId
                            String configId = doc.getDocumentElement().getAttribute("configId");
                            if (configId != null && !("".equals(configId))) {
                                StringWriter sw = new StringWriter();
                                new Upgrade1_0To1_1().upgrade(new ByteArrayInputStream(plan), sw);
                                // have to store the original and upgraded plans in the session
                                // because the buffer size for render parameters is sometimes not
                                // big enough
                                actionRequest.getPortletSession().setAttribute(MIGRATED_PLAN_PARM, sw.getBuffer());
                                actionRequest.getPortletSession().setAttribute(ORIGINAL_PLAN_PARM, new String(plan));
                            }
                        }
                    } catch (Exception e) {
                        // cannot provide a migrated plan in this case, most likely
                        // because the deployment plan would not parse. a valid
                        // status message has already been provided in this case
                    }
                }
                // have to store the status messages in the portlet session
                // because the buffer size for render parameters is sometimes not big enough
                actionRequest.getPortletSession().setAttribute(FULL_STATUS_PARM, fullStatusMessage);
                actionRequest.getPortletSession().setAttribute(ABBR_STATUS_PARM, abbrStatusMessage);
            } 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();
View Full Code Here

    protected static String save(PortletRequest request, ActionResponse response, JMSResourceData data, boolean planOnly) throws IOException {
        JMSProviderData provider = JMSProviderData.getProviderData(data.rarURI, request);
        if(data.objectName == null || data.objectName.equals("")) { // we're creating a new pool
            //data.instanceName = data.instanceName.replaceAll("\\s", "");
            DeploymentManager mgr = ManagementHelper.getManagementHelper(request).getDeploymentManager();
            try {
                File rarFile = PortletManager.getRepositoryEntry(request, data.getRarURI());
                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.jms");
                configId.setArtifactId(data.instanceName);
                configId.setVersion("1.0");
                configId.setType("rar");
                if(data.dependency != null && !data.dependency.trim().equals("")) {
                    Artifact artifact = Artifact.create(data.dependency.trim());
                    org.apache.geronimo.deployment.service.jsr88.Artifact dep = new org.apache.geronimo.deployment.service.jsr88.Artifact();
                    environment.setDependencies(new org.apache.geronimo.deployment.service.jsr88.Artifact[]{dep});
                    dep.setArtifactId(artifact.getArtifactId());
                    if(artifact.getGroupId() != null) {
                        dep.setGroupId(artifact.getGroupId());
                    }
                    if(artifact.getType() != null) {
                        dep.setType(artifact.getType());
                    }
                    if(artifact.getVersion() != null) {
                        dep.setVersion(artifact.getVersion().toString());
                    }
                }
               
                // Basic settings on RA plan and RA instance
                ResourceAdapter ra;
                if(connector.getResourceAdapter().length > 0) {
                    ra = connector.getResourceAdapter(0);
                } else {
                    ra = new ResourceAdapter();
                    connector.setResourceAdapter(new ResourceAdapter[]{ra});
                }
                ResourceAdapterInstance raInstance = new ResourceAdapterInstance();
                ra.setResourceAdapterInstance(raInstance);
                raInstance.setResourceAdapterName(data.instanceName);
                for (Iterator it = data.instanceProps.entrySet().iterator(); it.hasNext();) {
                    Map.Entry entry = (Map.Entry) it.next();
                    String name = getPropertyName((String)entry.getKey(), provider.getInstanceConfigProperties());
                    for(int i=0; i<raInstance.getConfigPropertySetting().length; i++) {
                        if(raInstance.getConfigPropertySetting(i).getName().equals(name)) {
                            raInstance.getConfigPropertySetting(i).setValue((String)entry.getValue());
                            break;
                        }
                    }
                }
                GBeanLocator workManager = new GBeanLocator();
                raInstance.setWorkManager(workManager);
                workManager.setGBeanLink(data.workManager); //todo
                // Connection Factories
                if(data.getConnectionFactoryCount() > 0) {
                    ConnectionDefinition[] defs = new ConnectionDefinition[data.getConnectionFactoryCount()];
                    for (int i = 0; i < defs.length; i++) {
                        defs[i] = new ConnectionDefinition();
                    }
                    ra.setConnectionDefinition(defs);
                    for (int i = 0; i < data.getConnectionFactories().size(); i++) {
                        JMSConnectionFactoryData factoryData = (JMSConnectionFactoryData) data.getConnectionFactories().get(i);
                        JMSProviderData.ConnectionDefinition providerData = provider.getConnectionDefinitions()[factoryData.getFactoryType()];
                        ConnectionDefinition def = defs[i];
                        def.setConnectionFactoryInterface(providerData.getConnectionFactoryInterface());
                        ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
                        def.setConnectionInstance(new ConnectionDefinitionInstance[]{instance});
                        if(providerData.getConnectionFactoryInterface().equals("javax.jms.ConnectionFactory")) {
                            instance.setImplementedInterface(new String[]{"javax.jms.QueueConnectionFactory","javax.jms.TopicConnectionFactory"});
                        }
                        instance.setName(factoryData.getInstanceName());
                        SinglePool pool = new SinglePool();
                        instance.getConnectionManager().setPoolSingle(pool);
                        pool.setMatchOne(true);
                        pool.setMaxSize(factoryData.getPoolMaxSize());
                        pool.setMinSize(factoryData.getPoolMinSize());
                        pool.setBlockingTimeoutMillis(factoryData.getPoolBlockingTimeout());
                        pool.setIdleTimeoutMinutes(factoryData.getPoolIdleTimeout());
                        if(factoryData.getTransaction().equals("none")) {
                            instance.getConnectionManager().setTransactionNone(true);
                        } else if(factoryData.getTransaction().equals("local")) {
                            instance.getConnectionManager().setTransactionLocal(true);
                        } else if(factoryData.getTransaction().equals("xa")) {
                            instance.getConnectionManager().setTransactionXA(true);
                            instance.getConnectionManager().setTransactionXACachingThread(factoryData.isXaThreadCaching());
                            instance.getConnectionManager().setTransactionXACachingTransaction(factoryData.isXaTransactionCaching());
                        }
                        for (Iterator it = factoryData.instanceProps.entrySet().iterator(); it.hasNext();) {
                            Map.Entry entry = (Map.Entry) it.next();
                            String name = getPropertyName((String)entry.getKey(), providerData.getConfigProperties());
                            for(int j=0; j<instance.getConfigPropertySetting().length; j++) {
                                if(instance.getConfigPropertySetting(j).getName().equals(name)) {
                                    instance.getConfigPropertySetting(j).setValue((String)entry.getValue());
                                    break;
                                }
                            }
                        }
                    }
                }

                // Destinations
                DDBean[] ddBeans = connector.getDDBean().getChildBean(connector.getXpaths()[0]);
                AdminObjectDCB[] adminDCBs = new AdminObjectDCB[ddBeans.length];
                for (int i = 0; i < adminDCBs.length; i++) {
                    adminDCBs[i] = (AdminObjectDCB) connector.getDConfigBean(ddBeans[i]);
                }
                for (int i = 0; i < data.getAdminObjects().size(); i++) {
                    JMSAdminObjectData admin = (JMSAdminObjectData) data.getAdminObjects().get(i);
                    JMSProviderData.AdminObjectDefinition providerData = provider.getAdminObjectDefinitions()[admin.getDestinationType()];
                    for (int j = 0; j < adminDCBs.length; j++) {
                        AdminObjectDCB adminDCB = adminDCBs[j];
                        if(adminDCB.getAdminObjectInterface().equals(providerData.getAdminObjectInterface())) {
                            AdminObjectInstance[] before = adminDCB.getAdminObjectInstance();
                            AdminObjectInstance[] after = new AdminObjectInstance[before.length+1];
                            System.arraycopy(before, 0, after, 0, before.length);
                            AdminObjectInstance instance = new AdminObjectInstance();
                            after[before.length] = instance;
                            adminDCB.setAdminObjectInstance(after);
                            instance.setMessageDestinationName(admin.getName());
                            for (Iterator it = admin.instanceProps.entrySet().iterator(); it.hasNext();) {
                                Map.Entry entry = (Map.Entry) it.next();
                                String name = getPropertyName((String)entry.getKey(), providerData.getConfigProperties());
                                for(int k=0; k<instance.getConfigPropertySetting().length; k++) {
                                    if(instance.getConfigPropertySetting(k).getName().equals(name)) {
                                        instance.getConfigPropertySetting(k).setValue((String)entry.getValue());
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }

                // Save
                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 JMS Resource 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();
                            log.info("Deployment completed successfully!");
                        }
                    }
                }
            } 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

            throw new PortletException("Unknown import type '" + type + "'");
        }
    }

    private ResourceAdapterParams loadConfigPropertiesByPath(PortletRequest request, String rarPath) {
        DeploymentManager mgr = ManagementHelper.getManagementHelper(request).getDeploymentManager();
        try {
            URL url = getRAR(request, rarPath).toURL();
            ConnectorDeployable deployable = new ConnectorDeployable(url);
            final DDBeanRoot ddBeanRoot = deployable.getDDBeanRoot();
            String adapterName = null, adapterDesc = null;
            String[] test = ddBeanRoot.getText("connector/display-name");
            if (test != null && test.length > 0) {
                adapterName = test[0];
            }
            test = ddBeanRoot.getText("connector/description");
            if (test != null && test.length > 0) {
                adapterDesc = test[0];
            }
            DDBean[] definitions = ddBeanRoot.getChildBean(
                    "connector/resourceadapter/outbound-resourceadapter/connection-definition");
            List<ConfigParam> configs = new ArrayList<ConfigParam>();
            if (definitions != null) {
                for (DDBean definition : definitions) {
                    String iface = definition.getText("connectionfactory-interface")[0];
                    if (iface.equals("javax.sql.DataSource")) {
                        DDBean[] beans = definition.getChildBean("config-property");
                        for (DDBean bean : beans) {
                            String name = bean.getText("config-property-name")[0].trim();
                            String type = bean.getText("config-property-type")[0].trim();
                            test = bean.getText("config-property-value");
                            String value = test == null || test.length == 0 ? null : test[0].trim();
                            test = bean.getText("description");
                            String desc = test == null || test.length == 0 ? null : test[0].trim();
                            configs.add(new ConfigParam(name, type, desc, value));
                        }
                    }
                }
            }
            return new ResourceAdapterParams(adapterName, adapterDesc,
                    configs.toArray(new ConfigParam[configs.size()]));
        } catch (Exception e) {
            log.error("Unable to read configuration properties", e);
            return null;
        } finally {
            if (mgr != null) mgr.release();
        }
    }
View Full Code Here

        // if it does not - then delete it -- otherwise it is a system database
        if (data.getAbstractName() != null) {
            boolean isSystemDatabasePool = (data.getAbstractName().indexOf("org.apache.geronimo.configs") == 0);

            if (!isSystemDatabasePool) {
                DeploymentManager mgr = ManagementHelper.getManagementHelper(request).getDeploymentManager();
                try {
                    // retrieve all running modules
                    TargetModuleID[] runningIds = mgr.getRunningModules(ModuleType.RAR, mgr.getTargets());

                    // index of module to keep
                    int index = -1;

                    // only keep module id that is associated with selected DB pool
                    for (int i = 0; i < runningIds.length; i++) {
                        if (data.getAbstractName().contains(runningIds[i].getModuleID())) {
                            index = i;
                            break;
                        }
                    }
                    TargetModuleID[] ids = {runningIds[index]};

                    // undeploy the db pool
                    ProgressObject po = mgr.undeploy(ids);
                    waitForProgress(po);

                    if (po.getDeploymentStatus().isCompleted()) {
                        log.info("Undeployment completed successfully!");
                    }
                } catch (Exception e) {
                    log.error("Undeployment unsuccessful!");
                } finally {
                    if (mgr != null) mgr.release();
                }
            }
        }
    }
View Full Code Here

    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

                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

TOP

Related Classes of javax.enterprise.deploy.spi.DeploymentManager

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.