def init(self): state = self.source._get_state() self.connection = state.replicator self.config = state.db_config d = conflicts.get_replication_status(self.connection, self.config.name) d.addCallback(defer.inject_param, 2, setattr, self, 'statuses') return d
def check_configured_replications(self, state): self.debug("checking status of configured replications") statuses = yield conflicts.get_replication_status( state.replicator, state.db_config.name) if not statuses: self.debug("No replications configured") return db = self.get_database() our_seq = yield db.get_update_seq() for target, rows in statuses.iteritems(): alert_name = self.get_replication_alert_name(target) self.may_raise_alert( alert.DynamicAlert( name=alert_name, severity=alert.Severity.warn, persistent=True, description='replication-' + alert_name)) update_seq, continuous, status, replication_id = rows[0] progress = float(update_seq) / our_seq if progress >= REPLICATION_PROGRESS_ALERT_THRESHOLD: self.debug("Replication to %s is fine.", target) self.resolve_alert(alert_name, 'ok') else: if status == 'completed': info = ('The replication is paused, ' 'last progress: %2.0f %%.' % (progress * 100, )) severity = alert.Severity.warn elif status == 'task_missing': info = ( 'The continuous replication is triggered ' 'but there is no active task running for it. ' 'The only time I saw this case was due to the ' 'bug in couchdb, which required restarting it. ' 'Please investigate!') severity = alert.Severity.critical elif status == 'running': info = ( "The replication is running, but hasn't yet reached " "the desired threshold of: %2.0f %%. " "Current progress is: %2.0f %%" % (REPLICATION_PROGRESS_ALERT_THRESHOLD * 100, progress * 100)) severity = alert.Severity.warn else: info = 'The replication is in %s state.' % ( status, ) severity = alert.Severity.critical self.info("Replication to %s is not fine. Rasing alert: %s", target, info) self.raise_alert(alert_name, info, severity)
def resume(self, value): state = self.source._get_state() connection = state.replicator statuses = yield conflicts.get_replication_status( connection, state.db_config.name) if value in statuses: seq, continuous, status, r_id = statuses[value][0] if continuous and status == 'running': defer.returnValue( response.Done( None, "There already is an continuous replication in " " running status to %s target. Not doing anything." % (value, ))) doc = {'source': unicode(state.db_config.name), 'target': value, 'continuous': True, 'filter': u'featjs/replication'} doc = yield connection.save_document(doc) defer.returnValue(response.Done(None, "done"))