use of com.vmware.xenon.common.Service in project photon-model by vmware.
the class ResourceRemovalTaskService method sendInstanceDelete.
private void sendInstanceDelete(String resourceLink, String subTaskLink, Operation o, ResourceRemovalTaskState currentState) {
ComputeStateWithDescription chd = o.getBody(ComputeStateWithDescription.class);
if (chd.description.instanceAdapterReference != null) {
ComputeInstanceRequest deleteReq = new ComputeInstanceRequest();
deleteReq.resourceReference = createInventoryUri(this.getHost(), resourceLink);
deleteReq.taskReference = UriUtils.buildUri(getHost(), subTaskLink);
deleteReq.requestType = ComputeInstanceRequest.InstanceRequestType.DELETE;
deleteReq.isMockRequest = currentState.isMockRequest;
sendRequest(Operation.createPatch(chd.description.instanceAdapterReference).setBody(deleteReq).setCompletion((deleteOp, e) -> {
if (e != null) {
logWarning(() -> String.format("PATCH to instance service %s, failed: %s", deleteOp.getUri(), e.toString()));
ResourceOperationResponse fail = ResourceOperationResponse.fail(resourceLink, e);
sendPatch(subTaskLink, fail);
return;
}
}));
} else {
logWarning(() -> String.format("Compute instance %s doesn't not have configured" + " instanceAdapter. Only local resource will be deleted.", resourceLink));
ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.finish(resourceLink);
sendPatch(subTaskLink, subTaskPatchBody);
}
}
use of com.vmware.xenon.common.Service in project photon-model by vmware.
the class BaseTestCase method verifyService.
protected void verifyService(URI factoryUri, FactoryService factoryInstance, Class<? extends ServiceDocument> serviceDocumentType, TestServiceDocumentInitialization serviceDocumentInit, TestServiceDocumentAssertion assertion) throws Throwable {
int childCount = 1;
TestContext ctx = testCreate(childCount);
String prefix = "example-";
URI[] childURIs = new URI[childCount];
for (int i = 0; i < childCount; i++) {
ServiceDocument serviceDocument = serviceDocumentInit.create(prefix, i);
final int finalI = i;
// create a ServiceDocument instance.
Operation createPost = createForcedPost(factoryUri).setBody(serviceDocument).setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ServiceDocument rsp = o.getBody(serviceDocumentType);
childURIs[finalI] = UriUtils.buildUri(this.host, rsp.documentSelfLink);
ctx.completeIteration();
});
this.host.send(createPost);
}
try {
// verify factory and service instance wiring.
factoryInstance.setHost(this.host);
Service serviceInstance = factoryInstance.createServiceInstance();
serviceInstance.setHost(this.host);
assertNotNull(serviceInstance);
ctx.await();
// do GET on all child URIs
Map<URI, ? extends ServiceDocument> childStates = this.host.getServiceState(null, serviceDocumentType, childURIs);
for (ServiceDocument s : childStates.values()) {
assertion.assertState(prefix, s);
}
// verify template GET works on factory
ServiceDocumentQueryResult templateResult = this.host.getServiceState(null, ServiceDocumentQueryResult.class, UriUtils.extendUri(factoryUri, ServiceHost.SERVICE_URI_SUFFIX_TEMPLATE));
assertTrue(templateResult.documentLinks.size() == templateResult.documents.size());
ServiceDocument childTemplate = Utils.fromJson(templateResult.documents.get(templateResult.documentLinks.iterator().next()), serviceDocumentType);
assertTrue(childTemplate.documentDescription != null);
assertTrue(childTemplate.documentDescription.propertyDescriptions != null && childTemplate.documentDescription.propertyDescriptions.size() > 0);
} catch (Throwable t) {
if (t instanceof RuntimeException) {
throw t;
}
throw new RuntimeException(t);
}
}
Aggregations