Search in sources :

Example 1 with UpdateRecipesV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response 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 2 with UpdateRecipesV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response in project cloudbreak by hortonworks.

the class UpdateRecipeService method updateRecipesForHostGroups.

private UpdateRecipesV4Response updateRecipesForHostGroups(Map<String, Set<String>> recipesToUpdate, Set<Recipe> recipes, Set<HostGroup> hostGroups) {
    UpdateRecipesV4Response result = new UpdateRecipesV4Response();
    for (HostGroup hostGroup : hostGroups) {
        UpdateHostGroupRecipesPair updatePairs = doHostGroupRecipeUpdate(recipesToUpdate, recipes, hostGroup);
        updatePairs.getRecipesToAttach().ifPresent(a -> result.getRecipesAttached().add(a));
        updatePairs.getRecipesToDetach().ifPresent(d -> result.getRecipesDetached().add(d));
    }
    return result;
}
Also used : UpdateRecipesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)

Example 3 with UpdateRecipesV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response in project cloudbreak by hortonworks.

the class UpdateRecipeServiceTest method testRefreshRecipesForClusterNoUpdate.

@Test
public void testRefreshRecipesForClusterNoUpdate() {
    // GIVEN
    Map<String, Set<String>> sampleMap = new HashMap<>();
    sampleMap.put(MASTER_HOST_GROUP_NAME, Set.of(PRE_CLDR_START_RECIPE));
    Map<String, Set<String>> hostGroupsSample = new HashMap<>();
    hostGroupsSample.put(MASTER_HOST_GROUP_NAME, Set.of(PRE_CLDR_START_RECIPE));
    when(recipeService.getByNamesForWorkspaceId(anySet(), anyLong())).thenReturn(createRecipes(Set.of(PRE_CLDR_START_RECIPE)));
    when(hostGroupService.getByClusterWithRecipes(anyLong())).thenReturn(createHostGroupWithRecipes(hostGroupsSample));
    // WHEN
    UpdateRecipesV4Response response = underTest.refreshRecipesForCluster(DUMMY_ID, createStack(), createUpdateHostGroupRecipes(sampleMap));
    // THEN
    assertTrue(response.getRecipesAttached().isEmpty());
    assertTrue(response.getRecipesDetached().isEmpty());
}
Also used : ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) HashSet(java.util.HashSet) Set(java.util.Set) UpdateRecipesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with UpdateRecipesV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response in project cloudbreak by hortonworks.

the class UpdateRecipeServiceTest method testRefreshRecipesForCluster.

@Test
public void testRefreshRecipesForCluster() {
    // GIVEN
    Map<String, Set<String>> sampleMap = new HashMap<>();
    sampleMap.put(MASTER_HOST_GROUP_NAME, Set.of(PRE_CLDR_START_RECIPE));
    Map<String, Set<String>> hostGroupsSample = new HashMap<>();
    hostGroupsSample.put(MASTER_HOST_GROUP_NAME, Set.of(POST_CLDR_START_RECIPE));
    when(recipeService.getByNamesForWorkspaceId(anySet(), anyLong())).thenReturn(createRecipes(Set.of(PRE_CLDR_START_RECIPE, POST_CLDR_START_RECIPE)));
    when(hostGroupService.getByClusterWithRecipes(anyLong())).thenReturn(createHostGroupWithRecipes(hostGroupsSample));
    doNothing().when(generatedRecipeService).deleteAll(anySet());
    // WHEN
    UpdateRecipesV4Response response = underTest.refreshRecipesForCluster(DUMMY_ID, createStack(), createUpdateHostGroupRecipes(sampleMap));
    // THEN
    assertTrue(response.getRecipesAttached().get(0).getRecipeNames().contains(PRE_CLDR_START_RECIPE));
    verify(generatedRecipeService, times(1)).deleteAll(anySet());
}
Also used : ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) HashSet(java.util.HashSet) Set(java.util.Set) UpdateRecipesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 5 with UpdateRecipesV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response in project cloudbreak by hortonworks.

the class UpdateRecipeServiceTest method testRefreshRecipesForClusterOnlyDbUpdate.

@Test
public void testRefreshRecipesForClusterOnlyDbUpdate() {
    // GIVEN
    Map<String, Set<String>> sampleMap = new HashMap<>();
    sampleMap.put(MASTER_HOST_GROUP_NAME, Set.of(PRE_CLDR_START_RECIPE));
    Map<String, Set<String>> hostGroupsSample = new HashMap<>();
    hostGroupsSample.put(MASTER_HOST_GROUP_NAME, Set.of(POST_CLDR_START_RECIPE));
    when(recipeService.getByNamesForWorkspaceId(anySet(), anyLong())).thenReturn(createRecipes(Set.of(PRE_CLDR_START_RECIPE, POST_CLDR_START_RECIPE)));
    when(hostGroupService.getByClusterWithRecipes(anyLong())).thenReturn(createHostGroupWithRecipes(hostGroupsSample));
    // WHEN
    UpdateRecipesV4Response response = underTest.refreshRecipesForCluster(DUMMY_ID, createStack(), createUpdateHostGroupRecipes(sampleMap));
    // THEN
    assertTrue(response.getRecipesAttached().get(0).getRecipeNames().contains(PRE_CLDR_START_RECIPE));
}
Also used : ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) HashSet(java.util.HashSet) Set(java.util.Set) UpdateRecipesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateRecipesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 HashMap (java.util.HashMap)4 Test (org.junit.jupiter.api.Test)4 ArgumentMatchers.anySet (org.mockito.ArgumentMatchers.anySet)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)2 Joiner (com.google.common.base.Joiner)1 UpdateHostGroupRecipes (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.UpdateHostGroupRecipes)1 AttachRecipeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.AttachRecipeV4Response)1 DetachRecipeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.DetachRecipeV4Response)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 Recipe (com.sequenceiq.cloudbreak.domain.Recipe)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 GeneratedRecipe (com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe)1 HostGroupService (com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService)1 List (java.util.List)1 Map (java.util.Map)1