Search in sources :

Example 6 with InstanceStatus

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

the class ProviderChecker method updateStatuses.

private InstanceStatus updateStatuses(CloudVmInstanceStatus vmInstanceStatus, InstanceMetaData instanceMetaData, Map<InstanceMetaData, DetailedStackStatus> instanceHealthStatusMap) {
    LOGGER.info(":::Auto sync::: {} instance metadata status update in progress, new status: {}", instanceMetaData.getShortHostname(), vmInstanceStatus);
    InstanceStatus status = null;
    switch(vmInstanceStatus.getStatus()) {
        case STARTED:
            if (DetailedStackStatus.UNREACHABLE == instanceHealthStatusMap.get(instanceMetaData)) {
                setStatusIfNotTheSame(instanceMetaData, InstanceStatus.UNREACHABLE);
                status = InstanceStatus.UNREACHABLE;
            } else if (DetailedStackStatus.UNHEALTHY == instanceHealthStatusMap.get(instanceMetaData)) {
                setStatusIfNotTheSame(instanceMetaData, InstanceStatus.UNHEALTHY);
                status = InstanceStatus.UNHEALTHY;
            } else {
                setStatusIfNotTheSame(instanceMetaData, InstanceStatus.CREATED);
                status = InstanceStatus.CREATED;
            }
            break;
        case STOPPED:
            setStatusIfNotTheSame(instanceMetaData, InstanceStatus.STOPPED);
            status = InstanceStatus.STOPPED;
            break;
        case FAILED:
            setStatusIfNotTheSame(instanceMetaData, InstanceStatus.FAILED);
            status = InstanceStatus.FAILED;
            break;
        case TERMINATED:
            setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_ON_PROVIDER_SIDE);
            status = InstanceStatus.DELETED_ON_PROVIDER_SIDE;
            break;
        case TERMINATED_BY_PROVIDER:
            setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_BY_PROVIDER);
            status = InstanceStatus.DELETED_BY_PROVIDER;
            break;
        default:
            LOGGER.info(":::Auto sync::: the '{}' status is not converted", vmInstanceStatus.getStatus());
    }
    if (updateStatus) {
        instanceMetaDataService.save(instanceMetaData);
    } else {
        LOGGER.debug("updateStatus flag is false, don't update status");
    }
    return status;
}
Also used : InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)

Example 7 with InstanceStatus

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

the class StackStatusCheckerJob method setStatusIfNotTheSame.

private void setStatusIfNotTheSame(InstanceMetaData instanceMetaData, InstanceStatus newStatus) {
    InstanceStatus oldStatus = instanceMetaData.getInstanceStatus();
    if (oldStatus != newStatus) {
        if (updateStatus) {
            instanceMetaData.setInstanceStatus(newStatus);
            LOGGER.info(":::Auto sync::: The instance status updated from {} to {}", oldStatus, newStatus);
        } else {
            LOGGER.info(":::Auto sync::: The instance status would be had to update from {} to {}", oldStatus, newStatus);
        }
    }
}
Also used : InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)

Example 8 with InstanceStatus

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

the class FreeIpaConfigProviderTest method createInstanceMetadata.

private InstanceMetaDataResponse createInstanceMetadata(String fqdn, InstanceStatus status) {
    InstanceMetaDataResponse response = new InstanceMetaDataResponse();
    response.setDiscoveryFQDN(fqdn);
    response.setInstanceStatus(status);
    return response;
}
Also used : InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse)

Example 9 with InstanceStatus

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

the class RepairInstancesService method repairInstances.

/**
 * If no instance passed in request, repair all bad instances (at least 1 instance must be good)
 * If instances passed in request, repair all valid passed bad instances (at least 1 instance must remain)
 * If force and instances passed in request, repair all valid passed instances (at least 1 instance must remain)
 * If force and no instances passed in request then report an error
 *
 * @param accountId - The account id for the instance to repair.
 * @param request   - A RepairInstanceRequest containing request parameters.
 */
public OperationStatus repairInstances(String accountId, RepairInstancesRequest request) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
    if (request.isForceRepair() && CollectionUtils.isEmpty(request.getInstanceIds())) {
        throw new UnsupportedOperationException("Force repair requires the instance IDs to be provided.");
    }
    Map<String, InstanceStatus> healthMap = request.isForceRepair() ? Collections.emptyMap() : getInstanceHealthMap(accountId, request.getEnvironmentCrn());
    Map<String, InstanceMetaData> allInstancesByInstanceId = getAllInstancesFromStack(stack);
    Map<String, InstanceMetaData> instancesToRepair = getInstancesToRepair(healthMap, allInstancesByInstanceId, request.getInstanceIds(), request.isForceRepair(), false);
    Set<InstanceMetaData> remainingGoodInstances = getRemainingGoodInstances(allInstancesByInstanceId, instancesToRepair, healthMap, request.isForceRepair());
    Set<InstanceMetaData> remainingBadInstances = getRemainingBadInstances(allInstancesByInstanceId, instancesToRepair, healthMap, request.isForceRepair());
    validate(accountId, stack, remainingGoodInstances, remainingBadInstances, instancesToRepair.values());
    int nodeCount = stack.getInstanceGroups().stream().findFirst().get().getNodeCount();
    List<String> additionalTerminatedInstanceIds = getAdditionalTerminatedInstanceIds(allInstancesByInstanceId.values(), request.getInstanceIds());
    Operation operation = operationService.startOperation(accountId, OperationType.REPAIR, Set.of(stack.getEnvironmentCrn()), Collections.emptySet());
    if (operation.getStatus() == OperationState.RUNNING) {
        stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_REQUESTED, "Repair requested");
        flowManager.notify(FlowChainTriggers.REPAIR_TRIGGER_EVENT, new RepairEvent(FlowChainTriggers.REPAIR_TRIGGER_EVENT, stack.getId(), operation.getOperationId(), nodeCount, new ArrayList<>(instancesToRepair.keySet()), additionalTerminatedInstanceIds));
    }
    return operationToOperationStatusConverter.convert(operation);
}
Also used : ArrayList(java.util.ArrayList) Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) RepairEvent(com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent)

Example 10 with InstanceStatus

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

the class InstanceUpdater method setStatusIfNotTheSame.

private void setStatusIfNotTheSame(InstanceMetaData instanceMetaData, InstanceStatus newStatus) {
    InstanceStatus oldStatus = instanceMetaData.getInstanceStatus();
    if (oldStatus != newStatus) {
        instanceMetaData.setInstanceStatus(newStatus);
        LOGGER.info("The instance status updated from {} to {}", oldStatus, newStatus);
    }
}
Also used : InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)

Aggregations

InstanceStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)8 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)5 Stack (com.sequenceiq.freeipa.entity.Stack)5 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)4 ArrayList (java.util.ArrayList)3 DetailedStackStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus)2 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)2 InstanceMetaDataService (com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)1 CollectMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest)1 CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1