use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class TestAWSSetupUtils method getInternalTagsByType.
public static ServiceDocumentQueryResult getInternalTagsByType(VerificationHost host, String type) {
Query query = Query.Builder.create().addKindFieldClause(TagService.TagState.class).addFieldClause(TagService.TagState.FIELD_NAME_KEY, PhotonModelConstants.TAG_KEY_TYPE).addFieldClause(TagService.TagState.FIELD_NAME_VALUE, type).build();
Query externalQuery = new Query().setTermPropertyName(TagService.TagState.FIELD_NAME_EXTERNAL).setTermMatchValue(Boolean.FALSE.toString());
externalQuery.occurance = Query.Occurance.SHOULD_OCCUR;
Query originQuery = new Query().addBooleanClause(Query.Builder.create().addCollectionItemClause(TagService.TagState.FIELD_NAME_ORIGIN, DISCOVERED.toString(), Occurance.MUST_NOT_OCCUR).addCollectionItemClause(TagService.TagState.FIELD_NAME_ORIGIN, SYSTEM.toString(), Query.Occurance.SHOULD_OCCUR).addCollectionItemClause(TagService.TagState.FIELD_NAME_ORIGIN, USER_DEFINED.toString(), Query.Occurance.SHOULD_OCCUR).build()).setOccurance(Query.Occurance.SHOULD_OCCUR);
Query originOrExternalQuery = new Query().addBooleanClause(externalQuery).addBooleanClause(originQuery).setOccurance(Query.Occurance.MUST_OCCUR);
query.addBooleanClause(originOrExternalQuery);
QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query).addOption(QuerySpecification.QueryOption.EXPAND_CONTENT).addOption(QuerySpecification.QueryOption.TOP_RESULTS).setResultLimit(getQueryResultLimit()).build();
queryTask.documentSelfLink = UUID.randomUUID().toString();
host.createQueryTaskService(queryTask, false, true, queryTask, null);
ServiceDocumentQueryResult results = queryTask.results;
return results;
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class AzureTestUtil method assertResourceExists.
/**
* Assert that a resource with the provided name exist in the document store.
*
* @param factoryLink
* Factory link to the stateful service which states to check.
* @param name
* name of the resource to assert if exists.
* @param shouldExists
* whether to assert if a resource exists or not.
*/
public static void assertResourceExists(VerificationHost host, String factoryLink, String name, boolean shouldExists) {
ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, factoryLink));
boolean exists = false;
for (Object document : result.documents.values()) {
ResourceState state = Utils.fromJson(document, ResourceState.class);
if (name.equals(state.name)) {
exists = true;
break;
}
}
assertEquals("Expected: " + shouldExists + ", but was: " + exists, shouldExists, exists);
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class AzureTestUtil method assertDiskExist.
/**
* Assert that a managed / un-managed disk with the provided name exist in the document store.
*
* @param factoryLink
* Factory link to the stateful service which states to check.
* @param name
* name of the resource to assert if exists.
* @param shouldExists
* whether to assert if a resource exists or not.
*/
public static void assertDiskExist(VerificationHost host, String factoryLink, String name, boolean shouldExists) {
ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, factoryLink));
boolean exists = false;
for (Object document : result.documents.values()) {
DiskState diskState = Utils.fromJson(document, DiskState.class);
if (diskState.name.contains(name)) {
exists = true;
break;
}
}
assertEquals("Expected: " + shouldExists + ", but was: " + exists, shouldExists, exists);
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class AzureTestUtil method assertResourceDisassociated.
/**
* Assert that a resource with the provided name exist in the document store.
*
* @param factoryLink
* Factory link to the stateful service which states to check.
* @param name
* name of the resource to assert if exists.
* @param isDisassociated
* whether to assert if a resource exists or not.
*/
public static void assertResourceDisassociated(VerificationHost host, String factoryLink, String name, boolean isDisassociated) {
ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, factoryLink));
boolean disassociated = false;
for (Object document : result.documents.values()) {
// Read doc as ServiceDocument to access its 'documentKind'
ServiceDocument serviceDoc = Utils.fromJson(document, ServiceDocument.class);
Class<? extends ResourceState> resourceClass = ENDPOINT_LINK_EXPLICIT_SUPPORT.stream().filter(clazz -> serviceDoc.documentKind.equals(Utils.buildKind(clazz))).findFirst().orElse(null);
if (resourceClass != null) {
// Read doc as ResourceState to access its 'endpointLinks'
ResourceState resource = Utils.fromJson(document, resourceClass);
if (Objects.equals(name, resource.name) && resource.endpointLinks.isEmpty()) {
String endpointLink = PhotonModelUtils.getEndpointLink(resource);
if (endpointLink == null || endpointLink.isEmpty()) {
disassociated = true;
break;
}
}
}
}
assertEquals("isDisassociated", isDisassociated, disassociated);
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class LongRunEndToEndAzureStatsAggregation method runStatsCollectionAndAggregationLogNodeStatsPeriodically.
/**
* Periodically runs stats collection and aggregation and logs node stats.
*/
private void runStatsCollectionAndAggregationLogNodeStatsPeriodically() {
this.host.getScheduledExecutor().scheduleAtFixedRate(() -> {
try {
this.host.log(Level.INFO, "Running azure stats collection...");
// perform stats collection on given Azure endpoint.
resourceStatsCollection(this.host, this.isMock, computeHost.resourcePoolLink);
ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)));
this.host.log(Level.INFO, "Running azure stats aggregation...");
resourceStatsAggregation(this.host, computeHost.resourcePoolLink);
logNodeStats(this.host.getServiceStats(this.nodeStatsUri));
ServiceDocumentQueryResult aggrResult = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, ResourceMetricsService.FACTORY_LINK));
// check compute resource has stats generated for all the metric keys
checkInMemoryStatsPresent(res);
// check expiration time for aggregate metric documents
checkExpirationTime(aggrResult);
// check to verify appropriate resource metrics entries are present for compute resources.
verifyResourceMetricEntries(res);
// verify time bin metrics for every compute resource and endpoint estimated charges
verifyTimeBinMetrics(res);
} catch (Throwable e) {
this.host.log(Level.WARNING, "Error running stats aggregation in test" + e.getMessage());
}
}, 0, this.aggregationFrequencyInMinutes, TimeUnit.MINUTES);
}
Aggregations