use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method updateTagLinks.
private DeferredResult<AWSNetworkStateCreationContext> updateTagLinks(AWSNetworkStateCreationContext context) {
if ((context.awsVpcs == null || context.awsVpcs.isEmpty()) && (context.awsSubnets == null || context.awsSubnets.isEmpty())) {
logFine(() -> "No local vpcs or subnets to be updated so there are no tags to update.");
return DeferredResult.completed(context);
} else {
List<DeferredResult<Set<String>>> updateNetworkSubnetTagLinksOps = new ArrayList<>();
// update tag links for the existing NetworkStates
for (String vpcId : context.awsVpcs.keySet()) {
if (!context.localNetworkStateMap.containsKey(vpcId)) {
// this is not a network to update
continue;
}
Vpc vpc = context.awsVpcs.get(vpcId);
NetworkState existingNetworkState = context.localNetworkStateMap.get(vpcId);
Map<String, String> remoteTags = new HashMap<>();
for (Tag awsVpcTag : vpc.getTags()) {
if (!awsVpcTag.getKey().equals(AWSConstants.AWS_TAG_NAME)) {
remoteTags.put(awsVpcTag.getKey(), awsVpcTag.getValue());
}
}
updateNetworkSubnetTagLinksOps.add(updateLocalTagStates(this, existingNetworkState, remoteTags, null));
}
// update tag links for the existing SubnetStates
for (String subnetId : context.awsSubnets.keySet()) {
if (!context.localSubnetStateMap.containsKey(subnetId)) {
// this is not a subnet to update
continue;
}
Subnet subnet = context.awsSubnets.get(subnetId);
SubnetState existingSubnetState = context.localSubnetStateMap.get(subnetId);
Map<String, String> remoteTags = new HashMap<>();
for (Tag awsSubnetTag : subnet.getTags()) {
if (!awsSubnetTag.getKey().equals(AWSConstants.AWS_TAG_NAME)) {
remoteTags.put(awsSubnetTag.getKey(), awsSubnetTag.getValue());
}
}
updateNetworkSubnetTagLinksOps.add(updateLocalTagStates(this, existingSubnetState, remoteTags, null));
}
return DeferredResult.allOf(updateNetworkSubnetTagLinksOps).thenApply(ignore -> context);
}
}
use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method getLocalSubnetStates.
/**
* Gets the Subnet information from the local database to perform updates to existing subnet
* states.
*/
private void getLocalSubnetStates(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
if (context.subnets.isEmpty()) {
handleNetworkStateChanges(context, next);
return;
}
QueryTask q = createQueryToGetExistingSubnetStatesFilteredByDiscoveredSubnets(context.subnets.keySet(), context.request.parentComputeLink, context.request.request.endpointLink, context.request.regionId, context.request.tenantLinks);
// create the query to find resources
QueryUtils.startInventoryQueryTask(this, q).whenComplete((queryTask, e) -> {
if (e != null) {
logSevere(() -> String.format("Failed retrieving query results: %s", e.toString()));
finishWithFailure(context, e);
return;
}
if (queryTask.results.documents != null) {
for (Object s : queryTask.results.documents.values()) {
SubnetState subnetState = Utils.fromJson(s, SubnetState.class);
context.localSubnetStateMap.put(subnetState.id, subnetState);
}
}
logFine(() -> String.format("%d subnet states found.", queryTask.results.documentCount));
handleNetworkStateChanges(context, next);
});
}
use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.
the class AWSNetworkUtils method mapSubnetToSubnetState.
/**
* NOTE: Keep in mind that subnetState.networkLink is not set and it should be updated once
* valid NetworkState.documentSelfLink is available.
*/
public static SubnetState mapSubnetToSubnetState(Subnet subnet, List<String> tenantLinks, String regionId, String parentComputeLink, String endpointLink) {
if (subnet == null) {
throw new IllegalArgumentException("Cannot map Subnet to subnet state for null instance");
}
SubnetState subnetState = new SubnetState();
subnetState.id = subnet.getSubnetId();
subnetState.name = subnet.getSubnetId();
subnetState.subnetCIDR = subnet.getCidrBlock();
subnetState.supportPublicIpAddress = subnet.isMapPublicIpOnLaunch();
subnetState.defaultForZone = subnet.isDefaultForAz();
subnetState.zoneId = subnet.getAvailabilityZone();
subnetState.tenantLinks = tenantLinks;
subnetState.endpointLink = endpointLink;
if (subnetState.endpointLinks == null) {
subnetState.endpointLinks = new HashSet<>();
}
subnetState.endpointLinks.add(endpointLink);
subnetState.computeHostLink = parentComputeLink;
subnetState.customProperties = new HashMap<>();
subnetState.regionId = regionId;
if (!subnet.getTags().isEmpty()) {
// The name of the subnet state is the value of the AWS_TAG_NAME tag
String nameTag = getTagValue(subnet.getTags(), AWS_TAG_NAME);
if (!StringUtil.isNullOrEmpty(nameTag)) {
subnetState.name = nameTag;
}
}
return subnetState;
}
use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.
the class TestUtils method getSubnetStates.
/**
* Get all SubnetStates within passed NetworkState. In other words, get all subnet states that
* refer the network state passed.
*/
public static List<SubnetState> getSubnetStates(VerificationHost host, NetworkState networkState) throws Throwable {
Query queryForReferrers = QueryUtils.queryForReferrers(networkState.documentSelfLink, SubnetState.class, SubnetState.FIELD_NAME_NETWORK_LINK);
QueryByPages<SubnetState> querySubnetStatesReferrers = new QueryByPages<>(host, queryForReferrers, SubnetState.class, networkState.tenantLinks, null, networkState.computeHostLink);
DeferredResult<List<SubnetState>> subnetDR = querySubnetStatesReferrers.collectDocuments(Collectors.toList());
return waitToComplete(subnetDR);
}
use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.
the class TestAzureEnumerationTask method validateVirtualNetworkGateways.
/**
* Validates that the Gateway information discovered from Azure has been propagated to the
* NetworkState custom properties.
*/
private void validateVirtualNetworkGateways(AzureNicSpecs nicSpecs) throws Throwable {
if (this.isMock) {
return;
}
// Query all network states in the system
Map<String, NetworkState> networkStatesMap = ProvisioningUtils.getResourceStates(this.host, NetworkService.FACTORY_LINK, NetworkState.class);
AtomicBoolean isGatewayFound = new AtomicBoolean(false);
networkStatesMap.values().forEach(networkState -> {
if (networkState.name.contains(nicSpecs.network.name)) {
List<SubnetState> subnetStates = getSubnetStates(this.host, networkState);
assertFalse(subnetStates.isEmpty());
subnetStates.stream().filter(subnetState -> AzureConstants.GATEWAY_SUBNET_NAME.equalsIgnoreCase(subnetState.name)).forEach(subnetState -> {
this.host.log(Level.INFO, "Validating gateway for network" + "(name %s, id: %s)", networkState.name, networkState.id);
assertNotNull("Custom properties are null.", networkState.customProperties);
assertNotNull("Virtual gateway property not found.", networkState.customProperties.get(ComputeProperties.FIELD_VIRTUAL_GATEWAY));
assertNotNull("SubnetState custom properties are null.", subnetState.customProperties);
assertEquals("Gateway SubnetState is not marked currectly with " + "infrastructure use custom property.", Boolean.TRUE.toString(), subnetState.customProperties.get(ComputeProperties.INFRASTRUCTURE_USE_PROP_NAME));
isGatewayFound.set(true);
});
}
});
assertTrue("Gateway custom property was not found at all.", isGatewayFound.get());
}
Aggregations