def sendto_lightcloud(self, fullurl): import lightcloud LIGHT_CLOUD = {'lookup1_A': LIGHTCLOUD_LOOKUPS,'storage1_A': LIGHTCLOUD_STORAGES} lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD) lightcloud.init(lookup_nodes, storage_nodes) # get last id and increment try: last_id = lightcloud.get("last_id") if last_id: pass else: lightcloud.set("last_id","0") except: pass next_id = int(last_id) + 1 # get shortened url id from current id shortened_url_id = self._squash(next_id) try: # store id, url into db lightcloud.set(str(next_id),fullurl) # update last_id lightcloud.set("last_id", str(next_id)) except: print "lightcloud update fail" pass # return id return shortened_url_id
def initialize(self, config_file_path = CONFIG_FILE_PATH): """ Initializes the lightcloud storage manager, load the configuration and creates the nodes @param config_file_path: path to the configuration file, which is formatted as INI file """ self.load_config(config_file_path) self._lookup_nodes, self._storage_nodes = lightcloud.generate_nodes(self.config) lightcloud.init(self._lookup_nodes, self._storage_nodes)
def initialize(self, config_file_path=CONFIG_FILE_PATH): """ Initializes the lightcloud storage manager, load the configuration and creates the nodes @param config_file_path: path to the configuration file, which is formatted as INI file """ self.load_config(config_file_path) self._lookup_nodes, self._storage_nodes = lightcloud.generate_nodes( self.config) lightcloud.init(self._lookup_nodes, self._storage_nodes)
def getfrom_lightcloud(self, shorturlid): import lightcloud LIGHT_CLOUD = { 'lookup1_A': LIGHTCLOUD_LOOKUPS, 'storage1_A': LIGHTCLOUD_STORAGES } lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD) lightcloud.init(lookup_nodes, storage_nodes) # get db key db_key = self._unsquash(shorturlid) # return url or None fullurl = None fullurl = lightcloud.get(str(db_key)) # return url return fullurl
#--- Setup path ---------------------------------------------- import sys from os.path import realpath, pardir, dirname, join sys.path.insert(0, realpath(join(dirname(__file__), '..', '..'))) import lightcloud #--- Setup test nodes ---------------------------------------------- LIGHT_CLOUD = { 'lookup1_A': [ '127.0.0.1:41201', '127.0.0.1:51201' ], 'storage1_A': [ '127.0.0.1:44201', '127.0.0.1:54201' ] } lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD) lightcloud.init(lookup_nodes, storage_nodes, node_type=lightcloud.TyrantNode) def test_set_get(): lightcloud.set('hello', 'world') assert lightcloud.get('hello') == 'world' def test_delete(): lightcloud.delete('hello') assert lightcloud.get('hello') == None def test_incr(): lightcloud.incr('hello', 2) assert lightcloud.get('hello') == '2' lightcloud.incr('hello', 2) assert lightcloud.get('hello') == '4'
#--- Setup path ---------------------------------------------- import sys from os.path import realpath, pardir, dirname, join sys.path.insert(0, realpath(join(dirname(__file__), '..', '..'))) import lightcloud #--- Setup test nodes ---------------------------------------------- LIGHT_CLOUD = { 'lookup1_A': ['127.0.0.1:41201', '127.0.0.1:51201'], 'storage1_A': ['127.0.0.1:44201', '127.0.0.1:54201'] } lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD) lightcloud.init(lookup_nodes, storage_nodes, node_type=lightcloud.TyrantNode) def test_set_get(): lightcloud.set('hello', 'world') assert lightcloud.get('hello') == 'world' def test_delete(): lightcloud.delete('hello') assert lightcloud.get('hello') == None def test_incr(): lightcloud.incr('hello', 2) assert lightcloud.get('hello') == '2'