Search in sources :

Example 1 with Server

use of org.eclipse.che.api.core.model.machine.Server in project che by eclipse.

the class ServerPresenter method getServers.

private List<ServerEntity> getServers(Machine machine) {
    MachineRuntimeInfo machineRuntime = machine.getRuntime();
    if (machineRuntime == null) {
        return emptyList();
    }
    Map<String, ? extends Server> servers = machineRuntime.getServers();
    List<ServerEntity> serversList = new ArrayList<>(servers.size());
    for (Map.Entry<String, ? extends Server> entry : servers.entrySet()) {
        String exposedPort = entry.getKey();
        Server descriptor = entry.getValue();
        ServerEntity serverEntity = entityFactory.createServer(exposedPort, descriptor);
        serversList.add(serverEntity);
    }
    return serversList;
}
Also used : Server(org.eclipse.che.api.core.model.machine.Server) MachineRuntimeInfo(org.eclipse.che.api.core.model.machine.MachineRuntimeInfo) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with Server

use of org.eclipse.che.api.core.model.machine.Server in project che by eclipse.

the class WsAgentPingRequestFactory method createRequest.

/**
     * Creates request which can check if workspace agent is pinging.
     *
     * @param machine
     *         machine instance
     * @return instance of {@link HttpJsonRequest}
     * @throws ServerException
     *         if internal server error occurred
     */
public HttpJsonRequest createRequest(Machine machine) throws ServerException {
    Map<String, ? extends Server> servers = machine.getRuntime().getServers();
    Server wsAgentServer = servers.get(Constants.WS_AGENT_PORT);
    if (wsAgentServer == null) {
        LOG.error("{} WorkspaceId: {}, DevMachine Id: {}, found servers: {}", WS_AGENT_SERVER_NOT_FOUND_ERROR, machine.getWorkspaceId(), machine.getId(), servers);
        throw new ServerException(WS_AGENT_SERVER_NOT_FOUND_ERROR);
    }
    String wsAgentPingUrl = wsAgentServer.getProperties().getInternalUrl();
    if (isNullOrEmpty(wsAgentPingUrl)) {
        LOG.error(WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR);
        throw new ServerException(WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR);
    }
    // we will always obtain not found response
    if (!wsAgentPingUrl.endsWith("/")) {
        wsAgentPingUrl = wsAgentPingUrl.concat("/");
    }
    return httpJsonRequestFactory.fromUrl(wsAgentPingUrl).setMethod(HttpMethod.GET).setTimeout(wsAgentPingConnectionTimeoutMs);
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) Server(org.eclipse.che.api.core.model.machine.Server)

Example 3 with Server

use of org.eclipse.che.api.core.model.machine.Server in project che by eclipse.

the class WsAgentHealthCheckerImpl method check.

@Override
public WsAgentHealthStateDto check(Machine machine) throws ServerException {
    Server wsAgent = getWsAgent(machine);
    final WsAgentHealthStateDto agentHealthStateDto = newDto(WsAgentHealthStateDto.class);
    if (wsAgent == null) {
        return agentHealthStateDto.withCode(NOT_FOUND.getStatusCode()).withReason("Workspace Agent not available");
    }
    try {
        final HttpJsonRequest pingRequest = createPingRequest(machine);
        final HttpJsonResponse response = pingRequest.request();
        return agentHealthStateDto.withCode(response.getResponseCode());
    } catch (ApiException | IOException e) {
        return agentHealthStateDto.withCode(SERVICE_UNAVAILABLE.getStatusCode()).withReason(e.getMessage());
    }
}
Also used : Server(org.eclipse.che.api.core.model.machine.Server) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) IOException(java.io.IOException) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) HttpJsonResponse(org.eclipse.che.api.core.rest.HttpJsonResponse) ApiException(org.eclipse.che.api.core.ApiException)

Example 4 with Server

use of org.eclipse.che.api.core.model.machine.Server in project che by eclipse.

the class ProcessesPanelPresenter method getSshServerAddress.

/**
     * Returns the ssh service address in format - host:port (example - localhost:32899)
     *
     * @param machine
     *         machine to retrieve address
     * @return ssh service address in format host:port
     */
private String getSshServerAddress(Machine machine) {
    Map<String, ? extends Server> servers = machine.getRuntime().getServers();
    final Server sshServer = servers.get(SSH_PORT + "/tcp");
    return sshServer != null ? sshServer.getAddress() : null;
}
Also used : Server(org.eclipse.che.api.core.model.machine.Server)

Aggregations

Server (org.eclipse.che.api.core.model.machine.Server)4 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ApiException (org.eclipse.che.api.core.ApiException)1 ServerException (org.eclipse.che.api.core.ServerException)1 MachineRuntimeInfo (org.eclipse.che.api.core.model.machine.MachineRuntimeInfo)1 HttpJsonRequest (org.eclipse.che.api.core.rest.HttpJsonRequest)1 HttpJsonResponse (org.eclipse.che.api.core.rest.HttpJsonResponse)1 WsAgentHealthStateDto (org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto)1