Search in sources :

Example 1 with HttpJsonResponse

use of org.eclipse.che.api.core.rest.HttpJsonResponse in project che by eclipse.

the class ApiEndpointAccessibilityChecker method start.

@PostConstruct
public void start() {
    try {
        final HttpJsonResponse pingResponse = httpJsonRequestFactory.fromUrl(apiEndpoint).setMethod(HttpMethod.GET).setTimeout(2000).request();
        if (pingResponse.getResponseCode() == HttpURLConnection.HTTP_OK) {
            return;
        }
    } catch (ApiException | IOException e) {
        LOG.error(e.getLocalizedMessage(), e);
    }
    LOG.error("The workspace agent has attempted to start, but it is unable to ping the Che server at " + apiEndpoint);
    LOG.error("The workspace agent has been forcefully stopped. " + "This error happens when the agent cannot resolve the location of the Che server. " + "This error can usually be fixed with additional configuration settings in /conf/che.properties. " + "The Che server will stop this workspace after a short timeout. " + "You can get help by posting your config, stacktrace and workspace /etc/hosts below as a GitHub issue.");
    // content of /etc/hosts file may provide clues on why the connection failed, e.g. how che-host is resolved
    try {
        LOG.info("Workspace /etc/hosts: " + IoUtil.readAndCloseQuietly(new FileInputStream(new File("/etc/hosts"))));
    } catch (Exception e) {
        LOG.info(e.getLocalizedMessage(), e);
    }
    System.exit(0);
}
Also used : IOException(java.io.IOException) HttpJsonResponse(org.eclipse.che.api.core.rest.HttpJsonResponse) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ApiException(org.eclipse.che.api.core.ApiException) ApiException(org.eclipse.che.api.core.ApiException) PostConstruct(javax.annotation.PostConstruct)

Example 2 with HttpJsonResponse

use of org.eclipse.che.api.core.rest.HttpJsonResponse 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)

Aggregations

IOException (java.io.IOException)2 ApiException (org.eclipse.che.api.core.ApiException)2 HttpJsonResponse (org.eclipse.che.api.core.rest.HttpJsonResponse)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 PostConstruct (javax.annotation.PostConstruct)1 Server (org.eclipse.che.api.core.model.machine.Server)1 HttpJsonRequest (org.eclipse.che.api.core.rest.HttpJsonRequest)1 WsAgentHealthStateDto (org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto)1