Java Code Examples for storm.trident.tuple.TridentTuple

The following are top voted examples for showing how to use storm.trident.tuple.TridentTuple. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: rb-bi   File: TridentKafkaState.java   Source Code and License 6 votes vote down vote up
public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
    String topic = null;
    for (TridentTuple tuple : tuples) {
        try {
            topic = topicSelector.getTopic(tuple);

            if(topic != null) {
                producer.send(new KeyedMessage(topic, mapper.getKeyFromTuple(tuple),
                        mapper.getMessageFromTuple(tuple)));
            } else {
                LOG.warn("skipping key = " + mapper.getKeyFromTuple(tuple) + ", topic selector returned null.");
            }
        } catch (Exception ex) {
            String errorMsg = "Could not send message with key = " + mapper.getKeyFromTuple(tuple)
                    + " to topic = " + topic;
            LOG.warn(errorMsg, ex);
            throw new FailedException(errorMsg, ex);
        }
    }
}
 
Example 2
Project: rb-bi   File: GetRadiusClient.java   Source Code and License 6 votes vote down vote up
/**
 * <p>This function get the radius client from radius event.</p>
 * @author Andres Gomez
 */
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String, Object> radiusData = (Map<String, Object>) tuple.getValue(0);

    String clientMac = radiusData.get("Calling-Station-Id").toString();
    clientMac = clientMac.replace("-", ":");
    
    Map<String, Object> radiusMap = new HashMap<>();
    
    radiusMap.put("client_mac", clientMac);
    
    if (_debug) {
        System.out.println(GetRadiusClient.class +" - Radius client to query: " + clientMac);
    }
    
    collector.emit(new Values(radiusMap));
}
 
Example 3
Project: rb-bi   File: MapperFunction.java   Source Code and License 6 votes vote down vote up
/**
 * <p>This function converts a JSON events to JAVA Map.</p>
 */
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String jsonEvent = tuple.getString(0);
    if (jsonEvent != null && jsonEvent.length() > 0) {
        Map<String, Object> event = null;
        try {
            event = _mapper.readValue(jsonEvent, Map.class);
            _metric.incrEvent();
        } catch (IOException | NullPointerException ex) {
            Logger.getLogger(MapperFunction.class.getName()).log(Level.SEVERE, "Failed converting a JSON tuple to a Map class [ " + _metricName + " ] \n"
                    + " JSON tuple: " + jsonEvent, ex);
        }
        if (event != null)
            collector.emit(new Values(event));
    }
}
 
Example 4
Project: rb-bi   File: SplitMSE10Data.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String , Object> mseData = (Map<String, Object>) tuple.get(0);
    List<Map<String, Object>> notifications = (List<Map<String, Object>>) mseData.get("notifications");

    for (Map<String, Object> notification : notifications){
        if(notification.get("notificationType").equals("association")){
            logger.fine("Mse10 event this event is a association, emitting: [" + notification.size() + ", " + "null]");
            collector.emit(new Values(notification, null));
        }else if(notification.get("notificationType").equals("locationupdate")){
            logger.fine("Mse10 event this event is a locationupdate, emitting: [null" + ", " + notification.size() + "]");
            collector.emit(new Values(null, notification));
        }else{
            Logger.getLogger(SplitMSE10Data.class.getName()).log(Level.WARNING, "MSE version 10 notificationType is unknown: " + notification.get("notificationType"));
        }
    }
}
 
Example 5
Project: rb-bi   File: MemcachedEventsLocationMseQuery.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        result.remove("client_rssi");
        result.remove("client_rssi_num");
        result.remove("client_snr");
        result.remove("client_snr_num");
        result.remove("dot11_status");
        result.remove("wireless_id");

        collector.emit(new Values(result));
    }
}
 
