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