Bladeren bron

AMBARI-3995. Pluggable services: few changes to command-??.json (dlysnichenko)

Lisnichenko Dmitro 11 jaren geleden
bovenliggende
commit
3f2d61e171

+ 6 - 0
ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py

@@ -27,6 +27,7 @@ from FileCache import FileCache
 from AgentException import AgentException
 from PythonExecutor import PythonExecutor
 from AmbariConfig import AmbariConfig
+import hostname
 
 
 logger = logging.getLogger()
@@ -95,6 +96,11 @@ class CustomServiceOrchestrator():
     """
     Converts command to json file and returns file path
     """
+    # Perform few modifications to stay compatible with the way in which
+    # site.pp files are generated by manifestGenerator.py
+    public_fqdn = hostname.public_hostname()
+    command['public_hostname'] = public_fqdn
+    # Now, dump the json file
     task_id = command['taskId']
     file_path = os.path.join(self.tmp_dir, "command-{0}.json".format(task_id))
     # Command json contains passwords, that's why we need proper permissions

+ 5 - 1
ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py

@@ -52,7 +52,9 @@ class TestCustomServiceOrchestrator(TestCase):
     self.config.set('agent', 'cache_dir', "/cachedir")
 
 
-  def test_dump_command_to_json(self):
+  @patch("hostname.public_hostname")
+  def test_dump_command_to_json(self, hostname_mock):
+    hostname_mock.return_value = "test.hst"
     command = {
       'commandType': 'EXECUTION_COMMAND',
       'role': u'DATANODE',
@@ -73,6 +75,8 @@ class TestCustomServiceOrchestrator(TestCase):
     self.assertTrue(os.path.getsize(file) > 0)
     self.assertEqual(oct(os.stat(file).st_mode & 0777), '0600')
     os.unlink(file)
+    # Testing side effect of dump_command_to_json
+    self.assertEquals(command['public_hostname'], "test.hst")
 
 
   @patch("os.path.exists")

+ 6 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceOsSpecific.java

@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.*;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.google.gson.annotations.SerializedName;
 /**
  * Represents service os-specific details (like repositories and packages). 
  * Represents <code>osSpecific</code>
@@ -58,9 +59,14 @@ public class ServiceOsSpecific {
    */
   @XmlAccessorType(XmlAccessType.FIELD)
   public static class Repo {
+
+    @SerializedName("baseUrl")
     private String baseurl;
+    @SerializedName("mirrorsList")
     private String mirrorslist;
+    @SerializedName("repoId")
     private String repoid;
+    @SerializedName("repoName")
     private String reponame;
 
     private Repo() {