Search in sources :

Example 1 with JobLogic

use of com.accenture.trac.svc.orch.jobs.JobLogic in project tracdap by finos.

the class JobLifecycle method loadResourcesResponse.

CompletionStage<JobState> loadResourcesResponse(JobState jobState, List<String> mappingKeys, MetadataBatchResponse batchResponse) {
    if (batchResponse.getTagCount() != mappingKeys.size())
        throw new EUnexpected();
    var jobLogic = JobLogic.forJobType(jobState.jobType);
    var resources = new HashMap<String, ObjectDefinition>(mappingKeys.size());
    var mappings = new HashMap<String, TagHeader>(mappingKeys.size());
    for (var resourceIndex = 0; resourceIndex < mappingKeys.size(); resourceIndex++) {
        var resourceTag = batchResponse.getTag(resourceIndex);
        var resourceKey = MetadataUtil.objectKey(resourceTag.getHeader());
        var mappingKey = mappingKeys.get(resourceIndex);
        resources.put(resourceKey, resourceTag.getDefinition());
        mappings.put(mappingKey, resourceTag.getHeader());
    }
    jobState.resources.putAll(resources);
    jobState.resourceMapping.putAll(mappings);
    var extraResources = jobLogic.requiredMetadata(resources).stream().filter(selector -> !jobState.resources.containsKey(MetadataUtil.objectKey(selector))).filter(selector -> !jobState.resourceMapping.containsKey(MetadataUtil.objectKey(selector))).collect(Collectors.toList());
    if (!extraResources.isEmpty())
        return loadResources(jobState, extraResources);
    return CompletableFuture.completedFuture(jobState);
}
Also used : EInputValidation(com.accenture.trac.common.exception.EInputValidation) com.accenture.trac.metadata(com.accenture.trac.metadata) StorageSettings(com.accenture.trac.config.StorageSettings) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) MetadataUtil.selectorFor(com.accenture.trac.common.metadata.MetadataUtil.selectorFor) ArrayList(java.util.ArrayList) MetadataConstants(com.accenture.trac.common.metadata.MetadataConstants) PlatformConfig(com.accenture.trac.config.PlatformConfig) MetadataWriteRequest(com.accenture.trac.api.MetadataWriteRequest) TRAC_CREATE_JOB(com.accenture.trac.common.metadata.MetadataConstants.TRAC_CREATE_JOB) MetadataBatchResponse(com.accenture.trac.api.MetadataBatchResponse) JobLogic(com.accenture.trac.svc.orch.jobs.JobLogic) MethodDescriptor(io.grpc.MethodDescriptor) MetadataBatchRequest(com.accenture.trac.api.MetadataBatchRequest) Logger(org.slf4j.Logger) EUnexpected(com.accenture.trac.common.exception.EUnexpected) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JobConfig(com.accenture.trac.config.JobConfig) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) MetadataCodec.encodeValue(com.accenture.trac.common.metadata.MetadataCodec.encodeValue) GrpcClientWrap(com.accenture.trac.common.grpc.GrpcClientWrap) MetadataCodec(com.accenture.trac.common.metadata.MetadataCodec) RuntimeConfig(com.accenture.trac.config.RuntimeConfig) JobState(com.accenture.trac.svc.orch.cache.JobState) TrustedMetadataApiGrpc(com.accenture.trac.api.TrustedMetadataApiGrpc) MetadataUtil(com.accenture.trac.common.metadata.MetadataUtil) HashMap(java.util.HashMap) EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Aggregations

MetadataBatchRequest (com.accenture.trac.api.MetadataBatchRequest)1 MetadataBatchResponse (com.accenture.trac.api.MetadataBatchResponse)1 MetadataWriteRequest (com.accenture.trac.api.MetadataWriteRequest)1 TrustedMetadataApiGrpc (com.accenture.trac.api.TrustedMetadataApiGrpc)1 EInputValidation (com.accenture.trac.common.exception.EInputValidation)1 EUnexpected (com.accenture.trac.common.exception.EUnexpected)1 GrpcClientWrap (com.accenture.trac.common.grpc.GrpcClientWrap)1 MetadataCodec (com.accenture.trac.common.metadata.MetadataCodec)1 MetadataCodec.encodeValue (com.accenture.trac.common.metadata.MetadataCodec.encodeValue)1 MetadataConstants (com.accenture.trac.common.metadata.MetadataConstants)1 TRAC_CREATE_JOB (com.accenture.trac.common.metadata.MetadataConstants.TRAC_CREATE_JOB)1 MetadataUtil (com.accenture.trac.common.metadata.MetadataUtil)1 MetadataUtil.selectorFor (com.accenture.trac.common.metadata.MetadataUtil.selectorFor)1 JobConfig (com.accenture.trac.config.JobConfig)1 PlatformConfig (com.accenture.trac.config.PlatformConfig)1 RuntimeConfig (com.accenture.trac.config.RuntimeConfig)1 StorageSettings (com.accenture.trac.config.StorageSettings)1 com.accenture.trac.metadata (com.accenture.trac.metadata)1 JobState (com.accenture.trac.svc.orch.cache.JobState)1 JobLogic (com.accenture.trac.svc.orch.jobs.JobLogic)1