def get_jdg_history(): hostname= os.getenv('JDG_HOSTNAME','0.0.0.0') basepath=os.getenv('BASE_PATH','/opt/imagerecognize/') remote_cache = RemoteCache(host=hostname) #os.chdir(basepath) files=glob.glob(".rad-img-recog/*") mock_data={} mock_data["results"]=[] bulk_data= remote_cache.bulk_get() for f in files: name=bulk_data[(f.split("/")[1])] data =json.loads(name) #print data mock_data["results"].append({ "filename": f.split("/")[1], "classification": data["pred"][0][1], "percentage":data["pred"][0][0] }) mock_data['time_taken']=remote_cache.get("time_taken") mock_data['last_transaction']=remote_cache.get("last_transaction") if (len(files) <10): mock_data["num_results"]=len(files) mock_data["num_pages"]=1 else: mock_data["num_results"]=len(files) total_files=len(files) num= total_files/10 if( total_files %10 != 0): num= num+1 mock_data["num_pages"]= num print (mock_data) return Response(json.dumps(mock_data), status=200, mimetype="application/json")
class HotRodCacheClient(CacheClient): """HotRod cache client implementation.""" def __init__(self, config): super(HotRodCacheClient, self).__init__(config["host"], config["port"], config["cache"]) self.config = config if config["hotrod.use_river_string_keys"] in TRUE_STR_VALUES: self.river_keys = RiverStringCodec() else: self.river_keys = None if self.cache_name == DEFAULT_CACHE_NAME: self.cache_name = ""; self.remote_cache = RemoteCache(self.host, int(self.port), self.cache_name) return def _optionally_encode_key(self, key_unmarshalled): if self.river_keys == None: return key_unmarshalled; else: return self.river_keys.encode(key_unmarshalled) def put(self, key, value, version=None, lifespan=None, max_idle=None, put_if_absent=False): key = self._optionally_encode_key(key) if lifespan == None: lifespan=0 if max_idle == None: max_idle=0 try: if (version == None): if (put_if_absent): retval = self.remote_cache.put_if_absent(key, value, lifespan, max_idle) if retval: return else: raise ConflictError else: self.remote_cache.put(key, value, lifespan, max_idle) else: numversion = None try: numversion = int(version) except ValueError: self._error("hotrod client only accepts numeric versions") retval = self.remote_cache.replace_with_version(key, value, numversion, lifespan, max_idle) if retval == 1: return elif retval == 0: raise NotFoundError elif retval == -1: raise ConflictError else: self._error("unexpected return value from hotrod client") except RemoteCacheError as e: self._error(e.args) def get(self, key, get_version=False): try: value = None version = None key = self._optionally_encode_key(key) if get_version: version, value = self.remote_cache.get_versioned(key) else: value = self.remote_cache.get(key) if value == None: raise NotFoundError if get_version: return version, value else: return value except RemoteCacheError as e: self._error(e.args) def delete(self, key, version=None): try: key = self._optionally_encode_key(key) if version == None: retval = self.remote_cache.remove(key) if retval: return else: raise NotFoundError else: numversion = None try: numversion = int(version) except ValueError: self._error("hotrod client only accepts numeric versions") retval = self.remote_cache.remove_with_version(key, numversion) if retval == 1: return elif retval == 0: raise NotFoundError elif retval == -1: raise ConflictError else: self._error("unexpected return value from hotrod client") except RemoteCacheError as e: self._error(e.args) def clear(self): self.remote_cache.clear() def exists(self, key): try: key = self._optionally_encode_key(key) if not self.remote_cache.contains_key(key): raise NotFoundError except RemoteCacheError as e: self._error(e.args)
import sys from infinispan.remotecache import RemoteCache hostname = 'datagrid-hotrod' port = 11333 itemID = 'SalesItem13' remote_cache = RemoteCache(host=hostname, port=port) def addRecord(itemID): [miss, val] = remote_cache.put_if_absent(itemID, '1', ret_prev=True) if miss == False: remote_cache.put(itemID, str(int(val)+1)) addRecord(itemID) salesItem = remote_cache.get(itemID) print('Sales of item: ' + salesItem)