예제 #1
0
    def add_jobs(self, jobs):
        uids = []
        if isinstance(jobs, dict):
            jobs = list(jobs)
        for job in jobs:
            schema.validate('Job', job)
            uid = str(uuid.uuid1())
            job['uuid'] = uid
            self.inst.jobs.add_job(job)
            uids.append(uid)

        return uids
예제 #2
0
파일: server.py 프로젝트: ahaas/smap
    def add_jobs(self, jobs):
        uids = []
        if isinstance(jobs, dict):
            jobs = list(jobs)
        for job in jobs:
            schema.validate('Job', job)
            uid = str(uuid.uuid1())
            job['uuid'] = uid
            self.inst.jobs.add_job(job)
            uids.append(uid)

        return uids
예제 #3
0
파일: core.py 프로젝트: tarunsmalviya/smap
    def __init__(self,
                 new_uuid,
                 unit, 
                 data_type=None,
                 timezone=None,
                 description=None,
                 buffersz=None,
                 milliseconds=False,
                 impl=None, 
                 read_limit=0,
                 write_limit=0,
                 autoadd=False):
        """
:param new_uuid: a :py:class:`uuid.UUID`
:param string unit: the engineering units of this timeseries
:param string data_type: the data type of the data. Options are ``long`` or ``double``
:param string timezone: a tzinfo-style timezone.
:param string description: the value of sMAP Description field.
:param int buffersz: how many readings to present when the timeseries is retrieved with a ``GET``.
:param bool milliseconds: if True, then the stream publishes time in
 units of Unix milliseconds.  Otherwise, normal unix timestamps are
 assumed
"""
        if not data_type:
            data_type = self.DEFAULTS['Properties/ReadingType']
        if not timezone:
            timezone = self.DEFAULTS['Properties/Timezone']
        if not buffersz:
            buffersz = self.DEFAULTS['BufferSize']

        if isinstance(new_uuid, dict):
            if not schema.validate('Timeseries', new_uuid):
                raise SmapSchemaException("Initializing timeseries failed -- invalid object")
            dict.__init__(self, new_uuid)
            reading_init = new_uuid['Readings']
        else:
            self.__setitem__("uuid", new_uuid)
            self.__setitem__("Properties", {
                    'UnitofMeasure' : unit,
                    'ReadingType' : data_type,
                    'Timezone' : timezone})
            if description:
                self.__setitem__("Description", description)
            reading_init = []
        self.dirty = True
        self.milliseconds = milliseconds
        self.__setitem__("Readings", util.FixedSizeList(buffersz, init=reading_init))

        self.impl = impl
        self.autoadd = autoadd
        if self.impl:
            self.reader = util.RateLimiter(read_limit, 
                                      lambda req: util.syncMaybeDeferred(self.impl.get_state, req),
                                      lambda req: self)
            self.writer = util.RateLimiter(write_limit, 
                                      lambda req, state: util.syncMaybeDeferred(self.impl.set_state, req, state))
        else:
            self.reader = lambda req: (True, self)
            self.writer = None
예제 #4
0
파일: server.py 프로젝트: ahaas/smap
def read_report(self, request, duplicate_error=True):
    """Read a Reporting object sent by the client.  Will validate the
    object and remove extra fields which are not specified in the
    schema.
    """
    obj = schema.filter_fields('Reporting', json.load(request.content))
    if not schema.validate("Reporting", obj):
        raise util.SmapSchemaException("Invalid Reporting object (does not validate)", 400)
    if duplicate_error and self.reports.get_report(obj['uuid']):
        raise util.SmapException("Report instance already exists!", 400)
    return obj
예제 #5
0
 def __setitem__(self, attr, value):
     if attr in self.FIELDS:
         dict.__setitem__(self, attr, value)
         if attr != 'uuid':
             if not schema.validate("Timeseries", self):
                 raise SmapSchemaException("Invalid schema in "
                                           "Timeseries for " + attr)
         # time series start dirty so when we publish them the
         # first time we send all their metadata.
         self.dirty = True
     else:
         raise KeyError(attr + " can not be set on a Timeseries!")
예제 #6
0
def read_report(self, request, duplicate_error=True):
    """Read a Reporting object sent by the client.  Will validate the
    object and remove extra fields which are not specified in the
    schema.
    """
    obj = schema.filter_fields('Reporting', json.load(request.content))
    if not schema.validate("Reporting", obj):
        raise util.SmapSchemaException(
            "Invalid Reporting object (does not validate)", 400)
    if duplicate_error and self.reports.get_report(obj['uuid']):
        raise util.SmapException("Report instance already exists!", 400)
    return obj
예제 #7
0
파일: core.py 프로젝트: andrewfang/smap
 def __setitem__(self, attr, value):
     if attr in self.FIELDS:
         dict.__setitem__(self, attr, value)
         if attr != 'uuid':
             if not schema.validate("Timeseries", self):
                 raise SmapSchemaException("Invalid schema in " 
                                           "Timeseries for " + 
                                           attr)
         # time series start dirty so when we publish them the
         # first time we send all their metadata.
         self.dirty = True
     else:
         raise KeyError(attr + " can not be set on a Timeseries!")
예제 #8
0
    def __init__(self, path, inst=None, description=None, *args):
        """
        :param string path: the path where the collection will be added
        :param SmapInstance inst: the containing :py:class:`SmapInstance` object
        :param string description: the contents of the sMAP description field
        :raise SmapSchemaException: if the resulting object does not validate
        """
        self.inst = inst
        setattr(self, 'path', util.norm_path(path))
        if len(args) == 1 and isinstance(args[0], dict):
            dict.__init__(self, args[0])
        else:
            self.__setitem__("Contents", [])

        if not schema.validate("Collection", self):
            raise SmapSchemaException("Error instantiating Collection: "
                                      "invalid parameter")
예제 #9
0
파일: core.py 프로젝트: andrewfang/smap
    def __init__(self, path, inst=None, description=None, *args):
        """
        :param string path: the path where the collection will be added
        :param SmapInstance inst: the containing :py:class:`SmapInstance` object
        :param string description: the contents of the sMAP description field
        :raise SmapSchemaException: if the resulting object does not validate
        """
        self.inst = inst
        setattr(self, 'path', util.norm_path(path))
        if len(args) == 1 and isinstance(args[0], dict):
            dict.__init__(self, args[0])
        else:
            self.__setitem__("Contents", [])

        if not schema.validate("Collection", self):
            raise SmapSchemaException("Error instantiating Collection: " 
                                      "invalid parameter")