def TimestampSpecFromTimestamp(self, timestamp): """Create a timestamp spec from a timestamp value. Args: timestamp: A range of times for consideration (In microseconds). Can be a constant such as ALL_TIMESTAMPS or NEWEST_TIMESTAMP or a tuple of ints (start, end). Returns: An rdfvalue.TimestampSpec() instance. """ if timestamp is None: all_ts = rdf_data_store.TimestampSpec.Type.ALL_TIMESTAMPS return rdf_data_store.TimestampSpec(type=all_ts) if timestamp in (rdf_data_store.TimestampSpec.Type.ALL_TIMESTAMPS, rdf_data_store.TimestampSpec.Type.NEWEST_TIMESTAMP): return rdf_data_store.TimestampSpec(type=timestamp) if timestamp == self.NEWEST_TIMESTAMP: newest = rdf_data_store.TimestampSpec.Type.NEWEST_TIMESTAMP return rdf_data_store.TimestampSpec(type=newest) if isinstance(timestamp, (list, tuple)): start, end = timestamp return rdf_data_store.TimestampSpec( start=start, end=end, type=rdf_data_store.TimestampSpec.Type.RANGED_TIME) return rdf_data_store.TimestampSpec( start=timestamp, type=rdf_data_store.TimestampSpec.Type.SPECIFIC_TIME)
def DeleteAttributes(self, subject, attributes, start=None, end=None, sync=True, token=None): self.security_manager.CheckDataStoreAccess(token, [subject], "w") request = rdf_data_store.DataStoreRequest(subject=[subject]) if isinstance(attributes, basestring): raise ValueError( "String passed to DeleteAttributes (non string iterable expected).") # Set timestamp. start = start or 0 if end is None: end = (2**63) - 1 # sys.maxint request.timestamp = rdf_data_store.TimestampSpec( start=start, end=end, type=rdf_data_store.TimestampSpec.Type.RANGED_TIME) if token: request.token = token if sync: request.sync = sync for attr in attributes: request.values.Append(attribute=attr) typ = rdf_data_server.DataStoreCommand.Command.DELETE_ATTRIBUTES self._MakeRequestSyncOrAsync(request, typ, sync)
def DeleteAttributes(self, subject, attributes, start=None, end=None, sync=True, token=None): request = rdf_data_store.DataStoreRequest(subject=[subject]) # Set timestamp. start = start or 0 if end is None: end = (2**63) - 1 # sys.maxint request.timestamp = rdf_data_store.TimestampSpec( start=start, end=end, type=rdf_data_store.TimestampSpec.Type.RANGED_TIME) if token: request.token = token if sync: request.sync = sync for attr in attributes: request.values.Append(attribute=attr) typ = rdf_data_server.DataStoreCommand.Command.DELETE_ATTRIBUTES self._MakeRequestSyncOrAsync(request, typ, sync)
def LockSubject(self, subject, lease_time): """Locks a specific subject.""" request = rdf_data_store.DataStoreRequest(subject=[subject]) specific = rdf_data_store.TimestampSpec.Type.SPECIFIC_TIME request.timestamp = rdf_data_store.TimestampSpec(start=lease_time, type=specific) typ = rdf_data_server.DataStoreCommand.Command.LOCK_SUBJECT response = self._MakeSyncRequest(request, typ) if not response.results: return None result = response.results[0] if not result.values: return None return result.values[0].value.string
def ExtendSubjectLock(self, subject, transid, lease_time): """Extends lock of subject.""" request = rdf_data_store.DataStoreRequest(subject=[subject]) specific = rdf_data_store.TimestampSpec.Type.SPECIFIC_TIME request.timestamp = rdf_data_store.TimestampSpec(start=lease_time, type=specific) blob = rdf_protodict.DataBlob(string=transid) value = rdf_data_store.DataStoreValue(value=blob) request.values.Append(value) typ = rdf_data_server.DataStoreCommand.Command.EXTEND_SUBJECT response = self._MakeSyncRequest(request, typ) if not response.results: return None result = response.results[0] if not result.values: return None value = result.values[0].value.string return transid if transid == value else None
def LockSubject(self, subject, lease_time, token): """Locks a specific subject.""" self.security_manager.CheckDataStoreAccess(token, [subject], "w") request = rdf_data_store.DataStoreRequest(subject=[subject]) specific = rdf_data_store.TimestampSpec.Type.SPECIFIC_TIME request.timestamp = rdf_data_store.TimestampSpec(start=lease_time, type=specific) if token: request.token = token typ = rdf_data_server.DataStoreCommand.Command.LOCK_SUBJECT response = self._MakeSyncRequest(request, typ) if not response.results: return None result = response.results[0] if not result.values: return None return result.values[0].value.string