use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsModelService method buildDefaultModelContext.
public ModelContext buildDefaultModelContext(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier resourceNotifier) {
Network network = stack.getNetwork();
AwsNetworkView awsNetworkView = new AwsNetworkView(network);
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonEc2Client amazonEC2Client = awsClient.createEc2Client(credentialView, regionName);
boolean mapPublicIpOnLaunch = awsNetworkService.isMapPublicOnLaunch(awsNetworkView, amazonEC2Client);
boolean existingVPC = awsNetworkView.isExistingVPC();
boolean existingSubnet = awsNetworkView.isExistingSubnet();
String cidr = network.getSubnet().getCidr();
String subnet = isNoCIDRProvided(existingVPC, existingSubnet, cidr) ? awsNetworkService.findNonOverLappingCIDR(ac, stack) : cidr;
AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack);
ModelContext modelContext = new ModelContext().withAuthenticatedContext(ac).withStack(stack).withExistingVpc(existingVPC).withExistingIGW(awsNetworkView.isExistingIGW()).withExistingSubnetCidr(existingSubnet ? awsNetworkService.getExistingSubnetCidr(ac, stack) : null).withExistinVpcCidr(awsNetworkService.getVpcCidrs(ac, awsNetworkView)).withExistingSubnetIds(existingSubnet ? awsNetworkView.getSubnetList() : null).mapPublicIpOnLaunch(mapPublicIpOnLaunch).withEnableInstanceProfile(awsInstanceProfileView.isInstanceProfileAvailable()).withInstanceProfileAvailable(awsInstanceProfileView.isInstanceProfileAvailable()).withTemplate(stack.getTemplate()).withDefaultSubnet(subnet).withOutboundInternetTraffic(network.getOutboundInternetTraffic()).withVpcCidrs(network.getNetworkCidrs()).withPrefixListIds(awsNetworkService.getPrefixListIds(amazonEC2Client, regionName, network.getOutboundInternetTraffic()));
AwsEfsFileSystem efsFileSystem = getAwsEfsFileSystem(stack);
if (efsFileSystem != null) {
modelContext.withEnableEfs(true);
modelContext.withEfsFileSystem(efsFileSystem);
} else {
modelContext.withEnableEfs(false);
}
return modelContext;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNetworkService method getExistingSubnetCidr.
public List<String> getExistingSubnetCidr(AuthenticatedContext ac, CloudStack stack) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonEc2Client ec2Client = awsClient.createEc2Client(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeSubnetsRequest subnetsRequest = new DescribeSubnetsRequest().withSubnetIds(awsNetworkView.getSubnetList());
List<Subnet> subnets = ec2Client.describeSubnets(subnetsRequest).getSubnets();
if (subnets.isEmpty()) {
throw new CloudConnectorException("The specified subnet does not exist (maybe it's in a different region).");
}
List<String> cidrs = Lists.newArrayList();
for (Subnet subnet : subnets) {
cidrs.add(subnet.getCidrBlock());
}
return cidrs;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsContextBuilder method contextInit.
@Override
public AwsContext contextInit(CloudContext context, AuthenticatedContext auth, Network network, List<CloudResource> resources, boolean build) {
Location location = context.getLocation();
AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(auth);
AmazonEc2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client();
AmazonElasticLoadBalancingClient elasticLoadBalancingClient = authenticatedContextView.getElasticLoadBalancingClient();
return new AwsContext(context.getName(), amazonEC2Client, location, PARALLEL_RESOURCE_REQUEST, build, elasticLoadBalancingClient);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsTaggingService method tagRootVolumes.
public void tagRootVolumes(AuthenticatedContext ac, AmazonEc2Client ec2Client, List<CloudResource> instanceResources, Map<String, String> userDefinedTags) {
String stackName = ac.getCloudContext().getName();
LOGGER.debug("Fetch AWS instances to collect all root volume ids for stack: {}", stackName);
List<String> instanceIds = instanceResources.stream().map(CloudResource::getInstanceId).collect(Collectors.toList());
DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds));
List<Instance> instances = describeInstancesResult.getReservations().stream().flatMap(res -> res.getInstances().stream()).collect(Collectors.toList());
List<String> rootVolumeIds = instances.stream().map(this::getRootVolumeId).filter(Optional::isPresent).map(blockDeviceMapping -> blockDeviceMapping.get().getEbs().getVolumeId()).collect(Collectors.toList());
int instanceCount = instances.size();
int volumeCount = rootVolumeIds.size();
if (instanceCount != volumeCount) {
LOGGER.debug("Did not find all root volumes, instanceResources: {}, found root volumes: {} for stack: {}", instanceCount, volumeCount, stackName);
} else {
LOGGER.debug("Found all ({}) root volumes for stack: {}", volumeCount, stackName);
}
AtomicInteger counter = new AtomicInteger();
Collection<List<String>> volumeIdChunks = rootVolumeIds.stream().collect(Collectors.groupingBy(it -> counter.getAndIncrement() / MAX_RESOURCE_PER_REQUEST)).values();
Collection<Tag> tags = prepareEc2Tags(userDefinedTags);
for (List<String> volumeIds : volumeIdChunks) {
LOGGER.debug("Tag {} root volumes for stack: {}", volumeIds.size(), stackName);
ec2Client.createTags(new CreateTagsRequest().withResources(volumeIds).withTags(tags));
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsLaunchTest method launchStackWithEfs.
@Test
public void launchStackWithEfs() throws Exception {
setup();
setupRetryService();
setupFreemarkerTemplateProcessing();
setupDescribeStacksResponses();
setupDescribeImagesResponse();
setupDescribeStackResourceResponse();
setupAutoscalingResponses();
setupDescribeInstancesResponse();
setupCreateVolumeResponse();
setupDescribeVolumeResponse();
setupDescribeSubnetResponse();
setupDescribePrefixListsResponse();
setupCreateFileSystem();
setupDescribeFileSystems();
setupDescribeMountTargets();
setupDeleteMountTarget();
setupDeleteFileSystem();
InMemoryStateStore.putStack(1L, PollGroup.POLLABLE);
AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext();
authenticatedContext.putParameter(AmazonEc2Client.class, amazonEc2Client);
authenticatedContext.putParameter(AmazonElasticFileSystemClient.class, amazonElasticFileSystemClient);
authenticatedContext.putParameter(AmazonEfsClient.class, amazonEfsClient);
awsResourceConnector.launch(authenticatedContext, componentTestUtil.getStackForLaunch(InstanceStatus.CREATE_REQUESTED, InstanceStatus.CREATE_REQUESTED), persistenceNotifier, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, Long.MAX_VALUE));
// assert
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_VPC.equals(cloudResource.getType())), any());
verify(persistenceNotifier, times(2)).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_VOLUMESET.equals(cloudResource.getType())), any());
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_SUBNET.equals(cloudResource.getType())), any());
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.CLOUDFORMATION_STACK.equals(cloudResource.getType())), any());
InOrder inOrder = inOrder(amazonElasticFileSystemClient, amazonEfsClient, amazonCloudFormationClient, amazonEc2Client);
inOrder.verify(amazonEc2Client).describeImages(any());
inOrder.verify(amazonCloudFormationClient).createStack(any());
inOrder.verify(amazonEc2Client, times(2)).createVolume(any());
inOrder.verify(amazonEc2Client, times(2)).attachVolume(any());
inOrder.verify(amazonEc2Client, never()).describePrefixLists();
}
Aggregations