Search in sources :

Example 41 with ServiceDocumentQueryResult

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

the class TestAzureImageEnumerationTask method testPublicImageEnumeration_delete.

/**
 * Validate that during enum only images of this 'endpointType' are deleted.
 */
@Test
public void testPublicImageEnumeration_delete() throws Throwable {
    Assume.assumeFalse(this.isMock);
    setImagesLoadMode(ImagesLoadMode.STANDARD);
    try {
        // Those images should not be touched by this image enum. {{
        // 
        // Pre-create public and private image in different end-point
        EndpointState vSphereEndpointState = createEndpointState(EndpointType.vsphere);
        ImageState publicImageState_diffEP = createImageState(vSphereEndpointState, true, PUBLIC);
        ImageState privateImageState_diffEP = createImageState(vSphereEndpointState, true, PRIVATE);
        // Pre-create public and private image in same end-point but different region
        ImageState publicImageState_diffRegion = createImageState(this.endpointState, false, PUBLIC);
        ImageState privateImageState_diffRegion = createImageState(this.endpointState, false, PRIVATE);
        // }}
        // Create one stale image that should be deleted by this enumeration
        ImageState staleImageState = createImageState(this.endpointState, true, PUBLIC);
        // Validate 5 image states are preCREATED: 1 stale and 2 vSphere and 2 diff region
        final int preCreatedCount = 1 + 2 + 2;
        queryDocumentsAndAssertExpectedCount(getHost(), preCreatedCount, ImageService.FACTORY_LINK, EXACT_COUNT);
        // Under TESTING
        kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_SINGLE_IMAGE_FILTER);
        // Validate 1 image state is CREATED and the 2 vSphere and 2 diff region are UNtouched
        // plus 1 because we are not deleting the
        final int postEnumCount = 1 + 2 + 2 + 1;
        // resource, only disassociating it.
        ServiceDocumentQueryResult imagesAfterEnum = queryDocumentsAndAssertExpectedCount(getHost(), postEnumCount, ImageService.FACTORY_LINK, EXACT_COUNT);
        // Validate 1 stale image state is DISASSOCIATED
        ImageState staleImage = Utils.fromJson(imagesAfterEnum.documents.get(staleImageState.documentSelfLink), ImageState.class);
        Assert.assertTrue("Dummy image should have been disassociated.", staleImage.endpointLinks.isEmpty());
        // Validate vSphere images are untouched
        Assert.assertTrue("Private images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(privateImageState_diffEP.documentSelfLink));
        Assert.assertTrue("Public images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(publicImageState_diffEP.documentSelfLink));
        Assert.assertTrue("Private images from same endpoints but different region should not have been deleted.", imagesAfterEnum.documentLinks.contains(privateImageState_diffRegion.documentSelfLink));
        Assert.assertTrue("Public images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(publicImageState_diffRegion.documentSelfLink));
    } finally {
        setImagesLoadMode(ImagesLoadMode.ALL);
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 42 with ServiceDocumentQueryResult

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

the class AzureSubscriptionEndpointsEnumerationServiceTest method testAddSameAzureSubscriptions.

private void testAddSameAzureSubscriptions() throws Throwable {
    // Request for creating computes for existing Azure Subscriptions
    AzureSubscription subscription1 = getAzureSubscription(SUBSCRIPTION_ID_1, ACCOUNT_ID_1);
    AzureSubscription subscription2 = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_ID_2);
    Collection<AzureSubscription> subscriptions = new ArrayList<>();
    subscriptions.add(subscription1);
    subscriptions.add(subscription2);
    createAzureEndpointsForSubscriptions(subscriptions);
    // Query the Endpoints to assert
    ServiceDocumentQueryResult result = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    Assert.assertEquals(3, result.documents.size());
}
Also used : ArrayList(java.util.ArrayList) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription)

Example 43 with ServiceDocumentQueryResult

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

the class AzureSubscriptionEndpointsEnumerationServiceTest method testAddFirstAzureSubscription.

private void testAddFirstAzureSubscription() throws Throwable {
    // Request for creating computes for 1 Azure Subscriptions
    AzureSubscription subscription = getAzureSubscription(SUBSCRIPTION_ID_1, ACCOUNT_ID_1);
    createAzureEndpointsForSubscriptions(Collections.singletonList(subscription));
    // Query the Endpoints to assert
    ServiceDocumentQueryResult result = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    Assert.assertEquals(2, result.documents.size());
    // Assert the created Endpoint and other resources
    result.documents.remove(this.endpointLink);
    EndpointState endpointStateCreated = Utils.fromJson(result.documents.values().iterator().next(), EndpointState.class);
    assertCreatedEndpoint(endpointStateCreated, SUBSCRIPTION_ID_1);
    this.createdEndpointLinks.add(endpointStateCreated.documentSelfLink);
    // Assert the root compute under the endpoint
    ComputeState computeStateCreated = getServiceSynchronously(endpointStateCreated.computeLink, ComputeState.class);
    assertCreatedComputeState(computeStateCreated, SUBSCRIPTION_ID_1, ACCOUNT_ID_1);
    // Assert the partial AuthCredentialsState
    AuthCredentialsServiceState authCreated = getServiceSynchronously(endpointStateCreated.authCredentialsLink, AuthCredentialsServiceState.class);
    assertAuthCredentialState(authCreated, SUBSCRIPTION_ID_1);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription)

Example 44 with ServiceDocumentQueryResult

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

the class TestAzureCostStatsService method verifyPersistedStats.

private void verifyPersistedStats(EndpointAllocationTaskService.EndpointAllocationTaskState completeState, String metric, int expectedCount) {
    this.host.waitFor("Timeout waiting for stats", () -> {
        QueryTask.QuerySpecification querySpec = new QueryTask.QuerySpecification();
        querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetricsService.ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, UriUtils.getLastPathSegment(completeState.endpointState.computeLink)), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(buildCompositeFieldName(ResourceMetricsService.ResourceMetrics.FIELD_NAME_ENTRIES, metric), createDoubleRange(Double.MIN_VALUE, Double.MAX_VALUE, true, true)).build();
        querySpec.options.add(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT);
        ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(querySpec, expectedCount, expectedCount);
        boolean statsCollected = true;
        for (Object metrics : result.documents.values()) {
            ResourceMetricsService.ResourceMetrics rawMetrics = Utils.fromJson(metrics, ResourceMetricsService.ResourceMetrics.class);
            Double rawMetric = rawMetrics.entries.get(metric);
            if (rawMetric != null) {
                continue;
            }
            statsCollected = false;
        }
        return statsCollected;
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 45 with ServiceDocumentQueryResult

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

the class TestGCPStatsCollection method testStatsCollection.

/**
 * The main flow of the test case. It will first run enumeration. After that, instance level
 * stats collection is done on the test VM, whose instance ID is specified as a constant.
 * Then, project level stats collection is done on the project to which the test VM belongs.
 * @throws Throwable
 */
@Test
public void testStatsCollection() throws Throwable {
    if (this.isMock) {
        this.host.waitFor("Error waiting for stats", () -> {
            try {
                issueStatsRequest(this.computeHost.documentSelfLink);
                return true;
            } catch (Throwable t) {
                return false;
            }
        });
        return;
    }
    // Run enumeration
    runEnumeration();
    ServiceDocumentQueryResult result = ProvisioningUtils.queryComputeInstances(host, this.initialNumberOfVms);
    for (Entry<String, Object> key : result.documents.entrySet()) {
        ComputeState document = Utils.fromJson(key.getValue(), ComputeState.class);
        if (document.id.equals(this.instanceID)) {
            this.enumeratedComputeLink = document.documentSelfLink;
            this.enumeratedComputeParentLink = document.parentLink;
            break;
        }
    }
    // Run VM level stats collection
    host.log(Level.INFO, "Retrieveing VM level stats...");
    this.host.waitFor("Error waiting for stats", () -> {
        try {
            issueStatsRequest(this.enumeratedComputeLink);
            return true;
        } catch (Throwable t) {
            return false;
        }
    });
    // Run project level stats collection
    host.log(Level.INFO, "Retrieveing host level stats...");
    this.host.waitFor("Error waiting for stats", () -> {
        try {
            issueStatsRequest(this.enumeratedComputeParentLink);
            return true;
        } catch (Throwable t) {
            return false;
        }
    });
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

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