Search in sources :

Example 31 with ParameterMap

use of org.glassfish.api.admin.ParameterMap 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 32 with ParameterMap

use of org.glassfish.api.admin.ParameterMap 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 33 with ParameterMap

use of org.glassfish.api.admin.ParameterMap 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 34 with ParameterMap

use of org.glassfish.api.admin.ParameterMap 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)

Example 35 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class InstanceInfo method pingInstance.

// TODO what about security????
private Future<InstanceCommandResult> pingInstance() {
    try {
        ActionReport aReport = report.addSubActionsReport();
        InstanceCommandResult aResult = new InstanceCommandResult();
        ParameterMap map = new ParameterMap();
        map.set("type", "terse");
        InstanceCommandExecutor ice = new InstanceCommandExecutor(habitat, "__locations", FailurePolicy.Error, FailurePolicy.Error, svr, host, port, logger, map, aReport, aResult);
        return stateService.submitJob(svr, ice, aResult);
    /*
            String ret = rac.executeCommand(map).trim();

            if (ret == null || (!ret.endsWith("/" + name)))
            return -1;
            running = true;
            String uptimeStr = rac.getAttributes().get("Uptime_value");
            return Long.parseLong(uptimeStr);
             */
    } catch (CommandException ex) {
        running = false;
        return null;
    }
}
Also used : InstanceCommandExecutor(com.sun.enterprise.admin.util.InstanceCommandExecutor) InstanceCommandResult(org.glassfish.api.admin.InstanceCommandResult) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport)

Aggregations

ParameterMap (org.glassfish.api.admin.ParameterMap)149 ActionReport (org.glassfish.api.ActionReport)68 CommandRunner (org.glassfish.api.admin.CommandRunner)37 Test (org.junit.Test)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 Map (java.util.Map)20 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)19 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)18 List (java.util.List)16 ArrayList (java.util.ArrayList)15 CommandRunner (org.glassfish.embeddable.CommandRunner)15 IOException (java.io.IOException)14 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)13 Before (org.junit.Before)13 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)13 CommandException (org.glassfish.api.admin.CommandException)12 File (java.io.File)11 MessagePart (org.glassfish.api.ActionReport.MessagePart)11 Resource (com.sun.enterprise.config.serverbeans.Resource)10 Logger (java.util.logging.Logger)9