Package javax.enterprise.deploy.spi

Examples of javax.enterprise.deploy.spi.DeploymentManager


            throw new DeploymentException("Could not write to output", e);
        }
    }

    private void executeOnline(ServerConnection connection, boolean inPlace, List targets, ConsoleReader out, File module, File plan) throws DeploymentException, IOException {
        final DeploymentManager mgr = connection.getDeploymentManager();
        TargetModuleID[] results;
        boolean multipleTargets;
        ProgressObject po;
        if(targets.size() > 0) {
            Target[] tlist = identifyTargets(targets, mgr);
            multipleTargets = tlist.length > 1;
            po = runCommand(mgr, out, inPlace, tlist, module, plan);
            waitForProgress(out, po);
        } else {
            Target[] tlist = mgr.getTargets();
            if (null == tlist) {
                throw new IllegalStateException("No target to distribute to");
            }
            tlist = new Target[] {tlist[0]};
View Full Code Here


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) {
                    repo = commandArgs.getArgs()[0];
                } else {
                    repo = getRepository(consoleReader, mgr);
                }
                PluginListType plugins = getPluginCategories(repo, mgr, consoleReader);
                if (plugins == null) {
                    return;
                }

                PluginListType list = getInstallList(plugins, consoleReader, repo);
                if (list == null) {
                    return;
                }

                installPlugins(mgr, list, repo, consoleReader, connection);
            } catch (IOException e) {
                throw new DeploymentException("Unable to install configuration", e);
            } catch (NumberFormatException e) {
                throw new DeploymentException("Invalid response");
            }
        } else {
            throw new DeploymentException("Cannot list repositories using " + dmgr.getClass().getName() + " deployment manager");
        }
    }
