def put(self, obj): """ @brief Write a content object to the store. @param obj instance providing cas.ICAStoreObject. @retval defer.Deferred that fires with the obj id. """ data = obj.encode() id = cas.sha1(data, bin=False) d = self.rpc_send('put', {'id': id, 'data': data}) d.addCallback(self._put_callback) #d.addErrback return d
def put(self, obj): """ @brief Write a content object to the store. @param obj instance providing cas.ICAStoreObject. @retval defer.Deferred that fires with the obj id. """ data = obj.encode() id = cas.sha1(data, bin=False) d = self.rpc_send('put', {'id':id, 'data':data}) d.addCallback(self._put_callback) #d.addErrback return d
def test_put(self): b = cas.Blob('test') id = yield self.object_store.put(b) self.failUnlessEqual(id, cas.sha1(b, bin=False))
class ObjectStoreClient(base_service.BaseServiceClient, cas.CAStore): """ The client end of Distributed ObjectStore that presents the same interface as the actual ObjectStore. The main variable is the name and sys-name of the service. All else should be invariant. This is where a caching/mirroring-backend layer can exist. """ interface.implements(objstore.IObjectStore, cas.ICAStore) objectChassis = objstore.ObjectChassis def ObjectChassis(self): """ @brief Factory for creating an active object chassis without explicitly specifying its context (object name/id). @retval objectChassis instance that uses this ObjectStore instance. @note clone and create are the only IObjectStore methods that should be used directly. get and put are use by IObjectChassis... """ return self.objectChassis(self) @defer.inlineCallbacks def create(self, name, baseClass): """ @brief Create a new DataObject with the structure of baseClass. @param name Unique identifier of data object. @param baseClass DataObject class. @retval defer.Deferred that succeeds with an instance of objectChassis. @todo Change name to id """ encoded_baseClass = dataobject.DEncoder().encode(baseClass()) (content, headers, msg) = yield self.rpc_send('create', [name, encoded_baseClass]) if content['status'] == 'OK': obj = content['value'] defer.returnValue(obj) else: defer.returnValue(None) #what to return? @defer.inlineCallbacks def clone(self, name): """ @brief Pull data object out of distributed store into local store. @param name Unique identifier of data object. @retval defer.Deferred that succeeds with an instance of objectChassis. @todo Change name to id. """ (content, headers, msg) = yield self.rpc_send('clone', name) if content['status'] == 'OK': obj = content['value'] defer.returnValue(obj) else: defer.returnValue(None) #what to return? def get(self, id): """ @brief get content object. @param id of content object. @retval defer.Deferred that fires with an object that provides cas.ICAStoreObject. """ d = self.rpc_send('get', id) d.addCallback(self._get_callback, id) d.addErrback(self._get_errback) return d def _get_callback(self, (content, headers, msg), id): """ """ data = content['value'] # This should not be content['value'] if content['status'] == 'OK': """@todo make 'ok' a bool instead """ obj = self.decode(data) if not id == cas.sha1(obj, bin=False): raise cas.CAStoreError("Object Integrity Error!") return obj else: """@todo should check for not found in store error """ raise cas.CAStoreError("Client Error")