class ContentRepairerWorker(ToolWorker): def __init__(self, tool, queue_workers, queue_reply): super(ContentRepairerWorker, self).__init__(tool, queue_workers, queue_reply) self.admin_client = AdminClient(self.conf, logger=self.logger) self.meta2_database = Meta2Database(self.conf, logger=self.logger) def _process_item(self, item): namespace, container_id = item if namespace != self.tool.namespace: raise ValueError('Invalid namespace (actual=%s, expected=%s)' % (namespace, self.tool.namespace)) self.logger.debug('Rebuilding %s', self.tool.string_from_item(item)) errors = list() for res in self.meta2_database.rebuild(container_id): if res['err']: errors.append('%s: %s' % (res['base'], res['err'])) if errors: raise Exception(errors) data = self.admin_client.election_sync(service_type='meta2', cid=container_id) for host, info in data.items(): if info['status']['status'] not in (200, 301): errors.append('%s (%d): %s' % (host, info['status']['status'], info['status']['message'])) if errors: raise Exception(errors)
class ContainerRepairerWorker(ToolWorker): def __init__(self, tool, queue_workers, queue_reply): super(ContainerRepairerWorker, self).__init__( tool, queue_workers, queue_reply) self.rebuild_bases = true_value(self.tool.conf.get( 'rebuild_bases', self.tool.DEFAULT_REBUILD_BASES)) self.sync_bases = true_value(self.tool.conf.get( 'sync_bases', self.tool.DEFAULT_SYNC_BASES)) self.update_account = true_value(self.tool.conf.get( 'update_account', self.tool.DEFAULT_UPDATE_ACCOUNT)) self.admin_client = AdminClient(self.conf, logger=self.logger) self.container_client = ContainerClient(self.conf, logger=self.logger) self.meta2_database = Meta2Database(self.conf, logger=self.logger) def _process_item(self, item): namespace, account, container = item if namespace != self.tool.namespace: raise ValueError('Invalid namespace (actual=%s, expected=%s)' % ( namespace, self.tool.namespace)) errors = list() if self.rebuild_bases: cid = cid_from_name(account, container) for res in self.meta2_database.rebuild(cid): if res['err']: errors.append('%s: %s' % (res['base'], res['err'])) if errors: raise Exception(errors) if self.sync_bases: data = self.admin_client.election_sync( service_type='meta2', account=account, reference=container) for host, info in data.items(): if info['status']['status'] not in (200, 301): errors.append('%s (%d): %s' % ( host, info['status']['status'], info['status']['message'])) if errors: raise Exception(errors) if self.update_account: self.container_client.container_touch( account=account, reference=container)