test_class.declarator: MANI_ID = 0
test_class.modifier: private static final
test_class.original_string: private static final long MANI_ID = 0;
test_class.type: long
test_class.var_name: MANI_ID
test_class.declarator: DURATION = 10
test_class.modifier: private static final
test_class.original_string: private static final int DURATION = 10;
test_class.type: int
test_class.var_name: DURATION
test_class.declarator: OCC = 20
test_class.modifier: private static final
test_class.original_string: private static final int OCC = 20;
test_class.type: int
test_class.var_name: OCC
test_class.declarator: THRESH_VALUE = 30
test_class.modifier: private static final
test_class.original_string: private static final double THRESH_VALUE = 30;
test_class.type: double
test_class.var_name: THRESH_VALUE
test_class.declarator: BUCKET = "bucket_a"
test_class.modifier: private static final
test_class.original_string: private static final String BUCKET = "bucket_a";
test_class.type: String
test_class.var_name: BUCKET
test_class.declarator: COOLOFF = "66"
test_class.modifier: private static final
test_class.original_string: private static final String COOLOFF = "66";
test_class.type: String
test_class.var_name: COOLOFF
test_class.declarator: METRIC = "avg"
test_class.modifier: private static final
test_class.original_string: private static final String METRIC = "avg";
test_class.type: String
test_class.var_name: METRIC
test_class.declarator: NAME_THRESH = "sum"
test_class.modifier: private static final
test_class.original_string: private static final String NAME_THRESH = "sum";
test_class.type: String
test_class.var_name: NAME_THRESH
test_class.declarator: STAT = "max"
test_class.modifier: private static final
test_class.original_string: private static final String STAT = "max";
test_class.type: String
test_class.var_name: STAT
test_class.declarator: STATE = "open"
test_class.modifier: private static final
test_class.original_string: private static final String STATE = "open";
test_class.type: String
test_class.var_name: STATE
test_class.declarator: OPERATOR = "anybody"
test_class.modifier: private static final
test_class.original_string: private static final String OPERATOR = "anybody";
test_class.type: String
test_class.var_name: OPERATOR
test_class.declarator: SOURCE = "sink"
test_class.modifier: private static final
test_class.original_string: private static final String SOURCE = "sink";
test_class.type: String
test_class.var_name: SOURCE
test_class.declarator: THRESH_DEF = new ThresholdDef()
test_class.modifier: private static final
test_class.original_string: private static final ThresholdDef THRESH_DEF = new ThresholdDef();
test_class.type: ThresholdDef
test_class.var_name: THRESH_DEF
test_class.file: sensor/src/test/java/com/oneops/sensor/StmtBuilderTest.java
test_class.identifier: StmtBuilderTest
test_case.body: @Test
      public void buildTriggerStmtTest() {
  
          String triggerStmt = "insert into OpsEvent select ciId, manifestId, timestamp, bucket, metrics, 'open' as state, 'metric' "
                  + "as type, source, 15 as coolOff, 'opsmq-compute-cpu:HighCpuUtil' as name, 'notify' as ciState, count(1) as count from "
                  + "PerfEvent(manifestId = 4823266 and bucket = '1h' and source = 'opsmq-compute-cpu' and (metrics.avg('CpuIdle') "
                  + "<= 20.0)).win:time(5 min) group by ciId having count(1)>=1 output first every 15 minutes";
  
  
          ThresholdDef thrDef = new ThresholdDef();
          thrDef.setBucket("1h");
          thrDef.setCooloff("15");
          thrDef.setMetric("CpuIdle");
          thrDef.setName("sum");
          thrDef.setStat("avg");
          thrDef.setState("notify");
  
          StmtParams params = thrDef.new StmtParams();
          params.setNumocc(1);
          params.setOperator("<=");
          params.setValue(20.0);
          params.setDuration(5);
          thrDef.setTrigger(params);
  
          StmtBuilder builder = new StmtBuilder();
          String stmt = builder.buildTriggerStmt(4823266, "opsmq-compute-cpu", "HighCpuUtil", thrDef);
          System.out.println(stmt); 
          assertEquals(triggerStmt, stmt);
  
      }
