use of org.ow2.proactive.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method getLiveLogJob.
@Override
public String getLiveLogJob(String sessionId, String jobId, boolean allLogs) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException, LogForwardingRestException, IOException {
try {
Scheduler scheduler = checkAccess(sessionId, "/scheduler/jobs/" + jobId + "/livelog");
Session session = sessionStore.get(sessionId);
JobState jobState = scheduler.getJobState(jobId);
boolean isFinished = jobState != null && jobState.isFinished();
int availableLinesCount = session.getJobsOutputController().availableLinesCount(jobId);
if (allLogs) {
if (!isFinished || availableLinesCount > 0) {
return session.getJobsOutputController().getAllLogs(jobId);
} else {
session.getJobsOutputController().removeAppender(jobId);
return "";
}
} else {
if (!isFinished || availableLinesCount > 0) {
return session.getJobsOutputController().getNewLogs(jobId);
} else {
session.getJobsOutputController().removeAppender(jobId);
return "";
}
}
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (LogForwardingException e) {
throw new LogForwardingRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.exception.NotConnectedException 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 = null;
try {
session = SharedSessionStore.getInstance().get(sessionId);
} catch (NotConnectedRestException e) {
LOGGER.warn("Session not valid.");
return null;
}
SchedulerProxyUserInterface scheduler = session.getScheduler();
try {
TaskState taskState = scheduler.getTaskState(JobIdImpl.makeJobId(jobId), taskName);
if (taskState != null && taskState.getTaskInfo() != null && taskState.getTaskInfo().isVisualizationActivated() && taskState.getTaskInfo().getVisualizationConnectionString() != null) {
List<String> connectionInfoRetrievedFromTaskState = Collections.singletonList(taskState.getTaskInfo().getVisualizationConnectionString());
return resolveVncTarget(connectionInfoRetrievedFromTaskState, jobId, taskState.getId().value());
}
TaskResult taskResult = scheduler.getTaskResult(jobId, taskName);
List<String> paRemoteConnectionLinesRetrievedFromLogs = retrievePaRemoteConnectionLines(session, jobId, taskResult);
return resolveVncTarget(paRemoteConnectionLinesRetrievedFromLogs, jobId, taskState.getId().value());
} 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;
}
use of org.ow2.proactive.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateListener method getSchedulerStatus.
public SchedulerStatus getSchedulerStatus(Scheduler scheduler) throws PermissionException, NotConnectedException {
SchedulerStatus status = state.getStatus();
if (status == null) {
status = scheduler.getStatus();
state.setStatus(status);
}
return status;
}
use of org.ow2.proactive.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class NoVncSecuredTargetResolverTest method mockSchedulerState.
@Before
public void mockSchedulerState() throws NotConnectedException, UnknownJobException, PermissionException, UnknownTaskException {
JobState jobState = mock(JobState.class);
when(schedulerMock.getJobState("42")).thenReturn(jobState);
TaskId taskId = mock(TaskId.class);
when(taskId.value()).thenReturn("1");
TaskState taskState = mock(TaskState.class);
when(taskState.getName()).thenReturn("remoteVisuTask");
when(taskState.getId()).thenReturn(taskId);
when(schedulerMock.getTaskState(JobIdImpl.makeJobId("42"), "remoteVisuTask")).thenReturn(taskState);
when(jobState.getHMTasks()).thenReturn(Collections.singletonMap(taskId, taskState));
JobState jobState2 = mock(JobState.class);
when(schedulerMock.getJobState("43")).thenReturn(jobState2);
TaskId taskId2 = mock(TaskId.class);
when(taskId2.value()).thenReturn("1");
TaskState taskState2 = mock(TaskState.class);
TaskInfo taskInfo2 = mock(TaskInfo.class);
when(taskState2.getTaskInfo()).thenReturn(taskInfo2);
when(taskState2.getName()).thenReturn("remoteVisuTask");
when(taskState2.getId()).thenReturn(taskId2);
when(schedulerMock.getTaskState(JobIdImpl.makeJobId("43"), "remoteVisuTask")).thenReturn(taskState2);
when(taskInfo2.isVisualizationActivated()).thenReturn(true);
when(taskInfo2.getVisualizationConnectionString()).thenReturn("PA_REMOTE_CONNECTION;43;1;vnc;node.grid.com:5900");
}
use of org.ow2.proactive.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SessionSharingTest method sessions_are_shared_rm_login.
@Test
public void sessions_are_shared_rm_login() throws Exception {
String sessionId = rmRest.rmConnect("login", "pw");
assertTrue(studioRest.getWorkflows(sessionId).isEmpty());
when(schedulerMock.freeze()).thenReturn(true);
boolean frozen = schedulerRest.freezeScheduler(sessionId);
assertTrue(frozen);
when(rmMock.getState()).thenReturn(new RMState(new RMStateNodeUrls(new HashSet<String>(), new HashSet<String>(), new HashSet<String>()), Long.valueOf(-1)));
RMState rmState = rmRest.getState(sessionId);
assertNotNull(rmState);
rmRest.rmDisconnect(sessionId);
try {
rmRest.getState(sessionId);
fail();
} catch (NotConnectedException expected) {
// expected
}
try {
schedulerRest.freezeScheduler(sessionId);
fail();
} catch (NotConnectedRestException expected) {
// expected
}
}
Aggregations