Search in sources :

Example 1 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.

the class NoVncSecuredTargetResolver method doResolve.

// package-protected for testing
InetSocketAddress doResolve(String sessionId, String jobId, String taskName) {
    if (sessionId == null || jobId == null || taskName == null) {
        LOGGER.warn("One of the web socket path parameter is missing (sessionId, jobId, taskName).");
        return null;
    }
    Session session = SharedSessionStore.getInstance().get(sessionId);
    if (session == null) {
        LOGGER.warn("Unknown sessionId.");
        return null;
    }
    SchedulerProxyUserInterface scheduler = session.getScheduler();
    try {
        TaskResult taskResult = scheduler.getTaskResult(jobId, taskName);
        List<String> paRemoteConnectionLines = retrievePaRemoteConnectionLines(session, jobId, taskResult);
        String taskId = retrieveTaskId(taskName, scheduler.getJobState(jobId));
        return resolveVncTargetFromLogs(paRemoteConnectionLines, jobId, taskId);
    } catch (NotConnectedException e) {
        LOGGER.warn("Failed to connect to scheduler", e);
    } catch (UnknownJobException e) {
        LOGGER.warn("Job does not exist", e);
    } catch (UnknownTaskException e) {
        LOGGER.warn("Task does not exist", e);
    } catch (PermissionException e) {
        LOGGER.warn("Not allowed to access task", e);
    }
    return null;
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 2 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.

the class DozerMappingTest method createJobState.

private JobState createJobState() {
    return new ClientJobState(new JobState() {

        @Override
        public void update(TaskInfo taskInfo) {
        }

        @Override
        public void update(JobInfo jobInfo) {
        }

        @Override
        public JobInfo getJobInfo() {
            return new JobInfoImpl();
        }

        @Override
        public ArrayList<TaskState> getTasks() {
            return new ArrayList<>(getHMTasks().values());
        }

        @Override
        public Map<TaskId, TaskState> getHMTasks() {
            TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(42, "job"), "remoteVisuTask", 1);
            TaskState value = new ClientTaskState(new TaskState() {

                @Override
                public void update(TaskInfo taskInfo) {
                }

                @Override
                public List<TaskState> getDependences() {
                    return null;
                }

                @Override
                public TaskInfo getTaskInfo() {
                    TaskInfoImpl taskInfo = new TaskInfoImpl();
                    taskInfo.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(42, "job"), "remoteVisuTask", 1));
                    return taskInfo;
                }

                @Override
                public int getMaxNumberOfExecutionOnFailure() {
                    return 0;
                }

                @Override
                public TaskState replicate() throws Exception {
                    return null;
                }

                @Override
                public int getIterationIndex() {
                    return 0;
                }

                @Override
                public int getReplicationIndex() {
                    return 0;
                }
            });
            return Collections.singletonMap(taskId, value);
        }

        @Override
        public String getOwner() {
            return null;
        }

        @Override
        public JobType getType() {
            return null;
        }
    });
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ArrayList(java.util.ArrayList) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl) ClientTaskState(org.ow2.proactive.scheduler.task.ClientTaskState) TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) JobType(org.ow2.proactive.scheduler.common.job.JobType) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) JobState(org.ow2.proactive.scheduler.common.job.JobState) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl) Map(java.util.Map) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) ClientTaskState(org.ow2.proactive.scheduler.task.ClientTaskState)

Example 3 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId 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 4 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId 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 5 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.

the class GetTaskOutputCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        String output = scheduler.taskLog(currentContext.getSessionId(), jobId, taskId);
        resultStack(currentContext).push(output);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", output);
        }
    } catch (Exception e) {
        handleError(String.format("An error occurred while retrieving %s output:", task()), e, currentContext);
    }
}
Also used : SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Aggregations

TaskId (org.ow2.proactive.scheduler.common.task.TaskId)100 Test (org.junit.Test)43 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)43 JobId (org.ow2.proactive.scheduler.common.job.JobId)33 ArrayList (java.util.ArrayList)27 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)25 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)22 HashMap (java.util.HashMap)18 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)18 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)15 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)12 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)12 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)11 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)11 List (java.util.List)10 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)9 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)9