def process(self, ctxt, publisher_id, event_type, payload, metadata): try: actions = { "dns.domain.create": self.create_or_update, "dns.domain.update": self.create_or_update, "dns.domain.delete": self.delete, "dns.domain.exists": self.create_or_update } actions[event_type](payload) # NOTE: So if this is a initial zone we need to index the SOA / NS # records it will have. Let's do this when recieving the create # event. if event_type == 'dns.domain.create': recordsets = designate._get_recordsets(payload['id']) for rs in recordsets: rs = designate._serialize_recordset(rs) # So project ID isn't provided in the recordset api. rs['project_id'] = payload['project_id'] # TODO(ekarlso,sjmc7): doc_type below should come from # the recordset plugin # registers options self.engine.index( index=self.index_name, doc_type=RecordSetHandler.DOCUMENT_TYPE, body=rs, parent=rs["zone_id"], id=rs["id"]) return oslo_messaging.NotificationResult.HANDLED except Exception as e: LOG.exception(e)
def update_record(self, payload, timestamp): version = self.get_version(payload, timestamp) # designate v2 client doesn't support all_tenants param for # get recordset, so retrieve all recordsets for zone recordsets = designate._get_recordsets(payload['zone_id']) for recordset in recordsets: if recordset['id'] == payload['recordset_id']: payload = designate._serialize_recordset(recordset) # Since recordset doesn't have record id, there is no reliable # way to update a record as 'data' field itself can change. # update the recordset itself self.index_helper.save_document( payload, version=version)
def create_record(self, payload, timestamp): version = self.get_version(payload, timestamp) # Sometimes dns.record.create event comes before dns.recordset.create # which can result in an recordset not found error. # Instead retrieve the whole recordset from api and save it, to avoid # race condition recordsets = designate._get_recordsets(payload['zone_id']) for recordset in recordsets: if recordset['id'] == payload['recordset_id']: payload = designate._serialize_recordset(recordset) self.index_helper.save_document( payload, version=version)
def process(self, ctxt, publisher_id, event_type, payload, metadata): if (event_type == 'dns.zone.update' and payload.get('status') == 'DELETED'): LOG.debug("Ignoring update notification for Domain with DELETED " "status; event will be processed on delete event") return None items = super(ZoneHandler, self).process( ctxt, publisher_id, event_type, payload, metadata) try: # NOTE: So if this is an initial zone we need to index the SOA / NS # records it will have. Let's do this when receiving the create # event. if event_type == 'dns.zone.create': if not items: LOG.warning("Not writing initial recordsets; exception" "occurred during zone indexing") return None recordsets = designate._get_recordsets(payload['id']) serialized_recordsets = [] recordset_versions = [] for rs in recordsets: rs = designate._serialize_recordset(rs) # So project ID isn't provided in the recordset api. rs['project_id'] = payload['project_id'] serialized_recordsets.append(rs) # Use the timestamp from *this* notification but the # updated_at from each recordset (which empirically appears # to be the same for all initial recordsets) recordset_versions.append( self.get_version(rs, metadata['timestamp'])) items.append( pipeline.IndexItem(self.recordset_helper.plugin, event_type, payload, rs ) ) self.recordset_helper.save_documents( serialized_recordsets, versions=recordset_versions) return items except Exception as e: LOG.exception(e)
def process(self, ctxt, publisher_id, event_type, payload, metadata): if (event_type == 'dns.zone.update' and payload.get('status') == 'DELETED'): LOG.debug("Ignoring update notification for Domain with DELETED " "status; event will be processed on delete event") return None items = super(ZoneHandler, self).process( ctxt, publisher_id, event_type, payload, metadata) try: # NOTE: So if this is an initial zone we need to index the SOA / NS # records it will have. Let's do this when receiving the create # event. if event_type == 'dns.zone.create': if not items: LOG.warning(_LW("Not writing initial recordsets; exception" "occurred during zone indexing")) return None recordsets = designate._get_recordsets(payload['id']) serialized_recordsets = [] recordset_versions = [] for rs in recordsets: rs = designate._serialize_recordset(rs) # So project ID isn't provided in the recordset api. rs['project_id'] = payload['project_id'] serialized_recordsets.append(rs) # Use the timestamp from *this* notification but the # updated_at from each recordset (which empirically appears # to be the same for all initial recordsets) recordset_versions.append( self.get_version(rs, metadata['timestamp'])) items.append( pipeline.IndexItem(self.recordset_helper.plugin, event_type, payload, rs ) ) self.recordset_helper.save_documents( serialized_recordsets, versions=recordset_versions) return items except Exception as e: LOG.exception(e)
def process(self, ctxt, publisher_id, event_type, payload, metadata): handled = super(DomainHandler, self).process( ctxt, publisher_id, event_type, payload, metadata) try: # NOTE: So if this is a initial zone we need to index the SOA / NS # records it will have. Let's do this when receiving the create # event. if event_type == 'dns.domain.create': if handled != oslo_messaging.NotificationResult.HANDLED: LOG.warning(_LW("Not writing initial recordsets; exception" "occurred during domain indexing")) return None recordsets = designate._get_recordsets(payload['id']) for rs in recordsets: rs = designate._serialize_recordset(rs) # So project ID isn't provided in the recordset api. rs['project_id'] = payload['project_id'] # TODO(ekarlso,sjmc7): doc_type below should come from # the recordset plugin # registers options version = self.get_version(rs) try: self.engine.index( index=self.index_name, doc_type=RecordSetHandler.DOCUMENT_TYPE, body=rs, parent=rs["zone_id"], id=rs["id"], version_type='external', version=version ) except exceptions.ConflictError as e: if e.error != VERSION_CONFLICT_MSG: raise e LOG.warning(_LW('Version conflict at updating' 'recordset %(id)s with version ' '%(version)s') % {'id': rs['id'], 'version': version}) return oslo_messaging.NotificationResult.HANDLED except Exception as e: LOG.exception(e)
def serialize(self, obj): return designate._serialize_recordset(obj)
def serialize(self, obj): obj["_parent"] = obj["zone_id"] return designate._serialize_recordset(obj)