Search in sources :

Example 6 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class UpdateRecipeService method refreshRecipesForCluster.

/**
 * Updating recipes for an existing cluster. The input should contain host group - recipes mapping
 * If a host group key from the mappings is missing from the input, that is not going to be updated.
 * (or both - that is the default). Output is the newly attached/detached recipes in db.
 */
public UpdateRecipesV4Response refreshRecipesForCluster(Long workspaceId, Stack stack, List<UpdateHostGroupRecipes> recipesPerHostGroup) {
    Set<String> recipesToFind = recipesPerHostGroup.stream().flatMap(rphg -> rphg.getRecipeNames().stream()).collect(Collectors.toSet());
    Map<String, Set<String>> recipesToUpdate = recipesPerHostGroup.stream().collect(Collectors.toMap(UpdateHostGroupRecipes::getHostGroupName, UpdateHostGroupRecipes::getRecipeNames, (n1, n2) -> n1));
    LOGGER.debug("Update recipes {}", recipesToUpdate);
    Set<Recipe> recipes = recipeService.getByNamesForWorkspaceId(recipesToFind, workspaceId);
    validate(recipesToFind, recipes);
    Set<HostGroup> hostGroups = hostGroupService.getByClusterWithRecipes(stack.getCluster().getId());
    UpdateRecipesV4Response result = updateRecipesForHostGroups(recipesToUpdate, recipes, hostGroups);
    LOGGER.debug("Update recipes result: {}", result);
    return result;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) GeneratedRecipe(com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe) AttachRecipeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.AttachRecipeV4Response) UpdateRecipesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) UpdateHostGroupRecipes(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.UpdateHostGroupRecipes) Collectors(java.util.stream.Collectors) DetachRecipeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.DetachRecipeV4Response) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) HashSet(java.util.HashSet) List(java.util.List) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Service(org.springframework.stereotype.Service) Map(java.util.Map) Optional(java.util.Optional) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Joiner(com.google.common.base.Joiner) Set(java.util.Set) HashSet(java.util.HashSet) UpdateRecipesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response) GeneratedRecipe(com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)

Example 7 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class StackV4RequestToStackConverterTest method testWhenRegionIsEmptyButDefaultRegionsAreEmptyThenBadRequestExceptionComes.

@Test
public void testWhenRegionIsEmptyButDefaultRegionsAreEmptyThenBadRequestExceptionComes() {
    setDefaultRegions(null);
    StackV4Request request = getRequest("stack.json");
    request.setCloudPlatform(MOCK);
    request.getPlacement().setRegion(null);
    BadRequestException resultException = assertThrows(BadRequestException.class, () -> underTest.convert(request));
    assertEquals("No default region is specified. Region cannot be empty.", resultException.getMessage());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest) Test(org.junit.jupiter.api.Test)

Example 8 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class ClusterToClusterV4RequestConverterTest method testConvertWhenRdsConfigsContainsElementsThenUserManagedOnesNameShouldBeStored.

