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