use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class StackDecorator method prepareInstanceGroups.
private void prepareInstanceGroups(Stack subject, StackV4Request request, Credential credential, User user, DetailedEnvironmentResponse environment) {
Map<String, InstanceGroupParameterResponse> instanceGroupParameterResponse = cloudParameterService.getInstanceGroupParameters(extendedCloudCredentialConverter.convert(credential), getInstanceGroupParameterRequests(subject));
CloudbreakUser cloudbreakUser = legacyRestRequestThreadLocalService.getCloudbreakUser();
subject.getInstanceGroups().parallelStream().forEach(instanceGroup -> {
subject.getCluster().getHostGroups().stream().filter(hostGroup -> hostGroup.getName().equals(instanceGroup.getGroupName())).forEach(hostGroup -> hostGroup.setInstanceGroup(instanceGroup));
legacyRestRequestThreadLocalService.setCloudbreakUser(cloudbreakUser);
updateInstanceGroupParameters(instanceGroupParameterResponse, instanceGroup);
if (instanceGroup.getTemplate() != null) {
Template template = instanceGroup.getTemplate();
if (template.getId() == null) {
template.setCloudPlatform(credential.cloudPlatform());
PlacementSettingsV4Request placement = request.getPlacement();
String availabilityZone = placement != null ? placement.getAvailabilityZone() : subject.getAvailabilityZone();
String region = placement != null ? placement.getRegion() : subject.getRegion();
CdpResourceType cdpResourceType = cdpResourceTypeProvider.fromStackType(request.getType());
template = templateDecorator.decorate(credential, template, region, availabilityZone, subject.getPlatformVariant(), cdpResourceType);
template.setWorkspace(subject.getWorkspace());
setupDatabaseAttachedVolume(subject, instanceGroup, template);
template = templateService.create(user, template);
instanceGroup.setTemplate(template);
}
}
if (instanceGroup.getSecurityGroup() != null) {
SecurityGroup securityGroup = instanceGroup.getSecurityGroup();
if (securityGroup.getId() == null) {
securityGroup.setCloudPlatform(credential.cloudPlatform());
securityGroup.setWorkspace(subject.getWorkspace());
securityGroup = securityGroupService.create(user, securityGroup);
instanceGroup.setSecurityGroup(securityGroup);
}
}
if (instanceGroup.getInstanceGroupNetwork() != null) {
InstanceGroupNetwork ign = instanceGroup.getInstanceGroupNetwork();
instanceGroup.setAvailabilityZones(getAvailabilityZoneFromEnv(instanceGroup, environment));
if (ign.getId() == null) {
ign.setCloudPlatform(credential.cloudPlatform());
ign = instanceGroupNetworkService.create(ign);
instanceGroup.setInstanceGroupNetwork(ign);
}
}
});
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class MultiAzValidatorTest method instanceGroupNetwork.
private InstanceGroupNetwork instanceGroupNetwork(Set<String> subnetIds) {
InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
Map<String, Object> map = new HashMap<>();
map.put(NetworkConstants.SUBNET_IDS, subnetIds);
instanceGroupNetwork.setAttributes(new Json(map));
return instanceGroupNetwork;
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class MultiAzValidatorTest method testNotSupportedForInstanceMetadataGenerationWhenPlatformSupportedShouldReturnFalse.
@Test
public void testNotSupportedForInstanceMetadataGenerationWhenPlatformSupportedShouldReturnFalse() {
InstanceGroup instanceGroup = new InstanceGroup();
InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
instanceGroupNetwork.setCloudPlatform(CloudPlatform.AZURE.name());
instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
boolean supported = underTest.supportedForInstanceMetadataGeneration(instanceGroup);
assertEquals(false, supported);
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class MultiAzValidatorTest method testSupportedForInstanceMetadataGenerationWhenPlatformSupportedShouldReturnTrue.
@Test
public void testSupportedForInstanceMetadataGenerationWhenPlatformSupportedShouldReturnTrue() {
InstanceGroup instanceGroup = new InstanceGroup();
InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
instanceGroupNetwork.setCloudPlatform(CloudPlatform.AWS.name());
instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
boolean supported = underTest.supportedForInstanceMetadataGeneration(instanceGroup);
assertEquals(true, supported);
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class MultiAzCalculatorService method collectSubnetIds.
private Set<String> collectSubnetIds(InstanceGroup instanceGroup, NetworkScaleDetails networkScaleDetails) {
Set<String> allSubnetIds = new HashSet<>();
InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
if (instanceGroupNetwork != null) {
Json attributes = instanceGroupNetwork.getAttributes();
if (attributes != null) {
List<String> subnetIds = (List<String>) attributes.getMap().getOrDefault(SUBNET_IDS, new ArrayList<>());
if (isPreferredSubnetsSpecifiedForScaling(networkScaleDetails)) {
List<String> preferredSubnetIds = networkScaleDetails.getPreferredSubnetIds();
String preferredSubnetIdList = String.join(",", preferredSubnetIds);
LOGGER.debug("Collect subnet ids considering the customer preferred subnet ids: {}", preferredSubnetIdList);
Set<String> subnetIdsMatchedWithPreferred = subnetIds.stream().filter(preferredSubnetIds::contains).collect(Collectors.toSet());
LOGGER.info("Filtered subnet id list '{}' based on the customer preferred subnet id list '{}'", String.join(",", subnetIdsMatchedWithPreferred), preferredSubnetIdList);
allSubnetIds.addAll(subnetIdsMatchedWithPreferred);
} else {
allSubnetIds.addAll(subnetIds);
}
}
}
return allSubnetIds;
}
Aggregations