test_case.class_method_signature: StmtBuilderTest.buildTriggerStmtTest()
test_case.full_signature: @Test public void buildTriggerStmtTest()
test_case.identifier: buildTriggerStmtTest
test_case.invocations: setBucket setCooloff setMetric setName setStat setState setNumocc setOperator setValue setDuration setTrigger buildTriggerStmt println assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void buildTriggerStmtTest()
focal_class.declarator: logger = Logger.getLogger(StmtBuilder.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = Logger.getLogger(StmtBuilder.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: THRESHOLDS_JSON_SIZE_FLOOR = 3
focal_class.modifier: public static final
focal_class.original_string: public static final int THRESHOLDS_JSON_SIZE_FLOOR = 3;
focal_class.type: int
focal_class.var_name: THRESHOLDS_JSON_SIZE_FLOOR
focal_class.declarator: CHANNEL_DOWN_INTERVAL = Integer.valueOf(getProperty("com.oneops.sensor.chdowntime", "15"))
focal_class.modifier: private static final
focal_class.original_string: private static final int CHANNEL_DOWN_INTERVAL = Integer.valueOf(getProperty("com.oneops.sensor.chdowntime", "15"));
focal_class.type: int
focal_class.var_name: CHANNEL_DOWN_INTERVAL
focal_class.declarator: WNDW_SIZE_MAX = Integer.valueOf(getProperty("com.oneops.sensor.MaxDuration", "5"))
focal_class.modifier: private static final
focal_class.original_string: private static final int WNDW_SIZE_MAX = Integer.valueOf(getProperty("com.oneops.sensor.MaxDuration", "5"));
focal_class.type: int
focal_class.var_name: WNDW_SIZE_MAX
focal_class.declarator: STMT_RESET = "insert into OpsCloseEvent select trigger.ciId as ciId, trigger.manifestId as manifestId, trigger.name as name, trigger.source as source, reset.timestamp as timestamp, reset.metrics as metrics, 'close' as state, trigger as openEvent from pattern [every trigger=OpsEvent(state = 'open') -> reset=OpsEvent(ciId = trigger.ciId and name = trigger.name and state = 'reset')]"
focal_class.modifier: public final static
focal_class.original_string: public final static String STMT_RESET = "insert into OpsCloseEvent select trigger.ciId as ciId, trigger.manifestId as manifestId, trigger.name as name, trigger.source as source, reset.timestamp as timestamp, reset.metrics as metrics, 'close' as state, trigger as openEvent from pattern [every trigger=OpsEvent(state = 'open') -> reset=OpsEvent(ciId = trigger.ciId and name = trigger.name and state = 'reset')]";
focal_class.type: String
focal_class.var_name: STMT_RESET
focal_class.declarator: STMT_RESET_HEARTBEAT = "insert into OpsCloseEvent select trigger.ciId as ciId, trigger.manifestId as manifestId, trigger.name as name, trigger.source as source, reset.timestamp as timestamp, 'close' as state, trigger as openEvent from pattern [every trigger=OpsEvent(state = 'open' and type = 'heartbeat') -> reset=PerfEvent(ciId = trigger.ciId and source = trigger.source)]"
focal_class.modifier: public final static
focal_class.original_string: public final static String STMT_RESET_HEARTBEAT = "insert into OpsCloseEvent select trigger.ciId as ciId, trigger.manifestId as manifestId, trigger.name as name, trigger.source as source, reset.timestamp as timestamp, 'close' as state, trigger as openEvent from pattern [every trigger=OpsEvent(state = 'open' and type = 'heartbeat') -> reset=PerfEvent(ciId = trigger.ciId and source = trigger.source)]";
focal_class.type: String
focal_class.var_name: STMT_RESET_HEARTBEAT
focal_class.declarator: STMT_RETRIGGER_HEARTBEAT = "insert into OpsEvent select hbtrigger.ciId as ciId,  hbtrigger.manifestId as manifestId,hbtrigger.channel as channel, hbtrigger.timestamp as timestamp, hbtrigger.state as state, 'heartbeat' as type, hbtrigger.source as source, hbtrigger.name as name, hbtrigger.ciState as ciState  from pattern [every hbtrigger=OpsEvent(state = 'open' and type = 'heartbeat') -> (timer:interval(15 min) and not PerfEvent(ciId = hbtrigger.ciId and source = hbtrigger.source))]"
focal_class.modifier: public final static
focal_class.original_string: public final static String STMT_RETRIGGER_HEARTBEAT = "insert into OpsEvent select hbtrigger.ciId as ciId,  hbtrigger.manifestId as manifestId,hbtrigger.channel as channel, hbtrigger.timestamp as timestamp, hbtrigger.state as state, 'heartbeat' as type, hbtrigger.source as source, hbtrigger.name as name, hbtrigger.ciState as ciState  from pattern [every hbtrigger=OpsEvent(state = 'open' and type = 'heartbeat') -> (timer:interval(15 min) and not PerfEvent(ciId = hbtrigger.ciId and source = hbtrigger.source))]";
focal_class.type: String
focal_class.var_name: STMT_RETRIGGER_HEARTBEAT
focal_class.declarator: STMT_TRIGGER_CHANNELDOWN = "insert into ChannelDownEvent select lastEvent.channel as channel from pattern [(every lastEvent=PerfEvent()) -> (timer:interval(" + CHANNEL_DOWN_INTERVAL + " sec) and not PerfEvent(channel = lastEvent.channel))]"
focal_class.modifier: public final static
focal_class.original_string: public final static String STMT_TRIGGER_CHANNELDOWN = "insert into ChannelDownEvent select lastEvent.channel as channel from pattern [(every lastEvent=PerfEvent()) -> (timer:interval(" + CHANNEL_DOWN_INTERVAL + " sec) and not PerfEvent(channel = lastEvent.channel))]";
focal_class.type: String
focal_class.var_name: STMT_TRIGGER_CHANNELDOWN
focal_class.declarator: STMT_DELAY_PERF_EVENT = "insert into PerfEvent select delayedEvent.perfEvent from pattern [(every delayedEvent=DelayedPerfEvent -> timer:interval(delayedEvent.delay sec))]"
focal_class.modifier: public final static
focal_class.original_string: public final static String STMT_DELAY_PERF_EVENT = "insert into PerfEvent select delayedEvent.perfEvent from pattern [(every delayedEvent=DelayedPerfEvent -> timer:interval(delayedEvent.delay sec))]";
focal_class.type: String
focal_class.var_name: STMT_DELAY_PERF_EVENT
focal_class.declarator: gson = new Gson()
focal_class.modifier: private final
focal_class.original_string: private final Gson gson = new Gson();
focal_class.type: Gson
focal_class.var_name: gson
focal_class.file: sensor/src/main/java/com/oneops/sensor/StmtBuilder.java
focal_class.identifier: StmtBuilder
focal_class.class_method_signature: StmtBuilder.StmtBuilder()
focal_class.full_signature: public  StmtBuilder()
focal_class.identifier: StmtBuilder
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  StmtBuilder()
focal_class.class_method_signature: StmtBuilder.buildTriggerStmt(long manifestId, String source, String trsName, ThresholdDef def)
focal_class.full_signature: public String buildTriggerStmt(long manifestId, String source, String trsName, ThresholdDef def)
focal_class.identifier: buildTriggerStmt
focal_class.modifiers: public
focal_class.parameters: (long manifestId, String source, String trsName, ThresholdDef def)
focal_class.return: String
focal_class.signature: String buildTriggerStmt(long manifestId, String source, String trsName, ThresholdDef def)
focal_class.class_method_signature: StmtBuilder.buildResetStmt(long manifestId, String source, String trsName, ThresholdDef def)
focal_class.full_signature: public String buildResetStmt(long manifestId, String source, String trsName, ThresholdDef def)
focal_class.identifier: buildResetStmt
focal_class.modifiers: public
focal_class.parameters: (long manifestId, String source, String trsName, ThresholdDef def)
focal_class.return: String
focal_class.signature: String buildResetStmt(long manifestId, String source, String trsName, ThresholdDef def)
focal_class.class_method_signature: StmtBuilder.buildHeartbeatStmt(long manifestId, String source, String duration)
focal_class.full_signature: public String buildHeartbeatStmt(long manifestId, String source, String duration)
focal_class.identifier: buildHeartbeatStmt
focal_class.modifiers: public
focal_class.parameters: (long manifestId, String source, String duration)
focal_class.return: String
focal_class.signature: String buildHeartbeatStmt(long manifestId, String source, String duration)
focal_class.class_method_signature: StmtBuilder.getThresholdStatements(long manifestId, String source,
                                                        long checksum, String thresholdsJson,
                                                        boolean isHeartbeat,
                                                        String hbDuration)
focal_class.full_signature: public ThresholdStatements getThresholdStatements(long manifestId, String source,
                                                        long checksum, String thresholdsJson,
                                                        boolean isHeartbeat,
                                                        String hbDuration)
focal_class.identifier: getThresholdStatements
focal_class.modifiers: public
focal_class.parameters: (long manifestId, String source,
                                                        long checksum, String thresholdsJson,
                                                        boolean isHeartbeat,
                                                        String hbDuration)
focal_class.return: ThresholdStatements
focal_class.signature: ThresholdStatements getThresholdStatements(long manifestId, String source,
                                                        long checksum, String thresholdsJson,
                                                        boolean isHeartbeat,
                                                        String hbDuration)
focal_method.body: public String buildTriggerStmt(long manifestId, String source, String trsName, ThresholdDef def) {
  
          String name = source + ":" + trsName;
  
          // Set max window size to 5 mins to avoid OOM
          int duration = def.getTrigger().getDuration();
          duration = (duration > WNDW_SIZE_MAX) ? WNDW_SIZE_MAX : duration;
  
          // Set default cooloff to 15 mins
          String coolOff = def.getCooloff();
          coolOff = (coolOff != null) ? coolOff : "15";
  
          // Set bigger capacity (450) to reduce internal buffer allocation.
          return new StringBuilder(450)
                  .append("insert into OpsEvent select ciId, manifestId, timestamp, bucket, metrics, 'open' as state, 'metric' as type, source, ")
                  .append(coolOff).append(" as coolOff, ")
                  .append("'").append(name).append("'")
                  .append(" as name, ")
                  .append("'").append(def.getState()).append("'")
                  .append(" as ciState, count(1) as count from PerfEvent(manifestId = ")
                  .append(manifestId)
                  .append(" and bucket = ")
                  .append("'").append(def.getBucket()).append("'")
                  .append(" and source = ")
                  .append("'").append(source).append("'")
                  .append(" and (metrics.")
                  .append(def.getStat())
                  .append("('").append(def.getMetric()).append("') ")
                  .append(def.getTrigger().getOperator())
                  .append(" ").append(def.getTrigger().getValue()).append(")).")
                  .append("win:time(")
                  .append(duration)
                  .append(" min) group by ciId having count(1)>=")
                  .append(def.getTrigger().getNumocc())
                  .append(" output first every ")
                  .append(coolOff)
                  .append(" minutes").toString();
      }
focal_method.class_method_signature: StmtBuilder.buildTriggerStmt(long manifestId, String source, String trsName, ThresholdDef def)
focal_method.full_signature: public String buildTriggerStmt(long manifestId, String source, String trsName, ThresholdDef def)
focal_method.identifier: buildTriggerStmt
focal_method.invocations: getDuration getTrigger getCooloff toString append append append append append append append append append append append append append append append append append append append append append append append append append append append append append append append append append append append append getState getBucket getStat getMetric getOperator getTrigger getValue getTrigger getNumocc getTrigger
focal_method.modifiers: public
focal_method.parameters: (long manifestId, String source, String trsName, ThresholdDef def)
focal_method.return: String
focal_method.signature: String buildTriggerStmt(long manifestId, String source, String trsName, ThresholdDef def)