Example 6
Project: rb-bi   File: MemcachedUpdater.java   Source Code and License 6 votes vote down vote up
@Override
public void updateState(MapState<Map<String, Object>> state, List<TridentTuple> tuples, TridentCollector collector) {
    List<Map<String, Object>> events = Lists.newArrayList();
    List<List<Object>> keys = Lists.newArrayList();
    for (TridentTuple t : tuples) {
        if(t!=null) {
            List<Object> l = Lists.newArrayList();
            l.add(_generalKey + t.getValueByField(_key));
            keys.add(l);
            events.add((Map<String, Object>) t.getValueByField(_value));

            //System.out.println("SAVED TO MEMCACHED KEY: " + _generalKey +t.getValueByField(_key) +
            //      " VALUE: " + t.getValueByField(_value));
        }
    }
    
    try {
        state.multiPut(keys, events);
    } catch (ReportedFailedException e) {
        Logger.getLogger(MemcachedUpdater.class.getName()).log(Level.WARNING, null, e);
    }
}
 
Example 7
Project: rb-bi   File: RiakUpdater.java   Source Code and License 6 votes vote down vote up
@Override
public void updateState(MapState<Map<String, Object>> state, List<TridentTuple> tuples, TridentCollector collector) {
    List<Map<String, Object>> events = new ArrayList<>();
    List<List<Object>> keys = new ArrayList<>();
    for (TridentTuple t : tuples) {
        if (t != null) {
            List<Object> l = new ArrayList<>();
            l.add(_generalKey + t.getValueByField(_key));
            keys.add(l);
            if (t.getValueByField(_value) != null)
                events.add((Map<String, Object>) t.getValueByField(_value));

            if (_debug) {
                System.out.println("SAVED TO RIAK KEY: " + _generalKey + t.getValueByField(_key)
                        + " VALUE: " + t.getValueByField(_value));
            }
        }
    }

    try {
        if (!events.isEmpty())
            state.multiPut(keys, events);
    } catch (ReportedFailedException e) {
        Logger.getLogger(RiakUpdater.class.getName()).log(Level.WARNING, null, e);
    }
}
 
Example 8
Project: rb-bi   File: RiakEventsLocationMseQuery.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        result.remove("client_rssi");
        result.remove("client_rssi_num");
        result.remove("client_snr");
        result.remove("client_snr_num");
        result.remove("dot11_status");
        result.remove("wireless_id");

        collector.emit(new Values(result));
    }
}
 
Example 9
Project: rb-bi   File: GridGainEventsLocationMseQuery.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        result.remove("client_rssi");
        result.remove("client_rssi_num");
        result.remove("client_snr");
        result.remove("client_snr_num");
        result.remove("dot11_status");
        result.remove("wireless_id");

        collector.emit(new Values(result));
    }
}
 
Example 10
Project: rb-bi   File: MacLocallyAdministeredFilter.java   Source Code and License 6 votes vote down vote up
@Override
public boolean isKeep(TridentTuple tuple) {
    String mac = tuple.getStringByField("src_mac");
    boolean status = true;

    if(mac!=null) {
        String macSplit[] = mac.split(":");
        String macHex = macSplit[0];

        // if (_debug)
        //    System.out.println("HEX: " + macHex);

        String binary = hexToBin(macHex);

        if (binary.endsWith("10") || binary.endsWith("11"))
            status = false;

        // if (_debug) {
        //     System.out.println("BIN: " + binary);
        //     System.out.println("TRUE/FALSE: " + status);
        // }
    }
    return status;
}
 
Example 11
Project: storm-scheduler   File: IncreaseHashByOneFunction.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String currentValue;
    int newHashModValue;
    String newValue;
    int currentTry;

    currentTry = 0;
    currentValue = tuple.getString(0);
    newHashModValue = (currentValue.hashCode() % this.numPartitions) + 1;
    newHashModValue = newHashModValue % this.numPartitions;  // rotate back to 0 if necessary

    do {
        newValue = UUID.randomUUID().toString();

        if (currentTry++ >= maxTry) {
            throw new RuntimeException("Couldn't find a value for hash/mod " + newHashModValue +
                    " in " + maxTry + " attempts. Current value is " + newValue +
                    " Number of partitions: " + this.numPartitions);
        }

    } while ((newValue.hashCode() % this.numPartitions) != newHashModValue);

    collector.emit(new Values(newValue));
}
 
