use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class TestVSphereLinkedCloneProvisionTask method findImage.
private String findImage() {
QueryTask.Query q = QueryTask.Query.Builder.create().addKindFieldClause(ImageService.ImageState.class).addFieldClause(ImageService.ImageState.FIELD_NAME_NAME, "*" + this.libraryItemName, QueryTask.QueryTerm.MatchType.WILDCARD).build();
QueryTask task = QueryTask.Builder.createDirectTask().setQuery(q).build();
Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
Operation result = this.host.waitForResponse(op);
try {
return result.getBody(QueryTask.class).results.documentLinks.get(0);
} catch (Exception e) {
Assert.fail(e.getMessage());
return null;
}
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class ServerX509TrustManager method certificateChanged.
private void certificateChanged(Operation operation) {
Utils.log(getClass(), getClass().getName(), Level.WARNING, "process certificate changed for operation %s", operation.toLogString());
QueryTask queryTask = operation.getBody(QueryTask.class);
if (queryTask.results != null && queryTask.results.documentLinks != null && !queryTask.results.documentLinks.isEmpty()) {
queryTask.results.documents.values().forEach(doc -> {
SslTrustCertificateState cert = Utils.fromJson(doc, SslTrustCertificateState.class);
if (Action.DELETE.toString().equals(cert.documentUpdateAction)) {
deleteCertificate(cert.getAlias());
} else {
registerCertificate(cert);
}
});
} else {
Utils.log(getClass(), getClass().getName(), Level.WARNING, "No document links for operation %s", operation.toLogString());
}
operation.complete();
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class SslTrustCertificateServiceUtils method getQueryTask.
private static QueryTask getQueryTask() {
Query computeQuery = Query.Builder.create().addKindFieldClause(SslTrustCertificateState.class).build();
QueryTask task = QueryTask.Builder.create().addOption(QueryOption.CONTINUOUS).addOption(QueryOption.EXPAND_CONTENT).setQuery(computeQuery).build();
task.documentSelfLink = QUERY_TASK_SELF_LINK_PREFIX;
task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(TimeUnit.DAYS.toMicros(QUERY_TASK_EXPIRATION_DAYS));
return task;
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class ResourceUtilsTest method testExpandTags.
@Test
public void testExpandTags() throws Throwable {
TagState tag1 = new TagState();
tag1.key = "A";
tag1.value = "1";
tag1 = postServiceSynchronously(TagService.FACTORY_LINK, tag1, TagState.class);
TagState tag2 = new TagState();
tag2.key = "A";
tag2.value = "2";
tag2 = postServiceSynchronously(TagService.FACTORY_LINK, tag2, TagState.class);
TagState tag3 = new TagState();
tag3.key = "A";
tag3.value = "3";
tag3 = postServiceSynchronously(TagService.FACTORY_LINK, tag3, TagState.class);
// validate expansion on POST
ComputeState compute = new ComputeState();
compute.descriptionLink = "cdLink";
compute.tagLinks = new HashSet<>();
compute.tagLinks.add(tag1.documentSelfLink);
compute.tagLinks.add(tag2.documentSelfLink);
compute = postServiceSynchronously(ComputeService.FACTORY_LINK, compute, ComputeState.class);
Collection<String> tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
assertEquals(2, tags.size());
assertTrue(tags.containsAll(Arrays.asList("A\n1", "A\n2")));
// validate tags cannot be modified directly
compute.expandedTags.remove(1);
assertEquals(1, compute.expandedTags.size());
putServiceSynchronously(compute.documentSelfLink, compute);
compute = getServiceSynchronously(compute.documentSelfLink, ComputeState.class);
tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
assertEquals(2, tags.size());
assertTrue(tags.containsAll(Arrays.asList("A\n1", "A\n2")));
// validate expansion on PUT
compute.tagLinks.remove(tag2.documentSelfLink);
compute.tagLinks.add(tag3.documentSelfLink);
putServiceSynchronously(compute.documentSelfLink, compute);
compute = getServiceSynchronously(compute.documentSelfLink, ComputeState.class);
tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
assertEquals(2, tags.size());
assertTrue(tags.containsAll(Arrays.asList("A\n1", "A\n3")));
// validate expansion on PATCH
ComputeState patchState = new ComputeState();
patchState.tagLinks = new HashSet<>();
patchState.tagLinks.add(tag2.documentSelfLink);
compute = patchServiceSynchronously(compute.documentSelfLink, patchState, ComputeState.class);
tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
assertEquals(3, tags.size());
assertTrue(tags.containsAll(Arrays.asList("A\n1", "A\n2", "A\n3")));
// validate expansion through custom PATCH body
Map<String, Collection<Object>> itemsToRemove = new HashMap<>();
itemsToRemove.put(ResourceState.FIELD_NAME_TAG_LINKS, Arrays.asList(tag2.documentSelfLink, tag3.documentSelfLink));
patchServiceSynchronously(compute.documentSelfLink, ServiceStateCollectionUpdateRequest.create(null, itemsToRemove));
compute = getServiceSynchronously(compute.documentSelfLink, ComputeState.class);
tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
assertEquals(1, tags.size());
assertTrue(tags.containsAll(Arrays.asList("A\n1")));
// validate query (case-insensitive) (Note: only 1 tag can be found with Xenon 1.6.1)
Query tagQuery = Query.Builder.create().addFieldClause(TagInfo.COMPOSITE_FIELD_NAME_TAG, "a*", MatchType.WILDCARD).build();
QueryTask tagQueryTask = QueryTask.Builder.createDirectTask().setQuery(tagQuery).addOption(QueryOption.EXPAND_CONTENT).build();
tagQueryTask = postServiceSynchronously(ServiceUriPaths.CORE_LOCAL_QUERY_TASKS, tagQueryTask, QueryTask.class);
assertEquals(1, tagQueryTask.results.documentLinks.size());
assertEquals(1, tagQueryTask.results.documents.size());
assertEquals(compute.documentSelfLink, tagQueryTask.results.documentLinks.get(0));
ComputeState foundCompute = Utils.fromJson(tagQueryTask.results.documents.values().iterator().next(), ComputeState.class);
assertEquals(1, foundCompute.expandedTags.size());
assertEquals("A\n1", foundCompute.expandedTags.get(0).tag);
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class BaseModelTest method createDirectQueryTask.
public QueryTask createDirectQueryTask(String kind, String propertyName, String propertyValue) {
QueryTask q = new QueryTask();
q.querySpec = new QueryTask.QuerySpecification();
q.taskInfo.isDirect = true;
QueryTask.Query kindClause = new QueryTask.Query().setTermPropertyName(ServiceDocument.FIELD_NAME_KIND).setTermMatchValue(kind);
kindClause.occurance = QueryTask.Query.Occurance.MUST_OCCUR;
q.querySpec.query.addBooleanClause(kindClause);
QueryTask.Query customPropClause = new QueryTask.Query().setTermPropertyName(propertyName).setTermMatchValue(propertyValue);
customPropClause.occurance = QueryTask.Query.Occurance.MUST_OCCUR;
q.querySpec.query.addBooleanClause(customPropClause);
return q;
}
Aggregations