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