def get_kconnect_config(): """ return all config of kafka connect connectors vne::tbd:: validate auth token """ try: if appconfig.get_app_module() != 'kconnect': #print 'Invalid Module' appconfig.get_app_logger().error('Invalid Module, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request"} #print 'GET received', request, rbody appconfig.get_app_logger().info('GET received, %s', request) return { "success": True, "config": json.dumps(appconfig.get_kconnect_config()) } except: appconfig.get_app_logger().exception( 'Invalid Request. Some Exception, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request. Some Exception"}
def delete_kconnect_connector(): """ delete kafka connect connector api/v1/internal/kconnect?authToken=<secret>&name=<connector name> use + in case of query params """ try: if appconfig.get_app_module() != 'kconnect': #print 'Invalid Module' appconfig.get_app_logger().error('Invalid Module, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request"} rbody = {} rbody['auth_token'] = request.query.auth_token or 'None' rbody['name'] = request.query.name or 'None' #Extract JSON payload # rbody = json.load(request.body) #print 'POST received', request, rbody appconfig.get_app_logger().info('DELETE received, %s:%s', request, rbody) return process_delete_kconnect(rbody) except: appconfig.get_app_logger().exception( 'Invalid Request. Some Exception, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request. Some Exception"}
def update_connection_config(): """ update MQTT connection appconfig if it already exists. If it doesn't, return error """ if appconfig.get_app_module() != 'web': #print 'Invalid Module' appconfig.get_app_logger().error('Invalid Module, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request"} try: #Extract JSON payload rbody = json.load(request.body) #print 'PUT received', request, rbody appconfig.get_app_logger().info('PUT received, %s:%s', request, rbody) return process_connection_config_v1(rbody) except: appconfig.get_app_logger().exception( 'Invalid Request. Some Exception, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request. Some Exception"}
def main(): global g_config if len (sys.argv) != 2: print "Usage: python main.py <web|mqtt|kconnect>" sys.exit(1) config_file = 'config.json' init_config(config_file, sys.argv[1]) if appconfig.get_app_module() == 'kconnect': appconfig.get_kconnect_sync_thrid().start() rest.start_rest_mod() if appconfig.get_app_module() == 'kconnect': appconfig.get_kconnect_sync_thrid().join()
def get_connection_config(): """ read MQTT current appconfig and send in HTTP response """ #print 'GET received' try: if appconfig.get_app_module() != 'web': appconfig.get_app_logger().error('Invalid Module, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request"} return {"success": False, "error": "Not Implemented"} except: appconfig.get_app_logger().exception( 'Invalid Request. Some Exception, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request. Some Exception"}
def get_vmq_config(): """ """ #print 'GET received' try: if appconfig.get_app_module() != 'mqtt': #print 'Invalid Module' appconfig.get_app_logger().error('Invalid Module, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request"} return {"success": False, "error": "Not Implemented"} except: appconfig.get_app_logger().exception( 'Invalid Request. Some Exception, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request. Some Exception"}
def delete_connection_config(): """ Delete MQTT Connection appconfig it is already exists If it doesn't, return error turn OFF the Nginx as well """ #print 'DELETE received' try: if appconfig.get_app_module() != 'web': #print 'Invalid Module' appconfig.get_app_logger().error('Invalid Module, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request"} #vne:: tbd: Stop Nginx server return {"success": False, "error": "Not Implemented"} except: appconfig.get_app_logger().exception( 'Invalid Request. Some Exception, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request. Some Exception"}
def update_kconnect_connector(): """ Update an existing kafka connect connector """ try: if appconfig.get_app_module() != 'kconnect': #print 'Invalid Module' appconfig.get_app_logger().error('Invalid Module, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request"} #Extract JSON payload rbody = json.load(request.body) #print 'PUT received', request, rbody appconfig.get_app_logger().info('PUT received, %s:%s', request, rbody) return process_update_kconnect(rbody) except: appconfig.get_app_logger().exception( 'Invalid Request. Some Exception, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request. Some Exception"}
def create_vmq_config(): """ """ try: if appconfig.get_app_module() != 'mqtt': #print 'Invalid Module' appconfig.get_app_logger().error('Invalid Module, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request"} #Extract JSON payload rbody = json.load(request.body) #print 'POST received', request, rbody appconfig.get_app_logger().info('POST received, %s:%s', request, rbody) return process_vmq_config(rbody) except: appconfig.get_app_logger().exception( 'Invalid Request. Some Exception, %s, %s', appconfig.get_app_module(), request.url) return {"success": False, "error": "Invalid Request. Some Exception"}