Search in sources :

Example 51 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.

the class UpgradeImageServiceTest method testFindTargetImagesCurrentImageMissingDateAndNoDateFromCatalog.

@Test
public void testFindTargetImagesCurrentImageMissingDateAndNoDateFromCatalog() {
    Stack stack = new Stack();
    stack.setCloudPlatform("AWS");
    stack.setRegion("reg");
    ImageSettingsRequest imageSettingsRequest = new ImageSettingsRequest();
    Image image = createImage("2021-09-01");
    ImageWrapper imageWrapper = new ImageWrapper(image, "catalogURL", "catalogName");
    when(imageService.fetchImagesWrapperAndName(stack, imageSettingsRequest)).thenReturn(List.of(Pair.of(imageWrapper, "imageName")));
    ArgumentCaptor<ImageSettingsRequest> captor = ArgumentCaptor.forClass(ImageSettingsRequest.class);
    Image currentImageFromCatalog = createImage(null);
    ImageWrapper currentImageWrapperFromCatalog = new ImageWrapper(currentImageFromCatalog, "asdf", "Asdf");
    when(imageService.getImage(captor.capture(), eq(stack.getRegion()), eq(stack.getCloudPlatform().toLowerCase()))).thenReturn(currentImageWrapperFromCatalog);
    ImageInfoResponse currentImage = new ImageInfoResponse();
    currentImage.setId("222-333");
    currentImage.setCatalogName("cat");
    currentImage.setOs("zOs");
    List<ImageInfoResponse> targetImages = underTest.findTargetImages(stack, imageSettingsRequest, currentImage);
    assertTrue(targetImages.isEmpty());
    ImageSettingsRequest settingsRequest = captor.getValue();
    assertEquals(currentImage.getCatalogName(), settingsRequest.getCatalog());
    assertEquals(currentImage.getId(), settingsRequest.getId());
    assertEquals(currentImage.getOs(), settingsRequest.getOs());
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 52 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.

the class UpgradeImageServiceTest method testSelectImage.

@Test
public void testSelectImage() {
    Stack stack = new Stack();
    ImageSettingsRequest imageSettingsRequest = new ImageSettingsRequest();
    Image image = createImage("now");
    ImageWrapper imageWrapper = new ImageWrapper(image, "catalogURL", "catalogName");
    when(imageService.fetchImageWrapperAndName(stack, imageSettingsRequest)).thenReturn(Pair.of(imageWrapper, "imageName"));
    ImageInfoResponse imageInfoResponse = underTest.selectImage(stack, imageSettingsRequest);
    assertEquals(imageWrapper.getCatalogName(), imageInfoResponse.getCatalogName());
    assertEquals(imageWrapper.getCatalogUrl(), imageInfoResponse.getCatalog());
    assertEquals(image.getDate(), imageInfoResponse.getDate());
    assertEquals(image.getUuid(), imageInfoResponse.getId());
    assertEquals(image.getOs(), imageInfoResponse.getOs());
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 53 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest 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 54 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.

the class UpgradeServiceTest method testUpgradeOptionsWithCatalogSet.

@Test
public void testUpgradeOptionsWithCatalogSet() {
    Stack stack = new Stack();
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
    ImageInfoResponse currentImage = new ImageInfoResponse();
    currentImage.setCatalog("cat2");
    currentImage.setCatalogName("catName");
    when(imageService.fetchCurrentImage(stack)).thenReturn(currentImage);
    ArgumentCaptor<ImageSettingsRequest> captor = ArgumentCaptor.forClass(ImageSettingsRequest.class);
    ImageInfoResponse targetImage = new ImageInfoResponse();
    when(imageService.findTargetImages(eq(stack), captor.capture(), eq(currentImage))).thenReturn(List.of(targetImage));
    FreeIpaUpgradeOptions result = underTest.collectUpgradeOptions(ACCOUNT_ID, ENVIRONMENT_CRN, "cat");
    assertEquals(currentImage, result.getCurrentImage());
    assertEquals(1, result.getImages().size());
    assertEquals(targetImage, result.getImages().get(0));
    ImageSettingsRequest imageSettingsRequest = captor.getValue();
    assertEquals("cat", imageSettingsRequest.getCatalog());
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeOptions(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeOptions) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 55 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest 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)

Aggregations

ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)57 Test (org.junit.jupiter.api.Test)41 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)28 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)23 Stack (com.sequenceiq.freeipa.entity.Stack)23 ImageInfoResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)16 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)7 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)5 FreeIpaUpgradeRequest (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest)4 ImageChangeEvent (com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 Backup (com.sequenceiq.freeipa.api.model.Backup)3 UpgradeEvent (com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent)3 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)2 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)2