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

The following examples show how to use org.codehaus.jackson.JsonGenerator#writeStartObject() . 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: 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 2
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 3
Source File: ExtensionSerDeserUtils.java    From occurrence with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(List<Map<Term, String>> value, JsonGenerator jgen, SerializerProvider provider)
  throws IOException {
  if ((value == null || value.isEmpty()) && provider.getConfig().isEnabled(Feature.WRITE_EMPTY_JSON_ARRAYS)) {
    jgen.writeStartArray();
    jgen.writeEndArray();
  } else {
    jgen.writeStartArray();
    for (Map<Term, String> extension : value) {
      jgen.writeStartObject();
      for (Entry<Term, String> entry : extension.entrySet()) {
        jgen.writeStringField(entry.getKey().qualifiedName(), entry.getValue());
      }
      jgen.writeEndObject();
    }
    jgen.writeEndArray();
  }
}
 
Example 4
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 5
Source File: AppPackage.java    From Bats 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 6
Source File: QueueManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/***
 * Dumps the configuration of hierarchy of queues with 
 * the xml file path given. It is to be used directly ONLY FOR TESTING.
 * @param out the writer object to which dump is written to.
 * @param configFile the filename of xml file
 * @throws IOException
 */
static void dumpConfiguration(Writer out, String configFile,
    Configuration conf) throws IOException {
  if (conf != null && conf.get(DeprecatedQueueConfigurationParser.
      MAPRED_QUEUE_NAMES_KEY) != null) {
    return;
  }
  
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  QueueConfigurationParser parser;
  boolean aclsEnabled = false;
  if (conf != null) {
    aclsEnabled = conf.getBoolean(MRConfig.MR_ACLS_ENABLED, false);
  }
  if (configFile != null && !"".equals(configFile)) {
    parser = new QueueConfigurationParser(configFile, aclsEnabled);
  }
  else {
    parser = getQueueConfigurationParser(null, false, aclsEnabled);
  }
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("queues");
  dumpGenerator.writeStartArray();
  dumpConfiguration(dumpGenerator,parser.getRoot().getChildren());
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 7
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 8
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 9
Source File: Configuration.java    From flink 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 (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 10
Source File: QueueManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/***
 * Dumps the configuration of hierarchy of queues with 
 * the xml file path given. It is to be used directly ONLY FOR TESTING.
 * @param out the writer object to which dump is written to.
 * @param configFile the filename of xml file
 * @throws IOException
 */
static void dumpConfiguration(Writer out, String configFile,
    Configuration conf) throws IOException {
  if (conf != null && conf.get(DeprecatedQueueConfigurationParser.
      MAPRED_QUEUE_NAMES_KEY) != null) {
    return;
  }
  
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  QueueConfigurationParser parser;
  boolean aclsEnabled = false;
  if (conf != null) {
    aclsEnabled = conf.getBoolean(MRConfig.MR_ACLS_ENABLED, false);
  }
  if (configFile != null && !"".equals(configFile)) {
    parser = new QueueConfigurationParser(configFile, aclsEnabled);
  }
  else {
    parser = getQueueConfigurationParser(null, false, aclsEnabled);
  }
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("queues");
  dumpGenerator.writeStartArray();
  dumpConfiguration(dumpGenerator,parser.getRoot().getChildren());
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 11
Source File: JsonMapper.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
static String toJson(HystrixThreadPoolMetrics threadPoolMetrics) throws IOException {
    HystrixThreadPoolKey key = threadPoolMetrics.getThreadPoolKey();

    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createJsonGenerator(jsonString);
    json.writeStartObject();

    json.writeStringField("type", "HystrixThreadPool");
    json.writeStringField("name", key.name());
    json.writeNumberField("currentTime", System.currentTimeMillis());

    json.writeNumberField("currentActiveCount", threadPoolMetrics.getCurrentActiveCount().intValue());
    json.writeNumberField("currentCompletedTaskCount", threadPoolMetrics.getCurrentCompletedTaskCount().longValue());
    json.writeNumberField("currentCorePoolSize", threadPoolMetrics.getCurrentCorePoolSize().intValue());
    json.writeNumberField("currentLargestPoolSize", threadPoolMetrics.getCurrentLargestPoolSize().intValue());
    json.writeNumberField("currentMaximumPoolSize", threadPoolMetrics.getCurrentMaximumPoolSize().intValue());
    json.writeNumberField("currentPoolSize", threadPoolMetrics.getCurrentPoolSize().intValue());
    json.writeNumberField("currentQueueSize", threadPoolMetrics.getCurrentQueueSize().intValue());
    json.writeNumberField("currentTaskCount", threadPoolMetrics.getCurrentTaskCount().longValue());
    json.writeNumberField("rollingCountThreadsExecuted", threadPoolMetrics.getRollingCountThreadsExecuted());
    json.writeNumberField("rollingMaxActiveThreads", threadPoolMetrics.getRollingMaxActiveThreads());

    json.writeNumberField("propertyValue_queueSizeRejectionThreshold", threadPoolMetrics.getProperties().queueSizeRejectionThreshold().get());
    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", threadPoolMetrics.getProperties().metricsRollingStatisticalWindowInMilliseconds().get());

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

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

    return jsonString.getBuffer().toString();
}
 
Example 12
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 13
Source File: JsonStorage.java    From spork with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void putNext(Tuple t) throws IOException {
    // Build a ByteArrayOutputStream to write the JSON into
    ByteArrayOutputStream baos = new ByteArrayOutputStream(BUF_SIZE);
    // Build the generator
    JsonGenerator json =
        jsonFactory.createJsonGenerator(baos, JsonEncoding.UTF8);

    // Write the beginning of the top level tuple object
    json.writeStartObject();
    
    ResourceFieldSchema[] fields = schema.getFields();
    for (int i = 0; i < fields.length; i++) {
        int tupleLength = t.size();
        //write col if exists in tuple, null otherwise
        if (i < tupleLength) {
            writeField(json, fields[i], t.get(i));
        } else {
            writeField(json, fields[i], null);
        }
    }
    json.writeEndObject();
    json.close();

    // Hand a null key and our string to Hadoop
    try {
        writer.write(null, new Text(baos.toByteArray()));
    } catch (InterruptedException ie) {
        throw new IOException(ie);
    }
}
 
Example 14
Source File: StartupProgressServlet.java    From hadoop 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 15
Source File: ResponseBuilder.java    From ReactiveLab 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();
}
 
Example 16
Source File: ServiceResponseBuilder.java    From WSPerfLab with Apache License 2.0 4 votes vote down vote up
public static ByteArrayOutputStream buildTestAResponse(JsonFactory jsonFactory,
        BackendResponse responseA, BackendResponse responseB,
        BackendResponse responseC, BackendResponse responseD,
        BackendResponse responseE) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(bos);

    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();
    jsonGenerator.close();

    return bos;
}
 
Example 17
Source File: NameNodeLoader.java    From NNAnalytics with Apache License 2.0 4 votes vote down vote up
/**
 * Sends the loading status as JSON to the parameter HTTP response. Copied from NameNode.
 *
 * @param resp the HTTP response
 * @throws IOException error in fetching loading status
 */
public void sendLoadingStatus(HttpServletResponse resp) throws IOException {
  String count = "count";
  String elapsedTime = "elapsedTime";
  String file = "file";
  String name = "name";
  String desc = "desc";
  String percentComplete = "percentComplete";
  String phases = "phases";
  String size = "size";
  String status = "status";
  String steps = "steps";
  String total = "total";

  StartupProgressView view = NameNode.getStartupProgress().createView();
  JsonGenerator json =
      new JsonFactory().createJsonGenerator(resp.getWriter()).useDefaultPrettyPrinter();

  try {
    json.writeStartObject();
    json.writeNumberField(elapsedTime, view.getElapsedTime());
    json.writeNumberField(percentComplete, 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(percentComplete, view.getPercentComplete(phase));
      json.writeNumberField(elapsedTime, 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 stepType = step.getType();
        if (stepType != null) {
          json.writeStringField(name, stepType.getName());
          json.writeStringField(desc, stepType.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(percentComplete, view.getPercentComplete(phase, step));
        json.writeNumberField(elapsedTime, view.getElapsedTime(phase, step));
        json.writeEndObject();
      }

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

    json.writeEndArray();
    json.writeEndObject();
  } finally {
    IOUtils.closeStream(json);
  }
}
 
Example 18
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 19
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 20
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();
    }
  }
}