Search in sources :

Example 6 with GroupNetwork

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));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Test(org.junit.jupiter.api.Test)

Example 7 with GroupNetwork

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);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Subnet(com.amazonaws.services.ec2.model.Subnet) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Test(org.junit.jupiter.api.Test)

Example 8 with GroupNetwork

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;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)

Aggregations

GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)8 GroupSubnet (com.sequenceiq.cloudbreak.cloud.model.GroupSubnet)6 Group (com.sequenceiq.cloudbreak.cloud.model.Group)5 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)4 Test (org.junit.jupiter.api.Test)4 Json (com.sequenceiq.cloudbreak.common.json.Json)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)2 Subnet (com.amazonaws.services.ec2.model.Subnet)2 InstanceGroupNetwork (com.sequenceiq.freeipa.entity.InstanceGroupNetwork)2 List (java.util.List)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)1 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 InstanceGroupNetwork (com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)1 AzureResourceGroup (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup)1 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)1