use of com.vmware.photon.controller.model.adapters.azure.enumeration.AzureNetworkEnumerationAdapterService.NetworkEnumContext.SubnetStateWithParentVNetId in project photon-model by vmware.
the class AzureNetworkEnumerationAdapterService method createUpdateSubnetStates.
/**
* Create new subnet states or updates matching subnet states with the actual state in Azure.
*/
private void createUpdateSubnetStates(NetworkEnumContext context, NetworkEnumStages next) {
if (context.subnets.size() == 0) {
logFine(() -> "No network states available for update.");
handleSubStage(context, next);
return;
}
Stream<Operation> operations = context.subnets.keySet().stream().map(subnetId -> {
SubnetStateWithParentVNetId subnetStateWithParentVNetId = context.subnets.get(subnetId);
SubnetState subnetState = subnetStateWithParentVNetId.subnetState;
if (!context.subnetStates.containsKey(subnetId)) {
// set internal tags as tagLinks for subnets to be newly created.
setTagLinksToResourceState(subnetState, context.subnetInternalTagsMap, false);
} else {
// 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());
}
}
// Update networkLink with "latest" (either created or updated)
// NetworkState.documentSelfLink
NetworkState networkState = context.networkStates.get(subnetStateWithParentVNetId.parentVNetId);
if (networkState != null) {
subnetState.networkLink = networkState.documentSelfLink;
} else {
logWarning(() -> String.format("Network state corresponding to subnet with" + " name [%s] was not found. Network Link is left empty.", subnetState.name));
}
if (StringUtils.isEmpty(subnetState.endpointLink)) {
subnetState.endpointLink = context.request.endpointLink;
}
subnetState.computeHostLink = context.parentCompute.documentSelfLink;
AdapterUtils.addToEndpointLinks(subnetState, context.request.endpointLink);
return context.subnetStates.containsKey(subnetId) ? // Update case
Operation.createPatch(this, context.subnetStates.get(subnetId)).setBody(subnetState) : // Create case.
Operation.createPost(getHost(), SubnetService.FACTORY_LINK).setBody(subnetState);
});
OperationJoin.create(operations).setCompletion((ops, failures) -> {
if (failures != null) {
// We don't want to fail the whole data collection if some of the
// operation fails.
failures.values().forEach(ex -> logWarning(() -> String.format("Error: %s", ex.getMessage())));
}
// Process successful operations.
ops.values().stream().filter(operation -> failures != null && !failures.containsKey(operation.getId())).filter(operation -> operation.getStatusCode() != Operation.STATUS_CODE_NOT_MODIFIED).forEach(operation -> {
SubnetState subnetState = operation.getBody(SubnetState.class);
context.subnets.get(subnetState.id).subnetState = subnetState;
});
if (context.enumNextPageLink != null) {
logFine(() -> "Fetch next page of Virtual Networks from Azure.");
handleSubStage(context, NetworkEnumStages.GET_VNETS);
return;
}
logFine(() -> "Finished updating network states");
handleSubStage(context, next);
}).sendWith(this);
}
use of com.vmware.photon.controller.model.adapters.azure.enumeration.AzureNetworkEnumerationAdapterService.NetworkEnumContext.SubnetStateWithParentVNetId in project photon-model by vmware.
the class AzureNetworkEnumerationAdapterService method getSubnets.
/**
* Based on the retrieved page of Virtual Network resources from azure, compose the structures
* holding Azure Subnets data.
*/
private void getSubnets(NetworkEnumContext context, NetworkEnumStages next) {
logFine(() -> "Enumerating Subnets from Azure.");
context.virtualNetworks.values().forEach(virtualNetwork -> {
if (virtualNetwork.properties.subnets != null) {
virtualNetwork.properties.subnets.forEach(subnet -> {
SubnetState subnetState = buildSubnetState(subnet, context.parentCompute.tenantLinks, context.request.endpointLink, virtualNetwork.location, context.parentCompute.documentSelfLink);
SubnetStateWithParentVNetId subnetStateWithParentVNetId = new SubnetStateWithParentVNetId(virtualNetwork.id, subnetState);
context.addSubnet(subnet, subnetStateWithParentVNetId);
});
}
});
handleSubStage(context, next);
}
Aggregations