use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class VSphereVMContextTest method beforeTest.
@Before
public void beforeTest() {
final URI mockUri = UriUtils.buildUri(this.host, UUID.randomUUID().toString());
ResourceOperationRequest resourceOperationRequest = new ResourceOperationRequest();
resourceOperationRequest.resourceReference = mockUri;
// reboot operation
resourceOperationRequest.operation = "Reboot";
resourceOperationRequest.taskReference = mockUri;
StatelessService mockService = new StatelessService();
mockService.setHost(this.host);
// create context calling the constructor, it should have errorHandler populated by default (i.e. errorHandler != null)
this.context = new VSphereVMContext(mockService, resourceOperationRequest);
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class AzurePowerServiceTest method createTaskResultListener.
private void createTaskResultListener(VerificationHost host, String taskLink, Function<Operation, Boolean> h) {
StatelessService service = new StatelessService() {
@Override
public void handleRequest(Operation update) {
if (!h.apply(update)) {
super.handleRequest(update);
}
}
};
TestContext ctx = this.host.testCreate(1);
Operation startOp = Operation.createPost(host, taskLink).setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
}).setReferer(this.host.getReferer());
this.host.startService(startOp, service);
ctx.await();
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class TestGCPStatsCollection method issueStatsRequest.
/**
* Creates a stateless service which will call GCPStatsService to collect stats of the
* resource specified by the argument.
* Receives response back and patches it to the caller service.
* @param selfLink The self link to the document of enumerated resource.
* @throws Throwable
*/
public void issueStatsRequest(String selfLink) throws Throwable {
// Spin up a stateless service that acts as the parent link to patch back to
StatelessService parentService = new StatelessService() {
@Override
public void handleRequest(Operation op) {
if (op.getAction() == Action.PATCH) {
if (!TestGCPStatsCollection.this.isMock) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp == null) {
TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("response was null."));
return;
}
if (resp.statsList.size() != 1) {
TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("response size was incorrect."));
return;
}
if (resp.statsList.get(0).statValues.size() != 9) {
TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
return;
}
if (!resp.statsList.get(0).computeLink.equals(selfLink)) {
TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
return;
}
}
TestGCPStatsCollection.this.host.completeIteration();
}
}
};
String servicePath = UUID.randomUUID().toString();
Operation startOp = Operation.createPost(UriUtils.buildUri(this.host, servicePath));
this.host.startService(startOp, parentService);
ComputeStatsRequest statsRequest = new ComputeStatsRequest();
statsRequest.resourceReference = UriUtils.buildUri(this.host, selfLink);
statsRequest.isMockRequest = this.isMock;
statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, GCPUriPaths.GCP_STATS_ADAPTER)).setBody(statsRequest).setReferer(this.host.getUri()));
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class TestAWSReservedInstancePlansService method test.
@Test
public void test() throws Throwable {
StatelessService parentService = new StatelessService() {
@Override
public void handleRequest(Operation op) {
if (op.getAction() == Action.PATCH) {
ComputeService.ComputeState state = op.getBody(ComputeService.ComputeState.class);
Assert.assertNotNull(state.customProperties);
Assert.assertNotNull(state.customProperties.get(AWSConstants.RESERVED_INSTANCE_PLAN_DETAILS));
TestAWSReservedInstancePlansService.this.host.completeIteration();
}
}
};
String servicePath = COMPUTE_SELF_LINK;
Operation startOp = Operation.createPost(UriUtils.buildUri(this.host, servicePath));
this.host.startService(startOp, parentService);
this.host.sendAndWait(Operation.createPost(UriUtils.buildUri(this.host, MockAWSReservedInstancePlansService.SELF_LINK)).setBody(COMPUTE_SELF_LINK).setReferer(this.host.getUri()));
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class TestAWSProvisionTask method issueStatsRequest.
private void issueStatsRequest(ComputeState vm, Long lastCollectionTime) throws Throwable {
// spin up a stateless service that acts as the parent link to patch back to
StatelessService parentService = new StatelessService() {
@Override
public void handleRequest(Operation op) {
if (op.getAction() == Action.PATCH) {
if (!TestAWSProvisionTask.this.isMock) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp.statsList.size() != 1) {
TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("response size was incorrect."));
return;
}
// Size == 1, because APICallCount
if (resp.statsList.get(0).statValues.size() == 1) {
TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
return;
}
if (lastCollectionTime != null) {
if (resp.statsList.get(0).statValues.get(PhotonModelConstants.CPU_UTILIZATION_PERCENT).size() < 2) {
TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("incorrect number of data points received when collection window is specified."));
return;
}
}
if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
return;
}
verifyCollectedStats(resp, lastCollectionTime);
}
TestAWSProvisionTask.this.host.completeIteration();
}
}
};
String servicePath = UUID.randomUUID().toString();
Operation startOp = Operation.createPost(UriUtils.buildUri(this.host, servicePath));
this.host.startService(startOp, parentService);
ComputeStatsRequest statsRequest = new ComputeStatsRequest();
statsRequest.resourceReference = UriUtils.buildUri(this.host, vm.documentSelfLink);
statsRequest.isMockRequest = this.isMock;
statsRequest.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
if (lastCollectionTime != null) {
statsRequest.lastCollectionTimeMicrosUtc = lastCollectionTime;
}
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, AWSUriPaths.AWS_STATS_ADAPTER)).setBody(statsRequest).setReferer(this.host.getUri()));
}
Aggregations