Search in sources :

Example 11 with BasicArguments

use of io.cdap.cdap.internal.app.runtime.BasicArguments in project cdap by caskdata.

the class MapReduceWithMultipleInputsTest method testMapperOutputTypeChecking.

@Test
public void testMapperOutputTypeChecking() throws Exception {
    final ApplicationWithPrograms app = deployApp(AppWithMapReduceUsingInconsistentMappers.class);
    // the mapreduce with consistent mapper types will succeed
    Assert.assertTrue(runProgram(app, AppWithMapReduceUsingInconsistentMappers.MapReduceWithConsistentMapperTypes.class, new BasicArguments()));
    // the mapreduce with mapper classes of inconsistent output types will fail, whether the mappers are set through
    // CDAP APIs or also directly on the job
    Assert.assertFalse(runProgram(app, AppWithMapReduceUsingInconsistentMappers.MapReduceWithInconsistentMapperTypes.class, new BasicArguments()));
    Assert.assertFalse(runProgram(app, AppWithMapReduceUsingInconsistentMappers.MapReduceWithInconsistentMapperTypes2.class, new BasicArguments()));
}
Also used : ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Test(org.junit.Test)

Example 12 with BasicArguments

use of io.cdap.cdap.internal.app.runtime.BasicArguments in project cdap by caskdata.

the class MapReduceWithMultipleInputsTest method testAddingMultipleInputsWithSameAlias.

@Test
public void testAddingMultipleInputsWithSameAlias() throws Exception {
    final ApplicationWithPrograms app = deployApp(AppWithMapReduceUsingMultipleInputs.class);
    // will fail because it configured two inputs with the same alias
    Assert.assertFalse(runProgram(app, AppWithMapReduceUsingMultipleInputs.InvalidMapReduce.class, new BasicArguments()));
}
Also used : ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Test(org.junit.Test)

Example 13 with BasicArguments

use of io.cdap.cdap.internal.app.runtime.BasicArguments in project cdap by caskdata.

the class MapReduceConfigTest method testConfigIsolation.

@Test
public void testConfigIsolation() throws Exception {
    ApplicationWithPrograms app = deployApp(AppWithSingleInputOutput.class);
    Assert.assertTrue(runProgram(app, AppWithSingleInputOutput.SimpleMapReduce.class, new BasicArguments()));
}
Also used : ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Test(org.junit.Test)

Example 14 with BasicArguments

use of io.cdap.cdap.internal.app.runtime.BasicArguments in project cdap by caskdata.

the class AbstractProgramRuntimeService method updateProgramOptions.

/**
 * Updates the given {@link ProgramOptions} and return a new instance.
 * It copies the {@link ProgramOptions}. Then it adds all entries returned by {@link #getExtraProgramOptions()}
 * followed by adding the {@link RunId} to the system arguments.
 *
 * Also scope resolution will be performed on the user arguments on the application and program.
 *
 * @param programId the program id
 * @param options The {@link ProgramOptions} in which the RunId to be included
 * @param runId   The RunId to be included
 * @param clusterMode clustermode for the program run
 * @param applicationClass application class for the program
 * @return the copy of the program options with RunId included in them
 */
private ProgramOptions updateProgramOptions(ArtifactId artifactId, ProgramId programId, ProgramOptions options, RunId runId, ClusterMode clusterMode, ApplicationClass applicationClass) {
    // Build the system arguments
    Map<String, String> systemArguments = new HashMap<>(options.getArguments().asMap());
    // this can happen if this is a program within a workflow, and the workflow already added these arguments
    for (Map.Entry<String, String> extraOption : getExtraProgramOptions().entrySet()) {
        systemArguments.putIfAbsent(extraOption.getKey(), extraOption.getValue());
    }
    systemArguments.putIfAbsent(ProgramOptionConstants.RUN_ID, runId.getId());
    systemArguments.putIfAbsent(ProgramOptionConstants.ARTIFACT_ID, Joiner.on(':').join(artifactId.toIdParts()));
    if (clusterMode == ClusterMode.ISOLATED) {
        systemArguments.putIfAbsent(ProgramOptionConstants.APPLICATION_CLASS, applicationClass.getClassName());
    }
    // Resolves the user arguments
    // First resolves at the cluster scope if the cluster.name is not empty
    String clusterName = options.getArguments().getOption(Constants.CLUSTER_NAME);
    Map<String, String> userArguments = options.getUserArguments().asMap();
    if (!Strings.isNullOrEmpty(clusterName)) {
        userArguments = RuntimeArguments.extractScope(CLUSTER_SCOPE, clusterName, userArguments);
    }
    // Then resolves at the application scope
    userArguments = RuntimeArguments.extractScope(APPLICATION_SCOPE, programId.getApplication(), userArguments);
    // Then resolves at the program level
    userArguments = RuntimeArguments.extractScope(programId.getType().getScope(), programId.getProgram(), userArguments);
    return new SimpleProgramOptions(options.getProgramId(), new BasicArguments(systemArguments), new BasicArguments(userArguments), options.isDebug());
}
Also used : HashMap(java.util.HashMap) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 15 with BasicArguments

use of io.cdap.cdap.internal.app.runtime.BasicArguments in project cdap by caskdata.

the class ProgramOptions method fromNotification.

/**
 * Decodes {@link ProgramOptions} from a {@link Notification} object, based on the
 * {@link Notification.Type#PROGRAM_STATUS} type.
 */
static ProgramOptions fromNotification(Notification notification, Gson gson) {
    Map<String, String> properties = notification.getProperties();
    ProgramId programId = gson.fromJson(properties.get(ProgramOptionConstants.PROGRAM_RUN_ID), ProgramRunId.class).getParent();
    String userArgumentsString = properties.get(ProgramOptionConstants.USER_OVERRIDES);
    String systemArgumentsString = properties.get(ProgramOptionConstants.SYSTEM_OVERRIDES);
    String debugString = properties.get(ProgramOptionConstants.DEBUG_ENABLED);
    Type stringStringMap = new TypeToken<Map<String, String>>() {
    }.getType();
    boolean debug = Boolean.parseBoolean(debugString);
    Map<String, String> userArguments = userArgumentsString == null ? Collections.emptyMap() : gson.fromJson(userArgumentsString, stringStringMap);
    Map<String, String> systemArguments = systemArgumentsString == null ? Collections.emptyMap() : gson.fromJson(systemArgumentsString, stringStringMap);
    return new SimpleProgramOptions(programId, new BasicArguments(systemArguments), new BasicArguments(userArguments), debug);
}
Also used : Type(java.lang.reflect.Type) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramId(io.cdap.cdap.proto.id.ProgramId) Map(java.util.Map)

Aggregations

BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)90 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)54 Test (org.junit.Test)44 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)36 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)32 ApplicationWithPrograms (io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms)32 HashMap (java.util.HashMap)32 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)28 ProgramId (io.cdap.cdap.proto.id.ProgramId)24 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)22 SystemArguments (io.cdap.cdap.internal.app.runtime.SystemArguments)20 ImmutableMap (com.google.common.collect.ImmutableMap)18 Map (java.util.Map)18 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)16 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)16 IOException (java.io.IOException)16 Injector (com.google.inject.Injector)14 Collections (java.util.Collections)14 ProgramController (io.cdap.cdap.app.runtime.ProgramController)12 RunIds (io.cdap.cdap.common.app.RunIds)12