use of com.vmware.xenon.common.Service in project photon-model by vmware.
the class BaseTestCase method createHost.
protected VerificationHost createHost() throws Throwable {
ServiceHost.Arguments args = new ServiceHost.Arguments();
// ask runtime to pick a random storage location
args.sandbox = null;
// ask runtime to pick a random port
args.port = 0;
Map<Class<? extends Service>, Class<? extends OperationProcessingChain>> chains = new HashMap<>();
customizeChains(chains);
VerificationHost h = VerificationHost.initialize(new CustomizationVerificationHost(chains), args);
h.setMaintenanceIntervalMicros(this.getMaintenanceIntervalMillis() * 1000);
h.setTimeoutSeconds(HOST_TIMEOUT_SECONDS);
h.setPeerSynchronizationEnabled(this.getPeerSynchronizationEnabled());
h.start();
return h;
}
use of com.vmware.xenon.common.Service in project photon-model by vmware.
the class ResourceRemovalTaskService method doInstanceDeletes.
private void doInstanceDeletes(ResourceRemovalTaskState currentState, QueryTask queryTask, String subTaskLink) {
// handle empty pages
if (queryTask.results.documentCount == 0) {
sendSelfPatch(currentState.taskInfo.stage, SubStage.DEALLOCATE_IP_ADDRESSES, s -> {
s.nextPageLink = null;
});
return;
}
if (subTaskLink == null) {
createSubTaskForDeleteCallbacks(currentState, queryTask, link -> doInstanceDeletes(currentState, queryTask, link));
return;
}
logFine(() -> String.format("Starting delete of %d compute resources using sub task %s", queryTask.results.documentLinks.size(), subTaskLink));
// a DELETE request to its associated instance service.
for (String resourceLink : queryTask.results.documentLinks) {
URI u = ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), resourceLink));
sendRequest(Operation.createGet(u).setCompletion((o, e) -> {
if (e != null) {
// we do not fail task if one delete failed ...
// send a FINISHED patch which is what a sub task
// would do. Since the
// current state
// is still at REMOVING_RESOURCES, we will just
// increment a counter
ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(resourceLink, e);
sendPatch(subTaskLink, subTaskPatchBody);
return;
}
sendInstanceDelete(resourceLink, subTaskLink, o, currentState);
}));
}
}
use of com.vmware.xenon.common.Service in project photon-model by vmware.
the class EndpointRemovalTaskService method doInstanceDelete.
/**
* Delete endpoint
*/
private void doInstanceDelete(EndpointRemovalTaskState currentState, SubStage next) {
EndpointState endpoint = currentState.endpoint;
Operation crdOp = Operation.createDelete(createInventoryUri(this.getHost(), endpoint.authCredentialsLink));
Operation epOp = Operation.createDelete(createInventoryUri(this.getHost(), endpoint.documentSelfLink));
// custom header identifier for endpoint service to validate before deleting endpoint
epOp.addRequestHeader(ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME, ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE);
OperationJoin.create(crdOp, epOp).setCompletion((ops, exc) -> {
if (exc != null) {
// failing to delete the endpoint itself is considered a critical error
Throwable endpointRemovalException = exc.get(epOp.getId());
if (endpointRemovalException != null) {
sendFailureSelfPatch(endpointRemovalException);
return;
}
// other removal exceptions are just warnings
logFine(() -> String.format("Failed delete some of the associated resources," + " reason %s", Utils.toString(exc)));
}
// Endpoint and AuthCredentials are deleted; mark the operation as complete
sendSelfPatch(TaskStage.STARTED, next);
}).sendWith(this);
}
use of com.vmware.xenon.common.Service 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.xenon.common.Service in project photon-model by vmware.
the class AdapterUtils method getServiceState.
/**
* Method will be responsible for getting the service state for the
* requested resource and invoke Consumer callback for success and
* failure
*/
public static void getServiceState(Service service, URI computeUri, String contentType, Consumer<Operation> success, Consumer<Throwable> failure) {
Operation getOp = Operation.createGet(computeUri);
if (contentType != null) {
getOp.setContentType(contentType);
}
service.sendRequest(getOp.setCompletion((o, e) -> {
if (e != null) {
failure.accept(e);
return;
}
success.accept(o);
}));
}
Aggregations