本文整理汇总了Java中com.vmware.xenon.common.Operation.addPragmaDirective方法的典型用法代码示例。如果您正苦于以下问题:Java Operation.addPragmaDirective方法的具体用法?Java Operation.addPragmaDirective怎么用?Java Operation.addPragmaDirective使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vmware.xenon.common.Operation
的用法示例。
在下文中一共展示了Operation.addPragmaDirective方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleIdempotentPut
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
public static void handleIdempotentPut(StatefulService s, Operation put) {
if (put.hasPragmaDirective(Operation.PRAGMA_DIRECTIVE_POST_TO_PUT)) {
// converted PUT due to IDEMPOTENT_POST option
s.logFine(() -> String.format("Task %s has already started. Ignoring converted PUT.",
put.getUri()));
put.setBody(s.getState(put));
put.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED);
put.setStatusCode(Operation.STATUS_CODE_OK);
put.complete();
return;
}
// normal PUT is not supported
put.fail(Operation.STATUS_CODE_BAD_METHOD);
}
示例2: deleteServiceSynchronously
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private <T extends ServiceDocument> void deleteServiceSynchronously(
String serviceUri, boolean stopOnly) throws Throwable {
TestContext ctx = this.host.testCreate(1);
Operation deleteOperation = Operation
.createDelete(UriUtils.buildUri(this.host, serviceUri))
.setCompletion((operation, throwable) -> {
if (throwable != null) {
ctx.failIteration(throwable);
}
ctx.completeIteration();
});
if (stopOnly) {
deleteOperation
.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_NO_INDEX_UPDATE);
}
this.send(deleteOperation);
this.testWait(ctx);
}
示例3: testDeletePragmaDirective
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Test
public void testDeletePragmaDirective() throws Throwable {
EndpointService.EndpointState startState = buildValidStartState();
EndpointService.EndpointState returnState = postServiceSynchronously(
EndpointService.FACTORY_LINK,
startState, EndpointState.class);
Operation deleteOperation = Operation
.createDelete(UriUtils.buildUri(this.host, returnState.documentSelfLink));
// custom header is not set in delete request, expect failure
this.host.sendAndWaitExpectFailure(deleteOperation);
// set custom header
deleteOperation.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_FROM_MIGRATION_TASK);
// custom header is set in delete request, expect success
this.host.sendAndWaitExpectSuccess(deleteOperation);
}
示例4: handlePatch
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
* This method handles merging of state for patch requests. It first checks to see if the
* patch body is for updating collections. If not it invokes the mergeWithState() method.
* Finally, users can specify a custom callback method to perform service specific merge
* operations.
*
* <p>If no changes are made to the current state, a response code {@code NOT_MODIFIED} is
* returned with no body. If changes are made, the response body contains the full updated
* state.
*
* @param op Input PATCH operation
* @param currentState The current state of the service
* @param description The service description
* @param stateClass Service state class
* @param customPatchHandler custom callback handler
*/
public static <T extends ResourceState> void handlePatch(Operation op, T currentState,
ServiceDocumentDescription description, Class<T> stateClass,
Function<Operation, Boolean> customPatchHandler) {
try {
boolean hasStateChanged;
// apply standard patch merging
EnumSet<Utils.MergeResult> mergeResult =
Utils.mergeWithStateAdvanced(description, currentState, stateClass, op);
hasStateChanged = mergeResult.contains(Utils.MergeResult.STATE_CHANGED);
if (!mergeResult.contains(Utils.MergeResult.SPECIAL_MERGE)) {
T patchBody = op.getBody(stateClass);
// apply ResourceState-specific merging
hasStateChanged |= ResourceUtils.mergeResourceStateWithPatch(currentState,
patchBody);
// handle NULL_LINK_VALUE links
hasStateChanged |= nullifyLinkFields(description, currentState, patchBody);
}
// apply custom patch handler, if any
if (customPatchHandler != null) {
hasStateChanged |= customPatchHandler.apply(op);
}
if (!hasStateChanged) {
op.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED);
}
op.setBody(currentState);
op.complete();
} catch (NoSuchFieldException | IllegalAccessException e) {
op.fail(e);
}
}
示例5: handlePut
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePut(Operation put) {
if (!put.hasBody()) {
put.fail(new IllegalArgumentException("body is required"));
}
try {
IPAddressState newState = put.getBody(IPAddressState.class);
// Verify valid status changes
IPAddressState currentState = getState(put);
if (isNoOperation(currentState, newState)) {
put.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED);
put.setBody(currentState);
put.complete();
return;
}
// Clear connected resource when releasing the ip address
if (IPAddressStatus.RELEASED.equals(newState.ipAddressStatus)) {
newState.connectedResourceLink = null;
}
validateState(newState);
logInfo("Validating transition for put request from current ip %s "
+ "current status %s to new ip %s new status %s",
currentState.ipAddress, currentState.ipAddressStatus,
newState.ipAddress, newState.ipAddressStatus);
validateIPAddressStatusTransition(currentState, newState);
setState(put, newState);
logInfo("Resource %s was granted the ip %s with the status %s", newState.connectedResourceLink,
newState.ipAddress, newState.ipAddressStatus);
put.complete();
} catch (Throwable t) {
put.fail(t);
}
}
示例6: handlePatch
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation patch) {
if (!patch.hasBody()) {
throw (new IllegalArgumentException("body is required"));
}
IPAddressState currentState = getState(patch);
IPAddressState patchState = patch.getBody(IPAddressState.class);
if (isNoOperation(currentState, patchState)) {
patch.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED);
patch.setBody(currentState);
patch.complete();
return;
}
if (IPAddressStatus.RELEASED.equals(patchState.ipAddressStatus)) {
patchState.connectedResourceLink = ResourceUtils.NULL_LINK_VALUE;
}
ResourceUtils.handlePatch(patch, currentState, getStateDescription(),
IPAddressState.class, op -> {
boolean hasChanged = false;
// Verify valid status changes
if (patchState.ipAddressStatus != null
&& patchState.ipAddressStatus != currentState.ipAddressStatus) {
logInfo("Validating transition for patch request from current ip %s "
+ "current status %s to new ip %s new status %s",
currentState.ipAddress, currentState.ipAddressStatus,
patchState.ipAddress, patchState.ipAddressStatus);
validateIPAddressStatusTransition(currentState, patchState);
currentState.ipAddressStatus = patchState.ipAddressStatus;
validateIPAddressStatusWithConnectedResource(currentState);
logInfo("Resource %s was granted the ip %s with the status %s", patchState.connectedResourceLink,
patchState.ipAddress, patchState.ipAddressStatus);
hasChanged = true;
}
return Boolean.valueOf(hasChanged);
});
}
示例7: handlePut
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePut(Operation put) {
try {
TagState currentState = getState(put);
TagState newTagState = put.getBody(TagState.class);
if (!ServiceDocument.equals(getStateDescription(), currentState, newTagState)) {
put.fail(new UnsupportedOperationException("Tags may not be modified"));
return;
}
// check if the tag has to be turned from external to local
boolean modified = false;
if (newTagState.external != null) {
if (currentState.external == null || (Boolean.TRUE.equals(currentState.external)
&& Boolean.FALSE.equals(newTagState.external))) {
currentState.external = newTagState.external;
modified = true;
}
}
// update the deleted property accordingly
if (newTagState.deleted != null) {
currentState.deleted = newTagState.deleted;
modified = true;
}
if (!modified) {
put.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED);
}
put.setBody(currentState);
put.complete();
} catch (Throwable t) {
put.fail(t);
}
}
示例8: handlePost
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePost(Operation post) {
post.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_FORCE_INDEX_UPDATE);
super.handlePost(post);
}
示例9: handlePatch
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
* Comes in here for a http patch on an existing doc
* For patch only the values being changed are sent.
* getState() method fills in the missing values from the existing doc.
*/
@Override
public void handlePatch(Operation patch) {
checkHasBody(patch);
try {
SubnetRangeState currentState = getState(patch);
SubnetRangeState patchBody = patch.getBody(SubnetRangeState.class);
// Merge the patch values to current state
// In order to validate the merged result
EnumSet<Utils.MergeResult> mergeResult =
Utils.mergeWithStateAdvanced(getStateDescription(), currentState,
SubnetRangeState.class, patch);
boolean hasStateChanged = mergeResult.contains(Utils.MergeResult.STATE_CHANGED);
if (patchBody.dnsSearchDomains != null) {
// replace dnsSearchDomains
// dnsSearchDomains are overwritten -- it's not a merge
currentState.dnsSearchDomains = patchBody.dnsSearchDomains;
hasStateChanged = true;
}
if (patchBody.dnsServerAddresses != null) {
// replace dnsServerAddresses
// dnsServerAddresses are overwritten -- it's not a merge
currentState.dnsServerAddresses = patchBody.dnsServerAddresses;
hasStateChanged = true;
}
if (hasStateChanged) {
validateAll(currentState)
.thenAccept((ignored) -> setState(patch, currentState))
.whenCompleteNotify(patch);
} else {
patch.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED);
patch.setBody(currentState);
patch.complete();
}
} catch (Exception e) {
this.logSevere(String.format("SubnetRangeService: failed to perform patch [%s]",
e.getMessage()));
patch.fail(e);
}
}
示例10: 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);
}