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));
}
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);
}
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);
}
Aggregations