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