Search in sources :

Example 6 with HttpServiceHandlerSpecification

use of co.cask.cdap.api.service.http.HttpServiceHandlerSpecification in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testServiceSpecification.

@Test
public void testServiceSpecification() throws Exception {
    deploy(AppWithServices.class);
    HttpResponse response = doGet("/v3/namespaces/default/apps/AppWithServices/services/NoOpService");
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Set<ServiceHttpEndpoint> expectedEndpoints = ImmutableSet.of(new ServiceHttpEndpoint("GET", "/ping"), new ServiceHttpEndpoint("POST", "/multi"), new ServiceHttpEndpoint("GET", "/multi"), new ServiceHttpEndpoint("GET", "/multi/ping"));
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(ServiceSpecification.class, new ServiceSpecificationCodec());
    Gson gson = gsonBuilder.create();
    ServiceSpecification specification = readResponse(response, ServiceSpecification.class, gson);
    Set<ServiceHttpEndpoint> returnedEndpoints = new HashSet<>();
    for (HttpServiceHandlerSpecification httpServiceHandlerSpecification : specification.getHandlers().values()) {
        returnedEndpoints.addAll(httpServiceHandlerSpecification.getEndpoints());
    }
    Assert.assertEquals("NoOpService", specification.getName());
    Assert.assertTrue(returnedEndpoints.equals(expectedEndpoints));
}
Also used : ServiceHttpEndpoint(co.cask.cdap.api.service.http.ServiceHttpEndpoint) ServiceSpecificationCodec(co.cask.cdap.internal.app.ServiceSpecificationCodec) ServiceSpecification(co.cask.cdap.api.service.ServiceSpecification) GsonBuilder(com.google.gson.GsonBuilder) HttpResponse(org.apache.http.HttpResponse) Gson(com.google.gson.Gson) HttpServiceHandlerSpecification(co.cask.cdap.api.service.http.HttpServiceHandlerSpecification) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with HttpServiceHandlerSpecification

use of co.cask.cdap.api.service.http.HttpServiceHandlerSpecification in project cdap by caskdata.

the class ServiceClient method getEndpoints.

/**
   * Gets a list of {@link ServiceHttpEndpoint} that a {@link Service} exposes.
   *
   * @param service ID of the service
   * @return A list of {@link ServiceHttpEndpoint}
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   * @throws NotFoundException if the app or service could not be found
   */
public List<ServiceHttpEndpoint> getEndpoints(ServiceId service) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    ServiceSpecification specification = get(service);
    ImmutableList.Builder<ServiceHttpEndpoint> builder = new ImmutableList.Builder<>();
    for (HttpServiceHandlerSpecification handlerSpecification : specification.getHandlers().values()) {
        builder.addAll(handlerSpecification.getEndpoints());
    }
    return builder.build();
}
Also used : ServiceHttpEndpoint(co.cask.cdap.api.service.http.ServiceHttpEndpoint) ServiceSpecification(co.cask.cdap.api.service.ServiceSpecification) ImmutableList(com.google.common.collect.ImmutableList) HttpServiceHandlerSpecification(co.cask.cdap.api.service.http.HttpServiceHandlerSpecification)

Example 8 with HttpServiceHandlerSpecification

use of co.cask.cdap.api.service.http.HttpServiceHandlerSpecification in project cdap by caskdata.

the class ApplicationRegistrationStage method registerDatasets.

// Register dataset usage, based upon the program specifications.
// Note that worker specifications' datasets are not registered upon app deploy because the useDataset of the
// WorkerConfigurer is deprecated. Workers' access to datasets is aimed to be completely dynamic. Other programs are
// moving in this direction.
// Also, SparkSpecifications are the same in that a Spark program's dataset access is completely dynamic.
private void registerDatasets(ApplicationWithPrograms input) {
    ApplicationSpecification appSpec = input.getSpecification();
    ApplicationId appId = input.getApplicationId();
    NamespaceId namespaceId = appId.getParent();
    for (FlowSpecification flow : appSpec.getFlows().values()) {
        ProgramId programId = appId.flow(flow.getName());
        for (FlowletConnection connection : flow.getConnections()) {
            if (connection.getSourceType().equals(FlowletConnection.Type.STREAM)) {
                usageRegistry.register(programId, namespaceId.stream(connection.getSourceName()));
            }
        }
        for (FlowletDefinition flowlet : flow.getFlowlets().values()) {
            for (String dataset : flowlet.getDatasets()) {
                usageRegistry.register(programId, namespaceId.dataset(dataset));
            }
        }
    }
    for (MapReduceSpecification program : appSpec.getMapReduce().values()) {
        ProgramId programId = appId.mr(program.getName());
        for (String dataset : program.getDataSets()) {
            usageRegistry.register(programId, namespaceId.dataset(dataset));
        }
    }
    for (SparkSpecification sparkSpec : appSpec.getSpark().values()) {
        ProgramId programId = appId.spark(sparkSpec.getName());
        for (String dataset : sparkSpec.getDatasets()) {
            usageRegistry.register(programId, namespaceId.dataset(dataset));
        }
    }
    for (ServiceSpecification serviceSpecification : appSpec.getServices().values()) {
        ProgramId programId = appId.service(serviceSpecification.getName());
        for (HttpServiceHandlerSpecification handlerSpecification : serviceSpecification.getHandlers().values()) {
            for (String dataset : handlerSpecification.getDatasets()) {
                usageRegistry.register(programId, namespaceId.dataset(dataset));
            }
        }
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) DefaultApplicationSpecification(co.cask.cdap.internal.app.DefaultApplicationSpecification) FlowletDefinition(co.cask.cdap.api.flow.FlowletDefinition) SparkSpecification(co.cask.cdap.api.spark.SparkSpecification) ServiceSpecification(co.cask.cdap.api.service.ServiceSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) FlowletConnection(co.cask.cdap.api.flow.FlowletConnection) MapReduceSpecification(co.cask.cdap.api.mapreduce.MapReduceSpecification) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) HttpServiceHandlerSpecification(co.cask.cdap.api.service.http.HttpServiceHandlerSpecification)

Aggregations

HttpServiceHandlerSpecification (co.cask.cdap.api.service.http.HttpServiceHandlerSpecification)8 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)5 ServiceHttpEndpoint (co.cask.cdap.api.service.http.ServiceHttpEndpoint)5 Resources (co.cask.cdap.api.Resources)2 HttpServiceHandler (co.cask.cdap.api.service.http.HttpServiceHandler)2 JsonObject (com.google.gson.JsonObject)2 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)1 FlowletConnection (co.cask.cdap.api.flow.FlowletConnection)1 FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)1 MapReduceSpecification (co.cask.cdap.api.mapreduce.MapReduceSpecification)1 SparkSpecification (co.cask.cdap.api.spark.SparkSpecification)1 InstantiatorFactory (co.cask.cdap.common.lang.InstantiatorFactory)1 DefaultApplicationSpecification (co.cask.cdap.internal.app.DefaultApplicationSpecification)1 ServiceSpecificationCodec (co.cask.cdap.internal.app.ServiceSpecificationCodec)1 DataSetFieldExtractor (co.cask.cdap.internal.specification.DataSetFieldExtractor)1 PropertyFieldExtractor (co.cask.cdap.internal.specification.PropertyFieldExtractor)1 ApplicationId (co.cask.cdap.proto.id.ApplicationId)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1