use of com.vmware.photon.controller.model.resources.ResourceState in project photon-model by vmware.
the class EndpointEnumerationProcess method createUpdateLocalResourceState.
protected DeferredResult<Operation> createUpdateLocalResourceState(LocalStateHolder localStateHolder) {
final ResourceState localState = localStateHolder.localState;
if (localState == this.SKIP) {
return DeferredResult.completed(null);
}
final LOCAL_STATE currentState = this.localResourceStates.get(localState.id);
// POST or PATCH local state
final Operation localStateOp;
if (currentState == null) {
if (localState.regionId == null) {
// By default populate REGION_ID, if not already set by descendant
localState.regionId = getEndpointRegion();
}
if (isApplyInfraFields()) {
// By default populate TENANT_LINKS
localState.tenantLinks = this.endpointState.tenantLinks;
// By default populate ENDPOINT_LINK
setEndpointLink(localState, this.endpointState.documentSelfLink);
updateEndpointLinks(localState, this.endpointState.documentSelfLink);
}
localState.computeHostLink = this.computeHostLink;
localStateOp = Operation.createPost(createInventoryUri(this.service.getHost(), this.localStateServiceFactoryLink));
} else {
// Update case
if (isApplyInfraFields()) {
setEndpointLink(localState, this.endpointState.documentSelfLink);
// update the endpointLinks
updateEndpointLinks(localState, this.endpointState.documentSelfLink);
}
localStateOp = Operation.createPatch(createInventoryUri(this.service.getHost(), currentState.documentSelfLink));
}
DeferredResult<Set<String>> tagLinksDR = TagsUtil.createOrUpdateTagStates(this.service, localState, currentState, localStateHolder.remoteTags, localStateHolder.internalTagLinks);
return tagLinksDR.thenApply(tagLinks -> {
localState.tagLinks = tagLinks;
localStateOp.setBodyNoCloning(localState);
return localStateOp;
}).thenCompose(this.service::sendWithDeferredResult).whenComplete((ignoreOp, exc) -> {
String msg = "%s local %s(id=%s) to match remote resources";
if (exc != null) {
this.service.logWarning(() -> String.format(msg + ": FAILED with %s", localStateOp.getAction(), localState.getClass().getSimpleName(), localState.id, Utils.toString(exc)));
} else {
this.service.log(Level.FINEST, () -> String.format(msg + ": SUCCESS", localStateOp.getAction(), localState.getClass().getSimpleName(), localState.id));
}
});
}
use of com.vmware.photon.controller.model.resources.ResourceState in project photon-model by vmware.
the class AdapterUtils method getDeletionState.
public static ResourceState getDeletionState(long documentExpirationMicros) {
ResourceState resourceState = new ResourceState();
resourceState.documentExpirationTimeMicros = documentExpirationMicros;
return resourceState;
}
use of com.vmware.photon.controller.model.resources.ResourceState in project photon-model by vmware.
the class TestAWSSetupUtils method verifyRemovalOfResourceState.
/**
* Validates the documents of ResourceState have been removed.
*
* @throws Throwable
*/
public static void verifyRemovalOfResourceState(VerificationHost host, List<String> resourceStateLinks) throws Throwable {
for (String resourceLink : resourceStateLinks) {
ResourceState resourceState = getResourceState(host, resourceLink);
assertNotNull(resourceState);
// make sure the document has been removed.
assertNull(resourceState.documentSelfLink);
}
}
use of com.vmware.photon.controller.model.resources.ResourceState in project photon-model by vmware.
the class AzureTestUtil method verifyRemovalOfResourceState.
/**
* Validate the deletion of documents of ResourceState.
*/
public static void verifyRemovalOfResourceState(VerificationHost host, List<String> resourceStateLinks) throws Throwable {
for (String resourceLink : resourceStateLinks) {
ResourceState resourceState = getResourceState(host, resourceLink);
assertNotNull(resourceState);
// make sure the document has been removed.
assertNull(resourceState.documentSelfLink);
}
}
use of com.vmware.photon.controller.model.resources.ResourceState in project photon-model by vmware.
the class TestAzureLongRunningEnumeration method verifyResourceDuplicates.
/**
* Verify documents for duplicates after multiple enumerations.
*/
private void verifyResourceDuplicates() {
int total_dup_resource_count = 0;
for (Class resource : resourcesList) {
QueryTask.Query.Builder qBuilder = QueryTask.Query.Builder.create().addKindFieldClause(resource).addFieldClause("endpointLinks.item", this.endpointState.documentSelfLink, QueryTask.QueryTerm.MatchType.TERM, QueryTask.Query.Occurance.MUST_OCCUR);
if (resource.getSimpleName().equals("ComputeState")) {
qBuilder.addFieldClause("type", "VM_GUEST", QueryTask.QueryTerm.MatchType.TERM, QueryTask.Query.Occurance.MUST_OCCUR);
}
QueryTask resourceQt = QueryTask.Builder.createDirectTask().setQuery(qBuilder.build()).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).addOption(QueryTask.QuerySpecification.QueryOption.TOP_RESULTS).setResultLimit(10000).build();
Operation queryDocuments = QueryUtils.createQueryTaskOperation(this.host, resourceQt, ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE).setReferer(this.host.getUri());
Operation queryResponse = this.host.waitForResponse(queryDocuments);
Assert.assertTrue("Error retrieving enumerated documents", queryResponse.getStatusCode() == 200);
QueryTask qt = queryResponse.getBody(QueryTask.class);
Set<String> resourceIdSet = new HashSet<>();
if (qt.results != null && qt.results.documentLinks != null && qt.results.documentLinks.size() > 0) {
this.host.log("Number of %s docs: %d", resource.getSimpleName(), qt.results.documentLinks.size());
for (String resourceDocumentLink : qt.results.documentLinks) {
Object object = qt.results.documents.get(resourceDocumentLink);
ResourceState resourceState = Utils.fromJson(object, ResourceState.class);
String resourceId = resourceState.id;
if (!resourceIdSet.contains(resourceId)) {
resourceIdSet.add(resourceId);
} else {
this.host.log("duplicate %s id = %s, with state: ", resource.getSimpleName(), resourceId, Utils.toJsonHtml(resourceState));
total_dup_resource_count++;
}
}
}
}
assertEquals("Duplicate resources found: ", 0, total_dup_resource_count);
}
Aggregations