Search in sources :

Example 16 with ServiceId

use of co.cask.cdap.proto.id.ServiceId in project cdap by caskdata.

the class CLIMainTest method testService.

@Test
public void testService() throws Exception {
    ServiceId service = FAKE_APP_ID.service(PrefixedEchoHandler.NAME);
    ServiceId serviceV1 = FAKE_APP_ID_V_1.service(PrefixedEchoHandler.NAME);
    String serviceName = String.format("%s.%s", FakeApp.NAME, PrefixedEchoHandler.NAME);
    String serviceArgument = String.format("%s version %s", serviceName, ApplicationId.DEFAULT_VERSION);
    String serviceV1Argument = String.format("%s version %s", serviceName, V1_SNAPSHOT);
    try {
        // Test service commands with no optional version argument
        testCommandOutputContains(cli, "start service " + serviceName, "Successfully started service");
        testCommandOutputContains(cli, "get endpoints service " + serviceName, "POST");
        testCommandOutputContains(cli, "get endpoints service " + serviceName, "/echo");
        testCommandOutputContains(cli, "check service availability " + serviceName, "Service is available");
        testCommandOutputContains(cli, "call service " + serviceName + " POST /echo body \"testBody\"", ":testBody");
        testCommandOutputContains(cli, "stop service " + serviceName, "Successfully stopped service");
        assertProgramStatus(programClient, service, "STOPPED");
        // Test service commands with version argument when two versions of the service are running
        testCommandOutputContains(cli, "start service " + serviceArgument, "Successfully started service");
        testCommandOutputContains(cli, "start service " + serviceV1Argument, "Successfully started service");
        assertProgramStatus(programClient, service, "RUNNING");
        assertProgramStatus(programClient, serviceV1, "RUNNING");
        testCommandOutputContains(cli, "get endpoints service " + serviceArgument, "POST");
        testCommandOutputContains(cli, "get endpoints service " + serviceV1Argument, "POST");
        testCommandOutputContains(cli, "get endpoints service " + serviceArgument, "/echo");
        testCommandOutputContains(cli, "get endpoints service " + serviceV1Argument, "/echo");
        testCommandOutputContains(cli, "check service availability " + serviceArgument, "Service is available");
        testCommandOutputContains(cli, "check service availability " + serviceV1Argument, "Service is available");
        testCommandOutputContains(cli, "call service " + serviceArgument + " POST /echo body \"testBody\"", ":testBody");
        testCommandOutputContains(cli, "call service " + serviceV1Argument + " POST /echo body \"testBody\"", ":testBody");
    } finally {
        // Stop all running services
        programClient.stopAll(NamespaceId.DEFAULT);
    }
}
Also used : ServiceId(co.cask.cdap.proto.id.ServiceId) Test(org.junit.Test)

Example 17 with ServiceId

use of co.cask.cdap.proto.id.ServiceId in project cdap by caskdata.

the class SetRouteConfigCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    ServiceId serviceId = new ServiceId(parseProgramId(arguments, ElementType.SERVICE));
    String routeConfig = arguments.get(ArgumentName.ROUTE_CONFIG.getName());
    serviceClient.storeRouteConfig(serviceId, ArgumentParser.parseStringIntegerMap(routeConfig, ArgumentName.ROUTE_CONFIG.toString()));
    output.printf("Successfully set route configuration of %s '%s' of application '%s' to '%s'\n", ElementType.SERVICE.getName(), serviceId.getProgram(), serviceId.getApplication(), routeConfig);
}
Also used : ServiceId(co.cask.cdap.proto.id.ServiceId)

Aggregations

ServiceId (co.cask.cdap.proto.id.ServiceId)17 Test (org.junit.Test)5 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3 ProgramIdArgument (co.cask.cdap.cli.ProgramIdArgument)2 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)2 HttpResponse (co.cask.common.http.HttpResponse)2 URL (java.net.URL)2 ServiceHttpEndpoint (co.cask.cdap.api.service.http.ServiceHttpEndpoint)1 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 EndpointStrategy (co.cask.cdap.common.discovery.EndpointStrategy)1 RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)1 BatchProgramStatus (co.cask.cdap.proto.BatchProgramStatus)1 ProgramStatus (co.cask.cdap.proto.ProgramStatus)1 FlowletId (co.cask.cdap.proto.id.FlowletId)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 HttpMethod (co.cask.common.http.HttpMethod)1 HttpRequest (co.cask.common.http.HttpRequest)1 TypeToken (com.google.common.reflect.TypeToken)1 File (java.io.File)1