use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsPublicKeyConnector method exists.
@Override
public boolean exists(PublicKeyDescribeRequest request) {
LOGGER.debug("Describe public key {} in {} region on AWS", request.getPublicKeyId(), request.getRegion());
AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential());
try {
AmazonEc2Client client = awsClient.createEc2Client(awsCredential, request.getRegion());
return exists(client, request.getPublicKeyId());
} catch (Exception e) {
String errorMessage = String.format("Failed to describe public key [%s:'%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage());
LOGGER.error(errorMessage, e);
}
return false;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNetworkCfTemplateProviderTest method testProvideWhenPrivateSubnetsAreDisabledAndInterfaceServicesWithDifferentAzs.
@Test
public void testProvideWhenPrivateSubnetsAreDisabledAndInterfaceServicesWithDifferentAzs() throws IOException, TemplateException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode expectedJson = objectMapper.readTree(new File("src/test/resources/json/aws-cf-network-publicsubnet-vpcendpoints-differentazs.json"));
when(freeMarkerTemplateUtils.processTemplateIntoString(any(), any())).thenCallRealMethod();
AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
when(awsClient.createEc2Client(any(), anyString())).thenReturn(ec2Client);
when(ec2Client.describeVpcEndpointServices()).thenReturn(createDescribeVpcEndpointServicesResultWithDifferentAzs());
NetworkCreationRequest networkCreationRequest = createNetworkRequest(false, PrivateEndpointType.USE_VPC_ENDPOINT);
List<SubnetRequest> subnetRequestList = createPublicSubnetRequestList();
String actual = underTest.provide(networkCreationRequest, subnetRequestList);
JsonNode json = objectMapper.readTree(actual);
assertEquals(expectedJson, json);
verify(freeMarkerTemplateUtils).processTemplateIntoString(any(Template.class), anyMap());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNetworkCfTemplateProviderTest method testProvideWhenOnlyPublicSubnetsAndInterfaceServicesWithDifferentAzs.
@Test
public void testProvideWhenOnlyPublicSubnetsAndInterfaceServicesWithDifferentAzs() throws IOException, TemplateException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode expectedJson = objectMapper.readTree(new File("src/test/resources/json/aws-cf-network-publicsubnet-vpcendpoints-differentazs.json"));
when(freeMarkerTemplateUtils.processTemplateIntoString(any(), any())).thenCallRealMethod();
AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
when(awsClient.createEc2Client(any(), anyString())).thenReturn(ec2Client);
when(ec2Client.describeVpcEndpointServices()).thenReturn(createDescribeVpcEndpointServicesResultWithDifferentAzs());
NetworkCreationRequest networkCreationRequest = createNetworkRequest(true, PrivateEndpointType.USE_VPC_ENDPOINT);
List<SubnetRequest> subnetRequestList = createPublicSubnetRequestList();
String actual = underTest.provide(networkCreationRequest, subnetRequestList);
JsonNode json = objectMapper.readTree(actual);
assertEquals(expectedJson, json);
verify(freeMarkerTemplateUtils).processTemplateIntoString(any(Template.class), anyMap());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNetworkCfTemplateProviderTest method testProvideWhenPrivateSubnetCreationEnabled.
@ParameterizedTest
@MethodSource("privateSubnetArguments")
public void testProvideWhenPrivateSubnetCreationEnabled(String expectedTemplate, List<String> gatewayServices, List<String> interfaceServices, DescribeVpcEndpointServicesResult describeVpcEndpointServicesResult) throws IOException, TemplateException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode expectedJson = objectMapper.readTree(new File(expectedTemplate));
when(freeMarkerTemplateUtils.processTemplateIntoString(any(), any())).thenCallRealMethod();
AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
when(awsClient.createEc2Client(any(), anyString())).thenReturn(ec2Client);
when(ec2Client.describeVpcEndpointServices()).thenReturn(describeVpcEndpointServicesResult);
NetworkCreationRequest networkCreationRequest = createNetworkRequest(true, PrivateEndpointType.USE_VPC_ENDPOINT);
List<SubnetRequest> subnetRequestList = createPrivateAndPublicSubnetRequestList();
ReflectionTestUtils.setField(underTest, "gatewayServices", gatewayServices);
ReflectionTestUtils.setField(underTest, "interfaceServices", interfaceServices);
String actual = underTest.provide(networkCreationRequest, subnetRequestList);
JsonNode json = objectMapper.readTree(actual);
assertEquals(expectedJson, json);
verify(freeMarkerTemplateUtils).processTemplateIntoString(any(Template.class), anyMap());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testGetNetworkCidrWithDuplicatedCidr.
@Test
public void testGetNetworkCidrWithDuplicatedCidr() {
String existingVpc = "vpc-1";
String cidrBlock = "10.0.0.0/16";
Network network = new Network(null, Map.of(NetworkConstants.VPC_ID, existingVpc, "region", "us-west-2"));
CloudCredential credential = new CloudCredential();
AmazonEc2Client amazonEC2Client = mock(AmazonEc2Client.class);
DescribeVpcsResult describeVpcsResult = describeVpcsResult(cidrBlock, cidrBlock);
describeVpcsResult.getVpcs().get(0).getCidrBlockAssociationSet().add(new VpcCidrBlockAssociation().withCidrBlock(cidrBlock));
when(awsClient.createEc2Client(any(AwsCredentialView.class), eq("us-west-2"))).thenReturn(amazonEC2Client);
when(amazonEC2Client.describeVpcs(new DescribeVpcsRequest().withVpcIds(existingVpc))).thenReturn(describeVpcsResult);
NetworkCidr result = underTest.getNetworkCidr(network, credential);
assertEquals(cidrBlock, result.getCidr());
assertEquals(1, result.getCidrs().size());
assertEquals(cidrBlock, result.getCidrs().get(0));
}
Aggregations