View Full Code Here

            if (args.length == 0) {
                throw new DeploymentSyntaxException("Must specify a module or plan (or both) and optionally module IDs to replace");
            }
           
            DeploymentManager mgr = connection.getDeploymentManager();
            Target[] allTargets = mgr.getTargets();
            TargetModuleID[] allModules;
            try {
                allModules = mgr.getAvailableModules(null, allTargets);
            } catch(TargetException e) {
                throw new DeploymentException("Unable to load modules from server", e);
            }

            List modules = new ArrayList();
            File module = null;
            File plan = null;
            File test = new File(args[0]); // Guess whether the first argument is a module or a plan
            if(!test.exists()) {
                throw new DeploymentSyntaxException("Module or plan file does not exist: " + test.getAbsolutePath());
            }
            if(!test.canRead()) {
                throw new DeploymentException("Cannot read file "+test.getAbsolutePath());
            }
            if(DeployUtils.isJarFile(test) || test.isDirectory()) {
                module = test;
            } else {
                plan = test;
            }
            if(args.length > 1) { // Guess whether the second argument is a module, plan, ModuleID, or TargetModuleID
                test = new File(args[1]);
                if(test.exists() && test.canRead() && !args[1].equals(args[0])) {
                    if(DeployUtils.isJarFile(test) || test.isDirectory()) {
                        if(module != null) {
                            throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
                        }
                        module = test;
                    } else {
                        if(plan != null) {
                            throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
                        }
                        plan = test;
                    }
                } else {
                    modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[1], false));
                }
            }
            for(int i=2; i<args.length; i++) { // Any arguments beyond 2 must be a ModuleID or TargetModuleID
                modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[i], false));
            }
            // If we don't have any moduleIDs, try to guess one.
            if(modules.size() == 0 && connection.isGeronimo()) {
                emit(consoleReader, "No ModuleID or TargetModuleID provided.  Attempting to guess based on the content of the "+(plan == null ? "archive" : "plan")+".");
                String moduleId = null;
                try {
                    if(plan != null) {
                        moduleId = DeployUtils.extractModuleIdFromPlan(plan);
                        if(moduleId == null) { // plan just doesn't have a config ID
                            String fileName = module == null ? plan.getName() : module.getName();
                            int pos = fileName.lastIndexOf('.');
                            String artifactId = pos > -1 ? module.getName().substring(0, pos) : module.getName();
                            moduleId = Artifact.DEFAULT_GROUP_ID+"/"+artifactId+"//";
                            emit(consoleReader, "Unable to locate Geronimo deployment plan in archive.  Calculating default ModuleID from archive name.");
                        }
                    } else if(module != null) {
                        moduleId = DeployUtils.extractModuleIdFromArchive(module);
                        if(moduleId == null) {
                            int pos = module.getName().lastIndexOf('.');
                            String artifactId = pos > -1 ? module.getName().substring(0, pos) : module.getName();
                            moduleId = Artifact.DEFAULT_GROUP_ID+"/"+artifactId+"//";
                            emit(consoleReader, "Unable to locate Geronimo deployment plan in archive.  Calculating default ModuleID from archive name.");
                        }
                    }
                } catch (IOException e) {
                    throw new DeploymentException("Unable to read input files: "+e.getMessage(), e);
                }
                if(moduleId != null) {
                    emit(consoleReader, "Attempting to use ModuleID '"+moduleId+"'");
                    modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, moduleId, true));
                } else {
                    emit(consoleReader, "Unable to calculate a ModuleID from supplied module and/or plan.");
                }
            }
            if(modules.size() == 0) { // Either not deploying to Geronimo or unable to identify modules
                throw new DeploymentSyntaxException("No ModuleID or TargetModuleID available.  Nothing to do.  Maybe you should add a ModuleID or TargetModuleID to the command line?");
            }
            if(module != null) {
                module = module.getAbsoluteFile();
            }
            if(plan != null) {
                plan = plan.getAbsoluteFile();
            }
            // Now that we've sorted out all the arguments, do the work
            TargetModuleID[] ids = (TargetModuleID[]) modules.toArray(new TargetModuleID[modules.size()]);
            boolean multiple = isMultipleTargets(ids);
            po = mgr.redeploy(ids, module, plan);
            waitForProgress(consoleReader, po);
            TargetModuleID[] done = po.getResultTargetModuleIDs();
            for(int i = 0; i < done.length; i++) {
                TargetModuleID id = done[i];
                emit(consoleReader, "Redeployed "+id.getModuleID()+(multiple ? " on "+id.getTarget().getName() : "")+(id.getWebURL() == null ? "" : " @ "+id.getWebURL()));
View Full Code Here

public class CommandEncrypt extends AbstractCommand {

    public void execute(ConsoleReader consoleReader, ServerConnection connection, CommandArgs commandArgs) throws DeploymentException {
        try {
            consoleReader.printString(DeployUtils.reformat("String to encrypt: "+commandArgs.getArgs()[0], 4, 72));
            DeploymentManager dm = connection.getDeploymentManager();
            if (dm instanceof RemoteDeploymentManager) {
                // Online encryption
                Kernel k = ((RemoteDeploymentManager)dm).getKernel();
                Object ret = k.invoke(ConfiguredEncryption.class, "encrypt", new Object[] {commandArgs.getArgs()[0]}, new String[] {"java.lang.String"});
                consoleReader.printString(DeployUtils.reformat("Online encryption result: "+ret, 4, 72));
View Full Code Here

            if (args.length == 0) {
                throw new DeploymentSyntaxException(
                        "Must specify a module or plan (or both) and optionally module IDs to replace");
            }

            DeploymentManager mgr = connection.getDeploymentManager();
            Target[] allTargets = mgr.getTargets();
            TargetModuleID[] allModules;
            try {
                allModules = mgr.getAvailableModules(null, allTargets);
            } catch (TargetException e) {
                throw new DeploymentException("Unable to load modules from server", e);
            }
            if (args.length >= 3 && args[0].equalsIgnoreCase("--targets")) // case of cluster redeployment
            {
                List modules = new ArrayList();
                boolean multipleTargets;
                File test = null;
                File test1 = null;
                File module = null;
                File plan = null;
                test = new File(args[2]); // check whether args[2] is a module or a plan
                checkFirstArguement(test);
                if (DeployUtils.isJarFile(test) || test.isDirectory()) {
                    if (module != null) {
                        throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
                    }
                    module = test;
                } else {
                    if (plan != null) {
                        throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
                    }
                    plan = test;
                }
                if (args.length >= 4) {// than it can be plan,moduleId,TargetModuleId
                    test1 = new File(args[3]);
                    if (test1.exists() && test1.canRead()) // check if it is plan
                    {
                        if (DeployUtils.isJarFile(test1) || test1.isDirectory()) {
                            if (module != null) {
                                throw new DeploymentSyntaxException(
                                        "Module and plan cannot both be JAR files or directories!");
                            }
                            module = test1;
                        } else {
                            if (plan != null) {
                                throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
                            }
                            plan = test1;
                        }
                    } else
                        modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[3], false));
                }
                if (module != null) {
                    module = module.getAbsoluteFile();
                }
                if (plan != null) {
                    plan = plan.getAbsoluteFile();
                }
                if (args.length >= 5) // Amy arguements beyond 4 should be ModuleId or Target ModuleId
                {
                    for (int i = 4; i < args.length; i++) {
                        modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[i], false));
                    }
                }
                try {
                    distributeCommandArgs = new DistributeCommandArgsImpl(args);
                } catch (CLParserException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                List<String> targets = Arrays.asList(distributeCommandArgs.getTargets());
                if (targets.size() > 0) {
                    Target[] tlist = identifyTargets(targets, mgr); // before starting undeployment and deployment verify the correctness of target argument
                }
                if (modules.size() == 0) {
                    String moduleId = guessModuleId(modules, connection, consoleReader, plan, module, allModules);
                    modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, moduleId, false));
                }

                TargetModuleID[] ids = (TargetModuleID[]) modules.toArray(new TargetModuleID[modules.size()]);
                boolean multiple = isMultipleTargets(ids);
                po = mgr.undeploy(ids);
                waitForProgress(consoleReader, po);
                TargetModuleID[] done = po.getResultTargetModuleIDs();

                if (targets.size() > 0) {
                    Target[] tlist = identifyTargets(targets, mgr);
                    multipleTargets = tlist.length > 1;
                    po = mgr.distribute(tlist, module, plan);
                    waitForProgress(consoleReader, po);
                } else {
                    Target[] tlist = mgr.getTargets();
                    if (null == tlist) {
                        throw new IllegalStateException("No target to distribute to");
                    }
                    tlist = new Target[] { tlist[0] };
                    multipleTargets = tlist.length > 1;
                    po = mgr.distribute(tlist, module, plan);
                    waitForProgress(consoleReader, po);
                }
                if (po.getDeploymentStatus().isFailed()) {
                    throw new DeploymentException("Unable to redeploy "
                            + (module == null ? plan.getName() : module.getName()) + ": "
                            + po.getDeploymentStatus().getMessage());
                }
                po = mgr.start(po.getResultTargetModuleIDs());
                waitForProgress(consoleReader, po);
                TargetModuleID[] resultsDeployment = po.getResultTargetModuleIDs();
                for (int i = 0; i < resultsDeployment.length; i++) {
                    TargetModuleID result = resultsDeployment[i];
                    consoleReader.printString(DeployUtils.reformat("Deployed"
                            + " "
                            + result.getModuleID()
                            + (multipleTargets ? " to " + result.getTarget().getName() : "")
                            + (result.getWebURL() == null || !getAction().equals("Deployed") ? "" : " @ "
                                    + result.getWebURL()), 4, 72));
                    if (result.getChildTargetModuleID() != null) {
                        for (int j = 0; j < result.getChildTargetModuleID().length; j++) {
                            TargetModuleID child = result.getChildTargetModuleID()[j];
                            consoleReader.printString(DeployUtils.reformat("  `-> "
                                    + child.getModuleID()
                                    + (child.getWebURL() == null || !getAction().equals("Deployed") ? "" : " @ "
                                            + child.getWebURL()), 4, 72));
                        }
                    }
                }
                // print the results that succeeded
                TargetModuleID[] results = po.getResultTargetModuleIDs();
                for (int i = 0; i < results.length; i++) {
                    TargetModuleID result = results[i];
                    consoleReader.printString(DeployUtils.reformat(getAction()
                            + " "
                            + result.getModuleID()
                            + (multipleTargets ? " to " + result.getTarget().getName() : "")
                            + (result.getWebURL() == null || !getAction().equals("Deployed") ? "" : " @ "
                                    + result.getWebURL()), 4, 72));
                    if (result.getChildTargetModuleID() != null) {
                        for (int j = 0; j < result.getChildTargetModuleID().length; j++) {
                            TargetModuleID child = result.getChildTargetModuleID()[j];
                            consoleReader.printString(DeployUtils.reformat("  `-> "
                                    + child.getModuleID()
                                    + (child.getWebURL() == null || !getAction().equals("Deployed") ? "" : " @ "
                                            + child.getWebURL()), 4, 72));
                        }
                    }
                }
                // if any results failed then throw so that we'll return non-0 to the operating system
                if (po.getDeploymentStatus().isFailed()) {
                    throw new DeploymentException("Operation failed: " + po.getDeploymentStatus().getMessage());
                }
            } else { // case of local redeployment
                List modules = new ArrayList();
                File module = null;
                File plan = null;
                File test = new File(args[0]); // Guess whether the first argument is a module or a plan
                if (!test.exists()) {
                    throw new DeploymentSyntaxException("Module or plan file does not exist: " + test.getAbsolutePath());
                }
                if (!test.canRead()) {
                    throw new DeploymentException("Cannot read file " + test.getAbsolutePath());
                }
                if (DeployUtils.isJarFile(test) || test.isDirectory()) {
                    module = test;
                } else {
                    plan = test;
                }
                if (args.length > 1) { // Guess whether the second argument is a module, plan, ModuleID or TargetModuleID
                    test = new File(args[1]);
                    if (test.exists() && test.canRead() && !args[1].equals(args[0])) {
                        if (DeployUtils.isJarFile(test) || test.isDirectory()) {
                            if (module != null) {
                                throw new DeploymentSyntaxException(
                                        "Module and plan cannot both be JAR files or directories!");
                            }
                            module = test;
                        } else {
                            if (plan != null) {
                                throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
                            }
                            plan = test;
                        }
                    } else {
                        modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[1], false));
                    }
                }
                for (int i = 2; i < args.length; i++) { // Any arguments beyond 2 must be a ModuleID or TargetModuleID
                    modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[i], false));
                }
                // If we don't have any moduleIDs, try to guess one.
                if (modules.size() == 0 && connection.isGeronimo()) {
                    emit(consoleReader,
                            "No ModuleID or TargetModuleID provided.  Attempting to guess based on the content of the "
                                    + (plan == null ? "archive" : "plan") + ".");
                    String moduleId = null;
                    try {
                        if (plan != null) {
                            moduleId = DeployUtils.extractModuleIdFromPlan(plan);
                            if (moduleId == null) { // plan just doesn't have a config ID
                                String fileName = module == null ? plan.getName() : module.getName();
                                int pos = fileName.lastIndexOf('.');
                                String artifactId = pos > -1 ? module.getName().substring(0, pos) : module.getName();
                                moduleId = Artifact.DEFAULT_GROUP_ID + "/" + artifactId + "//";
                                emit(consoleReader,
                                        "Unable to locate Geronimo deployment plan in archive.  Calculating default ModuleID from archive name.");
                            }
                        } else if (module != null) {
                            moduleId = DeployUtils.extractModuleIdFromArchive(module);
                            if (moduleId == null) {
                                int pos = module.getName().lastIndexOf('.');
                                String artifactId = pos > -1 ? module.getName().substring(0, pos) : module.getName();
                                moduleId = Artifact.DEFAULT_GROUP_ID + "/" + artifactId + "//";
                                emit(consoleReader,
                                        "Unable to locate Geronimo deployment plan in archive.  Calculating default ModuleID from archive name.");
                            }
                        }
                    } catch (IOException e) {
                        throw new DeploymentException("Unable to read input files: " + e.getMessage(), e);
                    }
                    if (moduleId != null) {
                        emit(consoleReader, "Attempting to use ModuleID '" + moduleId + "'");
                        modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, moduleId, true));
                    } else {
                        emit(consoleReader, "Unable to calculate a ModuleID from supplied module and/or plan.");
                    }
                }
                if (modules.size() == 0) { // Either not deploying to Geronimo or unable to identify modules
                    throw new DeploymentSyntaxException(
                            "No ModuleID or TargetModuleID available.  Nothing to do.  Maybe you should add a ModuleID or TargetModuleID to the command line?");
                }
                if (module != null) {
                    module = module.getAbsoluteFile();
                }
                if (plan != null) {
                    plan = plan.getAbsoluteFile();
                }
                // Now that we've sorted out all the arguments, do the work
                TargetModuleID[] ids = (TargetModuleID[]) modules.toArray(new TargetModuleID[modules.size()]);
                boolean multiple = isMultipleTargets(ids);
                po = mgr.redeploy(ids, module, plan);
                waitForProgress(consoleReader, po);
                TargetModuleID[] done = po.getResultTargetModuleIDs();
                for (int i = 0; i < done.length; i++) {
                    TargetModuleID id = done[i];
                    emit(consoleReader, "Redeployed " + id.getModuleID()
View Full Code Here

    protected static String save(PortletRequest request, final 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("car");
                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);
                    po.addProgressListener(new ProgressListener() {
                       
                        public void handleProgressEvent(ProgressEvent event)  {
                            DeploymentStatus status = event.getDeploymentStatus();
                            String msg = status.getMessage();
                            if (status.isCompleted()) {
                                response.setRenderParameter("successMsg", msg);
                            } else if (status.isFailed()) {
                                response.setRenderParameter("errorMsg", msg);
                            }
                        }
                       
                    });
                    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

    public void execute(ConsoleReader consoleReader, ServerConnection connection, CommandArgs commandArgs) throws DeploymentException {
        String args[] = commandArgs.getArgs();
        if (args.length == 0) {
            throw new DeploymentException("Specify the key store name to be unlocked");
        }
        DeploymentManager dm = connection.getDeploymentManager();
        Kernel kernel = null;
        if (dm instanceof RemoteDeploymentManager) {
            kernel = ((RemoteDeploymentManager) dm).getKernel();
        }
        AbstractNameQuery anq= new AbstractNameQuery("org.apache.geronimo.management.geronimo.KeystoreManager");
View Full Code Here

        DDBeanRoot ddBeanRoot = webDeployable.getDDBeanRoot();
        DDBean ddBean = ddBeanRoot.getChildBean("web-app")[0];

        Kernel kernel = PortletManager.getKernel();
        DeploymentFactory factory = new DeploymentFactoryWithKernel(kernel);
        DeploymentManager deploymentManager = factory.getDeploymentManager("deployer:geronimo:inVM", null, null);
        DeploymentConfiguration deploymentConfiguration = deploymentManager.createConfiguration(webDeployable);
        WebAppDConfigRoot configRoot = (WebAppDConfigRoot) deploymentConfiguration.getDConfigBeanRoot(ddBeanRoot);
        WebAppDConfigBean webApp = (WebAppDConfigBean) configRoot.getDConfigBean(ddBean);

        webApp.setContextRoot(data.getContextRoot());
View Full Code Here

        // org.apache.geronimo.console.configmanager.DeploymentPortlet.processAction()
        // TODO need to eliminate this duplicate code
        DeploymentFactoryManager dfm = DeploymentFactoryManager.getInstance();
        String[] statusMsgs = new String[2];
        try {
            DeploymentManager mgr = dfm.getDeploymentManager("deployer:geronimo:inVM", null, null);
            try {
                if (mgr instanceof JMXDeploymentManager) {
                    ((JMXDeploymentManager) mgr).setLogConfiguration(false, true);
                }
               
                Target[] targets = mgr.getTargets();
                if (null == targets) {
                    throw new IllegalStateException("No target to distribute to");
                }
                targets = new Target[] {targets[0]};
               
                ProgressObject progress = mgr.distribute(targets, moduleFile, planFile);
                while (progress.getDeploymentStatus().isRunning()) {
                    Thread.sleep(100);
                }

                if (progress.getDeploymentStatus().isCompleted()) {
                    progress = mgr.start(progress.getResultTargetModuleIDs());
                    while (progress.getDeploymentStatus().isRunning()) {
                        Thread.sleep(100);
                    }
                    statusMsgs[0] = "infoMsg01";
                } else {
                    statusMsgs[0] = "errorMsg02";
                    statusMsgs[1] = progress.getDeploymentStatus().getMessage();
                }
            } finally {
                mgr.release();
            }
        } catch (Exception e) {
            throw new PortletException(e);
        }
        return statusMsgs;
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) {
                        addErrorMessage(actionRequest, getLocalizedString(actionRequest, "errorMsg04"), null);
                        log.error(getLocalizedString(actionRequest, "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 ? "infoMsg01" : "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, "infoMsg03");
                            addInfoMessage(actionRequest, abbrStatusMessage);                           
                        } else {
                            abbrStatusMessage = getLocalizedString(actionRequest, "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, "errorMsg01");
                    addErrorMessage(actionRequest, abbrStatusMessage, fullStatusMessage);
                    log.error(abbrStatusMessage + "\n" + fullStatusMessage);
                   
                    // 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
                    }
                }
            } 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

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.