Search in sources :

Example 31 with SubnetState

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

the class VSphereNetworkEnumerationHelper method createSubnetStateForNetwork.

private static SubnetState createSubnetStateForNetwork(NetworkState networkState, EnumerationProgress enumerationProgress, NetworkOverlay net) {
    if (!VimNames.TYPE_NETWORK.equals(net.getId().getType()) && !VimNames.TYPE_OPAQUE_NETWORK.equals(net.getId().getType())) {
        return null;
    }
    SubnetState subnet = new SubnetState();
    subnet.documentSelfLink = UriUtils.buildUriPath(SubnetService.FACTORY_LINK, UriUtils.getLastPathSegment(networkState.documentSelfLink));
    subnet.id = subnet.name = net.getName();
    subnet.endpointLink = enumerationProgress.getRequest().endpointLink;
    AdapterUtils.addToEndpointLinks(subnet, enumerationProgress.getRequest().endpointLink);
    subnet.networkLink = networkState.documentSelfLink;
    subnet.tenantLinks = enumerationProgress.getTenantLinks();
    subnet.regionId = networkState.regionId;
    enumerationProgress.touchResource(subnet.documentSelfLink);
    CustomProperties.of(subnet).put(CustomProperties.MOREF, net.getId()).put(CustomProperties.TYPE, net.getId().getType());
    // Add NSX-T related properties to the subnet
    if (VimNames.TYPE_OPAQUE_NETWORK.equals(net.getId().getType())) {
        OpaqueNetworkSummary opaqueNetworkSummary = (OpaqueNetworkSummary) net.getSummary();
        CustomProperties.of(subnet).put(NsxProperties.OPAQUE_NET_ID, opaqueNetworkSummary.getOpaqueNetworkId()).put(NsxProperties.OPAQUE_NET_TYPE, opaqueNetworkSummary.getOpaqueNetworkType());
    }
    return subnet;
}
Also used : OpaqueNetworkSummary(com.vmware.vim25.OpaqueNetworkSummary) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 32 with SubnetState

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

the class ProvisionContext method populateContextThen.

/**
 * Populates the given initial context and invoke the onSuccess handler when built. At every step,
 * if failure occurs the ProvisionContext's errorHandler is invoked to cleanup.
 *
 * @param ctx
 * @param onSuccess
 */
