Java Code Examples for org.codehaus.jackson.JsonGenerator#writeEndObject()

The following examples show how to use org.codehaus.jackson.JsonGenerator#writeEndObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericEntitySerializer.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(GenericEntity entity, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    
    jgen.writeStartObject();
    
    // The SLI API only supports entity body elements for PUT and POST requests. If the
    // entity data has a 'body' element, use that explicitly.
    if (entity.getData().containsKey(ENTITY_BODY_KEY)) {
        jgen.writeObject(serializeObject(entity.getData().get(ENTITY_BODY_KEY)));
        
    } else {
        for (Map.Entry<String, Object> entry : entity.getData().entrySet()) {
            if (entry.getKey().equals(ENTITY_LINKS_KEY) || entry.getKey().equals(ENTITY_METADATA_KEY)) {
                // ignore these read-only fields.
                continue;
            }
            jgen.writeFieldName(entry.getKey());
            jgen.writeObject(serializeObject(entry.getValue()));
        }
    }
    jgen.writeEndObject();
}
 
Example 2
Source File: ObjectMapperProvider.java    From hraven with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Configuration conf, JsonGenerator jsonGenerator,
    SerializerProvider serializerProvider) throws IOException {
  SerializationContext context = RestResource.serializationContext
      .get();
  Predicate<String> configFilter = context.getConfigurationFilter();
  Iterator<Map.Entry<String, String>> keyValueIterator = conf.iterator();

  jsonGenerator.writeStartObject();

  // here's where we can filter out keys if we want
  while (keyValueIterator.hasNext()) {
    Map.Entry<String, String> kvp = keyValueIterator.next();
    if (configFilter == null || configFilter.apply(kvp.getKey())) {
      jsonGenerator.writeFieldName(kvp.getKey());
      jsonGenerator.writeString(kvp.getValue());
    }
  }
  jsonGenerator.writeEndObject();
}
 
Example 3
Source File: AttributesSearchQueryImpl.java    From bintray-client-java with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(AttributesSearchQueryImpl value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {

    jgen.writeStartArray();
    jgen.writeStartObject();
    jgen.writeArrayFieldStart(value.attributeName);

    @SuppressWarnings("unchecked")
    List<AttributesSearchQueryClauseImpl> clauses = value.getQueryClauses();
    for (AttributesSearchQueryClauseImpl clause : clauses) {
        if (clause.getType().equals(Attribute.Type.Boolean)) {
            jgen.writeBoolean((Boolean) clause.getClauseValue());
        } else if (clause.getType().equals(Attribute.Type.number)) {
            jgen.writeNumber(String.valueOf(clause.getClauseValue()));
        } else {  //String or Date
            jgen.writeString((String) clause.getClauseValue());
        }
    }
    jgen.writeEndArray();
    jgen.writeEndObject();
    jgen.writeEndArray();
}
 
Example 4
Source File: ObjectMapperProvider.java    From hraven with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(CounterMap counterMap, JsonGenerator jsonGenerator,
    SerializerProvider serializerProvider) throws IOException {

  jsonGenerator.writeStartObject();
  for (String group : counterMap.getGroups()) {
    jsonGenerator.writeFieldName(group);

    jsonGenerator.writeStartObject();
    Map<String, Counter> groupMap = counterMap.getGroup(group);
    for (String counterName : groupMap.keySet()) {
      Counter counter = groupMap.get(counterName);
      jsonGenerator.writeFieldName(counter.getKey());
      jsonGenerator.writeNumber(counter.getValue());
    }
    jsonGenerator.writeEndObject();
  }
  jsonGenerator.writeEndObject();
}
 
Example 5
Source File: Helper.java    From NNAnalytics with Apache License 2.0 6 votes vote down vote up
/**
 * Write a set of enums out to HTTP Response as a JSON list.
 *
 * @param resp the http response
 * @param values the enums
 * @throws IOException if parsing or writing fails
 */
public static void toJsonList(HttpServletResponse resp, Enum[]... values) throws IOException {
  JsonGenerator json =
      new JsonFactory().createJsonGenerator(resp.getWriter()).useDefaultPrettyPrinter();
  try {
    json.writeStartObject();
    for (int i = 0; i < values.length; i++) {
      Enum[] enumList = values[i];
      json.writeArrayFieldStart("Possibilities " + (i + 1));
      for (Enum value : enumList) {
        if (value != null) {
          json.writeStartObject();
          json.writeStringField("Name", value.name());
          json.writeEndObject();
        }
      }
      json.writeEndArray();
    }
    json.writeEndObject();
  } finally {
    IOUtils.closeStream(json);
  }
}
 
Example 6
Source File: RepositoryImpl.java    From bintray-client-java with Apache License 2.0 6 votes vote down vote up
/**
 * PATCH repo only accepts description and label updates, name is needed for URL creation, because of the special
 * ignore and property structure of the RepositoryDetails class this method just uses a json generator to write
 * the update json.
 */
public static String getUpdateJson(RepositoryDetails repositoryDetails) throws IOException {
    StringWriter writer = new StringWriter();
    JsonGenerator jGen = ObjectMapperHelper.get().getJsonFactory().createJsonGenerator(writer);
    jGen.writeStartObject();
    jGen.writeStringField("name", repositoryDetails.getName());
    jGen.writeStringField("desc", repositoryDetails.getDescription());
    if (repositoryDetails.getLabels().size() > 0) {
        jGen.writeArrayFieldStart("labels");
        for (String label : repositoryDetails.getLabels()) {
            jGen.writeString(label);
        }
        jGen.writeEndArray();
    }
    jGen.writeEndObject();
    jGen.close();
    writer.close();
    return writer.toString();
}
 
Example 7
Source File: SiteToSiteReceiver.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public TransactionCompletion receiveFiles() throws IOException {
    Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE);
    JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output);
    jsonGenerator.writeStartArray();
    DataPacket dataPacket;
    while ((dataPacket = transaction.receive()) != null) {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeFieldName("attributes");
        jsonGenerator.writeStartObject();
        Map<String, String> attributes = dataPacket.getAttributes();
        if (attributes != null) {
            for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) {
                jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue());
            }
        }
        jsonGenerator.writeEndObject();
        InputStream data = dataPacket.getData();
        if (data != null) {
            jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data));
        }
        jsonGenerator.writeEndObject();
    }
    jsonGenerator.writeEndArray();
    jsonGenerator.close();
    transaction.confirm();
    return transaction.complete();
}
 
