use of com.sequenceiq.cloudbreak.cloud.model.GroupNetwork in project cloudbreak by hortonworks.
the class AwsGatewaySubnetMultiAzValidatorTest method testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkHasValidSubnetAndEC2ClientCallFails.
@Test
void testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkHasValidSubnetAndEC2ClientCallFails() {
String aSubnetId = "aSubnetId";
Set<GroupSubnet> of = Set.of(new GroupSubnet(aSubnetId));
GroupNetwork groupNetwork = new GroupNetwork(OutboundInternetTraffic.ENABLED, of, Map.of());
Group gatewayGroup = getGroup("aGroupName", InstanceGroupType.GATEWAY, groupNetwork);
CloudStack cloudStack = getCloudStack(Set.of(gatewayGroup));
when(awsClient.createEc2Client(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeSubnets(any())).thenThrow(new AmazonServiceException("Something went wrong"));
Assertions.assertThrows(CloudConnectorException.class, () -> underTest.validate(authenticatedContext, cloudStack));
}
use of com.sequenceiq.cloudbreak.cloud.model.GroupNetwork in project cloudbreak by hortonworks.
the class AwsGatewaySubnetMultiAzValidatorTest method testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkHasValidSubnetConfiguration.
@Test
void testValidateWhenThereIsGatewayGroupButInstanceGroupNetworkHasValidSubnetConfiguration() {
String aSubnetId = "aSubnetId";
Set<GroupSubnet> of = Set.of(new GroupSubnet(aSubnetId));
GroupNetwork groupNetwork = new GroupNetwork(OutboundInternetTraffic.ENABLED, of, Map.of());
Group gatewayGroup = getGroup("aGroupName", InstanceGroupType.GATEWAY, groupNetwork);
CloudStack cloudStack = getCloudStack(Set.of(gatewayGroup));
when(awsClient.createEc2Client(any(), any())).thenReturn(ec2Client);
DescribeSubnetsResult describeSubnetsResult = new DescribeSubnetsResult().withSubnets(Set.of(new Subnet().withSubnetId(aSubnetId).withAvailabilityZone("anAZ")));
when(ec2Client.describeSubnets(any())).thenReturn(describeSubnetsResult);
underTest.validate(authenticatedContext, cloudStack);
}
use of com.sequenceiq.cloudbreak.cloud.model.GroupNetwork in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildInstanceGroups.
private List<Group> buildInstanceGroups(Stack stack, List<InstanceGroup> instanceGroups, Collection<String> deleteRequests, String imageName, Optional<CloudFileSystemView> fileSystemView) {
String cloudPlatform = stack.getCloudPlatform();
// sort by name to avoid shuffling the different instance groups
Collections.sort(instanceGroups);
List<Group> groups = new ArrayList<>();
InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stack.getStackAuthentication());
for (InstanceGroup instanceGroup : instanceGroups) {
if (instanceGroup.getTemplate() != null) {
CloudInstance skeleton = null;
List<CloudInstance> instances = new ArrayList<>();
Template template = instanceGroup.getTemplate();
// existing instances
for (InstanceMetaData metaData : instanceGroup.getNotDeletedInstanceMetaDataSet()) {
InstanceStatus status = getInstanceStatus(metaData, deleteRequests);
instances.add(buildInstance(stack, metaData, instanceGroup, stack.getStackAuthentication(), metaData.getPrivateId(), status, imageName));
}
if (instanceGroup.getNodeCount() == 0) {
skeleton = buildInstance(stack, null, instanceGroup, stack.getStackAuthentication(), 0L, CREATE_REQUESTED, imageName);
}
Json attributes = instanceGroup.getAttributes();
Map<String, Object> fields = attributes == null ? Collections.emptyMap() : attributes.getMap();
Integer rootVolumeSize = instanceGroup.getTemplate().getRootVolumeSize();
if (Objects.isNull(rootVolumeSize)) {
rootVolumeSize = defaultRootVolumeSizeProvider.getForPlatform(cloudPlatform);
}
GroupNetwork groupNetwork = buildGroupNetwork(stack.getNetwork(), instanceGroup);
groups.add(new Group(instanceGroup.getGroupName(), InstanceGroupType.GATEWAY, instances, buildSecurity(instanceGroup), skeleton, fields, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), rootVolumeSize, fileSystemView, groupNetwork, getUserDefinedTags(stack)));
}
}
return groups;
}
Aggregations