Example 12
Project: storm-hbase-1.0.x   File: HBaseState.java   Source Code and License 6 votes vote down vote up
public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
    List<Mutation> mutations = Lists.newArrayList();

    for (TridentTuple tuple : tuples) {
        byte[] rowKey = options.mapper.rowKey(tuple);
        ColumnList cols = options.mapper.columns(tuple);
        mutations.addAll(hBaseClient.constructMutationReq(rowKey, cols, options.durability));
    }

    try {
        hBaseClient.batchMutate(mutations);
    } catch (Exception e) {
        LOG.warn("Batch write failed but some requests might have succeeded. Triggering replay.", e);
        throw new FailedException(e);
    }
}
 
Example 13
Project: storm-hbase-1.0.x   File: HBaseState.java   Source Code and License 6 votes vote down vote up
public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
    List<List<Values>> batchRetrieveResult = Lists.newArrayList();
    List<Get> gets = Lists.newArrayList();
    for (TridentTuple tuple : tridentTuples) {
        byte[] rowKey = options.mapper.rowKey(tuple);
        gets.add(hBaseClient.constructGetRequests(rowKey, options.projectionCriteria));
    }

    try {
        Result[] results = hBaseClient.batchGet(gets);
        for(Result result : results) {
            List<Values> values = options.rowToStormValueMapper.toValues(result);
            batchRetrieveResult.add(values);
        }
    } catch (Exception e) {
        LOG.warn("Batch get operation failed. Triggering replay.", e);
        throw new FailedException(e);
    }
    return batchRetrieveResult;
}
 
Example 14
Project: jstrom   File: StateQueryProcessor.java   Source Code and License 6 votes vote down vote up
@Override
public void finishBatch(ProcessorContext processorContext) {
    BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
    if (!state.tuples.isEmpty()) {
        List<Object> results = _function.batchRetrieve(_state, state.args);
        if (results.size() != state.tuples.size()) {
            throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
        }
        for (int i = 0; i < state.tuples.size(); i++) {
            TridentTuple tuple = state.tuples.get(i);
            Object result = results.get(i);
            _collector.setContext(processorContext, tuple);
            _function.execute(_projection.create(tuple), result, _collector);
        }
    }
}
 
Example 15
Project: realtime-event-processing   File: GetAdFreeWebPage.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(TridentTuple tridentTuple, TridentCollector tridentCollector) {
    String url = tridentTuple.getString(0);

    Readability readability = null;
    Integer timeoutMillis = 5000;

    try {
        readability = new Readability(new URL(url), timeoutMillis);  // URL
        readability.init();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return;
    }

    String webPageString = readability.content; //readability.outerHtml();
    String webPageTitle = readability.title;
    String hrefString = readability.hrefString.toString();

    //System.out.println("GetAdFreeWebPage: hrefString: \""+ hrefString+"\"");
    tridentCollector.emit(new Values(webPageString, webPageTitle, hrefString));
}
 
Example 16
Project: realtime-event-processing   File: PrepareHrefKafka.java   Source Code and License 6 votes vote down vote up
@Override
    public void execute(TridentTuple tridentTuple, TridentCollector tridentCollector) {
        String hrefList = tridentTuple.getString(0);
        Integer depth = Integer.parseInt(tridentTuple.getString(1));

        if(hrefList == null || hrefList.trim().length() == 0 || depth == 0)
            return;
        depth--;

//        System.out.println("PrepareHrefKafka: \""+hrefList+"\"");

        String[] hrefArray = hrefList.split(" ");
        for(String href : hrefArray) {
            tridentCollector.emit(new Values(href, depth.toString()));
        }
    }
 
