Search in sources :

Example 1 with UpgradeEvent

use of com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent in project cloudbreak by hortonworks.

the class UpgradeServiceTest method testUpgradeTriggered.

@Test
public void testUpgradeTriggered() {
    FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
    request.setImage(new ImageSettingsRequest());
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    Stack stack = mock(Stack.class);
    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()));
    assertFalse(upgradeEvent.isBackupSet());
    verify(validationService).validateEntitlement(ACCOUNT_ID);
    verify(validationService).validateStackForUpgrade(allInstances, stack);
    verify(validationService).validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) FreeIpaUpgradeResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse) UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 2 with UpgradeEvent

use of com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent 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());
}
Also used : UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) DownscaleEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) UpscaleEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleEvent) SaltUpdateTriggerEvent(com.sequenceiq.freeipa.flow.freeipa.salt.update.SaltUpdateTriggerEvent) ChangePrimaryGatewayEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayEvent) Test(org.junit.jupiter.api.Test)

Example 3 with UpgradeEvent

use of com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent in project cloudbreak by hortonworks.

the class UpgradeServiceTest method testImageSettingsCreatedIfMissingAndUpgradeTriggered.

@Test
public void testImageSettingsCreatedIfMissingAndUpgradeTriggered() {
    FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    Stack stack = mock(Stack.class);
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
    Set<InstanceMetaData> allInstances = createValidImSet();
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    ImageInfoResponse selectedImage = new ImageInfoResponse();
    when(imageService.selectImage(eq(stack), any(ImageSettingsRequest.class))).thenReturn(selectedImage);
    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();
    assertNotNull(upgradeEvent.getImageSettingsRequest());
    assertEquals(operation.getOperationId(), upgradeEvent.getOperationId());
    assertEquals("pgw", upgradeEvent.getPrimareGwInstanceId());
    assertEquals(2, upgradeEvent.getInstanceIds().size());
    assertTrue(Set.of("im2", "im3").containsAll(upgradeEvent.getInstanceIds()));
    verify(validationService).validateEntitlement(ACCOUNT_ID);
    verify(validationService).validateStackForUpgrade(allInstances, stack);
    verify(validationService).validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) FreeIpaUpgradeResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse) UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with UpgradeEvent

use of com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent 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);
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) FreeIpaUpgradeResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) Backup(com.sequenceiq.freeipa.api.model.Backup) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Test(org.junit.jupiter.api.Test)

Example 5 with UpgradeEvent

use of com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent 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());
}
Also used : UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) FreeIpaUpgradeResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Aggregations

UpgradeEvent (com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent)5 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)4 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)4 FreeIpaUpgradeResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse)4 Operation (com.sequenceiq.freeipa.entity.Operation)4 Test (org.junit.jupiter.api.Test)4 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)3 FreeIpaUpgradeRequest (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest)3 ImageInfoResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)3 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)3 Stack (com.sequenceiq.freeipa.entity.Stack)3 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)1 Backup (com.sequenceiq.freeipa.api.model.Backup)1 DownscaleEvent (com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent)1 ChangePrimaryGatewayEvent (com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayEvent)1 SaltUpdateTriggerEvent (com.sequenceiq.freeipa.flow.freeipa.salt.update.SaltUpdateTriggerEvent)1 UpscaleEvent (com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleEvent)1 ImageChangeEvent (com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent)1