Search in sources :

Example 1 with PRIVATE_ID

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.PRIVATE_ID in project cloudbreak by hortonworks.

the class VolumeMatcher method addVolumeResourcesToContext.

public ResourceBuilderContext addVolumeResourcesToContext(List<CloudInstance> instances, List<CloudResource> groupInstances, List<CloudResource> groupVolumeSets, ResourceBuilderContext context) {
    List<CloudResource> groupVolumeSetsWithFQDN = getGroupVolumeSetsWithFQDN(groupVolumeSets);
    List<CloudResource> groupVolumeSetsWithoutFQDN = getGroupVolumeSetsWithoutFQDN(groupVolumeSets);
    List<CloudResource> groupInstancesWithoutPrivateId = groupInstances.stream().filter(groupInstance -> groupInstance.getParameter(PRIVATE_ID, Long.class) == null).collect(Collectors.toList());
    for (int i = 0; i < instances.size() && i < groupInstances.size(); i++) {
        CloudInstance cloudInstance = instances.get(i);
        LOGGER.info("Check volumes for instance: {}", cloudInstance);
        CloudResource instanceResource = getCloudResource(groupInstances, groupInstancesWithoutPrivateId, cloudInstance);
        LOGGER.info("Instance resource: {}", instanceResource);
        Optional<CloudResource> volumeSetForFQDN = getVolumeSetForFQDN(groupVolumeSetsWithFQDN, cloudInstance);
        volumeSetForFQDN.ifPresent(cloudResource -> LOGGER.info("Volume set for this fqdn: {}", cloudResource));
        List<CloudResource> computeResource = volumeSetForFQDN.map(groupVolumeSet -> List.of(instanceResource, groupVolumeSet)).orElseGet(() -> getComputeResourceFromVolumesWithoutFQDN(groupVolumeSetsWithoutFQDN, instanceResource));
        LOGGER.info("Add volume resources {} to instance with private id: {}", computeResource, cloudInstance.getTemplate().getPrivateId());
        context.addComputeResources(cloudInstance.getTemplate().getPrivateId(), computeResource);
    }
    return context;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) List(java.util.List) Logger(org.slf4j.Logger) Service(org.springframework.stereotype.Service) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) PRIVATE_ID(com.sequenceiq.cloudbreak.cloud.model.CloudResource.PRIVATE_ID) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 PRIVATE_ID (com.sequenceiq.cloudbreak.cloud.model.CloudResource.PRIVATE_ID)1 VolumeSetAttributes (com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Service (org.springframework.stereotype.Service)1