Ejemplo n.º 1
0
    def ntnv_asserts(self, function, params):

        alarm = Alarm()
        time_stamp = TimeStamp()
        ntnv = NTNameValue(function, params)
        self.channelRPC.issueRequest(ntnv.getNTNameValue(), False)
        response = self.channelRPC.waitResponse()
        self.assertNotEqual(response, None, "ChannelRPC connection failure.")
        result = NTMultiChannel(response)
        result.getAlarm(alarm)
        result.getTimeStamp(time_stamp)
        self.assertEqual(3, len(str(time_stamp).split(":")))  # Timestamp string format test

        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())
Ejemplo n.º 2
0
def __clientRPC(function, params):
    alarm = Alarm()
    timeStamp = TimeStamp()

    ntnv = NTNameValue(function, params)

    # now do issue + wait
    channelRPC = ChannelRPC("masarService")
    channelRPC.issueConnect()
    if not channelRPC.waitConnect(1.0):
        print "error when waiting connection.", channelRPC.getMessage()
        exit(1)
    channelRPC.issueRequest(ntnv.getNTNameValue(), False)
    result = channelRPC.waitResponse()
    if result is None:
        print channelRPC.getMessage()
        exit(1)
#    print "problem to get nttable using getNTTable()"
    if function in ["retrieveSnapshot", "getLiveMachine", "saveSnapshot"]:
        result = NTMultiChannel(result)
    elif function in ["retrieveServiceEvents", "retrieveServiceConfigs", "retrieveServiceConfigProps"]:
        result = NTTable(result)
        label = result.getLabels()
        print "label", label
        print result.getPVStructure()
    elif function == "updateSnapshotEvent":
        result = NTScalar(result)
#    print "Problem above"
#     print result

    result.getAlarm(alarm)
    # print alarm

    result.getTimeStamp(timeStamp)
    # print timeStamp

    # numberValues = result.getNumberValues()
    # print "numberValues", numberValues

#
#    i = 0
#    while i < numberValues :
#        value = nttable.getValue(i)
#        print "value",label[i],value
#        i += 1
    return result
Ejemplo n.º 3
0
    def ntnv_asserts(self, function, params):

        alarm = Alarm()
        time_stamp = TimeStamp()
        ntnv = NTNameValue(function, params)
        self.channelRPC.issueRequest(ntnv.getNTNameValue(), False)
        response = self.channelRPC.waitResponse()
        self.assertNotEqual(response, None, "ChannelRPC connection failure.")
        result = NTMultiChannel(response)
        result.getAlarm(alarm)
        result.getTimeStamp(time_stamp)
        self.assertEqual(3, len(
            str(time_stamp).split(":")))  # Timestamp string format test

        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())
