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;
});
}
Aggregations