Package org.apache.hadoop.chukwa.extraction.engine

Examples of org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord


  public void parse(String line, OutputCollector<Text, ChukwaRecord> output,
      Reporter reporter)
  {
    log.info("record: [" + line + "] type[" + chunk.getDataType() + "]");
   
    ChukwaRecord record = new ChukwaRecord();
    buildGenericRecord(record,line, System.currentTimeMillis(),recordType);
    key.set("" + chunk.getSeqID());
    try
    {
      output.collect(key, record);
View Full Code Here


      log.info("JobLogHistoryProcessor Matches");

      try
      {
        Date d = sdf.parse(matcher.group(1).trim());
        ChukwaRecord record = new ChukwaRecord();

        logLevel = matcher.group(2);
        className = matcher.group(3);
        body = matcher.group(4);

        key.set("" + d.getTime());
       
        record.add(Record.logLevelField, logLevel);
        record.add(Record.classField, className);
       
        int firstSep = body.indexOf(" ");
        String logEntryType = body.substring(0,firstSep);
        record.add(jobEntryTypeField, logEntryType);
       
        internalMatcher.reset(body.substring(firstSep));
        String fieldName = null;
        String fieldValue = null;
        while (internalMatcher.matches())
        {
          fieldName = internalMatcher.group(1).trim();
          fieldValue = internalMatcher.group(2).trim();
          record.add(fieldName, fieldValue);
          log.info("JobLogHistoryProcessor Add field: [" + fieldName + "][" + fieldValue +"]" );
          internalMatcher.reset(internalMatcher.group(3));
        }

        buildGenericRecord(record, body, d.getTime(), JobLogHistoryProcessor.recordType);
View Full Code Here

      try
      {
        Date d = sdf.parse(matcher.group(1).trim());
        System.out.println(d);
        ChukwaRecord record = new ChukwaRecord();

        String logLevel = matcher.group(2);
        String className = matcher.group(3);
        String body = matcher.group(4);

        System.out.println(matcher.group(1));
        System.out.println(matcher.group(2));
        System.out.println(matcher.group(3));
        System.out.println(matcher.group(4));
       
        System.out.println(body);
       
        record.add(Record.logLevelField, logLevel);
        record.add(Record.classField, className);
       
        int firstSep = body.indexOf(" ");
        System.out.println(firstSep);
        String logEntryType = body.substring(0,firstSep);
        record.add(jobEntryTypeField, logEntryType);
       
        internalMatcher.reset(body.substring(firstSep));
        String fieldName = null;
        String fieldValue = null;
        while (internalMatcher.matches())
        {
          fieldName = internalMatcher.group(1).trim();
          fieldValue = internalMatcher.group(2).trim();
          record.add(fieldName, fieldValue);
          System.out.println("JobLogHistoryProcessor Add field: [" + fieldName + "][" + fieldValue +"]" );
          internalMatcher.reset(internalMatcher.group(3));
        }

       
View Full Code Here

    int totalDownNode = 0;
   
    String logLevel = null;
    String className = null;
    String body = null;
    ChukwaRecord record = null;
   
    matcher.reset(recordEntry);
    if (matcher.matches())
    {
      log.info("PbsNodeProcessor Matches");
     
      try
      {
        Date d = sdf.parse( matcher.group(0).trim());
       
        logLevel = matcher.group(2);
        className = matcher.group(3);
        body = matcher.group(4);
       
        // Raw PBS output
        /*
          record = new ChukwaRecord();
        buildGenericRecord(record,recordEntry,d.getTime(),rawPBSRecordType);
       
        //TODO create a more specific key structure
        // part of ChukwaArchiveKey + record index if needed
        key.set("" + d.getTime());
       
        record.add(Record.logLevelField, logLevel);
        record.add(Record.classField, className);
        record.add(Record.bodyField, body);
        //Output PbsNode record for all machines (raw information)
        output.collect(key, record);
        log.info("PbsNodeProcessor output 1 record");
        */
       
        // TODO if we're not saving the PBS' output, we don't need to parse and save it ...
        String[] lines = recordEntry.split("\n");
        while (i < lines.length)
        {
          while ((i < lines.length) && (lines[i].trim().length() > 0))
          {
            sb.append(lines[i].trim()).append("\n");
            i++;
          }

           if ( (i< lines.length) && (lines[i].trim().length() > 0) )
           {
           throw new PbsInvalidEntry(recordEntry);
           }

          // Empty line
          i++;

          if (sb.length() > 0)
          {
            body =  sb.toString();
            // Process all entries for a machine
            System.out.println("=========>>> Record [" + body+ "]");
           
            record = new ChukwaRecord();
            buildGenericRecord(record,body,d.getTime(),machinePBSRecordType);
           
            // TODO Change the key information
            key.set("" + d.getTime());
            record.add(Record.logLevelField, logLevel);
            record.add(Record.classField, className);
            record.add(Record.bodyField, body);
           
            parsePbsRecord(body, record);
           
            //Output PbsNode record for 1 machine
            output.collect(key, record);
            log.info("PbsNodeProcessor output 1 sub-record");
            //compute Node Activity information
            nodeActivityStatus = record.getValue("state");
            if (nodeActivityStatus != null)
            {
              if (nodeActivityStatus.equals("free"))
              {
                totalFreeNode ++;
View Full Code Here

  public void parse(String line, OutputCollector<Text, ChukwaRecord> output,
      Reporter reporter)
  {
    log.info("record: [" + line + "] type[" + chunk.getDataType() + "]");
   
    ChukwaRecord record = new ChukwaRecord();
   
    matcher.reset(line);
    if (matcher.matches())
    {
      try
      {
        Date d = sdf.parse( matcher.group(0).trim());
        if (this.chunk.getStreamName().indexOf("datanode") > 0)
        {
          buildGenericRecord(record,line,d.getTime(),dataNodeType);
        }
        else if (this.chunk.getStreamName().indexOf("namenode") > 0)
        {
          buildGenericRecord(record,line,d.getTime(),nameNodeType);
        }
        else
        {
          buildGenericRecord(record,line,d.getTime(),recordType);
        }
       
        key.set("" + d.getTime());
        record.add(Record.logLevelField, "" +matcher.group(2));
        record.add(Record.classField, "" +matcher.group(3));
        record.add(Record.bodyField, "" +matcher.group(4));
        output.collect(key, record);
      }
      catch (ParseException e)
      {
        e.printStackTrace();
View Full Code Here

  }

  public Tuple getNext() throws IOException
  {
    ChukwaRecord record = new ChukwaRecord();
    if (!reader.next(reader.createKey(), record))
      return null;

    Tuple ret = tf.newTuple(2);
    try
    {
      ret.set(0, new Long(record.getTime()));

      HashMap<Object, Object> pigMapFields = new HashMap<Object, Object>();
      TreeMap<String, Buffer> mapFields = record.getMapFields();

      if (mapFields != null)
      {
        for (String key : mapFields.keySet())
        {
          pigMapFields.put(key, new DataByteArray(record.getValue(key).getBytes()));
        }
      }
      ret.set(1, pigMapFields);

    } catch (ExecException e)
View Full Code Here

    {

      ChukwaRecordKey key = new ChukwaRecordKey();
    

      ChukwaRecord record = new ChukwaRecord();
      record.setTime(System.currentTimeMillis());
      int inputSize = f.size();     
      for(int i=0;i<inputSize;i++) {
        Object field = f.get(i);
       
        if (field == null) {
          continue;
        }
       
        if (i == this.pkFieldIndex) {
          pk = field.toString();
          continue;
        } else if ( i == this.sourceFieldIndex) {
          source = field.toString();
          continue;
         
        }else if ( i== this.recordTypeFieldIndex) {
          recordType = field.toString();
          continue;
         
        }else if ( i== this.applicationFieldIndex) {
          application = field.toString();
          continue;
         
        } else if ( i== this.clusterNameFieldIndex) {
          clusterName = field.toString();
          continue;
         
        }else if (i == this.timestampFieldIndex) {
         
          timestamp = Long.parseLong(field.toString());
          record.setTime(timestamp);

          synchronized (calendar)
          {
            calendar.setTimeInMillis(timestamp);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            timePartition = calendar.getTimeInMillis();
          }
          record.setTime(Long.parseLong(field.toString()));
          continue;
         
        else if (field instanceof Map) {
          Map<Object, Object> m = (Map<Object, Object>)field;
          for(Object o: m.keySet()) {
            record.add(o.toString(),m.get(o).toString());
          }
          continue;
        } else {
          if (i <fields.length ) {
            record.add(fields[i],field.toString());
          } else {
            record.add("field-"+i,field.toString());
          }
         
          continue;
        }
      }

      record.add(Record.tagsField, " cluster=\"" + clusterName.trim() + "\" ");
      record.add(Record.sourceField, source);
      record.add(Record.applicationField, application);
      key.setKey("" + timePartition + "/" + pk + "/" + timestamp);
      key.setReduceType(recordType);
     
      writer.append(key, record);
    } catch (ExecException e)
View Full Code Here

      String jobID = "";
        matcher = jobPattern.matcher(capp);
        if(matcher.matches()) {
          jobID=matcher.group(2);
        }
        ChukwaRecord record = new ChukwaRecord();
        ChukwaRecord jobConfRecord = new ChukwaRecord();
      DocumentBuilderFactory docBuilderFactory
        = DocumentBuilderFactory.newInstance();
      //ignore all comments inside the xml file
      docBuilderFactory.setIgnoringComments(true);
      try {
          DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
          Document doc = null;
          String fileName = "test_"+randomNumber.nextInt();
          File tmp = new File(fileName);
          FileOutputStream out = new FileOutputStream(tmp);
          out.write(recordEntry.getBytes());
          out.close();
        doc = builder.parse(fileName);
        Element root = doc.getDocumentElement();
        if (!"configuration".equals(root.getTagName()))
            log.fatal("bad conf file: top-level element not <configuration>");
        NodeList props = root.getChildNodes();
            JSONObject json = new JSONObject();
            String queue = "default";
   
        for (int i = 0; i < props.getLength(); i++) {
            Node propNode = props.item(i);
            if (!(propNode instanceof Element))
                continue;
            Element prop = (Element)propNode;
            if (!"property".equals(prop.getTagName()))
                log.warn("bad conf file: element not <property>");
            NodeList fields = prop.getChildNodes();
            String attr = null;
            String value = null;
            boolean finalParameter = false;
            for (int j = 0; j < fields.getLength(); j++) {
                Node fieldNode = fields.item(j);
                if (!(fieldNode instanceof Element))
                    continue;
                Element field = (Element)fieldNode;
                if ("name".equals(field.getTagName()) && field.hasChildNodes())
                    attr = ((Text)field.getFirstChild()).getData().trim();
                if ("value".equals(field.getTagName()) && field.hasChildNodes())
                    value = ((Text)field.getFirstChild()).getData();
                if ("final".equals(field.getTagName()) && field.hasChildNodes())
                    finalParameter = "true".equals(((Text)field.getFirstChild()).getData());
            }
           
            // Ignore this parameter if it has already been marked as 'final'
            if (attr != null && value != null) {
                json.put(attr, value);
                if(attr.intern()=="mapred.job.queue.name".intern()) {
                    queue=value;
                }
                jobConfRecord.add("job_conf." + attr, value);
            }
        }
        record.add("JOBCONF-JSON", json.toString());
        record.add("mapred.job.queue.name", queue);
        record.add("JOBID", "job_" + jobID);
        buildGenericRecord(record, null, time, "JobData");
        calendar.setTimeInMillis(time);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        key.setKey("" + calendar.getTimeInMillis() + "/job_" + jobID + "/" + time);
        output.collect(key, record);

        jobConfRecord.add("JOBID", "job_" + jobID);
        buildGenericRecord(jobConfRecord, null, time, "JobConfData");
        output.collect(key, jobConfRecord);
           
        tmp.delete();
      } catch(Exception e) {
View Full Code Here

      log.debug("Parser Open [" + fileName + "]");

      long timestamp = 0;
      int listSize = 0;
      ChukwaRecordKey key = new ChukwaRecordKey();
      ChukwaRecord record = new ChukwaRecord();

      r = new SequenceFile.Reader(fs, new Path(fileName), conf);

      log.debug("readData Open2 [" + fileName + "]");
      if ((fileName.equals(res.fileName)) && (res.position != -1)) {
        r.seek(res.position);
      }
      res.fileName = fileName;

      while (r.next(key, record)) {
        if (record != null) {
          res.position = r.getPosition();

          timestamp = record.getTime();
          res.currentTs = timestamp;
          log.debug("\nSearch for startDate: " + new Date(t0) + " is :"
              + new Date(timestamp));

          if (timestamp < t0) {
            // log.debug("Line not in range. Skipping: " +record);
            continue;
          } else if (timestamp < t1) {
            log.debug("In Range: " + record.toString());
            boolean valid = false;

            if ((filter == null || filter.equals(""))) {
              valid = true;
            } else if (isValid(record, filter)) {
              valid = true;
            }

            if (valid) {
              records.add(record);
              record = new ChukwaRecord();
              listSize = records.size();
              if (listSize >= maxRows) {
                // maxRow so stop here
                // Update token
                token.key = key.getKey();
View Full Code Here

      if (stmt.execute(query)) {
        rs = stmt.getResultSet();
        ResultSetMetaData rmeta = rs.getMetaData();
        int col = rmeta.getColumnCount();
        while (rs.next()) {
          ChukwaRecord event = new ChukwaRecord();
          String cell = "";
          long timestamp = 0;

          for (int i = 1; i < col; i++) {
            String value = rs.getString(i);
            if (value != null) {
              cell = cell + " " + rmeta.getColumnName(i) + ":" + value;
            }
            if (rmeta.getColumnName(i).equals(timeField)) {
              timestamp = rs.getLong(i);
              event.setTime(timestamp);
            }
          }
          boolean isValid = false;
          if (filter == null || filter.equals("")) {
            isValid = true;
          } else if (cell.indexOf(filter) > 0) {
            isValid = true;
          }
          if (!isValid) {
            continue;
          }

          event.add(Record.bodyField, cell);
          event.add(Record.sourceField, cluster + "." + dataSource);
          if (records.containsKey(timestamp)) {
            records.get(timestamp).add(event);
          } else {
            List<Record> list = new LinkedList<Record>();
            list.add(event);
            records.put(event.getTime(), list);
          }
        }
      }
    } catch (SQLException e) {
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord

Copyright © 2018 www.massapicom. 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.