Search in sources :

Example 21 with PermissionException

use of org.ow2.proactive.scheduler.common.exception.PermissionException in project scheduling by ow2-proactive.

the class SchedulerStateRestLiveLogsTest method verifyListenAndGetAppender.

private Appender verifyListenAndGetAppender(String jobId) throws NotConnectedException, UnknownJobException, PermissionException, LogForwardingException {
    ArgumentCaptor<AppenderProvider> appenderProviderArgumentCaptor = ArgumentCaptor.forClass(AppenderProvider.class);
    verify(scheduler).listenJobLogs(eq(jobId), appenderProviderArgumentCaptor.capture());
    AppenderProvider appenderProvider = appenderProviderArgumentCaptor.getValue();
    return appenderProvider.getAppender();
}
Also used : AppenderProvider(org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider)

Example 22 with PermissionException

use of org.ow2.proactive.scheduler.common.exception.PermissionException in project scheduling by ow2-proactive.

the class NoVncSecuredTargetResolverTest method mockSchedulerState.

@Before
public void mockSchedulerState() throws NotConnectedException, UnknownJobException, PermissionException {
    JobState jobState = mock(JobState.class);
    when(schedulerMock.getJobState("42")).thenReturn(jobState);
    TaskState taskState = mock(TaskState.class);
    when(taskState.getName()).thenReturn("remoteVisuTask");
    TaskId taskId = mock(TaskId.class);
    when(taskId.value()).thenReturn("1");
    when(taskState.getId()).thenReturn(taskId);
    when(jobState.getHMTasks()).thenReturn(Collections.singletonMap(taskId, taskState));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Before(org.junit.Before)

Example 23 with PermissionException

use of org.ow2.proactive.scheduler.common.exception.PermissionException in project scheduling by ow2-proactive.

the class RestJobTrackerImpl method removeAwaitedJob.

@Override
public void removeAwaitedJob(String id) {
    AwaitedJob aj = jobDatabase.getAwaitedJob(id);
    if (aj == null) {
        logger.warn("Job " + id + " not in the awaited list");
        return;
    }
    logger.debug("Removing knowledge of job " + id);
    String pullUrl = aj.getPullURL();
    String pushUrl = aj.getPushURL();
    Path remotePullFolder = null;
    Path remotePushFolder = null;
    try {
        remotePullFolder = Paths.get(new URI(pullUrl));
        remotePushFolder = Paths.get(new URI(pushUrl));
    } catch (Exception e) {
        logger.error("Could not remove data for job " + id, e);
        return;
    }
    if (aj.isIsolateTaskOutputs()) {
        Path tmp = remotePullFolder.getParent();
        if (tmp != null) {
            remotePullFolder = tmp;
        }
    }
    Set<Path> foldersToDelete = new HashSet<>();
    foldersToDelete.add(remotePullFolder.getParent());
    if (!remotePullFolder.getParent().equals(remotePushFolder.getParent())) {
        foldersToDelete.add(remotePushFolder.getParent());
    }
    RemoteSource remoteSource = new RemoteSource(IDataSpaceClient.Dataspace.USER);
    remoteSource.setType(FileType.FOLDER);
    for (Path path : foldersToDelete) {
        String location = path.toUri().toString();
        try {
            if (!logger.isTraceEnabled()) {
                logger.debug("Deleting directory " + location);
                remoteSource.setPath(location);
                restDataSpaceClient.delete(remoteSource);
            }
        } catch (NotConnectedException | PermissionException e) {
            logger.warn("Could not delete temporary files at location " + location + " .", e);
        }
    }
    jobDatabase.removeAwaitedJob(id);
    try {
        jobDatabase.commit();
    } catch (IOException e) {
        logger.error("Could not save status file after removing job " + id, e);
    }
}
Also used : Path(java.nio.file.Path) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) RemoteSource(org.ow2.proactive.scheduler.rest.ds.RemoteSource) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) IOException(java.io.IOException) AwaitedJob(org.ow2.proactive.scheduler.smartproxy.common.AwaitedJob) URI(java.net.URI) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 24 with PermissionException

use of org.ow2.proactive.scheduler.common.exception.PermissionException 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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) RemoteSource(org.ow2.proactive.scheduler.rest.ds.RemoteSource) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) AwaitedTask(org.ow2.proactive.scheduler.smartproxy.common.AwaitedTask) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) File(java.io.File) LocalDestination(org.ow2.proactive.scheduler.rest.ds.LocalDestination)

Example 25 with PermissionException

use of org.ow2.proactive.scheduler.common.exception.PermissionException 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);
    }
}
Also used : SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState) ArrayList(java.util.ArrayList) JobState(org.ow2.proactive.scheduler.common.job.JobState) JobId(org.ow2.proactive.scheduler.common.job.JobId) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException)

Aggregations

PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)64 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)62 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)46 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)46 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)44 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)39 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)34 Path (javax.ws.rs.Path)32 Produces (javax.ws.rs.Produces)30 GET (javax.ws.rs.GET)26 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)25 JobState (org.ow2.proactive.scheduler.common.job.JobState)21 GZIP (org.jboss.resteasy.annotations.GZIP)17 JobAlreadyFinishedException (org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)16 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)16 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)16 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)15