org.codehaus.jackson.JsonFactory Java Examples

The following examples show how to use org.codehaus.jackson.JsonFactory. 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: TestJacksonMarshalling.java    From Eagle with Apache License 2.0 6 votes vote down vote up
@Test
public void testComplexMapMarshalling(){
	Map<List<String>, String> map = new HashMap<List<String>, String>();
	map.put(Arrays.asList("cluster1","dc1"), "123");
	map.put(Arrays.asList("cluster1","dc1"), "456");
	
	JsonFactory factory = new JsonFactory(); 
    ObjectMapper mapper = new ObjectMapper(factory);
    String result = null;
    try{
    	result = mapper.writeValueAsString(map);
    }catch(Exception ex){
    	LOG.error("Cannot marshall", ex);
    	Assert.fail("Cannot marshall a complex map");
    }
    System.out.println(result);
}
 
Example #2
Source File: RemoteTableJoinExample.java    From samza-hello-samza with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<Double> getAsync(String symbol) {
  return CompletableFuture.supplyAsync(() -> {
    try {
      URL url = new URL(String.format(URL_TEMPLATE, symbol));
      String response = HttpUtil.read(url, 5000, new ExponentialSleepStrategy());
      JsonParser parser = new JsonFactory().createJsonParser(response);
      while (!parser.isClosed()) {
        if (JsonToken.FIELD_NAME.equals(parser.nextToken()) && "4. close".equalsIgnoreCase(parser.getCurrentName())) {
          return Double.valueOf(parser.nextTextValue());
        }
      }
      return -1d;
    } catch (Exception ex) {
      throw new SamzaException(ex);
    }
  });
}
 
Example #3
Source File: TestJacksonMarshalling.java    From Eagle with Apache License 2.0 6 votes vote down vote up
@Test
public void testPojoMarshalling(){
	Pojo p = new Pojo();
	p.setField1("field1");
	p.setField2("field2");
	
	JsonFactory factory = new JsonFactory(); 
    ObjectMapper mapper = new ObjectMapper(factory);
    String result = null;
    try{
    	result = mapper.writeValueAsString(p);
    }catch(Exception ex){
    	LOG.error("Cannot marshall", ex);
    	Assert.fail("Cannot marshall a Pojo");
    }
    System.out.println(result);
    Assert.assertEquals("{\"field1\":\"field1\",\"field2\":\"field2\"}", result);
}
 
Example #4
Source File: SLSUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * parse the input node file, return each host name
 */
public static Set<String> parseNodesFromNodeFile(String nodeFile)
        throws IOException {
  Set<String> nodeSet = new HashSet<String>();
  JsonFactory jsonF = new JsonFactory();
  ObjectMapper mapper = new ObjectMapper();
  Reader input = new FileReader(nodeFile);
  try {
    Iterator<Map> i = mapper.readValues(
            jsonF.createJsonParser(input), Map.class);
    while (i.hasNext()) {
      Map jsonE = i.next();
      String rack = "/" + jsonE.get("rack");
      List tasks = (List) jsonE.get("nodes");
      for (Object o : tasks) {
        Map jsonNode = (Map) o;
        nodeSet.add(rack + "/" + jsonNode.get("node"));
      }
    }
  } finally {
    input.close();
  }
  return nodeSet;
}
 
Example #5
Source File: RumenToSLSConverter.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  Reader input = new FileReader(inputFile);
  try {
    Writer output = new FileWriter(outputFile);
    try {
      ObjectMapper mapper = new ObjectMapper();
      ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
      Iterator<Map> i = mapper.readValues(
              new JsonFactory().createJsonParser(input), Map.class);
      while (i.hasNext()) {
        Map m = i.next();
        output.write(writer.writeValueAsString(createSLSJob(m)) + EOL);
      }
    } finally {
      output.close();
    }
  } finally {
    input.close();
  }
}
 
Example #6
Source File: TestJacksonMarshalling.java    From Eagle with Apache License 2.0 6 votes vote down vote up
@Test
public void testPojoArrayMashalling(){
	Pojo[] ps = new Pojo[2];
	ps[0] = new Pojo();
	ps[0].setField1("0_field1");
	ps[0].setField2("0_field2");
	ps[1] = new Pojo();
	ps[1].setField1("1_field1");
	ps[1].setField2("1_field2");
	
	JsonFactory factory = new JsonFactory(); 
    ObjectMapper mapper = new ObjectMapper(factory);
    String result = null;
    try{
    	result = mapper.writeValueAsString(ps);
    }catch(Exception ex){
    	LOG.error("Cannot marshall", ex);
    	Assert.fail("Cannot marshall a Pojo array");
    }
    System.out.println(result);
    Assert.assertEquals("[{\"field1\":\"0_field1\",\"field2\":\"0_field2\"},{\"field1\":\"1_field1\",\"field2\":\"1_field2\"}]", result);
}
 
