Exemplo n.º 1
0
  /**
   * This method writes the state of the NodeManager to disk
   *
   * @param jsonGenerator The instance of JsonGenerator, which will be used to write JSON to disk
   * @throws IOException
   */
  public void write(JsonGenerator jsonGenerator) throws IOException {
    jsonGenerator.writeStartObject();

    // nameToNode begins
    jsonGenerator.writeFieldName("nameToNode");
    jsonGenerator.writeStartObject();
    for (Map.Entry<String, ClusterNode> entry : nameToNode.entrySet()) {
      jsonGenerator.writeFieldName(entry.getKey());
      entry.getValue().write(jsonGenerator);
    }
    jsonGenerator.writeEndObject();
    // nameToNode ends

    // hostsToSessions begins
    // We create a new Map of type <ClusterNode.name, Set<SessionIds>>.
    // The original hostsToSessions map has the ClusterNode as its key, and
    // we do not need to persist the entire ClusterNode again, since we have
    // already done that with nameToNode.
    Map<String, Set<String>> hostsToSessionsMap = new HashMap<String, Set<String>>();
    for (Map.Entry<ClusterNode, Set<String>> entry : hostsToSessions.entrySet()) {
      hostsToSessionsMap.put(entry.getKey().getName(), entry.getValue());
    }
    jsonGenerator.writeObjectField("hostsToSessions", hostsToSessionsMap);
    // hostsToSessions ends

    jsonGenerator.writeObjectField("nameToApps", nameToApps);

    // faultManager is not required

    // We can rebuild the loadManager
    jsonGenerator.writeEndObject();
  }
Exemplo n.º 2
0
 @Override
 public void serialize(
     final JobFailure jobFailure, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeStringField("worker", jobFailure.getWorker());
   jgen.writeStringField("queue", jobFailure.getQueue());
   jgen.writeFieldName("payload");
   ObjectMapperFactory.get().writeValue(jgen, jobFailure.getPayload());
   jgen.writeStringField(
       "exception",
       (jobFailure.getException() == null)
           ? null
           : jobFailure.getException().getClass().getName());
   jgen.writeStringField(
       "error",
       (jobFailure.getException() == null) ? null : jobFailure.getException().getMessage());
   jgen.writeFieldName("backtrace");
   ObjectMapperFactory.get()
       .writeValue(
           jgen,
           (jobFailure.getException() == null)
               ? null
               : JesqueUtils.createBacktrace(jobFailure.getException()));
   jgen.writeFieldName("failed_at");
   ObjectMapperFactory.get().writeValue(jgen, jobFailure.getFailedAt());
   jgen.writeFieldName("retried_at");
   ObjectMapperFactory.get().writeValue(jgen, jobFailure.getRetriedAt());
   jgen.writeEndObject();
 }