Example 17
Project: Tstream   File: StateQueryProcessor.java   Source Code and License 6 votes vote down vote up
@Override
public void finishBatch(ProcessorContext processorContext) {
    BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
    if(!state.tuples.isEmpty()) {
        List<Object> results = _function.batchRetrieve(_state, state.args);
        if(results.size()!=state.tuples.size()) {
            throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
        }
        for(int i=0; i<state.tuples.size(); i++) {
            TridentTuple tuple = state.tuples.get(i);
            Object result = results.get(i);
            _collector.setContext(processorContext, tuple);
            _function.execute(_projection.create(tuple), result, _collector);            
        }
    }
}
 
Example 18
Project: jstorm-0.9.6.3-   File: StateQueryProcessor.java   Source Code and License 6 votes vote down vote up
@Override
public void finishBatch(ProcessorContext processorContext) {
    BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
    if(!state.tuples.isEmpty()) {
        List<Object> results = _function.batchRetrieve(_state, state.args);
        if(results.size()!=state.tuples.size()) {
            throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
        }
        for(int i=0; i<state.tuples.size(); i++) {
            TridentTuple tuple = state.tuples.get(i);
            Object result = results.get(i);
            _collector.setContext(processorContext, tuple);
            _function.execute(_projection.create(tuple), result, _collector);            
        }
    }
}
 
Example 19
Project: jstorm-0.9.6.3-   File: PartitionPersistProcessor.java   Source Code and License 6 votes vote down vote up
@Override
public void finishBatch(ProcessorContext processorContext) {
    _collector.setContext(processorContext);
    Object batchId = processorContext.batchId;
    // since this processor type is a committer, this occurs in the commit phase
    List<TridentTuple> buffer = (List) processorContext.state[_context.getStateIndex()];
    
    // don't update unless there are tuples
    // this helps out with things like global partition persist, where multiple tasks may still
    // exist for this processor. Only want the global one to do anything
    // this is also a helpful optimization that state implementations don't need to manually do
    if(buffer.size() > 0) {
        Long txid = null;
        // this is to support things like persisting off of drpc stream, which is inherently unreliable
        // and won't have a tx attempt
        if(batchId instanceof TransactionAttempt) {
            txid = ((TransactionAttempt) batchId).getTransactionId();
        }
        _state.beginCommit(txid);
        _updater.updateState(_state, buffer, _collector);
        _state.commit(txid);
    }
}
 
Example 20
Project: learn_jstorm   File: MapCombinerAggStateUpdater.java   Source Code and License 6 votes vote down vote up
@Override
public void updateState(MapState map, List<TridentTuple> tuples, TridentCollector collector) {
    List<List<Object>> groups = new ArrayList<List<Object>>(tuples.size());
    List<ValueUpdater> updaters = new ArrayList<ValueUpdater>(tuples.size());
            
    for(TridentTuple t: tuples) {
        groups.add(_groupFactory.create(t));
        updaters.add(new CombinerValueUpdater(_agg,_inputFactory.create(t).getValue(0)));
    }
    List<Object> newVals = map.multiUpdate(groups, updaters);
   
    for(int i=0; i<tuples.size(); i++) {
        List<Object> key = groups.get(i);
        Object result = newVals.get(i);            
        collector.emit(_factory.create(new List[] {key, new Values(result) }));
    }
}
 
Example 21
Project: web-crawler   File: SplitKafkaInput.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(TridentTuple tridentTuple, TridentCollector tridentCollector) {
    String kafkaInput = tridentTuple.getString(0);

    String url;
    Integer depth;

    String[] tokens = kafkaInput.split(" ");
    if(tokens.length == 2){
        url = tokens[0];
        depth = Integer.parseInt(tokens[1]);
    } else if (tokens.length == 1){
        url = tokens[0];
        depth = new Integer(0);
    } else {
        return;
    }
    tridentCollector.emit(new Values(url, depth) );
}
 
