Search in sources :

Example 1 with HInvalidRequestException

use of me.prettyprint.hector.api.exceptions.HInvalidRequestException 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

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