示例#1
0
    def XmlCreate(self):

        self.XmlAddMembers()

        self.XmlData = []
        self.XmlData.append('<?xml version="1.0" encoding="UTF-8"?>\n')
        self.XmlData.append('<ProbeDetails>\n')

        # Add the record indentity

        self.XmlData.append('<RecordIdentity recordId="' + socket.getfqdn() +
                            ':' + str(global_state.RecordPid) + '.' +
                            str(record.RecordId) + '" createTime="' +
                            utils.TimeToString(time.gmtime()) + '" />\n')
        record.RecordId += 1

        for data in self.RecordData:
            self.XmlData.append('\t')
            self.XmlData.append(data)
            self.XmlData.append('\n')

        if len(self.__ProbeDetails__) > 0:
            for data in self.__ProbeDetails__:
                self.XmlData.append('\t')
                self.XmlData.append(data)
                self.XmlData.append('\n')

        self.XmlData.append('</ProbeDetails>\n')
示例#2
0
 def Timestamp(self, value):
     """ The time the record was gathered
     Expressed in number of second since epoch or a string formated using the format xsd:dateTime. """
     if isinstance(value, types.StringType):
         realvalue = value
     else:
         realvalue = utils.TimeToString(time.gmtime(value))
     self.AppendToList(self.RecordData, "Timestamp", "", realvalue)
示例#3
0
    def Timestamp(self, value):
        """
        The time the metric was gathered
        Expressed in number of second since epoch or a string formated using the format xsd:dateTime.
        """
        if type(value)==str:
            realvalue = value
        else:
            realvalue = utils.TimeToString(time.gmtime(value))
#        self.AppendToList(self.RecordData,   "Timestamp",   self.Type(timetype)+self.Description(description),   realvalue)
        self.AppendToList(self.RecordData,   "Timestamp",   "",   realvalue)
示例#4
0
    def __init__(self):

        # Initializer

        super(self.__class__, self).__init__()
        DebugPrint(1, 'Creating a ProbeDetails record ' + utils.TimeToString())

        self.__ProbeDetails__ = []

        self.ReporterLibrary('Gratia')

        for data in __handshakeReg__:
            self.__ProbeDetails__ = self.AppendToList(self.__ProbeDetails__,
                                                      data[0], data[1],
                                                      data[2])
示例#5
0
    def __init__(self):

        # See the function ResourceType for details on the
        # parameter
        if not config.Config:
            DebugPrint(0, "Error: Configuration is not initialized")
            raise utils.InternalError("Configuration is not initialized")

        DebugPrint(2, 'Creating a Record ' + utils.TimeToString())
        self.XmlData = []
        self.__ProbeName = Config.get_ProbeName()
        self.__ProbeNameDescription = r''
        self.__SiteName = Config.get_SiteName()
        self.__SiteNameDescription = r''
        self.__Grid = Config.get_Grid()
        self.__GridDescription = r''
        self.RecordData = []
        self.TransientInputFiles = []
        self.__VOOverrid = Config.get_VOOverride()
示例#6
0
    def __init__(self):

        # Initializer

        super(self.__class__, self).__init__()
        DebugPrint(1, 'Creating a ProbeDetails record ' + utils.TimeToString())

        self.__ProbeDetails__ = []

        # Extract the revision number

        rev = utils.ExtractSvnRevision('$Revision: 3997 $')

        self.ReporterLibrary('Gratia', rev)

        for data in __handshakeReg__:
            self.__ProbeDetails__ = self.AppendToList(self.__ProbeDetails__,
                                                      data[0], data[1],
                                                      data[2])
示例#7
0
    def XmlCreate(self):

        self.XmlAddMembers()

        self.XmlData = []
        self.XmlData.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
        self.XmlData.append(
            "<Subcluster xmlns:urwg=\"http://www.gridforum.org/2003/ur-wg\">\n"
        )

        # Add the record indentity
        self.XmlData.append("<RecordIdentity urwg:recordId=\"" +
                            socket.getfqdn() + ":" +
                            str(global_state.RecordPid) + "." +
                            str(record.RecordId) + "\" urwg:createTime=\"" +
                            utils.TimeToString(time.gmtime()) + "\" />\n")
        record.RecordId += 1

        for data in self.RecordData:
            self.XmlData.append("\t")
            self.XmlData.append(data)
            self.XmlData.append("\n")
        self.XmlData.append("</Subcluster>\n")
