Search in sources :

Example 1 with ArtifactVersion

use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.

the class RunnableTaskLauncherTest method testRunnableTaskRequestJsonConversion.

@Test
public void testRunnableTaskRequestJsonConversion() {
    ArtifactId artifactId = new ArtifactId("test-artifact", new ArtifactVersion("1.0"), ArtifactScope.SYSTEM);
    RunnableTaskRequest request = RunnableTaskRequest.getBuilder("taskClassName").withParam("param").withNamespace("n1").withArtifact(artifactId).build();
    Gson gson = new Gson();
    String requestJson = gson.toJson(request);
    RunnableTaskRequest requestFromJson = gson.fromJson(requestJson, RunnableTaskRequest.class);
    Assert.assertEquals(request.getClassName(), requestFromJson.getClassName());
    Assert.assertEquals(request.getNamespace(), requestFromJson.getNamespace());
    Assert.assertEquals(request.getParam(), requestFromJson.getParam());
    Assert.assertEquals(request.getArtifactId(), requestFromJson.getArtifactId());
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) Gson(com.google.gson.Gson) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 2 with ArtifactVersion

use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.

the class PipelinePhase method registerPlugins.

/**
 * Registers all the plugin to the given pluginConfigurer by calling {@link PluginConfigurer#usePluginClass(String,
 * String, String, PluginProperties, PluginSelector)}
 *
 * @param pluginConfigurer the {@link PluginConfigurer} to which the plugins in this {@link PipelinePhase} needs to be
 * registered
 * @param runtimeConfigurer the runtime configurer to provide runtime arguments to resolve macro better, null
 *                          if this is the initial deploy
 * @param namespace namespace the app is deployed
 */
public void registerPlugins(PluginConfigurer pluginConfigurer, @Nullable RuntimeConfigurer runtimeConfigurer, String namespace) {
    MacroParserOptions options = MacroParserOptions.builder().skipInvalidMacros().setEscaping(false).setFunctionWhitelist(ConnectionMacroEvaluator.FUNCTION_NAME).build();
    MacroEvaluator runtimeEvaluator = null;
    if (runtimeConfigurer != null) {
        Map<String, MacroEvaluator> evaluators = Collections.singletonMap(ConnectionMacroEvaluator.FUNCTION_NAME, new ConnectionMacroEvaluator(namespace, runtimeConfigurer));
        runtimeEvaluator = new DefaultMacroEvaluator(new BasicArguments(runtimeConfigurer.getRuntimeArguments()), evaluators, Collections.singleton(ConnectionMacroEvaluator.FUNCTION_NAME));
    }
    for (StageSpec stageSpec : stagesByName.values()) {
        // we don't need to register connectors only source, sink and transform plugins
        if (stageSpec.getPluginType().equals(Constants.Connector.PLUGIN_TYPE)) {
            continue;
        }
        PluginSpec pluginSpec = stageSpec.getPlugin();
        ArtifactVersion version = pluginSpec.getArtifact().getVersion();
        ArtifactSelector artifactSelector = new ArtifactSelector(pluginSpec.getArtifact().getScope(), pluginSpec.getArtifact().getName(), new ArtifactVersionRange(version, true, version, true));
        Map<String, String> prop = pluginSpec.getProperties();
        pluginConfigurer.usePluginClass(pluginSpec.getType(), pluginSpec.getName(), stageSpec.getName(), PluginProperties.builder().addAll(runtimeConfigurer == null ? prop : pluginConfigurer.evaluateMacros(prop, runtimeEvaluator, options)).build(), artifactSelector);
    }
}
Also used : MacroEvaluator(io.cdap.cdap.api.macro.MacroEvaluator) ArtifactVersionRange(io.cdap.cdap.api.artifact.ArtifactVersionRange) MacroParserOptions(io.cdap.cdap.api.macro.MacroParserOptions) PluginSpec(io.cdap.cdap.etl.proto.v2.spec.PluginSpec) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) StageSpec(io.cdap.cdap.etl.proto.v2.spec.StageSpec)

Example 3 with ArtifactVersion

use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.

the class BatchPhaseSpecTest method testDescription.

