use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class InstanceMetadataServiceComponentTest method saveInstanceAndGetUpdatedStackWhenPreferredSubnetSet.
@Test
public void saveInstanceAndGetUpdatedStackWhenPreferredSubnetSet() {
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(environmentClientService.getByCrn(ENV_CRN)).thenReturn(detailedEnvResponse);
NetworkScaleDetails networkScaleDetails = new NetworkScaleDetails(List.of("sub1", "sub2"));
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, Map.of("worker", 42), Map.of(), false, false, networkScaleDetails);
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(1, groupByAz.size());
Assertions.assertEquals(42, groupByAz.get("az").size());
Assertions.assertNull(groupByAz.get("az1"));
Assertions.assertEquals(2, groupBySub.size());
Assertions.assertEquals(21, groupBySub.get("sub1").size());
Assertions.assertEquals(21, groupBySub.get("sub2").size());
Assertions.assertNull(groupBySub.get("sub3"));
Assertions.assertNull(groupBySub.get("sub4"));
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.network.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(environmentClientService.getByCrn(ENV_CRN)).thenReturn(detailedEnvResponse);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, Map.of("worker", 42), Map.of(), false, false, null);
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.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method instanceGroup.
private InstanceGroup instanceGroup(CloudPlatform cloudPlatform, int instanceNumber, int subnetCount) {
InstanceGroup instanceGroup = new InstanceGroup();
List<String> subnets = new ArrayList<>();
for (int i = 0; i < subnetCount; i++) {
instanceGroup.getAvailabilityZones().add(cloudSubnetAz(i));
subnets.add(cloudSubnetName(i));
}
InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
instanceGroupNetwork.setCloudPlatform(cloudPlatform.name());
instanceGroupNetwork.setAttributes(new Json(Map.of(NetworkConstants.SUBNET_IDS, subnets)));
instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
for (int i = 0; i < instanceNumber; i++) {
instanceGroup.getAllInstanceMetaData().add(instanceMetaData(i));
}
return instanceGroup;
}
Aggregations