예제 #1
0
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_publisher(**kwargs):
    '''
    Deletes publisher (the source of the publishes_files relationship)
    from the feed (the target of the relationship).
    Assumes that the 'publisher_id' property was added to the dictionary of feed-related properties,
    when the publisher was added to the feed.
    '''

    try:
        # Make sure we have a name under which to store DMaaP configuration
        # Check early so we don't needlessly create DMaaP entities
        if 'service_component_name' not in ctx.source.instance.runtime_properties:
            raise Exception("Source node does not have 'service_component_name' in runtime_properties")

        # Get the publisher id
        target_feed = ctx.target.node.id
        publisher_id = ctx.source.instance.runtime_properties[target_feed]["publisher_id"]
        ctx.logger.info("Attempting to delete publisher {0}".format(publisher_id))

        # Make the request
        dmc = DMaaPControllerHandle(DMAAP_API_URL, DMAAP_USER, DMAAP_PASS, ctx.logger)
        del_result = dmc.delete_publisher(publisher_id)
        del_result.raise_for_status()

        ctx.logger.info("Deleted publisher {0}".format(publisher_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 publisher: {er}".format(er=e))