Search in sources :

Example 1 with NetworkInterfacesInner

use of com.microsoft.azure.management.network.implementation.NetworkInterfacesInner 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);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Arrays(java.util.Arrays) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) Action1(rx.functions.Action1) StringUtils(org.apache.commons.lang3.StringUtils) Azure(com.microsoft.azure.management.Azure) Utils(com.vmware.xenon.common.Utils) Pair(org.apache.commons.lang3.tuple.Pair) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) OSDisk(com.microsoft.azure.management.compute.OSDisk) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) StorageAccountTypes(com.microsoft.azure.management.compute.StorageAccountTypes) TagService(com.vmware.photon.controller.model.resources.TagService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) InstanceViewStatus(com.microsoft.azure.management.compute.InstanceViewStatus) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) AZURE_DATA_DISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DATA_DISK_CACHING) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) VirtualMachinesInner(com.microsoft.azure.management.compute.implementation.VirtualMachinesInner) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) RegionInfo(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) ArrayList(java.util.ArrayList) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) OperatingSystemTypes(com.microsoft.azure.management.compute.OperatingSystemTypes) BiConsumer(java.util.function.BiConsumer) AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK) AZURE_STORAGE_ACCOUNT_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_URI) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) DataDisk(com.microsoft.azure.management.compute.DataDisk) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ENVIRONMENT_NAME_AZURE(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_AZURE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) CUSTOM_OS_TYPE(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QueryTask(com.vmware.xenon.services.common.QueryTask) AZURE_RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_RESOURCE_GROUP_NAME) OSType(com.vmware.photon.controller.model.ComputeProperties.OSType) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) AZURE_MANAGED_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) AzureUtils.injectOperationContext(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.injectOperationContext) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AzureConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.getQueryResultLimit) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureUtils.getResourceGroupName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getResourceGroupName) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) Entry(java.util.Map.Entry) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) InstanceViewTypes(com.microsoft.azure.management.compute.InstanceViewTypes) TagsUtil.setTagLinksToResourceState(com.vmware.photon.controller.model.adapters.util.TagsUtil.setTagLinksToResourceState) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) DiskService(com.vmware.photon.controller.model.resources.DiskService) AzureUtils.isDiskManaged(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.isDiskManaged) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) AZURE_OSDISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_OSDISK_CACHING) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) HashMap(java.util.HashMap) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) TagsUtil.updateLocalTagStates(com.vmware.photon.controller.model.adapters.util.TagsUtil.updateLocalTagStates) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) Operation(com.vmware.xenon.common.Operation) Page(com.microsoft.azure.Page) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) NetworkInterfaceReferenceInner(com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) Azure(com.microsoft.azure.management.Azure) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) DeferredResult(com.vmware.xenon.common.DeferredResult) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Example 2 with NetworkInterfacesInner

use of com.microsoft.azure.management.network.implementation.NetworkInterfacesInner 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);
            }
        });
    }
}
Also used : AzureNicContext(com.vmware.photon.controller.model.adapters.azure.instance.AzureInstanceContext.AzureNicContext) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) CompletionStage(java.util.concurrent.CompletionStage) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Example 3 with NetworkInterfacesInner

use of com.microsoft.azure.management.network.implementation.NetworkInterfacesInner in project photon-model by vmware.

the class AzureLoadBalancerService method getNetworkInterfaceInner.

/**
 * Fetch single Network Interface from Azure
 *
 * @param context               Azure load balancer context
 * @param networkInterfaceState state of the network interface to be fetched from Azure
 * @return DeferredResult
 */
private DeferredResult<NetworkInterfaceInner> getNetworkInterfaceInner(AzureLoadBalancerContext context, NetworkInterfaceState networkInterfaceState) {
    String networkInterfaceResGrp = AzureUtils.getResourceGroupName(networkInterfaceState.id);
    final String msg = "Getting network Interface [" + networkInterfaceState.name + "] in resource group [" + networkInterfaceResGrp + "].";
    logInfo(() -> msg);
    AzureDeferredResultServiceCallback<NetworkInterfaceInner> callback = new AzureDeferredResultServiceCallback<NetworkInterfaceInner>(this, msg) {

        @Override
        protected DeferredResult<NetworkInterfaceInner> consumeSuccess(NetworkInterfaceInner networkInterface) {
            if (networkInterface == null) {
                logWarning("Failed to get information for network interface: %s", networkInterfaceState.name);
            }
            return DeferredResult.completed(networkInterface);
        }
    };
    NetworkInterfacesInner azureNetworkInterfaceClient = context.azureSdkClients.getNetworkManagementClientImpl().networkInterfaces();
    azureNetworkInterfaceClient.getByResourceGroupAsync(networkInterfaceResGrp, networkInterfaceState.name, null, /* expand */
    callback);
    return callback.toDeferredResult();
}
Also used : AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Example 4 with NetworkInterfacesInner

