use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildGroupNetwork.
private GroupNetwork buildGroupNetwork(com.sequenceiq.freeipa.entity.Network network, InstanceGroup instanceGroup) {
GroupNetwork groupNetwork = null;
InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
if (instanceGroupNetwork != null) {
Json attributes = instanceGroupNetwork.getAttributes();
Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
Set<GroupSubnet> subnets = new HashSet<>();
if (params != null) {
List<String> subnetIds = (List<String>) params.getOrDefault(NetworkConstants.SUBNET_IDS, new ArrayList<>());
for (String subnetId : subnetIds) {
GroupSubnet groupSubnet = new GroupSubnet(subnetId);
subnets.add(groupSubnet);
}
}
groupNetwork = new GroupNetwork(network.getOutboundInternetTraffic(), subnets, params);
}
return groupNetwork;
}
use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class InstanceGroupNetworkRequestToInstanceGroupNetworkConverter method convert.
public InstanceGroupNetwork convert(String cloudPlatform, @Nonnull InstanceGroupNetworkRequest source) {
InstanceGroupNetwork entity = new InstanceGroupNetwork();
entity.setCloudPlatform(cloudPlatform);
Map<String, Object> params = new HashMap<>();
InstanceGroupAwsNetworkParameters aws = source.getAws();
if (aws != null && aws.getSubnetIds() != null) {
List<String> subnetIds = aws.getSubnetIds();
params.put(NetworkConstants.SUBNET_IDS, subnetIds);
}
entity.setAttributes(new Json(params));
return entity;
}
use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class InstanceMetadataServiceComponentTest method saveInstanceAndGetUpdatedStack.
@Test
public void saveInstanceAndGetUpdatedStack() {
DetailedEnvironmentResponse detailedEnvResponse = DetailedEnvironmentResponse.builder().withCrn(ENV_CRN).withNetwork(EnvironmentNetworkResponse.builder().withSubnetMetas(Map.of("sub1", cloudSubnet("az", "sub1"), "sub2", cloudSubnet("az", "sub2"), "sub3", cloudSubnet("az", "sub3"), "sub4", cloudSubnet("az1", "sub4"))).build()).build();
Stack stack = new Stack();
stack.setEnvironmentCrn(ENV_CRN);
InstanceGroup workerInstanceGroup = new InstanceGroup();
workerInstanceGroup.setGroupName("worker");
InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
instanceGroupNetwork.setCloudPlatform("AWS");
instanceGroupNetwork.setAttributes(new Json(Map.of(SUBNET_IDS, List.of("sub1", "sub2", "sub3", "sub4"))));
workerInstanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
stack.setInstanceGroups(Set.of(workerInstanceGroup));
when(cachedEnvironmentClientService.getByCrn(ENV_CRN)).thenReturn(detailedEnvResponse);
FreeIpa freeIpa = new FreeIpa();
freeIpa.setHostname("hostname");
freeIpa.setDomain("domain");
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, cloudInstances(42));
Map<String, List<InstanceMetaData>> groupBySub = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getSubnetId, Collectors.mapping(Function.identity(), Collectors.toList())));
Map<String, List<InstanceMetaData>> groupByAz = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getAvailabilityZone, Collectors.mapping(Function.identity(), Collectors.toList())));
Assertions.assertEquals(2, groupByAz.size());
Assertions.assertEquals(21, groupByAz.get("az").size());
Assertions.assertEquals(21, groupByAz.get("az1").size());
Assertions.assertEquals(4, groupBySub.size());
Assertions.assertEquals(7, groupBySub.get("sub1").size());
Assertions.assertEquals(7, groupBySub.get("sub2").size());
Assertions.assertEquals(7, groupBySub.get("sub3").size());
Assertions.assertEquals(21, groupBySub.get("sub4").size());
}
use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class DefaultInstanceGroupProviderTest method createDefaultNetworkWithAwsAttributesShouldReturnWithNetworkAttributes.
@Test
void createDefaultNetworkWithAwsAttributesShouldReturnWithNetworkAttributes() {
Json json = new Json(Map.of(NetworkConstants.SUBNET_IDS, Set.of("id")));
NetworkRequest network = new NetworkRequest();
AwsNetworkParameters awsNetworkParameters = new AwsNetworkParameters();
awsNetworkParameters.setSubnetId("id");
network.setAws(awsNetworkParameters);
InstanceGroupNetwork defaultNetwork = underTest.createDefaultNetwork(CloudPlatform.AWS, network);
assertThat(defaultNetwork.getAttributes()).isEqualTo(json);
}
use of com.sequenceiq.freeipa.entity.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method testCalculateRoundRobin.
@Test
public void testCalculateRoundRobin() {
InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
instanceGroupNetwork.setAttributes(Json.silent(Map.of(SUBNET_IDS, List.of(SUB_1, SUB_2, "ONLYINIG"))));
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
InstanceMetaData deletedInstance = createInstanceMetadata(SUB_1);
deletedInstance.setInstanceStatus(InstanceStatus.TERMINATED);
instanceGroup.setInstanceMetaData(Set.of(createInstanceMetadata(null), createInstanceMetadata(null), createInstanceMetadata(null), createInstanceMetadata(SUB_2), createInstanceMetadata(null), createInstanceMetadata(" "), createInstanceMetadata("IGNORED"), deletedInstance));
when(multiAzValidator.supportedForInstanceMetadataGeneration(instanceGroup)).thenReturn(Boolean.TRUE);
underTest.calculateByRoundRobin(SUBNET_AZ_PAIRS, instanceGroup);
assertEquals(3, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_1.equals(im.getSubnetId()) && "AZ1".equals(im.getAvailabilityZone())).count());
assertEquals(2, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_2.equals(im.getSubnetId()) && "AZ2".equals(im.getAvailabilityZone())).count());
assertEquals(3, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_2.equals(im.getSubnetId())).count());
assertEquals(1, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> "IGNORED".equals(im.getSubnetId())).count());
}
Aggregations