use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariClusterCreationSuccessHandlerTest method testHandleClusterCreationSuccessWhenEverythingGoesFine.
@Test
public void testHandleClusterCreationSuccessWhenEverythingGoesFine() {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
Set<HostMetadata> hostMetadataList = new HashSet<>();
cluster.getHostGroups().forEach(hostGroup -> hostGroup.getHostMetadata().forEach(hostMetadataList::add));
List<InstanceMetaData> instanceMetaDataList = new ArrayList<>();
stack.getInstanceGroups().forEach(instanceGroup -> instanceGroup.getInstanceMetaData().forEach(instanceMetaDataList::add));
when(clusterService.updateCluster(cluster)).thenReturn(cluster);
when(instanceMetadataRepository.save(anyCollection())).thenReturn(instanceMetaDataList);
when(hostMetadataRepository.findHostsInCluster(cluster.getId())).thenReturn(hostMetadataList);
when(hostMetadataRepository.save(anyCollection())).thenReturn(hostMetadataList);
underTest.handleClusterCreationSuccess(stack, cluster);
ArgumentCaptor<Cluster> clusterCaptor = ArgumentCaptor.forClass(Cluster.class);
verify(clusterService, times(1)).updateCluster(clusterCaptor.capture());
assertNotNull(clusterCaptor.getValue().getCreationFinished());
assertNotNull(clusterCaptor.getValue().getUpSince());
ArgumentCaptor<List> instanceMetadataCaptor = ArgumentCaptor.forClass(List.class);
verify(instanceMetadataRepository, times(1)).save(instanceMetadataCaptor.capture());
for (InstanceMetaData instanceMetaData : (List<InstanceMetaData>) instanceMetadataCaptor.getValue()) {
Assert.assertEquals(InstanceStatus.REGISTERED, instanceMetaData.getInstanceStatus());
}
ArgumentCaptor<List> hostMetadataCaptor = ArgumentCaptor.forClass(List.class);
verify(hostMetadataRepository, times(1)).save(hostMetadataCaptor.capture());
for (HostMetadata hostMetadata : (List<HostMetadata>) hostMetadataCaptor.getValue()) {
Assert.assertEquals(HostMetadataState.HEALTHY, hostMetadata.getHostMetadataState());
}
verify(hostMetadataRepository, times(1)).findHostsInCluster(cluster.getId());
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariDecommissionerTest method testSelectNodesWhenHasOneUnhealthyNodeAndShouldSelectOne.
@Test
public void testSelectNodesWhenHasOneUnhealthyNodeAndShouldSelectOne() {
String hostname1 = "10.0.0.1";
String hostname2 = "10.0.0.2";
HostMetadata unhealhtyNode = getHostMetadata(hostname1, HostMetadataState.UNHEALTHY);
HostMetadata healhtyNode = getHostMetadata(hostname2, HostMetadataState.HEALTHY);
Collection<HostMetadata> nodes = Arrays.asList(unhealhtyNode, healhtyNode);
Map<String, Long> ascendingNodes = new LinkedHashMap<>();
ascendingNodes.put(hostname1, 100L);
ascendingNodes.put(hostname2, 110L);
Map<String, Long> selectedNodes = underTest.selectNodes(ascendingNodes, nodes, 1);
Assert.assertEquals(1, selectedNodes.size());
Assert.assertEquals(hostname1, selectedNodes.keySet().stream().findFirst().get());
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariDecommissionerTest method testSelectNodesWhenHasOneUnhealthyNodeAndShouldSelectTwo.
@Test
public void testSelectNodesWhenHasOneUnhealthyNodeAndShouldSelectTwo() {
String hostname1 = "10.0.0.1";
String hostname2 = "10.0.0.2";
String hostname3 = "10.0.0.3";
HostMetadata unhealhtyNode = getHostMetadata(hostname1, HostMetadataState.UNHEALTHY);
HostMetadata healhtyNode1 = getHostMetadata(hostname2, HostMetadataState.HEALTHY);
HostMetadata healhtyNode2 = getHostMetadata(hostname3, HostMetadataState.HEALTHY);
List<HostMetadata> nodes = Arrays.asList(unhealhtyNode, healhtyNode1, healhtyNode2);
Map<String, Long> ascendingNodes = new LinkedHashMap<>();
ascendingNodes.put(hostname1, 100L);
ascendingNodes.put(hostname2, 110L);
ascendingNodes.put(hostname3, 120L);
Map<String, Long> selectedNodes = underTest.selectNodes(ascendingNodes, nodes, 2);
Assert.assertEquals(2, selectedNodes.size());
Assert.assertTrue(selectedNodes.keySet().containsAll(Arrays.asList(hostname1, hostname2)));
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariClusterUpscaleService method installServicesOnNewHosts.
public void installServicesOnNewHosts(Long stackId, String hostGroupName) throws CloudbreakException {
Stack stack = stackService.getByIdWithLists(stackId);
LOGGER.info("Start installing Ambari services");
HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stack.getCluster().getId(), hostGroupName);
Set<HostMetadata> hostMetadata = hostGroupService.findEmptyHostMetadataInHostGroup(hostGroup.getId());
ambariClusterConnector.upscaleCluster(stack, hostGroup, hostMetadata);
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class StackResponseHardwareInfoProvider method providerEntriesToStackResponse.
@Override
public StackResponse providerEntriesToStackResponse(Stack stack, StackResponse stackResponse) {
Set<HardwareInfoResponse> hardwareInfoResponses = new HashSet<>();
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
for (InstanceMetaData instanceMetaData : instanceGroup.getAllInstanceMetaData()) {
HostMetadata hostMetadata = null;
if (stack.getCluster() != null && instanceMetaData.getDiscoveryFQDN() != null) {
hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), instanceMetaData.getDiscoveryFQDN());
}
HardwareInfoResponse hardwareInfoResponse = new HardwareInfoResponse();
hardwareInfoResponse.setInstanceMetaData(conversionService.convert(instanceMetaData, InstanceMetaDataJson.class));
hardwareInfoResponse.setHostMetadata(conversionService.convert(hostMetadata, HostMetadataResponse.class));
hardwareInfoResponses.add(hardwareInfoResponse);
}
}
stackResponse.setHardwareInfos(hardwareInfoResponses);
return stackResponse;
}
Aggregations