Search in sources :

Example 1 with CheckResult

use of com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult in project cloudbreak by hortonworks.

the class FreeIpaInstanceHealthDetailsServiceTest method getErrorPayloadWithMixedResults.

private RPCResponse<CheckResult> getErrorPayloadWithMixedResults(String host) {
    CheckResult checkResult = new CheckResult();
    checkResult.setHost(host);
    CheckEntry healthy = new CheckEntry();
    healthy.setStatus("HEALTHY");
    healthy.setCheckId("hId");
    healthy.setPlugin("good");
    CheckEntry unhealthy = new CheckEntry();
    unhealthy.setStatus("UNHEALTHY");
    unhealthy.setCheckId("unhId");
    unhealthy.setPlugin("bad");
    checkResult.setChecks(List.of(healthy, unhealthy));
    PluginStatusEntry healthyPlugin = new PluginStatusEntry();
    healthyPlugin.setPlugin("healthyPlugin");
    healthyPlugin.setStatus("HEALTHY");
    healthyPlugin.setHost(host);
    PluginStatusEntry unhealthyPlugin = new PluginStatusEntry();
    unhealthyPlugin.setPlugin("unhealthyPlugin");
    unhealthyPlugin.setStatus("UNHEALTHY");
    unhealthyPlugin.setHost(host);
    checkResult.setPluginStats(List.of(healthyPlugin, unhealthyPlugin));
    RPCResponse<CheckResult> badResponse;
    badResponse = new RPCResponse<>();
    badResponse.setResult(checkResult);
    RPCMessage message = new RPCMessage();
    message.setCode(503);
    message.setMessage(JsonUtil.writeValueAsStringSilentSafe(checkResult));
    badResponse.setMessages(List.of(message));
    return badResponse;
}
Also used : CheckEntry(com.sequenceiq.freeipa.client.healthcheckmodel.CheckEntry) PluginStatusEntry(com.sequenceiq.freeipa.client.healthcheckmodel.PluginStatusEntry) CheckResult(com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult) RPCMessage(com.sequenceiq.cloudbreak.client.RPCMessage)

Example 2 with CheckResult

use of com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult in project cloudbreak by hortonworks.

the class FreeIpaInstanceHealthDetailsServiceTest method getGoodPayload.

private RPCResponse<CheckResult> getGoodPayload(String host) {
    CheckResult checkResult = new CheckResult();
    checkResult.setHost(host);
    RPCResponse<CheckResult> goodResponse;
    goodResponse = new RPCResponse<>();
    goodResponse.setResult(checkResult);
    RPCMessage message = new RPCMessage();
    message.setCode(200);
    message.setMessage("success");
    goodResponse.setMessages(List.of(message));
    return goodResponse;
}
Also used : CheckResult(com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult) RPCMessage(com.sequenceiq.cloudbreak.client.RPCMessage)

Example 3 with CheckResult

use of com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult in project cloudbreak by hortonworks.

the class FreeipaHealthCheckController method healthCheck.

@RequestMapping("/freeipahealthcheck")
public ResponseEntity<CheckResult> healthCheck(@PathVariable("mock_uuid") String mockUuid) {
    SpiDto read = spiStoreService.read(mockUuid.replace(":9443", ""));
    Optional<CloudVmMetaDataStatus> first = read.getVmMetaDataStatuses().stream().findFirst();
    CheckResult checkResult = new CheckResult();
    if (first.isPresent() && first.get().getCloudVmInstanceStatus().getStatus() == InstanceStatus.STARTED) {
        checkResult.setHost(first.get().getMetaData().getPublicIp());
        checkResult.setStatus("healthy");
        return ResponseEntity.ok(checkResult);
    }
    return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
}
Also used : CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CheckResult(com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult) SpiDto(com.sequenceiq.mock.spi.SpiDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CheckResult

use of com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult in project cloudbreak by hortonworks.

the class FreeIpaInstanceHealthDetailsServiceTest method getErrorPayload.

private RPCResponse<CheckResult> getErrorPayload(String host) {
    CheckResult checkResult = new CheckResult();
    checkResult.setHost(host);
    RPCResponse<CheckResult> badResponse;
    badResponse = new RPCResponse<>();
    badResponse.setResult(checkResult);
    RPCMessage message = new RPCMessage();
    message.setCode(503);
    message.setMessage("failure");
    badResponse.setMessages(List.of(message));
    return badResponse;
}
Also used : CheckResult(com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult) RPCMessage(com.sequenceiq.cloudbreak.client.RPCMessage)

Example 5 with CheckResult

use of com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult in project cloudbreak by hortonworks.

the class FreeIpaInstanceHealthDetailsServiceTest method testCheckFreeIpaHealthUnhealthyNodeWithFiltering.

@Test
public void testCheckFreeIpaHealthUnhealthyNodeWithFiltering() throws Exception {
    FreeIpaHealthCheckClient mockIpaHealthClient = Mockito.mock(FreeIpaHealthCheckClient.class);
    Mockito.when(healthCheckAvailabilityChecker.isCdpFreeIpaHeathAgentAvailable(any())).thenReturn(true);
    Mockito.when(freeIpaHealthCheckClientFactory.getClient(any(), any())).thenReturn(mockIpaHealthClient);
    Mockito.when(mockIpaHealthClient.nodeHealth()).thenReturn(getErrorPayloadWithMixedResults(HOST));
    InstanceMetaData instanceMetaData = getInstance();
    Stack stack = getStack(Set.of(instanceMetaData));
    RPCResponse<Boolean> response = underTest.checkFreeIpaHealth(stack, instanceMetaData);
    assertFalse(response.getResult());
    assertEquals("node health check", response.getFirstRpcMessage().getName());
    CheckResult checkResult = JsonUtil.readValue(response.getFirstRpcMessage().getMessage(), CheckResult.class);
    assertEquals(1, checkResult.getChecks().size());
    assertEquals("UNHEALTHY", checkResult.getChecks().get(0).getStatus());
    assertEquals(1, checkResult.getPluginStats().size());
    assertEquals("UNHEALTHY", checkResult.getPluginStats().get(0).getStatus());
    assertEquals(HOST, checkResult.getHost());
    assertEquals(HOST, checkResult.getPluginStats().get(0).getHost());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FreeIpaHealthCheckClient(com.sequenceiq.freeipa.client.FreeIpaHealthCheckClient) CheckResult(com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

CheckResult (com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult)6 RPCMessage (com.sequenceiq.cloudbreak.client.RPCMessage)4 CheckEntry (com.sequenceiq.freeipa.client.healthcheckmodel.CheckEntry)2 PluginStatusEntry (com.sequenceiq.freeipa.client.healthcheckmodel.PluginStatusEntry)2 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)1 FreeIpaHealthCheckClient (com.sequenceiq.freeipa.client.FreeIpaHealthCheckClient)1 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 SpiDto (com.sequenceiq.mock.spi.SpiDto)1 Test (org.junit.jupiter.api.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1