Search in sources :

Example 26 with NetworkInterfaceState

use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState in project photon-model by vmware.

the class NetworkInterfaceServiceTest method buildValidStartState.

private static NetworkInterfaceState buildValidStartState(boolean assignHost) {
    NetworkInterfaceState networkInterfaceState = new NetworkInterfaceState();
    networkInterfaceState.id = UUID.randomUUID().toString();
    networkInterfaceState.name = NetworkInterfaceServiceTest.class.getSimpleName();
    networkInterfaceState.address = "9.9.9.9";
    networkInterfaceState.securityGroupLinks = Collections.singletonList("/resources/security-groups/1");
    networkInterfaceState.networkInterfaceDescriptionLink = "/resources/nicDesc/nicDesc9";
    networkInterfaceState.subnetLink = "/resources/subnet/subnet9";
    if (assignHost) {
        networkInterfaceState.computeHostLink = "host-1";
    }
    return networkInterfaceState;
}
Also used : NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)

Example 27 with NetworkInterfaceState

use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState in project photon-model by vmware.

the class TestAWSEnumerationTask method testEnumerationUpdateNICs.

// Runs the enumeration task after a new nic has been added to a CS and then after it has been
// removed
@Test
public void testEnumerationUpdateNICs() throws Throwable {
    if (this.isMock) {
        return;
    }
    this.host.log("Running test: " + this.currentTestName.getMethodName());
    ComputeState vmState = createAWSVMResource(this.host, this.computeHost, this.endpointState, TestAWSSetupUtils.class, zoneId, regionId, null, this.singleNicSpec, this.awsTestContext);
    // Overriding the page size to test the pagination logic with limited instances on AWS.
    // This is a functional test
    // so the latency numbers maybe higher from this test due to low page size.
    setQueryPageSize(DEFAULT_TEST_PAGE_SIZE);
    setQueryResultLimit(DEFAULT_TEST_PAGE_SIZE);
    // Provision a single VM . Check initial state.
    vmState = provisionMachine(this.host, vmState, this.isMock, this.instancesToCleanUp);
    // Run enumeration to discover the new VM
    enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_INITIAL);
    int numberOfNICsBeforeAdding = vmState.networkInterfaceLinks.size();
    String newNICId = createNICDirectlyWithEC2Client(this.client, this.host, this.subnetId);
    this.nicToCleanUp = newNICId;
    String newAWSNicAttachmentId = addNICDirectlyWithEC2Client(vmState, this.client, this.host, newNICId);
    // Run enumeration to discover the changes in the NICs in the new VM
    enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_ADDITIONAL_NIC);
    // validate NICs
    ComputeState updatedComputeState = getComputeByAWSId(this.host, vmState.id);
    // New NIC State link should have been added to the CS
    assertEquals(numberOfNICsBeforeAdding + 1, updatedComputeState.networkInterfaceLinks.size());
    NetworkInterfaceState addedNetworkInterfaceState = getNICByAWSId(this.host, newNICId);
    // Assert that the network interface state has the right internal tag link
    assertTrue(addedNetworkInterfaceState.tagLinks.contains(TagsUtil.newTagState(TAG_KEY_TYPE, AWSResourceType.ec2_net_interface.toString(), false, this.endpointState.tenantLinks).documentSelfLink));
    // NIC State with the new ID should have been created
    assertNotNull(addedNetworkInterfaceState);
    detachNICDirectlyWithEC2Client(vmState.id, newAWSNicAttachmentId, newNICId, this.client, this.host);
    // Run again enumeration to discover the changes in the NICs in the new VM
    enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_REMOVED_NIC);
    // validate NICs
    ComputeState updatedAgainComputeState = getComputeByAWSId(this.host, vmState.id);
    // The link to the removed NIC State should have been removed
    assertEquals(numberOfNICsBeforeAdding, updatedAgainComputeState.networkInterfaceLinks.size());
    NetworkInterfaceState removedNetworkInterfaceState = getNICByAWSId(this.host, newNICId);
    // NIC State with this ID should have been removed
    assertEquals(null, removedNetworkInterfaceState);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) TestAWSSetupUtils.deleteVMsOnThisEndpoint(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.deleteVMsOnThisEndpoint) Test(org.junit.Test)

Example 28 with NetworkInterfaceState

use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState 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 29 with NetworkInterfaceState

use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState 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)

Example 30 with NetworkInterfaceState

use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState in project photon-model by vmware.

the class TestAWSProvisionTask method assertVmNetworksConfiguration.

private void assertVmNetworksConfiguration(Instance awsInstance) throws Throwable {
    // This assert is only suitable for real (non-mocking env).
    if (this.isMock) {
        return;
    }
    this.host.log(Level.INFO, "%s: Assert network configuration for [%s] VM", this.currentTestName.getMethodName(), this.vmState.name);
    ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
    assertNotNull("ComputeState.address should be set to public IP.", vm.address);
    assertEquals("ComputeState.address should be set to AWS Instance public IP.", awsInstance.getPublicIpAddress(), vm.address);
    for (String nicLink : vm.networkInterfaceLinks) {
        NetworkInterfaceState nicState = this.host.getServiceState(null, NetworkInterfaceState.class, UriUtils.buildUri(this.host, nicLink));
        // for now validate only the 0 NIC as we are creating single NIC VM
        if (nicState.deviceIndex != 0) {
            continue;
        }
        InstanceNetworkInterface awsNic = null;
        for (InstanceNetworkInterface nic : awsInstance.getNetworkInterfaces()) {
            if (nic.getAttachment().getDeviceIndex() == nicState.deviceIndex) {
                awsNic = nic;
                break;
            }
        }
        assertNotNull("Unable to find AWS NIC with device index " + nicState.deviceIndex, awsNic);
        assertEquals("NetworkInterfaceState[" + nicState.deviceIndex + "].address should be set to AWS NIC private IP.", awsNic.getPrivateIpAddress(), nicState.address);
    }
    assertVMSercurityGroupsConfiguration(awsInstance, vm);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) InstanceNetworkInterface(com.amazonaws.services.ec2.model.InstanceNetworkInterface)

Aggregations

NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)32 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)17 Operation (com.vmware.xenon.common.Operation)15 ArrayList (java.util.ArrayList)14 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)13 URI (java.net.URI)10 HashSet (java.util.HashSet)10 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)9 DeferredResult (com.vmware.xenon.common.DeferredResult)9 QueryTask (com.vmware.xenon.services.common.QueryTask)9 List (java.util.List)9 Map (java.util.Map)9 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)8 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)7 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)7 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)7 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)7 OperationJoin (com.vmware.xenon.common.OperationJoin)7