Search in sources :

Example 6 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.

the class DeletedProgramHandlerStage method process.

@Override
public void process(ApplicationDeployable appSpec) throws Exception {
    List<ProgramSpecification> deletedSpecs = store.getDeletedProgramSpecifications(appSpec.getApplicationId(), appSpec.getSpecification());
    // TODO: this should also delete logs and run records (or not?), and do it for all program types [CDAP-2187]
    Set<ProgramId> deletedPrograms = new HashSet<>();
    for (ProgramSpecification spec : deletedSpecs) {
        // call the deleted spec
        ProgramType type = ProgramTypes.fromSpecification(spec);
        ProgramId programId = appSpec.getApplicationId().program(type, spec.getName());
        programTerminator.stop(programId);
        programScheduler.deleteSchedules(programId);
        programScheduler.modifySchedulesTriggeredByDeletedProgram(programId);
        // Remove metadata for the deleted program
        metadataServiceClient.drop(new MetadataMutation.Drop(programId.toMetadataEntity()));
        deletedPrograms.add(programId);
    }
    deleteMetrics(deletedPrograms);
    emit(appSpec);
}
Also used : MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramId(io.cdap.cdap.proto.id.ProgramId) HashSet(java.util.HashSet)

Example 7 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.

the class ProgramLifecycleService method getExistingAppProgramSpecification.

/**
 * Returns the {@link ProgramSpecification} for the specified {@link ProgramId program}.
 * @param appSpec the {@link ApplicationSpecification} of the existing application
 * @param programId the {@link ProgramId program} for which the {@link ProgramSpecification} is requested
 * @return the {@link ProgramSpecification} for the specified {@link ProgramId program}, or {@code null} if it does
 *         not exist
 */
@Nullable
private ProgramSpecification getExistingAppProgramSpecification(ApplicationSpecification appSpec, ProgramId programId) {
    String programName = programId.getProgram();
    ProgramType type = programId.getType();
    ProgramSpecification programSpec;
    if (type == ProgramType.MAPREDUCE && appSpec.getMapReduce().containsKey(programName)) {
        programSpec = appSpec.getMapReduce().get(programName);
    } else if (type == ProgramType.SPARK && appSpec.getSpark().containsKey(programName)) {
        programSpec = appSpec.getSpark().get(programName);
    } else if (type == ProgramType.WORKFLOW && appSpec.getWorkflows().containsKey(programName)) {
        programSpec = appSpec.getWorkflows().get(programName);
    } else if (type == ProgramType.SERVICE && appSpec.getServices().containsKey(programName)) {
        programSpec = appSpec.getServices().get(programName);
    } else if (type == ProgramType.WORKER && appSpec.getWorkers().containsKey(programName)) {
        programSpec = appSpec.getWorkers().get(programName);
    } else {
        programSpec = null;
    }
    return programSpec;
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ProgramType(io.cdap.cdap.proto.ProgramType) Nullable(javax.annotation.Nullable)

Example 8 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.

the class ProgramLifecycleService method createProgramOptions.

@VisibleForTesting
ProgramOptions createProgramOptions(ProgramId programId, Map<String, String> userArgs, Map<String, String> sysArgs, boolean debug) throws NotFoundException, ProfileConflictException {
    ProfileId profileId = SystemArguments.getProfileIdForProgram(programId, userArgs);
    Map<String, String> profileProperties = SystemArguments.getProfileProperties(userArgs);
    Profile profile = profileService.getProfile(profileId, profileProperties);
    if (profile.getStatus() == ProfileStatus.DISABLED) {
        throw new ProfileConflictException(String.format("Profile %s in namespace %s is disabled. It cannot be " + "used to start the program %s", profileId.getProfile(), profileId.getNamespace(), programId.toString()), profileId);
    }
    ProvisionerDetail spec = provisioningService.getProvisionerDetail(profile.getProvisioner().getName());
    if (spec == null) {
        throw new NotFoundException(String.format("Provisioner '%s' not found.", profile.getProvisioner().getName()));
    }
    // get and add any user overrides for profile properties
    Map<String, String> systemArgs = new HashMap<>(sysArgs);
    // add profile properties to the system arguments
    SystemArguments.addProfileArgs(systemArgs, profile);
    // Set the ClusterMode. If it is NATIVE profile, then it is ON_PREMISE, otherwise is ISOLATED
    // This should probably move into the provisioner later once we have a better contract for the
    // provisioner to actually pick what launching mechanism it wants to use.
    systemArgs.put(ProgramOptionConstants.CLUSTER_MODE, (ProfileId.NATIVE.equals(profileId) ? ClusterMode.ON_PREMISE : ClusterMode.ISOLATED).name());
    ProgramSpecification programSpecification = getProgramSpecificationWithoutAuthz(programId);
    if (programSpecification == null) {
        throw new NotFoundException(programId);
    }
    addAppCDAPVersion(programId, systemArgs);
    // put all the plugin requirements if any involved in the run
    systemArgs.put(ProgramOptionConstants.PLUGIN_REQUIREMENTS, GSON.toJson(getPluginRequirements(programSpecification)));
    return new SimpleProgramOptions(programId, new BasicArguments(systemArgs), new BasicArguments(userArgs), debug);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) HashMap(java.util.HashMap) NotFoundException(io.cdap.cdap.common.NotFoundException) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) Profile(io.cdap.cdap.proto.profile.Profile) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.

