Search in sources :

Example 6 with HealthDetailsFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method createHealthDetails.

private HealthDetailsFreeIpaResponse createHealthDetails(InstanceStatus status1, InstanceStatus status2) {
    HealthDetailsFreeIpaResponse response = new HealthDetailsFreeIpaResponse();
    NodeHealthDetails healthDetails1 = new NodeHealthDetails();
    healthDetails1.setInstanceId("i-1");
    healthDetails1.setStatus(status1);
    NodeHealthDetails healthDetails2 = new NodeHealthDetails();
    healthDetails2.setInstanceId("i-2");
    healthDetails2.setStatus(status2);
    response.setNodeHealthDetails(List.of(healthDetails1, healthDetails2));
    return response;
}
Also used : NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) HealthDetailsFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse)

Example 7 with HealthDetailsFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse in project cloudbreak by hortonworks.

the class FreeIpaStackHealthDetailsService method addUnreachableResponse.

private void addUnreachableResponse(InstanceMetaData instance, HealthDetailsFreeIpaResponse response, String issue) {
    NodeHealthDetails nodeResponse = new NodeHealthDetails();
    response.addNodeHealthDetailsFreeIpaResponses(nodeResponse);
    nodeResponse.setName(instance.getDiscoveryFQDN());
    nodeResponse.setStatus(InstanceStatus.UNREACHABLE);
    nodeResponse.setInstanceId(instance.getInstanceId());
    nodeResponse.addIssue(issue);
}
Also used : NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails)

Example 8 with HealthDetailsFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse in project cloudbreak by hortonworks.

the class FreeIpaStackHealthDetailsService method getHealthDetails.

public HealthDetailsFreeIpaResponse getHealthDetails(String environmentCrn, String accountId) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(environmentCrn, accountId);
    List<InstanceMetaData> instances = stack.getAllInstanceMetaDataList();
    HealthDetailsFreeIpaResponse response = new HealthDetailsFreeIpaResponse();
    for (InstanceMetaData instance : instances) {
        if (shouldRunHealthCheck(instance)) {
            try {
                NodeHealthDetails nodeHealthDetails = freeIpaInstanceHealthDetailsService.getInstanceHealthDetails(stack, instance);
                response.addNodeHealthDetailsFreeIpaResponses(nodeHealthDetails);
            } catch (Exception e) {
                addUnreachableResponse(instance, response, e.getLocalizedMessage());
                LOGGER.error(String.format("Unable to check the health of FreeIPA instance: %s", instance.getInstanceId()), e);
            }
        } else {
            NodeHealthDetails nodeResponse = new NodeHealthDetails();
            response.addNodeHealthDetailsFreeIpaResponses(nodeResponse);
            nodeResponse.setName(instance.getDiscoveryFQDN());
            nodeResponse.setStatus(instance.getInstanceStatus());
            nodeResponse.setInstanceId(instance.getInstanceId());
            nodeResponse.addIssue("Unable to check health as instance is " + instance.getInstanceStatus().name());
        }
    }
    return updateResponse(stack, response);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) HealthDetailsFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 9 with HealthDetailsFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse in project cloudbreak by hortonworks.

the class UpgradeCcmService method healthCheck.

public void healthCheck(Long stackId) {
    Stack stack = stackService.getStackById(stackId);
    HealthDetailsFreeIpaResponse healthDetails = healthService.getHealthDetails(stack.getEnvironmentCrn(), stack.getAccountId());
    if (healthDetails.getNodeHealthDetails().stream().anyMatch(hd -> !hd.getStatus().isAvailable())) {
        throw new CloudbreakServiceException("One or more FreeIPA instance is not available. Need to roll back CCM upgrade to previous version.");
    }
// TODO: rollback if bad, but how?
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) HealthDetailsFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 10 with HealthDetailsFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse in project cloudbreak by hortonworks.

the class FreeIpaStackHealthDetailsServiceTest method testUnresponsiveSingleNodeThatThrowsRuntimeException.

@Test
public void testUnresponsiveSingleNodeThatThrowsRuntimeException() throws Exception {
    Mockito.when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(anyString(), anyString())).thenReturn(getStack());
    Mockito.when(freeIpaInstanceHealthDetailsService.getInstanceHealthDetails(any(), any())).thenThrow(new RuntimeException("Expected"));
    HealthDetailsFreeIpaResponse response = underTest.getHealthDetails(ENVIRONMENT_ID, ACCOUNT_ID);
    Assert.assertEquals(Status.UNREACHABLE, response.getStatus());
    Assert.assertTrue(response.getNodeHealthDetails().size() == 1);
    for (NodeHealthDetails nodeHealth : response.getNodeHealthDetails()) {
        Assert.assertTrue(!nodeHealth.getIssues().isEmpty());
        Assert.assertEquals(InstanceStatus.UNREACHABLE, nodeHealth.getStatus());
        Assert.assertTrue(nodeHealth.getIssues().size() == 1);
        Assert.assertTrue(nodeHealth.getIssues().get(0).equals("Expected"));
    }
}
Also used : NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) HealthDetailsFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HealthDetailsFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse)18 Test (org.junit.jupiter.api.Test)13 NodeHealthDetails (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails)9 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 Stack (com.sequenceiq.freeipa.entity.Stack)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1