Example #7
Source File: StatePool.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void write(DataOutput out) throws IOException {
  // This is just a JSON experiment
  System.out.println("Dumping the StatePool's in JSON format.");
  ObjectMapper outMapper = new ObjectMapper();
  outMapper.configure(
      SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
  // define a module
  SimpleModule module = new SimpleModule("State Serializer",  
      new Version(0, 1, 1, "FINAL"));
  // add the state serializer
  //module.addSerializer(State.class, new StateSerializer());

  // register the module with the object-mapper
  outMapper.registerModule(module);

  JsonFactory outFactory = outMapper.getJsonFactory();
  JsonGenerator jGen = 
    outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8);
  jGen.useDefaultPrettyPrinter();

  jGen.writeObject(this);
  jGen.close();
}
 
Example #8
Source File: JsonStorage.java    From spork with Apache License 2.0 6 votes vote down vote up
@Override
public void prepareToWrite(RecordWriter writer) throws IOException {
    // Store the record writer reference so we can use it when it's time
    // to write tuples
    this.writer = writer;

    // Get the schema string from the UDFContext object.
    UDFContext udfc = UDFContext.getUDFContext();
    Properties p =
        udfc.getUDFProperties(this.getClass(), new String[]{udfcSignature});
    String strSchema = p.getProperty(SCHEMA_SIGNATURE);
    if (strSchema == null) {
        throw new IOException("Could not find schema in UDF context");
    }

    // Parse the schema from the string stored in the properties object.
    schema = new ResourceSchema(Utils.getSchemaFromString(strSchema));

    // Build a Json factory
    jsonFactory = new JsonFactory();
}
 
Example #9
Source File: JsonLoader.java    From spork with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void prepareToRead(RecordReader reader, PigSplit split)
throws IOException {
    this.reader = reader;
    
    // Get the schema string from the UDFContext object.
    UDFContext udfc = UDFContext.getUDFContext();
    Properties p =
        udfc.getUDFProperties(this.getClass(), new String[]{udfcSignature});
    String strSchema = p.getProperty(SCHEMA_SIGNATURE);
    if (strSchema == null) {
        throw new IOException("Could not find schema in UDF context");
    }

    // Parse the schema from the string stored in the properties object.
    schema = new ResourceSchema(Utils.getSchemaFromString(strSchema));

    jsonFactory = new JsonFactory();
}
 
Example #10
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 #11
Source File: TaggerServiceImpl.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
private int getCurrentRetrainingThreshold() throws Exception {
	try {
		String retrainingThreshold = this.getRetainingThreshold();

		ObjectMapper mapper = JacksonWrapper.getObjectMapper();
		JsonFactory factory = mapper.getJsonFactory(); // since 2.1 use
														// mapper.getFactory()
														// instead
		JsonParser jp = factory.createJsonParser(retrainingThreshold);
		JsonNode actualObj = mapper.readTree(jp);

		JsonNode nameNode = actualObj.get("sampleCountThreshold");

		int sampleCountThreshold = Integer.parseInt(nameNode.asText());

		return sampleCountThreshold;
	} catch (Exception e) {
		logger.error("Exception while getting CurrentRetrainingThreshold", e);
		return 50;

	}
}
 
Example #12
Source File: Configuration.java    From RDFS with Apache License 2.0 6 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()));
      dumpGenerator.writeStringField("resource",
                                     config.updatingResource.get(item.getKey()));
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example #13
Source File: AbstractSiteToSiteReportingTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
public JsonRecordReader(final InputStream in, RecordSchema recordSchema) throws IOException, MalformedRecordException {
    this.recordSchema = recordSchema;
    try {
        jsonParser = new JsonFactory().createJsonParser(in);
        jsonParser.setCodec(new ObjectMapper());
        JsonToken token = jsonParser.nextToken();
        if (token == JsonToken.START_ARRAY) {
            array = true;
            token = jsonParser.nextToken();
        } else {
            array = false;
        }
        if (token == JsonToken.START_OBJECT) {
            firstJsonNode = jsonParser.readValueAsTree();
        } else {
            firstJsonNode = null;
        }
    } catch (final JsonParseException e) {
        throw new MalformedRecordException("Could not parse data as JSON", e);
    }
}
 