Example 8
Source File: ServiceResponseBuilder.java    From WSPerfLab with Apache License 2.0 5 votes vote down vote up
public static ByteArrayOutputStream buildTestBResponse(JsonFactory jsonFactory, BackendResponse response)
            throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(bos);

    jsonGenerator.writeStartObject();

    // delay values of each response
    jsonGenerator.writeArrayFieldStart("delay");
    writeTuple(jsonGenerator, "a", response.getDelay());
    jsonGenerator.writeEndArray();

    // itemSize values of each response
    jsonGenerator.writeArrayFieldStart("itemSize");
    writeTuple(jsonGenerator, "a", response.getItemSize());
    jsonGenerator.writeEndArray();

    // numItems values of each response
    jsonGenerator.writeArrayFieldStart("numItems");
    writeTuple(jsonGenerator, "a", response.getNumItems());
    jsonGenerator.writeEndArray();

    // all items from responses
    jsonGenerator.writeArrayFieldStart("items");
    addItemsFromResponse(jsonGenerator, response);
    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
    jsonGenerator.close();

    return bos;
}
 
Example 9
Source File: JMXJsonServlet.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      jg.writeStartArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(jg, item);
      }
      jg.writeEndArray();
    } else if(value instanceof Number) {
      Number n = (Number)value;
      jg.writeNumber(n.toString());
    } else if(value instanceof Boolean) {
      Boolean b = (Boolean)value;
      jg.writeBoolean(b);
    } else if(value instanceof CompositeData) {
      CompositeData cds = (CompositeData)value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      jg.writeStartObject();
      for(String key: keys) {
        writeAttribute(jg, key, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, entry);
      }
      jg.writeEndArray();
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
Example 10
Source File: Configuration.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be 
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] } 
 *  It does not output the parameters of the configuration object which is 
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value", 
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      String[] resources = config.updatingResource.get(item.getKey());
      String resource = UNKNOWN_RESOURCE;
      if(resources != null && resources.length > 0) {
        resource = resources[0];
      }
      dumpGenerator.writeStringField("resource", resource);
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 11
Source File: MediaTypeSerializer.java    From jwala with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final MediaType mediaType, final JsonGenerator generator, final SerializerProvider provider)
        throws IOException {
    generator.writeStartObject();
    generator.writeFieldName("name");
    generator.writeString(mediaType.name());
    generator.writeFieldName("displayName");
    generator.writeString(mediaType.getDisplayName());
    generator.writeEndObject();
}
 
