}
});
} else {
target = LazyComputationTargetResolver.resolve(getTargetResolver(), jobItem.getComputationTargetSpecification());
}
final FunctionInvoker invoker = getFunctions().getInvoker(functionUniqueId);
if (invoker == null) {
postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
resultItemBuilder.withException(ERROR_BAD_FUNCTION, "Unable to locate " + functionUniqueId + " in function repository");
return;
}
// set parameters
getFunctionExecutionContext().setFunctionParameters(jobItem.getFunctionParameters());
// assemble inputs
final ValueSpecification[] inputValueSpecs = jobItem.getInputs();
final Set<ValueSpecification> missing = Sets.newHashSetWithExpectedSize(inputValueSpecs.length);
if (!isUseAsynchronousTargetResolve() && (target == null)) {
if (invoker.canHandleMissingInputs()) {
// A missing target is just a special case of missing input
missing.add(TargetSourcingFunction.createSpecification(jobItem.getComputationTargetSpecification()));
} else {
postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
resultItemBuilder.withException(ERROR_CANT_RESOLVE, "Unable to resolve target " + jobItem.getComputationTargetSpecification());
return;
}
}
final Collection<ComputedValue> inputs = new ArrayList<ComputedValue>(inputValueSpecs.length);
int inputBytes = 0;
int inputSamples = 0;
final DeferredViewComputationCache cache = getCache();
_inputs._inputs = inputValueSpecs;
for (final Pair<ValueSpecification, Object> input : cache.getValues(_inputs, getJob().getCacheSelectHint())) {
if ((input.getSecond() == null) || (input.getSecond() instanceof MissingValue)) {
missing.add(input.getFirst());
} else {
final ComputedValue value = new ComputedValue(input.getFirst(), input.getSecond());
inputs.add(value);
final Integer bytes = cache.estimateValueSize(value);
if (bytes != null) {
inputBytes += bytes;
inputSamples++;
}
}
}
statistics.setDataInputBytes(inputBytes, inputSamples);
if (!missing.isEmpty()) {
if (invoker.canHandleMissingInputs()) {
s_logger.debug("Executing even with missing inputs {}", missing);
resultItemBuilder.withPartialInputs(missing);
} else {
s_logger.info("Not able to execute as missing inputs {}", missing);
if (targetFuture != null) {
// Cancelling doesn't do anything so we have to block and clear the result
try {
targetFuture.get();
} catch (final Throwable t) {
s_logger.warn("Error resolving target", t);
postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
resultItemBuilder.withException(t);
return;
}
}
postEvaluationErrors(jobItem.getOutputs(), MissingOutput.MISSING_INPUTS);
resultItemBuilder.withMissingInputs(missing);
return;
}
}
final FunctionInputs functionInputs = new FunctionInputsImpl(getTargetResolver().getSpecificationResolver(), inputs, missing);
if (target == null) {
try {
target = targetFuture.get();
} catch (final Throwable t) {
s_logger.warn("Error resolving target", t);
postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
resultItemBuilder.withException(t);
return;
}
if (target == null) {
if (invoker.canHandleMissingInputs()) {
// A missing target is just a special case of missing input
missing.add(new ValueSpecification(ValueRequirementNames.TARGET, jobItem.getComputationTargetSpecification(), ValueProperties.with(ValuePropertyNames.FUNCTION, "TargetSourcingFunction")
.get()));
} else {
postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
resultItemBuilder.withException(ERROR_CANT_RESOLVE, "Unable to resolve target " + jobItem.getComputationTargetSpecification());
return;
}
}
}
// Execute
statistics.beginInvocation();
Set<ComputedValue> result;
try {
result = invoker.execute(getFunctionExecutionContext(), functionInputs, target, plat2290(outputs));
} catch (final AsynchronousExecution e) {
s_logger.debug("Asynchronous execution of {} at {}", jobItem, _nodeId);
final AsynchronousOperation<Deferred<Void>> async = deferredOperation();
e.setResultListener(new ResultListener<Set<ComputedValue>>() {
@Override