Search in sources :

Example 1 with ServiceSpecification

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

the class DistributedServiceProgramRunner method setupLaunchConfig.

@Override
protected void setupLaunchConfig(ProgramLaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) {
    ApplicationSpecification appSpec = program.getApplicationSpecification();
    ServiceSpecification serviceSpec = appSpec.getServices().get(program.getName());
    // Add a runnable for the service handler
    launchConfig.addRunnable(serviceSpec.getName(), new ServiceTwillRunnable(serviceSpec.getName()), serviceSpec.getInstances(), options.getUserArguments().asMap(), serviceSpec.getResources());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification)

Example 2 with ServiceSpecification

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

the class DistributedServiceProgramRunner method validateOptions.

@Override
protected void validateOptions(Program program, ProgramOptions options) {
    super.validateOptions(program, 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());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) ProgramType(io.cdap.cdap.proto.ProgramType)

Example 3 with ServiceSpecification

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

the class ServiceClient method get.

/**
 * Gets a {@link ServiceSpecification} for a {@link Service}.
 *
 * @param service ID of the service
 * @return {@link ServiceSpecification} representing the service
 * @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 ServiceSpecification get(ProgramId service) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s", service.getApplication(), service.getVersion(), service.getProgram()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(service);
    }
    return ObjectResponse.fromJsonBody(response, ServiceSpecification.class).getResponseObject();
}
Also used : ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Example 4 with ServiceSpecification

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

the class DefaultAppConfigurer method addService.

@Override
public void addService(Service service) {
    Preconditions.checkArgument(service != null, "Service cannot be null.");
    // check that a system service is only used in system namespace
    if (!deployNamespace.equals(Id.Namespace.fromEntityId(NamespaceId.SYSTEM))) {
        TypeToken<?> type = TypeToken.of(service.getClass()).resolveType(Service.class.getTypeParameters()[0]);
        if (SystemServiceConfigurer.class.isAssignableFrom(type.getRawType())) {
            throw new IllegalArgumentException(String.format("Invalid service '%s'. Services can only use a SystemServiceConfigurer if the application is " + "deployed in the system namespace.", service.getClass().getSimpleName()));
        }
    }
    DefaultSystemTableConfigurer systemTableConfigurer = new DefaultSystemTableConfigurer();
    DefaultServiceConfigurer configurer = new DefaultServiceConfigurer(service, deployNamespace, artifactId, pluginFinder, pluginInstantiator, systemTableConfigurer, runtimeInfo, getFeatureFlagsProvider());
    service.configure(configurer);
    ServiceSpecification spec = configurer.createSpecification();
    addDatasetsAndPlugins(configurer);
    addSystemTableSpecs(systemTableConfigurer.getTableSpecs());
    services.put(spec.getName(), spec);
}
Also used : ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) DefaultSystemTableConfigurer(io.cdap.cdap.internal.app.services.DefaultSystemTableConfigurer) DefaultServiceConfigurer(io.cdap.cdap.internal.app.services.DefaultServiceConfigurer)

Example 5 with ServiceSpecification

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

the class DefaultStore method setServiceInstances.

@Override
public void setServiceInstances(ProgramId id, int instances) {
    Preconditions.checkArgument(instances > 0, "Cannot change number of service instances to %s", instances);
    TransactionRunners.run(transactionRunner, context -> {
        AppMetadataStore metaStore = getAppMetadataStore(context);
        ApplicationSpecification appSpec = getAppSpecOrFail(metaStore, id);
        ServiceSpecification serviceSpec = getServiceSpecOrFail(id, appSpec);
        // Create a new spec copy from the old one, except with updated instances number
        serviceSpec = new ServiceSpecification(serviceSpec.getClassName(), serviceSpec.getName(), serviceSpec.getDescription(), serviceSpec.getHandlers(), serviceSpec.getResources(), instances, serviceSpec.getPlugins());
        ApplicationSpecification newAppSpec = replaceServiceSpec(appSpec, id.getProgram(), serviceSpec);
        metaStore.updateAppSpec(id.getParent(), newAppSpec);
    });
    LOG.trace("Setting program instances: namespace: {}, application: {}, service: {}, new instances count: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), instances);
}
Also used : ForwardingApplicationSpecification(io.cdap.cdap.internal.app.ForwardingApplicationSpecification) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification)

Aggregations

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