Example 12
Source File: AppPackage.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
    PropertyInfo propertyInfo, JsonGenerator jgen, SerializerProvider provider)
  throws IOException, JsonProcessingException
{
  if (provideDescription) {
    jgen.writeStartObject();
    jgen.writeStringField("value", propertyInfo.value);
    jgen.writeStringField("description", propertyInfo.description);
    jgen.writeEndObject();
  } else {
    jgen.writeString(propertyInfo.value);
  }
}
 
Example 13
Source File: ResponseBuilder.java    From ReactiveLab with Apache License 2.0 4 votes vote down vote up
private static void generateResponse(BackendResponse responseA, BackendResponse responseB, BackendResponse responseC, BackendResponse responseD, BackendResponse responseE, JsonGenerator jsonGenerator) throws IOException, JsonGenerationException {
    jsonGenerator.writeStartObject();
    // multiplication of C, D, E responseKey
    jsonGenerator.writeNumberField("responseKey", responseC.getResponseKey() + responseD.getResponseKey() +
            responseE.getResponseKey());

    // delay values of each response
    jsonGenerator.writeArrayFieldStart("delay");
    writeTuple(jsonGenerator, "a", responseA.getDelay());
    writeTuple(jsonGenerator, "b", responseB.getDelay());
    writeTuple(jsonGenerator, "c", responseC.getDelay());
    writeTuple(jsonGenerator, "d", responseD.getDelay());
    writeTuple(jsonGenerator, "e", responseE.getDelay());
    jsonGenerator.writeEndArray();

    // itemSize values of each response
    jsonGenerator.writeArrayFieldStart("itemSize");
    writeTuple(jsonGenerator, "a", responseA.getItemSize());
    writeTuple(jsonGenerator, "b", responseB.getItemSize());
    writeTuple(jsonGenerator, "c", responseC.getItemSize());
    writeTuple(jsonGenerator, "d", responseD.getItemSize());
    writeTuple(jsonGenerator, "e", responseE.getItemSize());
    jsonGenerator.writeEndArray();

    // numItems values of each response
    jsonGenerator.writeArrayFieldStart("numItems");
    writeTuple(jsonGenerator, "a", responseA.getNumItems());
    writeTuple(jsonGenerator, "b", responseB.getNumItems());
    writeTuple(jsonGenerator, "c", responseC.getNumItems());
    writeTuple(jsonGenerator, "d", responseD.getNumItems());
    writeTuple(jsonGenerator, "e", responseE.getNumItems());
    jsonGenerator.writeEndArray();

    // all items from responses
    jsonGenerator.writeArrayFieldStart("items");
    addItemsFromResponse(jsonGenerator, responseA);
    addItemsFromResponse(jsonGenerator, responseB);
    addItemsFromResponse(jsonGenerator, responseC);
    addItemsFromResponse(jsonGenerator, responseD);
    addItemsFromResponse(jsonGenerator, responseE);
    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
}
 
Example 14
Source File: ObjectMapperProvider.java    From hraven with Apache License 2.0 4 votes vote down vote up
/**
 * checks if the member is to be filtered out or no if filter itself is
 * null, writes out that member
 *
 * @param member
 * @param includeFilter
 * @param jsonGenerator
 * @throws JsonGenerationException
 * @throws IOException
 */