Exemplo n.º 3
0
  private void writeDebug() throws JsonGenerationException, IOException {
    if (debugInfo != null) {
      writer.writeFieldName("debug");
      writer.writeStartObject();

      writer.writeStringField("script-version", debugInfo.getScriptVersion());

      List<LoadDescription> descriptions = debugInfo.getDescriptions();
      List<QueryData> queries = debugInfo.getQueries();
      for (int index = 0; index < descriptions.size(); index++) {
        writer.writeFieldName("query_" + index);
        writer.writeStartObject();

        LoadDescription description = descriptions.get(index);
        OrcsSession session = description.getSession();
        if (session != null) {
          writer.writeStringField("session", session.getGuid());
        }
        Options options = description.getOptions();
        for (String key : new TreeSet<String>(options.getKeys())) {
          writer.writeStringField(key, options.get(key).replaceAll("\\s+", " "));
        }
        writeQuery(queries.get(index));
        writer.writeEndObject();
      }
      writer.writeEndObject();
    }
  }
    @Override
    public void serialize(
        SimpleEvaluationObject value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {

      synchronized (value) {
        String id = getUpdateManager().register(value);
        jgen.writeStartObject();
        jgen.writeObjectField("type", "SimpleEvaluationObject");
        jgen.writeStringField("update_id", id);
        jgen.writeStringField("expression", value.getExpression());
        jgen.writeObjectField("status", value.getStatus());
        if (value.getMessage() != null) jgen.writeStringField("message", value.getMessage());
        if (value.getProgressBar() > 0)
          jgen.writeNumberField("progressBar", value.getProgressBar());
        if (value.getPayloadChanged()) {
          EvaluationResult o = value.getPayload();
          if (o != null && o.getValue() != null) {
            jgen.writeFieldName("payload");
            if (!getObjectSerializer().writeObject(o, jgen, true)) jgen.writeObject(o.toString());
          } else if (value.getJsonRes() != null) {
            jgen.writeFieldName("payload");
            if (ControlCharacterUtils.containsControlCharacters(value.getJsonRes())) {
              jgen.writeRawValue(ControlCharacterUtils.escapeControlCharacters(value.getJsonRes()));
            } else {
              jgen.writeRawValue(value.getJsonRes());
            }
          }
        }
        if (value.getJsonRes() != null
            && value.getPayload() != null
            && value.getPayload().getValue() != null) {
          logger.trace("adding raw json data: '" + value.getJsonRes() + "'");
          jgen.writeFieldName("jsonres");
          if (ControlCharacterUtils.containsControlCharacters(value.getJsonRes())) {
            jgen.writeRawValue(ControlCharacterUtils.escapeControlCharacters(value.getJsonRes()));
          } else {
            jgen.writeRawValue(value.getJsonRes());
          }
        }
        jgen.writeArrayFieldStart("outputdata");
        for (Object o : value.getOutputdata()) {
          if (o instanceof EvaluationStdOutput) {
            jgen.writeStartObject();
            jgen.writeStringField("type", "out");
            jgen.writeStringField("value", ((EvaluationStdOutput) o).payload);
            jgen.writeEndObject();
          } else if (o instanceof EvaluationStdError) {
            jgen.writeStartObject();
            jgen.writeStringField("type", "err");
            jgen.writeStringField("value", ((EvaluationStdError) o).payload);
            jgen.writeEndObject();
          }
        }
        jgen.writeEndArray();
        jgen.writeEndObject();
      }
    }
Exemplo n.º 5
0
  void toJson(JsonGenerator gen) throws IOException {
    gen.writeStartObject();
    gen.writeArrayFieldStart("sourceSchemas");
    for (Schema schema : schemas) {
      schema.toJson(gen);
    }
    gen.writeEndArray();
    gen.writeObjectFieldStart("fieldAliases");
    for (Map.Entry<String, Map<String, String>> entry : schemaFieldAliases.entrySet()) {
      String schemaName = entry.getKey();
      Map<String, String> aliases = entry.getValue();
      gen.writeObjectField(schemaName, aliases);
    }
    gen.writeEndObject();

    gen.writeArrayFieldStart("groupByFields");
    for (String field : groupByFields) {
      gen.writeString(field);
    }
    gen.writeEndArray();

    if (customPartitionFields != null && !customPartitionFields.isEmpty()) {
      gen.writeArrayFieldStart("customPartitionFields");
      for (String field : customPartitionFields) {
        gen.writeString(field);
      }
      gen.writeEndArray();
    }

    if (rollupFrom != null) {
      gen.writeFieldName("rollupFrom");
      gen.writeString(rollupFrom);
    }

    gen.writeFieldName("commonOrderBy");
    commonCriteria.toJson(gen);

    gen.writeStringField("schemasOrder", schemasOrder.toString());

    // TODO this code should write a map with sourceName
    if (specificCriterias == null || specificCriterias.isEmpty()) {
      initSecondaryCriteriasWithNull();
    }
    gen.writeArrayFieldStart("specificOrderBys");
    for (Criteria c : specificCriterias) {
      if (c == null) {
        gen.writeNull();
      } else {
        c.toJson(gen);
      }
    }
    gen.writeEndArray();
    gen.writeEndObject();
  }
 @Override
 public void serialize(
     final RegisterMessage register, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(RegisterMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(register.getMessageType().toString().toLowerCase());
   jgen.writeFieldName(RegisterMessage.CHANNEL_ID_FIELD);
   jgen.writeString(register.getChannelId());
   jgen.writeEndObject();
 }
  public void jacksonTest() throws Exception {
    JsonFactory factory = new JsonFactory();
    StringWriter writer = new StringWriter();
    JsonGenerator generator = factory.createJsonGenerator(writer);
    generator.writeStartObject();
    generator.writeFieldName("bool");
    generator.writeBoolean(true);
    generator.writeFieldName("firstName");
    generator.writeString("john");
    generator.writeFieldName("age");
    generator.writeNumber(1);
    generator.writeFieldName("gg");
    generator.writeStartObject();
    generator.writeFieldName("firstName");
    generator.writeString("john");
    generator.writeEndObject();

    generator.writeEndObject();
    generator.close();
    String generated = writer.toString();
    System.out.print(generated);

    JsonParser parser = factory.createJsonParser(generated);
    assertTrue(parser.nextToken() == JsonToken.START_OBJECT);
    parser.nextToken();

    assertEquals("bool", parser.getCurrentName());
    assertTrue(parser.nextToken() == JsonToken.VALUE_TRUE);
    parser.nextToken();

    assertEquals("firstName", parser.getCurrentName());
    parser.nextToken();
    assertEquals("john", parser.getText());
    parser.nextToken();

    assertEquals("age", parser.getCurrentName());
    parser.nextToken();
    assertTrue(1 == parser.getIntValue());
    parser.nextToken();

    assertEquals("gg", parser.getCurrentName());
    assertTrue(parser.nextToken() == JsonToken.START_OBJECT);
    parser.nextToken();
    assertEquals("firstName", parser.getCurrentName());
    parser.nextToken();
    assertEquals("john", parser.getText());
    assertTrue(parser.nextToken() == JsonToken.END_OBJECT);

    assertTrue(parser.nextToken() == JsonToken.END_OBJECT);

    parser.close();
  }
 @Override
 public void serialize(
     final HelloResponse helloResponse,
     final JsonGenerator jgen,
     final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(HelloMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(helloResponse.getMessageType().toString().toLowerCase());
   jgen.writeFieldName(HelloMessage.UAID_FIELD);
   jgen.writeString(helloResponse.getUAID().toString());
   jgen.writeEndObject();
 }
Exemplo n.º 9
0
  @Override
  public void serialize(HateoasLinkList value, JsonGenerator jgen, SerializerProvider provider)
      throws IOException {
    jgen.writeStartObject();

    for (HateoasLink link : value) {
      jgen.writeFieldName(link.rel);
      jgen.writeStartObject();
      jgen.writeFieldName("href");
      jgen.writeString(link.href.toExternalForm());
      jgen.writeEndObject();
    }
    jgen.writeEndObject();
  }
Exemplo n.º 10
0
 @Override
 public void serialize(
     final UnregisterResponse unregisterResponse,
     final JsonGenerator jgen,
     final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(RegisterResponse.MESSSAGE_TYPE_FIELD);
   jgen.writeString(unregisterResponse.getMessageType().toString().toLowerCase());
   jgen.writeFieldName(RegisterResponse.CHANNEL_ID_FIELD);
   jgen.writeString(unregisterResponse.getChannelId());
   jgen.writeFieldName(RegisterResponse.STATUS_FIELD);
   jgen.writeNumber(unregisterResponse.getStatus().getCode());
   jgen.writeEndObject();
 }
Exemplo n.º 11
0
 @Override
 public void serialize(
     final HelloMessage hello, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(HelloMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(hello.getMessageType().toString().toLowerCase());
   jgen.writeFieldName(HelloMessage.UAID_FIELD);
   jgen.writeString(hello.getUAID());
   jgen.writeArrayFieldStart(HelloMessage.CHANNEL_IDS_FIELD);
   for (String channelId : hello.getChannelIds()) {
     jgen.writeString(channelId);
   }
   jgen.writeEndArray();
   jgen.writeEndObject();
 }
Exemplo n.º 12
0
 private void writeCollect(SelectSet selectSet) throws IOException {
   writer.writeFieldName("collect");
   writer.writeStartObject();
   writer.writeNumberField("limit", selectSet.getLimit());
   writeDynamicData(selectSet.getData());
   writer.writeEndObject();
 }
 @SuppressWarnings({"unchecked"})
 @Override
 public void serialize(
     final Object value, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException, JsonGenerationException {
   if (null == value) {
     provider.defaultSerializeNull(jgen);
   } else {
     Class<?> type = value.getClass();
     if (ClassUtils.isAssignable(type, Collection.class)) {
       jgen.writeStartArray();
       for (Object o : (Collection) value) {
         write(o, jgen, provider);
       }
       jgen.writeEndArray();
     } else if (ClassUtils.isAssignable(type, Map.class)) {
       jgen.writeStartObject();
       for (Map.Entry<String, Object> entry : ((Map<String, Object>) value).entrySet()) {
         jgen.writeFieldName(entry.getKey());
         write(entry.getValue(), jgen, provider);
       }
       jgen.writeEndObject();
     } else {
       write(value, jgen, provider);
     }
   }
 }
Exemplo n.º 14
0
 private void writeDynamicData(DynamicData data) throws JsonGenerationException, IOException {
   if (data != null) {
     if (data instanceof DynamicObject) {
       DynamicObject obj = (DynamicObject) data;
       if (obj.hasChildren()) {
         writer.writeFieldName(data.getName());
         writer.writeStartObject();
         for (DynamicData child : obj.getChildren()) {
           writeDynamicData(child);
         }
         writer.writeEndObject();
       }
     } else {
       StringBuilder value = new StringBuilder();
       if (data.isHidden()) {
         value.append("hidden->");
       }
       value.append(data.getGuid());
       if (data.isPrimaryKey()) {
         value.append("*");
       }
       writer.writeStringField(data.getName(), value.toString());
     }
   }
 }
Exemplo n.º 15
0
 protected void writeComplexProperty(JsonGenerator jg, Property prop) throws IOException {
   jg.writeStartObject();
   for (Property p : prop.getChildren()) {
     jg.writeFieldName(p.getName());
     writeProperty(jg, p);
   }
   jg.writeEndObject();
 }
Exemplo n.º 16
0
 @Override
 public void serialize(String value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   if (value.startsWith("$")) {
     value = "#" + value.substring(1);
   }
   jgen.writeFieldName(value.replace('.', '-'));
 }
Exemplo n.º 17
0
  public void toJson(JsonGenerator gen) throws IOException {

    gen.writeStartObject();

    if (type != null) {
      gen.writeStringField("type", type.getName());
    }

    if (tableName != null) {
      gen.writeStringField("tableName", tableName);
    }

    if (versionUpdated != -1) {
      gen.writeNumberField("versionUpdated", versionUpdated);
    }

    if (versionCreated != -1) {
      gen.writeNumberField("versionCreated", versionCreated);
    }

    if (recordTypeChanged) {
      gen.writeBooleanField("recordTypeChanged", true);
    }

    if (updatedFields != null && updatedFields.size() > 0) {
      gen.writeArrayFieldStart("updatedFields");
      for (SchemaId updatedField : updatedFields) {
        gen.writeBinary(updatedField.getBytes());
      }
      gen.writeEndArray();
    }

    if (vtagsToIndex != null && vtagsToIndex.size() > 0) {
      gen.writeArrayFieldStart("vtagsToIndex");
      for (SchemaId vtag : vtagsToIndex) {
        gen.writeBinary(vtag.getBytes());
      }
      gen.writeEndArray();
    }

    if (attributes != null && attributes.size() > 0) {
      gen.writeObjectFieldStart("attributes");
      for (String key : attributes.keySet()) {
        gen.writeStringField(key, attributes.get(key));
      }
      gen.writeEndObject();
    }

    if (indexRecordFilterData != null) {
      gen.writeFieldName("indexFilterData");
      indexRecordFilterData.toJson(gen);
    }

    gen.writeEndObject();
    gen.flush();
  }
Exemplo n.º 18
0
 @Override
 public void serialize(
     final AckMessage ack, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(AckMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(ack.getMessageType().toString().toLowerCase());
   jgen.writeArrayFieldStart(AckMessage.UPDATES_FIELD);
   for (Update update : ack.getUpdates()) {
     jgen.writeStartObject();
     jgen.writeFieldName("channelID");
     jgen.writeString(update.getChannelId());
     jgen.writeFieldName(AckMessage.VERSION_FIELD);
     jgen.writeNumber(update.getVersion());
     jgen.writeEndObject();
   }
   jgen.writeEndArray();
   jgen.writeEndObject();
 }
  @Override
  public void serialize(
      PROPERTY_VALUE property_value,
      JsonGenerator jsonGenerator,
      SerializerProvider serializerProvider)
      throws IOException, JsonProcessingException {

    jsonGenerator.writeStartObject();
    jsonGenerator.writeFieldName(property_value.getKey());
    jsonGenerator.writeString(property_value.getValue());
    jsonGenerator.writeEndObject();
  }
Exemplo n.º 20
0
 @Override
 public void serialize(
     final NotificationMessage notification,
     final JsonGenerator jgen,
     final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(NotificationMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(notification.getMessageType().toString().toLowerCase());
   jgen.writeArrayFieldStart(NotificationMessage.UPDATES_FIELD);
   for (Update update : notification.getUpdates()) {
     jgen.writeStartObject();
     jgen.writeFieldName(RegisterMessage.CHANNEL_ID_FIELD);
     jgen.writeString(update.getChannelId());
     jgen.writeFieldName(NotificationMessage.VERSION_FIELD);
     jgen.writeNumber(update.getVersion());
     jgen.writeEndObject();
   }
   jgen.writeEndArray();
   jgen.writeEndObject();
 }
Exemplo n.º 21
0
  @Override
  public void serialize(
      EnumEventField field, JsonGenerator g, SerializerProvider serializerProvider)
      throws IOException {

    // outer objectj
    g.writeStartObject();

    g.writeFieldName(field.interfaceKey);
    // inner object
    g.writeStartObject();
    g.writeStringField("value", field.getValue());
    g.writeFieldName("attributes");
    g.writeObject(field.getAttributes());
    g.writeFieldName("enum");
    g.writeObject(field.getEnums());
    // end inner object
    g.writeEndObject();

    // end outer object
    g.writeEndObject();
  }
 private void write(
     final Object value, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException {
   Class<?> type = value.getClass();
   if (ClassUtils.isAssignable(type, _handledType)) {
     jgen.writeStartObject();
     for (String fname : FluentBeanUtils.metadata(type).fieldNames()) {
       jgen.writeFieldName(fname);
       write(FluentBeanUtils.get(fname, value), jgen, provider);
     }
     jgen.writeEndObject();
   } else {
     jgen.writeObject(value);
   }
 }
Exemplo n.º 23
0
 private void writeScriptData(OrcsScript model) throws IOException {
   Map<String, Object> binding = OrcsScriptUtil.getBinding(model);
   if (binding != null && !binding.isEmpty()) {
     writer.writeFieldName("parameters");
     writer.writeStartObject();
     for (Entry<String, Object> entry : binding.entrySet()) {
       writer.writeStringField(entry.getKey(), String.valueOf(entry.getValue()));
     }
     writer.writeEndObject();
   }
   writer.writeFieldName("script");
   String value = "N/A";
   try {
     if (model != null && model.eAllContents().hasNext()) {
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       OrcsScriptUtil.saveModel(
           model, "orcs:/unknown.orcs", outputStream, OsStorageOption.NO_VALIDATION_ON_SAVE);
       value = outputStream.toString("UTF-8");
     }
   } catch (Exception ex) {
     value = ex.getMessage();
   }
   writer.writeString(value);
 }
 /**
  * Method that can be called to serialize this node and all of its descendants using specified
  * JSON generator.
  */
 @Override
 public final void serialize(JsonGenerator jg, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jg.writeStartObject();
   if (_children != null) {
     for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
       jg.writeFieldName(en.getKey());
       /* 17-Feb-2009, tatu: Can we trust that all nodes will always
        *   extend BaseJsonNode? Or if not, at least implement
        *   JsonSerializable? Let's start with former, change if
        *   we must.
        */
       ((BaseJsonNode) en.getValue()).serialize(jg, provider);
     }
   }
   jg.writeEndObject();
 }