Search in sources :

Example 1 with LINK

use of com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.LINK in project photon-model by vmware.

the class NicSecurityGroupsTaskService method validateSecurityGroupsEndpoint.

/**
 * Validate that all security groups belong to the same endpoint
 */
private DeferredResult<Void> validateSecurityGroupsEndpoint(NicSecurityGroupsTaskState state) {
    QueryTask.Query query = QueryTask.Query.Builder.create().addKindFieldClause(SecurityGroupState.class).addInClause(ServiceDocument.FIELD_NAME_SELF_LINK, state.securityGroupLinks).build();
    QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query).addSelectTerm(SecurityGroupState.FIELD_NAME_ENDPOINT_LINK).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_SELECTED_FIELDS).build();
    return QueryUtils.startInventoryQueryTask(this, queryTask).thenApply(qrt -> {
        AssertUtil.assertTrue(qrt != null && qrt.results.documentCount > 0, String.format("Could not find security groups with links %s", state.securityGroupLinks));
        Set<String> endpointLinks = qrt.results.documents.values().stream().map(o -> Utils.fromJson(o, SecurityGroupState.class).endpointLink).collect(Collectors.toSet());
        // we only support security groups from the same endpoint for the same request
        if (endpointLinks.size() != 1) {
            throw new IllegalArgumentException("All security groups must belong to the same endpoint.");
        }
        if (endpointLinks.iterator().next() == null) {
            throw new IllegalArgumentException("All security groups must have endpoint link set.");
        }
        return null;
    });
}
Also used : LINK(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.LINK) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) Map(java.util.Map) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) URI(java.net.URI) AssertUtil(com.vmware.photon.controller.model.util.AssertUtil) FIXED_ITEM_NAME(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.FIXED_ITEM_NAME) Operation(com.vmware.xenon.common.Operation) NicSecurityGroupsRequest(com.vmware.photon.controller.model.adapterapi.NicSecurityGroupsRequest) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Set(java.util.Set) OperationRequestType(com.vmware.photon.controller.model.adapterapi.NicSecurityGroupsRequest.OperationRequestType) Collectors(java.util.stream.Collectors) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) NicSecurityGroupsTaskState(com.vmware.photon.controller.model.tasks.NicSecurityGroupsTaskService.NicSecurityGroupsTaskState) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) REQUIRED(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.REQUIRED) EXPAND(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.EXPAND) TaskService(com.vmware.xenon.services.common.TaskService) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) QueryTask(com.vmware.xenon.services.common.QueryTask) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)

Aggregations

UriPaths (com.vmware.photon.controller.model.UriPaths)1 NicSecurityGroupsRequest (com.vmware.photon.controller.model.adapterapi.NicSecurityGroupsRequest)1 OperationRequestType (com.vmware.photon.controller.model.adapterapi.NicSecurityGroupsRequest.OperationRequestType)1 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)1 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)1 NicSecurityGroupsTaskState (com.vmware.photon.controller.model.tasks.NicSecurityGroupsTaskService.NicSecurityGroupsTaskState)1 AssertUtil (com.vmware.photon.controller.model.util.AssertUtil)1 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1 Operation (com.vmware.xenon.common.Operation)1 ServiceDocument (com.vmware.xenon.common.ServiceDocument)1 EXPAND (com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.EXPAND)1 FIXED_ITEM_NAME (com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.FIXED_ITEM_NAME)1 PropertyUsageOption (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption)1 LINK (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.LINK)1 OPTIONAL (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL)1 REQUIRED (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.REQUIRED)1 TaskState (com.vmware.xenon.common.TaskState)1 UriUtils (com.vmware.xenon.common.UriUtils)1 Utils (com.vmware.xenon.common.Utils)1