本文整理汇总了Java中com.vmware.xenon.common.Operation.createPost方法的典型用法代码示例。如果您正苦于以下问题:Java Operation.createPost方法的具体用法?Java Operation.createPost怎么用?Java Operation.createPost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vmware.xenon.common.Operation
的用法示例。
在下文中一共展示了Operation.createPost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendStatsRequest
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private void sendStatsRequest(ComputeState account, StatelessService parentService)
throws Throwable {
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, account.documentSelfLink);
statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
statsRequest.isMockRequest = !this.isMock;
statsRequest.nextStage = SingleResourceStatsCollectionTaskService
.SingleResourceTaskCollectionStage.UPDATE_STATS.name();
this.host.sendAndWait(Operation
.createPatch(UriUtils.buildUri(this.host, MockCostStatsAdapterService.SELF_LINK))
.setBody(statsRequest)
.setReferer(this.host.getUri()));
}
示例2: testGetAvailableRegions
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Test
public void testGetAvailableRegions() {
URI uri = UriUtils.buildUri(
ServiceHost.LOCAL_HOST,
host.getPort(),
UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(
PhotonModelConstants.EndpointType.aws.toString().toLowerCase()), null);
Operation post = Operation.createPost(uri);
post.setBody(new AuthCredentialsServiceState());
Operation operation = host.getTestRequestSender().sendAndWait(post);
RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
assertEquals(Regions.values().length, result.regions.size());
}
示例3: test
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@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()));
}
示例4: testGetAvailableRegions
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Test
public void testGetAvailableRegions() throws Throwable {
Assume.assumeFalse(isMock());
startAdditionalServices();
this.host.waitForServiceAvailable(VSphereUriPaths.VSPHERE_REGION_ENUMERATION_ADAPTER_SERVICE);
URI uri = UriUtils.buildUri(
ServiceHost.LOCAL_HOST,
host.getPort(),
UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(
PhotonModelConstants.EndpointType.vsphere.toString().toLowerCase()), null);
Operation post = Operation.createPost(uri);
post.setBody(createEndpoint((a) -> { }, (b) -> { }));
Operation operation = host.getTestRequestSender().sendAndWait(post);
RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
assertTrue(!result.regions.isEmpty());
}
示例5: testGetAvailableRegions
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Test
public void testGetAvailableRegions() {
Assume.assumeFalse(this.isMock);
URI uri = UriUtils.buildUri(
ServiceHost.LOCAL_HOST,
host.getPort(),
UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(
PhotonModelConstants.EndpointType.azure.toString().toLowerCase()), null);
Operation post = Operation.createPost(uri);
post.setBody(endpointState);
Operation operation = host.getTestRequestSender().sendAndWait(post);
RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
assertTrue(!result.regions.isEmpty());
}
示例6: startServicesSynchronously
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private void startServicesSynchronously(ServiceHost serviceHost, Service... services) throws Throwable {
List<Operation> posts = new ArrayList<>();
for (Service s : services) {
URI u = null;
if (ReflectionUtils.hasField(s.getClass(), UriUtils.FIELD_NAME_SELF_LINK)) {
u = UriUtils.buildUri(serviceHost, s.getClass());
} else if (s instanceof FactoryService) {
u = UriUtils.buildFactoryUri(serviceHost,
((FactoryService) s).createServiceInstance().getClass());
} else {
throw new IllegalStateException("field SELF_LINK or FACTORY_LINK is required");
}
Operation startPost = Operation.createPost(u);
posts.add(startPost);
}
startServicesSynchronously(serviceHost, posts, Arrays.asList(services));
}
示例7: createComputeDescriptionOp
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private Operation createComputeDescriptionOp(EndpointAllocationTaskState currentState,
String computeDescriptionLink) {
if (currentState.accountAlreadyExists) {
return Operation.createPatch(this, computeDescriptionLink);
}
return Operation.createPost(this, ComputeDescriptionService.FACTORY_LINK);
}
示例8: createComputeStateOp
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private Operation createComputeStateOp(EndpointAllocationTaskState currentState,
String computeStateLink) {
if (currentState.accountAlreadyExists) {
return Operation.createPatch(this, computeStateLink);
}
return Operation.createPost(this, ComputeService.FACTORY_LINK);
}
示例9: issueMockStatsRequest
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
* Verify whether the mock stats gathered are correct or not.
* @param vm The AWS VM compute state.
* @throws Throwable
*/
private void issueMockStatsRequest(ComputeService.ComputeState vm) 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) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp.statsList.size() != 1) {
TestAWSEnumerationAtScale.this.host.failIteration(
new IllegalStateException("response size was incorrect."));
return;
}
if (resp.statsList.get(0).statValues.size() != MOCK_STATS_SIZE) {
TestAWSEnumerationAtScale.this.host.failIteration(
new IllegalStateException("incorrect number of metrics received."));
return;
}
if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
TestAWSEnumerationAtScale.this.host.failIteration(
new IllegalStateException("Incorrect resourceReference returned."));
return;
}
verifyCollectedMockStats(resp);
TestAWSEnumerationAtScale.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);
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(
this.host, AWSMockStatsService.SELF_LINK))
.setBody(statsRequest)
.setReferer(this.host.getUri()));
}
示例10: issueStatsRequest
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
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()));
}
示例11: issueStatsRequest
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private void issueStatsRequest(ComputeState vm) 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 (!TestAzureProvisionTask.this.isMock) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp.statsList.size() != 1) {
TestAzureProvisionTask.this.host.failIteration(
new IllegalStateException("response size was incorrect."));
return;
}
if (resp.statsList.get(0).statValues.size() == 0) {
TestAzureProvisionTask.this.host
.failIteration(new IllegalStateException(
"incorrect number of metrics received."));
return;
}
if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
TestAzureProvisionTask.this.host.failIteration(
new IllegalStateException(
"Incorrect computeReference returned."));
return;
}
}
TestAzureProvisionTask.this.host.completeIteration();
}
}
};
String servicePath = UUID.randomUUID().toString();
Operation startOp = Operation.createPost(UriUtils.buildUri(getHost(), servicePath));
getHost().startService(startOp, parentService);
ComputeStatsRequest statsRequest = new ComputeStatsRequest();
statsRequest.resourceReference = UriUtils.buildUri(getHost(), vm.documentSelfLink);
statsRequest.isMockRequest = this.isMock;
statsRequest.taskReference = UriUtils.buildUri(getHost(), servicePath);
getHost().sendAndWait(Operation.createPatch(UriUtils.buildUri(
getHost(), AzureUriPaths.AZURE_STATS_ADAPTER))
.setBody(statsRequest)
.setReferer(getHost().getUri()));
}
示例12: issueStatsRequest
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private void issueStatsRequest(String selfLink, boolean isComputeHost) 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 (!TestAzureEnumerationTask.this.isMock) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp == null) {
TestAzureEnumerationTask.this.host.failIteration(
new IllegalStateException("response was null."));
return;
}
if (resp.statsList.size() != 1) {
TestAzureEnumerationTask.this.host.failIteration(
new IllegalStateException("response size was incorrect."));
return;
}
if (resp.statsList.get(0).statValues.size() == 0) {
TestAzureEnumerationTask.this.host
.failIteration(new IllegalStateException(
"incorrect number of metrics received."));
return;
}
if (!resp.statsList.get(0).computeLink.equals(selfLink)) {
TestAzureEnumerationTask.this.host
.failIteration(new IllegalStateException(
"Incorrect resourceReference returned."));
return;
}
// Verify all the stats are obtained
verifyStats(resp, isComputeHost);
// Persist stats on Verification Host for testing the computeHost stats.
URI persistStatsUri = UriUtils.buildUri(getHost(),
ResourceMetricsService.FACTORY_LINK);
ResourceMetricsService.ResourceMetrics resourceMetric = new ResourceMetricsService.ResourceMetrics();
resourceMetric.documentSelfLink = StatsUtil.getMetricKey(selfLink,
Utils.getNowMicrosUtc());
resourceMetric.entries = new HashMap<>();
resourceMetric.timestampMicrosUtc = Utils.getNowMicrosUtc();
for (String key : resp.statsList.get(0).statValues.keySet()) {
List<ServiceStat> stats = resp.statsList.get(0).statValues.get(key);
for (ServiceStat stat : stats) {
if (stat == null) {
continue;
}
resourceMetric.entries.put(key, stat.latestValue);
}
}
TestAzureEnumerationTask.this.host.sendRequest(Operation
.createPost(persistStatsUri)
.setReferer(TestAzureEnumerationTask.this.host.getUri())
.setBodyNoCloning(resourceMetric));
}
TestAzureEnumerationTask.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.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
statsRequest.isMockRequest = this.isMock;
statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(
this.host, AzureUriPaths.AZURE_STATS_ADAPTER))
.setBody(statsRequest)
.setReferer(this.host.getUri()));
}
示例13: issueStatsRequest
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
* 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()));
}
示例14: createUpdateLocalResourceState
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
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) {
// Create case
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(this.service, this.localStateServiceFactoryLink);
} else {
// Update case
if (isApplyInfraFields()) {
setEndpointLink(localState, this.endpointState.documentSelfLink);
// update the endpointLinks
updateEndpointLinks(localState, this.endpointState.documentSelfLink);
}
localStateOp = Operation.createPatch(this.service, 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));
}
});
}
示例15: doOperation
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
protected <T extends ServiceDocument> T doOperation(T inState, URI uri, Class<T> type,
boolean expectFailure, Action action) throws Throwable {
this.host.log("Executing operation %s for resource: %s ...", action.name(), uri);
final List<T> doc = Arrays.asList((T) null);
final Throwable[] error = { null };
TestContext ctx = testCreate(1);
Operation op;
if (action == Action.POST) {
op = createForcedPost(uri);
} else {
// createPost sets the proper authorization context for the operation
op = Operation.createPost(uri);
// replace POST with the provided action
op.setAction(action);
}
op.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY);
op.setBody(inState)
.setCompletion(
(o, e) -> {
if (e != null) {
if (expectFailure) {
error[0] = e;
ctx.completeIteration();
} else {
ctx.failIteration(e);
}
return;
}
if (!o.hasBody()) {
ctx.failIteration(new IllegalStateException("body was expected"));
return;
}
doc.set(0, o.getBody(type));
if (expectFailure) {
ctx.failIteration(new IllegalStateException(
"ERROR: operation completed successfully but exception excepted."));
} else {
ctx.completeIteration();
}
});
this.host.send(op);
ctx.await();
this.host.logThroughput();
if (expectFailure) {
Throwable ex = error[0];
throw ex;
}
return doc.get(0);
}