Search in sources :

Example 21 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class Validator method registeredValidation.

private <TMsg extends Message> ValidationContext registeredValidation(TMsg msg, ValidationContext ctx) {
    var key = ctx.key();
    var validator = validators.get(key);
    if (validator == null) {
        log.error("Required validator is not registered: [{}]", key.displayName());
        throw new EUnexpected();
    }
    if (validator.isBasic())
        return ctx.apply(validator.basic());
    if (!validator.targetClass().isInstance(msg))
        throw new EUnexpected();
    if (validator.isTyped()) {
        @SuppressWarnings("unchecked") var typedValidator = (ValidationFunction.Typed<TMsg>) validator.typed();
        @SuppressWarnings("unchecked") var typedTarget = (Class<TMsg>) msg.getClass();
        return ctx.apply(typedValidator, typedTarget);
    }
    if (validator.isVersion()) {
        @SuppressWarnings("unchecked") var typedValidator = (ValidationFunction.Version<TMsg>) validator.version();
        @SuppressWarnings("unchecked") var typedTarget = (Class<TMsg>) msg.getClass();
        return ctx.apply(typedValidator, typedTarget);
    }
    throw new EUnexpected();
}
Also used : EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Example 22 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class RunModelJob method requiredMetadata.

@Override
public List<TagSelector> requiredMetadata(JobDefinition job) {
    if (job.getJobType() != JobType.RUN_MODEL)
        throw new EUnexpected();
    var runModel = job.getRunModel();
    var resources = new ArrayList<TagSelector>(runModel.getInputsCount() + 1);
    resources.add(runModel.getModel());
    resources.addAll(runModel.getInputsMap().values());
    return resources;
}
Also used : EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Example 23 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected 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)

Example 24 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class LocalJobCache method deleteJob.

@Override
public void deleteJob(String jobKey, Ticket ticket) {
    var operationTime = Instant.now();
    var cacheEntry = cache.computeIfPresent(jobKey, (key, priorEntry) -> {
        if (priorEntry.ticket != ticket)
            return priorEntry;
        if (priorEntry.jobState == null)
            throw new EUnexpected();
        var newEntry = priorEntry.clone();
        newEntry.jobState = null;
        newEntry.lastActivity = operationTime;
        newEntry.revision = priorEntry.revision + 1;
        return newEntry;
    });
    if (cacheEntry != null && cacheEntry.ticket != ticket)
        // TODO: Error
        throw new ECacheTicket("");
}
Also used : EUnexpected(com.accenture.trac.common.exception.EUnexpected) ECacheTicket(com.accenture.trac.common.exception.ECacheTicket)

Example 25 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class JobApiService method checkJob.

public CompletionStage<JobStatus> checkJob(JobStatusRequest request) {
    // TODO: Keys for other selector types
    if (!request.getSelector().hasObjectVersion())
        throw new EUnexpected();
    var jobKey = MetadataUtil.objectKey(request.getSelector());
    var jobState = jobCache.readJob(jobKey);
    // TODO: Should there be a different error for jobs not found in the cache? EJobNotLive?
    if (jobState == null) {
        var message = String.format("Job not found (it may have completed): [%s]", jobKey);
        log.error(message);
        throw new EMetadataNotFound(message);
    }
    var jobStatus = reportStatus(jobState);
    return CompletableFuture.completedFuture(jobStatus);
}
Also used : EMetadataNotFound(com.accenture.trac.common.exception.EMetadataNotFound) EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Aggregations

EUnexpected (com.accenture.trac.common.exception.EUnexpected)44 IOException (java.io.IOException)8 EDataCorruption (com.accenture.trac.common.exception.EDataCorruption)4 ArrayList (java.util.ArrayList)3 ECacheTicket (com.accenture.trac.common.exception.ECacheTicket)2 EInputValidation (com.accenture.trac.common.exception.EInputValidation)2 ByteSeekableChannel (com.accenture.trac.common.util.ByteSeekableChannel)2 Http1to2Framing (com.accenture.trac.gateway.proxy.http.Http1to2Framing)2 JacksonException (com.fasterxml.jackson.core.JacksonException)2 JsonToken (com.fasterxml.jackson.core.JsonToken)2 ByteString (com.google.protobuf.ByteString)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)2 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 EMetadataNotFound (com.accenture.trac.common.exception.EMetadataNotFound)1 EPluginNotAvailable (com.accenture.trac.common.exception.EPluginNotAvailable)1 EStartup (com.accenture.trac.common.exception.EStartup)1