Search in sources :

Example 6 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class NetworkDeviceBackingFactoryTest method testNetworkStateBackingInfo.

@Test
public void testNetworkStateBackingInfo() {
    this.network = new NetworkState();
    this.network.name = UUID.randomUUID().toString();
    this.network.customProperties = new HashMap<>();
    VirtualDeviceBackingInfo deviceBackingInfo = NetworkDeviceBackingFactory.getNetworkDeviceBackingInfo(this.network);
    assertTrue(deviceBackingInfo instanceof VirtualEthernetCardNetworkBackingInfo);
    VirtualEthernetCardNetworkBackingInfo virtualEthernetCardNetworkBackingInfo = (VirtualEthernetCardNetworkBackingInfo) deviceBackingInfo;
    assertEquals(this.network.name, virtualEthernetCardNetworkBackingInfo.getDeviceName());
}
Also used : VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) Test(org.junit.Test)

Example 7 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class ModelUtils method createCompute.

public static ComputeService.ComputeStateWithDescription createCompute(BaseModelTest test, ComputeDescriptionService.ComputeDescription cd) throws Throwable {
    ComputeService.ComputeState cs = new ComputeService.ComputeStateWithDescription();
    cs.id = UUID.randomUUID().toString();
    cs.name = cd.name;
    cs.descriptionLink = cd.documentSelfLink;
    cs.resourcePoolLink = null;
    cs.address = "10.0.0.1";
    cs.primaryMAC = "01:23:45:67:89:ab";
    cs.powerState = ComputeService.PowerState.ON;
    cs.adapterManagementReference = URI.create("https://esxhost-01:443/sdk");
    cs.diskLinks = new ArrayList<>();
    cs.diskLinks.add(createDiskState(test, cs.name).documentSelfLink);
    cs.networkInterfaceLinks = new ArrayList<>();
    EndpointState endpointState = createEndpoint(test);
    NetworkState networkState = createNetwork(test, endpointState);
    SubnetState subnetState = createSubnet(test, networkState, endpointState);
    SubnetRangeState subnetRangeState = createSubnetRange(test, subnetState, "12.12.12.2", "12.12.12.120");
    NetworkInterfaceState networkInterfaceState1 = createNetworkInterface(test, "nic-1", subnetState, networkState);
    IPAddressState ipAddressState1 = createIpAddress(test, "12.12.12.2", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState1.documentSelfLink);
    NetworkInterfaceState networkInterfaceState2 = createNetworkInterface(test, "nic-2", subnetState, networkState);
    IPAddressState ipAddressState2 = createIpAddress(test, "12.12.12.3", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState2.documentSelfLink);
    NetworkInterfaceState networkInterfaceState3 = createNetworkInterface(test, "nic-3", subnetState, networkState);
    IPAddressState ipAddressState3 = createIpAddress(test, "12.12.12.4", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState3.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState1.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState2.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState3.documentSelfLink);
    cs.customProperties = new HashMap<>();
    cs.customProperties.put(TEST_DESC_PROPERTY_NAME, TEST_DESC_PROPERTY_VALUE);
    cs.tenantLinks = new ArrayList<>();
    cs.tenantLinks.add("http://tenant");
    ComputeService.ComputeState returnState = test.postServiceSynchronously(ComputeService.FACTORY_LINK, cs, ComputeService.ComputeState.class);
    return ComputeService.ComputeStateWithDescription.create(cd, returnState);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SubnetRangeState(com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState) IPAddressState(com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 8 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class ResourceGroomerTaskService method populateEndpointLinksByDocumentLinks.

/**
 * Helper for creating corresponding object and parsing the response for given documentKind
 * to store selfLink and endpointLink.
 */
private static void populateEndpointLinksByDocumentLinks(Map<String, Object> documents, Map<String, Set<String>> endpointLinksByDocumentLinks, Map<String, String> endpointLinkByDocumentLinks) {
    for (Object document : documents.values()) {
        ServiceDocument doc = Utils.fromJson(document, ServiceDocument.class);
        Set<String> endpointLinks = new HashSet<>();
        if (doc.documentKind.equals(COMPUTE_STATE_DOCUMENT_KIND)) {
            ComputeState state = Utils.fromJson(document, ComputeState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(DISK_STATE_DOCUMENT_KIND)) {
            DiskState state = Utils.fromJson(document, DiskState.class);
            if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
                // skip resources that have never been attached to a particular endpoint
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(COMPUTE_DESCRIPTION_DOCUMENT_KIND)) {
            ComputeDescription state = Utils.fromJson(document, ComputeDescription.class);
            // only deleting discovered resources
            if (!(state.customProperties != null && (ResourceEnumerationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK)) || EndpointAllocationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK))))) {
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(NETWORK_STATE_DOCUMENT_KIND)) {
            NetworkState state = Utils.fromJson(document, NetworkState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(NETWORK_INTERFACE_STATE_DOCUMENT_KIND)) {
            NetworkInterfaceState state = Utils.fromJson(document, NetworkInterfaceState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(SECURITY_GROUP_STATE_DOCUMENT_KIND)) {
            SecurityGroupState state = Utils.fromJson(document, SecurityGroupState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(SUBNET_STATE_DOCUMENT_KIND)) {
            SubnetState state = Utils.fromJson(document, SubnetState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(LOAD_BALANCER_DOCUMENT_KIND)) {
            LoadBalancerState state = Utils.fromJson(document, LoadBalancerState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(STORAGE_DESCRIPTION_DOCUMENT_KIND)) {
            StorageDescription state = Utils.fromJson(document, StorageDescription.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(RESOURCE_GROUP_DOCUMENT_KIND)) {
            ResourceGroupState state = Utils.fromJson(document, ResourceGroupState.class);
            if (state.customProperties != null && state.customProperties.containsKey(ResourceGroupService.PROPERTY_NAME_IS_USER_CREATED)) {
                continue;
            }
            if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
                // skip resources that have never been attached to a particular endpoint
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(IMAGE_STATE_KIND)) {
            ImageState state = Utils.fromJson(document, ImageState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(ROUTER_STATE_KIND)) {
            RouterState state = Utils.fromJson(document, RouterState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(AUTH_CREDENTIALS_SERVICE_STATE_KIND)) {
            AuthCredentialsServiceState state = Utils.fromJson(document, AuthCredentialsServiceState.class);
            if (state.customProperties != null && state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK) != null) {
                endpointLinkByDocumentLinks.put(state.documentSelfLink, state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK));
            } else {
                endpointLinkByDocumentLinks.put(state.documentSelfLink, EMPTY_STRING);
            }
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) RouterState(com.vmware.photon.controller.model.resources.RouterService.RouterState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) HashSet(java.util.HashSet) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 9 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class ProvisionNetworkTaskServiceTest method buildValidStartState.

private static ProvisionNetworkTaskService.ProvisionNetworkTaskState buildValidStartState(BaseModelTest test, NetworkInstanceRequest.InstanceRequestType requestType, boolean success) throws Throwable {
    NetworkState nState = new NetworkState();
    nState.authCredentialsLink = "authCredentialsLink";
    nState.name = "firewall-name";
    nState.regionId = "regionId";
    nState.resourcePoolLink = "http://resourcePoolLink";
    nState.subnetCIDR = "152.151.150.222/22";
    if (success) {
        nState.instanceAdapterReference = UriUtils.buildUri(test.getHost(), MockAdapter.MockNetworkInstanceSuccessAdapter.SELF_LINK);
    } else {
        nState.instanceAdapterReference = UriUtils.buildUri(test.getHost(), MockAdapter.MockNetworkInstanceFailureAdapter.SELF_LINK);
    }
    nState.id = UUID.randomUUID().toString();
    NetworkState returnState = test.postServiceSynchronously(NetworkService.FACTORY_LINK, nState, NetworkState.class);
    ProvisionNetworkTaskService.ProvisionNetworkTaskState startState = new ProvisionNetworkTaskService.ProvisionNetworkTaskState();
    startState.requestType = requestType;
    startState.networkDescriptionLink = returnState.documentSelfLink;
    startState.isMockRequest = true;
    return startState;
}
Also used : NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState)

Example 10 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class AWSLoadBalancerServiceTest method createNetworkState.

private NetworkState createNetworkState(String id) throws Throwable {
    NetworkState networkState = new NetworkState();
    networkState.name = id;
    networkState.id = id;
    networkState.endpointLink = this.endpointState.documentSelfLink;
    networkState.endpointLinks = new HashSet<String>();
    networkState.endpointLinks.add(this.endpointState.documentSelfLink);
    networkState.tenantLinks = this.endpointState.tenantLinks;
    networkState.instanceAdapterReference = UriUtils.buildUri(this.host, AWSNetworkService.SELF_LINK);
    networkState.resourcePoolLink = this.endpointState.resourcePoolLink;
    networkState.regionId = this.endpointState.regionId;
    return postServiceSynchronously(NetworkService.FACTORY_LINK, networkState, NetworkState.class);
}
Also used : NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState)

Aggregations

NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)43 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)23 Operation (com.vmware.xenon.common.Operation)15 URI (java.net.URI)14 ArrayList (java.util.ArrayList)13 NetworkService (com.vmware.photon.controller.model.resources.NetworkService)10 HashMap (java.util.HashMap)10 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)9 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)9 SubnetService (com.vmware.photon.controller.model.resources.SubnetService)9 UriUtils (com.vmware.xenon.common.UriUtils)9 Query (com.vmware.xenon.services.common.QueryTask.Query)9 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)8 HashSet (java.util.HashSet)8 List (java.util.List)8 TagsUtil.newTagState (com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)7 TagState (com.vmware.photon.controller.model.resources.TagService.TagState)7 DeferredResult (com.vmware.xenon.common.DeferredResult)7 StatelessService (com.vmware.xenon.common.StatelessService)7 Map (java.util.Map)7