Java Code Examples for me.prettyprint.hector.api.mutation.Mutator#insert()
The following examples show how to use
me.prettyprint.hector.api.mutation.Mutator#insert() .
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: PerfDataAccessor.java From oneops with Apache License 2.0 | 5 votes |
public void insert(Mutator<String> mutator, String key, Map<String, String> columnsMap, String columnFamily, String superColumn) { List<HColumn<String, String>> columns = new ArrayList<HColumn<String, String>>(); for (String name : columnsMap.keySet()) { HFactory.createStringColumn(name, columnsMap.get(name)); } mutator.insert(key, columnFamily, HFactory.createSuperColumn(superColumn, columns, stringSerializer, stringSerializer, stringSerializer)); }
Example 2
Source File: CassandraService.java From usergrid with Apache License 2.0 | 5 votes |
public void setColumn( Keyspace ko, Object columnFamily, Object key, Object columnName, Object columnValue, int ttl ) throws Exception { if ( db_logger.isTraceEnabled() ) { db_logger.trace( "setColumn cf={} key={} name={} value={}", columnFamily, key, columnName, columnValue ); } ByteBuffer name_bytes = null; if ( columnName instanceof List ) { name_bytes = DynamicComposite.toByteBuffer( ( List<?> ) columnName ); } else { name_bytes = bytebuffer( columnName ); } ByteBuffer value_bytes = null; if ( columnValue instanceof List ) { value_bytes = DynamicComposite.toByteBuffer( ( List<?> ) columnValue ); } else { value_bytes = bytebuffer( columnValue ); } HColumn<ByteBuffer, ByteBuffer> col = createColumn( name_bytes, value_bytes, be, be ); if ( ttl != 0 ) { col.setTtl( ttl ); } Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be ); m.insert( bytebuffer( key ), columnFamily.toString(), col ); }
Example 3
Source File: PerfHeaderDao.java From oneops with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public void createHeader(String key, String metricsJson) throws IOException { PerfHeader header = new PerfHeader(); header.setStep(60); PerfArchive.setDefaultArchives(header); logger.info("createHeader:"+key); // write info header List<HColumn<String, String>> columns = Arrays.asList( HFactory.createStringColumn(UPDATED, "0" ), HFactory.createStringColumn(STEP, new Integer(header.getStep()).toString() ), HFactory.createStringColumn(IP, "" ) ); Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(INFO, columns, stringSerializer, stringSerializer, stringSerializer)); logger.debug("write INFO :: UPDATED:"+new Long(header.getUpdated()).toString()+ " STEP:"+new Integer(header.getStep()).toString() + " IP:"+ header.getIp()); String keysPending = "info"; // update datasource headers HashMap<String,HashMap<String,String>> metricMap = mapper.readValue(metricsJson, new TypeReference<Map<String,Map<String,String>>>() { }); for (String metricKey : metricMap.keySet() ) { HashMap<String,String> attrs = metricMap.get(metricKey); String dsType = PerfDatasource.GAUGE; if (attrs.containsKey(DS_TYPE)) { dsType = attrs.get(DS_TYPE); } columns = Arrays.asList( HFactory.createStringColumn(TYPE, dsType ), HFactory.createStringColumn(HEARTBEAT, "300"), HFactory.createStringColumn(MIN, NAN ), HFactory.createStringColumn(MAX, NAN ), HFactory.createStringColumn(LAST, NAN ), HFactory.createStringColumn(INPUT, NAN ), HFactory.createStringColumn(PDP, NAN ) ); mutator.insert(key.getBytes(), HEADER, HFactory .createSuperColumn(metricKey, columns, stringSerializer, stringSerializer, stringSerializer)); keysPending += ", "+metricKey; } Map<String,PerfArchive> rraMap = header.getRraMap(); for (String rraKey : rraMap.keySet() ) { PerfArchive rra = rraMap.get(rraKey); columns = Arrays.asList( HFactory.createStringColumn(CF, rra.getConsolidationFunction() ), HFactory.createStringColumn(XFF, new Double(rra.getXff()).toString() ), HFactory.createStringColumn(STEPS, new Integer(rra.getSteps()).toString() ), HFactory.createStringColumn(ROWS, new Integer(rra.getRows()).toString() ) ); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn( rraKey, columns, stringSerializer, stringSerializer, stringSerializer)); keysPending += ", "+rraKey; } logger.debug("write keys:"+keysPending); // perform the insert mutator.execute(); }
Example 4
Source File: PerfHeaderDao.java From oneops with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public String createSingleHeader(String key, String step, String metricsJson) throws IOException { logger.info("createHeader: "+key+" step: "+step+" metrics: "+metricsJson); PerfHeader header = new PerfHeader(); header.setStep(60); PerfArchive.setDefaultArchives(header); // write info header List<HColumn<String, String>> columns = Arrays.asList( HFactory.createStringColumn(UPDATED, "0"), HFactory.createStringColumn(STEP, "60"), HFactory.createStringColumn(IP, "" ) ); Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(INFO, columns, stringSerializer, stringSerializer, stringSerializer)); logger.debug("write INFO :: UPDATED:"+new Long(header.getUpdated()).toString()+ " STEP:"+new Integer(header.getStep()).toString() + " IP:"+ header.getIp()); String keysPending = "info"; //"metrics":"{\"WriteOperations\":{\"display\":true,\"unit\":\"Per Second\",\"dstype\":\"DERIVE\",\"description\":\"Write Operations\"}}" //"metrics":"{\"ReadOperations\":{\"display\":true,\"unit\":\"per second\",\"dstype\":\"DERIVE\",\"description\":\"Read Operations\"}}" HashMap<String,HashMap<String,String>> metricMap = mapper.readValue(metricsJson, new TypeReference<Map<String,Map<String,String>>>() { }); for (String metricKey : metricMap.keySet() ) { HashMap<String,String> attrs = metricMap.get(metricKey); String dsType = PerfDatasource.GAUGE; if (attrs.containsKey(DS_TYPE)) { dsType = attrs.get(DS_TYPE); } columns = Arrays.asList( HFactory.createStringColumn(TYPE, dsType ), HFactory.createStringColumn(HEARTBEAT, "300" ), HFactory.createStringColumn(MIN, NAN ), HFactory.createStringColumn(MAX, NAN ), HFactory.createStringColumn(LAST, NAN ), HFactory.createStringColumn(INPUT, NAN ), HFactory.createStringColumn(PDP, NAN ) ); mutator.insert(key.getBytes(), HEADER, HFactory .createSuperColumn(metricKey, columns, stringSerializer, stringSerializer, stringSerializer)); keysPending += ", "+metricKey; } Map<String,PerfArchive> rraMap = header.getRraMap(); for (String rraKey : rraMap.keySet() ) { PerfArchive rra = rraMap.get(rraKey); columns = Arrays.asList( HFactory.createStringColumn(CF, rra.getConsolidationFunction() ), HFactory.createStringColumn(XFF, new Double(rra.getXff()).toString() ), HFactory.createStringColumn(STEPS, new Integer(rra.getSteps()).toString() ), HFactory.createStringColumn(ROWS, new Integer(rra.getRows()).toString() ) ); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn( rraKey, columns, stringSerializer, stringSerializer, stringSerializer)); keysPending += ", "+rraKey; } logger.debug("write keys:"+keysPending); // perform the insert mutator.execute(); return "{\"result_code\":200}\n"; }
Example 5
Source File: PerfHeaderDao.java From oneops with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public void putHeader(String key, PerfHeader header, Mutator<byte[]> mutator) { headerCache.put(key, header); // write info header List<HColumn<String, String>> columns = Arrays.asList( HFactory.createStringColumn(UPDATED, Long.valueOf(header.getUpdated()).toString() ), HFactory.createStringColumn(STEP, Integer.valueOf(header.getStep()).toString() ), HFactory.createStringColumn(IP, header.getIp() )); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(INFO, columns, stringSerializer, stringSerializer, stringSerializer)); logger.debug("write INFO :: UPDATED:"+ Long.valueOf(header.getUpdated()) + " STEP:"+ Integer.valueOf(header.getStep()).toString() + " IP:"+ header.getIp()); // update datasource headers Map<String,PerfDatasource> dsMap = header.getDsMap(); for (String dsKey : dsMap.keySet() ) { PerfDatasource ds = dsMap.get(dsKey); columns = Arrays.asList( HFactory.createStringColumn(TYPE, ds.getType() ), HFactory.createStringColumn(HEARTBEAT, Integer.valueOf(ds.getHeartbeat()).toString() ), HFactory.createStringColumn(MIN, Double.valueOf(ds.getMin() ).toString() ), HFactory.createStringColumn(MAX, Double.valueOf(ds.getMax() ).toString() ), HFactory.createStringColumn(LAST, Double.valueOf(ds.getLast() ).toString() ), HFactory.createStringColumn(INPUT, Double.valueOf(ds.getInput() ).toString() ), HFactory.createStringColumn(PDP, Double.valueOf(ds.getPdp() ).toString() ) ); logger.debug("setting ds header last:"+ ds.getLast()); mutator.insert(key.getBytes(), HEADER, HFactory .createSuperColumn(dsKey, columns, stringSerializer, stringSerializer, stringSerializer)); } Map<String,Double> cdpMap = header.getCdpMap(); columns = new ArrayList<HColumn<String, String>>(); for (String cdpKey: cdpMap.keySet()) { String value = cdpMap.get(cdpKey).toString(); if (value != null) columns.add(HFactory.createStringColumn(cdpKey, value )); if (cdpKey.contains(LOGBUCKET)) { logger.debug("CDP PUT: "+cdpKey +" "+cdpMap.get(cdpKey).toString()); } } mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn( CDP, columns, stringSerializer, stringSerializer, stringSerializer)); }