def handle_delivery(message, sys=None): logger.info("Got: " + str(message)) try: message = message.decode() except (UnicodeDecodeError, AttributeError): e = sys.exc_info()[0] logger.info("Parsing Error: " + str(e)) parsed_json_message = json.loads(message) owner = parsed_json_message['owner'] tosca_file_name = 'tosca_template' tosca_template_json = parsed_json_message['toscaTemplate'] input_current_milli_time = lambda: int(round(time.time() * 1000)) # rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672, user=owner) # logger.addHandler(rabbit) try: tosca_folder_path = os.path.join(tempfile.gettempdir(), "planner_files", str(input_current_milli_time())) except NameError: import sys millis = int(round(time.time() * 1000)) tosca_folder_path = os.path.dirname( os.path.abspath(sys.argv[0])) + os.path.join( tempfile.gettempdir(), "planner_files", str(millis)) if not os.path.exists(tosca_folder_path): os.makedirs(tosca_folder_path) input_tosca_file_path = os.path.join(tosca_folder_path, tosca_file_name + ".yml") with open(input_tosca_file_path, 'w') as outfile: outfile.write(yaml.dump(tosca_template_json)) conf = {'url': "http://host"} spec_service = SpecService(conf) test_planner = Planner(tosca_path=input_tosca_file_path, spec_service=spec_service) tosca_template = test_planner.resolve_requirements() tosca_template = test_planner.set_node_templates_properties() template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary( tosca_template) Planner(yaml_dict_tpl=template_dict, spec_service=spec_service) logger.info("template ----: \n" + yaml.dump(template_dict)) response = {'toscaTemplate': template_dict} output_current_milli_time = int(round(time.time() * 1000)) response["creationDate"] = output_current_milli_time if queue_name == "planner_queue": logger.info("Planning") logger.info("Returning plan") logger.info("Output message:" + json.dumps(response)) return json.dumps(response)
def run_test(self, input_tosca_file_path): conf = {'url': "http://host"} spec_service = SpecService(conf) test_planner = Planner(input_tosca_file_path, spec_service) test_tosca_template = test_planner.resolve_requirements() template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary(test_tosca_template) test_tosca_template = test_planner.set_node_templates_properties() template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary(test_tosca_template) logger.info("template ----: \n" + yaml.dump(template_dict)) print(yaml.dump(template_dict)) ToscaTemplate(yaml_dict_tpl=copy.deepcopy(template_dict)) test_response = {'toscaTemplate': template_dict} response = {'toscaTemplate': template_dict} output_current_milli_time = int(round(time.time() * 1000)) response["creationDate"] = output_current_milli_time response["parameters"] = [] # print("Output message:" + json.dumps(response)) self.assertEqual(True, True)
def threaded_function(args): while not done: connection.process_data_events() sleep(5) if __name__ == "__main__": logging.basicConfig(level=logging.INFO) if sys.argv[1] == "test_local": tosca_path = "../TOSCA/" input_tosca_file_path = tosca_path + '/application_example_updated.yaml' conf = {'url': "http://host"} spec_service = SpecService(conf) test_planner = Planner(input_tosca_file_path, spec_service) test_tosca_template = test_planner.resolve_requirements() test_tosca_template = test_planner.set_node_templates_properties() template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary( test_tosca_template) logger.info("template ----: \n" + yaml.dump(template_dict)) ToscaTemplate(yaml_dict_tpl=copy.deepcopy(template_dict)) test_response = {'toscaTemplate': template_dict} logger.info("Output message:" + json.dumps(test_response)) else: logger.info("Input args: " + sys.argv[0] + ' ' + sys.argv[1] + ' ' + sys.argv[2]) global channel global connection channel, connection = init_chanel(sys.argv)