Search in sources :

Example 1 with ServerDto

use of org.eclipse.che.api.machine.shared.dto.ServerDto 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));
            });
        }
    }
}
Also used : WorkspaceRuntimeDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto) ServerDto(org.eclipse.che.api.machine.shared.dto.ServerDto) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto)

Aggregations

MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)1 ServerDto (org.eclipse.che.api.machine.shared.dto.ServerDto)1 WorkspaceRuntimeDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto)1