public static void populateContextThen(Service service, ProvisionContext ctx, Consumer<ProvisionContext> onSuccess) {
    // TODO fetch all required state in parallel using OperationJoin.
    if (ctx.child == null) {
        URI computeUri = UriUtils.extendUriWithQuery(ctx.computeReference, UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
        computeUri = createInventoryUri(service.getHost(), computeUri);
        AdapterUtils.getServiceState(service, computeUri, op -> {
            ctx.child = op.getBody(ComputeStateWithDescription.class);
            populateContextThen(service, ctx, onSuccess);
        }, ctx.errorHandler);
        return;
    }
    String templateLink = VimUtils.firstNonNull(CustomProperties.of(ctx.child).getString(CustomProperties.TEMPLATE_LINK), CustomProperties.of(ctx.child.description).getString(CustomProperties.TEMPLATE_LINK));
    // in all other cases ignore the presence of the template
    if (templateLink != null && ctx.templateMoRef == null && ctx.instanceRequestType == InstanceRequestType.CREATE) {
        URI computeUri = createInventoryUri(service.getHost(), templateLink);
        AdapterUtils.getServiceState(service, computeUri, op -> {
            ImageState body = op.getBody(ImageState.class);
            ctx.templateMoRef = CustomProperties.of(body).getMoRef(CustomProperties.MOREF);
            if (ctx.templateMoRef == null) {
                String msg = String.format("The linked template %s does not contain a MoRef in its custom properties", templateLink);
                ctx.fail(new IllegalStateException(msg));
            } else {
                populateContextThen(service, ctx, onSuccess);
            }
        }, ctx.errorHandler);
        return;
    }
    // For creation based on linked clone of snapshot
    if (ctx.snapshotMoRef == null) {
        String snapshotLink = CustomProperties.of(ctx.child).getString(CustomProperties.SNAPSHOT_LINK);
        if (snapshotLink != null && ctx.instanceRequestType == InstanceRequestType.CREATE) {
            URI snapshotUri = createInventoryUri(service.getHost(), snapshotLink);
            AdapterUtils.getServiceState(service, snapshotUri, op -> {
                SnapshotService.SnapshotState snapshotState = op.getBody(SnapshotService.SnapshotState.class);
                ctx.snapshotMoRef = CustomProperties.of(snapshotState).getMoRef(CustomProperties.MOREF);
                if (ctx.snapshotMoRef == null) {
                    String msg = String.format("The linked clone snapshot %s does not contain a MoRef in its custom properties", snapshotLink);
                    ctx.fail(new IllegalStateException(msg));
                } else {
                    // Retrieve the reference endpoint moref from which the linkedclone has to be created.
                    String refComputeLink = snapshotState.computeLink;
                    if (refComputeLink != null) {
                        URI refComputeUri = createInventoryUri(service.getHost(), refComputeLink);
                        AdapterUtils.getServiceState(service, refComputeUri, opCompute -> {
                            ComputeStateWithDescription refComputeState = opCompute.getBody(ComputeStateWithDescription.class);
                            ctx.referenceComputeMoRef = CustomProperties.of(refComputeState).getMoRef(CustomProperties.MOREF);
                            if (ctx.referenceComputeMoRef == null) {
                                String msg = String.format("The linked clone endpoint ref %s does not contain a MoRef in its custom properties", refComputeLink);
                                ctx.fail(new IllegalStateException(msg));
                            }
                            populateContextThen(service, ctx, onSuccess);
                        }, ctx.errorHandler);
                    }
                }
            }, ctx.errorHandler);
            return;
        }
    }
    if (ctx.parent == null && ctx.child.parentLink != null) {
        URI computeUri = UriUtils.extendUriWithQuery(UriUtils.buildUri(service.getHost(), ctx.child.parentLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
        computeUri = createInventoryUri(service.getHost(), computeUri);
        AdapterUtils.getServiceState(service, computeUri, op -> {
            ctx.parent = op.getBody(ComputeStateWithDescription.class);
            populateContextThen(service, ctx, onSuccess);
        }, ctx.errorHandler);
        return;
    }
    if (ctx.vSphereCredentials == null) {
        if (IAAS_API_ENABLED) {
            if (ctx.operation == null) {
                ctx.fail(new IllegalArgumentException("Caller operation cannot be empty"));
                return;
            }
            SessionUtil.retrieveExternalToken(service, ctx.operation.getAuthorizationContext()).whenComplete((authCredentialsServiceState, throwable) -> {
                if (throwable != null) {
                    ctx.errorHandler.accept(throwable);
                    return;
                }
                ctx.vSphereCredentials = authCredentialsServiceState;
                populateContextThen(service, ctx, onSuccess);
            });
        } else {
            if (ctx.parent.description.authCredentialsLink == null) {
                ctx.fail(new IllegalStateException("authCredentialsLink is not defined in resource " + ctx.parent.description.documentSelfLink));
                return;
            }
            URI credUri = createInventoryUri(service.getHost(), ctx.parent.description.authCredentialsLink);
            AdapterUtils.getServiceState(service, credUri, op -> {
                ctx.vSphereCredentials = op.getBody(AuthCredentialsServiceState.class);
                populateContextThen(service, ctx, onSuccess);
            }, ctx.errorHandler);
        }
        return;
    }
    if (ctx.task == null) {
        // Verify if this makes sense? These tasks should always be local to deployment?
        AdapterUtils.getServiceState(service, ctx.provisioningTaskReference, op -> {
            ctx.task = op.getBody(ServiceDocument.class);
            populateContextThen(service, ctx, onSuccess);
        }, ctx.errorHandler);
        return;
    }
    if (ctx.nics == null && ctx.instanceRequestType == InstanceRequestType.CREATE) {
        if (ctx.child.networkInterfaceLinks == null || ctx.child.networkInterfaceLinks.isEmpty()) {
            ctx.nics = Collections.emptyList();
            populateContextThen(service, ctx, onSuccess);
            return;
        }
        ctx.nics = new ArrayList<>();
        Query query = Query.Builder.create().addInClause(ServiceDocument.FIELD_NAME_SELF_LINK, ctx.child.networkInterfaceLinks).build();
        QueryTask qt = QueryTask.Builder.createDirectTask().setQuery(query).addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.EXPAND_LINKS).addOption(QueryOption.SELECT_LINKS).addOption(QueryOption.INDEXED_METADATA).addLinkTerm(NetworkInterfaceState.FIELD_NAME_NETWORK_LINK).addLinkTerm(NetworkInterfaceState.FIELD_NAME_SUBNET_LINK).addLinkTerm(NetworkInterfaceState.FIELD_NAME_DESCRIPTION_LINK).build();
        QueryUtils.startInventoryQueryTask(service, qt).whenComplete((o, e) -> {
            if (e != null) {
                ctx.errorHandler.accept(e);
                return;
            }
            QueryResultsProcessor processor = QueryResultsProcessor.create(o);
            for (NetworkInterfaceStateWithDetails nic : processor.documents(NetworkInterfaceStateWithDetails.class)) {
                if (nic.networkInterfaceDescriptionLink != null) {
                    NetworkInterfaceDescription desc = processor.selectedDocument(nic.networkInterfaceDescriptionLink, NetworkInterfaceDescription.class);
                    nic.description = desc;
                }
                if (nic.subnetLink != null) {
                    SubnetState subnet = processor.selectedDocument(nic.subnetLink, SubnetState.class);
                    nic.subnet = subnet;
                }
                if (nic.networkLink != null) {
                    NetworkState network = processor.selectedDocument(nic.networkLink, NetworkState.class);
                    nic.network = network;
                }
                ctx.nics.add(nic);
            }
            populateContextThen(service, ctx, onSuccess);
        });
        return;
    }
    if (ctx.computeMoRef == null) {
        String placementLink = CustomProperties.of(ctx.child).getString(ComputeProperties.PLACEMENT_LINK);
        if (placementLink == null) {
            Exception error = new IllegalStateException("A Compute resource must have a " + ComputeProperties.PLACEMENT_LINK + " custom property");
            ctx.fail(error);
            return;
        }
        URI expandedPlacementUri = UriUtils.extendUriWithQuery(createInventoryUri(service.getHost(), placementLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
        expandedPlacementUri = createInventoryUri(service.getHost(), expandedPlacementUri);
        Operation.createGet(expandedPlacementUri).setCompletion((o, e) -> {
            if (e != null) {
                ctx.fail(e);
                return;
            }
            ComputeStateWithDescription host = o.getBody(ComputeStateWithDescription.class);
            // extract the target resource pool for the placement
            CustomProperties hostCustomProperties = CustomProperties.of(host);
            ctx.computeMoRef = hostCustomProperties.getMoRef(CustomProperties.MOREF);
            if (ctx.computeMoRef == null) {
                Exception error = new IllegalStateException(String.format("Compute @ %s does not contain a %s custom property", placementLink, CustomProperties.MOREF));
                ctx.fail(error);
                return;
            }
            if (host.description.regionId == null) {
                Exception error = new IllegalStateException(String.format("Compute @ %s does not specify a region", placementLink));
                ctx.fail(error);
                return;
            }
            try {
                ctx.datacenterMoRef = VimUtils.convertStringToMoRef(host.description.regionId);
            } catch (IllegalArgumentException ex) {
                ctx.fail(ex);
                return;
            }
            populateContextThen(service, ctx, onSuccess);
        }).sendWith(service);
        return;
    }
    if (ctx.disks == null) {
        // no disks attached
        if (ctx.child.diskLinks == null || ctx.child.diskLinks.isEmpty()) {
            ctx.disks = Collections.emptyList();
            populateContextThen(service, ctx, onSuccess);
            return;
        }
        ctx.disks = new ArrayList<>(ctx.child.diskLinks.size());
        // collect disks in parallel
        Stream<Operation> opsGetDisk = ctx.child.diskLinks.stream().map(link -> {
            URI diskStateUri = UriUtils.buildUri(service.getHost(), link);
            return Operation.createGet(createInventoryUri(service.getHost(), DiskStateExpanded.buildUri(diskStateUri)));
        });
        OperationJoin join = OperationJoin.create(opsGetDisk).setCompletion((os, errors) -> {
            if (errors != null && !errors.isEmpty()) {
                // fail on first error
                ctx.errorHandler.accept(new IllegalStateException("Cannot get disk state", errors.values().iterator().next()));
                return;
            }
            os.values().forEach(op -> ctx.disks.add(op.getBody(DiskStateExpanded.class)));
            populateContextThen(service, ctx, onSuccess);
        });
        join.sendWith(service);
        return;
    }
    String libraryItemLink = VimUtils.firstNonNull(CustomProperties.of(ctx.child).getString(CustomProperties.LIBRARY_ITEM_LINK), CustomProperties.of(ctx.child.description).getString(CustomProperties.LIBRARY_ITEM_LINK));
    if (libraryItemLink != null && ctx.image == null && ctx.instanceRequestType == InstanceRequestType.CREATE) {
        URI libraryUri = createInventoryUri(service.getHost(), libraryItemLink);
        AdapterUtils.getServiceState(service, libraryUri, op -> {
            ImageState body = op.getBody(ImageState.class);
            ctx.image = body;
            populateContextThen(service, ctx, onSuccess);
        }, ctx.errorHandler);
        return;
    }
    if (ctx.instanceRequestType == InstanceRequestType.CREATE) {
        if (ctx.image == null) {
            DiskStateExpanded bootDisk = ctx.disks.stream().filter(d -> d.imageLink != null).findFirst().orElse(null);
            if (bootDisk != null) {
                URI bootImageRef = createInventoryUri(service.getHost(), bootDisk.imageLink);
                AdapterUtils.getServiceState(service, bootImageRef, op -> {
                    ImageState body = op.getBody(ImageState.class);
                    ctx.image = body;
                    populateContextThen(service, ctx, onSuccess);
                }, ctx.errorHandler);
                return;
            }
        }
    }
    // Order networks by deviceIndex so that nics are created in the same order
    if (ctx.nics != null) {
        // configure network
        ctx.nics.sort((lnis, rnis) -> {
            return Integer.compare(lnis.deviceIndex, rnis.deviceIndex);
        });
    }
    // context populated, invoke handler
    onSuccess.accept(ctx);
}
Also used : Service(com.vmware.xenon.common.Service) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) SessionUtil(com.vmware.photon.controller.model.resources.SessionUtil) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) ArrayList(java.util.ArrayList) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) ResourceRequest(com.vmware.photon.controller.model.adapterapi.ResourceRequest) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) URI(java.net.URI) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest.InstanceRequestType) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) UriUtils(com.vmware.xenon.common.UriUtils) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) IAAS_API_ENABLED(com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) Query(com.vmware.xenon.services.common.QueryTask.Query) OperationJoin(com.vmware.xenon.common.OperationJoin) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) ServiceDocument(com.vmware.xenon.common.ServiceDocument) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QueryTask(com.vmware.xenon.services.common.QueryTask) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 33 with SubnetState

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

