use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class AWSEnumerationAdapterService method handlePatch.
@Override
public void handlePatch(Operation op) {
setOperationHandlerInvokeTimeStat(op);
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
op.complete();
ComputeEnumerateResourceRequest request = op.getBody(ComputeEnumerateResourceRequest.class);
AdapterUtils.validateEnumRequest(request);
EnumerationContext context = new EnumerationContext(this, request, op);
if (request.isMockRequest) {
// patch status to parent task
context.taskManager.finishTask();
return;
}
context.populateBaseContext(BaseAdapterStage.PARENTDESC).whenComplete((ignoreCtx, t) -> {
// NOTE: In case of error 'ignoreCtx' is null so use passed context!
if (t != null) {
context.error = t;
context.stage = AWSEnumerationStages.ERROR;
}
handleEnumerationRequest(context);
});
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class AzureEnumerationAdapterService method handlePatch.
@Override
public void handlePatch(Operation op) {
setOperationHandlerInvokeTimeStat(op);
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
ComputeEnumerateResourceRequest request = op.getBody(ComputeEnumerateResourceRequest.class);
try {
AdapterUtils.validateEnumRequest(request);
op.complete();
} catch (Exception e) {
op.fail(e);
}
EnumerationContext context = new EnumerationContext(this, request, op);
if (request.isMockRequest) {
// patch status to parent task
context.taskManager.finishTask();
return;
}
context.populateBaseContext(BaseAdapterStage.PARENTDESC).whenComplete((ignoreCtx, t) -> {
// NOTE: In case of error 'ignoreCtx' is null so use passed context!
if (t != null) {
context.error = t;
context.stage = AzureEnumerationStages.ERROR;
}
handleEnumerationRequest(context);
});
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class ResourceEnumerationTaskService method sendEnumRequest.
private void sendEnumRequest(Operation start, ResourceEnumerationTaskState state) {
ComputeEnumerateResourceRequest req = new ComputeEnumerateResourceRequest();
req.resourcePoolLink = state.resourcePoolLink;
req.adapterManagementReference = state.adapterManagementReference;
req.resourceReference = createInventoryUri(this.getHost(), state.parentComputeLink);
req.endpointLinkReference = createInventoryUri(this.getHost(), state.endpointLink);
req.enumerationAction = state.enumerationAction;
req.taskReference = UriUtils.buildUri(getHost(), state.documentSelfLink);
req.isMockRequest = state.options.contains(TaskOption.IS_MOCK);
req.preserveMissing = state.options.contains(TaskOption.PRESERVE_MISSING_RESOUCES);
req.endpointLink = state.endpointLink;
req.deletedResourceExpirationMicros = getResourceExpirationMicros(state.expirationPolicy == null ? ResourceExpirationPolicy.EXPIRE_AFTER_ONE_MONTH : state.expirationPolicy);
// Patch the enumerate service URI from the CHD
CompletionHandler descriptionCompletion = (o, ex) -> {
if (ex != null) {
TaskUtils.sendFailurePatch(this, state, ex);
start.fail(ex);
return;
}
ComputeStateWithDescription csd = o.getBody(ComputeStateWithDescription.class);
if (csd.description.enumerationAdapterReference == null) {
// no enumeration adapter associated with this resource, just patch completion
sendSelfFinishedPatch(state);
return;
}
sendRequest(Operation.createPatch(csd.description.enumerationAdapterReference).setBody(req));
};
URI computeUri = UriUtils.extendUriWithQuery(UriUtils.buildUri(this.getHost(), state.parentComputeLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
sendRequest(Operation.createGet(computeUri).setCompletion(descriptionCompletion));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class AzureDiskEnumerationServiceTest method kickOffEnumeration.
private ComputeEnumerateResourceRequest kickOffEnumeration() throws Throwable {
ComputeEnumerateResourceRequest resourceRequest = new ComputeEnumerateResourceRequest();
resourceRequest.endpointLink = this.endpointState.documentSelfLink;
resourceRequest.enumerationAction = EnumerationAction.START;
resourceRequest.adapterManagementReference = UriUtils.buildUri(AzureEnumerationAdapterService.SELF_LINK);
resourceRequest.resourcePoolLink = this.resourcePool.documentSelfLink;
resourceRequest.resourceReference = UriUtils.buildUri(getHost(), "");
resourceRequest.isMockRequest = this.isMock;
return resourceRequest;
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VSphereIncrementalEnumerationService method garbageCollectUntouchedComputeResources.
private void garbageCollectUntouchedComputeResources(ComputeEnumerateResourceRequest request, Set<String> untouchedResources, TaskManager mgr) {
if (untouchedResources.isEmpty()) {
mgr.patchTask(TaskStage.FINISHED);
return;
}
if (!request.preserveMissing) {
// delete dependent resources without waiting for response
for (String resourceLink : untouchedResources) {
Operation.createDelete(PhotonModelUriUtils.createInventoryUri(getHost(), resourceLink)).sendWith(this);
}
mgr.patchTask(TaskStage.FINISHED);
return;
}
List<Operation> deleteOps = new ArrayList<>();
for (String resourceLink : untouchedResources) {
if (resourceLink.startsWith(ComputeService.FACTORY_LINK)) {
ResourceCleanRequest patch = new ResourceCleanRequest();
patch.resourceLink = resourceLink;
deleteOps.add(Operation.createPatch(this, VSphereUriPaths.RESOURCE_CLEANER).setBody(patch));
} else {
deleteOps.add(Operation.createDelete(PhotonModelUriUtils.createInventoryUri(getHost(), resourceLink)));
}
}
OperationJoin.create(deleteOps).setCompletion((os, es) -> mgr.patchTask(TaskStage.FINISHED)).sendWith(this);
}
Aggregations