use of com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSNetworkStateEnumerationAdapterService.AWSNetworkStateCreationContext.SubnetStateWithParentVpcId in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method createSubnetStateOperations.
/**
* Create the subnet state operations for all the Subnets that need to be created or updated in
* the system.
*/
private void createSubnetStateOperations(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
if (context.subnets.isEmpty()) {
logFine(() -> "No new subnets found.");
handleNetworkStateChanges(context, next);
return;
}
final List<Operation> subnetOperations = new ArrayList<>();
for (String remoteSubnetId : context.subnets.keySet()) {
SubnetStateWithParentVpcId subnetStateWithParentVpcId = context.subnets.get(remoteSubnetId);
SubnetState subnetState = subnetStateWithParentVpcId.subnetState;
// Update networkLink with "latest" (either created or updated)
// NetworkState.documentSelfLink
subnetState.networkLink = context.vpcs.get(subnetStateWithParentVpcId.parentVpcId).documentSelfLink;
final Operation subnetStateOp;
if (context.localSubnetStateMap.containsKey(remoteSubnetId)) {
// If the local subnet state already exists for the Subnet -> Update it.
subnetState.documentSelfLink = context.localSubnetStateMap.get(remoteSubnetId).documentSelfLink;
// for already existing subnets, add internal tags only if missing
if (subnetState.tagLinks == null || subnetState.tagLinks.isEmpty()) {
setTagLinksToResourceState(subnetState, context.subnetInternalTagsMap, false);
} else {
context.subnetInternalTagLinksSet.stream().filter(tagLink -> !subnetState.tagLinks.contains(tagLink)).map(tagLink -> subnetState.tagLinks.add(tagLink)).collect(Collectors.toSet());
}
subnetStateOp = createPatchOperation(this, subnetState, subnetState.documentSelfLink);
} else {
// add tag links
Subnet awsSubnet = context.awsSubnets.get(remoteSubnetId);
setResourceTags(subnetState, awsSubnet.getTags());
setTagLinksToResourceState(subnetState, context.subnetInternalTagsMap, false);
subnetStateOp = createPostOperation(this, subnetState, SubnetService.FACTORY_LINK);
}
subnetOperations.add(subnetStateOp);
}
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 Subnet state: %s", op.getAction(), Utils.toString(excs)));
finishWithFailure(context, exc);
return;
}
logFine(() -> "Successfully created/updated all subnet states.");
ops.values().stream().filter(op -> op.getStatusCode() != Operation.STATUS_CODE_NOT_MODIFIED).forEach(op -> {
SubnetState subnetState = op.getBody(SubnetState.class);
context.subnets.get(subnetState.id).subnetState = subnetState;
});
handleNetworkStateChanges(context, next);
};
OperationJoin.create(subnetOperations).setCompletion(joinCompletion).sendWith(this);
}
Aggregations