Ejemplo n.º 1
0
	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()
Ejemplo n.º 2
0
	def _push(self):
		"""Tries to push the current data to the other instance. """
		# Check that current configuration is newer than that on the other instance
		xdata = data.cur_data()
		if self._version >= xdata.version:
			return

		# Push data
		_logger.info( '%s Push', self.address)
		result = helpers.push( self.address, helpers.dump_json({
				'version': {
					'sequence': xdata.version.sequence,
					'checksum': xdata.version.checksum,
				},
				'data': xdata.data,
			}))

		_logger.info('push result: %s', result)
		# Mark time when we tried to push new data
		if result:
			self._touch_last_push()
Ejemplo n.º 3
0
    def _push(self):
        """Tries to push the current data to the other instance. """
        # Check that current configuration is newer than that on the other instance
        xdata = data.cur_data()
        if self._version >= xdata.version:
            return

        # Push data
        _logger.info('%s Push', self.address)
        result = helpers.push(
            self.address,
            helpers.dump_json({
                'version': {
                    'sequence': xdata.version.sequence,
                    'checksum': xdata.version.checksum,
                },
                'data': xdata.data,
            }))

        _logger.info('push result: %s', result)
        # Mark time when we tried to push new data
        if result:
            self._touch_last_push()
Ejemplo n.º 4
0
    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()