Build a MonitoringRule given a guarantee term
338627
private MonitoringRule buildRelatedRule(IGuaranteeTerm guarantee) {
        
        MonitoringRule result = new MonitoringRule();
        result.setId(guarantee.getName());

        String violation = extractOutputMetric(guarantee);
        Parameter param = new Parameter();
        param.setName(QosModels.METRIC_PARAM_NAME);
        param.setValue(violation);
        
        Action action = new Action();
        action.setName(QosModels.OUTPUT_METRIC_ACTION);
        action.getParameters().add(param);
        
        Actions actions = new Actions();
        actions.getActions().add(action);
        
        result.setActions(actions);
        
        return result;
    }
303299
function checkAtruler(i) {
  const start = i;
  let l;

  if (i >= tokensLength) return 0;

  if (l = checkAtkeyword(i)) i += l;
  else return 0;

  if (l = checkTsets(i)) i += l;

  if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket) i++;
  else return 0;

  if (l = checkAtrulers(i)) i += l;

  if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket) i++;
  else return 0;

  return i - start;
}
1235929
def _sanity_check_construct_result_block(ir_blocks):
    """"""
    if not isinstance(ir_blocks[-1], ConstructResult):
        raise AssertionError(u'The last block was not ConstructResult: {}'.format(ir_blocks))
    for block in ir_blocks[:-1]:
        if isinstance(block, ConstructResult):
            raise AssertionError(u'Found ConstructResult before the last block: '
                                 u'{}'.format(ir_blocks))
563246
def _watchdog(self):
        '''  '''
        too_early = (time.time() - self._last_time < self._min_interval)
        too_much = (self._count >= self._rate_limit)
        return (False if (too_early or too_much) else True)
241361
def ratable_result(value, name, msgs):
    """"""
    return lambda w: Result(w, value, name, msgs)
1071062
def monitor(name):
    '''
    
    '''
    ret = {'result': None,
           'name': name,
           'comment': '',
           'changes': {}
           }
    result = __salt__['monit.summary'](name)

    try:
        for key, value in result.items():
            if 'Running' in value[name]:
                ret['comment'] = ('{0} is being being monitored.').format(name)
                ret['result'] = True
            else:
                if __opts__['test']:
                    ret['comment'] = 'Service {0} is set to be monitored.'.format(name)
                    ret['result'] = None
                    return ret
                __salt__['monit.monitor'](name)
                ret['comment'] = ('{0} started to be monitored.').format(name)
                ret['changes'][name] = 'Running'
                ret['result'] = True
                break
    except KeyError:
        ret['comment'] = ('{0} not found in configuration.').format(name)
        ret['result'] = False

    return ret
1175041
def asserts(self, *args, **kwargs):
        
        result = self.match(*args, **kwargs)
        self.expect(result)
        return result
740809
def SecurityCheck(func):
  """"""

  def Wrapper(request, *args, **kwargs):
    """Wrapping function."""
    if WEBAUTH_MANAGER is None:
      raise RuntimeError("Attempt to initialize before WEBAUTH_MANAGER set.")
    return WEBAUTH_MANAGER.SecurityCheck(func, request, *args, **kwargs)

  return Wrapper
749298
def become_monitor(self, rules) :
        ""
        message = Message.new_method_call \
          (
            destination = DBUS.SERVICE_DBUS,
            path = DBUS.PATH_DBUS,
            iface = DBUS.INTERFACE_MONITORING,
            method = "BecomeMonitor"
          )
        message.append_objects("asu", (list(format_rule(rule) for rule in rules)), 0)
        self.send(message)
61986
def watch_activations(self, flag):
        """"""
        lib.EnvSetDefruleWatchActivations(self._env, int(flag), self._rule)
1299128
function quantified(rule, min, max) {
        if (min === void 0) { min = 0; }
        if (max === void 0) { max = Infinity; }
        if (min === 0 && max === 1)
            return new Optional(RuleTypeToRule(rule));
        else
            return new Quantified(RuleTypeToRule(rule), min, max);
    }
835616
def try_until_succeed(_warning_period, func, *argv, **kwarg):
    
    if (not isinstance(_warning_period, int)) or (_warning_period < 1):
        raise Exception("'_warning_period' argument has to be int "
                        "and greater than 0")
        
    counter = 1
    while 1:
        try:
            return func(*argv, **kwarg)
        except Exception as e:
            current_exception = e
            counter += 1
            if (counter % _warning_period) == 0:
                print("Warning: this is %sth try, current error is "
                      "%s" % (counter, repr(current_exception)))
1303707
def rules(self):
        """"""
        rule = lib.EnvGetNextDefrule(self._env, ffi.NULL)

        while rule != ffi.NULL:
            yield Rule(self._env, rule)

            rule = lib.EnvGetNextDefrule(self._env, rule)
175604
def _ensure_counter(self):
        """"""
        if not isinstance(self.sync_counter, self._SynchronizationManager):
            self.sync_counter = self._SynchronizationManager()
686362
def constrain_positive(self, warning=True, trigger_parent=True):
        
        self.constrain(Logexp(), warning=warning, trigger_parent=trigger_parent)
1060924
public static String getOutputMetric(MonitoringRule rule) {
        String paramName = METRIC_PARAM_NAME;

        for (Action action : rule.getActions().getActions()) {
            if (OUTPUT_METRIC_ACTION.equalsIgnoreCase(action.getName())) {
                Parameter param = getActionParameter(action, paramName);
                return param.getValue();
            }
        }
        return "";
    }
443063
function helper_updateRuleState(triggerIdentifier, ruleIdentifier, state)
{
	exec(null,
		null,
		'EstimoteBeacons',
		'triggers_updateRuleState',
		[triggerIdentifier, ruleIdentifier, state]
	);
}