use of com.vmware.photon.controller.model.query.QueryUtils.QueryTop in project photon-model by vmware.
the class AzureSubscriptionEndpointsEnumerationService method fetchExistingSubscriptionEndpoints.
private void fetchExistingSubscriptionEndpoints(AzureSubscriptionEndpointsEnumerationContext enumerationContext, AzureSubscriptionEndpointComputeEnumerationStages nextStage) {
Query azureEndpointsQuery = createQueryForAzureSubscriptionEndpoints(enumerationContext);
// Use Top query with 10K max EndpointStates
QueryTop<EndpointState> querySubscriptionEndpoints = new QueryTop<>(getHost(), azureEndpointsQuery, EndpointState.class, enumerationContext.parent.tenantLinks);
querySubscriptionEndpoints.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
querySubscriptionEndpoints.queryDocuments(epState -> {
if (epState.endpointProperties != null && epState.endpointProperties.containsKey(EndpointConfigRequest.USER_LINK_KEY)) {
String subscriptionUuid = epState.endpointProperties.get(EndpointConfigRequest.USER_LINK_KEY);
enumerationContext.idToSubscription.remove(subscriptionUuid);
}
}).whenComplete((aVoid, t) -> {
if (t != null) {
getFailureConsumer(enumerationContext).accept(t);
return;
}
enumerationContext.stage = nextStage;
handleAzureCostComputeEnumerationRequest(enumerationContext);
});
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryTop in project photon-model by vmware.
the class AWSSecurityGroupEnumerationAdapterService method createResponse.
/**
* Having the enumerated SecurityGroup Ids, query the States and provide them in the response
*/
private DeferredResult<AWSSecurityGroupEnumerationResponse> createResponse(SecurityGroupEnumContext context) {
AWSSecurityGroupEnumerationResponse response = new AWSSecurityGroupEnumerationResponse();
if (context.enumExternalResourcesIds == null || context.enumExternalResourcesIds.isEmpty()) {
DeferredResult<AWSSecurityGroupEnumerationResponse> deferredResult = new DeferredResult<>();
deferredResult.complete(response);
return deferredResult;
}
Query.Builder findSecurityGroupStates = Builder.create().addKindFieldClause(SecurityGroupState.class).addFieldClause(ResourceState.FIELD_NAME_COMPUTE_HOST_LINK, context.request.parentCompute.documentSelfLink).addInClause(SecurityGroupState.FIELD_NAME_ID, context.enumExternalResourcesIds);
QueryTop<SecurityGroupState> querySecurityGroupStates = new QueryTop<>(context.service.getHost(), findSecurityGroupStates.build(), SecurityGroupState.class, context.request.parentCompute.tenantLinks).setMaxResultsLimit(context.enumExternalResourcesIds.size());
querySecurityGroupStates.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
return querySecurityGroupStates.queryDocuments(sgState -> response.securityGroupStates.put(sgState.id, sgState.documentSelfLink)).thenApply(aVoid -> response);
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryTop in project photon-model by vmware.
the class TestAzureImageEnumerationTask method testPrivateImageEnumeration_single.
/**
* That's the private image we are testing:
* {@link /resourceGroups/Images/providers/Microsoft.Compute/images/LinuxImageWithOsAndDataUnmanaged/overview}
*/
@Test
@Ignore("For now run the test manually. Will enable it once the image is created programatically, but not hardcoded")
public void testPrivateImageEnumeration_single() throws Throwable {
Assume.assumeFalse(this.isMock);
kickOffImageEnumeration(this.endpointState, PRIVATE, AZURE_ALL_IMAGES_FILTER);
// Validate at least 1 image state is CREATED
QueryTop<ImageState> queryAll = new QueryTop<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, this.endpointState.tenantLinks, this.endpointState.documentSelfLink);
List<ImageState> images = PhotonModelUtils.waitToComplete(queryAll.collectDocuments(Collectors.toList()));
Assert.assertTrue("Expected at least " + 1 + " private image, but found " + images.size(), images.size() >= 1);
ImageState image = images.stream().filter(imageState -> {
return imageState.name.equalsIgnoreCase(PRIVATE_IMAGE_NAME);
}).findFirst().orElse(null);
// Validate created image is correctly populated
Assert.assertNotNull("Private image with '" + PRIVATE_IMAGE_NAME + "' name must have been enumerated.", image);
Assert.assertNull("Private image must NOT have endpointType set.", image.endpointType);
Assert.assertEquals("Private image must have endpointLink set.", this.endpointState.documentSelfLink, image.endpointLink);
Assert.assertNotNull("Private image must have endpointLinks set.", image.endpointLinks);
Assert.assertTrue("Private image must have endpointLinks set.", image.endpointLinks.contains(this.endpointState.documentSelfLink));
Assert.assertEquals("Private image must have tenantLinks set.", this.endpointState.tenantLinks, image.tenantLinks);
Assert.assertTrue("Image.id is invalid", image.id.endsWith(PRIVATE_IMAGE_NAME));
Assert.assertEquals("Image.name is invalid", PRIVATE_IMAGE_NAME, image.name);
Assert.assertEquals("Image.description is invalid", PRIVATE_IMAGE_NAME, image.description);
Assert.assertNotNull("Image.diskConfigs", image.diskConfigs);
Assert.assertEquals("Image.diskConfigs.size", 2, image.diskConfigs.size());
{
DiskConfiguration osDiskConfig = image.diskConfigs.get(0);
Assert.assertNotNull("Image.osDiskConfig.properties", osDiskConfig.properties);
Assert.assertNotNull("Image.osDiskConfig.properties.blobUri", osDiskConfig.properties.get(AzureConstants.AZURE_DISK_BLOB_URI));
Assert.assertNull("Image.osDiskConfig.properties.lun", osDiskConfig.properties.get(AzureConstants.AZURE_DISK_LUN));
}
{
DiskConfiguration dataDiskConfig = image.diskConfigs.get(1);
Assert.assertNotNull("Image.dataDiskConfig.properties", dataDiskConfig.properties);
Assert.assertNotNull("Image.dataDiskConfig.properties.blobUri", dataDiskConfig.properties.get(AzureConstants.AZURE_DISK_BLOB_URI));
Assert.assertEquals("Image.dataDiskConfig.properties.lun", "0", dataDiskConfig.properties.get(AzureConstants.AZURE_DISK_LUN));
}
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryTop in project photon-model by vmware.
the class EndpointAdapterUtils method getEndpointLinks.
private static DeferredResult<List<String>> getEndpointLinks(ServiceHost host, Query endpointQuery, List<String> credentialsLinks, String endpointType, List<String> queryTaskTenantLinks) {
if (credentialsLinks.isEmpty()) {
return DeferredResult.completed(Collections.emptyList());
}
Query.Builder qBuilder = Builder.create().addKindFieldClause(EndpointState.class).addFieldClause(EndpointState.FIELD_NAME_ENDPOINT_TYPE, endpointType).addInClause(EndpointState.FIELD_NAME_AUTH_CREDENTIALS_LINK, credentialsLinks);
if (endpointQuery != null) {
qBuilder.addClause(endpointQuery);
}
QueryTop<EndpointState> queryEndpoints = new QueryTop<>(host, qBuilder.build(), EndpointState.class, queryTaskTenantLinks).setQueryTaskTenantLinks(queryTaskTenantLinks).setMaxResultsLimit(1);
queryEndpoints.setClusterType(INVENTORY_SERVICE);
return queryEndpoints.collectLinks(Collectors.toList());
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryTop in project photon-model by vmware.
the class ResourceOperationUtils method lookUp.
/**
* Lookup for {@link ResourceOperationSpec}s by given {@code endpointType},
* {@code resourceType} and optionally {@code operation}
* <p>
* If operation not specified then return all resource operation specs for the given
* {@code endpointType} and {@code resourceType}
* @param host
* host to use to create operation
* @param refererURI
* the referer to use when send the operation
* @param endpointType
* the resource's endpoint type
* @param resourceType
* the resource type
* @param operation
* optional operation id argument
* @param queryTaskTenantLinks
* tenant links used for the QueryTask
* @param authorizationContext
* authorization context that will be used for operations (if set to null the context
* will not be changed)
* @return
*/
private static DeferredResult<List<ResourceOperationSpec>> lookUp(ServiceHost host, URI refererURI, String endpointType, ResourceType resourceType, String operation, List<String> queryTaskTenantLinks, AuthorizationContext authorizationContext) {
Query.Builder builder = Query.Builder.create().addKindFieldClause(ResourceOperationSpec.class).addFieldClause(ResourceOperationSpec.FIELD_NAME_ENDPOINT_TYPE, endpointType).addFieldClause(ResourceOperationSpec.FIELD_NAME_RESOURCE_TYPE, resourceType);
if (operation != null) {
builder.addFieldClause(ResourceOperationSpec.FIELD_NAME_OPERATION, operation);
}
Query query = builder.build();
QueryTop<ResourceOperationSpec> top = new QueryTop<>(host, query, ResourceOperationSpec.class, null).setQueryTaskTenantLinks(queryTaskTenantLinks).setAuthorizationContext(authorizationContext);
if (operation != null) {
// resource operation spec id and selfLink are built from the endpoint type, resource
// type and operation id, so the query result is guaranteed to return at most 1 element
top.setMaxResultsLimit(1);
}
top.setReferer(refererURI);
return top.collectDocuments(Collectors.toList());
}
Aggregations