Example 22
Project: jstrom   File: JoinerMultiReducer.java   Source Code and License 6 votes vote down vote up
private void emitCrossJoin(JoinState state, TridentCollector collector, int overrideIndex, TridentTuple overrideTuple) {
    List<List>[] sides = state.sides;
    int[] indices = state.indices;
    for (int i = 0; i < indices.length; i++) {
        indices[i] = 0;
    }

    boolean keepGoing = true;
    // emit cross-join of all emitted tuples
    while (keepGoing) {
        List[] combined = new List[sides.length + 1];
        combined[0] = state.group;
        for (int i = 0; i < sides.length; i++) {
            if (i == overrideIndex) {
                combined[i + 1] = overrideTuple;
            } else {
                combined[i + 1] = sides[i].get(indices[i]);
            }
        }
        collector.emit(_factory.create(combined));
        keepGoing = increment(sides, indices, indices.length - 1, overrideIndex);
    }
}
 
Example 23
Project: realtime-event-processing   File: PrepareDocForElasticSearch.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {

    String file = tuple.getString(0).replaceAll("\\s+","");
    String task = tuple.getString(1);
    String user = tuple.getString(2);
    String content = JSONObject.escape(tuple.getString(3));

    JSONObject json = new JSONObject();
    json.put("file",file);
    json.put("task",task);
    json.put("user",user);
    json.put("content",content);

    collector.emit(new Values(esIndex,task,file,json.toJSONString()));
}
 
