本文整理了Java中com.vmware.xenon.common.Utils.mergeWithStateAdvanced()
方法的一些代码示例,展示了Utils.mergeWithStateAdvanced()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.mergeWithStateAdvanced()
方法的具体详情如下:
包路径:com.vmware.xenon.common.Utils
类名称:Utils
方法名:mergeWithStateAdvanced
[英]Merges the given patch body into the provided current service state. It first checks for patch bodies representing special update requests (such as ServiceStateCollectionUpdateRequest or others in the future) and if not, assumes the patch body is a new service state and merges it into the current state according to the provided ServiceDocumentDescription (see Utils#mergeWithState(ServiceDocumentDescription,ServiceDocument,ServiceDocument)).
[中]将给定的补丁正文合并到提供的当前服务状态。它首先检查代表特殊更新请求(如ServiceStateCollectionUpdateRequest或将来的其他)的补丁正文,如果没有,假设补丁主体是一个新的服务状态,并根据提供的ServiceDocumentDescription(请参阅Utils#mergeWithState(ServiceDocumentDescription,ServiceDocument,ServiceDocument))将其合并到当前状态。
代码示例来源:origin: vmware/admiral
EnumSet<Utils.MergeResult> mergeResult = Utils.mergeWithStateAdvanced(description,
currentState, stateClass, op);
hasStateChanged = mergeResult.contains(Utils.MergeResult.STATE_CHANGED);
代码示例来源:origin: vmware/xenon
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
UserState currentState = getState(op);
try {
UserState newState = getBody(op);
if (newState.email != null && !validate(op, newState)) {
op.fail(new IllegalArgumentException("Invalid email address"));
return;
}
Utils.mergeWithStateAdvanced(getStateDescription(), currentState, UserState.class, op);
} catch (NoSuchFieldException | IllegalAccessException e) {
op.fail(e);
return;
}
op.setBody(currentState).complete();
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testCollectionsUpdateThroughMergeMethod() throws Throwable {
MergeTest state = new MergeTest();
state.setOfStrings = new HashSet<String>();
Map<String, Collection<Object>> collectionsToAdd = new HashMap<>();
collectionsToAdd.put("setOfStrings", new ArrayList<>(Arrays.asList(SOME_STRING_VALUE)));
ServiceStateCollectionUpdateRequest request = ServiceStateCollectionUpdateRequest
.create(collectionsToAdd, null);
Operation patchOperation = Operation.createPatch(new URI("http://test")).setBody(request);
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create()
.buildDescription(MergeTest.class);
EnumSet<MergeResult> result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class,
patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertTrue(result.contains(MergeResult.STATE_CHANGED));
assertEquals(state.setOfStrings.size(), 1);
// repeating the update should not change the state anymore
result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class, patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertFalse(result.contains(MergeResult.STATE_CHANGED));
}
代码示例来源:origin: vmware/xenon
@Test
public void testCollectionsUpdateThroughMergeMethod() throws Throwable {
MergeTest state = new MergeTest();
state.setOfStrings = new HashSet<String>();
Map<String, Collection<Object>> collectionsToAdd = new HashMap<>();
collectionsToAdd.put("setOfStrings", new ArrayList<>(Arrays.asList(SOME_STRING_VALUE)));
ServiceStateCollectionUpdateRequest request = ServiceStateCollectionUpdateRequest
.create(collectionsToAdd, null);
Operation patchOperation = Operation.createPatch(new URI("http://test")).setBody(request);
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create()
.buildDescription(MergeTest.class);
EnumSet<MergeResult> result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class,
patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertTrue(result.contains(MergeResult.STATE_CHANGED));
assertEquals(state.setOfStrings.size(), 1);
// repeating the update should not change the state anymore
result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class, patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertFalse(result.contains(MergeResult.STATE_CHANGED));
}
代码示例来源:origin: vmware/admiral
/**
* 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);
// 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 (hasStateChanged) {
validateAll(currentState)
.thenAccept((ignored) -> setState(patch, currentState))
.whenCompleteNotify(patch);
} else {
patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
patch.complete();
}
} catch (Exception e) {
this.logSevere(String.format("SubnetRangeService: failed to perform patch [%s]",
e.getMessage()));
patch.fail(e);
}
}
代码示例来源:origin: vmware/admiral
@Override
public void handlePatch(Operation patch) {
ElasticPlacementZoneState currentState = getState(patch);
boolean hasStateChanged = false;
try {
EnumSet<Utils.MergeResult> mergeResult = Utils.mergeWithStateAdvanced(
getStateDescription(), currentState, ElasticPlacementZoneState.class, patch);
hasStateChanged = mergeResult.contains(MergeResult.STATE_CHANGED);
} catch (NoSuchFieldException | IllegalAccessException e) {
patch.fail(e);
return;
}
if (!hasStateChanged) {
patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
patch.complete();
} else {
// update the underlying resource pool
setOrRemoveResourcePoolElasticity(currentState, (t) -> {
if (t != null) {
patch.fail(t);
} else {
patch.complete();
}
});
}
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testSetFieldUpdate() throws Throwable {
// current state with null set
MergeTest state = new MergeTest();
// collection update with a list collection instead of a set collection
Map<String, Collection<Object>> collectionsToAdd = new HashMap<>();
collectionsToAdd.put("setOfStrings", Arrays.asList(SOME_STRING_VALUE));
ServiceStateCollectionUpdateRequest request = ServiceStateCollectionUpdateRequest
.create(collectionsToAdd, null);
Operation patchOperation = Operation.createPatch(new URI("http://test")).setBody(request);
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create()
.buildDescription(MergeTest.class);
EnumSet<MergeResult> result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class,
patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertTrue(result.contains(MergeResult.STATE_CHANGED));
assertEquals(1, state.setOfStrings.size());
assertEquals(SOME_STRING_VALUE, state.setOfStrings.iterator().next());
}
代码示例来源:origin: vmware/xenon
@Test
public void testSetFieldUpdate() throws Throwable {
// current state with null set
MergeTest state = new MergeTest();
// collection update with a list collection instead of a set collection
Map<String, Collection<Object>> collectionsToAdd = new HashMap<>();
collectionsToAdd.put("setOfStrings", Arrays.asList(SOME_STRING_VALUE));
ServiceStateCollectionUpdateRequest request = ServiceStateCollectionUpdateRequest
.create(collectionsToAdd, null);
Operation patchOperation = Operation.createPatch(new URI("http://test")).setBody(request);
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create()
.buildDescription(MergeTest.class);
EnumSet<MergeResult> result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class,
patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertTrue(result.contains(MergeResult.STATE_CHANGED));
assertEquals(1, state.setOfStrings.size());
assertEquals(SOME_STRING_VALUE, state.setOfStrings.iterator().next());
}
代码示例来源:origin: vmware/xenon
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create()
.buildDescription(MergeTest.class);
EnumSet<MergeResult> result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class,
patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class, patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertTrue(result.contains(MergeResult.STATE_CHANGED));
result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class, patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertFalse(result.contains(MergeResult.STATE_CHANGED));
代码示例来源:origin: com.vmware.xenon/xenon-common
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create()
.buildDescription(MergeTest.class);
EnumSet<MergeResult> result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class,
patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class, patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertTrue(result.contains(MergeResult.STATE_CHANGED));
result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class, patchOperation);
assertTrue(result.contains(MergeResult.SPECIAL_MERGE));
assertFalse(result.contains(MergeResult.STATE_CHANGED));
代码示例来源:origin: com.vmware.photon.controller/photon-model
Utils.mergeWithStateAdvanced(getStateDescription(), currentState,
SubnetRangeState.class, patch);
代码示例来源:origin: vmware/xenon
@Test
public void testMergeWithStateAdvanced() throws Throwable {
MergeTest state = new MergeTest();
state.s = "one";
MergeTest patch = new MergeTest();
patch.s = "two";
Operation patchOperation = Operation.createPatch(new URI("http://test")).setBody(patch);
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create()
.buildDescription(MergeTest.class);
EnumSet<MergeResult> result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class,
patchOperation);
assertFalse(result.contains(MergeResult.SPECIAL_MERGE));
assertTrue(result.contains(MergeResult.STATE_CHANGED));
assertEquals("two", state.s);
// repeating the update should not change the state anymore
result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class, patchOperation);
assertFalse(result.contains(MergeResult.SPECIAL_MERGE));
assertFalse(result.contains(MergeResult.STATE_CHANGED));
assertEquals("two", state.s);
}
代码示例来源:origin: com.vmware.photon.controller/photon-model
Utils.mergeWithStateAdvanced(description, currentState, stateClass, op);
hasStateChanged |= mergeResult.contains(Utils.MergeResult.STATE_CHANGED);
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testMergeWithStateAdvanced() throws Throwable {
MergeTest state = new MergeTest();
state.s = "one";
MergeTest patch = new MergeTest();
patch.s = "two";
Operation patchOperation = Operation.createPatch(new URI("http://test")).setBody(patch);
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create()
.buildDescription(MergeTest.class);
EnumSet<MergeResult> result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class,
patchOperation);
assertFalse(result.contains(MergeResult.SPECIAL_MERGE));
assertTrue(result.contains(MergeResult.STATE_CHANGED));
assertEquals("two", state.s);
// repeating the update should not change the state anymore
result = Utils.mergeWithStateAdvanced(desc, state, MergeTest.class, patchOperation);
assertFalse(result.contains(MergeResult.SPECIAL_MERGE));
assertFalse(result.contains(MergeResult.STATE_CHANGED));
assertEquals("two", state.s);
}
内容来源于网络,如有侵权,请联系作者删除!