Example #1
0
    def _update_atom_details(self, ad, txn, create_missing=False):
        # Determine whether the desired data exists or not.
        ad_path = paths.join(self.atom_path, ad.uuid)
        e_ad = None
        try:
            ad_data, _zstat = self._client.get(ad_path)
        except k_exc.NoNodeError:
            # Not-existent: create or raise exception.
            raise exc.NotFound("No atom details found with id: %s" % ad.uuid)
        else:
            # Existent: read it out.
            try:
                ad_data = misc.decode_json(ad_data)
                ad_cls = logbook.atom_detail_class(ad_data['type'])
                e_ad = ad_cls.from_dict(ad_data['atom'])
            except KeyError:
                pass

        # Update and write it back
        if e_ad:
            e_ad = e_ad.merge(ad)
        else:
            e_ad = ad
        ad_data = base._format_atom(e_ad)
        txn.set_data(ad_path,
                     misc.binary_encode(jsonutils.dumps(ad_data)))
        return e_ad
Example #2
0
    def _update_atom_details(self, ad, txn, create_missing=False):
        # Determine whether the desired data exists or not.
        ad_path = paths.join(self.atom_path, ad.uuid)
        e_ad = None
        try:
            ad_data, _zstat = self._client.get(ad_path)
        except k_exc.NoNodeError:
            # Not-existent: create or raise exception.
            if not create_missing:
                raise exc.NotFound("No atom details found with"
                                   " id: %s" % ad.uuid)
            else:
                txn.create(ad_path)
        else:
            # Existent: read it out.
            try:
                ad_data = misc.decode_json(ad_data)
                ad_cls = logbook.atom_detail_class(ad_data['type'])
                e_ad = ad_cls.from_dict(ad_data['atom'])
            except KeyError:
                pass

        # Update and write it back
        if e_ad:
            e_ad = e_ad.merge(ad)
        else:
            e_ad = ad
        ad_data = base._format_atom(e_ad)
        txn.set_data(ad_path, misc.binary_encode(jsonutils.dumps(ad_data)))
        return e_ad
Example #3
0
 def _get_atom_details(self, ad_uuid):
     ad_path = paths.join(self.atom_path, ad_uuid)
     try:
         ad_data, _zstat = self._client.get(ad_path)
     except k_exc.NoNodeError:
         raise exc.NotFound("No atom details found with id: %s" % ad_uuid)
     else:
         ad_data = misc.decode_json(ad_data)
         ad_cls = logbook.atom_detail_class(ad_data['type'])
         return ad_cls.from_dict(ad_data['atom'])
Example #4
0
 def _deserialize(cls, data):
     if issubclass(cls, logbook.LogBook):
         return cls.from_dict(data, unmarshal_time=True)
     elif issubclass(cls, logbook.FlowDetail):
         return cls.from_dict(data)
     elif issubclass(cls, logbook.AtomDetail):
         atom_class = logbook.atom_detail_class(data['type'])
         return atom_class.from_dict(data['atom'])
     else:
         raise exc.StorageFailure("Invalid storage class %s" % cls)
Example #5
0
 def _get_atom_details(self, ad_uuid):
     ad_path = paths.join(self.atom_path, ad_uuid)
     try:
         ad_data, _zstat = self._client.get(ad_path)
     except k_exc.NoNodeError:
         raise exc.NotFound("No atom details found with id: %s" % ad_uuid)
     else:
         ad_data = misc.decode_json(ad_data)
         ad_cls = logbook.atom_detail_class(ad_data['type'])
         return ad_cls.from_dict(ad_data['atom'])
Example #6
0
 def _deserialize(cls, data):
     if issubclass(cls, logbook.LogBook):
         return cls.from_dict(data, unmarshal_time=True)
     elif issubclass(cls, logbook.FlowDetail):
         return cls.from_dict(data)
     elif issubclass(cls, logbook.AtomDetail):
         atom_class = logbook.atom_detail_class(data['type'])
         return atom_class.from_dict(data['atom'])
     else:
         raise exc.StorageFailure("Invalid storage class %s" % cls)
Example #7
0
def _convert_ad_to_external(ad):
    # Convert from sqlalchemy model -> external model, this allows us
    # to change the internal sqlalchemy model easily by forcing a defined
    # interface (that isn't the sqlalchemy model itself).
    atom_cls = logbook.atom_detail_class(ad.atom_type)
    return atom_cls.from_dict({
        'state': ad.state,
        'intention': ad.intention,
        'results': ad.results,
        'failure': ad.failure,
        'meta': ad.meta,
        'version': ad.version,
        'name': ad.name,
        'uuid': ad.uuid,
    })
Example #8
0
def _convert_ad_to_external(ad):
    # Convert from sqlalchemy model -> external model, this allows us
    # to change the internal sqlalchemy model easily by forcing a defined
    # interface (that isn't the sqlalchemy model itself).
    atom_cls = logbook.atom_detail_class(ad.atom_type)
    return atom_cls.from_dict({
        'state': ad.state,
        'intention': ad.intention,
        'results': ad.results,
        'failure': ad.failure,
        'meta': ad.meta,
        'version': ad.version,
        'name': ad.name,
        'uuid': ad.uuid,
    })
Example #9
0
 def convert_atom_detail(row):
     row = dict(row.items())
     atom_cls = logbook.atom_detail_class(row.pop('atom_type'))
     return atom_cls.from_dict(row)
Example #10
0
 def _get():
     ad_path = os.path.join(self._atom_path, uuid)
     ad_data = misc.decode_json(self._read_from(ad_path))
     ad_cls = logbook.atom_detail_class(ad_data['type'])
     return ad_cls.from_dict(ad_data['atom'])
Example #11
0
 def _get():
     ad_path = os.path.join(self._atom_path, uuid)
     ad_data = misc.decode_json(self._read_from(ad_path))
     ad_cls = logbook.atom_detail_class(ad_data['type'])
     return ad_cls.from_dict(ad_data['atom'])
Example #12
0
 def convert_atom_detail(row):
     row = dict(row.items())
     atom_cls = logbook.atom_detail_class(row.pop('atom_type'))
     return atom_cls.from_dict(row)