Search in sources :

Example 1 with Result

use of com.sequenceiq.cloudbreak.service.cluster.model.Result 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());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Result(com.sequenceiq.cloudbreak.service.cluster.model.Result) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Test(org.junit.Test)

Example 2 with Result

use of com.sequenceiq.cloudbreak.service.cluster.model.Result in project cloudbreak by hortonworks.

the class ClusterUpgradeAvailabilityServiceTest method testCheckForUpgradesByNameShouldReturnImagesWhenThereAreAvailableImagesUsingImageCatalogByName.

@Test
public void testCheckForUpgradesByNameShouldReturnImagesWhenThereAreAvailableImagesUsingImageCatalogByName() 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);
    ImageCatalog imageCatalogDomain = createImageCatalogDomain();
    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)).thenReturn(imageCatalogDomain);
    when(imageCatalogProvider.getImageCatalogV3(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(CATALOG_URL);
    verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
    verify(upgradeOptionsResponseFactory).createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
}
Also used : CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Result(com.sequenceiq.cloudbreak.service.cluster.model.Result) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Test(org.junit.Test)

Example 3 with Result

use of com.sequenceiq.cloudbreak.service.cluster.model.Result in project cloudbreak by hortonworks.

the class ClusterRepairServiceTest method testCannotRepairGatewayWithoutExternalDatabase.

@Test
public void testCannotRepairGatewayWithoutExternalDatabase() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    HostGroup hostGroup1 = new HostGroup();
    hostGroup1.setName("hostGroup1");
    hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
    InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_HEALTHY, InstanceGroupType.GATEWAY);
    hostGroup1.setInstanceGroup(host1.getInstanceGroup());
    when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
    when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
    when(componentConfigProviderService.getImage(stack.getId())).thenReturn(mock(Image.class));
    com.sequenceiq.cloudbreak.cloud.model.catalog.Image image = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    when(image.isPrewarmed()).thenReturn(true);
    when(imageCatalogService.getImage(any(), any(), any())).thenReturn(StatedImage.statedImage(image, "catalogUrl", "catalogName"));
    when(clusterDBValidationService.isGatewayRepairEnabled(cluster)).thenReturn(false);
    when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
    when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
    Result result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairWithDryRun(stack.getId()));
    assertFalse(result.isSuccess());
    verifyNoInteractions(stackUpdater, flowManager, resourceService);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Result(com.sequenceiq.cloudbreak.service.cluster.model.Result) Test(org.junit.jupiter.api.Test)

Example 4 with Result

use of com.sequenceiq.cloudbreak.service.cluster.model.Result in project cloudbreak by hortonworks.

the class ClusterRepairServiceTest method testCanRepairCoreTypeNode.

@Test
public void testCanRepairCoreTypeNode() {
    cluster.setDatabaseServerCrn("dbCrn");
    HostGroup hostGroup1 = new HostGroup();
    hostGroup1.setName("hostGroup1");
    hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
    InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_RUNNING, InstanceGroupType.CORE);
    hostGroup1.setInstanceGroup(host1.getInstanceGroup());
    when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
    when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
    when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
    when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
    DatabaseServerV4Response databaseServerV4Response = new DatabaseServerV4Response();
    databaseServerV4Response.setStatus(AVAILABLE);
    when(redbeamsClientService.getByCrn(eq("dbCrn"))).thenReturn(databaseServerV4Response);
    when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.NONE);
    Result result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairWithDryRun(stack.getId()));
    assertTrue(result.isSuccess());
    verifyNoInteractions(stackUpdater, flowManager, resourceService);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Result(com.sequenceiq.cloudbreak.service.cluster.model.Result) Test(org.junit.jupiter.api.Test)

Example 5 with Result

use of com.sequenceiq.cloudbreak.service.cluster.model.Result in project cloudbreak by hortonworks.

the class ClusterRepairServiceTest method testCanRepairPrewarmedGatewayWithRepairPossibleBasedOnDBSetup.

@Test
public void testCanRepairPrewarmedGatewayWithRepairPossibleBasedOnDBSetup() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    HostGroup hostGroup1 = new HostGroup();
    hostGroup1.setName("hostGroup1");
    hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
    InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_HEALTHY, InstanceGroupType.GATEWAY);
    hostGroup1.setInstanceGroup(host1.getInstanceGroup());
    when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
    when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
    when(componentConfigProviderService.getImage(stack.getId())).thenReturn(mock(Image.class));
    com.sequenceiq.cloudbreak.cloud.model.catalog.Image image = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    when(image.isPrewarmed()).thenReturn(true);
    when(imageCatalogService.getImage(any(), any(), any())).thenReturn(StatedImage.statedImage(image, "catalogUrl", "catalogName"));
    when(clusterDBValidationService.isGatewayRepairEnabled(cluster)).thenReturn(true);
    when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
    when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
    when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.NONE);
    Result result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairWithDryRun(stack.getId()));
    assertTrue(result.isSuccess());
    verifyNoInteractions(stackUpdater, flowManager, resourceService);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Result(com.sequenceiq.cloudbreak.service.cluster.model.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Result (com.sequenceiq.cloudbreak.service.cluster.model.Result)6 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)4 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)4 Test (org.junit.jupiter.api.Test)4 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)3 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)2 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)2 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 ImageFilterParams (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams)2 ImageFilterResult (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)2 Test (org.junit.Test)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)1