Example #14
Source File: JsonUtils.java    From binlake with Apache License 2.0 6 votes vote down vote up
public static JsonNode parseJson(String json) throws Exception {

		ObjectMapper mapper = new ObjectMapper();	
		JsonFactory f = new MappingJsonFactory();
		JsonParser jp = null;
		JsonNode rootNode = null;
		try {
			jp = f.createJsonParser(json);
			rootNode = mapper.readTree(jp);
		} catch (Exception e) {
			throw e;
		} finally {
			if (jp != null)
				jp.close();
		}
		return rootNode;
	}
 
Example #15
Source File: GlobalJsonAuthorization.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Override
public void setupProvider(BlurConfiguration config) throws Exception {

  String securityFile = config.get("blur.console.authorization.provider.globaljson.file");

  if (securityFile != null) {
    JsonFactory factory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(factory);
    File from = new File(securityFile);
    TypeReference<Map<String, Map<String, String>>> typeRef = new TypeReference<Map<String, Map<String, String>>>() {
    };

    try {
      Map<String, Map<String, String>> properties = mapper.readValue(from, typeRef);
      globalUserProperties = Collections.unmodifiableMap(properties);
    } catch (Exception e) {
      log.error("Unable to parse security file.  Search may not work right.", e);
      globalUserProperties = null;
    }
  }
}
 
Example #16
Source File: Display.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public AvroFileInputStream(FileStatus status) throws IOException {
  pos = 0;
  buffer = new byte[0];
  GenericDatumReader<Object> reader = new GenericDatumReader<Object>();
  FileContext fc = FileContext.getFileContext(new Configuration());
  fileReader =
    DataFileReader.openReader(new AvroFSInput(fc, status.getPath()),reader);
  Schema schema = fileReader.getSchema();
  writer = new GenericDatumWriter<Object>(schema);
  output = new ByteArrayOutputStream();
  JsonGenerator generator =
    new JsonFactory().createJsonGenerator(output, JsonEncoding.UTF8);
  MinimalPrettyPrinter prettyPrinter = new MinimalPrettyPrinter();
  prettyPrinter.setRootValueSeparator(System.getProperty("line.separator"));
  generator.setPrettyPrinter(prettyPrinter);
  encoder = EncoderFactory.get().jsonEncoder(schema, generator);
}
 
Example #17
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private com.esri.core.geometry.Geometry constructGeometry(com.esri.ges.spatial.Geometry geo) throws Exception
{
	try{
		String jsonIn = geo.toJson();
		JsonFactory jf = new JsonFactory();
		JsonParser jp = jf.createJsonParser(jsonIn);
		MapGeometry mgeo = GeometryEngine.jsonToGeometry(jp);
		com.esri.core.geometry.Geometry geoIn= mgeo.getGeometry();
		return GeometryEngine.project(geoIn, srIn, srBuffer);
	}
	catch(Exception e)
	{
		LOG.error(e.getMessage());
		LOG.error(e.getStackTrace());
		throw(e);
	}
}
 
Example #18
Source File: TestJacksonMarshalling.java    From Eagle with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapMapMarshalling(){
	Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
	Map<String, String> childmap1 = new HashMap<String, String>();
	childmap1.put("dc1", "123");
	childmap1.put("dc1", "456");
	map.put("cluster1", childmap1);
	
	JsonFactory factory = new JsonFactory(); 
    ObjectMapper mapper = new ObjectMapper(factory);
    String result = null;
    try{
    	result = mapper.writeValueAsString(map);
    }catch(Exception ex){
    	LOG.error("Cannot marshall", ex);
    	Assert.fail("Cannot marshall a complex map");
    }
    System.out.println(result);
}
 
Example #19
Source File: AvroJson.java    From brooklin with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Convert the HashMap {@code _info} into an AvroSchema
 * This involves using the Avro Parser which will ensure the entire
 * schema is properly formatted
 *
 * If the Schema is not formatted properly, this function will throw an
 * error
 */
public Schema toSchema() throws SchemaGenerationException {
  try {
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory factory = new JsonFactory();
    StringWriter writer = new StringWriter();
    JsonGenerator jgen = factory.createJsonGenerator(writer);
    jgen.useDefaultPrettyPrinter();
    mapper.writeValue(jgen, _info);
    String schema = writer.getBuffer().toString();

    return Schema.parse(schema);
  } catch (IOException e) {
    throw new SchemaGenerationException("Failed to generate Schema from AvroJson", e);
  }
}
 
