Search in sources :

Example 31 with NotConnectedException

use of org.ow2.proactive.scheduler.common.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 sourceFile;
    try {
        List<String> userSpaces = getUserSpaceURIs();
        List<String> outputSpaces = Arrays.asList(Tools.dataSpaceConfigPropertyToUrls(awaitedjob.getOutputSpaceURL()));
        sourceFile = extractRelativePath(userSpaces, outputSpaces);
        if (sourceFile == null) {
            if (awaitedjob.isAutomaticTransfer()) {
                logger.error("Could not extract remote path using inputSpace=" + outputSpaces + " and userSpace=" + userSpaces);
            } else {
                throw new IllegalArgumentException("Could not extract remote path using outputSpace=" + outputSpaces + " and userSpace=" + userSpaces);
            }
        }
    } 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 32 with NotConnectedException

use of org.ow2.proactive.scheduler.common.exception.NotConnectedException 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 33 with NotConnectedException

use of org.ow2.proactive.scheduler.common.exception.NotConnectedException 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 34 with NotConnectedException

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

the class RestSmartProxyImpl method uploadInputFilesForTask.

private void uploadInputFilesForTask(String localInputFolderPath, String remotePath, Task task) throws NotConnectedException, PermissionException {
    logger.debug("Pushing files for task " + task.getName());
    List<String> includes = Lists.newArrayList();
    List<String> excludes = Lists.newArrayList();
    List<InputSelector> inputFilesList = task.getInputFilesList();
    if (inputFilesList != null) {
        for (InputSelector is : inputFilesList) {
            addfileSelection(is.getInputFiles(), includes, excludes);
        }
    }
    LocalDirSource source = new LocalDirSource(localInputFolderPath);
    source.setIncludes(includes);
    source.setExcludes(excludes);
    RemoteDestination dest = new RemoteDestination(USER, remotePath);
    restDataSpaceClient.upload(source, dest);
}
Also used : RemoteDestination(org.ow2.proactive.scheduler.rest.ds.RemoteDestination) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector) LocalDirSource(org.ow2.proactive.scheduler.rest.ds.LocalDirSource)

Example 35 with NotConnectedException

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

the class SchedulerStateRestSecurityTest method testAllMethodsAreSecured.

// call all interface's methods using reflection
@Test
public void testAllMethodsAreSecured() throws Exception {
    for (Method method : SchedulerRestInterface.class.getMethods()) {
        if (methodShouldBeSecured(method)) {
            Object[] params = createMethodParameters(method);
            try {
                // by default we are not connected, any call should fail
                method.invoke(restInterface, params);
                fail(method + " should throw a NotConnectedException");
            } catch (InvocationTargetException exception) {
                if (!exception.getCause().getClass().equals(NotConnectedRestException.class) && !exception.getCause().getCause().getClass().equals(NotConnectedRestException.class)) {
                    fail(method + " should throw a NotConnectedException");
                }
            }
        }
    }
}
Also used : NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Aggregations

NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)85 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)76 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)54 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)53 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)47 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)44 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)36 Path (javax.ws.rs.Path)33 GET (javax.ws.rs.GET)29 Produces (javax.ws.rs.Produces)28 ImmediateService (org.objectweb.proactive.annotation.ImmediateService)28 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)26 IOException (java.io.IOException)25 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)25 JobAlreadyFinishedException (org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException)24 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)24 JobId (org.ow2.proactive.scheduler.common.job.JobId)23 SchedulerException (org.ow2.proactive.scheduler.common.exception.SchedulerException)20 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)20 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)20