use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe in project cloudbreak by hortonworks.
the class RecipeTemplateService method isRecipeUpToDateInHostGroup.
private boolean isRecipeUpToDateInHostGroup(HostGroup hostGroup, Map<String, GeneratedRecipe> generatedRecipeNameMap, List<RecipeModel> recipeModelList) {
for (RecipeModel recipeModel : recipeModelList) {
String recipeName = recipeModel.getName();
if (!generatedRecipeNameMap.containsKey(recipeName)) {
LOGGER.debug("No generated recipe with name {} for host group '{}'. Recipes should be uploaded and regenerated.", recipeName, hostGroup.getName());
return false;
}
GeneratedRecipe generatedRecipe = generatedRecipeNameMap.get(recipeName);
if (!recipeModel.getGeneratedScript().equals(generatedRecipe.getExtendedRecipeText())) {
LOGGER.debug("Regenerated recipe [name: {}] not matching with currently generated recipe for host group '{}'. " + "Recipes should be uploaded and regenerated.", recipeName, hostGroup.getName());
return false;
}
}
return true;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe in project cloudbreak by hortonworks.
the class RecipeTemplateService method isGeneratedRecipesInDbStale.
/**
* Compare generated recipes from the database against on-the-fly generated recipes for every host groups
* If any of those will differ from the source (in database) or no recipe relation found for generated recipe, the result will be false.
*/
public boolean isGeneratedRecipesInDbStale(Set<HostGroup> hostGroups, Map<HostGroup, List<RecipeModel>> generatedModels) {
for (HostGroup hostGroup : hostGroups) {
Set<GeneratedRecipe> generatedRecipes = hostGroup.getGeneratedRecipes();
boolean hasRecipes = CollectionUtils.isNotEmpty(hostGroup.getRecipes());
boolean hasGeneratedRecipes = CollectionUtils.isNotEmpty(generatedRecipes);
boolean recipeModelsContainsHostGroup = MapUtils.isNotEmpty(generatedModels) && generatedModels.containsKey(hostGroup);
if (hasRecipes && !hasGeneratedRecipes) {
LOGGER.debug("No generated recipes found for host group '{}', but it has recipes. Recipes should be uploaded and regenerated.", hostGroup.getName());
return false;
} else if (!hasGeneratedRecipes) {
LOGGER.debug("No source and generated recipes found for host group '{}', skip comparing source and generated recipes.", hostGroup.getName());
continue;
} else if (!recipeModelsContainsHostGroup) {
LOGGER.debug("Generated recipe models do not contain host group {}. Recipes should be regenerated.", hostGroup.getName());
return false;
}
boolean anyWithoutRecipeSource = generatedRecipes.stream().anyMatch(g -> g.getRecipe() == null);
if (anyWithoutRecipeSource) {
LOGGER.debug("Not found recipe source for generated recipe. Recipes should be uploaded and regenerated.");
return false;
}
Map<String, GeneratedRecipe> generatedRecipeNameMap = generatedRecipes.stream().collect(Collectors.toMap(g -> g.getRecipe().getName(), g -> g, (g1, g2) -> g1));
List<RecipeModel> recipeModelList = generatedModels.get(hostGroup);
if (generatedRecipes.size() != recipeModelList.size()) {
LOGGER.debug("Source and generated recipe counts are not matching for host group '{}'. Recipes should be uploaded and regenerated.", hostGroup.getName());
return false;
}
if (isRecipeUpToDateInHostGroup(hostGroup, generatedRecipeNameMap, recipeModelList)) {
LOGGER.debug("Recipes matches for host group '{}'", hostGroup.getName());
} else {
return false;
}
}
return true;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe in project cloudbreak by hortonworks.
the class UpdateRecipeServiceTest method testDetachRecipeFromCluster.
@Test
public void testDetachRecipeFromCluster() {
// GIVEN
Set<Recipe> recipes = createRecipes(Set.of(POST_CLDR_START_RECIPE));
Map<String, Set<String>> hostGroupsSample = new HashMap<>();
hostGroupsSample.put(MASTER_HOST_GROUP_NAME, Set.of(POST_CLDR_START_RECIPE));
Set<HostGroup> hostGroups = createHostGroupWithRecipes(hostGroupsSample);
Recipe sampleRecipe = recipes.stream().findFirst().orElse(null);
HostGroup sampleHostGroup = hostGroups.stream().findFirst().orElse(null);
given(hostGroupService.getByClusterIdAndNameWithRecipes(anyLong(), anyString())).willReturn(sampleHostGroup);
given(recipeService.getByNameForWorkspaceId(anyString(), anyLong())).willReturn(sampleRecipe);
given(hostGroupService.save(any())).willReturn(sampleHostGroup);
given(generatedRecipeService.save(any())).willReturn(new GeneratedRecipe());
// WHEN
underTest.detachRecipeFromCluster(DUMMY_ID, createStack(), POST_CLDR_START_RECIPE, MASTER_HOST_GROUP_NAME);
// THEN
verify(hostGroupService, times(1)).save(any());
verify(hostGroupService, times(1)).getByClusterIdAndNameWithRecipes(anyLong(), anyString());
verify(generatedRecipeService, times(1)).save(any());
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe in project cloudbreak by hortonworks.
the class UpdateRecipeServiceTest method createHostGroupWithRecipes.
private Set<HostGroup> createHostGroupWithRecipes(Map<String, Set<String>> hostGroupRecipesMap) {
Set<HostGroup> result = new HashSet<>();
for (Map.Entry<String, Set<String>> entry : hostGroupRecipesMap.entrySet()) {
HostGroup hostGroup = new HostGroup();
hostGroup.setName(entry.getKey());
Set<Recipe> recipeSet = new HashSet<>();
Set<GeneratedRecipe> generatedRecipeSet = new HashSet<>();
for (String recipeName : entry.getValue()) {
Recipe recipe = new Recipe();
GeneratedRecipe generatedRecipe = new GeneratedRecipe();
generatedRecipe.setRecipe(recipe);
recipe.setName(recipeName);
recipe.setGeneratedRecipes(Set.of(generatedRecipe));
recipeSet.add(recipe);
generatedRecipeSet.add(generatedRecipe);
}
hostGroup.setRecipes(recipeSet);
hostGroup.setGeneratedRecipes(generatedRecipeSet);
result.add(hostGroup);
}
return result;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.GeneratedRecipe in project cloudbreak by hortonworks.
the class RecipeTemplateServiceTest method testCompareGenerateRecipesWithGeneratedRecipeButNoRecipe.
@Test
public void testCompareGenerateRecipesWithGeneratedRecipeButNoRecipe() {
// 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", new HashSet<>(), generatedRecipes);
hgs.add(hgMaster);
Map<HostGroup, List<RecipeModel>> recipeModels = new HashMap<>();
// WHEN
boolean result = recipeTemplateService.isGeneratedRecipesInDbStale(hgs, recipeModels);
// THEN
assertFalse(result);
}
Aggregations