Search in sources :

Example 76 with ActionReport

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

the class GetResourceAdapterConfigProperties method execute.

/**
 * @inheritDoc
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Map<String, String> configProps = connectorRuntime.getResourceAdapterConfigProps(rarName);
        Properties extraProperties = new Properties();
        extraProperties.put("configProps", configProps);
        List<String> confidentialProperties = connectorRuntime.getConfidentialProperties(rarName, ConnectorConstants.RAR);
        extraProperties.put("confidentialConfigProps", confidentialProperties);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage("_get-resource-adapter-config-properties failed : " + e.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    report.setActionExitCode(ec);
}
Also used : ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 77 with ActionReport

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

the class RecoverTransactions method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (_logger.isLoggable(Level.INFO)) {
        _logger.info("==> original target: " + destinationServer + " ... server: " + serverToRecover);
    }
    String error = validate(destinationServer, false);
    if (error != null) {
        _logger.log(Level.WARNING, localStrings.getString("recover.transactions.failed") + " " + error);
        report.setMessage(error);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // here we are only if parameters consistent
    if (destinationServer == null)
        destinationServer = serverToRecover;
    try {
        boolean result;
        CommandRunner.CommandInvocation inv = runner.getCommandInvocation("_recover-transactions-internal", report, context.getSubject());
        final ParameterMap parameters = new ParameterMap();
        parameters.add("target", destinationServer);
        parameters.add("DEFAULT", serverToRecover);
        parameters.add("transactionlogdir", transactionLogDir);
        if (_logger.isLoggable(Level.INFO)) {
            _logger.info("==> calling _recover-transactions-internal with params: " + parameters);
        }
        inv.parameters(parameters).execute();
        if (_logger.isLoggable(Level.INFO)) {
            _logger.info("==> _recover-transactions-internal returned with: " + report.getActionExitCode());
        }
    // Exit code is set by _recover-transactions-internal
    } catch (Exception e) {
        _logger.log(Level.WARNING, localStrings.getString("recover.transactions.failed"), e);
        report.setMessage(localStrings.getString("recover.transactions.failed"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 78 with ActionReport

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

the class EnableDisableTest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS application.
    File archive = new File(System.getProperty("basedir") + // TODO :: use
    "/target/enable-disable-sample.war");
    // mvn apis to
    // get the
    // archive
    // location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    try {
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandResult result = null;
        CommandRunner commandRunner = glassfish.getCommandRunner();
        {
            result = commandRunner.run("list-services", "appname=" + appName, "output=STATE");
            System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
            boolean notRunning = result.getOutput().toLowerCase().contains("notrunning");
            Assert.assertTrue(!notRunning);
            boolean stopped = result.getOutput().toLowerCase().contains("stopped");
            Assert.assertTrue(!stopped);
        }
        // 2.a.Check if all services of the application are in ONLY running state.
        ServiceLocator habitat = Globals.getDefaultHabitat();
        org.glassfish.api.admin.CommandRunner commandRunner1 = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        ActionReport report = habitat.getService(ActionReport.class);
        org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner1.getCommandInvocation("list-services", report);
        ParameterMap parameterMap = new ParameterMap();
        parameterMap.add("appname", appName);
        parameterMap.add("output", "state");
        parameterMap.add("scope", "application");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        List<Map<String, String>> listOfMap = (List<Map<String, String>>) report.getExtraProperties().get("list");
        String state = null;
        boolean servicesRunning = false;
        for (Map<String, String> map : listOfMap) {
            servicesRunning = false;
            state = map.get("STATE");
            if (state.equalsIgnoreCase("running")) {
                servicesRunning = true;
            } else {
                break;
            }
        }
        Assert.assertTrue(servicesRunning);
        System.out.println("All services in RUNNING state");
        // 3. Access the app to make sure PaaS app is correctly provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/enable-disable-sample/EnableDisableServlet", "Customer ID");
        // 4.Disable application
        ParameterMap parameterMap1 = new ParameterMap();
        parameterMap1.add("DEFAULT", appName);
        invocation = commandRunner1.getCommandInvocation("disable", report);
        invocation.parameters(parameterMap1).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Disabled application ' " + appName + " ' ");
        // 5.Check if NONE of the application of the service are in 'RUNNING' state
        invocation = commandRunner1.getCommandInvocation("list-services", report);
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        listOfMap = (List<Map<String, String>>) report.getExtraProperties().get("list");
        for (Map<String, String> map : listOfMap) {
            servicesRunning = true;
            state = map.get("STATE");
            if (state.equalsIgnoreCase("running")) {
                break;
            } else {
                servicesRunning = false;
            }
        }
        Assert.assertFalse(servicesRunning);
        System.out.println("No service in RUNNING state");
        // 6.Enable application
        invocation = commandRunner1.getCommandInvocation("enable", report);
        parameterMap1 = new ParameterMap();
        parameterMap1.add("DEFAULT", appName);
        invocation.parameters(parameterMap1).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Enabled application ' " + appName + " ' ");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/enable-disable-sample/EnableDisableServlet", "Customer ID");
    // 8.. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.out.println("Destroying the resources created");
            System.err.println("Undeployed [" + appName + "]");
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                if (commandResult.getOutput().contains("Nothing to list.")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
        glassfish.dispose();
    }
}
Also used : PrintStream(java.io.PrintStream) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) List(java.util.List) File(java.io.File) ParameterMap(org.glassfish.api.admin.ParameterMap) Map(java.util.Map) Test(org.junit.Test)

Example 79 with ActionReport

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

the class ExtSharedServiceEnableDisableTest 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);
    // Disable the application and try stopping  the shared service. Command should succeed
    org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("disable", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "ext-shared-service-enable-disable-test");
    invocation.parameters(parameterMap).execute();
    System.out.println("Disabled application ext-shared-service-enable-disable-test: " + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
    invocation = commandRunner.getCommandInvocation("stop-shared-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertFalse(report.hasFailures());
    System.out.println("MSG: " + report.getMessage());
    // try deleting a external service when an app is using it. it should 'FAIL'
    invocation = commandRunner.getCommandInvocation("delete-external-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-external-db-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertTrue(report.hasFailures());
    System.out.println("Expected Failure Msg: " + report.getMessage());
    invocation = commandRunner.getCommandInvocation("stop-shared-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-gf-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertFalse(report.hasFailures());
    System.out.println("MSG: " + report.getMessage());
    // List the services and check the status of both the services - it should be 'STOPPED'
    parameterMap = new ParameterMap();
    parameterMap.add("scope", "shared");
    parameterMap.add("output", "service-name,state");
    invocation = commandRunner.getCommandInvocation("list-services", report);
    invocation.parameters(parameterMap).execute();
    boolean sharedServiceStopped = false;
    List<Map<String, String>> list = (List<Map<String, String>>) report.getExtraProperties().get("list");
    for (Map<String, String> map : list) {
        sharedServiceStopped = false;
        String state = map.get("STATE");
        if ("STOPPED".equalsIgnoreCase(state)) {
            sharedServiceStopped = true;
        } else {
            sharedServiceStopped = false;
            break;
        }
    }
    // check if the shared services are stopped
    Assert.assertTrue(sharedServiceStopped);
    // Start the shared services.
    report = habitat.getService(ActionReport.class);
    invocation = commandRunner.getCommandInvocation("start-shared-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-gf-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertFalse(report.hasFailures());
    System.out.println("MSG: " + report.getMessage());
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertFalse(report.hasFailures());
    System.out.println("MSG: " + report.getMessage());
    // List the services and check the status of both the services - it should be 'STARTED'
    parameterMap = new ParameterMap();
    parameterMap.add("scope", "shared");
    parameterMap.add("output", "service-name,state");
    invocation = commandRunner.getCommandInvocation("list-services", report);
    invocation.parameters(parameterMap).execute();
    boolean sharedServiceStarted = false;
    list = (List<Map<String, String>>) report.getExtraProperties().get("list");
    for (Map<String, String> map : list) {
        sharedServiceStarted = false;
        String state = map.get("STATE");
        if ("STARTED".equalsIgnoreCase(state) || "RUNNING".equalsIgnoreCase(state)) {
            sharedServiceStarted = true;
        } else {
            break;
        }
    }
    // check if the shared services are started.
    Assert.assertTrue(sharedServiceStarted);
    // Enable the application and try stopping  accessing
    invocation = commandRunner.getCommandInvocation("enable", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "ext-shared-service-enable-disable-test");
    invocation.parameters(parameterMap).execute();
    System.out.println("Enabled application ext-shared-service-enable-disable-test: " + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
    {
        // 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();
        sharedServiceStarted = false;
        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) CommandRunner(org.glassfish.embeddable.CommandRunner) ParameterMap(org.glassfish.api.admin.ParameterMap)

Example 80 with ActionReport

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

the class ExtSharedServiceEnableDisableTest 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());
    invocation = commandRunner.getCommandInvocation("delete-shared-service", report);
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-gf-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) CommandRunner(org.glassfish.embeddable.CommandRunner)

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