use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class LiveJobs method finishInErrorTask.
TerminationData finishInErrorTask(JobId jobId, String taskName) throws UnknownTaskException, UnknownJobException {
JobData jobData = lockJob(jobId);
if (jobData == null) {
throw new UnknownJobException(jobId);
}
InternalJob job = jobData.job;
try {
InternalTask task = job.getTask(taskName);
if (task == null) {
throw new UnknownTaskException(taskName);
}
TaskId taskId = task.getId();
if (task.getStatus() != TaskStatus.IN_ERROR) {
tlogger.info(task.getId(), "Task must be in state IN_ERROR: " + task.getStatus());
return emptyResult(task.getId());
}
TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, job, task);
RunningTaskData data = new RunningTaskData(task, job.getOwner(), job.getCredentials(), null);
TerminationData terminationData = TerminationData.newTerminationData();
terminationData.addTaskData(job, data, TerminationData.TerminationStatus.ABORTED, taskResult);
tlogger.debug(taskId, "result added to job " + job.getId());
// to be done before terminating the task, once terminated it is not
// running anymore..
ChangedTasksInfo changesInfo = job.finishInErrorTask(taskId, taskResult, listener);
((JobInfoImpl) job.getJobInfo()).setPreciousTasks(job.getPreciousTasksFinished());
boolean jobFinished = job.isFinished();
// update job info if it is terminated
if (jobFinished) {
// terminating job
job.terminate();
jlogger.debug(job.getId(), "terminated");
jobs.remove(job.getId());
terminationData.addJobToTerminate(job.getId(), job.getGenericInformation(), job.getCredentials());
}
task.setInErrorTime(-1);
boolean jobUpdated = false;
if (job.getNumberOfInErrorTasks() == 0) {
job.setInErrorTime(-1);
jobUpdated = true;
}
// Update database
if (taskResult.getAction() != null) {
dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, taskResult);
} else {
dbManager.updateAfterTaskFinished(job, task, taskResult);
}
// send event
listener.taskStateUpdated(job.getOwner(), new NotificationData<TaskInfo>(SchedulerEvent.TASK_IN_ERROR_TO_FINISHED, new TaskInfoImpl((TaskInfoImpl) task.getTaskInfo())));
// if this job is finished (every task have finished)
jlogger.info(job.getId(), "finished tasks " + job.getNumberOfFinishedTasks() + ", total tasks " + job.getTotalNumberOfTasks() + ", finished " + jobFinished);
if (jobFinished) {
// send event to client
listener.jobStateUpdated(job.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, new JobInfoImpl((JobInfoImpl) job.getJobInfo())));
listener.jobUpdatedFullData(job);
} else if (jobUpdated) {
listener.jobStateUpdated(job.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_UPDATED, new JobInfoImpl((JobInfoImpl) job.getJobInfo())));
listener.jobUpdatedFullData(job);
}
return terminationData;
} finally {
jobData.unlock();
}
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class LiveJobs method terminateTask.
private void terminateTask(JobData jobData, InternalTask task, boolean errorOccurred, TaskResultImpl result, TerminationData terminationData) {
InternalJob job = jobData.job;
TaskId taskId = task.getId();
tlogger.debug(taskId, "result added to job " + job.getId());
// to be done before terminating the task, once terminated it is not
// running anymore..
job.getRunningTaskDescriptor(taskId);
// merge task map result to job map result
job.getResultMap().putAll(result.getResultMap());
ChangedTasksInfo changesInfo = job.terminateTask(errorOccurred, taskId, listener, result.getAction(), result);
((JobInfoImpl) job.getJobInfo()).setPreciousTasks(job.getPreciousTasksFinished());
boolean jobFinished = job.isFinished();
// update job info if it is terminated
if (jobFinished) {
// terminating job
job.terminate();
// Cleaning job signals
cleanJobSignals(job.getId());
jlogger.debug(job.getId(), "terminated");
terminationData.addJobToTerminate(job.getId(), job.getGenericInformation(), job.getCredentials());
jobs.remove(job.getId());
}
task.setTaskResult(result);
// Update database
if (result.getAction() != null) {
dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
} else {
dbManager.updateAfterTaskFinished(job, task, result);
}
// send event
listener.taskStateUpdated(job.getOwner(), new NotificationData<TaskInfo>(SchedulerEvent.TASK_RUNNING_TO_FINISHED, new TaskInfoImpl((TaskInfoImpl) task.getTaskInfo())));
// if this job is finished (every task have finished)
jlogger.info(job.getId(), "finished tasks " + job.getNumberOfFinishedTasks() + ", total tasks " + job.getTotalNumberOfTasks() + ", finished " + jobFinished);
if (jobFinished) {
// send event to client
listener.jobStateUpdated(job.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, new JobInfoImpl((JobInfoImpl) job.getJobInfo())));
listener.jobUpdatedFullData(job);
}
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class SchedulerFactory method createScheduler.
/**
* Create a new scheduler on the local host plugged on the given resource manager.<br>
* This constructor also requires the credentials of the client to connect.<br><br>
* It will return a client scheduler able to managed the scheduler.<br><br>
* <font color="red">WARNING :</font> this method provides a way to connect to the scheduler after its creation,
* BUT if the scheduler is restarting after failure, this method will create the scheduler
* but will throw a SchedulerException due to the failure of client connection.<br>
* In fact, while the scheduler is restarting after a crash, no one can connect it during the whole restore process.<br><br>
* In any other case, the method will block until connection is allowed or error occurred.
*
* @param rmURL the resource manager URL on which the scheduler will connect
* @param policyFullClassName the full policy class name for the scheduler.
* @return a scheduler interface to manage the scheduler.
* @throws SchedulerException if the scheduler cannot be created.
* @throws AdminSchedulerException if a client connection exception occurs.
* @throws LoginException if a user login/password exception occurs.
*/
public static Scheduler createScheduler(Credentials creds, URI rmURL, String policyFullClassName) throws AdminSchedulerException, SchedulerException, LoginException {
createScheduler(rmURL, policyFullClassName, SchedulerStatus.STARTED);
SchedulerAuthenticationInterface auth = SchedulerConnection.waitAndJoin(null);
return auth.login(creds);
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class SchedulerAuthentication method login.
/**
* {@inheritDoc}
*/
public Scheduler login(Credentials cred) throws LoginException, AlreadyConnectedException {
Subject subject = authenticate(cred);
UserNamePrincipal unPrincipal = subject.getPrincipals(UserNamePrincipal.class).iterator().next();
String user = unPrincipal.getName();
logger.info("user : " + user);
// add this user to the scheduler front-end
UserIdentificationImpl ident = new UserIdentificationImpl(user, subject);
ident.setHostName(getSenderHostName());
this.frontend.connect(PAActiveObject.getContext().getCurrentRequest().getSourceBodyID(), ident, cred);
try {
// return the stub on Scheduler interface to keep avoid using server class on client side
return PAActiveObject.lookupActive(Scheduler.class, PAActiveObject.getUrl(frontend));
} catch (ActiveObjectCreationException e) {
rethrowSchedulerStubException(e);
} catch (IOException e) {
rethrowSchedulerStubException(e);
}
return null;
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class RMRestClient method createRestProxy.
private static RMRestInterface createRestProxy(ResteasyProviderFactory provider, String restEndpointURL, ClientHttpEngine httpEngine) {
ResteasyClient client = buildResteasyClient(provider);
ResteasyWebTarget target = client.target(restEndpointURL);
RMRestInterface rmRestInterface = target.proxy(RMRestInterface.class);
return createExceptionProxy(rmRestInterface);
}
Aggregations