public static void filteredCounterWrite(String member, Predicate<String> includeFilter,
    Predicate<String> includeCounterFilter,
    CounterMap counterMap, JsonGenerator jsonGenerator)
    throws IOException {
  if (includeFilter != null && includeCounterFilter == null) {
    if (includeFilter.apply(member)) {
      jsonGenerator.writeFieldName(member);
      jsonGenerator.writeObject(counterMap);
    }
  } else {
    if (includeCounterFilter != null) {
      // get group name, counter name,
      // check if it is wanted
      // if yes print it.
      boolean startObjectGroupMap = false;
      jsonGenerator.writeFieldName(member);

      String fullCounterName;
      jsonGenerator.writeStartObject();

      for (String group : counterMap.getGroups()) {
        Map<String, Counter> groupMap = counterMap.getGroup(group);
        for (Map.Entry<String, Counter> nameCounterEntry : groupMap.entrySet()) {
          Counter counter = nameCounterEntry.getValue();
          fullCounterName = group + "." + counter.getKey();
          if (includeCounterFilter.apply(fullCounterName)) {
            if (startObjectGroupMap == false) {
              jsonGenerator.writeFieldName(group);
              jsonGenerator.writeStartObject();
              startObjectGroupMap = true;
            }
            jsonGenerator.writeFieldName(counter.getKey());
            jsonGenerator.writeNumber(counter.getValue());
          }
        }
        if (startObjectGroupMap) {
          jsonGenerator.writeEndObject();
          startObjectGroupMap = false;
        }
      }
      jsonGenerator.writeEndObject();
    }
  }
}
 
Example 15
Source File: QueueManager.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * method to perform depth-first search and write the parameters of every 
 * queue in JSON format.
 * @param dumpGenerator JsonGenerator object which takes the dump and flushes
 *  to a writer object
 * @param rootQueues the top-level queues
 * @throws JsonGenerationException
 * @throws IOException
 */
private static void dumpConfiguration(JsonGenerator dumpGenerator,
    Set<Queue> rootQueues) throws JsonGenerationException, IOException {
  for (Queue queue : rootQueues) {
    dumpGenerator.writeStartObject();
    dumpGenerator.writeStringField("name", queue.getName());
    dumpGenerator.writeStringField("state", queue.getState().toString());
    AccessControlList submitJobList = null;
    AccessControlList administerJobsList = null;
    if (queue.getAcls() != null) {
      submitJobList =
        queue.getAcls().get(toFullPropertyName(queue.getName(),
            QueueACL.SUBMIT_JOB.getAclName()));
      administerJobsList =
        queue.getAcls().get(toFullPropertyName(queue.getName(),
            QueueACL.ADMINISTER_JOBS.getAclName()));
    }
    String aclsSubmitJobValue = " ";
    if (submitJobList != null ) {
      aclsSubmitJobValue = submitJobList.getAclString();
    }
    dumpGenerator.writeStringField("acl_submit_job", aclsSubmitJobValue);
    String aclsAdministerValue = " ";
    if (administerJobsList != null) {
      aclsAdministerValue = administerJobsList.getAclString();
    }
    dumpGenerator.writeStringField("acl_administer_jobs",
        aclsAdministerValue);
    dumpGenerator.writeFieldName("properties");
    dumpGenerator.writeStartArray();
    if (queue.getProperties() != null) {
      for (Map.Entry<Object, Object>property :
        queue.getProperties().entrySet()) {
        dumpGenerator.writeStartObject();
        dumpGenerator.writeStringField("key", (String)property.getKey());
        dumpGenerator.writeStringField("value", (String)property.getValue());
        dumpGenerator.writeEndObject();
      }
    }
    dumpGenerator.writeEndArray();
    Set<Queue> childQueues = queue.getChildren();
    dumpGenerator.writeFieldName("children");
    dumpGenerator.writeStartArray();
    if (childQueues != null && childQueues.size() > 0) {
      dumpConfiguration(dumpGenerator, childQueues);
    }
    dumpGenerator.writeEndArray();
    dumpGenerator.writeEndObject();
  }
}
 