Example 24
Project: rb-bi   File: SiddhiState.java   Source Code and License 5 votes vote down vote up
public void sendToSiddhi(TridentTuple tuple) {
        String section = tuple.getStringByField("sections");
        Map<String, Object> map = (Map<String, Object>) tuple.getValueByField("maps");
        for (int i = 0; i < _inputsHandler.get(section).size(); i++) {
            try {
                _inputsHandler.get(section).get(i).send(mapToArray(map, section, i).toArray());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
}
 
Example 25
Project: rb-bi   File: KafkaStateUpdater.java   Source Code and License 5 votes vote down vote up
@Override
public void updateState(KafkaState state, List<TridentTuple> tuples,
        TridentCollector collector) {
    for (TridentTuple t : tuples) {            
        try {
            if (t.size() > 0) {
                state.send(_topic, t.getStringByField(_messageFieldName));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
 
Example 26
Project: rb-bi   File: ThroughputLoggingFilter.java   Source Code and License 5 votes vote down vote up
@Override
public boolean isKeep(TridentTuple tuple) {
    Long timestamp = System.currentTimeMillis() / 1000;

    if(_count.containsKey(timestamp)) {
        Integer count = _count.get(timestamp);
        _count.put(timestamp, count + 1);
    } else {
        if (_count.containsKey(timestamp - 1)) {
            int msgs = _count.get(timestamp - 1);
            //System.out.println(msgs);

            if (_sec_count <= 60) {
                _mean += msgs;
            } else {
                _mean = _mean / 60;

                if (_totalMean == 0) {
                    _totalMean = _mean;
                } else {
                    _totalMean = (_totalMean + _mean) / 2;
                }

                System.out.println("STATS THROUGHPUT [ "+ _position +" ] - MINUTE MEAN " + _mean);
                System.out.println("STATS THROUGHPUT [ "+ _position +" ] - TOTAL MEAN " + _totalMean);

                _sec_count = 0;
                _mean = 0;
            }
        }

        _count.put(timestamp, 1);
        _sec_count += 1;
    }

    return true;
}
 
Example 27
Project: rb-bi   File: PrinterFunction.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    List<Object> list = tuple.getValues();
    for (Object o : list) {
        System.out.println(_str + " " + o.toString());
    }

}
 
Example 28
Project: rb-bi   File: MapToJSONFunction.java   Source Code and License 5 votes vote down vote up
/**
 * <p>This function converts a JAVA Map to JSON events.</p>
 */
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String eventJSON = "";
    try {
        eventJSON = _mapper.writeValueAsString((Map<String, Object>) tuple.getValue(0));
    } catch (IOException ex) {
        Logger.getLogger(MapToJSONFunction.class.getName()).log(Level.SEVERE, null, ex);
    }

    collector.emit(new Values(eventJSON));
}
 
Example 29
Project: rb-bi   File: PostgreSQLocation.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String, Object> flow = (Map<String, Object>) tuple.getValue(0);
    String wireless_station = (String) flow.get("wireless_station");

    if (wireless_station != null) {
         collector.emit(new Values(PostgresqlManager.get(wireless_station)));
    } else {
        collector.emit(new Values(new HashMap<String, Object>()));
    }
}
 
Example 30
Project: rb-bi   File: GetLocationClient.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector tridentCollector) {
    Map<String, Object> mseEvent = (Map<String, Object>) tuple.get(0);
    mseEventContent = (Map<String, Object>) mseEvent.get("StreamingNotification");
    location = (Map<String, Object>) mseEventContent.get("location");
    String macAddress = (String) location.get("macAddress");

    Map<String, Object> map = new HashMap<>();
    map.put("client_mac", macAddress);
    tridentCollector.emit(new Values(map));
}
 
Example 31
Project: rb-bi   File: GetNMSPInfoData.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String, Object> map = (Map<String, Object>) tuple.get(0);

    if (map != null) {
        Map<String, Object> data = new HashMap<>();
        data.putAll(map);
        data.remove("client_mac");

        Map<String, Object> druid = new HashMap<>();
        druid.put("bytes", 0);
        druid.put("pkts", 0);
        druid.put("timestamp", System.currentTimeMillis() / 1000);
        druid.putAll(map);
        druid.put("type", "nmsp-info");

        Object vlan = map.get("vlan_id");

        if (vlan != null) {
            druid.put("src_vlan", vlan);
            data.put("src_vlan", vlan);
            data.remove("vlan_id");
            druid.remove("vlan_id");
        }

        // logger.severe("Processed NMSP data info, emitting  [" + map.get("client_mac") + ", " + data.size() + ", " + druid.size() + "]");

        collector.emit(new Values(map.get("client_mac"), data, druid));
    }
}
 
Example 32
Project: rb-bi   File: CheckTimestampFunction.java   Source Code and License 5 votes vote down vote up
/**
 * <p>This function check if the event contains the timestamp. If the event does not contain it creates it from the current time.</p>
 */
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String, Object> event = (Map<String, Object>) tuple.getValue(0);
    if(!event.containsKey("timestamp")){
        event.put("timestamp", System.currentTimeMillis()/1000);
        collector.emit(new Values(event));
    }else{
        collector.emit(new Values(event));
    }

}
 
Example 33
Project: rb-bi   File: MacVendorFunction.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String, Object> event = (Map<String, Object>) tuple.getValue(0);
    Map<String, Object> vendorMap = new HashMap<>();
    String clientMac = (String) event.get("client_mac");

    if (clientMac != null) {
        String oui = buildOui(clientMac);
        if (_ouiMap.get(oui) != null)
            vendorMap.put("client_mac_vendor", _ouiMap.get(oui));
    }

    collector.emit(new Values(vendorMap));
}
 
Example 34
Project: rb-bi   File: MemcachedLocationV10Query.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        empty.put("dot11_status", "PROBING");
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 35
Project: rb-bi   File: MemcachedTrapQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        empty.put("client_rssi", "unknown");
        empty.put("client_rssi_num", 0);
        empty.put("client_snr", "unknown");
        empty.put("client_snr_num", 0);
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 36
Project: rb-bi   File: MemcachedLocationQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String,Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        result.put("dot11_status", "ASSOCIATED");
        collector.emit(new Values(result));
    }
}
 
Example 37
Project: rb-bi   File: MemcachedEventsLocationNmspQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        Map<String, Object> ap = new HashMap<>();
        ap.put("wireless_station", result.get("wireless_station"));
        collector.emit(new Values(ap));
    }
}
 
