use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class AWSCostStatsService method insertEC2ServiceDetail.
private void insertEC2ServiceDetail(AwsAccountDetailDto awsAccountDetailDto) {
AwsServiceDetailDto vm = awsAccountDetailDto.serviceDetailsMap.get(AwsServices.EC2_Instance_Usage.getName());
AwsServiceDetailDto ebs = awsAccountDetailDto.serviceDetailsMap.get(AwsServices.EC2_EBS.getName());
AwsServiceDetailDto others = awsAccountDetailDto.serviceDetailsMap.get(AwsServices.EC2_Others.getName());
AwsServiceDetailDto ec2ServiceDetail = new AwsServiceDetailDto();
ec2ServiceDetail.id = AwsServices.EC2.getName();
ec2ServiceDetail.type = AwsServices.getTypeByName(AwsServices.EC2.getName()).toString();
ec2ServiceDetail.directCosts = Stream.of(vm, ebs, others).filter(Objects::nonNull).map(dto -> dto.directCosts.entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Double::sum));
ec2ServiceDetail.otherCosts = Stream.of(vm, ebs, others).filter(Objects::nonNull).map(dto -> dto.otherCosts.entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Double::sum));
ec2ServiceDetail.remainingCosts = Stream.of(vm, ebs, others).filter(Objects::nonNull).map(dto -> dto.remainingCosts.entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Double::sum));
ec2ServiceDetail.reservedRecurringCosts = Stream.of(vm, ebs, others).filter(Objects::nonNull).map(dto -> dto.reservedRecurringCosts.entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Double::sum));
awsAccountDetailDto.serviceDetailsMap.put(AwsServices.EC2.getName(), ec2ServiceDetail);
}
use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method getSubnetInformation.
/**
* Gets the Subnets that are attached to the VPCs that were discovered during the enumeration
* process.
*/
private void getSubnetInformation(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest();
List<String> vpcList = new ArrayList<>(context.vpcs.keySet());
Filter filter = new Filter(AWS_VPC_ID_FILTER, vpcList);
subnetRequest.getFilters().add(filter);
AWSSubnetAsyncHandler asyncHandler = new AWSSubnetAsyncHandler(next, context);
context.amazonEC2Client.describeSubnetsAsync(subnetRequest, asyncHandler);
}
use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method createNetworkStateOperations.
/**
* Create the network state operations for all the VPCs that need to be created or updated in
* the system.
*/
private void createNetworkStateOperations(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
if (context.vpcs.isEmpty()) {
logFine(() -> "No new VPCs have been discovered.");
handleNetworkStateChanges(context, next);
return;
}
final List<Operation> networkOperations = new ArrayList<>();
for (String remoteVPCId : context.vpcs.keySet()) {
NetworkState networkState = context.vpcs.get(remoteVPCId);
final Operation networkStateOp;
if (context.localNetworkStateMap.containsKey(remoteVPCId)) {
// If the local network state already exists for the VPC -> Update it.
networkState.documentSelfLink = context.localNetworkStateMap.get(remoteVPCId).documentSelfLink;
// don't overwrite resourcePoolLink
networkState.resourcePoolLink = null;
if (networkState.tagLinks == null || networkState.tagLinks.isEmpty()) {
setTagLinksToResourceState(networkState, context.networkInternalTagsMap, false);
} else {
context.networkInternalTagLinksSet.stream().filter(tagLink -> !networkState.tagLinks.contains(tagLink)).map(tagLink -> networkState.tagLinks.add(tagLink)).collect(Collectors.toSet());
}
networkStateOp = createPatchOperation(this, networkState, networkState.documentSelfLink);
} else {
Vpc awsVpc = context.awsVpcs.get(remoteVPCId);
// Add both external and internal tags.
setResourceTags(networkState, awsVpc.getTags());
setTagLinksToResourceState(networkState, context.networkInternalTagsMap, false);
networkStateOp = createPostOperation(this, networkState, NetworkService.FACTORY_LINK);
}
networkOperations.add(networkStateOp);
}
JoinedCompletionHandler joinCompletion = (ops, excs) -> {
if (excs != null) {
Entry<Long, Throwable> excEntry = excs.entrySet().iterator().next();
Throwable exc = excEntry.getValue();
Operation op = ops.get(excEntry.getKey());
logSevere(() -> String.format("Error %s-ing a Network state: %s", op.getAction(), Utils.toString(excs)));
finishWithFailure(context, exc);
return;
}
logFine(() -> "Created/updated all network states.");
ops.values().stream().filter(op -> op.getStatusCode() != Operation.STATUS_CODE_NOT_MODIFIED).forEach(op -> {
NetworkState networkState = op.getBody(NetworkState.class);
context.vpcs.put(networkState.id, networkState);
});
handleNetworkStateChanges(context, next);
};
OperationJoin.create(networkOperations).setCompletion(joinCompletion).sendWith(this);
}
use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method getInternetGatewayInformation.
/**
* Gets the Internet gateways that are attached to the VPCs that were discovered during the
* enumeration process.
*/
private void getInternetGatewayInformation(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
DescribeInternetGatewaysRequest internetGatewayRequest = new DescribeInternetGatewaysRequest();
List<String> vpcList = new ArrayList<>(context.vpcs.keySet());
Filter filter = new Filter(AWS_ATTACHMENT_VPC_FILTER, vpcList);
internetGatewayRequest.getFilters().add(filter);
AWSInternetGatewayAsyncHandler asyncHandler = new AWSInternetGatewayAsyncHandler(next, context);
context.amazonEC2Client.describeInternetGatewaysAsync(internetGatewayRequest, asyncHandler);
}
use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class AWSNetworkClient method getMainRouteTable.
/**
* Get the main route table for a given VPC
*/
public RouteTable getMainRouteTable(String vpcId) {
// build filter list
List<Filter> filters = new ArrayList<>();
filters.add(AWSUtils.getFilter(AWSUtils.AWS_FILTER_VPC_ID, vpcId));
filters.add(AWSUtils.getFilter(AWS_MAIN_ROUTE_ASSOCIATION, "true"));
DescribeRouteTablesRequest req = new DescribeRouteTablesRequest().withFilters(filters);
DescribeRouteTablesResult res = this.client.describeRouteTables(req);
List<RouteTable> routeTables = res.getRouteTables();
return routeTables.isEmpty() ? null : routeTables.get(0);
}
Aggregations