Search in sources :

Example 1 with AppSystemMetadataWriter

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);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) DatasetSystemMetadataWriter(co.cask.cdap.data2.metadata.system.DatasetSystemMetadataWriter) ProgramSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ProgramSystemMetadataWriter) ViewSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ViewSystemMetadataWriter) SystemMetadataWriter(co.cask.cdap.data2.metadata.system.SystemMetadataWriter) AppSystemMetadataWriter(co.cask.cdap.data2.metadata.system.AppSystemMetadataWriter) ArtifactSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ArtifactSystemMetadataWriter) StreamSystemMetadataWriter(co.cask.cdap.data2.metadata.system.StreamSystemMetadataWriter) ApplicationId(co.cask.cdap.proto.id.ApplicationId) AppSystemMetadataWriter(co.cask.cdap.data2.metadata.system.AppSystemMetadataWriter)

Example 2 with AppSystemMetadataWriter

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);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) SystemMetadataWriter(co.cask.cdap.data2.metadata.system.SystemMetadataWriter) AppSystemMetadataWriter(co.cask.cdap.data2.metadata.system.AppSystemMetadataWriter) ProgramSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ProgramSystemMetadataWriter) ApplicationId(co.cask.cdap.proto.id.ApplicationId) AppSystemMetadataWriter(co.cask.cdap.data2.metadata.system.AppSystemMetadataWriter)

Example 3 with AppSystemMetadataWriter

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);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) ArrayList(java.util.ArrayList) Metadata(io.cdap.cdap.api.metadata.Metadata) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) AppSystemMetadataWriter(io.cdap.cdap.data2.metadata.system.AppSystemMetadataWriter)

Aggregations

ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)2 AppSystemMetadataWriter (co.cask.cdap.data2.metadata.system.AppSystemMetadataWriter)2 ProgramSystemMetadataWriter (co.cask.cdap.data2.metadata.system.ProgramSystemMetadataWriter)2 SystemMetadataWriter (co.cask.cdap.data2.metadata.system.SystemMetadataWriter)2 ApplicationId (co.cask.cdap.proto.id.ApplicationId)2 ArtifactSystemMetadataWriter (co.cask.cdap.data2.metadata.system.ArtifactSystemMetadataWriter)1 DatasetSystemMetadataWriter (co.cask.cdap.data2.metadata.system.DatasetSystemMetadataWriter)1 StreamSystemMetadataWriter (co.cask.cdap.data2.metadata.system.StreamSystemMetadataWriter)1 ViewSystemMetadataWriter (co.cask.cdap.data2.metadata.system.ViewSystemMetadataWriter)1 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)1 Metadata (io.cdap.cdap.api.metadata.Metadata)1 AppSystemMetadataWriter (io.cdap.cdap.data2.metadata.system.AppSystemMetadataWriter)1 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)1 MetadataMutation (io.cdap.cdap.spi.metadata.MetadataMutation)1 ArrayList (java.util.ArrayList)1