use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ApplicationLifecycleService method deleteMetrics.
/**
* Delete the metrics for an application.
*
* @param applicationId the application to delete metrics for.
*/
private void deleteMetrics(ApplicationId applicationId) throws Exception {
ApplicationSpecification spec = this.store.getApplication(applicationId);
long endTs = System.currentTimeMillis() / 1000;
Map<String, String> tags = Maps.newHashMap();
tags.put(Constants.Metrics.Tag.NAMESPACE, applicationId.getNamespace());
// add or replace application name in the tagMap
tags.put(Constants.Metrics.Tag.APP, spec.getName());
MetricDeleteQuery deleteQuery = new MetricDeleteQuery(0, endTs, tags);
metricStore.delete(deleteQuery);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ApplicationLifecycleService method getAppDetail.
/**
* Get detail about the specified application
*
* @param appId the id of the application to get
* @return detail about the specified application
* @throws ApplicationNotFoundException if the specified application does not exist
*/
public ApplicationDetail getAppDetail(ApplicationId appId) throws Exception {
// TODO: CDAP-12473: filter based on the entity visibility in the app detail
// user needs to pass the visibility check to get the app detail
AuthorizationUtil.ensureAccess(appId, authorizationEnforcer, authenticationContext.getPrincipal());
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
String ownerPrincipal = ownerAdmin.getOwnerPrincipal(appId);
return filterApplicationDetail(appId, ApplicationDetail.fromSpec(appSpec, ownerPrincipal));
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ApplicationLifecycleService method updateAppAllowed.
/**
* To determine whether the app version is allowed to be deployed
*
* @param appId the id of the application to be determined
* @return whether the app version is allowed to be deployed
*/
public boolean updateAppAllowed(ApplicationId appId) throws Exception {
AuthorizationUtil.ensureAccess(appId, authorizationEnforcer, authenticationContext.getPrincipal());
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
// App does not exist. Allow to create a new one
return true;
}
String version = appId.getVersion();
return version.endsWith(ApplicationId.DEFAULT_VERSION);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ProgramLifecycleService method getProgramSpecification.
/**
* Returns the {@link ProgramSpecification} for the specified {@link ProgramId program}.
*
* @param programId the {@link ProgramId program} for which the {@link ProgramSpecification} is requested
* @return the {@link ProgramSpecification} for the specified {@link ProgramId program}
*/
@Nullable
public ProgramSpecification getProgramSpecification(ProgramId programId) throws Exception {
AuthorizationUtil.ensureOnePrivilege(programId, EnumSet.allOf(Action.class), authorizationEnforcer, authenticationContext.getPrincipal());
ApplicationSpecification appSpec;
appSpec = store.getApplication(programId.getParent());
if (appSpec == null) {
return null;
}
return getExistingAppProgramSpecification(appSpec, programId);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ProgramLifecycleService method isRunningInSameProgram.
/**
* Returns whether the given program is running in any versions of the app.
* @param programId the id of the program for which the running status in all versions of the app is found
* @return whether the given program is running in any versions of the app
* @throws NotFoundException if the application to which this program belongs was not found
*/
private boolean isRunningInSameProgram(ProgramId programId) throws Exception {
// check that app exists
Collection<ApplicationId> appIds = store.getAllAppVersionsAppIds(programId.getParent());
if (appIds == null) {
throw new NotFoundException(Id.Application.from(programId.getNamespace(), programId.getApplication()));
}
ApplicationSpecification appSpec = store.getApplication(programId.getParent());
for (ApplicationId appId : appIds) {
ProgramId pId = appId.program(programId.getType(), programId.getProgram());
if (getExistingAppProgramStatus(appSpec, pId).equals(ProgramStatus.RUNNING)) {
return true;
}
}
return false;
}
Aggregations