use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit20Vpc.
@Test
public void testFindNonOverLappingCIDRWit20Vpc() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet2 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet3 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet4 = mock(com.amazonaws.services.ec2.model.Subnet.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(cloudContext.getName()).thenReturn(new String(new byte[] { 15 }));
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/20");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Arrays.asList(subnet1, subnet2, subnet3, subnet4));
when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/24");
when(subnet2.getCidrBlock()).thenReturn("10.0.1.0/24");
when(subnet3.getCidrBlock()).thenReturn("10.0.2.0/24");
when(subnet4.getCidrBlock()).thenReturn("10.0.3.0/24");
String cidr = underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
Assert.assertEquals("10.0.15.0/24", cidr);
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit20VpcFull.
@Test
public void testFindNonOverLappingCIDRWit20VpcFull() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet2 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet3 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet4 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet5 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet6 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet7 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet8 = mock(com.amazonaws.services.ec2.model.Subnet.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(cloudContext.getName()).thenReturn(new String(new byte[] { 15 }));
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/20");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Arrays.asList(subnet1, subnet2, subnet3, subnet4, subnet5, subnet6, subnet7, subnet8));
when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/23");
when(subnet2.getCidrBlock()).thenReturn("10.0.2.0/23");
when(subnet3.getCidrBlock()).thenReturn("10.0.4.0/23");
when(subnet4.getCidrBlock()).thenReturn("10.0.6.0/23");
when(subnet5.getCidrBlock()).thenReturn("10.0.8.0/23");
when(subnet6.getCidrBlock()).thenReturn("10.0.10.0/23");
when(subnet7.getCidrBlock()).thenReturn("10.0.12.0/23");
when(subnet8.getCidrBlock()).thenReturn("10.0.14.0/23");
thrown.expect(CloudConnectorException.class);
thrown.expectMessage("Cannot find non-overlapping CIDR range");
underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit20Vpc1Empty2.
@Test
public void testFindNonOverLappingCIDRWit20Vpc1Empty2() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet2 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet3 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet4 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet5 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet6 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet7 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet8 = mock(com.amazonaws.services.ec2.model.Subnet.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(cloudContext.getName()).thenReturn(new String(new byte[] { 4 }));
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/20");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Arrays.asList(subnet1, subnet2, subnet3, subnet4, subnet5, subnet6, subnet7, subnet8));
when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/23");
when(subnet2.getCidrBlock()).thenReturn("10.0.2.0/24");
when(subnet3.getCidrBlock()).thenReturn("10.0.4.0/23");
when(subnet4.getCidrBlock()).thenReturn("10.0.6.0/23");
when(subnet5.getCidrBlock()).thenReturn("10.0.8.0/23");
when(subnet6.getCidrBlock()).thenReturn("10.0.10.0/23");
when(subnet7.getCidrBlock()).thenReturn("10.0.12.0/23");
when(subnet8.getCidrBlock()).thenReturn("10.0.14.0/23");
String cidr = underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
Assert.assertEquals("10.0.3.0/24", cidr);
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWithNon24Subnets2.
@Test
public void testFindNonOverLappingCIDRWithNon24Subnets2() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet2 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet3 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet4 = mock(com.amazonaws.services.ec2.model.Subnet.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(cloudContext.getName()).thenReturn(new String(new byte[] { 76 }));
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/16");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Arrays.asList(subnet1, subnet2, subnet3, subnet4));
when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/20");
when(subnet2.getCidrBlock()).thenReturn("10.0.16.0/20");
when(subnet3.getCidrBlock()).thenReturn("10.0.32.0/20");
when(subnet4.getCidrBlock()).thenReturn("10.0.48.0/20");
String cidr = underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
Assert.assertEquals("10.0.76.0/24", cidr);
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method setUp.
@Before
public void setUp() throws Exception {
initMocks(this);
FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
factoryBean.setPreferFileSystemAccess(false);
factoryBean.setTemplateLoaderPath("classpath:/");
factoryBean.afterPropertiesSet();
Configuration configuration = factoryBean.getObject();
ReflectionTestUtils.setField(cloudFormationTemplateBuilder, "freemarkerConfiguration", configuration);
awsCloudFormationTemplate = configuration.getTemplate(templatePath, "UTF-8").toString();
authenticatedContext = authenticatedContext();
existingSubnetCidr = "testSubnet";
name = "master";
List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
Security security = new Security(rules, null);
Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
List<Group> groups = new ArrayList<>();
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
groups.add(new Group(name, InstanceGroupType.GATEWAY, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
Network network = new Network(new Subnet("testSubnet"));
Map<String, String> parameters = new HashMap<>();
parameters.put("persistentStorage", "persistentStorageTest");
parameters.put("attachedStorageOption", "attachedStorageOptionTest");
Map<String, String> tags = new HashMap<>();
tags.put("testtagkey", "testtagvalue");
defaultTags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key());
defaultTags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key());
defaultTags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key());
defaultTags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key());
defaultTags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key());
defaultTags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key());
defaultTags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key());
cloudStack = new CloudStack(groups, network, image, parameters, tags, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
Aggregations