Juan Hernandez has posted comments on this change.

Change subject: engine:Trusted Compute Pools - Open Attestation integration 
with oVirt engine proposal
......................................................................


Patch Set 2:

(1 comment)

http://gerrit.ovirt.org/#/c/26381/2/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/attestation/AttestationService.java
File 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/attestation/AttestationService.java:

Line 121:         List<AttestationValue> values = new 
ArrayList<AttestationValue>();
Line 122:         JsonParser jParser = jfactory.createJsonParser(str);
Line 123:         try {
Line 124:             jParser.nextToken(); //START_OBJECT
Line 125:             while (jParser.nextToken() != JsonToken.END_OBJECT) {
> so maybe we need to use other parser that supports that.
I'm not sure exactly what kind of JSON document are you trying to parse, but 
lets assume that it is something like this:

  {
    "hosts": [
      {
        "host_name": "host1.example.com",
        "trust_lvl": "trusted",
        "vtime": "..."
      },
      {
        "host_name": "host2.example.com",
        "trust_lvl": "untrusted",
        "vtime": "..."
      }
      ...
    ]
  }

If the structure is simple like this, then it may be simpler and more reliable 
for you to parse the complete string to a JsonNode object, and then access it 
similar to a normal Java object:

  List<AttestationValue> values = new ArrayList<>();

  ObjectMapper mapper = new ObjectMapper();
  JsonNode tree = mapper.readTree(str);

  JsonNode hosts = tree.get(HEADER_HOSTS);
  if (hosts != null) {
    for (JsonNode host : hosts) {
      String name = host.get(HEADER_HOST_NAME).asText();
      String level = host.get(HEADER_RESULT).asText();
      AttestationValue value = new AttestationValue();
      value.setHostName(name);
      value.setTrustLevel(AttestationResultEnum.valueOf(level.toUpperCase()));
      values.add(value);
    }
  }

This is already supported by Jackson, and is more resistant to simple changes 
in the structure of the JSON object.
Line 126:                 if 
(jParser.getCurrentName().equalsIgnoreCase(HEADER_HOSTS)) {
Line 127:                     jParser.nextToken(); //START_ARRAY
Line 128:                     jParser.nextToken(); //START_OBJECT
Line 129:                     jParser.nextToken(); //FIELD_NAME


-- 
To view, visit http://gerrit.ovirt.org/26381
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I2f541b004ba383a3098cf7fbfca7a000b11b750f
Gerrit-PatchSet: 2
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Emily Zhang <lijuan.zh...@intel.com>
Gerrit-Reviewer: Dave Chen <wei.d.c...@intel.com>
Gerrit-Reviewer: Doron Fediuck <dfedi...@redhat.com>
Gerrit-Reviewer: Emily Zhang <lijuan.zh...@intel.com>
Gerrit-Reviewer: Gilad Chaplik <gchap...@redhat.com>
Gerrit-Reviewer: Juan Hernandez <juan.hernan...@redhat.com>
Gerrit-Reviewer: Kobi Ianko <k...@redhat.com>
Gerrit-Reviewer: Vojtech Szocs <vsz...@redhat.com>
Gerrit-Reviewer: automat...@ovirt.org
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to