Search in sources :

Example 6 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.

the class HostGroupAssociationBuilder method buildHostGroupAssociations.

public Map<String, List<Map<String, String>>> buildHostGroupAssociations(Iterable<HostGroup> hostGroups) {
    Map<String, List<Map<String, String>>> hostGroupMappings = new HashMap<>();
    LOGGER.info("Computing host - hostGroup mappings based on hostGroup - instanceGroup associations");
    for (HostGroup hostGroup : hostGroups) {
        List<Map<String, String>> hostInfoForHostGroup = new ArrayList<>();
        if (hostGroup.getConstraint().getInstanceGroup() != null) {
            Map<String, String> topologyMapping = getTopologyMapping(hostGroup);
            Long instanceGroupId = hostGroup.getConstraint().getInstanceGroup().getId();
            List<InstanceMetaData> metas = instanceMetadataRepository.findAliveInstancesInInstanceGroup(instanceGroupId);
            if (metas.isEmpty()) {
                for (HostMetadata hostMetadata : hostGroup.getHostMetadata()) {
                    Map<String, String> hostInfo = new HashMap<>();
                    hostInfo.put(FQDN, hostMetadata.getHostName());
                    hostInfoForHostGroup.add(hostInfo);
                }
            } else {
                for (InstanceMetaData meta : metas) {
                    Map<String, String> hostInfo = new HashMap<>();
                    hostInfo.put(FQDN, meta.getDiscoveryFQDN());
                    String localityIndicator = meta.getLocalityIndicator();
                    if (localityIndicator != null) {
                        if (topologyMapping.isEmpty()) {
                            // Azure
                            if (localityIndicator.startsWith("/")) {
                                hostInfo.put("rack", meta.getLocalityIndicator());
                            // Openstack
                            } else {
                                hostInfo.put("rack", '/' + meta.getLocalityIndicator());
                            }
                        // With topology mapping
                        } else {
                            hostInfo.put("hypervisor", meta.getLocalityIndicator());
                            hostInfo.put("rack", topologyMapping.get(meta.getLocalityIndicator()));
                        }
                    }
                    hostInfoForHostGroup.add(hostInfo);
                }
            }
        } else {
            for (HostMetadata hostMetadata : hostGroup.getHostMetadata()) {
                Map<String, String> hostInfo = new HashMap<>();
                hostInfo.put(FQDN, hostMetadata.getHostName());
                hostInfoForHostGroup.add(hostInfo);
            }
        }
        hostGroupMappings.put(hostGroup.getName(), hostInfoForHostGroup);
    }
    LOGGER.info("Computed host-hostGroup associations: {}", hostGroupMappings);
    return hostGroupMappings;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 7 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.

the class TestUtil method instanceMetaData.

public static InstanceMetaData instanceMetaData(Long serverNumber, Long instanceGroupId, InstanceStatus instanceStatus, boolean ambariServer, InstanceGroup instanceGroup, InstanceMetadataType instanceMetadataType) {
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setInstanceStatus(instanceStatus);
    instanceMetaData.setAmbariServer(ambariServer);
    instanceMetaData.setConsulServer(true);
    instanceMetaData.setSshPort(22);
    instanceMetaData.setDiscoveryFQDN("test-" + instanceGroupId + '-' + serverNumber);
    instanceMetaData.setInstanceId("test-" + instanceGroupId + '-' + serverNumber);
    instanceMetaData.setPrivateIp("1.1." + instanceGroupId + '.' + serverNumber);
    instanceMetaData.setPublicIp("2.2." + instanceGroupId + '.' + serverNumber);
    instanceMetaData.setId(instanceGroupId + serverNumber);
    instanceMetaData.setInstanceGroup(instanceGroup);
    instanceMetaData.setStartDate(new Date().getTime());
    instanceMetaData.setInstanceMetadataType(instanceMetadataType);
    return instanceMetaData;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Date(java.util.Date)

Example 8 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.

the class StackScalingService method updateRemovedResourcesState.

@Transactional
public int updateRemovedResourcesState(Stack stack, Collection<String> instanceIds, InstanceGroup instanceGroup) {
    int nodesRemoved = 0;
    for (InstanceMetaData instanceMetaData : instanceGroup.getInstanceMetaData()) {
        if (instanceIds.contains(instanceMetaData.getInstanceId())) {
            long timeInMillis = Calendar.getInstance().getTimeInMillis();
            instanceMetaData.setTerminationDate(timeInMillis);
            instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
            instanceMetaDataRepository.save(instanceMetaData);
            nodesRemoved++;
        }
    }
    int nodeCount = instanceGroup.getNodeCount() - nodesRemoved;
    if (nodesRemoved != 0) {
        instanceGroup.setNodeCount(nodeCount);
        instanceGroupRepository.save(instanceGroup);
    }
    LOGGER.info("Successfully terminated metadata of instances '{}' in stack.", instanceIds);
    eventService.fireCloudbreakEvent(stack.getId(), BillingStatus.BILLING_CHANGED.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SCALING_BILLING_CHANGED.code()));
    return nodeCount;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.

the class StackScalingService method getUnusedInstanceIds.

public Map<String, String> getUnusedInstanceIds(String instanceGroupName, Integer scalingAdjustment, Stack stack) {
    Map<String, String> instanceIds = new HashMap<>();
    int i = 0;
    List<InstanceMetaData> instanceMetaDatas = new ArrayList<>(stack.getInstanceGroupByInstanceGroupName(instanceGroupName).getInstanceMetaData());
    instanceMetaDatas.sort(Comparator.comparing(InstanceMetaData::getStartDate));
    for (InstanceMetaData metaData : instanceMetaDatas) {
        if (!metaData.getAmbariServer() && (metaData.isDecommissioned() || metaData.isUnRegistered() || metaData.isCreated() || metaData.isFailed())) {
            instanceIds.put(metaData.getInstanceId(), metaData.getDiscoveryFQDN());
            if (++i >= scalingAdjustment * -1) {
                break;
            }
        }
    }
    return instanceIds;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 10 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.

the class TerminationService method terminateMetaDataInstances.

private void terminateMetaDataInstances(Stack stack) {
    Collection<InstanceMetaData> instanceMetaDatas = new ArrayList<>();
    for (InstanceMetaData metaData : stack.getRunningInstanceMetaData()) {
        long timeInMillis = Calendar.getInstance().getTimeInMillis();
        metaData.setTerminationDate(timeInMillis);
        metaData.setInstanceStatus(InstanceStatus.TERMINATED);
        instanceMetaDatas.add(metaData);
    }
    instanceMetaDataRepository.save(instanceMetaDatas);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)71 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)24 Stack (com.sequenceiq.cloudbreak.domain.Stack)23 ArrayList (java.util.ArrayList)18 HashSet (java.util.HashSet)17 Map (java.util.Map)16 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)13 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)11 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)9 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)9 List (java.util.List)9 Set (java.util.Set)9 Inject (javax.inject.Inject)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 Matchers.anyString (org.mockito.Matchers.anyString)7