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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations