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);
}
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));
}
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);
}
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();
}
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);
}
Aggregations