Search in sources :

Example 6 with GeneratedRecipe

use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe in project cloudbreak by hortonworks.

the class UpdateRecipeService method doHostGroupRecipeUpdate.

private UpdateHostGroupRecipesPair doHostGroupRecipeUpdate(Map<String, Set<String>> recipesToUpdate, Set<Recipe> recipes, HostGroup hostGroup) {
    String hostGroupName = hostGroup.getName();
    Optional<UpdateHostGroupRecipes> attachHostGroupRecipesOpt = Optional.empty();
    Optional<UpdateHostGroupRecipes> detachHostGroupRecipesOpt = Optional.empty();
    if (recipesToUpdate.containsKey(hostGroupName)) {
        LOGGER.debug("Checking host group '{}' needs any refresh.", hostGroupName);
        Set<String> recipesForHostGroup = recipesToUpdate.get(hostGroupName);
        Set<Recipe> existingRecipes = hostGroup.getRecipes();
        Set<String> existingRecipeNames = existingRecipes.stream().map(Recipe::getName).collect(Collectors.toSet());
        LOGGER.debug("Current recipes: {}", existingRecipes);
        boolean allExists = existingRecipes.stream().allMatch(r -> recipesForHostGroup.contains(r.getName()));
        if (allExists && recipesForHostGroup.size() == existingRecipes.size()) {
            LOGGER.debug("No need for any recipe update for '{}' host group", hostGroupName);
        } else {
            Set<Recipe> updateRecipes = recipes.stream().filter(r -> recipesForHostGroup.contains(r.getName())).collect(Collectors.toSet());
            attachHostGroupRecipesOpt = collectAttachHostGroupRecipes(hostGroupName, existingRecipeNames, updateRecipes);
            detachHostGroupRecipesOpt = collectDetachHostGroupRecipes(hostGroupName, recipesForHostGroup, existingRecipes);
            Set<GeneratedRecipe> generatedRecipeToDeleteSet = new HashSet<>();
            if (detachHostGroupRecipesOpt.isPresent()) {
                UpdateHostGroupRecipes detachHostGroupRecipes = detachHostGroupRecipesOpt.get();
                generatedRecipeToDeleteSet = hostGroup.getGeneratedRecipes().stream().filter(gr -> recipeNamesMatchForGeneratedRecipe(gr, detachHostGroupRecipes.getRecipeNames())).collect(Collectors.toSet());
                hostGroup.getGeneratedRecipes().removeAll(generatedRecipeToDeleteSet);
            }
            hostGroup.setRecipes(updateRecipes);
            hostGroupService.save(hostGroup);
            if (detachHostGroupRecipesOpt.isPresent() && !generatedRecipeToDeleteSet.isEmpty()) {
                generatedRecipeService.deleteAll(generatedRecipeToDeleteSet);
            }
        }
    }
    return new UpdateHostGroupRecipesPair(attachHostGroupRecipesOpt.orElse(null), detachHostGroupRecipesOpt.orElse(null));
}
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) GeneratedRecipe(com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe) GeneratedRecipe(com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) UpdateHostGroupRecipes(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.UpdateHostGroupRecipes) HashSet(java.util.HashSet)

Example 7 with GeneratedRecipe

use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe in project cloudbreak by hortonworks.

the class RecipeTemplateServiceTest method hostGroup.

private HostGroup hostGroup(String name, Set<Recipe> recipes) {
    Set<GeneratedRecipe> generatedRecipes = new HashSet<>();
    for (Recipe recipe : recipes) {
        GeneratedRecipe generatedRecipe = new GeneratedRecipe();
        generatedRecipe.setRecipe(recipe);
        generatedRecipe.setExtendedRecipeText(recipe.getContent());
        generatedRecipes.add(generatedRecipe);
    }
    return hostGroup(name, recipes, generatedRecipes);
}
Also used : GeneratedRecipe(com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe) GeneratedRecipe(com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) HashSet(java.util.HashSet)

Example 8 with GeneratedRecipe

use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe in project cloudbreak by hortonworks.

the class RecipeTemplateServiceTest method testCompareGenerateRecipesWithNotMatchingGeneratedReceipe.

@Test
public void testCompareGenerateRecipesWithNotMatchingGeneratedReceipe() {
    // GIVEN
    Recipe recipe = recipe("r1", DUMMY_CONTENT_2);
    Set<HostGroup> hgs = new HashSet<>();
    Set<GeneratedRecipe> generatedRecipes = new HashSet<>();
    GeneratedRecipe generatedRecipe = new GeneratedRecipe();
    generatedRecipe.setExtendedRecipeText(DUMMY_CONTENT_1);
    generatedRecipe.setRecipe(recipe);
    generatedRecipes.add(generatedRecipe);
    HostGroup hgMaster = hostGroup("master", Set.of(recipe), generatedRecipes);
    hgs.add(hgMaster);
    Map<HostGroup, List<RecipeModel>> recipeModels = new HashMap<>();
    recipeModels.put(hgMaster, List.of(new RecipeModel("r1", RecipeType.PRE_CLOUDERA_MANAGER_START, DUMMY_CONTENT_2)));
    // WHEN
    boolean result = recipeTemplateService.isGeneratedRecipesInDbStale(hgs, recipeModels);
    // THEN
    assertFalse(result);
}
Also used : GeneratedRecipe(com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe) GeneratedRecipe(com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) HashMap(java.util.HashMap) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) List(java.util.List) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

GeneratedRecipe (com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe)8 Recipe (com.sequenceiq.cloudbreak.domain.Recipe)7 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)6 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)4 List (java.util.List)4 Set (java.util.Set)4 RecipeModel (com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel)3 Map (java.util.Map)3 Test (org.junit.jupiter.api.Test)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 Collectors (java.util.stream.Collectors)2 ArgumentMatchers.anySet (org.mockito.ArgumentMatchers.anySet)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Service (org.springframework.stereotype.Service)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