Search in sources :

Example 31 with InstanceGroup

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();
}
Also used : InstanceGroupDetails(com.sequenceiq.cloudbreak.structuredevent.event.InstanceGroupDetails) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 32 with InstanceGroup

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;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Example 33 with InstanceGroup

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);
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 34 with InstanceGroup

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;
}
Also used : MultiAzCalculatorService(com.sequenceiq.freeipa.service.multiaz.MultiAzCalculatorService) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceMetadataType(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetadataType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CachedEnvironmentClientService(com.sequenceiq.freeipa.service.client.CachedEnvironmentClientService) StackAuthenticationView(com.sequenceiq.freeipa.entity.projection.StackAuthenticationView) Service(org.springframework.stereotype.Service) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) FreeIpaService(com.sequenceiq.freeipa.service.freeipa.FreeIpaService) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Optional(java.util.Optional) InstanceMetaDataRepository(com.sequenceiq.freeipa.repository.InstanceMetaDataRepository) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) List(java.util.List) Map(java.util.Map)

Example 35 with InstanceGroup

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;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Aggregations

InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)60 Stack (com.sequenceiq.freeipa.entity.Stack)32 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)31 Test (org.junit.jupiter.api.Test)30 Template (com.sequenceiq.freeipa.entity.Template)18 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 FreeIpaServerRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)11 Json (com.sequenceiq.cloudbreak.common.json.Json)10 InstanceGroupRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest)10 NetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)9 InstanceGroupNetwork (com.sequenceiq.freeipa.entity.InstanceGroupNetwork)9 HashSet (java.util.HashSet)9 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)8 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)7 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)6 InstanceTemplateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest)6 HashMap (java.util.HashMap)6 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)5