Search in sources :

Example 36 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class ClusterUpgradeServiceTest method testClusterUpgradeFinishedWhenNeededNoStackDetails.

@ParameterizedTest
@MethodSource("upgradeNeededImages")
public void testClusterUpgradeFinishedWhenNeededNoStackDetails(Image currentIm, Image targetIm) {
    // GIVEN
    StatedImage currentImage = StatedImage.statedImage(currentIm, null, null);
    StatedImage targetImage = StatedImage.statedImage(targetIm, null, null);
    // WHEN
    underTest.clusterUpgradeFinished(STACK_ID, currentImage, targetImage);
    // THEN
    verify(flowMessageService).fireEventAndLog(STACK_ID, Status.AVAILABLE.name(), CLUSTER_UPGRADE_FINISHED, NullUtil.getIfNotNull(targetIm.getStackDetails(), ImageStackDetails::getVersion));
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 37 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class ClusterUpgradeServiceTest method testClusterUpgradeFinishedWhenNotNeeded.

@Test
public void testClusterUpgradeFinishedWhenNotNeeded() {
    // GIVEN
    Image currentImmage = createImage(CURRENT_BUILD_NUMBER, CURRENT_BUILD_NUMBER);
    StatedImage currentImage = StatedImage.statedImage(currentImmage, null, null);
    Image targetImmage = createImage(CURRENT_BUILD_NUMBER, CURRENT_BUILD_NUMBER);
    StatedImage targetImage = StatedImage.statedImage(targetImmage, null, null);
    // WHEN
    underTest.clusterUpgradeFinished(STACK_ID, currentImage, targetImage);
    // THEN
    verify(flowMessageService).fireEventAndLog(STACK_ID, Status.AVAILABLE.name(), CLUSTER_UPGRADE_FINISHED_NOVERSION);
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class StackCreatorService method getImageCatalog.

private StatedImage getImageCatalog(Future<StatedImage> imgFromCatalogFuture) {
    int time = 1;
    TimeUnit unit = TimeUnit.MINUTES;
    return Optional.ofNullable(imgFromCatalogFuture).map(f -> {
        try {
            return f.get(time, unit);
        } catch (ExecutionException e) {
            if (e.getCause() instanceof RuntimeException) {
                if (e.getCause().getCause() instanceof CloudbreakImageNotFoundException) {
                    throw new BadRequestException("Image id settings are incorrect: " + e.getMessage(), e);
                }
                if (e.getCause().getCause() instanceof CloudbreakImageCatalogException) {
                    throw new BadRequestException("Image or image catalog settings are incorrect: " + ExceptionUtils.getRootCauseMessage(e), e.getCause());
                }
            }
            throw new RuntimeException("Unknown error happened when determining image from image catalog:" + e.getMessage(), e);
        } catch (InterruptedException e) {
            throw new RuntimeException("Determining image from image catalog interrupted", e);
        } catch (TimeoutException e) {
            throw new RuntimeException(String.format("Could not determine image from image catalog in %d %s", time, unit), e);
        }
    }).orElse(null);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) RecipeService(com.sequenceiq.cloudbreak.service.recipe.RecipeService) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) STACK_PREPARATION(com.sequenceiq.cloudbreak.service.metrics.MetricType.STACK_PREPARATION) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) CloudbreakRestRequestThreadLocalService(com.sequenceiq.cloudbreak.structuredevent.CloudbreakRestRequestThreadLocalService) Future(java.util.concurrent.Future) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Map(java.util.Map) CloudbreakMetricService(com.sequenceiq.cloudbreak.service.metrics.CloudbreakMetricService) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Collectors(java.util.stream.Collectors) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) NodeCountLimitValidator(com.sequenceiq.cloudbreak.service.NodeCountLimitValidator) CollectionUtils(org.springframework.util.CollectionUtils) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) HueWorkaroundValidatorService(com.sequenceiq.cloudbreak.validation.HueWorkaroundValidatorService) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StackV4RequestToStackConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.StackV4RequestToStackConverter) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) Network(com.sequenceiq.cloudbreak.domain.Network) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) ClusterCreationSetupService(com.sequenceiq.cloudbreak.service.ClusterCreationSetupService) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) HueRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.hue.HueRoles) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StackRuntimeVersionValidator(com.sequenceiq.cloudbreak.controller.validation.stack.StackRuntimeVersionValidator) LinkedHashSet(java.util.LinkedHashSet) ExecutorService(java.util.concurrent.ExecutorService) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) StackUnderOperationService(com.sequenceiq.cloudbreak.service.StackUnderOperationService) StackDecorator(com.sequenceiq.cloudbreak.service.decorator.StackDecorator) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) StackViewService(com.sequenceiq.cloudbreak.service.stack.StackViewService) IOException(java.io.IOException) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) User(com.sequenceiq.cloudbreak.workspace.model.User) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) MultiAzCalculatorService(com.sequenceiq.cloudbreak.service.multiaz.MultiAzCalculatorService) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ImageCatalogService(com.sequenceiq.cloudbreak.service.image.ImageCatalogService) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) StackToStackV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.StackToStackV4ResponseConverter) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) ClouderaManagerV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.ClouderaManagerV4Request) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) TimeoutException(java.util.concurrent.TimeoutException)

Example 39 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class ImageCatalogV4Controller method getImageByImageId.

@Override
@DisableCheckPermissions
public ImagesV4Response getImageByImageId(Long workspaceId, String imageId, @AccountId String accountId) throws Exception {
    StatedImage statedImage = imageCatalogService.getImageByCatalogName(restRequestThreadLocalService.getRequestedWorkspaceId(), imageId, "");
    Images images = new Images(List.of(), List.of(statedImage.getImage()), List.of(), Set.of());
    return imagesToImagesV4ResponseConverter.convert(images);
}
Also used : Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) DisableCheckPermissions(com.sequenceiq.authorization.annotation.DisableCheckPermissions)

Example 40 with StatedImage

use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.

the class ImageCatalogV4Controller method getImageByCatalogNameAndImageId.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.DESCRIBE_IMAGE_CATALOG)
public ImagesV4Response getImageByCatalogNameAndImageId(Long workspaceId, @ResourceName String name, String imageId, @AccountId String accountId) throws Exception {
    StatedImage statedImage = imageCatalogService.getImageByCatalogName(restRequestThreadLocalService.getRequestedWorkspaceId(), imageId, name);
    Images images = new Images(List.of(), List.of(statedImage.getImage()), List.of(), Set.of());
    return imagesToImagesV4ResponseConverter.convert(images);
}
Also used : Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Aggregations

StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)48 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)19 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 Test (org.junit.Test)12 Image (com.sequenceiq.cloudbreak.cloud.model.Image)11 Test (org.junit.jupiter.api.Test)10 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)9 Json (com.sequenceiq.cloudbreak.common.json.Json)7 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)7 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)7 CheckResult (com.sequenceiq.cloudbreak.core.flow2.CheckResult)6 Map (java.util.Map)6 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CloudbreakDetails (com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)4 StackImageUpdateTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 ImageUpdateEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent)3