SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ConfigParser
  2. import json
  3. import os
  4. import requests
  5. import sys
  6. import uuid
  7. import time
  8.  
  9.  
  10. config = ConfigParser.RawConfigParser()
  11. __file__ = os.path.join(sys.path[0], sys.argv[1])
  12. config.read(__file__)
  13.  
  14. plugin = config.get('manager', 'plugin')
  15. ip = config.get('manager', 'ip')
  16. port = config.get('manager', 'port')
  17. cluster_size = config.getint('manager', 'cluster_size')
  18. flavor_id = config.get('manager', 'flavor_id')
  19. image_id = config.get('manager', 'image_id')
  20. bigsea_username = config.get('manager', 'bigsea_username')
  21. bigsea_password = config.get('manager', 'bigsea_password')
  22.  
  23. opportunistic = config.get('plugin', 'opportunistic')
  24. dependencies = config.get('plugin', 'dependencies')
  25. args = config.get('plugin', 'args').split()
  26. main_class = config.get('plugin', 'main_class')
  27. job_template_name = config.get('plugin', 'job_template_name')
  28. job_binary_name = config.get('plugin', 'job_binary_name')
  29. job_binary_url = config.get('plugin', 'job_binary_url')
  30. input_ds_id = ''
  31. output_ds_id = ''
  32. plugin_app = config.get('plugin', 'plugin_app')
  33. expected_time = config.getint('plugin', 'expected_time')
  34. collect_period = config.getint('plugin', 'collect_period')
  35. openstack_plugin = config.get('plugin', 'openstack_plugin')
  36. job_type = config.get('plugin', 'job_type')
  37. version = '2.1.0'
  38. cluster_id = config.get('plugin', 'cluster_id')
  39. slave_ng = config.get('plugin', 'slave_ng')
  40. opportunistic_slave_ng = config.get('plugin', 'opportunistic_slave_ng')
  41. master_ng = config.get('plugin', 'master_ng')
  42. net_id = config.get('plugin', 'net_id')
  43. actuator = config.get('scaler', 'actuator')
  44. starting_cap = config.get('scaler', 'starting_cap')
  45.  
  46. scaler_plugin = config.get('scaler', 'scaler_plugin')
  47. scaling_parameters = {}
  48. scaling_parameters['actuator'] = config.get('scaler', 'actuator')
  49. scaling_parameters['metric_source'] = config.get('scaler', 'metric_source')
  50. scaling_parameters['application_type'] = config.get('scaler', 'application_type')
  51. scaling_parameters['check_interval'] = config.getint('scaler', 'check_interval')
  52. scaling_parameters['trigger_down'] = config.getint('scaler', 'trigger_down')
  53. scaling_parameters['trigger_up'] = config.getint('scaler', 'trigger_up')
  54. scaling_parameters['min_cap'] = config.getint('scaler', 'min_cap')
  55. scaling_parameters['max_cap'] = config.getint('scaler', 'max_cap')
  56. scaling_parameters['actuation_size'] = config.getint('scaler', 'actuation_size')
  57. scaling_parameters['metric_rounding'] = config.getint('scaler', 'metric_rounding')
  58.  
  59. headers = {'Content-Type': 'application/json'}
  60. body = dict(plugin=plugin, scaler_plugin=scaler_plugin,
  61.     scaling_parameters=scaling_parameters, cluster_size=cluster_size,
  62.     starting_cap=starting_cap, actuator=actuator,
  63.     flavor_id=flavor_id, image_id=image_id, opportunistic=opportunistic,
  64.     args=args, main_class=main_class, job_template_name=job_template_name,
  65.     job_binary_name=job_binary_name, job_binary_url=job_binary_url,
  66.     input_ds_id=input_ds_id, output_ds_id=output_ds_id,
  67.     plugin_app=plugin_app, expected_time=expected_time,
  68.     collect_period=collect_period, bigsea_username=bigsea_username,
  69.     bigsea_password=bigsea_password, openstack_plugin=openstack_plugin,
  70.     job_type=job_type, version=version, opportunistic_slave_ng=opportunistic_slave_ng,
  71.     slave_ng=slave_ng, master_ng=master_ng, net_id=net_id, dependencies=dependencies
  72.     )
  73. url = "http://%s:%s/manager/execute" % (ip, port)
  74. print "Making request to", url
  75. body_log = body.copy()
  76. r = requests.post(url, headers=headers, data=json.dumps(body))
  77. print "Application id: %s" % r.content
  78.  
  79. url_status = "http://%s:%s/manager/status" % (ip, port)
  80. url_execution_log = "http://%s:%s/manager/execution_log" % (ip, port)
  81. print "Running application"
  82.  
  83. old_status = []
  84. f = open("app.log", "w")
  85. while(True):
  86.     r_status = requests.get(url_status)
  87.  
  88.     for line in r_status.json():
  89.         if line not in old_status:
  90.             print str(line)
  91.             f.write(str(line)+"\n")
  92.             old_status.append(line)
  93.         if "Finished" in line:
  94.             std = requests.get(url_execution_log).json()
  95.  
  96.             err = open("stderr", "w")
  97.             err.write(str(std[1]))
  98.             err.close()
  99.  
  100.             out = open("stdout", "w")
  101.             out.write(str(std[0]))
  102.             out.close()
  103.  
  104.             f.close()
  105.  
  106.             print "See stderr and stdout files to more details of application execution"
  107.  
  108.             exit()
  109.  
  110.     time.sleep(20)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top