Ejemplo n.º 4
0
    def testNTMultiChannel(self):
        result = self.gatherv3data.get()
        self.assertTrue(result, "Connection failed with message:  " + self.gatherv3data.getMessage())
        pvstructure = self.gatherv3data.getPVStructure()
        ntmultichannel = NTMultiChannel(pvstructure)

        alarm = Alarm()
        ntmultichannel.getAlarm(alarm)
        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())

        time_stamp = TimeStamp()
        ntmultichannel.getTimeStamp(time_stamp)
        self.assertEqual(3, len(str(time_stamp).split(':')))  # Time stamp format test

        channel_count = ntmultichannel.getNumberChannel()

        self.assertEqual(channel_count, len(self.names))

        test_val_list = (0, 1, 'zero', 'one', 10, 'string value', 1.9, (), (), (), (), (), ())
        self.assertEqual(ntmultichannel.getValue(), test_val_list)

        self.assertEqual(ntmultichannel.getChannelName(), self.names)

        test_connected_list = (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        self.assertEqual(ntmultichannel.getIsConnected(), test_connected_list)

        test_severity_list = (3, 0, 3, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3)
        self.assertEqual(ntmultichannel.getSeverity(), test_severity_list)

        test_status_list = (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
        self.assertEqual(ntmultichannel.getStatus(), test_status_list)

        test_message_list = ('UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM')
        self.assertEqual(ntmultichannel.getMessage(), test_message_list)

        test_dbrtype_list = (0, 5, 0, 0, 5, 0, 6, 4, 0, 1, 5, 2, 6)
        self.assertEqual(ntmultichannel.getDbrType(), test_dbrtype_list)

        test_secondspastepoch_list = (631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000)
        self.assertEqual(ntmultichannel.getSecondsPastEpoch(), test_secondspastepoch_list)

        test_nanoseconds_list = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.assertEqual(ntmultichannel.getNanoseconds(), test_nanoseconds_list)

        test_usertag_list = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.assertEqual(ntmultichannel.getUserTag(), test_usertag_list)

        self.assertEqual(type(ntmultichannel.getDescriptor()), StringType)
Ejemplo n.º 5
0
    def saveSnapshot(self, params):
        key = ['servicename', 'configname', 'comment']
        service, config, comment = self._parseParams(params[1], key)
        if not service:
            service = self.__servicename
        
        result = NTMultiChannel(params[0])
        dataLen = result.getNumberChannel() 
        if dataLen == 0:
            raise RuntimeError("No available snapshot data.")
        
        # values format: the value is raw data from IOC
        # [(pv name), (value), (dbr type),
        #  (isConnected), (secondsPastEpoch), (nanoSeconds), (timeStampTag),
        #  (alarmSeverity), (alarmStatus), (alarmMessage)]
        pvnames = result.getChannelName()
        values = result.getValue()
        dbrtype = result.getDbrType()
        isconnected = result.getIsConnected()
        severity = result.getSeverity()
        status = result.getStatus()
        message = result.getMessage()
        sec = result.getSecondsPastEpoch()
        nanosec = result.getNanoseconds()
        usertag = result.getUserTag()

        # data format: the data is prepared to save into rdb
        # rawdata format
        # [('channel name', 'string value', 'double value', 'long value', 'dbr type', 'is connected', 
        #  'seconds past epoch', 'nano seconds', 'time stamp tag', 'alarm severity', 'alarm status', 'alarm message',
        #  'is_array', 'array_value'),
        #  ...
        # ]
        datas = []

        for i in range(dataLen):
            tmp = []
            if isinstance(values[i], (list, tuple)):
                tmp = [pvnames[i], "", None, None, dbrtype[i], isconnected[i],
                       sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i],
                       1, values[i]]
            else:
                if dbrtype[i] in self.epicsString:
                     tmp = [pvnames[i], values[i], None, None, dbrtype[i], isconnected[i],
                            sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i],
                            0, None]
                else:
                     tmp = [pvnames[i], str(values[i]), values[i], values[i], dbrtype[i], isconnected[i],
                            sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i],
                            0, None]
            datas.append(tmp)

        # save into database
        try:
            conn = pymasar.utils.connect()
            eid, result = pymasar.masardata.saveSnapshot(conn, datas, servicename=service, configname=config, comment=comment)
            pymasar.utils.save(conn)
            pymasar.utils.close(conn)
            result.insert(0, eid)
            return result
        except:
            # keep the same format with a normal operation
            return [-1]
Ejemplo n.º 6
0
     'masarExample0000',
     'masarExample0001',
     'masarExample0004',
     'masarExampleCharArray',
     'masarExampleUCharArray',
     'masarExampleStringArray',
     'masarExampleShortArray',
     'masarExampleLongArray',
     'masarExampleFloatArray',
     'masarExampleDoubleArray',
     )
 gatherV3Data = GatherV3Data(names)
 gatherV3Data.connect(2.0)
 gatherV3Data.get()
 pvStructure = gatherV3Data.getPVStructure()
 ntmultiChannel = NTMultiChannel(pvStructure)
 print ntmultiChannel
 alarm = Alarm()
 ntmultiChannel.getAlarm(alarm)
 print "alarm:" ,alarm
 timeStamp = TimeStamp()
 ntmultiChannel.getTimeStamp(timeStamp)
 print "timeStamp:",timeStamp
 print "numberChannel:" ,ntmultiChannel.getNumberChannel();
 print "value:"
 print ntmultiChannel.getValue();
 print "channelName"
 print ntmultiChannel.getChannelName();
 print "isConnected:"
 print ntmultiChannel.getIsConnected();
 print "severity:"
