com.vmware.xenon.common.Utils.computeSignature()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(17.4k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中com.vmware.xenon.common.Utils.computeSignature()方法的一些代码示例,展示了Utils.computeSignature()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.computeSignature()方法的具体详情如下:
包路径:com.vmware.xenon.common.Utils
类名称:Utils
方法名:computeSignature

Utils.computeSignature介绍

暂无

代码示例

代码示例来源:origin: vmware/xenon

/**
 * Compares ServiceDocument for equality. If they are same, then this method returns true;
 * false otherwise.
 *
 * @param description     ServiceDocumentDescription obtained by calling getDocumentTemplate
 *                        ().documentDescription
 * @param currentDocument current service document instance
 * @param newDocument     new service document instance
 * @return true / false
 */
public static boolean equals(ServiceDocumentDescription description,
    ServiceDocument currentDocument, ServiceDocument newDocument) {
  if (currentDocument == null || newDocument == null) {
    throw new IllegalArgumentException(
        "Null Service documents cannot be checked for equality.");
  }
  try {
    String currentSignature = Utils.computeSignature(currentDocument, description);
    String newSignature = Utils.computeSignature(newDocument, description);
    return currentSignature.equals(newSignature);
  } catch (Exception e) {
    if (e instanceof IllegalArgumentException) {
      throw (IllegalArgumentException) e;
    }
    return false;
  }
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  ContainerNetworkDescription currentState = getState(patch);
  ContainerNetworkDescription patchBody = getValidInputFrom(patch, currentState);
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  PropertyUtils.mergeServiceDocuments(currentState, patchBody,
      NetworkUtils.SHALLOW_MERGE_SKIP_MAPS_STRATEGY);
  PropertyUtils.mergeCustomProperties(currentState.options, patchBody.options);
  if (patchBody.parentDescriptionLink != null
      && patchBody.parentDescriptionLink.trim().isEmpty()) {
    currentState.parentDescriptionLink = null;
  }
  String newSignature = Utils.computeSignature(currentState, docDesc);
  boolean changed = !newSignature.equals(currentSignature);
  if (!changed) {
    patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  }
  patch.complete();
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  ContainerDescription currentState = getState(patch);
  ContainerDescription patchBody = patch.getBody(ContainerDescription.class);
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  PropertyUtils.mergeServiceDocuments(currentState, patchBody);
  if (patchBody.parentDescriptionLink != null
      && patchBody.parentDescriptionLink.trim().isEmpty()) {
    currentState.parentDescriptionLink = null;
  }
  if (patchBody.networkMode != null && patchBody.networkMode.trim().isEmpty()) {
    currentState.networkMode = null;
  }
  if (patchBody.networks != null) {
    currentState.networks = patchBody.networks;
  }
  if (patchBody.volumes != null) {
    Set<String> uniqueVolumes = new HashSet<>(Arrays.asList(patchBody.volumes));
    currentState.volumes = uniqueVolumes.toArray(new String[uniqueVolumes.size()]);
  }
  validateState(currentState);
  String newSignature = Utils.computeSignature(currentState, docDesc);
  // if the signature hasn't change we shouldn't modify the state
  if (currentSignature.equals(newSignature)) {
    currentState = null;
    patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  }
  patch.setBody(currentState).complete();
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  ContainerVolumeDescription currentState = getState(patch);
  ContainerVolumeDescription patchBody = getValidInputFrom(patch, true);
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  PropertyUtils.mergeServiceDocuments(currentState, patchBody);
  PropertyUtils.mergeCustomProperties(currentState.customProperties,
      patchBody.customProperties);
  if (patchBody.parentDescriptionLink != null
      && patchBody.parentDescriptionLink.trim().isEmpty()) {
    currentState.parentDescriptionLink = null;
  }
  String newSignature = Utils.computeSignature(currentState, docDesc);
  boolean changed = !newSignature.equals(currentSignature);
  if (!changed) {
    patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  }
  patch.complete();
}

代码示例来源:origin: vmware/admiral

/**
 * Returns whether the projects state signature was changed after the patch.
 */
private DeferredResult<Boolean> handleProjectPatch(ProjectState currentState,
    ProjectState patchState) {
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  DeferredResult<Integer> projectIndex;
  if (currentState.customProperties == null) {
    projectIndex = generateProjectIndex();
  } else {
    projectIndex = DeferredResult.completed(Integer.parseInt(
        currentState.customProperties.get(CUSTOM_PROPERTY_PROJECT_INDEX)));
  }
  return projectIndex.thenApply(index -> {
    Map<String, String> mergedProperties = PropertyUtils.mergeCustomProperties(
        currentState.customProperties, patchState.customProperties);
    PropertyUtils.mergeServiceDocuments(currentState, patchState);
    currentState.customProperties = mergedProperties;
    handleProjectIndex(index, currentState);
    String newSignature = Utils.computeSignature(currentState, docDesc);
    return !currentSignature.equals(newSignature);
  });
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  ContainerVolumeState currentState = getState(patch);
  ContainerVolumeState patchBody = getValidInputFrom(patch, true);
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  List<String> currentCompositeComponentLinks = currentState.compositeComponentLinks;
  PropertyUtils.mergeServiceDocuments(currentState, patchBody);
  String newSignature = Utils.computeSignature(currentState, docDesc);
  boolean changed = !newSignature.equals(currentSignature);
  if (!changed) {
    patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  } else {
    CompositeComponentNotifier.notifyCompositionComponentsOnChange(this, patch.getAction(),
        currentState.compositeComponentLinks, currentCompositeComponentLinks);
  }
  patch.complete();
}

代码示例来源:origin: vmware/xenon

@Test
public void testComputeSignatureUnchanged() {
  ServiceDocumentDescription description = ServiceDocumentDescription.Builder.create()
      .buildDescription(QueryValidationTestService.QueryValidationServiceState.class);
  QueryValidationTestService.QueryValidationServiceState document = new QueryValidationTestService.QueryValidationServiceState();
  document.documentSelfLink = "testComputeSignatureChange";
  document.textValue = "valueA";
  document.documentUpdateTimeMicros = 1;
  String initialSignature = Utils.computeSignature(document, description);
  document.documentUpdateTimeMicros = 2;
  String updateChangedSignature = Utils.computeSignature(document, description);
  assertEquals(initialSignature, updateChangedSignature);
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation op) {
  if (!checkForBody(op)) {
    return;
  }
  Endpoint currentState = getState(op);
  Endpoint patchBody = op.getBody(Endpoint.class);
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  List<String> mergedTenantLinks = mergeTenantLinks(currentState.tenantLinks,
      patchBody.tenantLinks);
  PropertyUtils.mergeServiceDocuments(currentState, patchBody);
  currentState.tenantLinks = mergedTenantLinks;
  validate(currentState);
  String newSignature = Utils.computeSignature(currentState, docDesc);
  // if the signature hasn't change we shouldn't modify the state
  if (currentSignature.equals(newSignature)) {
    currentState = null;
    op.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  }
  op.setBody(currentState).complete();
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  CompositeDescription currentState = getState(patch);
  CompositeDescription patchBody = patch.getBody(CompositeDescription.class);
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  currentState.name = mergeProperty(currentState.name, patchBody.name);
  currentState.status = mergeProperty(currentState.status, patchBody.status);
  currentState.lastPublished = mergeProperty(currentState.lastPublished,
      patchBody.lastPublished);
  if (patchBody.parentDescriptionLink != null
      && patchBody.parentDescriptionLink.trim().isEmpty()) {
    currentState.parentDescriptionLink = null;
  } else {
    currentState.parentDescriptionLink = mergeProperty(currentState.parentDescriptionLink,
        patchBody.parentDescriptionLink);
  }
  currentState.descriptionLinks = mergeProperty(currentState.descriptionLinks,
      patchBody.descriptionLinks);
  currentState.customProperties = mergeCustomProperties(
      currentState.customProperties, patchBody.customProperties);
  String newSignature = Utils.computeSignature(currentState, docDesc);
  // if the signature hasn't change we shouldn't modify the state
  if (currentSignature.equals(newSignature)) {
    currentState = null;
    patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  }
  patch.setBody(currentState).complete();
}

代码示例来源:origin: com.vmware.xenon/xenon-common

@Test
public void testComputeSignatureUnchanged() {
  ServiceDocumentDescription description = ServiceDocumentDescription.Builder.create()
      .buildDescription(QueryValidationTestService.QueryValidationServiceState.class);
  QueryValidationTestService.QueryValidationServiceState document = new QueryValidationTestService.QueryValidationServiceState();
  document.documentSelfLink = "testComputeSignatureChange";
  document.textValue = "valueA";
  document.documentUpdateTimeMicros = 1;
  String initialSignature = Utils.computeSignature(document, description);
  document.documentUpdateTimeMicros = 2;
  String updateChangedSignature = Utils.computeSignature(document, description);
  assertEquals(initialSignature, updateChangedSignature);
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  ContainerState currentState = getState(patch);
  ContainerState patchBody = patch.getBody(ContainerState.class);
  if (ContainerStats.KIND.equals(patchBody.documentKind)) {
    patchContainerStats(patch, currentState);
    return;
  }
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  PropertyUtils.mergeServiceDocuments(currentState, patchBody);
  String newSignature = Utils.computeSignature(currentState, docDesc);
  // if the signature hasn't change we shouldn't modify the state
  if (currentSignature.equals(newSignature)) {
    patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  }
  if (ContainerUtil.isDiscoveredContainer(currentState)) {
    ContainerUtil.ContainerDescriptionHelper.createInstance(this)
        .updateDiscoveredContainerDesc(currentState, patchBody);
  }
  ContainerUtil.ContainerDescriptionHelper.createInstance(this)
      .updateContainerPorts(currentState, patchBody);
  patch.complete();
}

代码示例来源:origin: vmware/xenon

@Test
public void testComputeSignatureChanged() {
  ServiceDocumentDescription description = ServiceDocumentDescription.Builder.create()
      .buildDescription(QueryValidationTestService.QueryValidationServiceState.class);
  QueryValidationTestService.QueryValidationServiceState document = new QueryValidationTestService.QueryValidationServiceState();
  document.documentSelfLink = "testComputeSignatureChange";
  document.textValue = "valueA";
  document.documentExpirationTimeMicros = 1;
  String initialSignature = Utils.computeSignature(document, description);
  document.textValue = "valueB";
  String valueChangedSignature = Utils.computeSignature(document, description);
  assertNotEquals(initialSignature, valueChangedSignature);
  document.documentExpirationTimeMicros = 2;
  String expirationChangedSignature = Utils.computeSignature(document, description);
  assertNotEquals(initialSignature, expirationChangedSignature);
  assertNotEquals(valueChangedSignature, expirationChangedSignature);
}

代码示例来源:origin: com.vmware.xenon/xenon-common

@Test
public void testComputeSignatureChanged() {
  ServiceDocumentDescription description = ServiceDocumentDescription.Builder.create()
      .buildDescription(QueryValidationTestService.QueryValidationServiceState.class);
  QueryValidationTestService.QueryValidationServiceState document = new QueryValidationTestService.QueryValidationServiceState();
  document.documentSelfLink = "testComputeSignatureChange";
  document.textValue = "valueA";
  document.documentExpirationTimeMicros = 1;
  String initialSignature = Utils.computeSignature(document, description);
  document.textValue = "valueB";
  String valueChangedSignature = Utils.computeSignature(document, description);
  assertNotEquals(initialSignature, valueChangedSignature);
  document.documentExpirationTimeMicros = 2;
  String expirationChangedSignature = Utils.computeSignature(document, description);
  assertNotEquals(initialSignature, expirationChangedSignature);
  assertNotEquals(valueChangedSignature, expirationChangedSignature);
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  ContainerNetworkState currentState = getState(patch);
  ConnectedContainersCountIncrement incrementPatch = patch
      .getBody(ConnectedContainersCountIncrement.class);
  if (incrementPatch != null && incrementPatch.increment != null) {
    currentState.connectedContainersCount += incrementPatch.increment;
    patch.complete();
    return;
  }
  ContainerNetworkState patchBody = getValidInputFrom(patch, currentState);
  ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription;
  String currentSignature = Utils.computeSignature(currentState, docDesc);
  List<String> currentCompositeComponentLinks = currentState.compositeComponentLinks;
  PropertyUtils.mergeServiceDocuments(currentState, patchBody,
      NetworkUtils.SHALLOW_MERGE_SKIP_MAPS_STRATEGY);
  PropertyUtils.mergeCustomProperties(currentState.options, patchBody.options);
  String newSignature = Utils.computeSignature(currentState, docDesc);
  boolean changed = !newSignature.equals(currentSignature);
  if (!changed) {
    patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  } else {
    CompositeComponentNotifier.notifyCompositionComponentsOnChange(this,
        patch.getAction(),
        currentState.compositeComponentLinks, currentCompositeComponentLinks);
  }
  patch.complete();
}

代码示例来源:origin: vmware/xenon

Utils.computeSignature(document, desc);

代码示例来源:origin: com.vmware.xenon/xenon-common

@Test
public void testComputeSignature() throws Exception {
  ServiceDocumentDescription sdd = TestUtils.buildStateDescription(
      TestInvalidComputerSignatureState.class, null);
  TestInvalidComputerSignatureState state1 = new TestInvalidComputerSignatureState();
  state1.key1 = "1";
  state1.key2 = null;
  TestInvalidComputerSignatureState state2 = new TestInvalidComputerSignatureState();
  state2.key1 = null;
  state2.key2 = "1";
  TestInvalidComputerSignatureState state3 = new TestInvalidComputerSignatureState();
  state3.key1 = "1";
  state3.key2 = "";
  String sign1 = Utils.computeSignature(state1, sdd);
  String sign2 = Utils.computeSignature(state2, sdd);
  String sign3 = Utils.computeSignature(state3, sdd);
  assertNotEquals(sign1, sign2);
  assertNotEquals(sign2, sign3);
  assertNotEquals(sign1, sign3);
}

代码示例来源:origin: vmware/xenon

@Test
public void testComputeSignature() throws Exception {
  ServiceDocumentDescription sdd = TestUtils.buildStateDescription(
      TestInvalidComputerSignatureState.class, null);
  TestInvalidComputerSignatureState state1 = new TestInvalidComputerSignatureState();
  state1.key1 = "1";
  state1.key2 = null;
  TestInvalidComputerSignatureState state2 = new TestInvalidComputerSignatureState();
  state2.key1 = null;
  state2.key2 = "1";
  TestInvalidComputerSignatureState state3 = new TestInvalidComputerSignatureState();
  state3.key1 = "1";
  state3.key2 = "";
  String sign1 = Utils.computeSignature(state1, sdd);
  String sign2 = Utils.computeSignature(state2, sdd);
  String sign3 = Utils.computeSignature(state3, sdd);
  assertNotEquals(sign1, sign2);
  assertNotEquals(sign2, sign3);
  assertNotEquals(sign1, sign3);
}

代码示例来源:origin: com.vmware.xenon/xenon-common

"Expected signature (%s) of document:\n%s",
        wellKnownSignature, Utils.toJsonHtml(document)));
