Search in sources :

Example 81 with ApplicationSpecification

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);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) MetricDeleteQuery(co.cask.cdap.api.metrics.MetricDeleteQuery)

Example 82 with ApplicationSpecification

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));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException)

Example 83 with ApplicationSpecification

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);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification)

Example 84 with ApplicationSpecification

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);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) Action(co.cask.cdap.proto.security.Action) Nullable(javax.annotation.Nullable)

Example 85 with ApplicationSpecification

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;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId)

Aggregations

ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)104 ApplicationId (co.cask.cdap.proto.id.ApplicationId)47 ProgramId (co.cask.cdap.proto.id.ProgramId)28 Test (org.junit.Test)27 ProgramType (co.cask.cdap.proto.ProgramType)22 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)16 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)15 NotFoundException (co.cask.cdap.common.NotFoundException)14 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)12 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)12 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)11 NamespaceId (co.cask.cdap.proto.id.NamespaceId)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)9 WordCountApp (co.cask.cdap.WordCountApp)8 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)8 IOException (java.io.IOException)8 RunId (org.apache.twill.api.RunId)8 Map (java.util.Map)7