Search in sources :

Example 26 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class CreateDatasetInstancesStage method process.

/**
 * Receives an input containing application specification and location
 * and verifies both.
 *
 * @param input An instance of {@link ApplicationDeployable}
 */
@Override
public void process(ApplicationDeployable input) throws Exception {
    // create dataset instances
    ApplicationSpecification specification = input.getSpecification();
    NamespaceId namespaceId = input.getApplicationId().getParent();
    KerberosPrincipalId ownerPrincipal = input.getOwnerPrincipal();
    // get the authorizing user
    String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, input.getApplicationId(), ownerPrincipal);
    datasetInstanceCreator.createInstances(namespaceId, specification.getDatasets(), ownerPrincipal, authorizingUser);
    // Emit the input to next stage.
    emit(input);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId)

Example 27 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class ProgramGenerationStage method process.

@Override
public void process(final ApplicationDeployable input) throws Exception {
    List<ProgramDescriptor> programDescriptors = new ArrayList<>();
    final ApplicationSpecification appSpec = input.getSpecification();
    // Now, we iterate through all ProgramSpecification and generate programs
    Iterable<ProgramSpecification> specifications = Iterables.concat(appSpec.getMapReduce().values(), appSpec.getWorkflows().values(), appSpec.getServices().values(), appSpec.getSpark().values(), appSpec.getWorkers().values());
    for (ProgramSpecification spec : specifications) {
        ProgramType type = ProgramTypes.fromSpecification(spec);
        ProgramId programId = input.getApplicationId().program(type, spec.getName());
        programDescriptors.add(new ProgramDescriptor(programId, appSpec));
    }
    emit(new ApplicationWithPrograms(input, programDescriptors));
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ArrayList(java.util.ArrayList) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 28 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class MapReduceContextConfigTest method testManyMacrosInAppSpec.

@Test
public void testManyMacrosInAppSpec() {
    Configuration hConf = new Configuration();
    MapReduceContextConfig cfg = new MapReduceContextConfig(hConf);
    StringBuilder appCfg = new StringBuilder();
    for (int i = 0; i < 100; i++) {
        appCfg.append("${").append(i).append("}");
        hConf.setInt(String.valueOf(i), i);
    }
    ApplicationSpecification appSpec = new DefaultApplicationSpecification("name", ProjectInfo.getVersion().toString(), "desc", appCfg.toString(), new ArtifactId("artifact", new ArtifactVersion("1.0.0"), ArtifactScope.USER), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    cfg.setApplicationSpecification(appSpec);
    Assert.assertEquals(appSpec.getConfiguration(), cfg.getApplicationSpecification().getConfiguration());
}
Also used : DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) Configuration(org.apache.hadoop.conf.Configuration) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) Test(org.junit.Test)

Example 29 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class AbstractProgramRuntimeService method run.

