use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method testRepairByNodeIds.
@Test
public void testRepairByNodeIds() {
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setInstanceGroupType(InstanceGroupType.CORE);
HostGroup hostGroup1 = new HostGroup();
hostGroup1.setName("hostGroup1");
hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
hostGroup1.setInstanceGroup(instanceGroup);
when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
InstanceMetaData instance1md = new InstanceMetaData();
instance1md.setInstanceId("instanceId1");
instance1md.setDiscoveryFQDN("host1Name.healthy");
instance1md.setInstanceGroup(instanceGroup);
instanceGroup.setInstanceMetaData(Collections.singleton(instance1md));
Resource volumeSet = new Resource();
VolumeSetAttributes attributes = new VolumeSetAttributes("eu-west-1", Boolean.TRUE, "", List.of(), 100, "standard");
attributes.setDeleteOnTermination(null);
volumeSet.setAttributes(new Json(attributes));
volumeSet.setInstanceId("instanceId1");
volumeSet.setResourceType(ResourceType.AWS_VOLUMESET);
FlowLog flowLog = new FlowLog();
flowLog.setStateStatus(StateStatus.SUCCESSFUL);
when(stackUpdater.updateStackStatus(1L, DetailedStackStatus.REPAIR_IN_PROGRESS)).thenReturn(stack);
when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
when(stack.getInstanceMetaDataAsList()).thenReturn(List.of(instance1md));
when(resourceService.findByStackIdAndType(stack.getId(), volumeSet.getResourceType())).thenReturn(List.of(volumeSet));
when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.NONE);
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairNodes(1L, Set.of("instanceId1"), false, false));
verify(resourceService).findByStackIdAndType(stack.getId(), volumeSet.getResourceType());
@SuppressWarnings("unchecked") ArgumentCaptor<List<Resource>> saveCaptor = ArgumentCaptor.forClass(List.class);
verify(resourceService).saveAll(saveCaptor.capture());
assertFalse(resourceAttributeUtil.getTypedAttributes(saveCaptor.getValue().get(0), VolumeSetAttributes.class).get().getDeleteOnTermination());
verify(flowManager).triggerClusterRepairFlow(eq(1L), eq(Map.of("hostGroup1", List.of("host1Name.healthy"))), eq(false), eq(false));
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method testValidateRepairWhenNoUnhealthyGWAndNotSelected.
@Test
public void testValidateRepairWhenNoUnhealthyGWAndNotSelected() {
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.NONE);
HostGroup hostGroup1 = new HostGroup();
hostGroup1.setName("idbroker");
hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
InstanceMetaData host1 = getHost("idbroker1", hostGroup1.getName(), InstanceStatus.SERVICES_UNHEALTHY, InstanceGroupType.CORE);
hostGroup1.setInstanceGroup(host1.getInstanceGroup());
when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
InstanceMetaData primaryGW = new InstanceMetaData();
primaryGW.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setGroupName("gateway");
primaryGW.setInstanceGroup(instanceGroup);
InstanceMetaData secondaryGW = new InstanceMetaData();
secondaryGW.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
secondaryGW.setInstanceGroup(instanceGroup);
ArrayList<InstanceMetaData> gatewayInstances = new ArrayList<>();
gatewayInstances.add(primaryGW);
gatewayInstances.add(secondaryGW);
when(stack.getNotTerminatedGatewayInstanceMetadata()).thenReturn(gatewayInstances);
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> actual = underTest.validateRepair(ManualClusterRepairMode.HOST_GROUP, STACK_ID, Set.of("idbroker"), false);
assertTrue(actual.isSuccess());
});
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterRepairServiceTest method testValidateRepairWhenReattachNotSupported.
@Test
public void testValidateRepairWhenReattachNotSupported() {
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.EPHEMERAL_VOLUMES);
String idbrokerGroupName = "idbroker";
HostGroup idbrokerHg = new HostGroup();
idbrokerHg.setName(idbrokerGroupName);
idbrokerHg.setRecoveryMode(RecoveryMode.MANUAL);
InstanceGroup idbrokerIg = createUnhealthyInstanceGroup(idbrokerGroupName, Set.of(createVolumeTemplate(AwsDiskType.Ephemeral)));
idbrokerHg.setInstanceGroup(idbrokerIg);
stack.setInstanceGroups(Set.of(idbrokerIg));
when(hostGroupService.getByCluster(CLUSTER_ID)).thenReturn(Set.of(idbrokerHg));
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> actual = underTest.validateRepair(ManualClusterRepairMode.HOST_GROUP, STACK_ID, Set.of(idbrokerGroupName), false);
assertEquals("Reattach not supported for this disk type.", actual.getError().getValidationErrors().get(0));
});
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class StopStartDownscaleDecommissionViaCMHandlerTest method createHostGroup.
private HostGroup createHostGroup(List<InstanceMetaData> instancesToDecommission) {
HostGroup hostGroup = new HostGroup();
hostGroup.setName(INSTANCE_GROUP_NAME);
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setGroupName(INSTANCE_GROUP_NAME);
instanceGroup.setInstanceMetaData(new HashSet<>(instancesToDecommission));
hostGroup.setInstanceGroup(instanceGroup);
return hostGroup;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class StopStartDownscaleDecommissionViaCMHandlerTest method testErrorFromCmCommission.
@Test
void testErrorFromCmCommission() {
int instancesToDecommissionCount = 5;
int expcetedInstanceToCollectCount = 5;
int expectedInstancesDecommissionedCount = 5;
List<InstanceMetaData> instancesToDecommission = getInstancesToDecommission(instancesToDecommissionCount);
HostGroup hostGroup = createHostGroup(instancesToDecommission);
Map<String, InstanceMetaData> collected = instancesToDecommission.stream().limit(expcetedInstanceToCollectCount).collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
List<InstanceMetaData> decommissionedMetadataList = collected.values().stream().limit(expectedInstancesDecommissionedCount).collect(Collectors.toList());
Set<String> fqdnsDecommissioned = decommissionedMetadataList.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toUnmodifiableSet());
Set<Long> instanceIdsToDecommission = instancesToDecommission.stream().map(InstanceMetaData::getPrivateId).collect(Collectors.toUnmodifiableSet());
Set<String> hostnamesToDecommission = instancesToDecommission.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toUnmodifiableSet());
setupAdditionalMocks(hostGroup, instancesToDecommission, collected, fqdnsDecommissioned);
when(clusterDecomissionService.decommissionClusterNodesStopStart(eq(collected), anyLong())).thenThrow(new RuntimeException("decommissionHostsError"));
StopStartDownscaleDecommissionViaCMRequest request = new StopStartDownscaleDecommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instanceIdsToDecommission);
HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
Selectable selectable = underTest.doAccept(handlerEvent);
verify(clusterDecomissionService).collectHostsToRemove(eq(hostGroup), eq(hostnamesToDecommission));
verify(clusterDecomissionService).decommissionClusterNodesStopStart(eq(collected), anyLong());
assertThat(selectable).isInstanceOf(StopStartDownscaleDecommissionViaCMResult.class);
StopStartDownscaleDecommissionViaCMResult result = (StopStartDownscaleDecommissionViaCMResult) selectable;
assertThat(result.getNotDecommissionedHostFqdns()).hasSize(0);
assertThat(result.getDecommissionedHostFqdns()).hasSize(0);
assertThat(result.getErrorDetails().getMessage()).isEqualTo("decommissionHostsError");
assertThat(result.getStatus()).isEqualTo(EventStatus.FAILED);
assertThat(result.selector()).isEqualTo("STOPSTARTDOWNSCALEDECOMMISSIONVIACMRESULT_ERROR");
verifyNoMoreInteractions(instanceMetaDataService);
verifyNoMoreInteractions(flowMessageService);
verifyNoMoreInteractions(clusterDecomissionService);
}
Aggregations