Example #20
Source File: BarFileUtils.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * barファイルエントリからJSONファイルを読み込む.
 * @param <T> JSONMappedObject
 * @param inStream barファイルエントリのInputStream
 * @param entryName entryName
 * @param clazz clazz
 * @return JSONファイルから読み込んだオブジェクト
 * @throws IOException JSONファイル読み込みエラー
 */
public static <T> T readJsonEntry(
        InputStream inStream, String entryName, Class<T> clazz) throws IOException {
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    jp = f.createJsonParser(inStream);
    JsonToken token = jp.nextToken(); // JSONルート要素("{")
    Pattern formatPattern = Pattern.compile(".*/+(.*)");
    Matcher formatMatcher = formatPattern.matcher(entryName);
    String jsonName = formatMatcher.replaceAll("$1");
    T json = null;
    if (token == JsonToken.START_OBJECT) {
        try {
            json = mapper.readValue(jp, clazz);
        } catch (UnrecognizedPropertyException ex) {
            throw DcCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
        }
    } else {
        throw DcCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
    }
    return json;
}
 
Example #21
Source File: BarFileValidateTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * DefaultPathを指定しない場合に例外がスローされる.
 */
@Test
@SuppressWarnings({"unchecked" })
public void DefaultPathを指定しない場合に例外がスローされる() {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("box_version", "1");
    json.put("schema", "http://app1.example.com");

    try {
        JsonParser jp = f.createJsonParser(json.toJSONString());
        ObjectMapper mapper = new ObjectMapper();
        jp.nextToken();

        TestBarRunner testBarRunner = new TestBarRunner();
        testBarRunner.manifestJsonValidate(jp, mapper);
    } catch (DcCoreException dce) {
        assertEquals(400, dce.getStatus());
        assertEquals("PR400-BI-0006", dce.getCode());
        return;
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
    fail("DcCoreExceptionが返却されない");
}
 
Example #22
Source File: BarFileValidateTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * box_versionを指定しない場合に例外がスローされる.
 */
@Test
@SuppressWarnings({"unchecked" })
public void box_versionを指定しない場合に例外がスローされる() {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "http://app1.example.com");

    try {
        JsonParser jp = f.createJsonParser(json.toJSONString());
        ObjectMapper mapper = new ObjectMapper();
        jp.nextToken();

        TestBarRunner testBarRunner = new TestBarRunner();
        testBarRunner.manifestJsonValidate(jp, mapper);
    } catch (DcCoreException dce) {
        assertEquals(400, dce.getStatus());
        assertEquals("PR400-BI-0006", dce.getCode());
        return;
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
    fail("DcCoreExceptionが返却されない");
}
 
Example #23
Source File: EventResource.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * リクエストボディを解析してEventオブジェクトを取得する.
 * @param reader Http入力ストリーム
 * @return 解析したEventオブジェクト
 */
protected JSONEvent getRequestBody(final Reader reader) {
    JSONEvent event = null;
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    try {
        jp = f.createJsonParser(reader);
        JsonToken token = jp.nextToken(); // JSONルート要素("{")
        if (token == JsonToken.START_OBJECT) {
            event = mapper.readValue(jp, JSONEvent.class);
        } else {
            throw DcCoreException.Event.JSON_PARSE_ERROR;
        }
    } catch (IOException e) {
        throw DcCoreException.Event.JSON_PARSE_ERROR;
    }
    return event;
}
 
Example #24
Source File: Display.java    From big-c with Apache License 2.0 6 votes vote down vote up
public AvroFileInputStream(FileStatus status) throws IOException {
  pos = 0;
  buffer = new byte[0];
  GenericDatumReader<Object> reader = new GenericDatumReader<Object>();
  FileContext fc = FileContext.getFileContext(new Configuration());
  fileReader =
    DataFileReader.openReader(new AvroFSInput(fc, status.getPath()),reader);
  Schema schema = fileReader.getSchema();
  writer = new GenericDatumWriter<Object>(schema);
  output = new ByteArrayOutputStream();
  JsonGenerator generator =
    new JsonFactory().createJsonGenerator(output, JsonEncoding.UTF8);
  MinimalPrettyPrinter prettyPrinter = new MinimalPrettyPrinter();
  prettyPrinter.setRootValueSeparator(System.getProperty("line.separator"));
  generator.setPrettyPrinter(prettyPrinter);
  encoder = EncoderFactory.get().jsonEncoder(schema, generator);
}
 
Example #25
Source File: JSONManifestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * manifest.jsonのschema値がURL形式である場合trueが返却されること.
 * @throws IOException IOException
 */
@SuppressWarnings("unchecked")
@Test
public void manifest_jsonのschema値がURL形式である場合trueが返却されること() throws IOException {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "http://app1.example.com/");
    JsonParser jp = f.createJsonParser(json.toJSONString());
    ObjectMapper mapper = new ObjectMapper();
    jp.nextToken();

    JSONManifest manifest = mapper.readValue(jp, JSONManifest.class);

    assertTrue(manifest.checkSchema());
}
 
