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