Search in sources :

Example 11 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class SubnetRangeServiceTest method buildValidSubnetState.

private static SubnetService.SubnetState buildValidSubnetState() {
    SubnetService.SubnetState subnetState = new SubnetState();
    subnetState.subnetCIDR = "192.130.120.0/24";
    subnetState.networkLink = UriUtils.buildUriPath(NetworkService.FACTORY_LINK, UUID.randomUUID().toString());
    subnetState.tenantLinks = new ArrayList<String>();
    subnetState.tagLinks = new HashSet<>();
    subnetState.gatewayAddress = "192.130.120.1";
    return subnetState;
}
Also used : SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 12 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState 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 13 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class SubnetRangeService method validateIps.

/**
 * Returns a Deferred result if start IP address and end IP address are within the network
 * specfied  by the subnet CIDR. If not an exception is raised in the method this calls.
 *
 * @param subnetRangeState The subnet state that is being validated.
 * @return a deferred result, that has no data. This method returning just validates the data.
 */
private DeferredResult<Void> validateIps(SubnetRangeState subnetRangeState) {
    if (subnetRangeState.subnetLink != null) {
        return getSubnetState(subnetRangeState.subnetLink).thenAccept((op) -> {
            SubnetState subnetState = op.getBody(SubnetState.class);
            validateIpInRange(subnetRangeState, subnetState);
        });
    }
    return DeferredResult.completed(null);
}
Also used : SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 14 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState 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 15 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class ProvisionSubnetTaskServiceTest method buildStartState.

private static ProvisionSubnetTaskState buildStartState(BaseModelTest test, SubnetInstanceRequest.InstanceRequestType requestType, InstanceAdapterTestTypes instanceAdapterType) throws Throwable {
    SubnetState state = new SubnetState();
    state.name = "subnet1-name";
    state.networkLink = "networkLink";
    state.gatewayAddress = "192.168.21.1";
    state.subnetCIDR = "192.168.21.0/28";
    switch(instanceAdapterType) {
        case SUCCESS:
            state.instanceAdapterReference = UriUtils.buildUri(test.getHost(), MockAdapter.MockSubnetInstanceSuccessAdapter.SELF_LINK);
            break;
        case FAILURE:
            state.instanceAdapterReference = UriUtils.buildUri(test.getHost(), MockAdapter.MockSubnetInstanceFailureAdapter.SELF_LINK);
            break;
        default:
            state.instanceAdapterReference = null;
    }
    state.id = UUID.randomUUID().toString();
    SubnetState returnState = test.postServiceSynchronously(SubnetService.FACTORY_LINK, state, SubnetState.class);
    ProvisionSubnetTaskState startState = new ProvisionSubnetTaskState();
    startState.requestType = requestType;
    startState.subnetLink = returnState.documentSelfLink;
    startState.options = EnumSet.of(TaskOption.IS_MOCK);
    return startState;
}
Also used : ProvisionSubnetTaskState(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Aggregations

SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)61 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)22 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)16 Operation (com.vmware.xenon.common.Operation)14 Query (com.vmware.xenon.services.common.QueryTask.Query)12 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)11 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)11 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)11 URI (java.net.URI)11 DeferredResult (com.vmware.xenon.common.DeferredResult)10 HashMap (java.util.HashMap)10 List (java.util.List)10 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)9 StatelessService (com.vmware.xenon.common.StatelessService)9 SubnetService (com.vmware.photon.controller.model.resources.SubnetService)8 UriUtils (com.vmware.xenon.common.UriUtils)8 TagsUtil.newTagState (com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)7 NetworkService (com.vmware.photon.controller.model.resources.NetworkService)7 TagState (com.vmware.photon.controller.model.resources.TagService.TagState)7