Example 38
Project: rb-bi   File: MemcachedQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String,Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 39
Project: rb-bi   File: RiakQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 40
Project: rb-bi   File: RiakTrapQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        empty.put("client_rssi", "unknown");
        empty.put("client_rssi_num", 0);
        empty.put("client_snr", "unknown");
        empty.put("client_snr_num", 0);
        //empty.put("quality", 0);
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 41
Project: rb-bi   File: RiakLocationV10Query.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        empty.put("dot11_status", "PROBING");
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 42
Project: rb-bi   File: RiakEventsLocationNmspQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        Map<String, Object> ap = new HashMap<>();
        ap.put("wireless_station", result.get("wireless_station"));
        collector.emit(new Values(ap));
    }
}
 
Example 43
Project: rb-bi   File: RiakLocationQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        //empty.put("quality", 100);
        collector.emit(new Values(empty));
    } else {
        result.put("dot11_status", "ASSOCIATED");
        collector.emit(new Values(result));
    }
}
 
Example 44
Project: rb-bi   File: GridGainTrapQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        empty.put("client_rssi", "unknown");
        empty.put("client_rssi_num", 0);
        empty.put("client_snr", "unknown");
        empty.put("client_snr_num", 0);
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 45
Project: rb-bi   File: GridGainEventsLocationNmspQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        Map<String, Object> ap = new HashMap<>();
        ap.put("wireless_station", result.get("wireless_station"));
        collector.emit(new Values(ap));
    }
}
 
Example 46
Project: rb-bi   File: GridGainUpdater.java   Source Code and License 5 votes vote down vote up
@Override
public void updateState(MapState<Map<String, Map<String, Object>>> state, List<TridentTuple> tuples, TridentCollector collector) {
    Map<String, Map<String, Object>> keyValue = new HashMap<>();
    List<Map<String, Map<String, Object>>> events = new ArrayList<>();
    List<List<Object>> keys = new ArrayList<>();

    for (TridentTuple t : tuples) {
        if (t != null) {
            List<Object> l = new ArrayList<>();
            l.add(_generalKey + t.getValueByField(_key));
            keys.add(l);
            keyValue.put(_generalKey + t.getValueByField(_key), (Map<String, Object>) t.getValueByField(_value));

            if (_debug) {
                System.out.println("SAVED TO GRIDGAIN, KEY: " + _generalKey + t.getValueByField(_key)
                        + " VALUE: " + t.getValueByField(_value));
            }
        }
    }

    events.add(keyValue);

    try {
        logger.fine("Calling gridgain multiput");
        state.multiPut(keys, events);
        logger.fine("Back from gridgain multiput");
    } catch (Exception e) {
        Logger.getLogger(GridGainUpdater.class.getName()).log(Level.SEVERE, null, e);
        e.printStackTrace();
    }
}
 
Example 47
Project: rb-bi   File: GridGainQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 48
Project: rb-bi   File: GridGainLocationV10Query.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        empty.put("dot11_status", "PROBING");
        collector.emit(new Values(empty));
    } else {
        collector.emit(new Values(result));
    }
}
 
Example 49
Project: rb-bi   File: GridGainLocationQuery.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        result.put("dot11_status", "ASSOCIATED");
        collector.emit(new Values(result));
    }
}
 
Example 50
Project: hadooparchitecturebook   File: TickParser.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple,
      TridentCollector collector) {

  String tick = tuple.getString(0);
  String[] parts = tick.split(",");
  System.out.println("TickParser: price=" + Double.valueOf(parts[4]));
  collector.emit(new Values(Double.valueOf(parts[4])));
}
 
Example 51
Project: LearnStorm   File: SumFunction.java   Source Code and License 5 votes vote down vote up
public void execute(TridentTuple tuple, TridentCollector collector) {
	int number1 = tuple.getInteger(0);
	int number2 = tuple.getInteger(1);
	int sum = number1 + number2;
	// emit the sum of first tow fields
	collector.emit(new Values(sum));
}
 
