use of com.amazonaws.services.ec2.AmazonEC2 in project cloudbreak by hortonworks.
the class AwsResourceConnector method associateElasticIpToInstance.
private void associateElasticIpToInstance(AmazonEC2 amazonEC2Client, String eipAllocationId, String instanceId) {
AssociateAddressRequest associateAddressRequest = new AssociateAddressRequest().withAllocationId(eipAllocationId).withInstanceId(instanceId);
amazonEC2Client.associateAddress(associateAddressRequest);
}
use of com.amazonaws.services.ec2.AmazonEC2 in project cloudbreak by hortonworks.
the class AwsResourceConnector method isMapPublicOnLaunch.
private boolean isMapPublicOnLaunch(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client) {
boolean mapPublicIpOnLaunch = true;
if (awsNetworkView.isExistingVPC() && awsNetworkView.isExistingSubnet()) {
DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
describeSubnetsRequest.setSubnetIds(awsNetworkView.getSubnetList());
DescribeSubnetsResult describeSubnetsResult = amazonEC2Client.describeSubnets(describeSubnetsRequest);
if (!describeSubnetsResult.getSubnets().isEmpty()) {
mapPublicIpOnLaunch = describeSubnetsResult.getSubnets().get(0).isMapPublicIpOnLaunch();
}
}
return mapPublicIpOnLaunch;
}
use of com.amazonaws.services.ec2.AmazonEC2 in project cloudbreak by hortonworks.
the class AwsSetup method validateExistingSubnet.
private void validateExistingSubnet(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client) {
if (awsNetworkView.isExistingSubnet()) {
DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
describeSubnetsRequest.withSubnetIds(awsNetworkView.getSubnetList());
DescribeSubnetsResult describeSubnetsResult = amazonEC2Client.describeSubnets(describeSubnetsRequest);
if (describeSubnetsResult.getSubnets().size() < awsNetworkView.getSubnetList().size()) {
throw new CloudConnectorException(String.format(SUBNET_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingSubnet()));
} else {
for (Subnet subnet : describeSubnetsResult.getSubnets()) {
String vpcId = subnet.getVpcId();
if (vpcId != null && !vpcId.equals(awsNetworkView.getExistingVPC())) {
throw new CloudConnectorException(String.format(SUBNETVPC_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingSubnet(), awsNetworkView.getExistingVPC()));
}
}
}
}
}
use of com.amazonaws.services.ec2.AmazonEC2 in project cloudbreak by hortonworks.
the class AwsSetup method validateExistingIGW.
private void validateExistingIGW(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client) {
if (awsNetworkView.isExistingIGW()) {
DescribeInternetGatewaysRequest describeInternetGatewaysRequest = new DescribeInternetGatewaysRequest();
describeInternetGatewaysRequest.withInternetGatewayIds(awsNetworkView.getExistingIGW());
DescribeInternetGatewaysResult describeInternetGatewaysResult = amazonEC2Client.describeInternetGateways(describeInternetGatewaysRequest);
if (describeInternetGatewaysResult.getInternetGateways().size() < 1) {
throw new CloudConnectorException(String.format(IGW_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingIGW()));
} else {
InternetGateway internetGateway = describeInternetGatewaysResult.getInternetGateways().get(0);
InternetGatewayAttachment attachment = internetGateway.getAttachments().get(0);
if (attachment != null && !attachment.getVpcId().equals(awsNetworkView.getExistingVPC())) {
throw new CloudConnectorException(String.format(IGWVPC_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingIGW(), awsNetworkView.getExistingVPC()));
}
}
}
}
use of com.amazonaws.services.ec2.AmazonEC2 in project cloudbreak by hortonworks.
the class RecoveryUtil method deleteAWSInstance.
public static void deleteAWSInstance(Regions region, String instanceId) {
List<String> idList = new ArrayList<>();
idList.add(instanceId);
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(idList);
ec2.terminateInstances(terminateInstancesRequest);
LOGGER.info("Instance was deleted with id:" + instanceId);
}
Aggregations