Example 16
Source File: JsonMapper.java    From ReactiveLab with Apache License 2.0 4 votes vote down vote up
static String toJson(Metrics commandMetrics) throws IOException {
    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createJsonGenerator(jsonString);

    json.writeStartObject();
    json.writeStringField("type", "HystrixCommand"); // act as this as we are hijacking Hystrix for the dashboard
    json.writeStringField("name", commandMetrics.getName());
    json.writeStringField("group", "");
    json.writeNumberField("currentTime", System.currentTimeMillis());

    json.writeBooleanField("isCircuitBreakerOpen", false);

    long errors = commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.FAILURE);
    long success = commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.SUCCESS);
    long requests = success + errors;
    int errorPercentage = (int) ((double) errors / requests * 100);

    json.writeNumberField("errorPercentage", errorPercentage);
    json.writeNumberField("errorCount", errors);
    json.writeNumberField("requestCount", requests);

    // rolling counters
    json.writeNumberField("rollingCountCollapsedRequests", 0);
    json.writeNumberField("rollingCountExceptionsThrown", commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.EXCEPTION_THROWN));
    json.writeNumberField("rollingCountFailure", errors);
    json.writeNumberField("rollingCountFallbackFailure", 0);
    json.writeNumberField("rollingCountFallbackRejection", 0);
    json.writeNumberField("rollingCountFallbackSuccess", 0);
    json.writeNumberField("rollingCountResponsesFromCache", 0);
    json.writeNumberField("rollingCountSemaphoreRejected", 0);
    json.writeNumberField("rollingCountShortCircuited", 0);
    json.writeNumberField("rollingCountSuccess", success);
    json.writeNumberField("rollingCountThreadPoolRejected", 0);
    json.writeNumberField("rollingCountTimeout", 0);

    json.writeNumberField("currentConcurrentExecutionCount", commandMetrics.getRollingNumber().getRollingMaxValue(Metrics.EventType.CONCURRENCY_MAX_ACTIVE));

    // latency percentiles
    json.writeNumberField("latencyExecute_mean", commandMetrics.getRollingPercentile().getMean());
    json.writeObjectFieldStart("latencyExecute");
    json.writeNumberField("0", commandMetrics.getRollingPercentile().getPercentile(0));
    json.writeNumberField("25", commandMetrics.getRollingPercentile().getPercentile(25));
    json.writeNumberField("50", commandMetrics.getRollingPercentile().getPercentile(50));
    json.writeNumberField("75", commandMetrics.getRollingPercentile().getPercentile(75));
    json.writeNumberField("90", commandMetrics.getRollingPercentile().getPercentile(90));
    json.writeNumberField("95", commandMetrics.getRollingPercentile().getPercentile(95));
    json.writeNumberField("99", commandMetrics.getRollingPercentile().getPercentile(99));
    json.writeNumberField("99.5", commandMetrics.getRollingPercentile().getPercentile(99.5));
    json.writeNumberField("100", commandMetrics.getRollingPercentile().getPercentile(100));
    json.writeEndObject();

    json.writeNumberField("latencyTotal_mean", commandMetrics.getRollingPercentile().getMean());
    json.writeObjectFieldStart("latencyTotal");
    json.writeNumberField("0", commandMetrics.getRollingPercentile().getPercentile(0));
    json.writeNumberField("25", commandMetrics.getRollingPercentile().getPercentile(25));
    json.writeNumberField("50", commandMetrics.getRollingPercentile().getPercentile(50));
    json.writeNumberField("75", commandMetrics.getRollingPercentile().getPercentile(75));
    json.writeNumberField("90", commandMetrics.getRollingPercentile().getPercentile(90));
    json.writeNumberField("95", commandMetrics.getRollingPercentile().getPercentile(95));
    json.writeNumberField("99", commandMetrics.getRollingPercentile().getPercentile(99));
    json.writeNumberField("99.5", commandMetrics.getRollingPercentile().getPercentile(99.5));
    json.writeNumberField("100", commandMetrics.getRollingPercentile().getPercentile(100));
    json.writeEndObject();
    
    json.writeNumberField("propertyValue_circuitBreakerRequestVolumeThreshold", 0);
    json.writeNumberField("propertyValue_circuitBreakerSleepWindowInMilliseconds", 0);
    json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", 0);
    json.writeBooleanField("propertyValue_circuitBreakerForceOpen", false);
    json.writeBooleanField("propertyValue_circuitBreakerForceClosed", false);
    json.writeBooleanField("propertyValue_circuitBreakerEnabled", false);

    json.writeStringField("propertyValue_executionIsolationStrategy", "");
    json.writeNumberField("propertyValue_executionIsolationThreadTimeoutInMilliseconds", 0);
    json.writeBooleanField("propertyValue_executionIsolationThreadInterruptOnTimeout", false);
    json.writeStringField("propertyValue_executionIsolationThreadPoolKeyOverride", "");
    json.writeNumberField("propertyValue_executionIsolationSemaphoreMaxConcurrentRequests", 0);
    json.writeNumberField("propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests", 0);

    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", 10000);

    json.writeBooleanField("propertyValue_requestCacheEnabled", false);
    json.writeBooleanField("propertyValue_requestLogEnabled", false);

    
    json.writeNumberField("reportingHosts", 1); // this will get summed across all instances in a cluster

    json.writeEndObject();
    json.close();

    return jsonString.getBuffer().toString();
}
 
