def _pull(self): # Ping the instance and get its version _logger.info( '%s Ping', self.address) # _logger.info( "dump_json: %s", sync.cluster_state.get_state() + [{'address': sync.cluster_state.me}]) # Try to push your state to the other side helpers.push_state( self.address, helpers.dump_json( sync.cluster_state.get_state() + [{'address': sync.cluster_state.me}])) info = helpers.info( self.address) if not info: self._reachable = False return try: self._version = data.DataVersion.from_dict( info[ 'version']) except (TypeError, KeyError): _logger.error( '%s Invalid pulled data', self.address) return self._touch_last_reachable() # Check that the other instance has newer configuration if self._version <= data.cur_data().version: return # The instance has newer configuration, try to pull it _logger.info( '%s Pull', self.address) content = helpers.pull( self.address) if content is None: return False # Check in new data if data.push_data( content): config.save_configuration()
def _load_from_content( content): # Content must contain data and state if not 'copy' in content or not 'cluster' in content: return False if data.push_data( content[ 'copy']): sync.cluster_state.update_state( content[ 'cluster']) return True return False
def _load_from_content(content): # Content must contain data and state if not 'copy' in content or not 'cluster' in content: return False if data.push_data(content['copy']): sync.cluster_state.update_state(content['cluster']) return True return False
def put_copy(self): """ Pushes new data """ # Get content content = self._read_input_json() # Update with the content given if data.push_data( content): config.save_configuration() self._response_created()
def put_copy(self): """ Pushes new data """ # Get content content = self._read_input_json() # Update with the content given if data.push_data(content): config.save_configuration() self._response_created()
def _pull(self): # Ping the instance and get its version _logger.info('%s Ping', self.address) # _logger.info( "dump_json: %s", sync.cluster_state.get_state() + [{'address': sync.cluster_state.me}]) # Try to push your state to the other side helpers.push_state( self.address, helpers.dump_json(sync.cluster_state.get_state() + [{ 'address': sync.cluster_state.me }])) info = helpers.info(self.address) if not info: self._reachable = False return try: self._version = data.DataVersion.from_dict(info['version']) except (TypeError, KeyError): _logger.error('%s Invalid pulled data', self.address) return self._touch_last_reachable() # Check that the other instance has newer configuration if self._version <= data.cur_data().version: return # The instance has newer configuration, try to pull it _logger.info('%s Pull', self.address) content = helpers.pull(self.address) if content is None: return False # Check in new data if data.push_data(content): config.save_configuration()