Search in sources :

Example 81 with ActionReport

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

the class SharedAndExternalServiceTest method testSharedAndExternalService.

private void testSharedAndExternalService() {
    System.out.println("$$$$$$$$$$$$$ TEST SHARED AND EXTERNAL SERVICES $$$$$$$$$$$$$$$");
    ServiceLocator habitat = Globals.getDefaultHabitat();
    org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
    ActionReport report = habitat.getService(ActionReport.class);
    // Try stopping a shared service, referenced by the app. Should 'FAIL'
    org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("stop-shared-service", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    System.out.print("Expected Failure message: " + report.getMessage());
    Assert.assertTrue(report.hasFailures());
    // Try deleting a shared service, referenced by the app. Should 'FAIL'
    report = habitat.getService(ActionReport.class);
    invocation = commandRunner.getCommandInvocation("delete-shared-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    System.out.print("Expected Failure message: " + report.getMessage());
    Assert.assertTrue(report.hasFailures());
    // Try deleting a external service, referenced by the app. Should 'FAIL'
    invocation = commandRunner.getCommandInvocation("delete-external-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-external-db-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Expected Failure message: " + report.getMessage());
    Assert.assertTrue(report.hasFailures());
    invocation = commandRunner.getCommandInvocation("stop-shared-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertTrue(report.hasFailures());
    System.out.print("Expected failure MSG: " + report.getMessage());
    // List the services and check the status of both the services - it should be 'RUNNING'
    invocation = commandRunner.getCommandInvocation("list-services", report);
    parameterMap = new ParameterMap();
    parameterMap.add("scope", "shared");
    parameterMap.add("output", "service-name,state");
    invocation.parameters(parameterMap).execute();
    boolean sharedServiceStarted = false;
    List<Map<String, String>> list = (List<Map<String, String>>) report.getExtraProperties().get("list");
    for (Map<String, String> map : list) {
        sharedServiceStarted = false;
        String state = map.get("STATE");
        if ("RUNNING".equalsIgnoreCase(state)) {
            sharedServiceStarted = true;
        } else {
            break;
        }
    }
    // check if the shared services are started.
    Assert.assertTrue(sharedServiceStarted);
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ParameterMap(org.glassfish.api.admin.ParameterMap)

Example 82 with ActionReport

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

the class SharedAndExternalServiceTest method deleteSharedAndExternalService.

private void deleteSharedAndExternalService() {
    ServiceLocator habitat = Globals.getDefaultHabitat();
    org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
    ActionReport report = habitat.getService(ActionReport.class);
    org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("delete-shared-service", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertFalse(report.hasFailures());
    invocation = commandRunner.getCommandInvocation("delete-external-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-external-db-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertFalse(report.hasFailures());
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport)

Example 83 with ActionReport

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

the class RollbackTransaction method execute.

/**
 * Executes the command
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        transactionMgr.forceRollback(txnId);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (Exception e) {
        report.setMessage(localStrings.getString("rollback.transaction.failed"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport)

Example 84 with ActionReport

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

the class UpdateNodeCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    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;
    }
    // validate installdir if passed and running on localhost
    if (StringUtils.ok(nodehost)) {
        if (NetUtils.isThisHostLocal(nodehost) && StringUtils.ok(installdir)) {
            TokenResolver resolver = null;
            // Create a resolver that can replace system properties in strings
            Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
            resolver = new TokenResolver(systemPropsMap);
            String resolvedInstallDir = resolver.resolve(installdir);
            File actualInstallDir = new File(resolvedInstallDir + "/" + NodeUtils.LANDMARK_FILE);
            if (!actualInstallDir.exists()) {
                report.setMessage(Strings.get("invalid.installdir", installdir));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    // like the install directory or node directory.
    if (node.nodeInUse()) {
        String badparam = null;
        String configNodedir = node.getNodeDir();
        String configInstalldir = node.getInstallDir();
        if (!allowableChange(nodedir, configNodedir)) {
            badparam = "nodedir";
        }
        if (!allowableChange(installdir, configInstalldir)) {
            badparam = "installdir";
        }
        if (StringUtils.ok(badparam)) {
            String msg = Strings.get("noUpdate.nodeInUse", name, badparam);
            logger.warning(msg);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    }
    try {
        updateNodeElement(name);
    } catch (TransactionFailure e) {
        logger.warning("failed.to.update.node " + name);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(e.getMessage());
    }
}
Also used : TokenResolver(com.sun.enterprise.universal.glassfish.TokenResolver) HashMap(java.util.HashMap) Node(com.sun.enterprise.config.serverbeans.Node) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) File(java.io.File)

Example 85 with ActionReport

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

the class UpdateNodeConfigCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    StringBuilder msg = new StringBuilder();
    Node node = null;
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    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;
    }
    // After updating the config node it needs to have a host
    if (!StringUtils.ok(nodehost) && !StringUtils.ok(node.getNodeHost())) {
        String m = Strings.get("update.node.config.missing.attribute", node.getName(), NodeUtils.PARAM_NODEHOST);
        logger.warning(m);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(m);
        return;
    }
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    if (installdir != null) {
        map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
    }
    if (nodehost != null) {
        map.add(NodeUtils.PARAM_NODEHOST, nodehost);
    }
    if (nodedir != null) {
        map.add(NodeUtils.PARAM_NODEDIR, nodedir);
    }
    map.add(NodeUtils.PARAM_TYPE, "CONFIG");
    if (map.size() > 1) {
        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)

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