Ejemplo n.º 1
0
    def set_calibrators(self, parameter, calibrators):
        """
        Apply an ordered set of calibrators for the specified parameter.
        This replaces existing calibrators (if any).

        Each calibrator may have a context, which indicates when it its
        effects may be applied. Only the first matching calibrator is
        applied.

        A calibrator with context ``None`` is the *default* calibrator.
        There can be only one such calibrator, and is always applied at
        the end when no other contextual calibrator was applicable.

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        :param .Calibrator[] calibrators: List of calibrators (either contextual or
                                          not)
        """
        req = mdb_pb2.UpdateParameterRequest()
        req.action = mdb_pb2.UpdateParameterRequest.SET_CALIBRATORS
        for c in calibrators:
            if c.context:
                context_calib = req.contextCalibrator.add()
                context_calib.context = c.context
                calib_info = context_calib.calibrator
            else:
                calib_info = req.defaultCalibrator

            _add_calib(calib_info, c.type, c.data)

        parameter = adapt_name_for_rest(parameter)
        url = "/mdb/{}/{}/parameters{}".format(
            self._instance, self._processor, parameter
        )
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 2
0
    def issue_command(self, command, args=None, dry_run=False, comment=None):
        """
        Issue the given command

        :param str command: Either a fully-qualified XTCE name or an alias in the
                            format ``NAMESPACE/NAME``.
        :param dict args: named arguments (if the command requires these)
        :param bool dry_run: If ``True`` the command is not actually issued. This
                             can be used to check if the server would generate
                             errors when preparing the command (for example
                             because an argument is missing).
        :param str comment: Comment attached to the command.
        :return: An object providing access to properties of the newly issued
                 command.
        :rtype: .IssuedCommand
        """
        req = rest_pb2.IssueCommandRequest()
        req.sequenceNumber = SequenceGenerator.next()
        req.origin = socket.gethostname()
        req.dryRun = dry_run
        if comment:
            req.comment = comment
        if args:
            for key in args:
                assignment = req.assignment.add()
                assignment.name = key
                assignment.value = str(args[key])

        command = adapt_name_for_rest(command)
        url = '/processors/{}/{}/commands{}'.format(self._instance,
                                                    self._processor, command)
        response = self._client.post_proto(url, data=req.SerializeToString())
        proto = rest_pb2.IssueCommandResponse()
        proto.ParseFromString(response.content)
        return IssuedCommand(proto, self)
Ejemplo n.º 3
0
    def get_parameter_value(self, parameter, from_cache=True, timeout=10):
        """
        Retrieve the current value of the specified parameter.

        :param str parameter: Either a fully-qualified XTCE name or an alias in the
                              format ``NAMESPACE/NAME``.
        :param bool from_cache: If ``False`` this call will block until a
                                fresh value is received on the processor.
                                If ``True`` the server returns the latest
                                value instead (which may be ``None``).
        :param float timeout: The amount of seconds to wait for a fresh value.
                              (ignored if ``from_cache=True``).
        :rtype: .ParameterValue
        """
        params = {
            "fromCache": from_cache,
            "timeout": int(timeout * 1000),
        }
        parameter = adapt_name_for_rest(parameter)
        url = "/processors/{}/{}/parameters{}".format(
            self._instance, self._processor, parameter
        )
        response = self.ctx.get_proto(url, params=params)
        proto = pvalue_pb2.ParameterValue()
        proto.ParseFromString(response.content)

        # Server returns ParameterValue with only 'id' set if no
        # value existed. Convert this to ``None``.
        if proto.HasField("rawValue") or proto.HasField("engValue"):
            return ParameterValue(proto)
        return None