示例#8
0
def sendUsageXML(meterId, recordXml, messageType='URLEncodedUpdate'):
    """
    sendUsageXML
   
    Author - Tim Byrne

    Contacts the 'GratiaCollector' web service, sending it an xml representation of Usage data
 
    param - meterId:  A unique Id for this meter, something the web service can use to identify 
          communication from this meter
    param - xmlData:  A string representation of usage xml
    """

    global connectionError
    global certificateRejected
    global __resending

    # Backward compatibility with old collectors

    if global_state.collector__wantsUrlencodeRecords == 0:
        messageType = 'update'

    try:

        # Connect to the web service, in case we aren't already
        # connected.  If we are already connected, this call will do
        # nothing

        if not connect():  # Failed to connect
            raise IOError  # Kick out to except: clause

        # Generate a unique Id for this transaction

        transactionId = meterId + utils.TimeToString().replace(':', r'')
        DebugPrint(3, 'TransactionId:  ' + transactionId)

        if Config.get_UseSSL() == 0 and Config.get_UseSoapProtocol() == 1:

            DebugPrint(0, 'Error: SOAP connection is no longer supported.')
            connectionError = True

            response_obj = response.Response(
                response.Response.Failed,
                'Error: SOAP connection is no longer supported.')
        elif Config.get_UseSSL() == 0 and Config.get_UseSoapProtocol() == 0:
            queryString = encodeData(messageType, recordXml)

            # Attempt to make sure Collector can actually read the post.

            headers = {'Content-type': 'application/x-www-form-urlencoded'}

            responseString = postRequest(connection,
                                         Config.get_CollectorService(),
                                         queryString, headers)

            response_obj = response.Response(response.Response.AutoSet,
                                             responseString)
            if response_obj.getCode() == response.Response.UnknownCommand:

                # We're talking to an old collector

                DebugPrint(
                    0,
                    'Unable to send new record to old collector -- engaging backwards-compatible mode for remainder of connection'
                )
                global_state.collector__wantsUrlencodeRecords = 0

                # Try again with the same record before returning to the
                # caller. There will be no infinite recursion because
                # __url_records has been reset

                response_obj = sendUsageXML(meterId, recordXml, messageType)
        else:

            # SSL

            DebugPrint(4, 'DEBUG: Encoding data for SSL transmission')
            queryString = encodeData(messageType, recordXml)
            DebugPrint(4, 'DEBUG: Encoding data for SSL transmission: OK')

            # Attempt to make sure Collector can actually read the post.

            headers = {'Content-type': 'application/x-www-form-urlencoded'}
            responseString = postRequest(connection,
                                         Config.get_SSLCollectorService(),
                                         queryString, headers)
            response_obj = response.Response(response.Response.AutoSet,
                                             responseString)

            if response_obj.getCode() == response.Response.UnknownCommand:

                # We're talking to an old collector

                DebugPrint(
                    0,
                    'Unable to send new record to old collector -- engaging backwards-compatible mode for remainder of connection'
                )
                global_state.collector__wantsUrlencodeRecords = 0

                # Try again with the same record before returning to the
                # caller. There will be no infinite recursion because
                # __url_records has been reset

                response_obj = sendUsageXML(meterId, recordXml, messageType)
            elif response_obj.getCode() == response.Response.BadCertificate:
                connectionError = True
                certificateRejected = True
                response_obj = response.Response(response.Response.AutoSet,
                                                 responseString)

        if response_obj.getCode == response.Response.ConnectionError or response_obj.getCode == response.Response.CollectorError:

            # Server threw an error - 503, maybe?

            connectionError = True
            response_obj = response.Response(
                response.Response.Failed,
                r'Server unable to receive data: save for reprocessing')
    except SystemExit:

        raise
    except socket.error, ex:
        if ex.args[0] == 111:
            DebugPrint(
                0,
                'Connection refused while attempting to send xml to web service'
            )
        else:
            DebugPrint(
                0,
                'Failed to send xml to web service due to an error of type "',
                sys.exc_info()[0], '": ',
                sys.exc_info()[1])
            DebugPrintTraceback(1)
        response_obj = response.Response(
            response.Response.Failed,
            r'Server unable to receive data: save for reprocessing')
示例#9
0
 def __init__(self):
     # Initializer
     super(self.__class__, self).__init__()
     DebugPrint(0, "Creating a Subcluster Record" + utils.TimeToString())
示例#10
0
 def __init__(self):
     # Initializer
     super(self.__class__, self).__init__()
     DebugPrint(0,
                "Creating a StorageElement Record" + utils.TimeToString())
示例#11
0
 def __init__(self):
     # Initializer
     super(self.__class__, self).__init__()
     DebugPrint(1, "Creating a metric Record " + utils.TimeToString())