use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest 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);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest 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);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.
the class CoreImageProviderTest method testGetImagesdReturnsEmptyListWhenFreeImagesNull.
@Test
public void testGetImagesdReturnsEmptyListWhenFreeImagesNull() throws Exception {
when(imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, CATALOG_NAME, null, PLATFORM, null, null, false)).thenReturn(new ImagesV4Response());
ImageSettingsRequest imageSettings = new ImageSettingsRequest();
imageSettings.setCatalog(CATALOG_NAME);
List<ImageWrapper> result = victim.getImages(imageSettings, "", PLATFORM);
assertTrue(result.isEmpty());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.
the class CoreImageProviderTest method anImageSettings.
private ImageSettingsRequest anImageSettings() {
ImageSettingsRequest imageSettings = new ImageSettingsRequest();
imageSettings.setCatalog(CATALOG_NAME);
imageSettings.setId(IMAGE_ID);
return imageSettings;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.
the class CoreImageProviderTest method testGetImagesdReturnsEmptyListWhenWebApplicationExceptionThrown.
@Test
public void testGetImagesdReturnsEmptyListWhenWebApplicationExceptionThrown() throws Exception {
when(imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, CATALOG_NAME, null, PLATFORM, null, null, false)).thenThrow(new WebApplicationException());
ImageSettingsRequest imageSettings = new ImageSettingsRequest();
imageSettings.setCatalog(CATALOG_NAME);
List<ImageWrapper> result = victim.getImages(imageSettings, "", PLATFORM);
assertTrue(result.isEmpty());
}
Aggregations