Ejemplo n.º 7
0
    def saveSnapshot(self, params):
        key = ['servicename', 'configname', 'comment']
        service, config, comment = self._parseParams(params[1], key)
        if not service:
            service = self.__servicename

        result = NTMultiChannel(params[0])
        dataLen = result.getNumberChannel()
        if dataLen == 0:
            raise RuntimeError("No available snapshot data.")

        # values format: the value is raw data from IOC
        # [(pv name), (value), (dbr type),
        #  (isConnected), (secondsPastEpoch), (nanoSeconds), (timeStampTag),
        #  (alarmSeverity), (alarmStatus), (alarmMessage)]
        pvnames = result.getChannelName()
        values = result.getValue()
        dbrtype = result.getDbrType()
        isconnected = result.getIsConnected()
        severity = result.getSeverity()
        status = result.getStatus()
        message = result.getMessage()
        sec = result.getSecondsPastEpoch()
        nanosec = result.getNanoseconds()
        usertag = result.getUserTag()

        # data format: the data is prepared to save into rdb
        # rawdata format
        # [('channel name', 'string value', 'double value', 'long value', 'dbr type', 'is connected',
        #  'seconds past epoch', 'nano seconds', 'time stamp tag', 'alarm severity', 'alarm status', 'alarm message',
        #  'is_array', 'array_value'),
        #  ...
        # ]
        datas = []

        for i in range(dataLen):
            tmp = []
            if isinstance(values[i], (list, tuple)):
                tmp = [
                    pvnames[i], "", None, None, dbrtype[i], isconnected[i],
                    sec[i], nanosec[i], usertag[i], severity[i], status[i],
                    message[i], 1, values[i]
                ]
            else:
                if dbrtype[i] in self.epicsString:
                    tmp = [
                        pvnames[i], values[i], None, None, dbrtype[i],
                        isconnected[i], sec[i], nanosec[i], usertag[i],
                        severity[i], status[i], message[i], 0, None
                    ]
                else:
                    tmp = [
                        pvnames[i],
                        str(values[i]), values[i], values[i], dbrtype[i],
                        isconnected[i], sec[i], nanosec[i], usertag[i],
                        severity[i], status[i], message[i], 0, None
                    ]
            datas.append(tmp)

        # save into database
        try:
            conn = pymasar.utils.connect()
            eid, result = pymasar.masardata.saveSnapshot(conn,
                                                         datas,
                                                         servicename=service,
                                                         configname=config,
                                                         comment=comment)
            pymasar.utils.save(conn)
            pymasar.utils.close(conn)
            result.insert(0, eid)
            return result
        except:
            # keep the same format with a normal operation
            return [-1]
