use of org.ow2.proactive.resourcemanager.exception.NotConnectedException 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.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class RMCore method checkMethodCallPermission.
/**
* Checks if the caller thread has permissions to call particular method name
*
* @return client object corresponding to the caller thread
*/
private Client checkMethodCallPermission(final String methodName, UniqueID clientId) {
Client client = RMCore.clients.get(clientId);
if (client == null) {
// Check if the client id is a local body or half body
LocalBodyStore lbs = LocalBodyStore.getInstance();
if (lbs.getLocalBody(clientId) != null || lbs.getLocalHalfBody(clientId) != null) {
return RMCore.localClient;
}
throw new NotConnectedException("Client " + clientId.shortString() + " is not connected to the resource manager");
}
final String fullMethodName = RMCore.class.getName() + "." + methodName;
final MethodCallPermission methodCallPermission = new MethodCallPermission(fullMethodName);
client.checkPermission(methodCallPermission, client + " is not authorized to call " + fullMethodName);
return client;
}
use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class AbstractFunctCmdTest method cleanScheduler.
protected void cleanScheduler() throws NotConnectedException, PermissionException, UnknownJobException {
scheduler = RestFuncTHelper.getScheduler();
SchedulerState state = scheduler.getState();
System.out.println("Cleaning scheduler.");
List<JobState> aliveJobsStates = new ArrayList<>(state.getPendingJobs().size() + state.getRunningJobs().size());
aliveJobsStates.addAll(state.getPendingJobs());
aliveJobsStates.addAll(state.getRunningJobs());
List<JobState> finishedJobsStates = new ArrayList<>(state.getFinishedJobs().size());
finishedJobsStates.addAll(state.getFinishedJobs());
for (JobState jobState : aliveJobsStates) {
JobId jobId = jobState.getId();
try {
System.out.println("Killing job " + jobId);
scheduler.killJob(jobId);
} catch (Exception ignored) {
}
System.out.println("Removing killed job " + jobId);
scheduler.removeJob(jobId);
}
for (JobState jobState : finishedJobsStates) {
JobId jobId = jobState.getId();
System.out.println("Removing finished job " + jobId);
scheduler.removeJob(jobId);
}
}
use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerClient method getTaskIds.
@Override
public Page<TaskId> getTaskIds(String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit) throws NotConnectedException, PermissionException {
RestPage<TaskStateData> page = null;
try {
page = restApi().getTaskStates(sid, from, to, mytasks, running, pending, finished, offset, limit, null);
} catch (NotConnectedRestException e) {
throw new NotConnectedException(e);
} catch (PermissionRestException e) {
throw new PermissionException(e);
}
List<TaskId> lTaskIds = new ArrayList<TaskId>(page.getList().size());
for (TaskStateData taskStateData : page.getList()) {
TaskInfoData taskInfo = taskStateData.getTaskInfo();
TaskIdData taskIdData = taskInfo.getTaskId();
JobId jobId = new JobIdImpl(taskInfo.getJobId().getId(), taskInfo.getJobId().getReadableName());
TaskId taskId = TaskIdImpl.createTaskId(jobId, taskIdData.getReadableName(), taskIdData.getId());
lTaskIds.add(taskId);
}
return new Page<TaskId>(lTaskIds, page.getSize());
}
use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerClient method renewSession.
@Override
public void renewSession() throws NotConnectedException {
Closer closer = Closer.create();
try {
LoginForm loginForm = new LoginForm();
loginForm.setUsername(connectionInfo.getLogin());
loginForm.setPassword(connectionInfo.getPassword());
if (connectionInfo.getCredentialFile() != null) {
FileInputStream inputStream = new FileInputStream(connectionInfo.getCredentialFile());
closer.register(inputStream);
loginForm.setCredential(inputStream);
}
sid = restApi().loginOrRenewSession(sid, loginForm);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
closer.close();
} catch (IOException e) {
// ignore
}
}
}
Aggregations