@Test
public void testDescription() throws Exception {
    /*
     * source1 --|
     *           |--> sink.connector
     * source2 --|
     */
    Map<String, String> props = new HashMap<>();
    PluginSpec connectorSpec = new PluginSpec(Constants.Connector.PLUGIN_TYPE, "connector", ImmutableMap.<String, String>of(), null);
    ArtifactId artifactId = new ArtifactId("art", new ArtifactVersion("1.0.0"), ArtifactScope.USER);
    PipelinePhase.Builder builder = PipelinePhase.builder(ImmutableSet.of(BatchSource.PLUGIN_TYPE, Constants.Connector.PLUGIN_TYPE)).addStage(StageSpec.builder("source1", new PluginSpec(BatchSource.PLUGIN_TYPE, "src", props, artifactId)).build()).addStage(StageSpec.builder("source2", new PluginSpec(BatchSource.PLUGIN_TYPE, "src", props, artifactId)).addInputSchema("a", Schema.recordOf("stuff", Schema.Field.of("x", Schema.of(Schema.Type.INT)))).build()).addStage(StageSpec.builder("sink.connector", connectorSpec).build()).addConnection("source1", "sink.connector").addConnection("source2", "sink.connector");
    BatchPhaseSpec phaseSpec = new BatchPhaseSpec("phase-1", builder.build(), new Resources(), new Resources(), new Resources(), false, false, Collections.<String, String>emptyMap(), 0, Collections.<String, String>emptyMap(), false, null);
    Assert.assertEquals("Sources 'source1', 'source2' to sinks 'sink.connector'.", phaseSpec.getDescription());
}
Also used : PluginSpec(io.cdap.cdap.etl.proto.v2.spec.PluginSpec) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HashMap(java.util.HashMap) PipelinePhase(io.cdap.cdap.etl.common.PipelinePhase) Resources(io.cdap.cdap.api.Resources) Test(org.junit.Test)

Example 4 with ArtifactVersion

use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.

the class DirectRuntimeRequestValidatorTest method testFetcher.

@Test
public void testFetcher() throws BadRequestException {
    ArtifactId artifactId = new ArtifactId("test", new ArtifactVersion("1.0"), ArtifactScope.USER);
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").spark("spark").run(RunIds.generate());
    ProgramRunStatus programRunStatus = ProgramRunStatus.RUNNING;
    RunRecordDetail runRecord = RunRecordDetail.builder().setProgramRunId(programRunId).setStartTime(System.currentTimeMillis()).setArtifactId(artifactId).setStatus(programRunStatus).setSystemArgs(ImmutableMap.of(SystemArguments.PROFILE_NAME, "default", SystemArguments.PROFILE_PROVISIONER, "native")).setProfileId(NamespaceId.DEFAULT.profile("native")).setSourceId(new byte[MessageId.RAW_ID_SIZE]).build();
    MockProgramRunRecordFetcher runRecordFetcher = new MockProgramRunRecordFetcher().setRunRecord(runRecord);
    RuntimeRequestValidator validator = new DirectRuntimeRequestValidator(cConf, txRunner, runRecordFetcher, accessEnforcer, authenticationContext);
    // The first call should be hitting the run record fetching to fetch the run record.
    ProgramRunInfo programRunInfo = validator.getProgramRunStatus(programRunId, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
    Assert.assertEquals(programRunStatus, programRunInfo.getProgramRunStatus());
    // The second call will hit the runtime store, so it shouldn't matter what the run record fetch returns
    runRecordFetcher.setRunRecord(null);
    programRunInfo = validator.getProgramRunStatus(programRunId, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
    Assert.assertEquals(programRunStatus, programRunInfo.getProgramRunStatus());
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 5 with ArtifactVersion

use of io.cdap.cdap.api.artifact.ArtifactVersion 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)

Aggregations

ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)67 Test (org.junit.Test)47 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)38 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)30 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)28 Id (io.cdap.cdap.common.id.Id)22 PluginClass (io.cdap.cdap.api.plugin.PluginClass)19 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)19 File (java.io.File)18 Manifest (java.util.jar.Manifest)13 Set (java.util.Set)11 Location (org.apache.twill.filesystem.Location)11 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)10 HashSet (java.util.HashSet)10 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)8 PluginNotExistsException (io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException)8 Gson (com.google.gson.Gson)7 ArtifactVersionRange (io.cdap.cdap.api.artifact.ArtifactVersionRange)7