Search in sources :

Example 1 with WsAgentHealthStateDto

use of org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto in project che by eclipse.

the class WorkspaceServiceTest method stateOfWsAgentShouldBeChecked.

@Test
public void stateOfWsAgentShouldBeChecked() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    workspace.setStatus(RUNNING);
    WsAgentHealthStateDto wsAgentState = newDto(WsAgentHealthStateDto.class);
    WorkspaceRuntimeImpl runtime = mock(WorkspaceRuntimeImpl.class);
    MachineImpl machine = mock(MachineImpl.class);
    when(runtime.getDevMachine()).thenReturn(machine);
    when(wsAgentHealthChecker.check(machine)).thenReturn(wsAgentState);
    workspace.setRuntime(runtime);
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/" + workspace.getId() + "/check");
    verify(wsAgentHealthChecker).check(machine);
    assertEquals(RUNNING, wsAgentState.getWorkspaceStatus());
    assertEquals(200, response.getStatusCode());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) Test(org.testng.annotations.Test)

Example 2 with WsAgentHealthStateDto

use of org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto in project che by eclipse.

the class WsAgentHealthCheckerTest method stateShouldBeReturnedWithStatusNotFoundIfWorkspaceAgentIsNotExist.

@Test
public void stateShouldBeReturnedWithStatusNotFoundIfWorkspaceAgentIsNotExist() throws Exception {
    when(machineRuntimeInfo.getServers()).thenReturn(emptyMap());
    WsAgentHealthStateDto result = checker.check(devMachine);
    assertEquals(NOT_FOUND.getStatusCode(), result.getCode());
}
Also used : WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) Test(org.testng.annotations.Test)

Example 3 with WsAgentHealthStateDto

use of org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto 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 WsAgentHealthStateDto

use of org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto in project che by eclipse.

the class WorkspaceService method checkAgentHealth.

@GET
@Path("/{id}/check")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get state of the workspace agent by the workspace id")
@ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested workspace entity"), @ApiResponse(code = 404, message = "The workspace with specified id does not exist"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WsAgentHealthStateDto checkAgentHealth(@ApiParam(value = "Workspace id") @PathParam("id") String id) throws NotFoundException, ServerException {
    final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
    if (WorkspaceStatus.RUNNING != workspace.getStatus()) {
        return newDto(WsAgentHealthStateDto.class).withWorkspaceStatus(workspace.getStatus());
    }
    final MachineImpl devMachine = workspace.getRuntime().getDevMachine();
    if (devMachine == null) {
        return newDto(WsAgentHealthStateDto.class).withWorkspaceStatus(workspace.getStatus()).withCode(NOT_FOUND.getStatusCode()).withReason("Workspace Agent isn't available if Dev machine isn't RUNNING");
    }
    final WsAgentHealthStateDto check = agentHealthChecker.check(devMachine);
    check.setWorkspaceStatus(workspace.getStatus());
    return check;
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with WsAgentHealthStateDto

use of org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto in project che by eclipse.

the class WsAgentHealthCheckerTest method returnStateWithNotFoundCode.

@Test
public void returnStateWithNotFoundCode() throws Exception {
    doReturn(emptyMap()).when(machineRuntimeInfo).getServers();
    final WsAgentHealthStateDto check = checker.check(devMachine);
    assertEquals(NOT_FOUND.getStatusCode(), check.getCode());
    assertEquals("Workspace Agent not available", check.getReason());
}
Also used : WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) Test(org.testng.annotations.Test)

Aggregations

WsAgentHealthStateDto (org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto)7 Test (org.testng.annotations.Test)5 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)2 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)2 Response (com.jayway.restassured.response.Response)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ApiException (org.eclipse.che.api.core.ApiException)1 Server (org.eclipse.che.api.core.model.machine.Server)1 HttpJsonRequest (org.eclipse.che.api.core.rest.HttpJsonRequest)1 HttpJsonResponse (org.eclipse.che.api.core.rest.HttpJsonResponse)1 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)1 WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)1