use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method doCreateUpdateNics.
/**
* Manages creating and updating Network Interfaces resources based on network interfaces
* associated with virtual machines.
*/
private DeferredResult<List<NetworkInterfaceState>> doCreateUpdateNics(EnumerationContext ctx, Map<String, String> subnetPerNicId, List<Pair<NetworkInterfaceInner, String>> remoteNics) {
Map<String, Pair<NetworkInterfaceInner, String>> remoteStates = remoteNics.stream().filter(p -> p.getLeft() != null).collect(Collectors.toMap(p -> p.getLeft().id(), p -> p));
Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(NetworkInterfaceState.class).addInClause(NetworkInterfaceState.FIELD_NAME_ID, remoteStates.keySet());
QueryByPages<NetworkInterfaceState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), NetworkInterfaceState.class, ctx.parentCompute.tenantLinks, // endpointLink
null, ctx.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
return queryLocalStates.collectDocuments(Collectors.toList()).thenCompose(localNics -> requestCreateUpdateNic(localNics, remoteStates, ctx, subnetPerNicId, remoteNics));
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createNetworkInterfaceStates.
/**
* Create network interface states for each VM
*/
private void createNetworkInterfaceStates(EnumerationContext ctx, ComputeEnumerationSubStages next) {
Consumer<Throwable> failure = e -> {
logWarning("Failure getting Azure network interface states [endpointLink:%s] [Exception:%s]", ctx.request.endpointLink, e.getMessage());
handleError(ctx, e);
};
PhotonModelUtils.runInExecutor(this.executorService, () -> {
Azure azureClient = ctx.azureSdkClients.getAzureClient();
NetworkInterfacesInner netOps = azureClient.networkInterfaces().inner();
List<DeferredResult<Pair<NetworkInterfaceInner, String>>> remoteNics = ctx.virtualMachines.values().stream().filter(vm -> vm.networkProfile() != null && !vm.networkProfile().networkInterfaces().isEmpty()).flatMap(vm -> vm.networkProfile().networkInterfaces().stream().map(nic -> Pair.of(nic, vm.id()))).map(pair -> loadRemoteNic(pair, netOps)).collect(Collectors.toList());
DeferredResult.allOf(remoteNics).thenCompose(rnics -> loadSubnets(ctx, rnics).thenCompose(subnetPerNicId -> doCreateUpdateNics(ctx, subnetPerNicId, rnics))).whenComplete(thenHandleSubStage(ctx, next));
}, failure);
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method loadSubnets.
private DeferredResult<Map<String, String>> loadSubnets(EnumerationContext ctx, List<Pair<NetworkInterfaceInner, String>> remoteNics) {
Map<String, List<Pair<NetworkInterfaceInner, String>>> nicsPerSubnet = remoteNics.stream().filter(p -> p.getLeft() != null && p.getLeft().ipConfigurations() != null && !p.getLeft().ipConfigurations().isEmpty() && p.getLeft().ipConfigurations().get(0).subnet() != null).collect(java.util.stream.Collectors.groupingBy(p -> p.getLeft().ipConfigurations().get(0).subnet().id()));
Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(SubnetState.class).addInClause(NetworkInterfaceState.FIELD_NAME_ID, nicsPerSubnet.keySet().stream().collect(Collectors.toList()));
QueryByPages<SubnetState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), SubnetState.class, ctx.parentCompute.tenantLinks, // endpointLink
null, ctx.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
Map<String, String> subnetLinkPerNicId = new HashMap<>();
return queryLocalStates.queryDocuments(subnet -> nicsPerSubnet.get(subnet.id).forEach(p -> subnetLinkPerNicId.put(p.getLeft().id(), subnet.documentSelfLink))).thenApply(ignore -> subnetLinkPerNicId);
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method updateNic.
private void updateNic(List<NetworkInterfaceState> localNics, Map<String, Pair<NetworkInterfaceInner, String>> remoteStates, EnumerationContext ctx, Map<String, String> subnetPerNicId, List<DeferredResult<NetworkInterfaceState>> ops) {
localNics.stream().forEach(nic -> {
// fetch and remove local NIC present in 'remoteStates' so that only new NICs are left
// present before we move forward to create new NICs.
Pair<NetworkInterfaceInner, String> pair = remoteStates.remove(nic.id);
if (pair != null) {
NetworkInterfaceInner remoteNic = pair.getLeft();
processCreateUpdateNicRequest(nic, remoteNic, ctx, ops, subnetPerNicId, false);
}
});
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner in project photon-model by vmware.
the class AzureInstanceService method createNICs.
private void createNICs(AzureInstanceContext ctx, AzureInstanceStage nextStage) {
if (ctx.nics.isEmpty()) {
handleAllocation(ctx, nextStage);
return;
}
// Shared state between multi async calls {{
AzureCallContext callContext = AzureCallContext.newBatchCallContext(ctx.nics.size());
NetworkInterfacesInner azureClient = getNetworkManagementClientImpl(ctx).networkInterfaces();
for (AzureNicContext nicCtx : ctx.nics) {
final String nicName = nicCtx.nicStateWithDesc.name;
final NetworkInterfaceInner nic = newAzureNetworkInterface(ctx, nicCtx);
String msg = "Creating Azure NIC [" + nicName + "] for [" + ctx.vmName + "] VM";
azureClient.createOrUpdateAsync(ctx.resourceGroup.name(), nicName, nic, new TransitionToCallback<NetworkInterfaceInner>(ctx, nextStage, callContext, msg) {
@Override
protected CompletionStage<NetworkInterfaceInner> handleSuccess(NetworkInterfaceInner nic) {
nicCtx.nic = nic;
return CompletableFuture.completedFuture(nic);
}
});
}
}
Aggregations