@Test
public void testConvertWhenRdsConfigsContainsElementsThenUserManagedOnesNameShouldBeStored() {
    RDSConfig notUserManaged = new RDSConfig();
    notUserManaged.setId(0L);
    notUserManaged.setStatus(DEFAULT);
    RDSConfig userManaged = new RDSConfig();
    notUserManaged.setId(1L);
    userManaged.setStatus(USER_MANAGED);
    Set<RDSConfig> rdsConfigs = new LinkedHashSet<>(2);
    rdsConfigs.add(notUserManaged);
    rdsConfigs.add(userManaged);
    when(cluster.getRdsConfigs()).thenReturn(rdsConfigs);
    ClusterV4Request result = underTest.convert(cluster);
    assertEquals(1L, result.getDatabases().size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Test(org.junit.Test)

Example 9 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class ClusterTemplateTest method validateDefaultCount.

private ClusterTemplateTestDto validateDefaultCount(TestContext tc, ClusterTemplateTestDto entity, CloudbreakClient cc) {
    try {
        assertNotNull(entity);
        assertNotNull(entity.getResponses());
        long defaultCount = entity.getResponses().stream().filter(template -> ResourceStatus.DEFAULT.equals(template.getStatus())).count();
        long expectedCount = 602;
        assertEquals("Should have " + expectedCount + " of default cluster templates.", expectedCount, defaultCount);
    } catch (Exception e) {
        throw new TestFailException(String.format("Failed to validate default count of cluster templates: %s", e.getMessage()), e);
    }
    return entity;
}
Also used : ClusterTestDto(com.sequenceiq.it.cloudbreak.dto.ClusterTestDto) DistroXTemplateTestDto(com.sequenceiq.it.cloudbreak.dto.clustertemplate.DistroXTemplateTestDto) ResourceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus) DistroXImageTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXImageTestDto) ClusterTemplateTestDto(com.sequenceiq.it.cloudbreak.dto.clustertemplate.ClusterTemplateTestDto) Test(org.testng.annotations.Test) StringUtils(org.apache.commons.lang3.StringUtils) MockCloudProvider(com.sequenceiq.it.cloudbreak.cloud.v4.mock.MockCloudProvider) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) DistroXNetworkTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.instancegroup.DistroXNetworkTestDto) StackTemplateTestDto(com.sequenceiq.it.cloudbreak.dto.stack.StackTemplateTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) BadRequestException(javax.ws.rs.BadRequestException) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ClusterTemplateAuditGrpcServiceAssertion(com.sequenceiq.it.cloudbreak.assertion.audit.ClusterTemplateAuditGrpcServiceAssertion) Assert.assertNotNull(org.junit.Assert.assertNotNull) PlacementSettingsTestDto(com.sequenceiq.it.cloudbreak.dto.PlacementSettingsTestDto) DistroXClouderaManagerTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.cluster.clouderamanager.DistroXClouderaManagerTestDto) ClusterTemplateV4Type(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.ClusterTemplateV4Type) LdapTestClient(com.sequenceiq.it.cloudbreak.client.LdapTestClient) ClusterTemplateTestAssertion(com.sequenceiq.it.cloudbreak.assertion.clustertemplate.ClusterTemplateTestAssertion) NotFoundException(javax.ws.rs.NotFoundException) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) ClusterTemplateTestClient(com.sequenceiq.it.cloudbreak.client.ClusterTemplateTestClient) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) RunningParameter(com.sequenceiq.it.cloudbreak.context.RunningParameter) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) CloudbreakClient(com.sequenceiq.it.cloudbreak.CloudbreakClient) RecipeTestClient(com.sequenceiq.it.cloudbreak.client.RecipeTestClient) RunningParameter.expectedMessage(com.sequenceiq.it.cloudbreak.context.RunningParameter.expectedMessage) Assert.assertEquals(org.junit.Assert.assertEquals) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException)

Example 10 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class ImageCatalogTest method testGetImageCatalogWhenCatalogDoesNotContainTheRequestedProvider.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "image catalog get the default catalog with AWS provider but catalog does not contain AWS entry", when = "calling get on the default", then = "the response does not contains AWS images")
public void testGetImageCatalogWhenCatalogDoesNotContainTheRequestedProvider(MockedTestContext testContext) {
    String imgCatalogName = resourcePropertyProvider().getName();
    testContext.given(imgCatalogName, ImageCatalogTestDto.class).withName(imgCatalogName).withUrl(getImageCatalogMockServerSetup().getImageCatalogUrl()).when(imageCatalogTestClient.createV4(), key(imgCatalogName)).when(new ImageCatalogGetImagesByNameAction(CloudPlatform.AWS), key(imgCatalogName)).then((testContext1, entity, cloudbreakClient) -> {
        ImagesV4Response catalog = entity.getResponseByProvider();
        if (!catalog.getBaseImages().isEmpty()) {
            throw new IllegalArgumentException("The Images response should NOT contain results for AWS provider.");
        }
        return entity;
    }).validate();
}
Also used : ImageCatalogTestClient(com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Test(org.testng.annotations.Test) ImageCatalogV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Responses) UpdateImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request) StackTestClient(com.sequenceiq.it.cloudbreak.client.StackTestClient) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) NotFoundException(javax.ws.rs.NotFoundException) ImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.ImageCatalogV4Request) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) ImageCatalogV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) ImageCatalogGetImagesByNameAction(com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogGetImagesByNameAction) BadRequestException(javax.ws.rs.BadRequestException) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) RunningParameter.expectedMessage(com.sequenceiq.it.cloudbreak.context.RunningParameter.expectedMessage) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) ImageCatalogGetImagesByNameAction(com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogGetImagesByNameAction) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)13 List (java.util.List)10 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 Inject (javax.inject.Inject)7 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Service (org.springframework.stereotype.Service)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 Map (java.util.Map)5 Optional (java.util.Optional)5 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 HashSet (java.util.HashSet)4 Sets (com.google.common.collect.Sets)3 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 BlueprintService (com.sequenceiq.cloudbreak.service.blueprint.BlueprintService)3 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)3