the class AWSLoadBalancerServiceTest method createSubnetState.

private SubnetState createSubnetState(String id, String networkLink) throws Throwable {
    SubnetState subnetState = new SubnetState();
    subnetState.name = id;
    subnetState.id = id;
    subnetState.endpointLink = this.endpointState.documentSelfLink;
    subnetState.endpointLinks = new HashSet<String>();
    subnetState.endpointLinks.add(this.endpointState.documentSelfLink);
    subnetState.networkLink = networkLink;
    subnetState.subnetCIDR = "10.10.10.10/24";
    subnetState.tenantLinks = this.endpointState.tenantLinks;
    return postServiceSynchronously(SubnetService.FACTORY_LINK, subnetState, SubnetState.class);
}
Also used : SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 34 with SubnetState

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

the class AWSNetworkStateEnumerationAdapterService method createSubnetStateOperations.

/**
 * Create the subnet state operations for all the Subnets that need to be created or updated in
 * the system.
 */
private void createSubnetStateOperations(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
    if (context.subnets.isEmpty()) {
        logFine(() -> "No new subnets found.");
        handleNetworkStateChanges(context, next);
        return;
    }
    final List<Operation> subnetOperations = new ArrayList<>();
    for (String remoteSubnetId : context.subnets.keySet()) {
        SubnetStateWithParentVpcId subnetStateWithParentVpcId = context.subnets.get(remoteSubnetId);
        SubnetState subnetState = subnetStateWithParentVpcId.subnetState;
        // Update networkLink with "latest" (either created or updated)
        // NetworkState.documentSelfLink
        subnetState.networkLink = context.vpcs.get(subnetStateWithParentVpcId.parentVpcId).documentSelfLink;
        final Operation subnetStateOp;
        if (context.localSubnetStateMap.containsKey(remoteSubnetId)) {
            // If the local subnet state already exists for the Subnet -> Update it.
            subnetState.documentSelfLink = context.localSubnetStateMap.get(remoteSubnetId).documentSelfLink;
            // for already existing subnets, add internal tags only if missing
            if (subnetState.tagLinks == null || subnetState.tagLinks.isEmpty()) {
                setTagLinksToResourceState(subnetState, context.subnetInternalTagsMap, false);
            } else {
                context.subnetInternalTagLinksSet.stream().filter(tagLink -> !subnetState.tagLinks.contains(tagLink)).map(tagLink -> subnetState.tagLinks.add(tagLink)).collect(Collectors.toSet());
            }
            subnetStateOp = createPatchOperation(this, subnetState, subnetState.documentSelfLink);
        } else {
            // add tag links
            Subnet awsSubnet = context.awsSubnets.get(remoteSubnetId);
            setResourceTags(subnetState, awsSubnet.getTags());
            setTagLinksToResourceState(subnetState, context.subnetInternalTagsMap, false);
            subnetStateOp = createPostOperation(this, subnetState, SubnetService.FACTORY_LINK);
        }
        subnetOperations.add(subnetStateOp);
    }
    JoinedCompletionHandler joinCompletion = (ops, excs) -> {
        if (excs != null) {
            Entry<Long, Throwable> excEntry = excs.entrySet().iterator().next();
            Throwable exc = excEntry.getValue();
            Operation op = ops.get(excEntry.getKey());
            logSevere(() -> String.format("Error %s-ing a Subnet state: %s", op.getAction(), Utils.toString(excs)));
            finishWithFailure(context, exc);
            return;
        }
        logFine(() -> "Successfully created/updated all subnet states.");
        ops.values().stream().filter(op -> op.getStatusCode() != Operation.STATUS_CODE_NOT_MODIFIED).forEach(op -> {
            SubnetState subnetState = op.getBody(SubnetState.class);
            context.subnets.get(subnetState.id).subnetState = subnetState;
        });
        handleNetworkStateChanges(context, next);
    };
    OperationJoin.create(subnetOperations).setCompletion(joinCompletion).sendWith(this);
}
Also used : Arrays(java.util.Arrays) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) AWSNetworkUtils.mapVPCToNetworkState(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSNetworkUtils.mapVPCToNetworkState) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) AWSResourceType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSResourceType) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) AWSNetworkUtils.createQueryToGetExistingNetworkStatesFilteredByDiscoveredVPCs(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSNetworkUtils.createQueryToGetExistingNetworkStatesFilteredByDiscoveredVPCs) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) Utils(com.vmware.xenon.common.Utils) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) SubnetStateWithParentVpcId(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSNetworkStateEnumerationAdapterService.AWSNetworkStateCreationContext.SubnetStateWithParentVpcId) AWS_ATTACHMENT_VPC_FILTER(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ATTACHMENT_VPC_FILTER) InternetGatewayAttachment(com.amazonaws.services.ec2.model.InternetGatewayAttachment) AdapterUtils.createPatchOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPatchOperation) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) AWS_MAIN_ROUTE_ASSOCIATION(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_MAIN_ROUTE_ASSOCIATION) AWSAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSAsyncHandler) StatelessService(com.vmware.xenon.common.StatelessService) AWSNetworkUtils.mapSubnetToSubnetState(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSNetworkUtils.mapSubnetToSubnetState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) Set(java.util.Set) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) AdapterUtils.getDeletionState(com.vmware.photon.controller.model.adapters.util.AdapterUtils.getDeletionState) Collectors(java.util.stream.Collectors) AWS_GATEWAY_ID(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_GATEWAY_ID) List(java.util.List) AWS_FILTER_VPC_ID(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_FILTER_VPC_ID) DescribeRouteTablesRequest(com.amazonaws.services.ec2.model.DescribeRouteTablesRequest) TagService(com.vmware.photon.controller.model.resources.TagService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) Entry(java.util.Map.Entry) TagsUtil.setTagLinksToResourceState(com.vmware.photon.controller.model.adapters.util.TagsUtil.setTagLinksToResourceState) DescribeRouteTablesResult(com.amazonaws.services.ec2.model.DescribeRouteTablesResult) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) HashMap(java.util.HashMap) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) AWSConstants(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) TagsUtil.updateLocalTagStates(com.vmware.photon.controller.model.adapters.util.TagsUtil.updateLocalTagStates) AdapterUtils.createPostOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPostOperation) BiConsumer(java.util.function.BiConsumer) Filter(com.amazonaws.services.ec2.model.Filter) RouteTable(com.amazonaws.services.ec2.model.RouteTable) Subnet(com.amazonaws.services.ec2.model.Subnet) AWS_VPC_ROUTE_TABLE_ID(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VPC_ROUTE_TABLE_ID) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Vpc(com.amazonaws.services.ec2.model.Vpc) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) AWSNetworkUtils.createQueryToGetExistingSubnetStatesFilteredByDiscoveredSubnets(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSNetworkUtils.createQueryToGetExistingSubnetStatesFilteredByDiscoveredSubnets) NumericRange.createLessThanRange(com.vmware.xenon.services.common.QueryTask.NumericRange.createLessThanRange) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) AWS_VPC_ID_FILTER(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VPC_ID_FILTER) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) AWSUriPaths(com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths) OperationJoin(com.vmware.xenon.common.OperationJoin) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) SubnetStateWithParentVpcId(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSNetworkStateEnumerationAdapterService.AWSNetworkStateCreationContext.SubnetStateWithParentVpcId) AdapterUtils.createPatchOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPatchOperation) AdapterUtils.createPostOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPostOperation) Operation(com.vmware.xenon.common.Operation) Subnet(com.amazonaws.services.ec2.model.Subnet) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) AWSNetworkUtils.mapSubnetToSubnetState(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSNetworkUtils.mapSubnetToSubnetState)

Example 35 with SubnetState

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

the class AWSSubnetTaskServiceTest method provisionSubnet.

private SubnetState provisionSubnet(String name, String subnetCidr, String publicSubnetLink) throws Throwable {
    SubnetState subnetState = createSubnetState(null, name, subnetCidr, publicSubnetLink);
    kickOffSubnetProvision(InstanceRequestType.CREATE, subnetState, TaskStage.FINISHED);
    return getServiceSynchronously(subnetState.documentSelfLink, SubnetState.class);
}
Also used : 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