Search in sources :

Example 11 with ServiceId

use of io.cdap.cdap.proto.id.ServiceId in project cdap by cdapio.

the class CLITestBase method testVersionedRuntimeArgs.

@Test
public void testVersionedRuntimeArgs() throws Exception {
    String versionedServiceId = String.format("%s.%s version %s", FakeApp.NAME, PrefixedEchoHandler.NAME, V1_SNAPSHOT);
    ServiceId service = FAKE_APP_ID_V_1.service(PrefixedEchoHandler.NAME);
    testServiceRuntimeArgs(versionedServiceId, service);
}
Also used : ServiceId(io.cdap.cdap.proto.id.ServiceId) Test(org.junit.Test)

Example 12 with ServiceId

use of io.cdap.cdap.proto.id.ServiceId in project cdap by cdapio.

the class CheckServiceAvailabilityCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    ServiceId serviceId = new ServiceId(parseProgramId(arguments, ElementType.SERVICE));
    serviceClient.checkAvailability(serviceId);
    output.println("Service is available to accept requests.");
}
Also used : ServiceId(io.cdap.cdap.proto.id.ServiceId)

Example 13 with ServiceId

use of io.cdap.cdap.proto.id.ServiceId in project cdap by cdapio.

the class SetProgramInstancesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    ApplicationId appId = cliConfig.getCurrentNamespace().app(programIdParts[0]);
    int numInstances = arguments.getInt(ArgumentName.NUM_INSTANCES.toString());
    switch(elementType) {
        case WORKER:
            if (programIdParts.length < 2) {
                throw new CommandInputError(this);
            }
            String workerName = programIdParts[1];
            ProgramId workerId = appId.worker(workerName);
            programClient.setWorkerInstances(workerId, numInstances);
            output.printf("Successfully set worker '%s' of app '%s' to %d instances\n", workerName, appId.getEntityName(), numInstances);
            break;
        case SERVICE:
            if (programIdParts.length < 2) {
                throw new CommandInputError(this);
            }
            String serviceName = programIdParts[1];
            ServiceId service = appId.service(serviceName);
            programClient.setServiceInstances(service, numInstances);
            output.printf("Successfully set service '%s' of app '%s' to %d instances\n", serviceName, appId.getEntityName(), numInstances);
            break;
        default:
            // TODO: remove this
            throw new IllegalArgumentException("Unrecognized program element type for scaling: " + elementType);
    }
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ServiceId(io.cdap.cdap.proto.id.ServiceId)

Example 14 with ServiceId

use of io.cdap.cdap.proto.id.ServiceId in project cdap by cdapio.

the class HttpMethodPrefixCompleter method complete.

@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    Map<String, String> arguments = ArgumentParser.getArguments(buffer, PATTERN);
    ProgramIdArgument programIdArgument = ArgumentParser.parseProgramId(arguments.get(SERVICE_ID));
    if (programIdArgument != null) {
        ServiceId service;
        if (arguments.get(APP_VERSION) == null) {
            service = cliConfig.getCurrentNamespace().app(programIdArgument.getAppId()).service(programIdArgument.getProgramId());
        } else {
            service = cliConfig.getCurrentNamespace().app(programIdArgument.getAppId(), arguments.get(APP_VERSION)).service(programIdArgument.getProgramId());
        }
        completer.setEndpoints(getMethods(service));
    } else {
        completer.setEndpoints(Collections.<String>emptyList());
    }
    return super.complete(buffer, cursor, candidates);
}
Also used : ProgramIdArgument(io.cdap.cdap.cli.ProgramIdArgument) ServiceId(io.cdap.cdap.proto.id.ServiceId)

Example 15 with ServiceId

use of io.cdap.cdap.proto.id.ServiceId in project cdap by cdapio.

the class MetricsClientTestRun method testAll.

@Test
public void testAll() throws Exception {
    appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class));
    ApplicationId app = NamespaceId.DEFAULT.app(FakeApp.NAME);
    ServiceId service = app.service(PingService.NAME);
    try {
        programClient.start(service);
        programClient.waitForStatus(service, ProgramStatus.RUNNING, 15, TimeUnit.SECONDS);
        URL serviceURL = serviceClient.getServiceURL(service);
        URL pingURL = new URL(serviceURL, "ping");
        HttpResponse response = HttpRequests.execute(HttpRequest.get(pingURL).build(), new DefaultHttpRequestConfig(false));
        Assert.assertEquals(200, response.getResponseCode());
        Tasks.waitFor(true, () -> metricsClient.query(MetricsTags.service(service), Collections.singletonList(Constants.Metrics.Name.Service.SERVICE_INPUT), Collections.emptyList(), ImmutableMap.of("start", "now-20s", "end", "now")).getSeries().length > 0, 10, TimeUnit.SECONDS);
        MetricQueryResult result = metricsClient.query(MetricsTags.service(service), Constants.Metrics.Name.Service.SERVICE_INPUT);
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        result = metricsClient.query(MetricsTags.service(service), Collections.singletonList(Constants.Metrics.Name.Service.SERVICE_INPUT), Collections.emptyList(), Collections.singletonMap("aggregate", "true"));
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        result = metricsClient.query(MetricsTags.service(service), Collections.singletonList(Constants.Metrics.Name.Service.SERVICE_INPUT), Collections.emptyList(), ImmutableMap.of("start", "now-20s", "end", "now"));
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        List<MetricTagValue> tags = metricsClient.searchTags(MetricsTags.service(service));
        Assert.assertEquals(1, tags.size());
        Assert.assertEquals("run", tags.get(0).getName());
        List<String> metrics = metricsClient.searchMetrics(MetricsTags.service(service));
        Assert.assertTrue(metrics.contains(Constants.Metrics.Name.Service.SERVICE_INPUT));
    } finally {
        programClient.stop(service);
        assertProgramRuns(programClient, service, ProgramRunStatus.KILLED, 1, 10);
        appClient.delete(app);
    }
}
Also used : FakeApp(io.cdap.cdap.client.app.FakeApp) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) MetricTagValue(io.cdap.cdap.proto.MetricTagValue) HttpResponse(io.cdap.common.http.HttpResponse) MetricQueryResult(io.cdap.cdap.proto.MetricQueryResult) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) URL(java.net.URL) ServiceId(io.cdap.cdap.proto.id.ServiceId) Test(org.junit.Test)

Aggregations

ServiceId (io.cdap.cdap.proto.id.ServiceId)32 Test (org.junit.Test)20 HttpResponse (io.cdap.common.http.HttpResponse)14 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)10 URL (java.net.URL)8 Gson (com.google.gson.Gson)6 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 JsonObject (com.google.gson.JsonObject)4 ProgramIdArgument (io.cdap.cdap.cli.ProgramIdArgument)4 CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)4 FakeApp (io.cdap.cdap.client.app.FakeApp)4 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)4 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)4 ProgramId (io.cdap.cdap.proto.id.ProgramId)4 File (java.io.File)4 TypeToken (com.google.common.reflect.TypeToken)2 ServiceHttpEndpoint (io.cdap.cdap.api.service.http.ServiceHttpEndpoint)2