Examples of RowUpdateDescriptor


Examples of org.apache.hadoop.hbase.rest.descriptors.RowUpdateDescriptor

   * (byte[], byte[][])
   */
  public RowUpdateDescriptor getRowUpdateDescriptor(byte[] input,
      byte[][] pathSegments) throws HBaseRestException {

    RowUpdateDescriptor rud = new RowUpdateDescriptor();
    JSONArray a;

    rud.setTableName(Bytes.toString(pathSegments[0]));
    rud.setRowName(Bytes.toString(pathSegments[2]));

    try {
      JSONObject updateObject = new JSONObject(new String(input));
      a = updateObject.getJSONArray(RESTConstants.COLUMNS);
      for (int i = 0; i < a.length(); i++) {
        rud.getColVals().put(
            Bytes.toBytes(a.getJSONObject(i).getString(RESTConstants.NAME)),
            org.apache.hadoop.hbase.util.Base64.decode(a.getJSONObject(i)
                .getString(RESTConstants.VALUE)));
      }
    } catch (JSONException e) {
View Full Code Here

Examples of org.apache.hadoop.hbase.rest.descriptors.RowUpdateDescriptor

  public void post(Status s, byte[][] pathSegments,
      Map<String, String[]> queryMap, byte[] input, IHBaseRestParser parser)
      throws HBaseRestException {
    RowModel innerModel = getModel();

    RowUpdateDescriptor rud = parser
        .getRowUpdateDescriptor(input, pathSegments);

    if (input.length == 0) {
      s.setUnsupportedMediaType("no data send with post request");
      s.respond();
      return;
    }

    Put put = new Put(Bytes.toBytes(rud.getRowName()));

    for (byte[] key : rud.getColVals().keySet()) {
      byte [][] famAndQf = KeyValue.parseColumn(key);
      put.add(famAndQf[0], famAndQf[1], rud.getColVals().get(key));
    }

    try {
      innerModel.post(rud.getTableName().getBytes(), put);
      s.setOK();
    } catch (HBaseRestException e) {
      s.setUnsupportedMediaType(e.getMessage());
    }
    s.respond();
View Full Code Here

Examples of org.apache.hadoop.hbase.rest.descriptors.RowUpdateDescriptor

   * org.apache.hadoop.hbase.rest.parser.IHBaseRestParser#getRowUpdateDescriptor
   * (byte[], byte[][])
   */
  public RowUpdateDescriptor getRowUpdateDescriptor(byte[] input,
      byte[][] pathSegments) throws HBaseRestException {
    RowUpdateDescriptor rud = new RowUpdateDescriptor();

    rud.setTableName(Bytes.toString(pathSegments[0]));
    rud.setRowName(Bytes.toString(pathSegments[2]));

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
        .newInstance();
    docBuilderFactory.setIgnoringComments(true);

    DocumentBuilder builder = null;
    Document doc = null;

    try {
      builder = docBuilderFactory.newDocumentBuilder();
      ByteArrayInputStream is = new ByteArrayInputStream(input);
      doc = builder.parse(is);
    } catch (Exception e) {
      throw new HBaseRestException(e.getMessage(), e);
    }

    NodeList cell_nodes = doc.getElementsByTagName(RESTConstants.COLUMN);
    System.out.println("cell_nodes.length: " + cell_nodes.getLength());
    for (int i = 0; i < cell_nodes.getLength(); i++) {
      String columnName = null;
      byte[] value = null;

      Element cell = (Element) cell_nodes.item(i);

      NodeList item = cell.getElementsByTagName(RESTConstants.NAME);
      if (item.getLength() > 0) {
        columnName = item.item(0).getFirstChild().getNodeValue();
      }

      NodeList item1 = cell.getElementsByTagName(RESTConstants.VALUE);
      if (item1.getLength() > 0) {
        value = org.apache.hadoop.hbase.util.Base64.decode(item1
            .item(0).getFirstChild().getNodeValue());
      }

      if (columnName != null && value != null) {
        rud.getColVals().put(columnName.getBytes(), value);
      }
    }
    return rud;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.