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))
def delete_mr_client(**kwargs):
    '''
    Delete the client (publisher or subscriber).
    Expect property 'client_id' to have been set in the instance's runtime_properties
    when the client was created.
    '''
    try:
        target_topic = ctx.target.node.id
        client_id = ctx.source.instance.runtime_properties[target_topic][
            "client_id"]
        ctx.logger.info("Attempting to delete client {0} ".format(client_id))
        dmc = DMaaPControllerHandle(DMAAP_API_URL, DMAAP_USER, DMAAP_PASS,
                                    ctx.logger)
        c = dmc.delete_client(client_id)
        c.raise_for_status()

        ctx.logger.info("Deleted client {0}".format(client_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 MR client: {er}".format(er=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))
Esempio n. 4
0
def test_add_entry(mockconsul):
    _ch = ConsulHandle("http://{0}:{1}".format(CONSUL_HOST, CONSUL_PORT), None,
                       None, None)

    key = 'DMAAP_TEST'
    name = 'dmaap_test_name'
    value = 'dmaap_test_value'
    _ch.add_to_entry(key, name, value)

    name = "dmaap_test_name_2"
    value = 'dmaap_test_value_2'
    _ch.add_to_entry(key, name, value)

    _ch.delete_entry(key)