Example 52
Project: Tstream   File: GroupedMultiReducerExecutor.java   Source Code and License 5 votes vote down vote up
@Override
public void complete(Map<TridentTuple, Object> state, TridentCollector collector) {
    for(Map.Entry e: state.entrySet()) {
        TridentTuple group = (TridentTuple) e.getKey();
        Object val = e.getValue();
        _reducer.complete(val, group, collector);
    }
}
 
Example 53
Project: cdh-storm   File: TridentReach.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
  List l = (List) tuple.getValue(0);
  if (l != null) {
    for (Object o : l) {
      collector.emit(new Values(o));
    }
  }
}
 
Example 54
Project: jstorm-0.9.6.3-   File: FirstN.java   Source Code and License 5 votes vote down vote up
@Override
public void complete(PriorityQueue val, TridentCollector collector) {
    int total = val.size();
    for(int i=0; i<_n && i < total; i++) {
        TridentTuple t = (TridentTuple) val.remove();
        collector.emit(t);
    }
}
 
Example 55
Project: jstorm-0.9.6.3-   File: TupleCollectionGet.java   Source Code and License 5 votes vote down vote up
@Override
public List<Iterator<List<Object>>> batchRetrieve(State state, List<TridentTuple> args) {
    List<Iterator<List<Object>>> ret = new ArrayList(args.size());
    for(int i=0; i<args.size(); i++) {
        ret.add(((ITupleCollection)state).getTuples());
    }
    return ret;
}
 
Example 56
Project: storm-cassandra-cql   File: CassandraCqlStateUpdater.java   Source Code and License 5 votes vote down vote up
@Override
 public void updateState(CassandraCqlState state, List<TridentTuple> tuples, TridentCollector collector) {
     for (TridentTuple tuple : tuples) {
         Statement statement = this.mapper.map(tuple);
         state.addStatement(statement);
if (propagateTuples) {
	collector.emit(tuple);
}
     }
 }
 
Example 57
Project: Tstream   File: ProjectedProcessor.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(ProcessorContext processorContext, String streamId, TridentTuple tuple) {
    TridentTuple toEmit = _factory.create(tuple);
    for(TupleReceiver r: _context.getReceivers()) {
        r.execute(processorContext, _context.getOutStreamId(), toEmit);
    }
}
 
Example 58
Project: jstrom   File: Equals.java   Source Code and License 5 votes vote down vote up
@Override
public boolean isKeep(TridentTuple tuple) {
    for (int i = 0; i < tuple.size() - 1; i++) {
        Object o1 = tuple.getValue(i);
        Object o2 = tuple.getValue(i + 1);
        if (o1 == null && o2 != null || o1 != null && o2 == null || !o1.equals(o2)) {
            return false;
        }
    }
    return true;
}
 
Example 59
Project: realtime-event-processing   File: BingAutoSuggest.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(TridentTuple tridentTuple, TridentCollector tridentCollector) {
    String[] args = tridentTuple.getString(0).split(" ");
    String searchQuery = args[0];

    try {
        tridentCollector.emit(new Values(searchQuery));//Emit!!! Query itself
        if(suggestionsLimit >0)
            bingAutoSuggestEmitter(searchQuery, tridentCollector);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 60
Project: jstorm-0.9.6.3-   File: CombinerAggStateUpdater.java   Source Code and License 5 votes vote down vote up
@Override
public void updateState(Snapshottable state, List<TridentTuple> tuples, TridentCollector collector) {
    if(tuples.size()!=1) {
        throw new IllegalArgumentException("Combiner state updater should receive a single tuple. Received: " + tuples.toString());
    }
    Object newVal = state.update(new CombinerValueUpdater(_agg, tuples.get(0).getValue(0)));
    collector.emit(new Values(newVal));
}