Search in sources :

Example 61 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class ProvisioningUtils method getVMCount.

public static int getVMCount(VerificationHost host, URI peerURI) throws Throwable {
    ServiceDocumentQueryResult res;
    res = host.getFactoryState(UriUtils.buildExpandLinksQueryUri(createServiceURI(host, peerURI, ComputeService.FACTORY_LINK)));
    return res.documents.size() - 1;
}
Also used : ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 62 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class ProvisioningUtils method queryComputeInstances.

public static ServiceDocumentQueryResult queryComputeInstances(VerificationHost host, URI peerURI, int desiredCount) throws Throwable {
    Date expiration = host.getTestExpiration();
    ServiceDocumentQueryResult res;
    do {
        res = host.getFactoryState(UriUtils.buildExpandLinksQueryUri(createServiceURI(host, peerURI, ComputeService.FACTORY_LINK)));
        if (res.documents.size() == desiredCount) {
            return res;
        }
    } while (new Date().before(expiration));
    throw new TimeoutException("Desired number of compute states not found. Expected " + desiredCount + ", found " + res.documents.size());
}
Also used : Date(java.util.Date) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) TimeoutException(java.util.concurrent.TimeoutException)

Example 63 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class ProvisioningUtils method queryDocumentsAndAssertExpectedCount.

public static ServiceDocumentQueryResult queryDocumentsAndAssertExpectedCount(VerificationHost host, URI peerURI, int desiredCount, String factoryLink, boolean exactCountFlag) throws Throwable {
    URI queryUri = UriUtils.buildExpandLinksQueryUri(createServiceURI(host, peerURI, factoryLink));
    // add limit, otherwise the query will not return if there are too many docs or versions
    queryUri = UriUtils.extendUriWithQuery(queryUri, UriUtils.URI_PARAM_ODATA_LIMIT, String.valueOf(desiredCount * 2));
    ServiceDocumentQueryResult res = host.getFactoryState(queryUri);
    if (exactCountFlag) {
        if (res.documents.size() == desiredCount) {
            return res;
        }
    } else {
        if (res.documents.size() >= desiredCount) {
            host.log(Level.INFO, "Documents count in %s is %s, expected at least %s", factoryLink, res.documents.size(), desiredCount);
            return res;
        }
    }
    throw new Exception("Desired number of documents not found in " + factoryLink + " factory states. Expected " + desiredCount + ", found " + res.documents.size());
}
Also used : URI(java.net.URI) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) TimeoutException(java.util.concurrent.TimeoutException)

Example 64 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class ProvisioningUtils method queryDiskInstances.

public static ServiceDocumentQueryResult queryDiskInstances(VerificationHost host, URI peerURI, int desiredCount) throws Throwable {
    Date expiration = host.getTestExpiration();
    ServiceDocumentQueryResult res;
    do {
        res = host.getFactoryState(UriUtils.buildExpandLinksQueryUri(createServiceURI(host, peerURI, DiskService.FACTORY_LINK)));
        if (res.documents.size() == desiredCount) {
            return res;
        }
    } while (new Date().before(expiration));
    throw new TimeoutException("Desired number of disk states not found. Expected " + desiredCount + ", found " + res.documents.size());
}
Also used : Date(java.util.Date) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)64 Test (org.junit.Test)26 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)25 ArrayList (java.util.ArrayList)15 QueryTask (com.vmware.xenon.services.common.QueryTask)14 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)13 Operation (com.vmware.xenon.common.Operation)13 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)12 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)12 HashMap (java.util.HashMap)12 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)11 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)11 URI (java.net.URI)11 Map (java.util.Map)11 List (java.util.List)10 StatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState)8 UriUtils (com.vmware.xenon.common.UriUtils)8 Utils (com.vmware.xenon.common.Utils)8 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)7 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)7