the class ProgramLifecycleService method getRunRecordMetas.

/**
 * Get the latest runs within the specified start and end times for the specified program.
 *
 * @param programId the program to get runs for
 * @param programRunStatus status of runs to return
 * @param start earliest start time of runs to return
 * @param end latest start time of runs to return
 * @param limit the maximum number of runs to return
 * @return the latest runs for the program sorted by start time, with the newest run as the first run
 * @throws NotFoundException if the application to which this program belongs was not found or the program is not
 *                           found in the app
 * @throws UnauthorizedException if the principal does not have access to the program
 * @throws Exception if there was some other exception performing authorization checks
 */
public List<RunRecordDetail> getRunRecordMetas(ProgramId programId, ProgramRunStatus programRunStatus, long start, long end, int limit) throws Exception {
    accessEnforcer.enforce(programId, authenticationContext.getPrincipal(), StandardPermission.GET);
    ProgramSpecification programSpec = getProgramSpecificationWithoutAuthz(programId);
    if (programSpec == null) {
        throw new NotFoundException(programId);
    }
    return store.getRuns(programId, programRunStatus, start, end, limit).values().stream().collect(Collectors.toList());
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 10 with ProgramSpecification

use of io.cdap.cdap.api.ProgramSpecification in project cdap by caskdata.

the class ApplicationDetail method fromSpec.

public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
    List<ProgramRecord> programs = new ArrayList<>();
    for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
        programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getServices().values()) {
        programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getSpark().values()) {
        programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkers().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    List<DatasetDetail> datasets = new ArrayList<>();
    for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
        datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
    }
    List<PluginDetail> plugins = new ArrayList<>();
    for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
        plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
    }
    // this is only required if there are old apps lying around that failed to get upgrading during
    // the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
    // in the meantime, we don't want this api call to null pointer exception.
    ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
    return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), datasets, programs, plugins, summary, ownerPrincipal);
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ArrayList(java.util.ArrayList) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) DatasetCreationSpec(io.cdap.cdap.internal.dataset.DatasetCreationSpec) Map(java.util.Map) Plugin(io.cdap.cdap.api.plugin.Plugin)

Aggregations

ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)32 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)12 NotFoundException (io.cdap.cdap.common.NotFoundException)12 ProgramType (io.cdap.cdap.proto.ProgramType)8 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)8 ProgramId (io.cdap.cdap.proto.id.ProgramId)8 Test (org.junit.Test)6 AllProgramsApp (io.cdap.cdap.AllProgramsApp)4 ForwardingApplicationSpecification (io.cdap.cdap.internal.app.ForwardingApplicationSpecification)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AppWithNoServices (io.cdap.cdap.AppWithNoServices)2 AppWithServices (io.cdap.cdap.AppWithServices)2 DefaultStoreTestApp (io.cdap.cdap.DefaultStoreTestApp)2 NoProgramsApp (io.cdap.cdap.NoProgramsApp)2 AbstractApplication (io.cdap.cdap.api.app.AbstractApplication)2 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)2 Plugin (io.cdap.cdap.api.plugin.Plugin)2 WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)2