String sig = Utils.computeSignature(document, desc);
assertEquals(wellKnownSignature, sig);

代码示例来源:origin: com.vmware.xenon/xenon-common

private void assertSavedStateMatchesFetched(FindForLink ffl) throws Exception {
  VerificationHost host = getHost();
  Operation op = Operation.createGet(host, ffl.selfLink);
  host.log("Checking service %s", ffl.selfLink);
  op = host.waitForResponse(op);
  assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
  ServiceDocument fetchedDoc = op.getBody(ffl.getDocumentClass());
  ServiceDocument originalDoc = ffl.getDocument();
  ServiceDocumentDescription desc = host.buildDescription(originalDoc.getClass());
  String s1 = Utils.computeSignature(fetchedDoc, desc);
  String s2 = Utils.computeSignature(originalDoc, desc);
  if (!s1.equals(s2)) {
    String msg = "A document from the sandbox has different signature after upgrade" + ffl.selfLink;
    host.log("Expected: %s, got %s", Utils.toJson(originalDoc), Utils.toJson(fetchedDoc));
    fail(msg);
  }
}

代码示例来源:origin: vmware/xenon

private void assertSavedStateMatchesFetched(FindForLink ffl) throws Exception {
  VerificationHost host = getHost();
  Operation op = Operation.createGet(host, ffl.selfLink);
  host.log("Checking service %s", ffl.selfLink);
  op = host.waitForResponse(op);
  assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
  ServiceDocument fetchedDoc = op.getBody(ffl.getDocumentClass());
  ServiceDocument originalDoc = ffl.getDocument();
  ServiceDocumentDescription desc = host.buildDescription(originalDoc.getClass());
  String s1 = Utils.computeSignature(fetchedDoc, desc);
  String s2 = Utils.computeSignature(originalDoc, desc);
  if (!s1.equals(s2)) {
    String msg = "A document from the sandbox has different signature after upgrade" + ffl.selfLink;
    host.log("Expected: %s, got %s", Utils.toJson(originalDoc), Utils.toJson(fetchedDoc));
    fail(msg);
  }
}

相关文章