diff options
author | Tommy Carpenter <tommy@research.att.com> | 2017-08-22 17:49:55 -0400 |
---|---|---|
committer | Tommy Carpenter <tommy@research.att.com> | 2017-08-22 17:50:24 -0400 |
commit | 94cbaca0f5d9447afe9b0f392f248470420422e5 (patch) | |
tree | 2ab7e46a6d63daa1a8a372d199245511b84d3105 /cdap | |
parent | c272a87b84189f3bf8b3c7287199b816affc9926 (diff) |
[DCAEGEN2-74] merge broker deletion plugin to cdap
Change-Id: If8fecde180c37ae1332e9ef53b9b2e8b17169cbe
Signed-off-by: Tommy Carpenter <tommy@research.att.com>
Diffstat (limited to 'cdap')
-rw-r--r-- | cdap/Changelog.md | 3 | ||||
-rwxr-xr-x | cdap/cdap_types.yaml | 13 | ||||
-rw-r--r-- | cdap/cdapplugin/cdapcloudify/cdap_plugin.py | 7 | ||||
-rw-r--r-- | cdap/cdapplugin/cdapcloudify/discovery.py | 38 | ||||
-rw-r--r-- | cdap/cdapplugin/setup.py | 2 |
5 files changed, 49 insertions, 14 deletions
diff --git a/cdap/Changelog.md b/cdap/Changelog.md index d919964..fa505e4 100644 --- a/cdap/Changelog.md +++ b/cdap/Changelog.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [14.1.0] +* Merge the broker deleter function into here; no need for seperate plugin + ## [14.0.2] * Start a tox/pytest unit test suite diff --git a/cdap/cdap_types.yaml b/cdap/cdap_types.yaml index 497307c..083d011 100755 --- a/cdap/cdap_types.yaml +++ b/cdap/cdap_types.yaml @@ -6,7 +6,7 @@ plugins: cdap_deploy: executor: central_deployment_agent package_name: cdapcloudify - package_version: 14.0.2 + package_version: 14.1.0 data_types: cdap_connections: @@ -88,3 +88,14 @@ node_types: description: "new unbound config for the CDAP AppConfig as a JSON" default: {} + dcae.nodes.broker_deleter: + derived_from: cloudify.nodes.Root + interfaces: + cloudify.interfaces.lifecycle: + delete: #stop better than delete? not sure it matters much. Think all source interfaces are operated on before target on uninstall. + implementation: cdap_deploy.cdapcloudify.cdap_plugin.delete_all_registered_apps + inputs: + connected_broker_dns_name: + type: string + description: This is the broker's DNS name. There could be multiple brokers/clusters at a site. Could by populated via an intrinsic_function in a blueprint, or manually via inputs file + default: "cdap_broker" diff --git a/cdap/cdapplugin/cdapcloudify/cdap_plugin.py b/cdap/cdapplugin/cdapcloudify/cdap_plugin.py index f5eaf0b..b4d22cd 100644 --- a/cdap/cdapplugin/cdapcloudify/cdap_plugin.py +++ b/cdap/cdapplugin/cdapcloudify/cdap_plugin.py @@ -228,4 +228,11 @@ def app_smart_reconfigure(new_config_template, **kwargs): except Exception as e: raise NonRecoverableError("CDAP Reconfigure error: {0}".format(e)) +@operation +def delete_all_registered_apps(connected_broker_dns_name, **kwargs): + """ + Used in the cdap broker deleter node. + Deletes all registered applications (in the broker) + """ + discovery.delete_all_registered_apps(connected_broker_dns_name, ctx.logger) diff --git a/cdap/cdapplugin/cdapcloudify/discovery.py b/cdap/cdapplugin/cdapcloudify/discovery.py index a8f0ce2..c654cbb 100644 --- a/cdap/cdapplugin/cdapcloudify/discovery.py +++ b/cdap/cdapplugin/cdapcloudify/discovery.py @@ -22,22 +22,22 @@ import json CONSUL_HOST = "http://localhost:8500" +def _get_connection_info_from_consul(service_component_name, logger): + """ + Call consul's catalog + TODO: currently assumes there is only one service + """ + url = "{0}/v1/catalog/service/{1}".format(CONSUL_HOST, service_component_name) + logger.info("Trying to query: {0}".format(url)) + res = requests.get(url) + res.raise_for_status() + services = res.json() + return services[0]["ServiceAddress"], services[0]["ServicePort"] + def _get_broker_url(cdap_broker_name, service_component_name, logger): """ fetch the broker connection information from Consul """ - def _get_connection_info_from_consul(service_component_name, logger): - """ - Call consul's catalog - TODO: currently assumes there is only one service - """ - url = "{0}/v1/catalog/service/{1}".format(CONSUL_HOST, service_component_name) - logger.info("Trying to query: {0}".format(url)) - res = requests.get(url) - res.raise_for_status() - services = res.json() - return services[0]["ServiceAddress"], services[0]["ServicePort"] - broker_ip, broker_port = _get_connection_info_from_consul(cdap_broker_name, logger) broker_url = "http://{ip}:{port}/application/{appname}".format(ip=broker_ip, port=broker_port, appname=service_component_name) logger.info("Trying to connect to broker endpoint: {0}".format(broker_url)) @@ -103,3 +103,17 @@ def delete_on_broker(cdap_broker_name, service_component_name, logger): logger.info((response, response.status_code, response.text)) response.raise_for_status() #bomb if not 2xx +def delete_all_registered_apps(cdap_broker_name, logger): + #get the broker connection + broker_ip, broker_port = _get_connection_info_from_consul(cdap_broker_name, logger) + broker_url = "http://{ip}:{port}".format(ip=broker_ip, port=broker_port) + + #binge and purge + logger.info("Trying to connect to broker called {0} at {1}".format(cdap_broker_name, broker_url)) + registered_apps = json.loads(requests.get("{0}/application".format(broker_url)).text) #should be proper list of strings (appnames) + logger.info("Trying to delete: {0}".format(registered_apps)) + r = requests.post("{0}/application/delete".format(broker_url), + headers = {'content-type':'application/json'}, + json = {"appnames" : registered_apps}) + logger.info("Response: {0}, Response Status: {1}".format(r.text, r.status_code)) + diff --git a/cdap/cdapplugin/setup.py b/cdap/cdapplugin/setup.py index d16667d..53a9a2b 100644 --- a/cdap/cdapplugin/setup.py +++ b/cdap/cdapplugin/setup.py @@ -22,7 +22,7 @@ from setuptools import setup, find_packages setup( name = "cdapcloudify", - version = "14.0.2", + version = "14.1.0", packages=find_packages(), author = "Tommy Carpenter", author_email = "tommy at research dot eh tee tee dot com", |