Search in sources :

Example 91 with ParameterMap

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

the class MQSharedServiceTest method createSharedServices.

private void createSharedServices() {
    System.out.println("################### Trying to Create Shared 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);
    org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("create-shared-service", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "MQ");
    parameterMap.add("characteristics", "service-type=MQ");
    parameterMap.add("configuration", "mq.service.name=my-shared-mq-service");
    parameterMap.add("DEFAULT", "my-shared-mq-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'my-shared-mq-service' :" + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
    parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "LB");
    parameterMap.add("characteristics", "service-type=LB");
    parameterMap.add("configuration", "http-port=50080:https-port=50081:ssl-enabled=true");
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'my-shared-lb-service' :" + !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();
    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) List(java.util.List) CommandRunner(org.glassfish.embeddable.CommandRunner) ParameterMap(org.glassfish.api.admin.ParameterMap) Map(java.util.Map)

Example 92 with ParameterMap

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

the class BasicSharedServiceTest method testSharedService.

private void testSharedService() {
    System.out.println("$$$$$$$$$$$$$ TEST SHARED 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());
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-db-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());
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-db-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Expected Failure message: " + report.getMessage());
    Assert.assertTrue(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();
    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);
/* //Disable the application and try stopping  the shared service. Command should succeed
        invocation = commandRunner.getCommandInvocation("disable", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT","basic-shared-service-test");
        invocation.parameters(parameterMap).execute();

        System.out.print("Disabled application basic-shared-service-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.print("MSG: "+report.getMessage());

        invocation = commandRunner.getCommandInvocation("stop-shared-service", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT","my-shared-db-service");
        invocation.parameters(parameterMap).execute();

        Assert.assertFalse(report.hasFailures());
        System.out.print("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 = (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;
            }
        }
        Assert.assertTrue(sharedServiceStopped);//check if the shared services are stopped

        // Start the shared services.
        invocation = commandRunner.getCommandInvocation("start-shared-service", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT","my-shared-lb-service");
        invocation.parameters(parameterMap).execute();

        Assert.assertFalse(report.hasFailures());
        System.out.print("MSG: "+report.getMessage());

        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT","my-shared-db-service");
        invocation.parameters(parameterMap).execute();

        Assert.assertFalse(report.hasFailures());
        System.out.print("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();

        sharedServiceStarted=false;
        list = (List<Map<String, String>>) report.getExtraProperties().get("list");
        for(Map<String,String> map:list){
            sharedServiceStopped=false;
            String state=map.get("STATE");
            if("STARTED".equalsIgnoreCase(state) || "RUNNING".equalsIgnoreCase(state) ){
                sharedServiceStarted=true;
            }else{
                sharedServiceStarted = false;
                break;
            }
        }
        Assert.assertTrue(sharedServiceStarted);//check if the shared services are started.

        //Enable the application and try stopping  accessing
        invocation = commandRunner.getCommandInvocation("enable", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT","basic-shared-service-test");
        invocation.parameters(parameterMap).execute();

        System.out.print("Enabled application basic-shared-service-test: "+!report.hasFailures());
        Assert.assertFalse(report.hasFailures());

*/
/*


                invocation = commandRunner.getCommandInvocation("delete-shared-service", report);
                parameterMap = new ParameterMap();
                parameterMap.add("DEFAULT","my-shared-db-service");
                invocation.parameters(parameterMap).execute();

                Assert.assertFalse(report.hasFailures());
                System.out.print("MSG: "+report.getMessage());



                invocation = commandRunner.getCommandInvocation("delete-shared-service", report);
                parameterMap = new ParameterMap();
                parameterMap.add("DEFAULT","my-shared-db-service");
                invocation.parameters(parameterMap).execute();

                Assert.assertFalse(report.hasFailures());
                System.out.print("MSG: "+report.getMessage());*/
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) List(java.util.List) CommandRunner(org.glassfish.embeddable.CommandRunner) ParameterMap(org.glassfish.api.admin.ParameterMap) Map(java.util.Map)

Example 93 with ParameterMap

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

the class BasicSharedServiceTest method deleteSharedService.

private void deleteSharedService() {
    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("delete-shared-service", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertFalse(report.hasFailures());
    parameterMap = new ParameterMap();
    parameterMap.add("DEFAULT", "my-shared-db-service");
    invocation.parameters(parameterMap).execute();
    Assert.assertFalse(report.hasFailures());
    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)

Example 94 with ParameterMap

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

the class BasicSharedServiceTest method createSharedServices.

private void createSharedServices() {
    System.out.println("################### Trying to Create Shared Service #######################");
    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("create-shared-service", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "JavaEE");
    parameterMap.add("characteristics", "service-type=JavaEE");
    parameterMap.add("configuration", "min.clustersize=2:max.clustersize=4");
    parameterMap.add("DEFAULT", "my-shared-gf-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'my-shared-gf-service' :" + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
    // Create shared service of type Database
    // asadmin create-shared-service --characteristics service-type=Database --configuration database.name=my-shared-db-service --servicetype Database my-shared-db-service
    parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "Database");
    parameterMap.add("characteristics", "service-type=Database");
    parameterMap.add("configuration", "database.name=my-shared-db-service");
    parameterMap.add("DEFAULT", "my-shared-db-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'my-shared-db-service' :" + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
    // Create shared service of type LB
    // asadmin create-shared-service --characteristics service-type=LB --configuration http-port=50080:https-port=50081:ssl-enabled=true --servicetype LB my-shared-lb-service
    parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "LB");
    parameterMap.add("characteristics", "service-type=LB");
    parameterMap.add("configuration", "http-port=50080:https-port=50081:ssl-enabled=true");
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'my-shared-lb-service' :" + !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();
    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);
// Try starting an uncreated service. Should fail
/* parameterMap=new ParameterMap();
        parameterMap.add("DEFAULT","Uncreated-shared-db-service");
        invocation.parameters(parameterMap).execute();

        System.out.println("Started uncreated db shared service"+!report.hasFailures());
        //Assert.assertTrue(report.hasFailures());*/
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) List(java.util.List) CommandRunner(org.glassfish.embeddable.CommandRunner) ParameterMap(org.glassfish.api.admin.ParameterMap) Map(java.util.Map)

Example 95 with ParameterMap

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

the class SetMonitoringConfiguration method enableOnTarget.

/**
 * @param actionReport
 * @param context
 * @param enabled
 */
private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) {
    CommandRunner runner = serviceLocator.getService(CommandRunner.class);
    ActionReport subReport = context.getActionReport().addSubActionsReport();
    CommandRunner.CommandInvocation invocation;
    if (target.equals("server-config")) {
        invocation = runner.getCommandInvocation("__enable-monitoring-service-on-das", subReport, context.getSubject());
    } else {
        invocation = runner.getCommandInvocation("__enable-monitoring-service-on-instance", subReport, context.getSubject());
    }
    // Build the parameters
    ParameterMap params = new ParameterMap();
    enabled = Boolean.valueOf(monitoringConfig.getEnabled());
    params.add("enabled", enabled.toString());
    params.add("target", target);
    invocation.parameters(params);
    invocation.execute();
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

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