@Override
public final RuntimeInfo run(ProgramDescriptor programDescriptor, ProgramOptions options, RunId runId) {
    ProgramId programId = programDescriptor.getProgramId();
    ProgramRunId programRunId = programId.run(runId);
    ClusterMode clusterMode = ProgramRunners.getClusterMode(options);
    // Creates the ProgramRunner based on the cluster mode
    ProgramRunner runner = (clusterMode == ClusterMode.ON_PREMISE ? programRunnerFactory : Optional.ofNullable(remoteProgramRunnerFactory).orElseThrow(UnsupportedOperationException::new)).create(programId.getType());
    File tempDir = createTempDirectory(programId, runId);
    AtomicReference<Runnable> cleanUpTaskRef = new AtomicReference<>(createCleanupTask(tempDir, runner));
    DelayedProgramController controller = new DelayedProgramController(programRunId);
    RuntimeInfo runtimeInfo = createRuntimeInfo(controller, programId, () -> cleanUpTaskRef.get().run());
    updateRuntimeInfo(runtimeInfo);
    executor.execute(() -> {
        try {
            // Get the artifact details and save it into the program options.
            ArtifactId artifactId = programDescriptor.getArtifactId();
            ArtifactDetail artifactDetail = getArtifactDetail(artifactId);
            ApplicationSpecification appSpec = programDescriptor.getApplicationSpecification();
            ProgramDescriptor newProgramDescriptor = programDescriptor;
            boolean isPreview = Boolean.valueOf(options.getArguments().getOption(ProgramOptionConstants.IS_PREVIEW, "false"));
            // for preview we already have a resolved app spec, so no need to regenerate the app spec again
            if (!isPreview && appSpec != null && ClusterMode.ON_PREMISE.equals(clusterMode)) {
                try {
                    ApplicationSpecification generatedAppSpec = regenerateAppSpec(artifactDetail, programId, artifactId, appSpec, options);
                    appSpec = generatedAppSpec != null ? generatedAppSpec : appSpec;
                    newProgramDescriptor = new ProgramDescriptor(programDescriptor.getProgramId(), appSpec);
                } catch (Exception e) {
                    LOG.warn("Failed to regenerate the app spec for program {}, using the existing app spec", programId);
                }
            }
            ProgramOptions runtimeProgramOptions = updateProgramOptions(artifactId, programId, options, runId, clusterMode, Iterables.getFirst(artifactDetail.getMeta().getClasses().getApps(), null));
            // Take a snapshot of all the plugin artifacts used by the program
            ProgramOptions optionsWithPlugins = createPluginSnapshot(runtimeProgramOptions, programId, tempDir, newProgramDescriptor.getApplicationSpecification());
            // Create and run the program
            Program executableProgram = createProgram(cConf, runner, newProgramDescriptor, artifactDetail, tempDir);
            cleanUpTaskRef.set(createCleanupTask(cleanUpTaskRef.get(), executableProgram));
            controller.setProgramController(runner.run(executableProgram, optionsWithPlugins));
        } catch (Exception e) {
            controller.failed(e);
            programStateWriter.error(programRunId, e);
            LOG.error("Exception while trying to run program", e);
        }
    });
    return runtimeInfo;
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) Program(io.cdap.cdap.app.program.Program) AppDeploymentRuntimeInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo) SimpleRuntimeInfo(io.cdap.cdap.internal.app.runtime.service.SimpleRuntimeInfo) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProgramId(io.cdap.cdap.proto.id.ProgramId) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ExecutionException(java.util.concurrent.ExecutionException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) File(java.io.File) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)

Example 30 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class ProvisioningServiceTest method createTaskInfo.

private TaskFields createTaskInfo(ProvisionerInfo provisionerInfo) {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("wf").run(RunIds.generate());
    Map<String, String> systemArgs = new HashMap<>();
    Map<String, String> userArgs = new HashMap<>();
    Profile profile = new Profile(ProfileId.NATIVE.getProfile(), "label", "desc", provisionerInfo);
    SystemArguments.addProfileArgs(systemArgs, profile);
    systemArgs.put(Constants.APP_CDAP_VERSION, APP_CDAP_VERSION);
    ProgramOptions programOptions = new SimpleProgramOptions(programRunId.getParent(), new BasicArguments(systemArgs), new BasicArguments(userArgs));
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
    ApplicationSpecification appSpec = new DefaultApplicationSpecification("name", "1.0.0", APP_CDAP_VERSION, "desc", null, artifactId, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    ProgramDescriptor programDescriptor = new ProgramDescriptor(programRunId.getParent(), appSpec);
    return new TaskFields(programDescriptor, programOptions, programRunId);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HashMap(java.util.HashMap) Profile(io.cdap.cdap.proto.profile.Profile) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor)

Aggregations

ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)228 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)114 ProgramId (io.cdap.cdap.proto.id.ProgramId)90 Test (org.junit.Test)90 AllProgramsApp (io.cdap.cdap.AllProgramsApp)54 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)52 ProgramType (io.cdap.cdap.proto.ProgramType)50 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)40 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)38 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)32 NotFoundException (io.cdap.cdap.common.NotFoundException)30 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)28 Map (java.util.Map)28 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)24 IOException (java.io.IOException)24 HashSet (java.util.HashSet)22 RunId (org.apache.twill.api.RunId)22 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)20 DefaultApplicationSpecification (io.cdap.cdap.internal.app.DefaultApplicationSpecification)20