public void execute(TridentTuple tuple, TridentCollector collector) {
   GenericRecord docEntry = new GenericData.Record(schema);
   docEntry.put("docid", tuple.getStringByField("documentId"));
   docEntry.put("time", Time.currentTimeMillis());
   docEntry.put("line", tuple.getStringByField("document"));
   try {
     dataFileWriter.append(docEntry);
     dataFileWriter.flush();
   } catch (IOException e) {
     LOG.error("Error writing to document record: " + e);
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 2
0
  @Override
  public void execute(TridentTuple tuple, TridentCollector collector) {
    try {
      String assetPhysical = tuple.getStringByField("asset_physical");
      String beginTime = tuple.getStringByField("begin_time");
      String endTime = tuple.getStringByField("end_time");
      String clientAddress = tuple.getStringByField("client_address"); // 获取对端IP

      String filePath = tuple.getStringByField("file_path");
      String fileSize = tuple.getStringByField("file_size"); // 获取文件大小,单位为byte

      String ftpAccount = tuple.getStringByField("ftp_account");
      Long operateType = tuple.getLongByField("operate_type");
      String serverName = tuple.getStringByField("server_name");
      String version = tuple.getStringByField("version");

      // 由于业务变更,改成属性映射获取业务类型数据与属性字典(暂时只包括businessType和Area编码映射)
      Map<String, Object> dictionaryMap = DictionaryMappingUtil.transfer(filePath);

      // 获取业务类型编码
      String businessType =
          dictionaryMap.get(DictionaryMappingUtil.BUSINESSTYPE_KEY).toString(); // "A0001";
      LOG.info("**businessType==>" + businessType);

      // 获取区域编码
      Long area =
          Long.parseLong(dictionaryMap.get(DictionaryMappingUtil.PROVINCECODE_KEY).toString());
      LOG.info("**area==>" + area);

      // 资产名从物理文件名中获取
      String assetEnName = DictionaryMappingUtil.getName(assetPhysical, businessType);
      LOG.info("**assetEnName==>" + assetEnName);

      MonitorDTO monitor = new MonitorDTO();
      monitor.setBusiness_type(businessType);
      monitor.setAsset_en_name(assetEnName);
      monitor.setAsset_physical(assetPhysical);
      monitor.setArea(area);
      monitor.setOperate_type(operateType);
      monitor.setBegin_time(beginTime);
      monitor.setEnd_time(endTime);
      monitor.setVersion(version);
      monitor.setServer_name(serverName);
      monitor.setFtp_account(ftpAccount);
      monitor.setFile_path(filePath);
      monitor.setFile_size(new Long(fileSize));
      monitor.setClient_address(clientAddress);

      Values values = new Values();
      values.add(monitor);

      collector.emit(values);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
 private double[] getFeatureVectorFromArgs(TridentTuple queryTuple) {
   String args =
       queryTuple.getStringByField(EnsembleLearnerTopologyBuilder.drpcQueryArgsField.get(0));
   try {
     return MlStormFeatureVectorUtils.deserializeToFeatureVector(args);
   } catch (DecoderException e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   } catch (IOException e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 4
0
 @Override
 public boolean isKeep(TridentTuple tuple) {
   int ageBand =
       Integer.parseInt(tuple.getStringByField(VehicleFields.AGE_BAND_OF_DRIVER.fieldName));
   return ageBand <= 5;
 }