use of io.cdap.cdap.data2.metadata.system.AppSystemMetadataWriter in project cdap by caskdata.
the class ExistingEntitySystemMetadataWriter method writeSystemMetadataForApps.
private void writeSystemMetadataForApps(NamespaceId namespace) {
for (ApplicationSpecification appSpec : store.getAllApplications(namespace)) {
ApplicationId app = namespace.app(appSpec.getName());
SystemMetadataWriter writer = new AppSystemMetadataWriter(metadataStore, app, appSpec);
writer.write();
writeSystemMetadataForPrograms(app, appSpec);
}
}
use of io.cdap.cdap.data2.metadata.system.AppSystemMetadataWriter in project cdap by caskdata.
the class SystemMetadataWriterStage method process.
@Override
public void process(ApplicationWithPrograms input) throws Exception {
// add system metadata for apps
ApplicationId appId = input.getApplicationId();
ApplicationSpecification appSpec = input.getSpecification();
// only update creation time if this is a new app
Map<String, String> properties = metadataStore.getProperties(MetadataScope.SYSTEM, appId);
SystemMetadataWriter appSystemMetadataWriter = new AppSystemMetadataWriter(metadataStore, appId, appSpec, !properties.isEmpty());
appSystemMetadataWriter.write();
// add system metadata for programs
writeProgramSystemMetadata(appId, ProgramType.FLOW, appSpec.getFlows().values());
writeProgramSystemMetadata(appId, ProgramType.MAPREDUCE, appSpec.getMapReduce().values());
writeProgramSystemMetadata(appId, ProgramType.SERVICE, appSpec.getServices().values());
writeProgramSystemMetadata(appId, ProgramType.SPARK, appSpec.getSpark().values());
writeProgramSystemMetadata(appId, ProgramType.WORKER, appSpec.getWorkers().values());
writeProgramSystemMetadata(appId, ProgramType.WORKFLOW, appSpec.getWorkflows().values());
// Emit input to the next stage
emit(input);
}
use of io.cdap.cdap.data2.metadata.system.AppSystemMetadataWriter in project cdap by caskdata.
the class MetadataWriterStage method process.
@Override
public void process(ApplicationWithPrograms input) {
// use current time as creation time for app and all programs
creationTime = String.valueOf(System.currentTimeMillis());
// add system metadata for apps
ApplicationId appId = input.getApplicationId();
ApplicationSpecification appSpec = input.getSpecification();
List<MetadataMutation> mutations = new ArrayList<>();
// get the system metadata and combine it with our own system metadata, metadata creation mutation will
// completely override the previous metadata in the scope, so we have to combine these together
Metadata systemAppMetadata = input.getMetadata().get(MetadataScope.SYSTEM);
mutations.add(new AppSystemMetadataWriter(metadataServiceClient, appId, appSpec, input.getApplicationClass(), creationTime, systemAppMetadata).getMetadataMutation());
// collect system metadata for programs
collectProgramSystemMetadata(appId, ProgramType.MAPREDUCE, appSpec.getMapReduce().values(), mutations);
collectProgramSystemMetadata(appId, ProgramType.SERVICE, appSpec.getServices().values(), mutations);
collectProgramSystemMetadata(appId, ProgramType.SPARK, appSpec.getSpark().values(), mutations);
collectProgramSystemMetadata(appId, ProgramType.WORKER, appSpec.getWorkers().values(), mutations);
collectProgramSystemMetadata(appId, ProgramType.WORKFLOW, appSpec.getWorkflows().values(), mutations);
// add the rest user defined metadata
Metadata userAppMetadata = input.getMetadata().get(MetadataScope.USER);
if (userAppMetadata != null && (!userAppMetadata.getProperties().isEmpty() || !userAppMetadata.getTags().isEmpty())) {
mutations.add(new MetadataMutation.Create(appId.toMetadataEntity(), new io.cdap.cdap.spi.metadata.Metadata(MetadataScope.USER, userAppMetadata.getTags(), userAppMetadata.getProperties()), Collections.emptyMap()));
}
// write all metadata
metadataServiceClient.batch(mutations);
// Emit input to the next stage
emit(input);
}
Aggregations