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;
}
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);
}
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());
}
}
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;
}
Aggregations