Ejemplo n.º 8
0
    def testNTMultiChannel(self):
        result = self.gatherv3data.get()
        self.assertTrue(
            result, "Connection failed with message:  " +
            self.gatherv3data.getMessage())
        pvstructure = self.gatherv3data.getPVStructure()
        ntmultichannel = NTMultiChannel(pvstructure)

        alarm = Alarm()
        ntmultichannel.getAlarm(alarm)
        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())

        time_stamp = TimeStamp()
        ntmultichannel.getTimeStamp(time_stamp)
        self.assertEqual(3, len(
            str(time_stamp).split(':')))  # Time stamp format test

        channel_count = ntmultichannel.getNumberChannel()

        self.assertEqual(channel_count, len(self.names))

        test_val_list = (0, 1, 'zero', 'one', 10, 'string value', 1.9, (), (),
                         (), (), (), ())
        self.assertEqual(ntmultichannel.getValue(), test_val_list)

        self.assertEqual(ntmultichannel.getChannelName(), self.names)

        test_connected_list = (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        self.assertEqual(ntmultichannel.getIsConnected(), test_connected_list)

        test_severity_list = (3, 0, 3, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3)
        self.assertEqual(ntmultichannel.getSeverity(), test_severity_list)

        test_status_list = (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
        self.assertEqual(ntmultichannel.getStatus(), test_status_list)

        test_message_list = ('UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM')
        self.assertEqual(ntmultichannel.getMessage(), test_message_list)

        test_dbrtype_list = (0, 5, 0, 0, 5, 0, 6, 4, 0, 1, 5, 2, 6)
        self.assertEqual(ntmultichannel.getDbrType(), test_dbrtype_list)

        test_secondspastepoch_list = (631152000, 631152000, 631152000,
                                      631152000, 631152000, 631152000,
                                      631152000, 631152000, 631152000,
                                      631152000, 631152000, 631152000,
                                      631152000)
        self.assertEqual(ntmultichannel.getSecondsPastEpoch(),
                         test_secondspastepoch_list)

        test_nanoseconds_list = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.assertEqual(ntmultichannel.getNanoseconds(),
                         test_nanoseconds_list)

        test_usertag_list = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.assertEqual(ntmultichannel.getUserTag(), test_usertag_list)

        self.assertEqual(type(ntmultichannel.getDescriptor()), StringType)
Ejemplo n.º 9
0
    def saveSnapshot(self, params):
        """Save event with data.

        :param params: a dictionary to carry query condition with structure like: ::

            [[(channel name,), (string value,),(double value,),(long value,),(dbr type),(is connected),
              (second past epoch,),(nano seconds,),(time stamp tag,),
              (alarm severity,),(alarm status,),(alarm message,),
              (is_array), (array_value)
             ],
             {"configname": , # configuration name which the new data set belongs to
              "comment": [optional], # comment description for this new data set
              "approval": [optional], # approval status, False is not provided
              "username": [optional], # user name who commands this action
             }
            ]

        :returns: list with tuple with header description for each field. Structure like: ::

            [event_id] or [-1] if fault

        :raises: ValueError

        """
        key = ['configname', 'comment', 'approval', 'username']
        config, comment, approval, username = self._parseParams(params[1], key)
        if config is None:
            raise ValueError("Unknown configuration when saving a new snapshot event.")
        if approval is None:
            approval = False
        else:
            approval = bool(json.loads(str(approval).lower()))

        result = NTMultiChannel(params[0])
        dataLen = result.getNumberChannel()
        if dataLen == 0:
            raise RuntimeError("No available snapshot data.")

        # values format: the value is raw data from IOC
        # [(channel name,), (value,), (dbr type), (is connected),
        #  (second past epoch,), (nano seconds,), (time stamp tag,),
        # (alarm severity,), (alarm status,), (alarm message,)]
        pvnames = result.getChannelName()
        values = result.getValue()
        dbrtype = result.getDbrType()
        isconnected = result.getIsConnected()
        severity = result.getSeverity()
        status = result.getStatus()
        message = result.getMessage()
        sec = result.getSecondsPastEpoch()
        nanosec = result.getNanoseconds()
        usertag = result.getUserTag()

        # data format: the data is prepared to save into rdb
        # rawdata format
        # [('channel name', 'string value', 'double value', 'long value', 'dbr type', 'is connected',
        #   'seconds past epoch', 'nano seconds', 'time stamp tag', 'alarm severity', 'alarm status',
        #   'alarm message', 'is_array', 'array_value'),
        #  ...
        # ]
        datas = []

        # get IOC raw data
        for i in range(dataLen):
            tmp = []
            if isinstance(values[i], (list, tuple)):
                tmp = [pvnames[i], "", None, None, dbrtype[i], isconnected[i],
                       sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i],
                       1, values[i]]
            else:
                if dbrtype[i] in self.epicsString:
                     tmp = [pvnames[i], values[i], None, None, dbrtype[i], isconnected[i],
                            sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i],
                            0, None]
                else:
                     tmp = [pvnames[i], str(values[i]), values[i], values[i], dbrtype[i], isconnected[i],
                            sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i],
                            0, None]
            datas.append(tmp)

        # save into database
        try:
            mongoconn, collection = utils.conn(host=os.environ["MASAR_MONGO_HOST"],
                                               port=os.environ["MASAR_MONGO_PORT"],
                                               db=os.environ["MASAR_MONGO_DB"])
            configs = pymasar.retrieveconfig(mongoconn, collection, name=config)
            if len(configs) != 1:
                raise RuntimeError("Cannot find a unique configuration.")

            eid = pymasar.saveevent(mongoconn, collection,
                                    configidx=configs[0]["configidx"],
                                    comment=comment,
                                    approval=approval,
                                    username=username,
                                    masar_data=datas)

            utils.close(mongoconn)
            return [eid, ]
        except:
            # keep the same format with a normal operation
            return [-1]
