Added heat translation support 03/15403/1
authorUlas Kozat <ulas.kozat@gmail.com>
Sat, 11 Jun 2016 04:38:16 +0000 (21:38 -0700)
committerUlas Kozat <ulas.kozat@gmail.com>
Sat, 11 Jun 2016 04:38:16 +0000 (21:38 -0700)
Change-Id: I9d2462e34eda9e052774be280984dd571ff14650
Signed-off-by: Ulas Kozat <ulas.kozat@gmail.com>
DominoServer.py
lib/partitioner/partitioner.py

index 98a67e3..fc9f0ad 100755 (executable)
@@ -33,6 +33,8 @@ from thrift.server import TServer
 from toscaparser.tosca_template import ToscaTemplate
 #from toscaparser.utils.gettextutils import _
 #import toscaparser.utils.urlutils
+from translator.hot.tosca_translator import TOSCATranslator
+
 
 from mapper import *
 from partitioner import *
@@ -279,13 +281,13 @@ class CommunicationHandler:
     logging.debug('Selected Sites: %s', node_site)
 
     # Create per-domain Tosca files
-    file_paths = partitioner.partition_tosca('./toscafiles/template1.yaml',node_site,tosca.tpl)
+    file_paths = partitioner.partition_tosca('./toscafiles/template',node_site,tosca.tpl)
     logging.debug('Per domain file paths: %s', file_paths)
  
-    # Create list of translated template files
-
     # Create work-flow
 
+
+
     # Send domain templates to each domain agent/client 
     # FOR NOW: send untranslated but partitioned tosca files to scheduled sites
     # TBD: read from work-flow
@@ -293,10 +295,19 @@ class CommunicationHandler:
       domino_client_ip = self.dominoServer.registration_record[site].ipaddr
       domino_client_port = self.dominoServer.registration_record[site].tcpport
       try:
-        template_lines = miscutil.read_templatefile(file_paths[site]) 
+        if 'hot' in self.dominoServer.subscribed_templateformats[site]:
+          tosca = ToscaTemplate(file_paths[site])
+          translator = TOSCATranslator(tosca, {}, False)
+          output = translator.translate()
+          logging.debug('HOT translation: \n %s', output)
+          template_lines = [ output ]
+        else: 
+          template_lines = miscutil.read_templatefile(file_paths[site]) 
         self.push_template(template_lines, domino_client_ip, domino_client_port)
       except IOError as e:
         logging.error('I/O error(%d): %s' , e.errno, e.strerror)
+      except:
+        logging.error('Error: %s', sys.exc_info()[0])
 
     #Fill in the details
     pub_r = PublishResponseMessage()
index a098aca..f5b1546 100644 (file)
@@ -45,8 +45,8 @@ def partition_tosca(filepath, nodesite, tpl):
   for site in sitenodes:
     tpl_l = tpl_local[site]
     print tpl_l , '\n'
-    file_paths[site] = filepath + '_part' + str(site)
-    fout = open(filepath + '_part' + str(site),'w')
+    file_paths[site] = filepath + '_part' + str(site) + '.yaml'
+    fout = open(file_paths[site],'w')
  
     if tpl_l.has_key('tosca_definitions_version'):
       fout.write('tosca_definitions_version: ')