Search in sources :

Example 16 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class StackUpdater method doUpdateStackStatus.

private Stack doUpdateStackStatus(Stack stack, DetailedStackStatus newDetailedStatus, String rawNewStatusReason) {
    Status newStatus = newDetailedStatus.getStatus();
    StackStatus stackStatus = stack.getStackStatus();
    if (!Status.DELETE_COMPLETED.equals(stackStatus.getStatus())) {
        rawNewStatusReason = serviceStatusRawMessageTransformer.transformMessage(rawNewStatusReason, stack.getTunnel());
        String transformedStatusReason = stackStatusMessageTransformator.transformMessage(rawNewStatusReason);
        if (isStatusChanged(stack, newDetailedStatus, transformedStatusReason, newStatus)) {
            stack = handleStatusChange(stack, newDetailedStatus, transformedStatusReason, newStatus, stackStatus);
        } else {
            LOGGER.debug("Statuses are the same, it will not update");
            updateInMemoryStoreIfStackIsMissing(stack, newStatus);
        }
    }
    return stack;
}
Also used : StackStatus(com.sequenceiq.freeipa.entity.StackStatus) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) StackStatus(com.sequenceiq.freeipa.entity.StackStatus) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus)

Example 17 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class FreeipaChecker method getStatus.

public SyncResult getStatus(Stack stack, Set<InstanceMetaData> checkableInstances) {
    try {
        if (checkableInstances.isEmpty()) {
            throw new UnsupportedOperationException("There are no instances of FreeIPA to check the status of");
        }
        // Exclude terminated but include deleted
        Set<InstanceMetaData> notTermiatedStackInstances = stack.getAllInstanceMetaDataList().stream().filter(Predicate.not(InstanceMetaData::isTerminated)).collect(Collectors.toSet());
        Pair<Map<InstanceMetaData, DetailedStackStatus>, String> statusCheckPair = checkStatus(stack, checkableInstances);
        List<DetailedStackStatus> responses = new ArrayList<>(statusCheckPair.getFirst().values());
        DetailedStackStatus status;
        if (areAllStatusTheSame(responses) && !hasMissingStatus(responses, notTermiatedStackInstances)) {
            status = responses.get(0);
        } else {
            status = DetailedStackStatus.UNHEALTHY;
        }
        return new SyncResult("FreeIpa is " + status + ", " + statusCheckPair.getSecond(), status, statusCheckPair.getFirst());
    } catch (Exception e) {
        LOGGER.info("Error occurred during status fetch: " + e.getMessage(), e);
        return new SyncResult("FreeIpa is unreachable, because error occurred: " + e.getMessage(), DetailedStackStatus.UNREACHABLE, null);
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ArrayList(java.util.ArrayList) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class FreeipaChecker method checkStatus.

private Pair<Map<InstanceMetaData, DetailedStackStatus>, String> checkStatus(Stack stack, Set<InstanceMetaData> checkableInstances) throws Exception {
    return checkedMeasure(() -> {
        Map<InstanceMetaData, DetailedStackStatus> statuses = new HashMap<>();
        List<RPCResponse<Boolean>> responses = new LinkedList<>();
        LOGGER.info("Checking FreeIPA status for instance IDs {}", checkableInstances.stream().map(InstanceMetaData::getInstanceId).collect(Collectors.toList()));
        for (InstanceMetaData instanceMetaData : checkableInstances) {
            try {
                RPCResponse<Boolean> response = checkedMeasure(() -> freeIpaInstanceHealthDetailsService.checkFreeIpaHealth(stack, instanceMetaData), LOGGER, ":::Auto sync::: FreeIPA health check ran in {}ms");
                responses.add(response);
                DetailedStackStatus newDetailedStackStatus;
                if (response.getResult()) {
                    newDetailedStackStatus = DetailedStackStatus.AVAILABLE;
                } else {
                    newDetailedStackStatus = DetailedStackStatus.UNHEALTHY;
                }
                LOGGER.info("FreeIpa health check reported {} for {}", newDetailedStackStatus, instanceMetaData);
                statuses.put(instanceMetaData, newDetailedStackStatus);
            } catch (Exception e) {
                LOGGER.info("FreeIpaClientException occurred during status fetch for {}: {}", instanceMetaData, e.getMessage(), e);
                statuses.put(instanceMetaData, DetailedStackStatus.UNREACHABLE);
            }
        }
        String message = getMessages(responses);
        return Pair.of(statuses, message);
    }, LOGGER, ":::Auto sync::: freeipa server status is checked in {}ms");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) HashMap(java.util.HashMap) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) LinkedList(java.util.LinkedList)

Example 19 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class StackUpdater method saveStackNewStatus.

private Stack saveStackNewStatus(Stack stack, DetailedStackStatus newDetailedStatus, String newStatusReason, Status newStatus, StackStatus stackStatus) {
    LOGGER.debug("Updated: status from {} to {} - detailed status from {} to {} - reason from {} to {}", stackStatus.getStatus(), newStatus, stackStatus.getDetailedStackStatus(), newDetailedStatus, stackStatus.getStatusReason(), newStatusReason);
    stack.setStackStatus(new StackStatus(stack, newStatus, newStatusReason, newDetailedStatus));
    stack = stackService.save(stack);
    return stack;
}
Also used : StackStatus(com.sequenceiq.freeipa.entity.StackStatus) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus)

Aggregations

DetailedStackStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus)17 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)3 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)2 InstanceStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)2 StackStatus (com.sequenceiq.freeipa.entity.StackStatus)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Benchmark.checkedMeasure (com.sequenceiq.cloudbreak.util.Benchmark.checkedMeasure)1 DistroXV1Request (com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 FlowLogService (com.sequenceiq.flow.core.FlowLogService)1 Status (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status)1 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 InstanceMetaDataService (com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1