def remove_dr_bridge(**kwargs): try: dmc = DMaaPControllerHandle(DMAAP_API_URL, DMAAP_USER, DMAAP_PASS, ctx.logger) if ctx.target.node.id in ctx.source.instance.runtime_properties: if 'subscriber_id' in ctx.source.instance.runtime_properties[ ctx.target.node.id]: # Delete the subscription for this bridge ctx.logger.info( "Removing bridge -- deleting subscriber {0}".format( ctx.source.instance.runtime_properties[ ctx.target.node.id]['subscriber_id'])) dmc.delete_subscriber(ctx.source.instance.runtime_properties[ ctx.target.node.id]['subscriber_id']) if 'publisher_id' in ctx.source.instance.runtime_properties: # Delete the publisher for this bridge ctx.logger.info( "Removing bridge -- deleting publisher {0}".format( ctx.source.instance.runtime_properties[ ctx.target.node.id]['publisher_id'])) dmc.delete_publisher(ctx.source.instance.runtime_properties[ ctx.target.node.id]['publisher_id']) ctx.logger.info("Remove bridge from {0} to {1}".format( ctx.source.node.id, ctx.target.node.id)) except Exception as e: ctx.logger.error("Error removing bridge: {0}".format(e))
def delete_dr_subscriber(**kwargs): ''' Deletes subscriber (the source of the subscribes_to_files relationship) from the feed (the target of the relationship). Assumes that the source node's runtime properties dictionary for the target feed includes 'subscriber_id', set when the publisher was added to the feed. ''' try: # Get the subscriber id target_feed = ctx.target.node.id subscriber_id = ctx.source.instance.runtime_properties[target_feed]["subscriber_id"] ctx.logger.info("Attempting to delete subscriber {0} from feed {1}".format(subscriber_id, target_feed)) # Make the request dmc = DMaaPControllerHandle(DMAAP_API_URL, DMAAP_USER, DMAAP_PASS, ctx.logger) del_result = dmc.delete_subscriber(subscriber_id) del_result.raise_for_status() ctx.logger.info("Deleted subscriber {0}".format(subscriber_id)) # Attempt to remove the entire ":dmaap" entry from the Consul KV store # Will quietly do nothing if the entry has already been removed ch = ConsulHandle("http://{0}:8500".format(CONSUL_HOST), None, None, ctx.logger) ch.delete_entry("{0}:dmaap".format(ctx.source.instance.runtime_properties['service_component_name'])) except Exception as e: ctx.logger.error("Error deleting subscriber: {er}".format(er=e))