Example 17
Source File: QueueManager.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * method to perform depth-first search and write the parameters of every 
 * queue in JSON format.
 * @param dumpGenerator JsonGenerator object which takes the dump and flushes
 *  to a writer object
 * @param rootQueues the top-level queues
 * @throws JsonGenerationException
 * @throws IOException
 */
private static void dumpConfiguration(JsonGenerator dumpGenerator,
    Set<Queue> rootQueues) throws JsonGenerationException, IOException {
  for (Queue queue : rootQueues) {
    dumpGenerator.writeStartObject();
    dumpGenerator.writeStringField("name", queue.getName());
    dumpGenerator.writeStringField("state", queue.getState().toString());
    AccessControlList submitJobList = null;
    AccessControlList administerJobsList = null;
    if (queue.getAcls() != null) {
      submitJobList =
        queue.getAcls().get(toFullPropertyName(queue.getName(),
            QueueACL.SUBMIT_JOB.getAclName()));
      administerJobsList =
        queue.getAcls().get(toFullPropertyName(queue.getName(),
            QueueACL.ADMINISTER_JOBS.getAclName()));
    }
    String aclsSubmitJobValue = " ";
    if (submitJobList != null ) {
      aclsSubmitJobValue = submitJobList.getAclString();
    }
    dumpGenerator.writeStringField("acl_submit_job", aclsSubmitJobValue);
    String aclsAdministerValue = " ";
    if (administerJobsList != null) {
      aclsAdministerValue = administerJobsList.getAclString();
    }
    dumpGenerator.writeStringField("acl_administer_jobs",
        aclsAdministerValue);
    dumpGenerator.writeFieldName("properties");
    dumpGenerator.writeStartArray();
    if (queue.getProperties() != null) {
      for (Map.Entry<Object, Object>property :
        queue.getProperties().entrySet()) {
        dumpGenerator.writeStartObject();
        dumpGenerator.writeStringField("key", (String)property.getKey());
        dumpGenerator.writeStringField("value", (String)property.getValue());
        dumpGenerator.writeEndObject();
      }
    }
    dumpGenerator.writeEndArray();
    Set<Queue> childQueues = queue.getChildren();
    dumpGenerator.writeFieldName("children");
    dumpGenerator.writeStartArray();
    if (childQueues != null && childQueues.size() > 0) {
      dumpConfiguration(dumpGenerator, childQueues);
    }
    dumpGenerator.writeEndArray();
    dumpGenerator.writeEndObject();
  }
}
 
Example 18
Source File: StartupProgressServlet.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
  resp.setContentType("application/json; charset=UTF-8");
  StartupProgress prog = NameNodeHttpServer.getStartupProgressFromContext(
    getServletContext());
  StartupProgressView view = prog.createView();
  JsonGenerator json = new JsonFactory().createJsonGenerator(resp.getWriter());
  try {
    json.writeStartObject();
    json.writeNumberField(ELAPSED_TIME, view.getElapsedTime());
    json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete());
    json.writeArrayFieldStart(PHASES);

    for (Phase phase: view.getPhases()) {
      json.writeStartObject();
      json.writeStringField(NAME, phase.getName());
      json.writeStringField(DESC, phase.getDescription());
      json.writeStringField(STATUS, view.getStatus(phase).toString());
      json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase));
      json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase));
      writeStringFieldIfNotNull(json, FILE, view.getFile(phase));
      writeNumberFieldIfDefined(json, SIZE, view.getSize(phase));
      json.writeArrayFieldStart(STEPS);

      for (Step step: view.getSteps(phase)) {
        json.writeStartObject();
        StepType type = step.getType();
        if (type != null) {
          json.writeStringField(NAME, type.getName());
          json.writeStringField(DESC, type.getDescription());
        }
        json.writeNumberField(COUNT, view.getCount(phase, step));
        writeStringFieldIfNotNull(json, FILE, step.getFile());
        writeNumberFieldIfDefined(json, SIZE, step.getSize());
        json.writeNumberField(TOTAL, view.getTotal(phase, step));
        json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase,
          step));
        json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase, step));
        json.writeEndObject();
      }

      json.writeEndArray();
      json.writeEndObject();
    }

    json.writeEndArray();
    json.writeEndObject();
  } finally {
    IOUtils.cleanup(LOG, json);
  }
}
 