Ejemplo n.º 4
0
    def reset_alarm_ranges(self, parameter):
        """
        Reset all alarm limits for the specified parameter to their original MDB value.
        """
        req = mdb_override_service_pb2.UpdateParameterRequest()
        req.action = mdb_override_service_pb2.UpdateParameterRequest.RESET_ALARMS

        parameter = adapt_name_for_rest(parameter)
        url = f"/mdb/{self._instance}/{self._processor}/parameters{parameter}"
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 5
0
    def set_default_alarm_ranges(
        self,
        parameter,
        watch=None,
        warning=None,
        distress=None,
        critical=None,
        severe=None,
        min_violations=1,
    ):
        """
        Generate out-of-limit alarms for a parameter using the specified
        alarm ranges.

        This replaces any previous default alarms on this parameter.

        .. note::

            Contextual range sets take precedence over the default alarm
            ranges. See :meth:`set_alarm_range_sets` for setting contextual
            range sets.

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        :param (float,float) watch: Range expressed as a tuple ``(lo, hi)``
                                    where lo and hi are assumed exclusive.
        :param (float,float) warning: Range expressed as a tuple ``(lo, hi)``
                                      where lo and hi are assumed exclusive.
        :param (float,float) distress: Range expressed as a tuple ``(lo, hi)``
                                       where lo and hi are assumed exclusive.
        :param (float,float) critical: Range expressed as a tuple ``(lo, hi)``
                                       where lo and hi are assumed exclusive.
        :param (float,float) severe: Range expressed as a tuple ``(lo, hi)``
                                     where lo and hi are assumed exclusive.
        :param int min_violations: Minimum violations before an alarm is
                                   generated.
        """
        req = mdb_pb2.UpdateParameterRequest()
        req.action = mdb_pb2.UpdateParameterRequest.SET_DEFAULT_ALARMS
        if watch or warning or distress or critical or severe:
            _add_alarms(
                req.defaultAlarm,
                watch,
                warning,
                distress,
                critical,
                severe,
                min_violations,
            )

        parameter = adapt_name_for_rest(parameter)
        url = "/mdb/{}/{}/parameters{}".format(
            self._instance, self._processor, parameter
        )
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 6
0
    def reset_alarm_ranges(self, parameter):
        """
        Reset all alarm limits for the specified parameter to their original MDB value.
        """
        req = mdb_pb2.ChangeParameterRequest()
        req.action = mdb_pb2.ChangeParameterRequest.RESET_ALARMS

        parameter = adapt_name_for_rest(parameter)
        url = '/mdb/{}/{}/parameters{}'.format(self._instance, self._processor,
                                               parameter)
        self._client.post_proto(url, data=req.SerializeToString())
Ejemplo n.º 7
0
    def reset_calibrators(self, parameter):
        """
        Reset all calibrators for the specified parameter to their original MDB value.
        """
        req = mdb_pb2.UpdateParameterRequest()
        req.action = mdb_pb2.UpdateParameterRequest.RESET_CALIBRATORS

        parameter = adapt_name_for_rest(parameter)
        url = "/mdb/{}/{}/parameters{}".format(
            self._instance, self._processor, parameter
        )
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 8
0
    def set_parameter_value(self, parameter, value):
        """
        Sets the value of the specified parameter.

        :param str parameter: Either a fully-qualified XTCE name or an alias in the
                              format ``NAMESPACE/NAME``.
        :param value: The value to set
        """
        parameter = adapt_name_for_rest(parameter)
        url = '/processors/{}/{}/parameters{}'.format(
            self._instance, self._processor, parameter)
        req = _build_value_proto(value)
        self._client.put_proto(url, data=req.SerializeToString())
Ejemplo n.º 9
0
    def reset_algorithm(self, parameter):
        """
        Reset the algorithm text to its original definition from MDB

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        """
        req = mdb_override_service_pb2.UpdateAlgorithmRequest()
        req.action = mdb_override_service_pb2.UpdateAlgorithmRequest.RESET

        parameter = adapt_name_for_rest(parameter)
        url = f"/mdb/{self._instance}/{self._processor}/algorithms{parameter}"
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 10
0
    def unshelve_alarm(self, alarm, comment=None):
        """
        Unshelve an alarm.

        :param alarm: Alarm instance
        :type alarm: :class:`.Alarm`
        :param str comment: Optional comment to associate with the state
                            change.
        """
        name = adapt_name_for_rest(alarm.name)
        url = f"/processors/{self._instance}/{self._processor}"
        url += f"/alarms{name}/{alarm.sequence_number}:unshelve"
        req = alarms_service_pb2.UnshelveAlarmRequest()
        self.ctx.post_proto(url, data=req.SerializeToString())
