use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent in project cloudbreak by hortonworks.
the class FreeIpaScalingService method triggerDownscale.
private DownscaleResponse triggerDownscale(DownscaleRequest request, Stack stack, AvailabilityType originalAvailabilityType) {
Operation operation = startScalingOperation(stack.getAccountId(), request.getEnvironmentCrn(), OperationType.DOWNSCALE);
ArrayList<String> instanceIdList = getDownscaleCandidates(stack, originalAvailabilityType, request.getTargetAvailabilityType());
DownscaleEvent downscaleEvent = new DownscaleEvent(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), stack.getId(), instanceIdList, request.getTargetAvailabilityType().getInstanceCount(), false, false, false, operation.getOperationId());
try {
LOGGER.info("Trigger downscale flow with event: {}", downscaleEvent);
FlowIdentifier flowIdentifier = flowManager.notify(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent);
DownscaleResponse response = new DownscaleResponse();
response.setOperationId(operation.getOperationId());
response.setOriginalAvailabilityType(originalAvailabilityType);
response.setTargetAvailabilityType(request.getTargetAvailabilityType());
response.setFlowIdentifier(flowIdentifier);
return response;
} catch (Exception e) {
String exception = handleFlowException(operation, e, stack);
throw new BadRequestException(exception);
}
}
use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent in project cloudbreak by hortonworks.
the class RepairFlowEventChainFactory method createFlowTriggerEventQueue.
@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(RepairEvent event) {
Set<String> terminatedOrRemovedInstanceIdsSet = new HashSet<>(event.getRepairInstanceIds());
terminatedOrRemovedInstanceIdsSet.addAll(event.getAdditionalTerminatedInstanceIds());
ArrayList<String> terminatedOrRemovedInstanceIds = new ArrayList<>(terminatedOrRemovedInstanceIdsSet);
Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
flowEventChain.add(new ChangePrimaryGatewayEvent(ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_EVENT.event(), event.getResourceId(), terminatedOrRemovedInstanceIds, Boolean.FALSE, event.getOperationId(), event.accepted()));
flowEventChain.add(new DownscaleEvent(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), event.getResourceId(), terminatedOrRemovedInstanceIds, event.getInstanceCountByGroup(), true, true, false, event.getOperationId()));
flowEventChain.add(new UpscaleEvent(UpscaleFlowEvent.UPSCALE_EVENT.event(), event.getResourceId(), event.getInstanceCountByGroup(), true, true, false, event.getOperationId()));
flowEventChain.add(new ChangePrimaryGatewayEvent(ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_EVENT.event(), event.getResourceId(), terminatedOrRemovedInstanceIds, true, event.getOperationId()));
return new FlowTriggerEventQueue(getName(), event, flowEventChain);
}
use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent in project cloudbreak by hortonworks.
the class UpgradeFlowEventChainFactory method createScaleEventsForNonPgwInstances.
private List<Selectable> createScaleEventsForNonPgwInstances(UpgradeEvent event, int instanceCountForUpscale, int instanceCountForDownscale) {
LOGGER.debug("Add scale events for non primary gateway instances. upscale count: [{}] downscale count: [{}]", instanceCountForUpscale, instanceCountForDownscale);
List<Selectable> events = new ArrayList<>(event.getInstanceIds().size() * 2);
for (String instanceId : event.getInstanceIds()) {
LOGGER.debug("Add upscale and downscale event for [{}]", instanceId);
events.add(new UpscaleEvent(UpscaleFlowEvent.UPSCALE_EVENT.event(), event.getResourceId(), instanceCountForUpscale, Boolean.FALSE, true, false, event.getOperationId()));
events.add(new DownscaleEvent(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), event.getResourceId(), Lists.newArrayList(instanceId), instanceCountForDownscale, false, true, false, event.getOperationId()));
}
return events;
}
use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent in project cloudbreak by hortonworks.
the class UpgradeFlowEventChainFactory method createScaleEventsAndChangePgw.
private List<Selectable> createScaleEventsAndChangePgw(UpgradeEvent event, int instanceCountForUpscale, int instanceCountForDownscale) {
LOGGER.debug("Add events for primary gateway with id: [{}]", event.getPrimareGwInstanceId());
List<Selectable> events = new ArrayList<>(PRIMARY_GW_EVENT_COUNT);
events.add(new UpscaleEvent(UpscaleFlowEvent.UPSCALE_EVENT.event(), event.getResourceId(), instanceCountForUpscale, Boolean.FALSE, true, false, event.getOperationId()));
ArrayList<String> oldInstances = new ArrayList<>(event.getInstanceIds());
oldInstances.add(event.getPrimareGwInstanceId());
events.add(new ChangePrimaryGatewayEvent(ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_EVENT.event(), event.getResourceId(), oldInstances, Boolean.FALSE, event.getOperationId()));
events.add(new DownscaleEvent(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), event.getResourceId(), Lists.newArrayList(event.getPrimareGwInstanceId()), instanceCountForDownscale, false, true, false, event.getOperationId()));
return events;
}
use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent in project cloudbreak by hortonworks.
the class UpgradeFlowEventChainFactoryTest method testFlowChainCreation.
@Test
public void testFlowChainCreation() {
ImageSettingsRequest imageSettingsRequest = new ImageSettingsRequest();
UpgradeEvent event = new UpgradeEvent("selector", STACK_ID, Sets.newHashSet("repl1", "repl2"), "pgw", OPERATION_ID, imageSettingsRequest, false);
FlowTriggerEventQueue eventQueue = underTest.createFlowTriggerEventQueue(event);
assertEquals("UpgradeFlowEventChainFactory", eventQueue.getFlowChainName());
Queue<Selectable> queue = eventQueue.getQueue();
assertEquals(10, queue.size());
SaltUpdateTriggerEvent saltUpdateTriggerEvent = (SaltUpdateTriggerEvent) queue.poll();
assertEquals(OPERATION_ID, saltUpdateTriggerEvent.getOperationId());
assertEquals(STACK_ID, saltUpdateTriggerEvent.getResourceId());
assertEquals(SaltUpdateEvent.SALT_UPDATE_EVENT.event(), saltUpdateTriggerEvent.selector());
assertFalse(saltUpdateTriggerEvent.isFinalChain());
ImageChangeEvent imageChangeEvent = (ImageChangeEvent) queue.poll();
assertEquals(OPERATION_ID, imageChangeEvent.getOperationId());
assertEquals(STACK_ID, imageChangeEvent.getResourceId());
assertEquals(IMAGE_CHANGE_EVENT.event(), imageChangeEvent.selector());
assertEquals(imageSettingsRequest, imageChangeEvent.getRequest());
UpscaleEvent upscaleEvent1 = (UpscaleEvent) queue.poll();
assertEquals(OPERATION_ID, upscaleEvent1.getOperationId());
assertEquals(STACK_ID, upscaleEvent1.getResourceId());
assertTrue(upscaleEvent1.isChained());
assertFalse(upscaleEvent1.isFinalChain());
assertFalse(upscaleEvent1.isRepair());
assertEquals(UpscaleFlowEvent.UPSCALE_EVENT.event(), upscaleEvent1.selector());
assertEquals(4, upscaleEvent1.getInstanceCountByGroup());
DownscaleEvent downscaleEvent1 = (DownscaleEvent) queue.poll();
assertEquals(OPERATION_ID, downscaleEvent1.getOperationId());
assertEquals(STACK_ID, downscaleEvent1.getResourceId());
assertTrue(downscaleEvent1.isChained());
assertFalse(downscaleEvent1.isFinalChain());
assertFalse(downscaleEvent1.isRepair());
assertEquals(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent1.selector());
assertEquals(3, downscaleEvent1.getInstanceCountByGroup());
assertEquals(1, downscaleEvent1.getInstanceIds().size());
String firstInstanceToDownscale = downscaleEvent1.getInstanceIds().get(0);
assertTrue(firstInstanceToDownscale.startsWith("repl"));
UpscaleEvent upscaleEvent2 = (UpscaleEvent) queue.poll();
assertEquals(OPERATION_ID, upscaleEvent2.getOperationId());
assertEquals(STACK_ID, upscaleEvent2.getResourceId());
assertTrue(upscaleEvent2.isChained());
assertFalse(upscaleEvent2.isFinalChain());
assertFalse(upscaleEvent2.isRepair());
assertEquals(UpscaleFlowEvent.UPSCALE_EVENT.event(), upscaleEvent2.selector());
assertEquals(4, upscaleEvent2.getInstanceCountByGroup());
DownscaleEvent downscaleEvent2 = (DownscaleEvent) queue.poll();
assertEquals(OPERATION_ID, downscaleEvent2.getOperationId());
assertEquals(STACK_ID, downscaleEvent2.getResourceId());
assertTrue(downscaleEvent2.isChained());
assertFalse(downscaleEvent2.isFinalChain());
assertFalse(downscaleEvent2.isRepair());
assertEquals(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent2.selector());
assertEquals(3, downscaleEvent2.getInstanceCountByGroup());
assertEquals(1, downscaleEvent2.getInstanceIds().size());
String secondInstanceToDownscale = downscaleEvent2.getInstanceIds().get(0);
assertTrue(secondInstanceToDownscale.startsWith("repl"));
assertNotEquals(firstInstanceToDownscale, secondInstanceToDownscale);
UpscaleEvent upscaleEvent3 = (UpscaleEvent) queue.poll();
assertEquals(OPERATION_ID, upscaleEvent3.getOperationId());
assertEquals(STACK_ID, upscaleEvent3.getResourceId());
assertTrue(upscaleEvent3.isChained());
assertFalse(upscaleEvent3.isFinalChain());
assertFalse(upscaleEvent3.isRepair());
assertEquals(UpscaleFlowEvent.UPSCALE_EVENT.event(), upscaleEvent3.selector());
assertEquals(4, upscaleEvent3.getInstanceCountByGroup());
ChangePrimaryGatewayEvent changePrimaryGatewayEvent = (ChangePrimaryGatewayEvent) queue.poll();
assertEquals(OPERATION_ID, changePrimaryGatewayEvent.getOperationId());
assertEquals(STACK_ID, changePrimaryGatewayEvent.getResourceId());
assertFalse(changePrimaryGatewayEvent.isFinalChain());
assertEquals(ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_EVENT.event(), changePrimaryGatewayEvent.selector());
assertEquals(3, changePrimaryGatewayEvent.getRepairInstaceIds().size());
assertTrue(List.of("repl1", "repl2", "pgw").containsAll(changePrimaryGatewayEvent.getRepairInstaceIds()));
DownscaleEvent downscaleEvent3 = (DownscaleEvent) queue.poll();
assertEquals(OPERATION_ID, downscaleEvent3.getOperationId());
assertEquals(STACK_ID, downscaleEvent3.getResourceId());
assertTrue(downscaleEvent3.isChained());
assertFalse(downscaleEvent3.isFinalChain());
assertFalse(downscaleEvent3.isRepair());
assertEquals(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent3.selector());
assertEquals(3, downscaleEvent3.getInstanceCountByGroup());
assertEquals(1, downscaleEvent3.getInstanceIds().size());
assertEquals("pgw", downscaleEvent3.getInstanceIds().get(0));
SaltUpdateTriggerEvent saltUpdateTriggerEvent2 = (SaltUpdateTriggerEvent) queue.poll();
assertEquals(OPERATION_ID, saltUpdateTriggerEvent2.getOperationId());
assertEquals(STACK_ID, saltUpdateTriggerEvent2.getResourceId());
assertEquals(SaltUpdateEvent.SALT_UPDATE_EVENT.event(), saltUpdateTriggerEvent2.selector());
assertTrue(saltUpdateTriggerEvent2.isChained());
assertTrue(saltUpdateTriggerEvent2.isFinalChain());
}
Aggregations