Search in sources :

Example 1 with FreeIpaUpgradeRequest

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

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

the class UpgradeServiceTest method testFailureIfOperationFailedToStart.

@Test
public void testFailureIfOperationFailedToStart() {
    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);
    mockOperation(OperationState.REJECTED);
    when(instanceMetaDataService.getPrimaryGwInstance(allInstances)).thenReturn(createPgwIm());
    when(instanceMetaDataService.getNonPrimaryGwInstances(allInstances)).thenReturn(createGwImSet());
    assertThrows(BadRequestException.class, () -> underTest.upgradeFreeIpa(ACCOUNT_ID, request));
    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) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with FreeIpaUpgradeRequest

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

the class UpgradeService method upgradeFreeIpa.

@SuppressWarnings("IllegalType")
public FreeIpaUpgradeResponse upgradeFreeIpa(String accountId, FreeIpaUpgradeRequest request) {
    validationService.validateEntitlement(accountId);
    Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
    Set<InstanceMetaData> allInstances = stack.getNotDeletedInstanceMetaDataSet();
    validationService.validateStackForUpgrade(allInstances, stack);
    String pgwInstanceId = instanceMetaDataService.getPrimaryGwInstance(allInstances).getInstanceId();
    HashSet<String> nonPgwInstanceIds = selectNonPgwInstanceIds(allInstances);
    ImageInfoResponse currentImage = imageService.fetchCurrentImage(stack);
    ImageSettingsRequest imageSettingsRequest = assembleImageSettingsRequest(request, currentImage);
    ImageInfoResponse selectedImage = imageService.selectImage(stack, imageSettingsRequest);
    validationService.validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
    return triggerUpgrade(request, stack, pgwInstanceId, nonPgwInstanceIds, imageSettingsRequest, selectedImage, currentImage);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 4 with FreeIpaUpgradeRequest

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

the class UpgradeServiceTest method testFailureWhenNoPrimaryGateway.

@Test
public void testFailureWhenNoPrimaryGateway() {
    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 = Set.of();
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    when(instanceMetaDataService.getPrimaryGwInstance(allInstances)).thenThrow(new BadRequestException("No primary Gateway found"));
    assertThrows(BadRequestException.class, () -> underTest.upgradeFreeIpa(ACCOUNT_ID, request));
    verify(validationService).validateEntitlement(ACCOUNT_ID);
    verify(validationService).validateStackForUpgrade(allInstances, stack);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with FreeIpaUpgradeRequest

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

the class UpgradeServiceTest method mockSelectedImage.

private ImageInfoResponse mockSelectedImage(FreeIpaUpgradeRequest request, Stack stack) {
    ImageInfoResponse selectedImage = new ImageInfoResponse();
    selectedImage.setId("333-444");
    when(imageService.selectImage(stack, request.getImage())).thenReturn(selectedImage);
    return selectedImage;
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)

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