Search in sources :

Example 86 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class UpdateNodeRemoteCommand method executeInternal.

protected final void executeInternal(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    StringBuilder msg = new StringBuilder();
    Node node = null;
    logger = context.getLogger();
    // Make sure Node is valid
    node = nodes.getNode(name);
    if (node == null) {
        String m = Strings.get("noSuchNode", name);
        logger.warning(m);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(m);
        return;
    }
    if (node.isDefaultLocalNode()) {
        String m = Strings.get("update.node.config.defaultnode", name);
        logger.warning(m);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(m);
        return;
    }
    // Ah the problems caused by hard-coding ssh into parameter names!
    populateParameters();
    // First create a map that holds the parameters and reflects what
    // the user passed on the command line.
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
    map.add(NodeUtils.PARAM_NODEHOST, nodehost);
    map.add(NodeUtils.PARAM_NODEDIR, nodedir);
    map.add(NodeUtils.PARAM_REMOTEPORT, remotePort);
    map.add(NodeUtils.PARAM_REMOTEUSER, remoteUser);
    map.add(NodeUtils.PARAM_SSHKEYFILE, sshkeyfile);
    map.add(NodeUtils.PARAM_REMOTEPASSWORD, remotepassword);
    map.add(NodeUtils.PARAM_SSHKEYPASSPHRASE, sshkeypassphrase);
    map.add(NodeUtils.PARAM_WINDOWSDOMAINNAME, windowsdomain);
    map.add(NodeUtils.PARAM_TYPE, getType().toString());
    // Now init any parameters that weren't passed into the command
    // using the values from the config
    initFromConfig(node);
    // Finally, anything that still isn't set, use the defaults.
    // These should likely come from config -- but they don't
    // as of now
    setDefaults();
    // validateMap holds the union of what the user passed and what was
    // in the config so we have all the settings needed to validate what
    // the node will look like after we update it.
    ParameterMap validateMap = new ParameterMap();
    validateMap.add(NodeUtils.PARAM_INSTALLDIR, installdir);
    validateMap.add(NodeUtils.PARAM_NODEHOST, nodehost);
    validateMap.add(NodeUtils.PARAM_NODEDIR, nodedir);
    validateMap.add(NodeUtils.PARAM_REMOTEPORT, remotePort);
    validateMap.add(NodeUtils.PARAM_REMOTEUSER, remoteUser);
    validateMap.add(NodeUtils.PARAM_SSHKEYFILE, sshkeyfile);
    validateMap.add(NodeUtils.PARAM_REMOTEPASSWORD, remotepassword);
    validateMap.add(NodeUtils.PARAM_SSHKEYPASSPHRASE, sshkeypassphrase);
    validateMap.add(NodeUtils.PARAM_WINDOWSDOMAINNAME, windowsdomain);
    validateMap.add(NodeUtils.PARAM_TYPE, getType().toString());
    // Validate the settings
    try {
        NodeUtils nodeUtils = new NodeUtils(habitat, logger);
        nodeUtils.validate(validateMap);
    } catch (CommandValidationException e) {
        String m1 = Strings.get("node.ssh.invalid.params");
        if (!force) {
            String m2 = Strings.get("update.node.ssh.not.updated");
            msg.append(StringUtils.cat(NL, m1, m2, e.getMessage()));
            report.setMessage(msg.toString());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } else {
            String m2 = Strings.get("update.node.ssh.continue.force");
            msg.append(StringUtils.cat(NL, m1, e.getMessage(), m2));
        }
    }
    // Settings are valid. Now use the generic update-node command to
    // update the node.
    CommandInvocation ci = cr.getCommandInvocation("_update-node", report, context.getSubject());
    ci.parameters(map);
    ci.execute();
    if (StringUtils.ok(report.getMessage())) {
        if (msg.length() > 0) {
            msg.append(NL);
        }
        msg.append(report.getMessage());
    }
    report.setMessage(msg.toString());
}
Also used : Node(com.sun.enterprise.config.serverbeans.Node) ActionReport(org.glassfish.api.ActionReport) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 87 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class ValidateNodeCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    if (logger.isLoggable(Level.FINE))
        logger.fine(Strings.get("Validating node {0}", name));
    Node node = nodes.getNode(name);
    if (node == null) {
        // node doesn't exist
        String msg = Strings.get("noSuchNode", name);
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    try {
        validateNode(node);
    } catch (CommandValidationException e) {
        logger.warning(e.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(e.getMessage());
        return;
    }
    if (logger.isLoggable(Level.FINE))
        logger.fine(Strings.get("Node {0} is valid. Updating if needed", name));
    // What is there in the node is valid. Now go update anything that
    // was not there.
    CommandInvocation ci = cr.getCommandInvocation("_update-node", report, context.getSubject());
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    if (!excludeFromUpdate.contains("installdir"))
        map.add("installdir", installdir);
    if (!excludeFromUpdate.contains("nodehost"))
        map.add("nodehost", nodehost);
    if (!excludeFromUpdate.contains("nodedir"))
        map.add("nodedir", nodedir);
    if (!excludeFromUpdate.contains("sshport"))
        map.add("sshport", sshport);
    if (!excludeFromUpdate.contains("sshuser"))
        map.add("sshuser", sshuser);
    if (!excludeFromUpdate.contains("sshkeyfile"))
        map.add("sshkeyfile", sshkeyfile);
    // Only update if there is something to do
    if (map.size() > 1) {
        ci.parameters(map);
        ci.execute();
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 88 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class ListDeploymentGroupsCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    DeploymentGroups deploymentGroups = domain.getDeploymentGroups();
    List<DeploymentGroup> listOfDeploymentGroup = deploymentGroups.getDeploymentGroup();
    if (listOfDeploymentGroup.isEmpty()) {
        report.appendMessage("No Deployment Group has been created");
    } else {
        StringBuffer sb = new StringBuffer();
        sb.append("List of Deployment Groups" + ":\n");
        Properties extrasProps = new Properties();
        ArrayList<String> deploymentGroupNames = new ArrayList<String>();
        for (DeploymentGroup deploymentGroup : listOfDeploymentGroup) {
            sb.append("\t" + deploymentGroup.getName() + "\n");
            deploymentGroupNames.add(deploymentGroup.getName());
        }
        extrasProps.put("listOfDeploymentGroups", deploymentGroupNames);
        report.setMessage(sb.toString());
        report.setExtraProperties(extrasProps);
    }
}
Also used : DeploymentGroups(fish.payara.enterprise.config.serverbeans.DeploymentGroups) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 89 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class RestartDeploymentGroupCommand method doRolling.

private void doRolling(AdminCommandContext context) {
    List<Server> servers = domain.getServersInTarget(deploymentGroup);
    StringBuilder output = new StringBuilder();
    Logger logger = context.getLogger();
    for (Server server : servers) {
        ParameterMap instanceParameterMap = new ParameterMap();
        // Set the instance name as the operand for the commnd
        instanceParameterMap.set("DEFAULT", server.getName());
        ActionReport instanceReport = runner.getActionReport("plain");
        instanceReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        CommandRunner.CommandInvocation invocation = runner.getCommandInvocation("stop-instance", instanceReport, context.getSubject());
        invocation.parameters(instanceParameterMap);
        String msg = "stop-instance" + " " + server.getName();
        logger.info(msg);
        if (verbose) {
            output.append(msg).append(NL);
        }
        invocation.execute();
        logger.info(invocation.report().getMessage());
        if (verbose) {
            output.append(invocation.report().getMessage()).append(NL);
        }
        instanceParameterMap = new ParameterMap();
        // Set the instance name as the operand for the commnd
        instanceParameterMap.set("DEFAULT", server.getName());
        instanceReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        invocation = runner.getCommandInvocation("start-instance", instanceReport, context.getSubject());
        invocation.parameters(instanceParameterMap);
        msg = "start-instance" + " " + server.getName();
        logger.info(msg);
        if (verbose) {
            output.append(msg).append(NL);
        }
        invocation.execute();
        logger.info(invocation.report().getMessage());
        if (verbose) {
            output.append(invocation.report().getMessage()).append(NL);
        }
        try {
            long delayVal = Long.valueOf(delay);
            if (delayVal > 0) {
                Thread.currentThread().sleep(delayVal);
            }
        } catch (InterruptedException e) {
        }
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) ParameterMap(org.glassfish.api.admin.ParameterMap) Logger(java.util.logging.Logger) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 90 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class StopDeploymentGroupCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    logger.info(Strings.get("stop.dg", deploymentGroup));
    // Require that we be a DAS
    if (!env.isDas()) {
        String msg = Strings.get("cluster.command.notDas");
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    ClusterCommandHelper clusterHelper = new ClusterCommandHelper(domain, runner);
    ParameterMap map = null;
    if (kill) {
        map = new ParameterMap();
        map.add("kill", "true");
    }
    try {
        // Run start-instance against each instance in the cluster
        String commandName = "stop-instance";
        clusterHelper.runCommand(commandName, map, deploymentGroup, context, verbose);
    } catch (CommandException e) {
        String msg = e.getLocalizedMessage();
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
    }
}
Also used : ClusterCommandHelper(com.sun.enterprise.v3.admin.cluster.ClusterCommandHelper) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

Aggregations

ActionReport (org.glassfish.api.ActionReport)508 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)86 Properties (java.util.Properties)83 Config (com.sun.enterprise.config.serverbeans.Config)73 PropertyVetoException (java.beans.PropertyVetoException)72 ParameterMap (org.glassfish.api.admin.ParameterMap)66 Logger (java.util.logging.Logger)56 IOException (java.io.IOException)47 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)43 File (java.io.File)41 CommandTarget (org.glassfish.config.support.CommandTarget)30 Target (org.glassfish.internal.api.Target)30 Map (java.util.Map)27 Server (com.sun.enterprise.config.serverbeans.Server)25 List (java.util.List)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 CommandRunner (org.glassfish.api.admin.CommandRunner)23 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)23 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)19