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());
}
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());
}
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();
}
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);
}
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);
}
Aggregations