Search in sources :

Example 41 with HostMetadata

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());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) ArrayList(java.util.ArrayList) List(java.util.List) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 42 with HostMetadata

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());
}
Also used : HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 43 with HostMetadata

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)));
}
Also used : HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 44 with HostMetadata

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);
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 45 with 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;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HostMetadataResponse(com.sequenceiq.cloudbreak.api.model.HostMetadataResponse) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) HardwareInfoResponse(com.sequenceiq.cloudbreak.api.model.HardwareInfoResponse) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)52 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)20 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)17 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)16 HashSet (java.util.HashSet)16 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Test (org.junit.Test)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 List (java.util.List)10 Map (java.util.Map)10 Status (com.sequenceiq.cloudbreak.api.model.Status)8 Collections.singletonMap (java.util.Collections.singletonMap)8 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)7 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)7 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)6 LinkedHashMap (java.util.LinkedHashMap)5 Set (java.util.Set)5