Search in sources :

Example 36 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class ApplicationLifecycleService method removeAll.

/**
 * Remove all the applications inside the given {@link Id.Namespace}
 *
 * @param namespaceId the {@link NamespaceId} under which all application should be deleted
 * @throws Exception
 */
public void removeAll(final NamespaceId namespaceId) throws Exception {
    Map<ProgramRunId, RunRecordMeta> runningPrograms = store.getActiveRuns(namespaceId);
    List<ApplicationSpecification> allSpecs = new ArrayList<>(store.getAllApplications(namespaceId));
    Map<ApplicationId, ApplicationSpecification> apps = new HashMap<>();
    for (ApplicationSpecification appSpec : allSpecs) {
        ApplicationId applicationId = namespaceId.app(appSpec.getName(), appSpec.getAppVersion());
        authorizationEnforcer.enforce(applicationId, authenticationContext.getPrincipal(), Action.ADMIN);
        apps.put(applicationId, appSpec);
    }
    if (!runningPrograms.isEmpty()) {
        Set<String> activePrograms = new HashSet<>();
        for (Map.Entry<ProgramRunId, RunRecordMeta> runningProgram : runningPrograms.entrySet()) {
            activePrograms.add(runningProgram.getKey().getApplication() + ": " + runningProgram.getKey().getProgram());
        }
        String appAllRunningPrograms = Joiner.on(',').join(activePrograms);
        throw new CannotBeDeletedException(namespaceId, "The following programs are still running: " + appAllRunningPrograms);
    }
    // All Apps are STOPPED, delete them
    for (ApplicationId appId : apps.keySet()) {
        removeAppInternal(appId, apps.get(appId));
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) HashMap(java.util.HashMap) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ArrayList(java.util.ArrayList) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Map(java.util.Map) HashMap(java.util.HashMap) CannotBeDeletedException(co.cask.cdap.common.CannotBeDeletedException) HashSet(java.util.HashSet)

Example 37 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class DefaultStore method getDeletedProgramSpecifications.

// todo: this method should be moved into DeletedProgramHandlerState, bad design otherwise
@Override
public List<ProgramSpecification> getDeletedProgramSpecifications(ApplicationId id, ApplicationSpecification appSpec) {
    ApplicationMeta existing = Transactionals.execute(transactional, context -> {
        return getAppMetadataStore(context).getApplication(id.getNamespace(), id.getApplication(), id.getVersion());
    });
    List<ProgramSpecification> deletedProgramSpecs = Lists.newArrayList();
    if (existing != null) {
        ApplicationSpecification existingAppSpec = existing.getSpec();
        Map<String, ProgramSpecification> existingSpec = ImmutableMap.<String, ProgramSpecification>builder().putAll(existingAppSpec.getMapReduce()).putAll(existingAppSpec.getSpark()).putAll(existingAppSpec.getWorkflows()).putAll(existingAppSpec.getFlows()).putAll(existingAppSpec.getServices()).putAll(existingAppSpec.getWorkers()).build();
        Map<String, ProgramSpecification> newSpec = ImmutableMap.<String, ProgramSpecification>builder().putAll(appSpec.getMapReduce()).putAll(appSpec.getSpark()).putAll(appSpec.getWorkflows()).putAll(appSpec.getFlows()).putAll(appSpec.getServices()).putAll(appSpec.getWorkers()).build();
        MapDifference<String, ProgramSpecification> mapDiff = Maps.difference(existingSpec, newSpec);
        deletedProgramSpecs.addAll(mapDiff.entriesOnlyOnLeft().values());
    }
    return deletedProgramSpecs;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ForwardingApplicationSpecification(co.cask.cdap.internal.app.ForwardingApplicationSpecification) ProgramSpecification(co.cask.cdap.api.ProgramSpecification)

Example 38 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class DefaultStore method setFlowletInstances.

@Override
public FlowSpecification setFlowletInstances(ProgramId id, String flowletId, int count) {
    Preconditions.checkArgument(count > 0, "Cannot change number of flowlet instances to %s", count);
    LOG.trace("Setting flowlet instances: namespace: {}, application: {}, flow: {}, flowlet: {}, " + "new instances count: {}", id.getNamespace(), id.getApplication(), id.getProgram(), flowletId, count);
    FlowSpecification flowSpec = Transactionals.execute(transactional, context -> {
        AppMetadataStore metaStore = getAppMetadataStore(context);
        ApplicationSpecification appSpec = getAppSpecOrFail(metaStore, id);
        ApplicationSpecification newAppSpec = updateFlowletInstancesInAppSpec(appSpec, id, flowletId, count);
        metaStore.updateAppSpec(id.getNamespace(), id.getApplication(), id.getVersion(), newAppSpec);
        return appSpec.getFlows().get(id.getProgram());
    });
    LOG.trace("Set flowlet instances: namespace: {}, application: {}, flow: {}, flowlet: {}, instances now: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), flowletId, count);
    return flowSpec;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ForwardingApplicationSpecification(co.cask.cdap.internal.app.ForwardingApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ForwardingFlowSpecification(co.cask.cdap.internal.app.ForwardingFlowSpecification)

Example 39 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class ProgramLifecycleService method getProgramStatus.

/**
 * Returns the program status.
 * @param programId the id of the program for which the status call is made
 * @return the status of the program
 * @throws NotFoundException if the application to which this program belongs was not found
 */
public ProgramStatus getProgramStatus(ProgramId programId) throws Exception {
    // check that app exists
    ApplicationId appId = programId.getParent();
    ApplicationSpecification appSpec = store.getApplication(appId);
    if (appSpec == null) {
        throw new NotFoundException(appId);
    }
    return getExistingAppProgramStatus(appSpec, programId);
}
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)

Example 40 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class ExistingEntitySystemMetadataWriter method writeSystemMetadataForApps.

private void writeSystemMetadataForApps(NamespaceId namespace) {
    for (ApplicationSpecification appSpec : store.getAllApplications(namespace)) {
        ApplicationId app = namespace.app(appSpec.getName());
        SystemMetadataWriter writer = new AppSystemMetadataWriter(metadataStore, app, appSpec);
        writer.write();
        writeSystemMetadataForPrograms(app, appSpec);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) DatasetSystemMetadataWriter(co.cask.cdap.data2.metadata.system.DatasetSystemMetadataWriter) ProgramSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ProgramSystemMetadataWriter) ViewSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ViewSystemMetadataWriter) SystemMetadataWriter(co.cask.cdap.data2.metadata.system.SystemMetadataWriter) AppSystemMetadataWriter(co.cask.cdap.data2.metadata.system.AppSystemMetadataWriter) ArtifactSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ArtifactSystemMetadataWriter) StreamSystemMetadataWriter(co.cask.cdap.data2.metadata.system.StreamSystemMetadataWriter) ApplicationId(co.cask.cdap.proto.id.ApplicationId) AppSystemMetadataWriter(co.cask.cdap.data2.metadata.system.AppSystemMetadataWriter)

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