Search in sources :

Example 6 with NetworkInterfaceInner

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

the class AzureInstanceService method newAzureNetworkInterface.

/**
 * Converts Photon model constructs to underlying Azure NetworkInterface model.
 */
private NetworkInterfaceInner newAzureNetworkInterface(AzureInstanceContext ctx, AzureNicContext nicCtx) {
    NetworkInterfaceDescription description = nicCtx.nicStateWithDesc.description;
    NetworkInterfaceIPConfigurationInner ipConfig = new NetworkInterfaceIPConfigurationInner();
    ipConfig.withName(AzureUtils.generateClusterCommonName(NICCONFIG_NAME_PREFIX, ctx));
    ipConfig.withSubnet(nicCtx.subnet);
    if (nicCtx.publicIP != null) {
        // Public IP is not auto-assigned so check for existence
        ipConfig.withPublicIPAddress(new SubResource().withId(nicCtx.publicIP.id()));
    }
    ipConfig.withPrivateIPAllocationMethod(new IPAllocationMethod(description.assignment.name()));
    if (description.assignment == IpAssignment.STATIC) {
        ipConfig.withPrivateIPAddress(description.address);
    }
    NetworkInterfaceInner nic = new NetworkInterfaceInner();
    nic.withLocation(ctx.resourceGroup.location());
    // Azure's custom serializers don't handle well collections constructed with
    // Collections.singletonList(), so initialize an ArrayList
    List<NetworkInterfaceIPConfigurationInner> ipConfigs = new ArrayList<>();
    ipConfigs.add(ipConfig);
    nic.withIpConfigurations(ipConfigs);
    if (nicCtx.securityGroup != null) {
        // Security group is optional so check for existence
        nic.withNetworkSecurityGroup(new SubResource().withId(nicCtx.securityGroup.id()));
    }
    return nic;
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) IPAllocationMethod(com.microsoft.azure.management.network.IPAllocationMethod) SubResource(com.microsoft.azure.SubResource) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) ArrayList(java.util.ArrayList) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Example 7 with NetworkInterfaceInner

use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner 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 8 with NetworkInterfaceInner

use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner 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)

Example 9 with NetworkInterfaceInner

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

the class AzureComputeEnumerationAdapterService method createNic.

private void createNic(Map<String, Pair<NetworkInterfaceInner, String>> remoteStates, EnumerationContext ctx, Map<String, String> subnetPerNicId, List<DeferredResult<NetworkInterfaceState>> ops) {
    remoteStates.values().stream().forEach(p -> {
        NetworkInterfaceInner remoteNic = p.getLeft();
        NetworkInterfaceState state = new NetworkInterfaceState();
        processCreateUpdateNicRequest(state, remoteNic, ctx, ops, subnetPerNicId, true);
    });
}
Also used : NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Example 10 with NetworkInterfaceInner

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

the class AzureComputeEnumerationAdapterService method processCreateUpdateNicRequest.

/**
 * Processes request for creating and updating Network interface resources.
 */
private void processCreateUpdateNicRequest(NetworkInterfaceState nic, NetworkInterfaceInner remoteNic, EnumerationContext ctx, List<DeferredResult<NetworkInterfaceState>> ops, Map<String, String> subnetPerNicId, boolean isCreate) {
    nic.name = remoteNic.name();
    nic.subnetLink = subnetPerNicId.get(remoteNic.id());
    NicMetadata nicMeta = new NicMetadata();
    nicMeta.state = nic;
    nicMeta.macAddress = remoteNic.macAddress();
    // else will default to original ID for PATCH requests
    if (isCreate) {
        nic.id = remoteNic.id();
        nic.endpointLink = ctx.request.endpointLink;
        AdapterUtils.addToEndpointLinks(nic, ctx.request.endpointLink);
        nic.tenantLinks = ctx.parentCompute.tenantLinks;
        nic.regionId = remoteNic.location();
        nic.computeHostLink = ctx.parentCompute.documentSelfLink;
    } else {
        if (StringUtils.isEmpty(nic.endpointLink)) {
            nic.endpointLink = ctx.request.endpointLink;
        }
        nic.endpointLinks.add(ctx.request.endpointLink);
    }
    List<NetworkInterfaceIPConfigurationInner> ipConfigurations = remoteNic.ipConfigurations();
    if (ipConfigurations == null || ipConfigurations.isEmpty()) {
        executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
        return;
    }
    NetworkInterfaceIPConfigurationInner nicIPConf = ipConfigurations.get(0);
    nic.address = nicIPConf.privateIPAddress();
    if (nicIPConf.publicIPAddress() == null) {
        executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
        return;
    }
    // IP address is not directly available in NetworkInterfaceIPConfigurationInner.
    // It is available as a SubResource, We use the SubResource ID of IP address from
    // NetworkInterfaceIPConfigurationInner to obtain the IP address.
    Consumer<Throwable> failure = e -> {
        logWarning("Error getting public IP address from Azure [endpointLink:%s], [Exception:%s]", ctx.request.endpointLink, e.getMessage());
        handleError(ctx, e);
    };
    PhotonModelUtils.runInExecutor(this.executorService, () -> {
        Azure azure = ctx.azureSdkClients.getAzureClient();
        azure.publicIPAddresses().getByIdAsync(nicIPConf.publicIPAddress().id()).subscribe(injectOperationContext(new Action1<PublicIPAddress>() {

            @Override
            public void call(PublicIPAddress publicIPAddress) {
                nicMeta.publicIp = publicIPAddress.ipAddress();
                if (publicIPAddress.inner().dnsSettings() != null) {
                    nicMeta.publicDnsName = publicIPAddress.inner().dnsSettings().fqdn();
                }
                executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
            }
        }));
    }, 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) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) Action1(rx.functions.Action1) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress)

Aggregations

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