Ejemplo n.º 11
0
    def reset_algorithm(self, parameter):
        """
        Reset the algorithm text to its original definition from MDB

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        """
        req = mdb_pb2.ChangeAlgorithmRequest()
        req.action = mdb_pb2.ChangeAlgorithmRequest.RESET

        parameter = adapt_name_for_rest(parameter)
        url = '/mdb/{}/{}/algorithms{}'.format(self._instance, self._processor,
                                               parameter)
        self._client.post_proto(url, data=req.SerializeToString())
Ejemplo n.º 12
0
    def get_parameter(self, name):
        """
        Gets a single parameter by its name.

        :param str name: Either a fully-qualified XTCE name or an alias in the
                         format ``NAMESPACE/NAME``.
        :rtype: .Parameter
        """
        name = adapt_name_for_rest(name)
        url = f"/mdb/{self._instance}/parameters{name}"
        response = self.ctx.get_proto(url)
        message = mdb_pb2.ParameterInfo()
        message.ParseFromString(response.content)
        return Parameter(message)
Ejemplo n.º 13
0
    def get_algorithm(self, name):
        """
        Gets a single algorithm by its unique name.

        :param str name: Either a fully-qualified XTCE name or an alias in the
                         format ``NAMESPACE/NAME``.
        :rtype: .Algorithm
        """
        name = adapt_name_for_rest(name)
        url = f"/mdb/{self._instance}/algorithms{name}"
        response = self.ctx.get_proto(url)
        message = mdb_pb2.AlgorithmInfo()
        message.ParseFromString(response.content)
        return Algorithm(message)
Ejemplo n.º 14
0
    def get_command(self, name):
        """
        Gets a single command by its unique name.

        :param str name: Either a fully-qualified XTCE name or an alias in the
                         format ``NAMESPACE/NAME``.
        :rtype: .Command
        """
        name = adapt_name_for_rest(name)
        url = '/mdb/{}/commands{}'.format(self._instance, name)
        response = self._client.get_proto(url)
        message = mdb_pb2.CommandInfo()
        message.ParseFromString(response.content)
        return Command(message)
Ejemplo n.º 15
0
    def unshelve_alarm(self, alarm, comment=None):
        """
        Unshelve an alarm.

        :param alarm: Alarm instance
        :type alarm: :class:`.Alarm`
        :param str comment: Optional comment to associate with the state
                            change.
        """
        name = adapt_name_for_rest(alarm.name)
        url = '/processors/{}/{}/alarms{}/{}'.format(
            self._instance, self._processor, name, alarm.sequence_number)
        req = alarms_pb2.EditAlarmRequest()
        req.state = 'unshelved'
        self._client.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 16
0
    def set_algorithm(self, parameter, text):
        """
        Change an algorithm text. Can only be peformed on JavaScript or Python
        algorithms.

        :param string text: new algorithm text (as it would appear in excel or XTCE)
        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        """
        req = mdb_override_service_pb2.UpdateAlgorithmRequest()
        req.action = mdb_override_service_pb2.UpdateAlgorithmRequest.SET
        req.algorithm.text = text

        parameter = adapt_name_for_rest(parameter)
        url = f"/mdb/{self._instance}/{self._processor}/algorithms{parameter}"
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 17
0
    def acknowledge_alarm(self, alarm, comment=None):
        """
        Acknowledges a specific alarm.

        :param alarm: Alarm instance
        :type alarm: :class:`.Alarm`
        :param str comment: Optional comment to associate with the state
                            change.
        """
        name = adapt_name_for_rest(alarm.name)
        url = f"/processors/{self._instance}/{self._processor}"
        url += f"/alarms{name}/{alarm.sequence_number}:acknowledge"
        req = alarms_service_pb2.AcknowledgeAlarmRequest()
        if comment is not None:
            req.comment = comment
        self.ctx.post_proto(url, data=req.SerializeToString())
