use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStore method getWorkerInstances.
@Override
public int getWorkerInstances(ProgramId id) {
return Transactionals.execute(transactional, context -> {
ApplicationSpecification appSpec = getAppSpecOrFail(getAppMetadataStore(context), id);
WorkerSpecification workerSpec = getWorkerSpecOrFail(id, appSpec);
return workerSpec.getInstances();
});
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStore method setWorkerInstances.
@Override
public void setWorkerInstances(ProgramId id, int instances) {
Preconditions.checkArgument(instances > 0, "Cannot change number of worker instances to %s", instances);
Transactionals.execute(transactional, context -> {
AppMetadataStore metaStore = getAppMetadataStore(context);
ApplicationSpecification appSpec = getAppSpecOrFail(metaStore, id);
WorkerSpecification workerSpec = getWorkerSpecOrFail(id, appSpec);
WorkerSpecification newSpecification = new WorkerSpecification(workerSpec.getClassName(), workerSpec.getName(), workerSpec.getDescription(), workerSpec.getProperties(), workerSpec.getDatasets(), workerSpec.getResources(), instances);
ApplicationSpecification newAppSpec = replaceWorkerInAppSpec(appSpec, id, newSpecification);
metaStore.updateAppSpec(id.getNamespace(), id.getApplication(), id.getVersion(), newAppSpec);
});
LOG.trace("Setting program instances: namespace: {}, application: {}, worker: {}, new instances count: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), instances);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStore method getFlowletInstances.
@Override
public int getFlowletInstances(ProgramId id, String flowletId) {
return Transactionals.execute(transactional, context -> {
ApplicationSpecification appSpec = getAppSpecOrFail(getAppMetadataStore(context), id);
FlowSpecification flowSpec = getFlowSpecOrFail(id, appSpec);
FlowletDefinition flowletDef = getFlowletDefinitionOrFail(flowSpec, flowletId, id);
return flowletDef.getInstances();
});
}
use of co.cask.cdap.api.app.ApplicationSpecification 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);
Transactionals.execute(transactional, 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);
ApplicationSpecification newAppSpec = replaceServiceSpec(appSpec, id.getProgram(), serviceSpec);
metaStore.updateAppSpec(id.getNamespace(), id.getApplication(), id.getVersion(), newAppSpec);
});
LOG.trace("Setting program instances: namespace: {}, application: {}, service: {}, new instances count: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), instances);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ApplicationLifecycleService method getApps.
/**
* Get all applications in the specified namespace that satisfy the specified predicate.
*
* @param namespace the namespace to get apps from
* @param predicate the predicate that must be satisfied in order to be returned
* @return list of all applications in the namespace that satisfy the specified predicate
*/
public List<ApplicationRecord> getApps(final NamespaceId namespace, com.google.common.base.Predicate<ApplicationRecord> predicate) throws Exception {
List<ApplicationRecord> appRecords = new ArrayList<>();
Map<ApplicationId, ApplicationSpecification> appSpecs = new HashMap<>();
for (ApplicationSpecification appSpec : store.getAllApplications(namespace)) {
appSpecs.put(namespace.app(appSpec.getName(), appSpec.getAppVersion()), appSpec);
}
appSpecs.keySet().retainAll(authorizationEnforcer.isVisible(appSpecs.keySet(), authenticationContext.getPrincipal()));
for (ApplicationId appId : appSpecs.keySet()) {
ApplicationSpecification appSpec = appSpecs.get(appId);
if (appSpec == null) {
continue;
}
// possible if this particular app was deploy prior to v3.2 and upgrade failed for some reason.
ArtifactId artifactId = appSpec.getArtifactId();
ArtifactSummary artifactSummary = artifactId == null ? new ArtifactSummary(appSpec.getName(), null) : ArtifactSummary.from(artifactId);
ApplicationRecord record = new ApplicationRecord(artifactSummary, appId, appSpec.getDescription(), ownerAdmin.getOwnerPrincipal(appId));
if (predicate.apply(record)) {
appRecords.add(record);
}
}
return appRecords;
}
Aggregations