Search in sources :

Example 61 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class SystemMetadataWriterStageTest method testCapabilityTags.

@Test
public void testCapabilityTags() throws Exception {
    String appName = CapabilityAppWithWorkflow.class.getSimpleName();
    ApplicationId appId = NamespaceId.DEFAULT.app(appName);
    String[] capabilityTestNames = { "cdc", "healthcare" };
    Requirements requirements = new Requirements(Collections.emptySet(), Stream.of(capabilityTestNames).collect(Collectors.toSet()));
    ApplicationClass applicationClass = new ApplicationClass(CapabilityAppWithWorkflow.class.getName(), appName, null, requirements);
    String workflowName = CapabilityAppWithWorkflow.SampleWorkflow.class.getSimpleName();
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
    ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName, new CapabilityAppWithWorkflow(), applicationClass);
    WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
    MetadataWriterStage systemMetadataWriterStage = new MetadataWriterStage(metadataServiceClient);
    StageContext stageContext = new StageContext(Object.class);
    systemMetadataWriterStage.process(stageContext);
    systemMetadataWriterStage.process(appWithPrograms);
    Assert.assertEquals(false, metadataStorage.read(new Read(appId.toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
    // Test that all test capabilities are present in the metadata
    Map<String, String> metadataProperties = metadataStorage.read(new Read(appId.toMetadataEntity())).getProperties(MetadataScope.SYSTEM);
    Set<String> capabilityNames = Arrays.stream(metadataProperties.get(AppSystemMetadataWriter.CAPABILITY_TAG).split(AppSystemMetadataWriter.CAPABILITY_DELIMITER)).collect(Collectors.toSet());
    Assert.assertEquals(Arrays.stream(capabilityTestNames).collect(Collectors.toSet()), capabilityNames);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) StageContext(io.cdap.cdap.internal.pipeline.StageContext) Requirements(io.cdap.cdap.api.plugin.Requirements) Read(io.cdap.cdap.spi.metadata.Read) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) Test(org.junit.Test)

Example 62 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class SystemMetadataWriterStageTest method testWorkflowTags.

@Test
public void testWorkflowTags() throws Exception {
    String appName = WorkflowAppWithFork.class.getSimpleName();
    ApplicationId appId = NamespaceId.DEFAULT.app(appName);
    ApplicationClass applicationClass = new ApplicationClass(WorkflowAppWithFork.class.getName(), appName, null);
    String workflowName = WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName();
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
    ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName, applicationClass);
    WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
    MetadataWriterStage systemMetadataWriterStage = new MetadataWriterStage(metadataServiceClient);
    StageContext stageContext = new StageContext(Object.class);
    systemMetadataWriterStage.process(stageContext);
    systemMetadataWriterStage.process(appWithPrograms);
    Assert.assertEquals(false, metadataStorage.read(new Read(appId.workflow(workflowName).toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.TAG)).isEmpty());
    Set<String> workflowSystemTags = metadataStorage.read(new Read(appId.workflow(workflowName).toMetadataEntity())).getTags(MetadataScope.SYSTEM);
    Sets.SetView<String> intersection = Sets.intersection(workflowSystemTags, getWorkflowForkNodes(workflowSpec));
    Assert.assertTrue("Workflows should not be tagged with fork node names, but found the following fork nodes " + "in the workflow's system tags: " + intersection, intersection.isEmpty());
    Assert.assertEquals(false, metadataStorage.read(new Read(appId.toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
    Map<String, String> metadataProperties = metadataStorage.read(new Read(appId.toMetadataEntity())).getProperties(MetadataScope.SYSTEM);
    Assert.assertEquals(WorkflowAppWithFork.SCHED_NAME + ":testDescription", metadataProperties.get("schedule:" + WorkflowAppWithFork.SCHED_NAME));
}
Also used : WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) StageContext(io.cdap.cdap.internal.pipeline.StageContext) Read(io.cdap.cdap.spi.metadata.Read) Sets(com.google.common.collect.Sets) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 63 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class HydratorTestBase method setupStreamingArtifacts.

protected static void setupStreamingArtifacts(ArtifactId artifactId, Class<?> appClass) throws Exception {
    // add the app artifact
    addAppArtifact(artifactId, appClass, StreamingSource.class.getPackage().getName(), Transform.class.getPackage().getName(), AutoJoiner.class.getPackage().getName(), JoinError.class.getPackage().getName(), SparkCompute.class.getPackage().getName(), InvalidStageException.class.getPackage().getName(), PipelineConfigurable.class.getPackage().getName(), // have to export this package, otherwise getting ClassCastException in unit test
    FieldOperation.class.getPackage().getName());
    streamingMocksArtifactId = new ArtifactId(artifactId.getNamespace(), artifactId.getArtifact() + "-mocks", "1.0.0");
    // add plugins artifact
    addPluginArtifact(streamingMocksArtifactId, artifactId, STREAMING_MOCK_PLUGINS, io.cdap.cdap.etl.mock.spark.streaming.MockSource.class, io.cdap.cdap.etl.mock.batch.MockSink.class, io.cdap.cdap.etl.mock.spark.streaming.MockSink.class, DoubleTransform.class, AllErrorTransform.class, IdentityTransform.class, IntValueFilterTransform.class, StringValueFilterTransform.class, StringValueFilterCompute.class, Window.class, NullFieldSplitterTransform.class, NullAlertTransform.class);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId)

Example 64 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class OwnerTable method createRowKey.

// Create row key from Namespaced Entity ID
private String createRowKey(NamespacedEntityId namespacedEntityId) {
    StringBuilder builder = new StringBuilder();
    switch(namespacedEntityId.getEntityType()) {
        case NAMESPACE:
            NamespaceId id = (NamespaceId) namespacedEntityId;
            builder.append(NAMESPACE_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(id.getNamespace());
            break;
        case PROGRAM:
            ProgramId program = (ProgramId) namespacedEntityId;
            builder.append(NAMESPACE_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(program.getNamespace());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(APP_ID_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(program.getApplication());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(PROGRAM_TYPE_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(program.getType().name());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(PROGRAM_ID_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(program.getProgram());
            break;
        case APPLICATION:
            ApplicationId application = (ApplicationId) namespacedEntityId;
            builder.append(NAMESPACE_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(application.getNamespace());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(APP_ID_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(application.getApplication());
            break;
        case DATASET:
            DatasetId datasetInstance = (DatasetId) namespacedEntityId;
            builder.append(NAMESPACE_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(datasetInstance.getNamespace());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(DATASET_ID_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(datasetInstance.getDataset());
            break;
        case ARTIFACT:
            ArtifactId artifactId = (ArtifactId) namespacedEntityId;
            builder.append(NAMESPACE_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(artifactId.getNamespace());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(ARTIFACT_ID_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(artifactId.getArtifact());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(ARTIFACT_VERSION_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(artifactId.getVersion());
            break;
        case SCHEDULE:
            ScheduleId scheduleId = (ScheduleId) namespacedEntityId;
            builder.append(NAMESPACE_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(scheduleId.getNamespace());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(APP_ID_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(scheduleId.getApplication());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(ARTIFACT_VERSION_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(scheduleId.getVersion());
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(SCHEDULE_NAME_ROW_KEY_PREFIX);
            builder.append(ROW_KEY_SEPARATOR);
            builder.append(scheduleId.getSchedule());
            break;
        default:
            throw new IllegalArgumentException(String.format("Error converting id for entity, %s. " + "Unexpected entity type %s", namespacedEntityId.toString(), namespacedEntityId.getEntityType().toString()));
    }
    return builder.toString();
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Example 65 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class StandaloneTester method addSystemArtifact.

/**
 * Adds a system artifact to CDAP instance that is used for testing.
 */
public void addSystemArtifact(String name, ArtifactVersion version, File artifactFile, @Nullable Set<ArtifactRange> parentArtifacts) throws Exception {
    ArtifactRepository artifactRepository = standaloneMain.getInjector().getInstance(ArtifactRepository.class);
    ArtifactId artifactId = NamespaceId.SYSTEM.artifact(name, version.getVersion());
    artifactRepository.addArtifact(Id.Artifact.fromEntityId(artifactId), artifactFile, parentArtifacts, null);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository)

Aggregations

ArtifactId (io.cdap.cdap.proto.id.ArtifactId)214 Test (org.junit.Test)118 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)94 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)68 IOException (java.io.IOException)50 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)42 ProgramId (io.cdap.cdap.proto.id.ProgramId)42 Id (io.cdap.cdap.common.id.Id)40 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)40 File (java.io.File)34 PluginClass (io.cdap.cdap.api.plugin.PluginClass)32 Path (javax.ws.rs.Path)32 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)30 Set (java.util.Set)30 ImmutableSet (com.google.common.collect.ImmutableSet)28 Location (org.apache.twill.filesystem.Location)28 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)26 ArtifactDetail (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)26 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)22 EntityId (io.cdap.cdap.proto.id.EntityId)20