Ejemplo n.º 18
0
    def set_algorithm(self, parameter, text):
        """
        Change an algorithm text. Can only be peformed on JavaScript or Python algorithms.

        :param string text: new algorithm text (as it would appear in excel or XTCE)
        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        """
        req = mdb_pb2.ChangeAlgorithmRequest()
        req.action = mdb_pb2.ChangeAlgorithmRequest.SET
        req.algorithm.text = text

        parameter = adapt_name_for_rest(parameter)
        url = '/mdb/{}/{}/algorithms{}'.format(self._instance, self._processor,
                                               parameter)
        self._client.post_proto(url, data=req.SerializeToString())
Ejemplo n.º 19
0
    def acknowledge_alarm(self, alarm, comment=None):
        """
        Acknowledges a specific alarm associated with a parameter.

        :param alarm: Alarm instance
        :type alarm: :class:`.Alarm`
        :param str comment: Optional comment to associate with the state
                            change.
        """
        name = adapt_name_for_rest(alarm.name)
        url = '/processors/{}/{}/parameters{}/alarms/{}'.format(
            self._instance, self._processor, name, alarm.sequence_number)
        req = rest_pb2.EditAlarmRequest()
        req.state = 'acknowledged'
        if comment is not None:
            req.comment = comment
        self._client.put_proto(url, data=req.SerializeToString())
Ejemplo n.º 20
0
    def shelve_alarm(self, alarm, comment=None):
        """
        Shelve an alarm.

        :param alarm: Alarm instance
        :type alarm: :class:`.Alarm`
        :param str comment: Optional comment to associate with the state
                            change.
        """
        name = adapt_name_for_rest(alarm.name)
        url = "/processors/{}/{}/alarms{}/{}".format(
            self._instance, self._processor, name, alarm.sequence_number
        )
        req = alarms_service_pb2.EditAlarmRequest()
        req.state = "shelved"
        if comment is not None:
            req.comment = comment
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 21
0
    def set_alarm_range_sets(self, parameter, sets):
        """
        Apply an ordered list of alarm range sets for the specified parameter.
        This replaces existing alarm sets (if any).

        Each RangeSet may have a context, which indicates when
        its effects may be applied. Only the first matching set is
        applied.

        A RangeSet with context ``None`` represents the *default* set of
        alarm ranges.  There can be only one such set, and it is always
        applied at the end when no other set of contextual ranges is
        applicable.

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        :param .RangeSet[] sets: List of range sets (either contextual or not)
        """
        req = mdb_pb2.UpdateParameterRequest()
        req.action = mdb_pb2.UpdateParameterRequest.SET_ALARMS
        for rs in sets:
            if rs.context:
                context_alarm = req.contextAlarm.add()
                context_alarm.context = rs.context
                alarm_info = context_alarm.alarm
            else:
                alarm_info = req.defaultAlarm

            _add_alarms(
                alarm_info,
                rs.watch,
                rs.warning,
                rs.distress,
                rs.critical,
                rs.severe,
                rs.min_violations,
            )

        parameter = adapt_name_for_rest(parameter)
        url = "/mdb/{}/{}/parameters{}".format(
            self._instance, self._processor, parameter
        )
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 22
0
    def clear_alarm(self, alarm, comment=None):
        """
        Clear an alarm.

        .. note::
            If the reason that caused the alarm is still present, a new
            alarm instance will be generated.

        :param alarm: Alarm instance
        :type alarm: :class:`.Alarm`
        :param str comment: Optional comment to associate with the state
                            change.
        """
        name = adapt_name_for_rest(alarm.name)
        url = f"/processors/{self._instance}/{self._processor}"
        url += f"/alarms{name}/{alarm.sequence_number}:clear"
        req = alarms_service_pb2.ClearAlarmRequest()
        if comment is not None:
            req.comment = comment
        self.ctx.post_proto(url, data=req.SerializeToString())
