use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method extendMetadataAction.
@Bean(name = "UPSCALE_EXTEND_METADATA_STATE")
public Action<?, ?> extendMetadataAction() {
return new AbstractUpscaleAction<>(StackEvent.class) {
private final Set<InstanceStatus> unusedInstanceStatuses = Set.of(InstanceStatus.CREATE_REQUESTED, InstanceStatus.CREATED);
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Extending metadata");
List<CloudInstance> allKnownInstances = cloudStackConverter.buildInstances(stack);
List<Resource> resources = resourceService.findAllByStackId(stack.getId());
List<CloudResource> cloudResources = resources.stream().map(r -> resourceConverter.convert(r)).collect(Collectors.toList());
List<CloudInstance> newCloudInstances = allKnownInstances.stream().filter(this::isNewInstances).collect(Collectors.toList());
CollectMetadataRequest request = new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, newCloudInstances, allKnownInstances);
sendEvent(context, request.selector(), request);
}
private boolean isNewInstances(CloudInstance cloudInstance) {
return unusedInstanceStatuses.contains(cloudInstance.getTemplate().getStatus());
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method createStack.
private Stack createStack(Status stackStatus, List<InstanceStatus> instanceStatuses, int requestedInstancesWithoutInstanceIds) {
Stack stack = new Stack();
stack.setId(STACK_ID);
stack.setEnvironmentCrn(ENVIRONMENT_ID1);
StackStatus s = new StackStatus();
s.setStatus(stackStatus);
stack.setStackStatus(s);
int i = 1;
Set<InstanceMetaData> instanceMetaDataSet = new HashSet<>();
for (InstanceStatus instanceStatus : instanceStatuses) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setInstanceId("i-" + i);
instanceMetaData.setInstanceStatus(instanceStatus);
instanceMetaDataSet.add(instanceMetaData);
i++;
}
for (i = 0; i < requestedInstancesWithoutInstanceIds; i++) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setInstanceStatus(InstanceStatus.REQUESTED);
instanceMetaDataSet.add(instanceMetaData);
}
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setInstanceMetaData(instanceMetaDataSet);
instanceGroup.setNodeCount(instanceMetaDataSet.size());
stack.setInstanceGroups(Set.of(instanceGroup));
return stack;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus 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;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus in project cloudbreak by hortonworks.
the class RepairInstancesService method rebootInstances.
/**
* If no instance passed in request, reboot all bad instances
* If instances passed in request, reboot all valid passed bad instances
* If force and instances passed in request, reboot all valid passed instances
* If force and no instances passed in request, reboot all instances
*
* @param accountId - The account id for the instance to reboot.
* @param request - A RebootInstanceRequest containing request parameters.
*/
public OperationStatus rebootInstances(String accountId, RebootInstancesRequest request) {
Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
Map<String, InstanceMetaData> allInstancesByInstanceId = getAllInstancesFromStack(stack);
Map<String, InstanceStatus> healthMap = request.isForceReboot() ? Collections.emptyMap() : getInstanceHealthMap(accountId, request.getEnvironmentCrn());
Map<String, InstanceMetaData> instancesToReboot = getInstancesToRepair(healthMap, allInstancesByInstanceId, request.getInstanceIds(), request.isForceReboot(), true);
if (instancesToReboot.keySet().isEmpty()) {
throw new NotFoundException("No unhealthy instances to reboot. Maybe use the force option.");
}
Operation operation = operationService.startOperation(accountId, OperationType.REBOOT, Set.of(stack.getEnvironmentCrn()), Collections.emptySet());
if (operation.getStatus() == OperationState.RUNNING) {
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_REQUESTED, "Reboot requested");
flowManager.notify(REBOOT_EVENT.event(), new RebootInstanceEvent(REBOOT_EVENT.event(), stack.getId(), instancesToReboot.keySet().stream().collect(Collectors.toList()), operation.getOperationId()));
}
return operationToOperationStatusConverter.convert(operation);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus in project cloudbreak by hortonworks.
the class ProviderChecker method updateAndGetStatuses.
public List<ProviderSyncResult> updateAndGetStatuses(Stack stack, Set<InstanceMetaData> checkableInstances, Map<InstanceMetaData, DetailedStackStatus> instanceHealthStatusMap, boolean updateStatusFromFlow) {
return checkedMeasure(() -> {
List<ProviderSyncResult> results = new ArrayList<>();
List<CloudVmInstanceStatus> statuses = stackInstanceProviderChecker.checkStatus(stack, checkableInstances);
if (!updateStatusFromFlow && flowLogService.isOtherFlowRunning(stack.getId())) {
throw new InterruptSyncingException(":::Auto sync::: interrupt syncing in updateAndGetStatuses, flow is running on freeipa stack " + stack.getName());
} else {
statuses.forEach(s -> {
Optional<InstanceMetaData> instanceMetaData = checkableInstances.stream().filter(i -> s.getCloudInstance().getInstanceId().equals(i.getInstanceId())).findFirst();
if (instanceMetaData.isPresent()) {
InstanceStatus instanceStatus = updateStatuses(s, instanceMetaData.get(), instanceHealthStatusMap);
if (instanceStatus != null) {
results.add(new ProviderSyncResult("", instanceStatus, false, s.getCloudInstance().getInstanceId()));
}
} else {
LOGGER.info(":::Auto sync::: Cannot find instanceMetaData");
}
});
checkableInstances.forEach(instanceMetaData -> {
if (statuses.stream().noneMatch(s -> s.getCloudInstance().getInstanceId().equals(instanceMetaData.getInstanceId()))) {
if (updateStatus) {
setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_ON_PROVIDER_SIDE);
instanceMetaDataService.save(instanceMetaData);
} else {
LOGGER.debug("updateStatus flag is false, don't update status");
}
}
});
return results;
}
}, LOGGER, ":::Auto sync::: provider is checked in {}ms");
}
Aggregations