Example 19
Source File: ObjectMapperProvider.java    From hraven with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(HdfsStats hdfsStats, JsonGenerator jsonGenerator,
    SerializerProvider serializerProvider) throws IOException {

  jsonGenerator.writeStartObject();
  jsonGenerator.writeFieldName("hdfsStatsKey");
  HdfsStatsKey hk = hdfsStats.getHdfsStatsKey();
  QualifiedPathKey qpk = hk.getQualifiedPathKey();
  jsonGenerator.writeStartObject();
  jsonGenerator.writeFieldName("cluster");
  jsonGenerator.writeString(qpk.getCluster());
  if (StringUtils.isNotBlank(qpk.getNamespace())) {
    jsonGenerator.writeFieldName("namespace");
    jsonGenerator.writeString(qpk.getNamespace());
  }
  jsonGenerator.writeFieldName("path");
  jsonGenerator.writeString(qpk.getPath());
  jsonGenerator.writeFieldName("runId");
  jsonGenerator.writeNumber(hk.getRunId());
  jsonGenerator.writeEndObject();
  jsonGenerator.writeFieldName("fileCount");
  jsonGenerator.writeNumber(hdfsStats.getFileCount());
  jsonGenerator.writeFieldName("dirCount");
  jsonGenerator.writeNumber(hdfsStats.getDirCount());
  jsonGenerator.writeFieldName("spaceConsumed");
  jsonGenerator.writeNumber(hdfsStats.getSpaceConsumed());
  jsonGenerator.writeFieldName("owner");
  jsonGenerator.writeString(hdfsStats.getOwner());
  jsonGenerator.writeFieldName("quota");
  jsonGenerator.writeNumber(hdfsStats.getQuota());
  jsonGenerator.writeFieldName("spaceQuota");
  jsonGenerator.writeNumber(hdfsStats.getSpaceQuota());
  jsonGenerator.writeFieldName("trashFileCount");
  jsonGenerator.writeNumber(hdfsStats.getTrashFileCount());
  jsonGenerator.writeFieldName("trashSpaceConsumed");
  jsonGenerator.writeNumber(hdfsStats.getTrashSpaceConsumed());
  jsonGenerator.writeFieldName("tmpFileCount");
  jsonGenerator.writeNumber(hdfsStats.getTmpFileCount());
  jsonGenerator.writeFieldName("tmpSpaceConsumed");
  jsonGenerator.writeNumber(hdfsStats.getTmpSpaceConsumed());
  jsonGenerator.writeFieldName("accessCountTotal");
  jsonGenerator.writeNumber(hdfsStats.getAccessCountTotal());
  jsonGenerator.writeFieldName("accessCost");
  jsonGenerator.writeNumber(hdfsStats.getAccessCost());
  jsonGenerator.writeFieldName("storageCost");
  jsonGenerator.writeNumber(hdfsStats.getStorageCost());
  jsonGenerator.writeFieldName("hdfsCost");
  jsonGenerator.writeNumber(hdfsStats.getHdfsCost());
  jsonGenerator.writeEndObject();
}
 
Example 20
Source File: ServiceResponseBuilder.java    From WSPerfLab with Apache License 2.0 4 votes vote down vote up
private static void writeTuple(JsonGenerator jsonGenerator, String name, int value) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeNumberField(name, value);
    jsonGenerator.writeEndObject();
}