use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class EnvironmentLoadBalancerServiceTest method testNoEnvironmentFound.
@Test
public void testNoEnvironmentFound() {
EnvironmentLoadBalancerDto environmentLbDto = EnvironmentLoadBalancerDto.builder().withEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED).build();
EnvironmentDto environmentDto = EnvironmentDto.builder().withName(ENV_NAME).withResourceCrn(ENV_CRN).build();
String expectedError = String.format("Could not find environment '%s' using crn '%s'", ENV_NAME, ENV_CRN);
when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(anyString(), anyString())).thenReturn(Optional.empty());
doNothing().when(loadBalancerEntitlementService).validateNetworkForEndpointGateway(any(), any(), any());
final NotFoundException[] exception = new NotFoundException[1];
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
exception[0] = assertThrows(NotFoundException.class, () -> underTest.updateLoadBalancerInEnvironmentAndStacks(environmentDto, environmentLbDto));
});
assertEquals(expectedError, exception[0].getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class ChangePrimaryGatewayService method selectNewPrimaryGatewayInstanceId.
public String selectNewPrimaryGatewayInstanceId(Stack stack, List<String> repairInstanceIds) {
String newPrimaryGatewayInstanceId;
try {
GatewayConfig currentPrimaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
Optional<String> freeIpaMasterInstanceId = findFreeIpaMasterInstanceId(stack, currentPrimaryGatewayConfig);
if (freeIpaMasterInstanceId.isPresent() && !repairInstanceIds.contains(freeIpaMasterInstanceId.get())) {
LOGGER.debug("Using the FreeIPA master as the new primary gateway");
newPrimaryGatewayInstanceId = freeIpaMasterInstanceId.get();
} else {
newPrimaryGatewayInstanceId = currentPrimaryGatewayConfig.getInstanceId();
if (repairInstanceIds.contains(newPrimaryGatewayInstanceId)) {
LOGGER.debug("The current primary gateway is on the list of to avoid, searching for a different primary gateway");
newPrimaryGatewayInstanceId = assignNewPrimaryGatewayInstanceId(stack, repairInstanceIds);
}
}
} catch (NotFoundException | CloudbreakOrchestratorException e) {
LOGGER.debug("No primary gateway found, searching for a different primary gateway");
newPrimaryGatewayInstanceId = assignNewPrimaryGatewayInstanceId(stack, repairInstanceIds);
}
LOGGER.debug("The new primary gateway will be {}", newPrimaryGatewayInstanceId);
return newPrimaryGatewayInstanceId;
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackImageServiceTest method testChangeImageCatalogOutOfFlowThrowsNotFoundExceptionInCaseOfMissingTargetCatalog.
@Test
public void testChangeImageCatalogOutOfFlowThrowsNotFoundExceptionInCaseOfMissingTargetCatalog() throws CloudbreakImageNotFoundException {
when(componentConfigProviderService.getImage(stack.getId())).thenReturn(anImageComponent());
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), TARGET_IMAGE_CATALOG)).thenThrow(new NotFoundException(""));
assertThrows(NotFoundException.class, () -> victim.changeImageCatalog(stack, TARGET_IMAGE_CATALOG));
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testCheckForUpgradesByNameShouldReturnImagesFromFallbackCatalogWhenThereAreAvailableImagesButImageCatalogByNameNotFound.
@Test
public void testCheckForUpgradesByNameShouldReturnImagesFromFallbackCatalogWhenThereAreAvailableImagesButImageCatalogByNameNotFound() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
Result result = Mockito.mock(Result.class);
Image currentImageFromCatalog = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
Image properImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
Image otherImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
CloudbreakImageCatalogV3 imageCatalog = createImageCatalog(List.of(properImage, otherImage, currentImageFromCatalog));
ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
UpgradeV4Response response = new UpgradeV4Response();
when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
when(clusterRepairService.repairWithDryRun(stack.getId())).thenReturn(result);
when(result.isError()).thenReturn(false);
when(imageService.getImage(stack.getId())).thenReturn(currentImage);
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME)).thenThrow(new NotFoundException("not found"));
when(imageCatalogProvider.getImageCatalogV3(FALLBACK_CATALOG_URL)).thenReturn(imageCatalog);
ImageFilterResult filteredImages = createFilteredImages(properImage);
when(clusterUpgradeImageFilter.filter(ACCOUNT_ID, imageCatalog, imageFilterParams)).thenReturn(filteredImages);
when(upgradeOptionsResponseFactory.createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName())).thenReturn(response);
when(imageProvider.getCurrentImageFromCatalog(CURRENT_IMAGE_ID, imageCatalog)).thenReturn(currentImageFromCatalog);
when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(false);
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
assertEquals(response, actual);
verify(imageService).getImage(stack.getId());
verify(imageCatalogProvider).getImageCatalogV3(FALLBACK_CATALOG_URL);
verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
verify(upgradeOptionsResponseFactory).createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class ImageCatalogServiceTest method testGetImagesWhenCustomImageCatalogDoesNotExists.
@Test
public void testGetImagesWhenCustomImageCatalogDoesNotExists() throws Exception {
when(imageCatalogRepository.findByNameAndWorkspaceId(anyString(), anyLong())).thenThrow(new NotFoundException("no no"));
thrown.expectMessage("The verycool catalog does not exist or does not belongs to your account.");
thrown.expect(CloudbreakImageCatalogException.class);
underTest.getImages(ORG_ID, "verycool", imageCatalogPlatform("aws")).getImages();
verify(entitlementService, times(1)).baseImageEnabled(Objects.requireNonNull(Crn.fromString(user.getUserCrn())).getAccountId());
verify(entitlementService, never()).baseImageEnabled(user.getUserCrn());
verify(imageCatalogProvider, times(0)).getImageCatalogV3("");
}
Aggregations