use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit20Vpc2.
@Test
public void testFindNonOverLappingCIDRWit20Vpc2() {
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[] { 16 }));
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.4.0/24", cidr);
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit24VpcEmptySubnet.
@Test
public void testFindNonOverLappingCIDRWit24VpcEmptySubnet() {
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);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
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/24");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Collections.emptyList());
thrown.expect(CloudConnectorException.class);
thrown.expectMessage("The selected VPC has to be in a bigger CIDR range than /24");
underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AwsTagPreparationServiceTest method authenticatedContext.
private AuthenticatedContext authenticatedContext() {
CloudContext cloudContext = new CloudContext(1L, "testname", "AWS", "owner");
CloudCredential cloudCredential = new CloudCredential(1L, "credentialname");
return new AuthenticatedContext(cloudContext, cloudCredential);
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method authenticatedContext.
private AuthenticatedContext authenticatedContext() {
Location location = Location.location(Region.region("region"), AvailabilityZone.availabilityZone("az"));
CloudContext cloudContext = new CloudContext(5L, "name", "platform", "owner", "variant", location);
CloudCredential cc = new CloudCredential(1L, null);
return new AuthenticatedContext(cloudContext, cc);
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AzureResourceConnector method terminate.
@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) {
AzureClient client = authenticatedContext.getParameter(AzureClient.class);
for (CloudResource resource : resources) {
try {
try {
retryService.testWith2SecDelayMax5Times(() -> {
if (!client.resourceGroupExists(resource.getName())) {
throw new ActionWentFailException("Resource group not exists");
}
return true;
});
client.deleteResourceGroup(resource.getName());
} catch (ActionWentFailException ignored) {
LOGGER.info(String.format("Resource group not found with name: %s", resource.getName()));
}
if (azureStorage.isPersistentStorage(azureStorage.getPersistentStorageName(stack))) {
CloudContext cloudCtx = authenticatedContext.getCloudContext();
AzureCredentialView azureCredentialView = new AzureCredentialView(authenticatedContext.getCloudCredential());
String imageStorageName = azureStorage.getImageStorageName(azureCredentialView, cloudCtx, stack);
String imageResourceGroupName = azureStorage.getImageResourceGroupName(cloudCtx, stack);
String diskContainer = azureStorage.getDiskContainerName(cloudCtx);
deleteContainer(client, imageResourceGroupName, imageStorageName, diskContainer);
}
} catch (CloudException e) {
if (e.response().code() != AzureConstants.NOT_FOUND) {
throw new CloudConnectorException(String.format("Could not delete resource group: %s", resource.getName()), e);
} else {
return check(authenticatedContext, Collections.emptyList());
}
}
}
return check(authenticatedContext, resources);
}
Aggregations