use of org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto in project che by eclipse.
the class WorkspaceServiceLinksInjector method injectRuntimeLinks.
protected void injectRuntimeLinks(WorkspaceDto workspace, URI ideUri, UriBuilder uriBuilder, ServiceContext serviceContext) {
final WorkspaceRuntimeDto runtime = workspace.getRuntime();
// add links for running workspace
if (workspace.getStatus() == RUNNING && runtime != null) {
runtime.getLinks().add(createLink("DELETE", uriBuilder.clone().path(WorkspaceService.class, "stop").build(workspace.getId()).toString(), LINK_REL_STOP_WORKSPACE));
runtime.getMachines().forEach(machine -> injectMachineLinks(machine, serviceContext));
final MachineDto devMachine = runtime.getDevMachine();
if (devMachine != null) {
final Collection<ServerDto> servers = devMachine.getRuntime().getServers().values();
servers.stream().filter(server -> WSAGENT_REFERENCE.equals(server.getRef())).findAny().ifPresent(wsAgent -> {
runtime.getLinks().add(createLink("GET", wsAgent.getUrl(), WSAGENT_REFERENCE));
runtime.getLinks().add(createLink("GET", UriBuilder.fromUri(wsAgent.getUrl()).path("ws").scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").build().toString(), WSAGENT_WEBSOCKET_REFERENCE));
devMachine.getLinks().add(createLink("GET", UriBuilder.fromUri(wsAgent.getUrl()).scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").path("/ws").build().toString(), WSAGENT_WEBSOCKET_REFERENCE));
});
servers.stream().filter(server -> TERMINAL_REFERENCE.equals(server.getRef())).findAny().ifPresent(terminal -> {
devMachine.getLinks().add(createLink("GET", UriBuilder.fromUri(terminal.getUrl()).scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").path("/pty").build().toString(), TERMINAL_REFERENCE));
devMachine.getLinks().add(createLink("GET", UriBuilder.fromUri(terminal.getUrl()).scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").path("/connect").build().toString(), EXEC_AGENT_REFERENCE));
});
}
}
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto in project che by eclipse.
the class DtoConverter method asDto.
/** Converts {@link WorkspaceRuntime} to {@link WorkspaceRuntimeDto}. */
public static WorkspaceRuntimeDto asDto(WorkspaceRuntime runtime) {
if (runtime == null) {
return null;
}
final WorkspaceRuntimeDto runtimeDto = newDto(WorkspaceRuntimeDto.class).withActiveEnv(runtime.getActiveEnv()).withRootFolder(runtime.getRootFolder());
runtimeDto.withMachines(runtime.getMachines().stream().map(org.eclipse.che.api.machine.server.DtoConverter::asDto).collect(toList()));
if (runtime.getDevMachine() != null) {
runtimeDto.withDevMachine(org.eclipse.che.api.machine.server.DtoConverter.asDto(runtime.getDevMachine()));
}
return runtimeDto;
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto in project che by eclipse.
the class WorkspaceEventsHandlerTest method onWsAgentOutputEventReceivedTest.
@Test
public void onWsAgentOutputEventReceivedTest() throws Exception {
WorkspaceRuntimeDto runtime = mock(WorkspaceRuntimeDto.class);
WorkspaceConfigDto workspaceConfig = mock(WorkspaceConfigDto.class);
when(workspace.getRuntime()).thenReturn(runtime);
MachineDto devMachine = mock(MachineDto.class);
when(devMachine.getWorkspaceId()).thenReturn(WORKSPACE_ID);
when(devMachine.getId()).thenReturn(MACHINE_NAME);
when(runtime.getDevMachine()).thenReturn(devMachine);
when(runtime.getActiveEnv()).thenReturn(ACTIVE_ENV);
when(workspace.getConfig()).thenReturn(workspaceConfig);
Map<String, EnvironmentDto> environments = new HashMap<>(3);
EnvironmentDto environment = mock(EnvironmentDto.class);
environments.put(ACTIVE_ENV, environment);
when(workspaceConfig.getEnvironments()).thenReturn(environments);
MachineConfigDto devMachineConfig = mock(MachineConfigDto.class);
when(devMachineConfig.getName()).thenReturn(MACHINE_NAME);
workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.wsAgentLogSubscriptionHandler.onMessageReceived("");
verify(eventBus).fireEvent(Matchers.<EnvironmentOutputEvent>anyObject());
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto in project che by eclipse.
the class MachineStatusHandler method onMachineStatusChanged.
@Override
public void onMachineStatusChanged(final MachineStatusChangedEvent event) {
final String machineId = event.getMachineId();
final String workspaceId = event.getWorkspaceId();
workspaceServiceClient.getWorkspace(workspaceId).then(workspace -> {
WorkspaceRuntimeDto workspaceRuntime = workspace.getRuntime();
if (workspaceRuntime == null) {
return;
}
appContext.setWorkspace(workspace);
switch(event.getEventType()) {
case CREATING:
handleMachineCreating(machineId, workspaceRuntime);
break;
case RUNNING:
handleMachineRunning(machineId, workspaceRuntime);
break;
case ERROR:
handleMachineError(event);
break;
}
});
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto in project che by eclipse.
the class WorkspaceEventsHandlerTest method shouldSubscribesOnWsAgentOutputWhenWorkspaceIsStarting.
// @Test disabled because of GWT timer usage
public void shouldSubscribesOnWsAgentOutputWhenWorkspaceIsStarting() throws Exception {
WorkspaceRuntimeDto runtime = mock(WorkspaceRuntimeDto.class);
WorkspaceConfigDto workspaceConfig = mock(WorkspaceConfigDto.class);
when(workspaceStatusEvent.getEventType()).thenReturn(STARTING);
when(workspace.getRuntime()).thenReturn(runtime);
when(runtime.getActiveEnv()).thenReturn(ACTIVE_ENV);
when(workspace.getConfig()).thenReturn(workspaceConfig);
Map<String, EnvironmentDto> environments = new HashMap<>(3);
EnvironmentDto environment = mock(EnvironmentDto.class);
environments.put(ACTIVE_ENV, environment);
when(workspaceConfig.getEnvironments()).thenReturn(environments);
MachineConfigDto devMachineConfig = mock(MachineConfigDto.class);
when(devMachineConfig.getName()).thenReturn(MACHINE_NAME);
workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.workspaceStatusSubscriptionHandler.onMessageReceived(workspaceStatusEvent);
verify(workspacePromise).then(workspaceCaptor.capture());
workspaceCaptor.getValue().apply(workspace);
verify(messageBus, times(2)).subscribe(eq(WS_AGENT_LOG_CHANNEL), (MessageHandler) anyObject());
}
Aggregations