use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class StopStartUpscaleCommissionViaCMHandlerTest method testErrorFromCmHostCollection.
@Test
void testErrorFromCmHostCollection() throws ClusterClientInitException {
int commissionInstanceCount = 5;
List<InstanceMetaData> instancesToCommission = createInstancesToCommission(commissionInstanceCount);
HostGroup hostGroup = createHostGroup(instancesToCommission);
Set<String> hostNames = instancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
Map<String, InstanceMetaData> cmAvailableHosts = instancesToCommission.stream().collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
Set<String> recommissionedFqdns = cmAvailableHosts.keySet().stream().collect(Collectors.toUnmodifiableSet());
setupPerTestMocks(hostGroup, hostNames, cmAvailableHosts, recommissionedFqdns);
when(clusterCommissionService.collectHostsToCommission(eq(hostGroup), eq(hostNames))).thenThrow(new RuntimeException("collectHostsToCommissionError"));
StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instancesToCommission, Collections.emptyList());
HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
Selectable selectable = underTest.doAccept(handlerEvent);
assertThat(selectable).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
StopStartUpscaleCommissionViaCMResult result = (StopStartUpscaleCommissionViaCMResult) selectable;
assertThat(result.getSuccessfullyCommissionedFqdns()).hasSize(0);
assertThat(result.getNotRecommissionedFqdns()).hasSize(0);
assertThat(result.getErrorDetails().getMessage()).isEqualTo("collectHostsToCommissionError");
assertThat(result.getStatus()).isEqualTo(EventStatus.FAILED);
assertThat(result.selector()).isEqualTo("STOPSTARTUPSCALECOMMISSIONVIACMRESULT_ERROR");
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup 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.HostGroup 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.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method testCannotRepairGatewayWithoutExternalDatabase.
@Test
public void testCannotRepairGatewayWithoutExternalDatabase() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
HostGroup hostGroup1 = new HostGroup();
hostGroup1.setName("hostGroup1");
hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_HEALTHY, InstanceGroupType.GATEWAY);
hostGroup1.setInstanceGroup(host1.getInstanceGroup());
when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
when(componentConfigProviderService.getImage(stack.getId())).thenReturn(mock(Image.class));
com.sequenceiq.cloudbreak.cloud.model.catalog.Image image = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
when(image.isPrewarmed()).thenReturn(true);
when(imageCatalogService.getImage(any(), any(), any())).thenReturn(StatedImage.statedImage(image, "catalogUrl", "catalogName"));
when(clusterDBValidationService.isGatewayRepairEnabled(cluster)).thenReturn(false);
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
Result result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairWithDryRun(stack.getId()));
assertFalse(result.isSuccess());
verifyNoInteractions(stackUpdater, flowManager, resourceService);
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method testCanRepairCoreTypeNode.
@Test
public void testCanRepairCoreTypeNode() {
cluster.setDatabaseServerCrn("dbCrn");
HostGroup hostGroup1 = new HostGroup();
hostGroup1.setName("hostGroup1");
hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
InstanceMetaData host1 = getHost("host1", hostGroup1.getName(), InstanceStatus.SERVICES_RUNNING, InstanceGroupType.CORE);
hostGroup1.setInstanceGroup(host1.getInstanceGroup());
when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
DatabaseServerV4Response databaseServerV4Response = new DatabaseServerV4Response();
databaseServerV4Response.setStatus(AVAILABLE);
when(redbeamsClientService.getByCrn(eq("dbCrn"))).thenReturn(databaseServerV4Response);
when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.NONE);
Result result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairWithDryRun(stack.getId()));
assertTrue(result.isSuccess());
verifyNoInteractions(stackUpdater, flowManager, resourceService);
}
Aggregations