Exemple #1
0
 def get_http_connection_instance(self, info, data):
     """
     :return conn: connection object to service.
     """
     self.logger.debug('Enter in get_http_connection_instance')
     headers = None
     conn = None
     shift_param = 512
     if info['flag']:
         node = self.__service_locator.get_container_from_ring(\
                     info['account_name'], data.keys()[0])
     else:
         node = self.__service_locator.get_account_from_ring(
             info['account_name'])
     headers = self.__html_header_builder.get_headers(None)
     info['entity_name'] = info['entity_name'].encode("utf-8")
     with self.__account_updater_timeout.get_connection_timeout(\
         self.__conn_timeout):
         self.logger.debug('Connecting to : node: %s, fs: %s, account: \
             %s, message body size: %s'                                           % (node, node['fs'], \
             info['account_name'], info['body_size']))
         headers['account'] = info['account_name']
         headers['filesystem'] = node['fs']
         headers['dir'] = node['dir']
         headers['x-component-number'] = Calculation.evaluate(\
               info['account_name'], shift_param) - 1
         headers['x-global-map-version'] = self.msg.get_global_map_version()
         conn = httplib.HTTPConnection(node['ip'], node['port'])
         conn.request("PUT_CONTAINER_RECORD", '', data, headers)
     self.logger.debug('Exit from get_http_connection_instance')
     return conn
Exemple #2
0
 def get_account_from_ring(self, account_hash):
     """get account node info from ring"""
     #TODO: Needs to modify to get complete node info(i.e. fs)
     comp_no = Calculation.evaluate(account_hash, self.shift_param) - 1
     node = self.get_service_details(\
         self.msg.get_account_map()[comp_no])
     node['fs'] = self.account_ring.get_filesystem()
     node['account'] = account_hash
     node['dir'] = self.get_acc_dir_by_hash(account_hash)
     return node
Exemple #3
0
 def get_component(self, account):
     """
     Returns the component responsible for the given account
     :param account: Account name
     :returns: component number responsible for account
     """
     key = hash_path(account)
     while not self.ring_data.get_account_map():
         self.logger.debug("Account map is empty:%s" %
                           self.ring_data.get_account_map())
         self.ring_data.update_global_map()
         sleep(20)
     shift_param = len(self.ring_data.get_account_map())
     comp_no = Calculation.evaluate(key, shift_param) - 1
     return comp_no
Exemple #4
0
 def get_obj_dir_by_hash(self, obj_hash):
     """
     Returns object level directory for object storage location
     :param obj_hash: object hash
     :returns: directory no and name
     """
     directories = self.ring_data.get_object_level_dir_list()
     shift_param = len(directories)
     dir_no = Calculation.evaluate(obj_hash, shift_param)
     try:
         dir_name = directories[dir_no - 1]
     except (IndexError, Exception) as err:
         self.logger.exception("Exception occured :%s" % err)
         raise err
     return dir_no, dir_name
Exemple #5
0
 def get_cont_dir_by_hash(self, cont_hash):
     """
     Returns container level directory for object storage
     :param cont_hash: container hash
     :returns: container level directory
     """
     directories = self._container_level_dir_list
     shift_param = len(directories)
     dir_no = Calculation.evaluate(cont_hash, shift_param)
     try:
         dir_name = directories[dir_no - 1]
     except (IndexError, Exception) as err:
         self.logger.exception("Exception occured :%s" % err)
         raise err
     return dir_name
Exemple #6
0
 def get_component(self, account, container):
     """
     Returns the component responsible for the given container
     :param account: account name
     :param container: container name
     :returns: component responsible for container
     """
     key = hash_path(account, container)
     while not self.ring_data.get_container_map():
         self.logger.debug("Container map is empty:%s" %
                           self.ring_data.get_container_map())
         self.ring_data.update_global_map()
         sleep(20)
     shift_param = len(self.ring_data.get_container_map())
     comp_no = Calculation.evaluate(key, shift_param) - 1
     return comp_no
Exemple #7
0
 def connect_container(self, method, account_name, container_name, \
                                                 container_path):
     self.logger.debug('Enter in connect_container')
     use_hub("selects")
     node = self.__service_locator.get_container_from_ring(\
         account_name, container_name)
     conn = None
     headers = None
     shift_param = 512
     with self.__account_updater_timeout.get_connection_timeout(\
         self.__conn_timeout):
         headers = self.__html_header_builder.get_headers(None)
         headers['x-updater-request'] = True
         headers['x-component-number'] = Calculation.evaluate(\
               container_name, shift_param) - 1
         headers['x-global-map-version'] = self.msg.get_global_map_version()
         conn = httplib.HTTPConnection(node['ip'], node['port'])
         conn.request(method, container_path, '', headers)
     return conn
Exemple #8
0
 def get_service_list(self, acc_hash, cont_hash):
     """
     Returns list of container service
     """
     try:
         while not self.ring_data.get_container_map():
             self.logger.debug("Container map is empty:%s" %
                               self.ring_data.get_container_map())
             self.ring_data.update_global_map()
             sleep(20)
         shift_param = len(self.ring_data.get_container_map())
         comp_no = Calculation.evaluate(cont_hash, shift_param) - 1
         container_service_obj = self.get_container_service(comp_no)
         service_details = self.get_service_details(container_service_obj)
         filesystem = self.get_filesystem()
         directory = self.get_directory_by_hash(acc_hash, cont_hash)
         self.logger.info("Container service details :%s, filesystem :%s, directory :%s"\
         %(service_details, filesystem, directory))
     except Exception as err:
         self.logger.exception("Exception occured :%s" % err)
         return '', '', ''
     return service_details, filesystem, directory