use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class UpgradeServiceTest method testUpgradeTriggeredWithBackup.
@Test
public void testUpgradeTriggeredWithBackup() {
FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
request.setImage(new ImageSettingsRequest());
request.setEnvironmentCrn(ENVIRONMENT_CRN);
Stack stack = mock(Stack.class);
when(stack.getBackup()).thenReturn(new Backup());
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
Set<InstanceMetaData> allInstances = createValidImSet();
when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
ImageInfoResponse selectedImage = mockSelectedImage(request, stack);
ImageInfoResponse currentImage = mockCurrentImage(stack);
Operation operation = mockOperation(OperationState.RUNNING);
ArgumentCaptor<Acceptable> eventCaptor = ArgumentCaptor.forClass(Acceptable.class);
FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "flowId");
when(flowManager.notify(eq(FlowChainTriggers.UPGRADE_TRIGGER_EVENT), eventCaptor.capture())).thenReturn(flowIdentifier);
when(instanceMetaDataService.getPrimaryGwInstance(allInstances)).thenReturn(createPgwIm());
when(instanceMetaDataService.getNonPrimaryGwInstances(allInstances)).thenReturn(createGwImSet());
FreeIpaUpgradeResponse response = underTest.upgradeFreeIpa(ACCOUNT_ID, request);
assertEquals(flowIdentifier, response.getFlowIdentifier());
assertEquals(operation.getOperationId(), response.getOperationId());
assertEquals(currentImage, response.getOriginalImage());
assertEquals(selectedImage, response.getTargetImage());
UpgradeEvent upgradeEvent = (UpgradeEvent) eventCaptor.getValue();
assertEquals(request.getImage(), upgradeEvent.getImageSettingsRequest());
assertEquals(operation.getOperationId(), upgradeEvent.getOperationId());
assertEquals("pgw", upgradeEvent.getPrimareGwInstanceId());
assertEquals(2, upgradeEvent.getInstanceIds().size());
assertTrue(Set.of("im2", "im3").containsAll(upgradeEvent.getInstanceIds()));
assertTrue(upgradeEvent.isBackupSet());
verify(validationService).validateEntitlement(ACCOUNT_ID);
verify(validationService).validateStackForUpgrade(allInstances, stack);
verify(validationService).validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class FreeIpaUpgradeCcmService method startUpgradeOperation.
private OperationStatus startUpgradeOperation(String accountId, Stack stack) {
LOGGER.info("Start 'UPGRADE_CCM' operation");
Operation operation = operationService.startOperation(accountId, OperationType.UPGRADE_CCM, List.of(stack.getEnvironmentCrn()), List.of());
if (OperationState.RUNNING == operation.getStatus()) {
return operationConverter.convert(triggerCcmUpgradeFlowChain(accountId, operation, stack));
} else {
LOGGER.info("Operation isn't in RUNNING state: {}", operation);
return operationConverter.convert(operation);
}
}
use of com.sequenceiq.freeipa.entity.Operation 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.entity.Operation in project cloudbreak by hortonworks.
the class UpgradeService method triggerUpgrade.
@SuppressWarnings("IllegalType")
private FreeIpaUpgradeResponse triggerUpgrade(FreeIpaUpgradeRequest request, Stack stack, String pgwInstanceId, HashSet<String> nonPgwInstanceIds, ImageSettingsRequest imageSettingsRequest, ImageInfoResponse selectedImage, ImageInfoResponse currentImage) {
Operation operation = startUpgradeOperation(stack.getAccountId(), request);
UpgradeEvent upgradeEvent = new UpgradeEvent(FlowChainTriggers.UPGRADE_TRIGGER_EVENT, stack.getId(), nonPgwInstanceIds, pgwInstanceId, operation.getOperationId(), imageSettingsRequest, Objects.nonNull(stack.getBackup()));
LOGGER.info("Trigger upgrade flow with event: {}", upgradeEvent);
FlowIdentifier flowIdentifier = flowManager.notify(FlowChainTriggers.UPGRADE_TRIGGER_EVENT, upgradeEvent);
return new FreeIpaUpgradeResponse(flowIdentifier, selectedImage, currentImage, operation.getOperationId());
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class OperationAcceptor method accept.
public AcceptResult accept(Operation operation) {
List<Operation> runningOperations = operationRepository.findRunningByAccountIdAndType(operation.getAccountId(), selector());
List<String> rejectionReasons = new ArrayList<>(runningOperations.size());
for (Operation o : runningOperations) {
if (o.getId() < operation.getId() && doOperationsConflict(operation, o)) {
rejectionReasons.add(String.format(CONFLICT_REASON, o.getOperationId(), o.getUserList().isEmpty() ? "[all users]" : o.getUserList(), o.getEnvironmentList().isEmpty() ? "[all environments]" : o.getEnvironmentList()));
}
}
if (rejectionReasons.isEmpty()) {
return AcceptResult.accept();
} else {
return AcceptResult.reject(String.format(REJECTION_MESSAGE, selector(), operation.getOperationId(), rejectionReasons));
}
}
Aggregations