Search in sources :

Example 6 with FreeIpaUpgradeRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest 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 7 with FreeIpaUpgradeRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest 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 8 with FreeIpaUpgradeRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest in project cloudbreak by hortonworks.

the class FreeIpaUpgradeAction method action.

public FreeIpaTestDto action(TestContext testContext, FreeIpaTestDto testDto, FreeIpaClient client) throws Exception {
    Log.whenJson(LOGGER, format(" FreeIPA post request:%n"), testDto.getRequest());
    FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
    request.setEnvironmentCrn(testDto.getRequest().getEnvironmentCrn());
    FreeIpaUpgradeResponse response = client.getDefaultClient().getFreeIpaUpgradeV1Endpoint().upgradeFreeIpa(request);
    testDto.setFlow("FreeIPA upgrade", response.getFlowIdentifier());
    testDto.setOperationId(response.getOperationId());
    Log.whenJson(LOGGER, format(" FreeIPA upgrade started: %n"), response);
    return testDto;
}
Also used : FreeIpaUpgradeResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest)

Example 9 with FreeIpaUpgradeRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest 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

ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)6 FreeIpaUpgradeRequest (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest)6 ImageInfoResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)6 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 FreeIpaUpgradeResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse)5 Test (org.junit.jupiter.api.Test)5 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)4 Operation (com.sequenceiq.freeipa.entity.Operation)4 UpgradeEvent (com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent)4 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Backup (com.sequenceiq.freeipa.api.model.Backup)1