Ejemplo n.º 23
0
    def clear_alarm(self, alarm, comment=None):
        """
        Clear an alarm.

        .. note::
            If the reason that caused the alarm is still present, a new
            alarm instance will be generated.

        :param alarm: Alarm instance
        :type alarm: :class:`.Alarm`
        :param str comment: Optional comment to associate with the state
                            change.
        """
        name = adapt_name_for_rest(alarm.name)
        url = '/processors/{}/{}/alarms{}/{}'.format(
            self._instance, self._processor, name, alarm.sequence_number)
        req = alarms_pb2.EditAlarmRequest()
        req.state = 'cleared'
        if comment is not None:
            req.comment = comment
        self._client.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 24
0
    def set_default_calibrator(self, parameter, type, data):
        """
        Apply a calibrator while processing raw values of the specified
        parameter. If there is already a default calibrator associated
        to this parameter, that calibrator gets replaced.

        .. note::

            Contextual calibrators take precedence over the default calibrator
            See :meth:`set_calibrators` for setting contextual calibrators.

        Two types of calibrators can be applied:

        * Polynomial calibrators apply a polynomial expression of the form:
          `y = a + bx + cx^2 + ...`.

          The `data` argument must be an array of floats ``[a, b, c, ...]``.

        * Spline calibrators interpolate the raw value between a set of points
          which represent a linear curve.

          The `data` argument must be an array of ``[x, y]`` points.

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        :param str type: One of ``polynomial`` or ``spline``.
        :param data: Calibration definition for the selected type.
        """
        req = mdb_pb2.UpdateParameterRequest()
        req.action = mdb_pb2.UpdateParameterRequest.SET_DEFAULT_CALIBRATOR
        if type:
            _add_calib(req.defaultCalibrator, type, data)

        parameter = adapt_name_for_rest(parameter)
        url = "/mdb/{}/{}/parameters{}".format(
            self._instance, self._processor, parameter
        )
        self.ctx.patch_proto(url, data=req.SerializeToString())
Ejemplo n.º 25
0
    def issue_command(
        self,
        command,
        args=None,
        dry_run=False,
        comment=None,
        verification=None,
        extra=None,
    ):
        """
        Issue the given command

        :param str command: Either a fully-qualified XTCE name or an alias in the
                            format ``NAMESPACE/NAME``.
        :param dict args: named arguments (if the command requires these)
        :param bool dry_run: If ``True`` the command is not actually issued. This
                             can be used to test if the server would generate
                             errors when preparing the command (for example
                             because an argument is missing).
        :param str comment: Comment attached to the command.
        :param .VerificationConfig verification: Overrides to the default
                                                 verification handling of this
                                                 command.
        :param dict extra: Extra command options for interpretation by non-core
                           extensions (custom preprocessor, datalinks, command
                           listeners).
                           Note that Yamcs will refuse command options that it
                           does now know about. Extensions should therefore
                           register available options.
        :return: An object providing access to properties of the newly issued
                 command.
        :rtype: .IssuedCommand
        """
        req = commands_service_pb2.IssueCommandRequest()
        req.sequenceNumber = SequenceGenerator.next()
        req.dryRun = dry_run
        if comment:
            req.comment = comment
        if args:
            for key in args:
                assignment = req.assignment.add()
                assignment.name = key
                assignment.value = _to_argument_value(args[key])

        if verification:
            if verification._disable_all:
                req.disableVerifiers = True
            else:
                for verifier in verification._disabled:
                    req.verifierConfig[verifier].disable = True
                for verifier in verification._check_windows:
                    window = verification._check_windows[verifier]
                    if window["start"]:
                        start = int(window["start"] * 1000)
                        req.verifierConfig[
                            verifier
                        ].checkWindow.timeToStartChecking = start
                    if window["stop"]:
                        stop = int(window["stop"] * 1000)
                        req.verifierConfig[
                            verifier
                        ].checkWindow.timeToStopChecking = stop

        if extra:
            for key in extra:
                req.extra[key].MergeFrom(_build_value_proto(extra[key]))

        command = adapt_name_for_rest(command)
        url = "/processors/{}/{}/commands{}".format(
            self._instance, self._processor, command
        )
        response = self.ctx.post_proto(url, data=req.SerializeToString())
        proto = commands_service_pb2.IssueCommandResponse()
        proto.ParseFromString(response.content)
        return IssuedCommand(proto)