use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceGroupToInstanceGroupDetailsConverterTest method convertEmptyNoNullPointer.
@Test
void convertEmptyNoNullPointer() {
InstanceGroup instanceGroup = new InstanceGroup();
InstanceGroupDetails instanceGroupDetails = underTest.convert(instanceGroup);
assertThat(instanceGroupDetails).isNotNull();
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceMetaDataToInstanceMetaDataResponseConverterTest method createInstanceMetaData.
private InstanceMetaData createInstanceMetaData(String publicIp, String privateIp) {
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setGroupName(INSTANCE_GROUP);
InstanceMetaData result = new InstanceMetaData();
result.setPrivateIp(privateIp);
result.setPublicIp(publicIp);
result.setSshPort(SSH_PORT);
result.setInstanceId(INSTANCE_ID);
result.setDiscoveryFQDN(DISCOVERY_FQDN);
result.setInstanceGroup(instanceGroup);
result.setSubnetId(SUBNET_ID);
result.setAvailabilityZone(AVAILABILITY_ZONE);
result.setInstanceStatus(INSTANCE_STATUS);
result.setInstanceMetadataType(INSTANCE_METADATA_TYPE);
result.setLifeCycle(LIFE_CYCLE);
return result;
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceRequests.
public void saveInstanceRequests(Stack stack, List<Group> groups) {
Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
for (Group group : groups) {
InstanceGroup instanceGroup = getInstanceGroup(instanceGroups, group.getName());
List<InstanceMetaData> existingInGroup = instanceMetaDataRepository.findAllByInstanceGroupAndInstanceStatus(instanceGroup, com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.REQUESTED);
for (CloudInstance cloudInstance : group.getInstances()) {
InstanceTemplate instanceTemplate = cloudInstance.getTemplate();
boolean exists = existingInGroup.stream().anyMatch(i -> i.getPrivateId().equals(instanceTemplate.getPrivateId()));
if (InstanceStatus.CREATE_REQUESTED == instanceTemplate.getStatus() && !exists) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setPrivateId(instanceTemplate.getPrivateId());
instanceMetaData.setInstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setVariant(stack.getPlatformvariant());
instanceMetaDataRepository.save(instanceMetaData);
}
}
}
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceAndGetUpdatedStack.
public Stack saveInstanceAndGetUpdatedStack(Stack stack, List<CloudInstance> cloudInstances) {
FreeIpa freeIpa = freeIpaService.findByStack(stack);
DetailedEnvironmentResponse environment = measure(() -> cachedEnvironmentClientService.getByCrn(stack.getEnvironmentCrn()), LOGGER, "Environment properties were queried under {} ms for environment {}", stack.getEnvironmentCrn());
Map<String, List<CloudInstance>> instancesPerGroup = cloudInstances.stream().collect(Collectors.groupingBy(cloudInstance -> cloudInstance.getTemplate().getGroupName()));
for (Map.Entry<String, List<CloudInstance>> instancesPerGroupEntry : instancesPerGroup.entrySet()) {
InstanceGroup instanceGroup = getInstanceGroup(stack.getInstanceGroups(), instancesPerGroupEntry.getKey());
if (instanceGroup != null) {
Map<String, String> subnetAzMap = multiAzCalculatorService.prepareSubnetAzMap(environment);
Map<String, Integer> currentSubnetUsage = multiAzCalculatorService.calculateCurrentSubnetUsage(subnetAzMap, instanceGroup);
for (CloudInstance cloudInstance : instancesPerGroupEntry.getValue()) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
Long privateId = cloudInstance.getTemplate().getPrivateId();
instanceMetaData.setPrivateId(privateId);
instanceMetaData.setInstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setDiscoveryFQDN(freeIpa.getHostname() + String.format("%d.", privateId) + freeIpa.getDomain());
if (!subnetAzMap.isEmpty()) {
Map<String, String> filteredSubnetsByLeastUsedAz = multiAzCalculatorService.filterSubnetByLeastUsedAz(instanceGroup, subnetAzMap);
multiAzCalculatorService.updateSubnetIdForSingleInstanceIfEligible(filteredSubnetsByLeastUsedAz, currentSubnetUsage, instanceMetaData, instanceGroup);
}
instanceMetaDataRepository.save(instanceMetaData);
LOGGER.debug("Saved InstanceMetaData: {}", instanceMetaData);
instanceGroup.getInstanceMetaDataSet().add(instanceMetaData);
}
}
}
return stack;
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class MetadataSetupService method saveInstanceMetaData.
public int saveInstanceMetaData(Stack stack, Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatusList, InstanceStatus status) {
int newInstances = 0;
Set<InstanceMetaData> allInstanceMetadata = instanceMetaDataService.findNotTerminatedForStack(stack.getId());
boolean primaryIgSelected = allInstanceMetadata.stream().anyMatch(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY);
for (CloudVmMetaDataStatus cloudVmMetaDataStatus : cloudVmMetaDataStatusList) {
CloudInstance cloudInstance = cloudVmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance();
CloudInstanceMetaData md = cloudVmMetaDataStatus.getMetaData();
Long privateId = cloudInstance.getTemplate().getPrivateId();
String instanceId = cloudInstance.getInstanceId();
InstanceMetaData instanceMetaDataEntry = createInstanceMetadataIfAbsent(allInstanceMetadata, privateId, instanceId);
if (instanceMetaDataEntry.getInstanceId() == null) {
newInstances++;
}
// CB 1.0.x clusters do not have private id thus we cannot correlate them with instance groups thus keep the original one
InstanceGroup ig = instanceMetaDataEntry.getInstanceGroup();
String group = ig == null ? cloudInstance.getTemplate().getGroupName() : ig.getGroupName();
InstanceGroup instanceGroup = instanceGroupService.findOneByGroupNameInStack(stack.getId(), group).orElse(null);
instanceMetaDataEntry.setPrivateIp(md.getPrivateIp());
instanceMetaDataEntry.setPublicIp(md.getPublicIp());
instanceMetaDataEntry.setSshPort(md.getSshPort());
instanceMetaDataEntry.setLocalityIndicator(md.getLocalityIndicator());
instanceMetaDataEntry.setInstanceGroup(instanceGroup);
instanceMetaDataEntry.setInstanceId(instanceId);
instanceMetaDataEntry.setPrivateId(privateId);
instanceMetaDataEntry.setStartDate(clock.getCurrentTimeMillis());
instanceMetaDataEntry.setSubnetId(cloudInstance.getSubnetId());
instanceMetaDataEntry.setAvailabilityZone(cloudInstance.getAvailabilityZone());
instanceMetaDataEntry.setInstanceName(cloudInstance.getStringParameter(CloudInstance.INSTANCE_NAME));
instanceMetaDataEntry.setLifeCycle(convertLifeCycle(md));
if (instanceMetaDataEntry.getInstanceMetadataType() == null) {
if (ig != null) {
if (!primaryIgSelected && ig.getInstanceGroupType() == com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupType.MASTER) {
primaryIgSelected = true;
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
} else {
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
}
} else {
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
}
}
if (status != null) {
instanceMetaDataEntry.setInstanceStatus(status);
}
instanceMetaDataService.save(instanceMetaDataEntry);
}
return newInstances;
}
Aggregations