Search in sources :

Example 1 with UUID

use of org.safehaus.uuid.UUID in project logprocessing by cloudian.

the class CDRCassandraSink method append.

/**
    * Writes the message to Cassandra.
    * The key is the current date (YYYYMMDD) and the column
    * name is a type 1 UUID, which includes a time stamp
    * component.
    *
    * CDR format is
    * op,market,tid,mdr_type,msg_ts,imsi,mo_ip,mt_ip,ptn,msg_type,mo_domain,mt_domain
    */
@Override
public void append(Event event) throws IOException {
    if (event.getBody().length > 0) {
        long timestamp = System.currentTimeMillis() * MILLI_TO_MICRO;
        // Make the index column
        UUID uuid = uuidGen.generateTimeBasedUUID();
        Column[] entryColumn = new Column[CDRENTRY_NAME.length];
        String rawEntry = new String(event.getBody());
        String[] rawEntries = rawEntry.split("\\,");
        long longTime = 0;
        String rawTimeLabel = null;
        String webTimeLabel = null;
        String longTimeLabel = null;
        for (int i = 0; i < CDRENTRY_NAME.length; i++) {
            entryColumn[i] = new Column();
            entryColumn[i].setName(CDRENTRY_NAME[i].getBytes());
            if (2 == i) {
                entryColumn[i].setValue(uuid.toString().getBytes());
            } else if (3 == i) {
                try {
                    Date date = m_sdf.parse(rawEntries[CDRENTRY_MAP[i]]);
                    longTime = date.getTime();
                    longTimeLabel = Long.toString(longTime);
                    rawTimeLabel = m_hdf.format(date);
                    longTime = (longTime / 3600000) * 3600000;
                    webTimeLabel = String.format("%013d_%s", longTime, uuid.toString());
                    LOGGER.debug(" webTimeLabel:" + webTimeLabel + " rawColumnFamily:" + rawColumnFamily + " rawTimeLabel:" + rawTimeLabel);
                    entryColumn[i].setValue(longTimeLabel.getBytes());
                } catch (java.text.ParseException e) {
                    System.out.println(e);
                }
            } else {
                entryColumn[i].setValue(rawEntries[CDRENTRY_MAP[i]].getBytes());
            }
            entryColumn[i].setTimestamp(timestamp);
        }
        //MSISDNTimeLine & HourlyTimeLine
        String msisdn = new String(rawEntries[8]);
        Column msisdnTimeLine = new Column();
        msisdnTimeLine.setName(webTimeLabel.getBytes());
        msisdnTimeLine.setValue(uuid.toString().getBytes());
        msisdnTimeLine.setTimestamp(timestamp);
        Column hourlyTimeLine = new Column();
        hourlyTimeLine.setName(webTimeLabel.getBytes());
        hourlyTimeLine.setValue(uuid.toString().getBytes());
        hourlyTimeLine.setTimestamp(timestamp);
        //Rawentry timeline;
        StringBuilder rawFamily = new StringBuilder(rawColumnFamily);
        rawFamily.append("_");
        rawFamily.append(rawEntries[1]);
        Column rawColumn = new Column();
        rawColumn.setName(uuid.toString().getBytes());
        rawColumn.setValue(event.getBody());
        rawColumn.setTimestamp(timestamp);
        //Insert CDREntry
        cClient.insert(uuid.toString().getBytes(), entryColumnFamily, entryColumn, ConsistencyLevel.QUORUM);
        //Insert MSISDNTimeLine
        cClient.insert(msisdn.getBytes(), msisdnColumnFamily, new Column[] { msisdnTimeLine }, ConsistencyLevel.QUORUM);
        //Insert HourlyTimeLine
        cClient.insert(rawTimeLabel.getBytes(), hourlyColumnFamily, new Column[] { hourlyTimeLine }, ConsistencyLevel.QUORUM);
        //Insert raw
        cClient.insert(rawTimeLabel.getBytes(), rawColumnFamily, new Column[] { rawColumn }, ConsistencyLevel.QUORUM);
    }
    super.append(event);
}
Also used : UUID(org.safehaus.uuid.UUID) Date(java.util.Date)

Example 2 with UUID

use of org.safehaus.uuid.UUID in project logprocessing by cloudian.

the class CDRCassandraSink method append.

/**
     * Writes the message to Cassandra.
    * The key is the current date (YYYYMMDD) and the column
    * name is a type 1 UUID, which includes a time stamp
    * component.
    */
@Override
public void append(Event event) throws IOException, InterruptedException {
    if (event.getBody().length > 0) {
        try {
            long timestamp = System.currentTimeMillis() * MILLI_TO_MICRO;
            // Make the index column
            UUID uuid = uuidGen.generateTimeBasedUUID();
            //CDREntry
            //
            //CDR format is
            //
            //op,market,tid,mdr_type,msg_ts,imsi,mo_ip,mt_ip,ptn,msg_type,mo_domain,mt_domain
            String rawEntry = new String(event.getBody());
            logger.debug("RAW: " + rawEntry);
            String[] rawEntries = rawEntry.split("\\,");
            for (int i = 0; i < CDRENTRY_NAME.length; i++) {
                mutator.addInsertion(uuid.toString().getBytes(), CF_ENTRY, createColumn(CDRENTRY_NAME[i].getBytes(), rawEntries[CDRENTRY_MAP[i]].getBytes()));
            }
            //MSISDNTimeLine & HourlyTimeLine
            String msisdn = new String(rawEntries[8]);
            mutator.addInsertion(msisdn.getBytes(), CF_MSISDN, createColumn(Long.toString(timestamp).getBytes(), uuid.toByteArray()));
            mutator.addInsertion(Long.toString(timestamp).getBytes(), CF_HOURLY, createColumn(Long.toString(timestamp).getBytes(), uuid.toByteArray()));
            mutator.addInsertion(uuid.toString().getBytes(), m_CFRawCdr, createColumn(uuid.toByteArray(), event.getBody()));
            mutator.execute();
        } catch (HInvalidRequestException e) {
            e.printStackTrace();
            throw new IOException("Failed to process log entry");
        }
    }
    super.append(event);
}
Also used : HInvalidRequestException(me.prettyprint.hector.api.exceptions.HInvalidRequestException) IOException(java.io.IOException) UUID(org.safehaus.uuid.UUID)

Aggregations

UUID (org.safehaus.uuid.UUID)2 IOException (java.io.IOException)1 Date (java.util.Date)1 HInvalidRequestException (me.prettyprint.hector.api.exceptions.HInvalidRequestException)1