Search in sources :

Example 21 with ServiceSpecification

use of io.cdap.cdap.api.service.ServiceSpecification in project cdap by caskdata.

the class InMemoryServiceProgramRunner method run.

@Override
public ProgramController run(Program program, ProgramOptions options) {
    // Extract and verify parameters
    ApplicationSpecification appSpec = program.getApplicationSpecification();
    Preconditions.checkNotNull(appSpec, "Missing application specification.");
    ProgramType processorType = program.getType();
    Preconditions.checkNotNull(processorType, "Missing processor type.");
    Preconditions.checkArgument(processorType == ProgramType.SERVICE, "Only SERVICE process type is supported.");
    ServiceSpecification serviceSpec = appSpec.getServices().get(program.getName());
    Preconditions.checkNotNull(serviceSpec, "Missing ServiceSpecification for %s", program.getName());
    return startAll(program, options, serviceSpec.getInstances());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) ProgramType(io.cdap.cdap.proto.ProgramType)

Example 22 with ServiceSpecification

use of io.cdap.cdap.api.service.ServiceSpecification in project cdap by caskdata.

the class DefaultStore method getServiceInstances.

@Override
public int getServiceInstances(ProgramId id) {
    return TransactionRunners.run(transactionRunner, context -> {
        ApplicationSpecification appSpec = getAppSpecOrFail(getAppMetadataStore(context), id);
        ServiceSpecification serviceSpec = getServiceSpecOrFail(id, appSpec);
        return serviceSpec.getInstances();
    });
}
Also used : ForwardingApplicationSpecification(io.cdap.cdap.internal.app.ForwardingApplicationSpecification) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification)

Example 23 with ServiceSpecification

use of io.cdap.cdap.api.service.ServiceSpecification in project cdap by caskdata.

the class ServiceClientTestRun method testGetServiceSpecification.

@Test
public void testGetServiceSpecification() throws Exception {
    ServiceSpecification serviceSpecification = serviceClient.get(service);
    assertEquals(serviceSpecification.getName(), PingService.NAME);
    assertEquals(serviceSpecification.getHandlers().size(), 1);
}
Also used : ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) Test(org.junit.Test)

Example 24 with ServiceSpecification

use of io.cdap.cdap.api.service.ServiceSpecification in project cdap by caskdata.

the class GenerateClientUsageExample method serviceClient.

public void serviceClient() throws Exception {
    // Construct the client used to interact with CDAP
    ServiceClient serviceClient = new ServiceClient(clientConfig);
    // Fetch service information using the service in the PurchaseApp example
    ServiceSpecification serviceSpec = serviceClient.get(NamespaceId.DEFAULT.app("PurchaseApp").service("CatalogLookup"));
}
Also used : ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) ServiceClient(io.cdap.cdap.client.ServiceClient)

Example 25 with ServiceSpecification

use of io.cdap.cdap.api.service.ServiceSpecification in project cdap by caskdata.

the class DefaultStoreTest method testServiceInstances.

@Test
public void testServiceInstances() {
    ApplicationSpecification appSpec = Specifications.from(new AppWithServices());
    ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
    store.addApplication(appId, appSpec);
    // Test setting of service instances
    ProgramId programId = appId.program(ProgramType.SERVICE, "NoOpService");
    int count = store.getServiceInstances(programId);
    Assert.assertEquals(1, count);
    store.setServiceInstances(programId, 10);
    count = store.getServiceInstances(programId);
    Assert.assertEquals(10, count);
    ApplicationSpecification newSpec = store.getApplication(appId);
    Assert.assertNotNull(newSpec);
    Map<String, ServiceSpecification> services = newSpec.getServices();
    Assert.assertEquals(1, services.size());
    ServiceSpecification serviceSpec = services.get("NoOpService");
    Assert.assertEquals(10, serviceSpec.getInstances());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) AppWithServices(io.cdap.cdap.AppWithServices) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Aggregations

ServiceSpecification (io.cdap.cdap.api.service.ServiceSpecification)34 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)16 HttpServiceHandlerSpecification (io.cdap.cdap.api.service.http.HttpServiceHandlerSpecification)10 JsonObject (com.google.gson.JsonObject)6 ProgramType (io.cdap.cdap.proto.ProgramType)6 ProgramId (io.cdap.cdap.proto.id.ProgramId)6 Test (org.junit.Test)6 Resources (io.cdap.cdap.api.Resources)4 MapReduceSpecification (io.cdap.cdap.api.mapreduce.MapReduceSpecification)4 Plugin (io.cdap.cdap.api.plugin.Plugin)4 ServiceHttpEndpoint (io.cdap.cdap.api.service.http.ServiceHttpEndpoint)4 SparkSpecification (io.cdap.cdap.api.spark.SparkSpecification)4 ForwardingApplicationSpecification (io.cdap.cdap.internal.app.ForwardingApplicationSpecification)4 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)4 HttpResponse (io.cdap.common.http.HttpResponse)4 ImmutableList (com.google.common.collect.ImmutableList)2 TypeToken (com.google.common.reflect.TypeToken)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 AppWithServices (io.cdap.cdap.AppWithServices)2