use of com.microsoft.azure.management.network.implementation.NetworkInterfacesInner in project photon-model by vmware.

the class AzureLoadBalancerService method createOrUpdateNetworkInterface.

/**
 * Create or Update network interface in Azure
 *
 * @param context               Azure load balancer context
 * @param networkInterfaceInner Azure network interface construct
 * @return DeferredResult
 */
private DeferredResult<NetworkInterfaceInner> createOrUpdateNetworkInterface(AzureLoadBalancerContext context, NetworkInterfaceInner networkInterfaceInner) {
    String networkInterfaceResGrp = AzureUtils.getResourceGroupName(networkInterfaceInner.id());
    final String msg = "Update network Interface [" + networkInterfaceInner.name() + "] in resource group [" + networkInterfaceResGrp + "].";
    logInfo(() -> msg);
    NetworkInterfacesInner azureNetworkInterfaceClient = context.azureSdkClients.getNetworkManagementClientImpl().networkInterfaces();
    AzureProvisioningCallbackWithRetry<NetworkInterfaceInner> handler = new AzureProvisioningCallbackWithRetry<NetworkInterfaceInner>(this, msg) {

        @Override
        protected DeferredResult<NetworkInterfaceInner> consumeProvisioningSuccess(NetworkInterfaceInner networkInterfaceInner) {
            return DeferredResult.completed(networkInterfaceInner);
        }

        @Override
        protected Runnable checkProvisioningStateCall(ServiceCallback<NetworkInterfaceInner> checkProvisioningStateCallback) {
            return () -> azureNetworkInterfaceClient.getByResourceGroupAsync(networkInterfaceResGrp, networkInterfaceInner.name(), null, /* expand */
            checkProvisioningStateCallback);
        }

        @Override
        protected String getProvisioningState(NetworkInterfaceInner body) {
            return body.provisioningState();
        }

        @Override
        protected Runnable retryServiceCall(ServiceCallback<NetworkInterfaceInner> retryCallback) {
            return () -> azureNetworkInterfaceClient.createOrUpdateAsync(networkInterfaceResGrp, networkInterfaceInner.name(), networkInterfaceInner, retryCallback);
        }
    };
    azureNetworkInterfaceClient.createOrUpdateAsync(networkInterfaceResGrp, networkInterfaceInner.name(), networkInterfaceInner, handler);
    return handler.toDeferredResult();
}
Also used : AzureProvisioningCallbackWithRetry(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallbackWithRetry) ServiceCallback(com.microsoft.rest.ServiceCallback) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Aggregations

NetworkInterfaceInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)4 NetworkInterfacesInner (com.microsoft.azure.management.network.implementation.NetworkInterfacesInner)4 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)3 Page (com.microsoft.azure.Page)1 Azure (com.microsoft.azure.management.Azure)1 DataDisk (com.microsoft.azure.management.compute.DataDisk)1 InstanceViewStatus (com.microsoft.azure.management.compute.InstanceViewStatus)1 InstanceViewTypes (com.microsoft.azure.management.compute.InstanceViewTypes)1 OSDisk (com.microsoft.azure.management.compute.OSDisk)1 OperatingSystemTypes (com.microsoft.azure.management.compute.OperatingSystemTypes)1 StorageAccountTypes (com.microsoft.azure.management.compute.StorageAccountTypes)1 ImageReferenceInner (com.microsoft.azure.management.compute.implementation.ImageReferenceInner)1 NetworkInterfaceReferenceInner (com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner)1 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)1 VirtualMachinesInner (com.microsoft.azure.management.compute.implementation.VirtualMachinesInner)1 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)1 NetworkInterfaceIPConfigurationInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner)1 ServiceCallback (com.microsoft.rest.ServiceCallback)1 CUSTOM_OS_TYPE (com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE)1 OSType (com.vmware.photon.controller.model.ComputeProperties.OSType)1