use of org.ow2.proactive.scheduler.smartproxy.common.AwaitedTask in project scheduling by ow2-proactive.
the class RestJobTrackerImpl method removeAwaitedTask.
@Override
public void removeAwaitedTask(String id, String taskName) {
AwaitedJob awaitedJob = jobDatabase.getAwaitedJob(id);
if (awaitedJob == null) {
logger.warn("Job " + id + " not in the awaited list");
return;
}
AwaitedTask awaitedTask = awaitedJob.getAwaitedTask(taskName);
if (awaitedTask == null) {
logger.warn("Task " + taskName + " from Job " + id + " not in the awaited list");
return;
}
logger.debug("Removing knowledge of task " + taskName + " from job " + id);
if (awaitedJob.isIsolateTaskOutputs() && awaitedTask.getTaskId() != null) {
// If the output data as been isolated in a dedicated folder we can delete it.
String pullUrl = awaitedJob.getPullURL();
pullUrl = pullUrl.replace(SchedulerConstants.TASKID_DIR_DEFAULT_NAME, SchedulerConstants.TASKID_DIR_DEFAULT_NAME + "/" + awaitedTask.getTaskId());
try {
RemoteSource remoteSource = new RemoteSource(IDataSpaceClient.Dataspace.USER, pullUrl + "/");
remoteSource.setType(FileType.FOLDER);
restDataSpaceClient.delete(remoteSource);
} catch (Throwable t) {
logger.warn("Could not remove data for task " + taskName + " of job " + id, t);
}
}
awaitedJob.removeAwaitedTask(taskName);
if (awaitedJob.getAwaitedTasks().isEmpty()) {
removeAwaitedJob(id);
return;
} else {
// this is done to ensure persistence of the operation
jobDatabase.putAwaitedJob(id, awaitedJob);
}
try {
jobDatabase.commit();
} catch (IOException e) {
logger.error("Could not save status file after removing task Task " + taskName + " from Job" + id, e);
}
}
use of org.ow2.proactive.scheduler.smartproxy.common.AwaitedTask in project scheduling by ow2-proactive.
the class RestSmartProxyImpl method downloadTaskOutputFiles.
@Override
protected void downloadTaskOutputFiles(AwaitedJob awaitedjob, String jobId, String taskName, String localFolder) throws NotConnectedException, PermissionException {
AwaitedTask atask = awaitedjob.getAwaitedTask(taskName);
if (atask == null) {
throw new IllegalArgumentException("The task " + taskName + " does not belong to job " + jobId + " or has already been removed");
}
if (atask.isTransferring()) {
logger.warn("The task " + taskName + " of job " + jobId + " is already transferring its output");
return;
}
String outputSpace = awaitedjob.getOutputSpaceURL();
String sourceFile;
try {
String userSpace = getLocalUserSpace();
if (!outputSpace.startsWith(userSpace)) {
logger.warn("RestSmartProxy does not support data transfers outside USERSPACE.");
}
sourceFile = outputSpace.substring(userSpace.length() + 1);
} catch (Throwable error) {
throw Throwables.propagate(error);
}
if (awaitedjob.isIsolateTaskOutputs()) {
sourceFile = sourceFile.replace(SchedulerConstants.TASKID_DIR_DEFAULT_NAME, SchedulerConstants.TASKID_DIR_DEFAULT_NAME + "/" + atask.getTaskId());
}
List<OutputSelector> outputFileSelectors = atask.getOutputSelectors();
List<String> includes = Lists.newArrayList();
List<String> excludes = Lists.newArrayList();
if (outputFileSelectors != null) {
for (OutputSelector os : outputFileSelectors) {
addfileSelection(os.getOutputFiles(), includes, excludes);
}
}
jobTracker.setTaskTransferring(jobId, taskName, true);
if (awaitedjob.isAutomaticTransfer()) {
threadPool.submit(new DownloadHandler(jobId, taskName, sourceFile, includes, excludes, localFolder));
} else {
try {
RemoteSource source = new RemoteSource(USER, sourceFile);
source.setIncludes(includes);
source.setExcludes(excludes);
File localDir = new File(localFolder);
LocalDestination dest = new LocalDestination(localDir);
restDataSpaceClient.download(source, dest);
} catch (NotConnectedException | PermissionException e) {
logger.error(String.format("Cannot download files, jobId=%s, taskId=%s, source=%s, destination=%s", jobId, taskName, sourceFile, localFolder), e);
throw e;
} finally {
jobTracker.setTaskTransferring(jobId, taskName, false);
}
// task is removed from the job tracker only if the transfer is successful
jobTracker.removeAwaitedTask(jobId, taskName);
}
}
use of org.ow2.proactive.scheduler.smartproxy.common.AwaitedTask in project scheduling by ow2-proactive.
the class SmartProxyImpl method downloadTaskOutputFiles.
@Override
protected void downloadTaskOutputFiles(AwaitedJob awaitedjob, String jobId, String t_name, String localFolder) throws Exception {
AwaitedTask atask = awaitedjob.getAwaitedTask(t_name);
if (atask == null) {
throw new IllegalArgumentException("The task " + t_name + " does not belong to job " + jobId + " or has already been removed");
}
if (atask.isTransferring()) {
log.warn("The task " + t_name + " of job " + jobId + " is already transferring its output");
return;
}
String pull_URL = awaitedjob.getPullURL();
if (awaitedjob.isIsolateTaskOutputs()) {
pull_URL = pull_URL.replace(SchedulerConstants.TASKID_DIR_DEFAULT_NAME, SchedulerConstants.TASKID_DIR_DEFAULT_NAME + "/" + atask.getTaskId());
}
FileObject remotePullFolderFO;
FileObject localfolderFO;
try {
remotePullFolderFO = jobTracker.resolveFile(pull_URL);
localfolderFO = jobTracker.resolveFile(localFolder);
} catch (FileSystemException e) {
log.error("Could not retrieve data for job " + jobId, e);
throw new IllegalStateException("Could not retrieve data for job " + jobId, e);
}
String sourceUrl = remotePullFolderFO.getURL().toString();
String destUrl = localfolderFO.getURL().toString();
org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector fileSelector = new org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector();
List<OutputSelector> ouputFileSelectors = atask.getOutputSelectors();
for (OutputSelector os : ouputFileSelectors) {
org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector fs = os.getOutputFiles();
if (!fs.getIncludes().isEmpty()) {
fileSelector.addIncludes(fs.getIncludes());
}
if (!fs.getExcludes().isEmpty()) {
fileSelector.addExcludes(fs.getExcludes());
}
}
if (log.isDebugEnabled()) {
log.debug("Looking at files in " + sourceUrl + " with " + fileSelector.getIncludes() + "-" + fileSelector.getExcludes());
boolean goon = true;
int cpt = 0;
FileObject[] fos = null;
while (goon) {
fos = remotePullFolderFO.findFiles(fileSelector);
goon = cpt < 50 && (fos == null || fos.length == 0);
cpt++;
if (goon) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
if (fos != null && fos.length > 0) {
for (FileObject fo : fos) {
log.debug("Found " + fo.getName());
}
} else {
log.warn("Couldn't find " + fileSelector.getIncludes() + "-" + fileSelector.getExcludes() + " in " + sourceUrl);
}
}
if (awaitedjob.isAutomaticTransfer()) {
DataTransferProcessor dtp = new DataTransferProcessor(remotePullFolderFO, localfolderFO, jobId, t_name, fileSelector);
jobTracker.setTaskTransferring(jobId, t_name, true);
threadPool.submit((Runnable) dtp);
} else {
log.debug("Copying files from " + sourceUrl + " to " + destUrl);
try {
localfolderFO.copyFrom(remotePullFolderFO, fileSelector);
} catch (FileSystemException e) {
log.error(e);
throw e;
} finally {
jobTracker.setTaskTransferring(jobId, t_name, false);
}
// task is removed from the job tracker only if the transfer is successful
jobTracker.removeAwaitedTask(jobId, t_name);
log.debug("Finished copying files from " + sourceUrl + " to " + destUrl);
// ok we can remove the task
}
}
use of org.ow2.proactive.scheduler.smartproxy.common.AwaitedTask in project scheduling by ow2-proactive.
the class AbstractSmartProxy method syncAwaitedJob.
/**
* This method will synchronize this proxy with a remote Scheduler for the
* given job
*
* @param id job ID
*/
private void syncAwaitedJob(String id) {
AwaitedJob awaitedJob = jobTracker.getAwaitedJob(id);
try {
JobState js = getJobState(id);
for (TaskState ts : js.getTasks()) {
String tname = ts.getName();
AwaitedTask at = awaitedJob.getAwaitedTask(tname);
if ((at != null) && (!at.isTransferring())) {
TaskResult tres = null;
try {
tres = getTaskResult(id, tname);
if (tres != null) {
log.debug("Synchonizing task " + tname + " of job " + id);
taskStateUpdatedEvent(new NotificationData<>(SchedulerEvent.TASK_RUNNING_TO_FINISHED, ts.getTaskInfo()));
}
} catch (NotConnectedException e) {
e.printStackTrace();
} catch (UnknownJobException e) {
log.error("Could not retrieve output data for job " + id + " because this job is not known by the Scheduler. \n ", e);
} catch (UnknownTaskException e) {
log.error("Could not retrieve output data for task " + tname + " of job " + id + " because this task is not known by the Scheduler. \n ", e);
} catch (Exception e) {
log.error("Unexpected error while getting the output data for task " + tname + " of job " + id, e);
}
}
}
if (js.isFinished()) {
jobStateUpdatedEvent(new NotificationData<>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, js.getJobInfo()));
}
} catch (NotConnectedException e) {
log.error("A connection error occured while trying to download output data of Job " + id + ". This job will remain in the list of awaited jobs. Another attempt to dowload the output data will be made next time the application is initialized. ", e);
} catch (UnknownJobException e) {
log.error("Could not retrieve output data for job " + id + " because this job is not known by the Scheduler. \n ", e);
log.warn("Job " + id + " will be removed from the known job list. The system will not attempt again to retrieve data for this job. You could try to manually copy the data from the location " + awaitedJob.getPullURL());
jobTracker.removeAwaitedJob(id);
} catch (PermissionException e) {
log.error("Could not retrieve output data for job " + id + " because you don't have permmission to access this job. You need to use the same connection credentials you used for submitting the job. \n Another attempt to dowload the output data for this job will be made next time the application is initialized. ", e);
}
}
use of org.ow2.proactive.scheduler.smartproxy.common.AwaitedTask in project scheduling by ow2-proactive.
the class AbstractSmartProxy method updateTask.
/**
* Check if the task concerned by this notification is awaited. Retrieve
* corresponding data if needed
*
* @param notification
*/
protected void updateTask(NotificationData<TaskInfo> notification) {
// am I interested in this task?
TaskInfo taskInfoData = notification.getData();
JobId id = taskInfoData.getJobId();
TaskId tid = taskInfoData.getTaskId();
String tname = tid.getReadableName();
TaskStatus status = taskInfoData.getStatus();
AwaitedJob aj = jobTracker.getAwaitedJob(id.toString());
if (aj == null)
return;
AwaitedTask at = aj.getAwaitedTask(tname);
if (at == null)
return;
at.setTaskId(tid.toString());
jobTracker.putAwaitedJob(id.toString(), aj);
switch(status) {
case ABORTED:
case NOT_RESTARTED:
case NOT_STARTED:
case SKIPPED:
{
log.debug("The task " + tname + " from job " + id + " couldn't start. No data will be transfered");
jobTracker.removeAwaitedTask(id.toString(), tname);
break;
}
case FINISHED:
{
log.debug("The task " + tname + " from job " + id + " is finished.");
if (aj.isAutomaticTransfer()) {
log.debug("Transferring data for finished task " + tname + " from job " + id);
try {
downloadTaskOutputFiles(aj, id.toString(), tname, aj.getLocalOutputFolder());
} catch (Throwable t) {
log.error("Error while handling data for finished task " + tname + " for job " + id + ", task will be removed");
jobTracker.removeAwaitedTask(id.toString(), tname);
}
}
break;
}
case FAILED:
case FAULTY:
{
log.debug("The task " + tname + " from job " + id + " is faulty.");
jobTracker.removeAwaitedTask(id.toString(), tname);
break;
}
}
}
Aggregations