Ejemplo n.º 10
0
def __clientRPC(function, params):
    alarm = Alarm()
    timeStamp = TimeStamp()

    ntnv = NTNameValue(function, params)

    # now do issue + wait
    channelRPC = ChannelRPC("masarService")
    channelRPC.issueConnect()
    if not channelRPC.waitConnect(1.0):
        print "error when waiting connection.", channelRPC.getMessage()
        exit(1)
    channelRPC.issueRequest(ntnv.getNTNameValue(), False)
    result = channelRPC.waitResponse()
    if result is None:
        print channelRPC.getMessage()
        exit(1)
#    print "problem to get nttable using getNTTable()"
    if function in ["retrieveSnapshot", "getLiveMachine", "saveSnapshot"]:
        result = NTMultiChannel(result)
    elif function in [
            "retrieveServiceEvents", "retrieveServiceConfigs",
            "retrieveServiceConfigProps"
    ]:
        result = NTTable(result)
        label = result.getLabels()
        print "label", label
        print result.getPVStructure()
    elif function == "updateSnapshotEvent":
        result = NTScalar(result)


#    print "Problem above"
#     print result

    result.getAlarm(alarm)
    # print alarm

    result.getTimeStamp(timeStamp)
    # print timeStamp

    # numberValues = result.getNumberValues()
    # print "numberValues", numberValues

    #
    #    i = 0
    #    while i < numberValues :
    #        value = nttable.getValue(i)
    #        print "value",label[i],value
    #        i += 1
    return result
Ejemplo n.º 11
0
     'masarExample0000',
     'masarExample0001',
     'masarExample0004',
     'masarExampleCharArray',
     'masarExampleUCharArray',
     'masarExampleStringArray',
     'masarExampleShortArray',
     'masarExampleLongArray',
     'masarExampleFloatArray',
     'masarExampleDoubleArray',
 )
 gatherV3Data = GatherV3Data(names)
 gatherV3Data.connect(2.0)
 gatherV3Data.get()
 pvStructure = gatherV3Data.getPVStructure()
 ntmultiChannel = NTMultiChannel(pvStructure)
 print ntmultiChannel
 alarm = Alarm()
 ntmultiChannel.getAlarm(alarm)
 print "alarm:", alarm
 timeStamp = TimeStamp()
 ntmultiChannel.getTimeStamp(timeStamp)
 print "timeStamp:", timeStamp
 print "numberChannel:", ntmultiChannel.getNumberChannel()
 print "value:"
 print ntmultiChannel.getValue()
 print "channelName"
 print ntmultiChannel.getChannelName()
 print "isConnected:"
 print ntmultiChannel.getIsConnected()
 print "severity:"