use of org.ow2.proactive.scheduler.synchronization.InvalidChannelException in project scheduling by ow2-proactive.
the class SignalApiTest method testReadyForSignalWithVariables.
@Test
public void testReadyForSignalWithVariables() throws SignalApiException, InvalidChannelException {
String signalName = "test_signal_1";
JobVariable jobVariable1 = new JobVariable("name1", "value1");
JobVariable jobVariable2 = new JobVariable("name2", "value2");
List<JobVariable> jobVariables = new ArrayList<>();
jobVariables.add(jobVariable1);
jobVariables.add(jobVariable2);
signalApi.readyForSignal(signalName, jobVariables);
Assert.assertTrue(((Signal) synchronizationInternal.get(USER, TASK_ID, SIGNALS_CHANNEL + JOB_ID.value(), READY_PREFIX + signalName)).getName().equals(signalName));
Assert.assertNotNull((synchronizationInternal.get(USER, TASK_ID, SIGNALS_CHANNEL + JOB_ID.value(), READY_PREFIX + signalName)));
Assert.assertEquals(jobVariables, ((Signal) synchronizationInternal.get(USER, TASK_ID, SIGNALS_CHANNEL + JOB_ID.value(), READY_PREFIX + signalName)).getInputVariables());
}
use of org.ow2.proactive.scheduler.synchronization.InvalidChannelException in project scheduling by ow2-proactive.
the class AOSynchronization method executeWaitPredicateFunction.
/**
* Extract from the request the parameters corresponding to the waitUntil method call, then execute waitUntil with these parameters
* @param request request used to extract parameters
* @return the result of the waitUntil method call
*/
private boolean executeWaitPredicateFunction(Request request) throws InvalidChannelException, CompilationException {
// extract the parameters which match the waitUntil call
int paramIndex = 0;
String originator = (String) request.getParameter(paramIndex++);
TaskId taskId = (TaskId) request.getParameter(paramIndex++);
String channel = (String) request.getParameter(paramIndex++);
String key = (String) request.getParameter(paramIndex++);
String predicate = (String) request.getParameter(paramIndex);
return this.executeWaitPredicate(originator, taskId, channel, key, predicate);
}
use of org.ow2.proactive.scheduler.synchronization.InvalidChannelException in project scheduling by ow2-proactive.
the class SchedulerFrontend method insertJobSignals.
private JobInfo insertJobSignals(JobInfo jobInfo) {
String jobid = jobInfo.getJobId().value();
if (checkJobPermissionMethod(jobid, "addJobSignal")) {
try {
TaskId taskId = createFakeTaskId(jobInfo.getJobId().value());
if (publicStore.channelExists(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobid)) {
Set<Map.Entry<String, Serializable>> signalEntries = publicStore.entrySet(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobid);
Set<String> signalsToBeAdded = signalEntries.stream().map(entry -> entry.getKey()).collect(Collectors.toSet());
List<Signal> signalList = signalEntries.stream().map(entry -> (Signal) entry.getValue()).collect(Collectors.toList());
Map<String, Map<String, JobVariable>> detailedSignalsToBeAdded = new LinkedHashMap<>();
signalList.forEach(signal -> {
Map<String, JobVariable> variableMap = new LinkedHashMap<>();
if (signal.getInputVariables() != null) {
signal.getInputVariables().forEach(jobVariable -> variableMap.put(jobVariable.getName(), jobVariable));
}
detailedSignalsToBeAdded.put(signal.getName(), variableMap);
});
Set<String> jobSignals = jobInfo.getSignals();
Map<String, Map<String, JobVariable>> jobDetailedSignals = jobInfo.getDetailedSignals();
if (signalsToBeAdded != null && !signalsToBeAdded.isEmpty()) {
jobSignals.addAll(signalsToBeAdded);
jobInfo.setSignals(jobSignals);
}
if (detailedSignalsToBeAdded != null && !detailedSignalsToBeAdded.isEmpty()) {
jobDetailedSignals.putAll(detailedSignalsToBeAdded);
jobInfo.setDetailedSignals(jobDetailedSignals);
}
}
} catch (InvalidChannelException e) {
logger.warn("Could not retrieve the signals of the job " + jobid);
}
}
return jobInfo;
}
use of org.ow2.proactive.scheduler.synchronization.InvalidChannelException in project scheduling by ow2-proactive.
the class SchedulerFrontend method validateJobSignal.
@Override
@ImmediateService
public List<JobVariable> validateJobSignal(String jobId, String signalName, Map<String, String> updatedVariables) throws NotConnectedException, UnknownJobException, PermissionException, SignalApiException, JobValidationException {
if (updatedVariables == null || updatedVariables.isEmpty()) {
return null;
}
String currentUser = frontendState.getCurrentUser();
logger.debug("Request to validate signal " + signalName + " on job " + jobId + " received from " + currentUser);
final JobId jobIdObject = JobIdImpl.makeJobId(jobId);
frontendState.checkPermissions("addJobSignal", frontendState.getIdentifiedJob(jobIdObject), YOU_DO_NOT_HAVE_PERMISSION_TO_SEND_SIGNALS_TO_THIS_JOB);
String readyPrefix = SignalApiImpl.READY_PREFIX;
if (StringUtils.isBlank(signalName.trim())) {
throw new SignalApiException("Empty signals are not allowed");
}
try {
TaskId taskId = createFakeTaskId(jobId);
publicStore.createChannelIfAbsent(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId, true);
Signal signal = (Signal) publicStore.get(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId, readyPrefix + signalName);
if (signal != null) {
DefaultModelJobValidatorServiceProvider validatorServiceProvider = new DefaultModelJobValidatorServiceProvider();
Map<String, Serializable> serializableUpdatedVariables = new LinkedHashMap<>();
serializableUpdatedVariables.putAll(updatedVariables);
validatorServiceProvider.validateVariables(signal.getInputVariables(), serializableUpdatedVariables, this, this);
return signal.getInputVariables();
} else {
throw new SignalApiException("Signal not found");
}
} catch (InvalidChannelException e) {
throw new SignalApiException("Could not read signals channel", e);
} catch (IOException e) {
throw new SignalApiException("Could not add signalName for the job " + jobId, e);
}
}
use of org.ow2.proactive.scheduler.synchronization.InvalidChannelException in project scheduling by ow2-proactive.
the class SchedulerFrontend method addJobSignal.
@Override
@ImmediateService
public Set<String> addJobSignal(String jobId, String signalName, Map<String, String> updatedVariables) throws NotConnectedException, UnknownJobException, PermissionException, SignalApiException, JobValidationException {
String currentUser = frontendState.getCurrentUser();
logger.info("Request to send signalName " + signalName + " on job " + jobId + " received from " + currentUser);
final JobId jobIdObject = JobIdImpl.makeJobId(jobId);
frontendState.checkPermissions("addJobSignal", frontendState.getIdentifiedJob(jobIdObject), YOU_DO_NOT_HAVE_PERMISSION_TO_SEND_SIGNALS_TO_THIS_JOB);
if (StringUtils.isBlank(signalName.trim())) {
throw new SignalApiException("Empty signals are not allowed");
}
try {
TaskId taskId = createFakeTaskId(jobId);
publicStore.createChannelIfAbsent(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId, true);
Set<String> signals = publicStore.keySet(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId);
String readyPrefix = SignalApiImpl.READY_PREFIX;
if (!(signals.contains(readyPrefix + signalName) || signalName.startsWith(readyPrefix))) {
throw new SignalApiException("Job " + jobId + " is not ready to receive the signalName " + signalName);
}
// Remove the existing ready signalName, add the signalName and return the set of signals
Signal readySignal = (Signal) publicStore.get(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId, readyPrefix + signalName);
setUpdatedVariables(updatedVariables, readySignal);
publicStore.remove(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId, readyPrefix + signalName);
publicStore.put(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId, signalName, readySignal);
Set<String> finalSignals = publicStore.keySet(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId);
return finalSignals;
} catch (InvalidChannelException e) {
throw new SignalApiException("Could not read signals channel", e);
} catch (IOException e) {
throw new SignalApiException("Could not add signalName for the job " + jobId, e);
}
}
Aggregations