Example #26
Source File: StatePool.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void write(DataOutput out) throws IOException {
  // This is just a JSON experiment
  System.out.println("Dumping the StatePool's in JSON format.");
  ObjectMapper outMapper = new ObjectMapper();
  outMapper.configure(
      SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
  // define a module
  SimpleModule module = new SimpleModule("State Serializer",  
      new Version(0, 1, 1, "FINAL"));
  // add the state serializer
  //module.addSerializer(State.class, new StateSerializer());

  // register the module with the object-mapper
  outMapper.registerModule(module);

  JsonFactory outFactory = outMapper.getJsonFactory();
  JsonGenerator jGen = 
    outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8);
  jGen.useDefaultPrettyPrinter();

  jGen.writeObject(this);
  jGen.close();
}
 
Example #27
Source File: JSONManifestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * manifest_jsonのschema値がnull場合falseが返却されること.
 * @throws IOException IOException
 */
@SuppressWarnings("unchecked")
@Test
public void manifest_jsonのschema値がnull場合falseが返却されること() throws IOException {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", null);
    JsonParser jp = f.createJsonParser(json.toJSONString());
    ObjectMapper mapper = new ObjectMapper();
    jp.nextToken();

    JSONManifest manifest = mapper.readValue(jp, JSONManifest.class);

    assertFalse(manifest.checkSchema());
}
 
Example #28
Source File: SLSUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * parse the sls trace file, return each host name
 */
public static Set<String> parseNodesFromSLSTrace(String jobTrace)
        throws IOException {
  Set<String> nodeSet = new HashSet<String>();
  JsonFactory jsonF = new JsonFactory();
  ObjectMapper mapper = new ObjectMapper();
  Reader input = new FileReader(jobTrace);
  try {
    Iterator<Map> i = mapper.readValues(
            jsonF.createJsonParser(input), Map.class);
    while (i.hasNext()) {
      Map jsonE = i.next();
      List tasks = (List) jsonE.get("job.tasks");
      for (Object o : tasks) {
        Map jsonTask = (Map) o;
        String hostname = jsonTask.get("container.host").toString();
        nodeSet.add(hostname);
      }
    }
  } finally {
    input.close();
  }
  return nodeSet;
}
 
Example #29
Source File: SLSUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * parse the input node file, return each host name
 */
public static Set<String> parseNodesFromNodeFile(String nodeFile)
        throws IOException {
  Set<String> nodeSet = new HashSet<String>();
  JsonFactory jsonF = new JsonFactory();
  ObjectMapper mapper = new ObjectMapper();
  Reader input = new FileReader(nodeFile);
  try {
    Iterator<Map> i = mapper.readValues(
            jsonF.createJsonParser(input), Map.class);
    while (i.hasNext()) {
      Map jsonE = i.next();
      String rack = "/" + jsonE.get("rack");
      List tasks = (List) jsonE.get("nodes");
      for (Object o : tasks) {
        Map jsonNode = (Map) o;
        nodeSet.add(rack + "/" + jsonNode.get("node"));
      }
    }
  } finally {
    input.close();
  }
  return nodeSet;
}
 
Example #30
Source File: JSONManifestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * manifest_jsonのschema値がURL形式でない場合falseが返却されること.
 * @throws IOException IOException
 */
@SuppressWarnings("unchecked")
@Test
public void manifest_jsonのschema値がURL形式でない場合falseが返却されること() throws IOException {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "test");
    JsonParser jp = f.createJsonParser(json.toJSONString());
    ObjectMapper mapper = new ObjectMapper();
    jp.nextToken();

    JSONManifest manifest = mapper.readValue(jp, JSONManifest.class);

    assertFalse(manifest.checkSchema());
}