incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject svn commit: r1462883 - in /incubator/ambari/trunk: ./ ambari-agent/ ambari-agent/src/main/python/ambari_agent/ ambari-agent/src/test/python/ ambari-agent/src/test/python/examples/ ambari-server/ ambari-server/conf/unix/ ambari-server/src/main/conf/ amb...
Date Sun, 31 Mar 2013 06:06:09 GMT
Author: smohanty
Date: Sun Mar 31 06:06:08 2013
New Revision: 1462883

URL: http://svn.apache.org/r1462883
Log:
AMBARI-1754. Add support to ensure that Ambari Server/Agent/Store are all of compatible version.
(smohanty)

Added:
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
    incubator/ambari/trunk/version
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-agent/pom.xml
    incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Controller.py
    incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py
    incubator/ambari/trunk/ambari-agent/src/test/python/TestRegistration.py
    incubator/ambari/trunk/ambari-agent/src/test/python/examples/ControllerTester.py
    incubator/ambari/trunk/ambari-server/conf/unix/ambari.properties
    incubator/ambari/trunk/ambari-server/pom.xml
    incubator/ambari/trunk/ambari-server/src/main/conf/ambari.properties
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
    incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
    incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/LocalAgentSimulator.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaServiceTest.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Sun Mar 31 06:06:08 2013
@@ -12,6 +12,9 @@ Trunk (unreleased changes):
 
  NEW FEATURES
 
+ AMBARI-1754. Add support to ensure that Ambari Server/Agent/Store are all of 
+ compatible version. (smohanty)
+
  AMBARI-1752. Backend support for MySQL and Oracle for Oozie and Hive. (swagle)
 
  AMBARI-1751. Ambari oracle-linux as a supported OS type. (swagle)

Modified: incubator/ambari/trunk/ambari-agent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/pom.xml?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/pom.xml (original)
+++ incubator/ambari/trunk/ambari-agent/pom.xml Sun Mar 31 06:06:08 2013
@@ -289,6 +289,17 @@
                 </source>
               </sources>
             </mapping>
+            <mapping>
+              <directory>/var/lib/${project.artifactId}/data</directory>
+              <filemode>755</filemode>
+              <username>root</username>
+              <groupname>root</groupname>
+              <sources>
+                <source>
+                  <location>../version</location>
+                </source>
+              </sources>
+            </mapping>
             <!-- -->
           </mappings>
         </configuration>

Modified: incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Controller.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Controller.py?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Controller.py (original)
+++ incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Controller.py Sun Mar
31 06:06:08 2013
@@ -66,7 +66,7 @@ class Controller(threading.Thread):
   def start(self):
     self.actionQueue = ActionQueue(self.config)
     self.actionQueue.start()
-    self.register = Register()
+    self.register = Register(self.config)
     self.heartbeat = Heartbeat(self.actionQueue)
     pass
   

Modified: incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py (original)
+++ incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/Register.py Sun Mar 31
06:06:08 2013
@@ -18,7 +18,7 @@ See the License for the specific languag
 limitations under the License.
 '''
 
-import sys
+import sys, os
 import json
 from Hardware import Hardware
 from ActionQueue import ActionQueue
@@ -34,8 +34,9 @@ firstContact = True
 class Register:
   """ Registering with the server. Get the hardware profile and 
   declare success for now """
-  def __init__(self):
+  def __init__(self, config):
     self.hardware = Hardware()
+    self.config = config
 
   def build(self, id='-1'):
     global clusterId, clusterDefinitionRevision, firstContact
@@ -44,16 +45,28 @@ class Register:
     hostInfo = HostInfo() 
     agentEnv = { }
     hostInfo.register(agentEnv)
+
+    version = self.read_agent_version()
     
     register = { 'responseId'        : int(id),
                   'timestamp'         : timestamp,
                   'hostname'          : hostname.hostname(),
                   'publicHostname'    : hostname.public_hostname(),
                   'hardwareProfile'   : self.hardware.get(),
-                  'agentEnv'          : agentEnv
+                  'agentEnv'          : agentEnv,
+                  'agentVersion'      : version
                 }
     return register
 
+  def read_agent_version(self):
+    data_dir = self.config.get('agent', 'prefix')
+    ver_file = os.path.join(data_dir, 'version')
+    f = open(ver_file, "r")
+    version = f.read()
+    f.close()
+    return version
+
+
 def doExec(vals, key, command, preLF=False):
   template = "{0}: {1} {2}"
   try:
@@ -95,14 +108,3 @@ def machineInfo():
   doExec(vals, "yum_repos", ["sh", "-c", "yum -C repolist enabled | egrep \"(AMBARI|HDP)\""],
True)
   # for SUSE-based agents
   doExec(vals, "zypper_repos", ["sh", "-c", "zypper repos | egrep \"(AMBARI|HDP)\""], True)
-  
-  
-def main(argv=None):
-  if len(argv) == 1:
-    register = Register()
-    print json.dumps(register.build())
-  else:
-    machineInfo()
-
-if __name__ == '__main__':
-  main(sys.argv)

Modified: incubator/ambari/trunk/ambari-agent/src/test/python/TestRegistration.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/test/python/TestRegistration.py?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/test/python/TestRegistration.py (original)
+++ incubator/ambari/trunk/ambari-agent/src/test/python/TestRegistration.py Sun Mar 31 06:06:08
2013
@@ -19,14 +19,25 @@ limitations under the License.
 '''
 
 from unittest import TestCase
+import os
+import tempfile
+
 from ambari_agent.Register import Register
-import socket
-import os, pprint, json
+from ambari_agent.AmbariConfig import AmbariConfig
+
 
 class TestRegistration(TestCase):
 
   def test_registration_build(self):
-    register = Register()
+    config = AmbariConfig().getConfig()
+    tmpdir = tempfile.gettempdir()
+    config.set('agent', 'prefix', tmpdir)
+
+    ver_file = os.path.join(tmpdir, "version")
+    with open(ver_file, "w") as text_file:
+      text_file.write("1.3.0")
+
+    register = Register(config)
     data = register.build(1)
     #print ("Register: " + pprint.pformat(data))
     self.assertEquals(len(data['hardwareProfile']) > 0, True, "hardwareProfile should
contain content")
@@ -35,4 +46,7 @@ class TestRegistration(TestCase):
     self.assertEquals(data['responseId'], 1)
     self.assertEquals(data['timestamp'] > 1353678475465L, True, "timestamp should not
be empty")
     self.assertEquals(len(data['agentEnv']) > 0, True, "agentEnv should not be empty")
-    self.assertEquals(len(data), 6)
+    self.assertEquals(data['agentVersion'], '1.3.0', "agentVersion should not be empty")
+    self.assertEquals(len(data), 7)
+
+    os.remove(ver_file)
\ No newline at end of file

Modified: incubator/ambari/trunk/ambari-agent/src/test/python/examples/ControllerTester.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/test/python/examples/ControllerTester.py?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/test/python/examples/ControllerTester.py (original)
+++ incubator/ambari/trunk/ambari-agent/src/test/python/examples/ControllerTester.py Sun Mar
31 06:06:08 2013
@@ -13,7 +13,9 @@ logger=logging.getLogger()
 queue = Queue.Queue()
 
 # Set to True to replace python and puppet calls with mockups
-disable_python_and_puppet = False
+disable_python_and_puppet = True
+
+agent_version = "1.3.0"
 
 # Values from the list below are returned in responce to agent requests (one per
 # request). When every value has been returned, the last element of list is
@@ -127,14 +129,17 @@ def run_simulation():
     os.pardir, 'main', 'upgrade_stack')
   config.set('stack', 'upgradeScriptsDir', scriptsDir)
 
+  ver_file = os.path.join(tmpfile, "version")
+
+  with open(ver_file, "w") as text_file:
+      text_file.write(agent_version)
+
   controller = Controller.Controller(config)
   controller.sendRequest = sendRequest_method
   controller.netutil.HEARTBEAT_IDDLE_INTERVAL_SEC = 0.1
   controller.netutil.HEARTBEAT_NOT_IDDLE_INTERVAL_SEC = 0.1
   controller.range = 1
 
-
-
   for responce in responces:
     queue.put(responce)
 

Modified: incubator/ambari/trunk/ambari-server/conf/unix/ambari.properties
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/conf/unix/ambari.properties?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/conf/unix/ambari.properties (original)
+++ incubator/ambari/trunk/ambari-server/conf/unix/ambari.properties Sun Mar 31 06:06:08 2013
@@ -21,6 +21,7 @@ resources.dir = /var/lib/ambari-server/r
 jdk.url=http://public-repo-1.hortonworks.com/ARTIFACTS/jdk-6u31-linux-x64.bin
 jce_policy.url=http://public-repo-1.hortonworks.com/ARTIFACTS/jce_policy-6.zip
 metadata.path=/var/lib/ambari-server/resources/stacks
+server.version.file=/var/lib/ambari-server/resources/version
 webapp.dir=/usr/lib/ambari-server/web
 bootstrap.dir=/var/run/ambari-server/bootstrap
 bootstrap.script=/usr/lib/python2.6/site-packages/ambari_server/bootstrap.py

Modified: incubator/ambari/trunk/ambari-server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/pom.xml?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/pom.xml (original)
+++ incubator/ambari/trunk/ambari-server/pom.xml Sun Mar 31 06:06:08 2013
@@ -78,6 +78,24 @@
           </excludes>
         </configuration>
       </plugin>
+      <!--<plugin>-->
+        <!-- Will be used for DDL file update on server version update-->
+        <!--<artifactId>maven-antrun-plugin</artifactId>-->
+        <!--<executions>-->
+          <!--<execution>-->
+            <!--<id>Copy-server-version-file</id>-->
+            <!--<phase>process-test-resources</phase>-->
+            <!--<configuration>-->
+              <!--<tasks>-->
+                <!--<copy file="../version" todir="${project.build.directory}/"/>-->
+              <!--</tasks>-->
+            <!--</configuration>-->
+            <!--<goals>-->
+              <!--<goal>run</goal>-->
+            <!--</goals>-->
+          <!--</execution>-->
+        <!--</executions>-->
+      <!--</plugin>-->
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>rpm-maven-plugin</artifactId>
@@ -316,6 +334,17 @@
                 </source>
               </sources>
             </mapping>
+            <mapping>
+              <directory>/var/lib/ambari-server/resources</directory>
+              <filemode>755</filemode>
+              <username>root</username>
+              <groupname>root</groupname>
+              <sources>
+                <source>
+                  <location>../version</location>
+                </source>
+              </sources>
+            </mapping>
           </mappings>
         </configuration>
       </plugin>

Modified: incubator/ambari/trunk/ambari-server/src/main/conf/ambari.properties
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/conf/ambari.properties?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/conf/ambari.properties (original)
+++ incubator/ambari/trunk/ambari-server/src/main/conf/ambari.properties Sun Mar 31 06:06:08
2013
@@ -15,4 +15,5 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-metadata.path=src/main/resources/stacks
\ No newline at end of file
+metadata.path=src/main/resources/stacks
+server.version.file=../version
\ No newline at end of file

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
Sun Mar 31 06:06:08 2013
@@ -36,6 +36,7 @@ import org.apache.ambari.server.state.sv
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceededEvent;
 import org.apache.ambari.server.utils.StageUtils;
+import org.apache.ambari.server.utils.VersionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -384,6 +385,21 @@ public class HeartBeatHandler {
     String hostname = register.getHostname();
     long now = System.currentTimeMillis();
 
+    String agentVersion = register.getAgentVersion();
+    String serverVersion = ambariMetaInfo.getServerVersion();
+    if (!VersionUtils.areVersionsCompatible(serverVersion, agentVersion)) {
+      LOG.warn("Received registration request from host with non compatible"
+              + " agent version"
+              + ", hostname=" + hostname
+              + ", agentVersion=" + agentVersion
+              + ", serverVersion=" + serverVersion);
+      throw new AmbariException("Cannot register host with non compatible"
+              + " agent version"
+              + ", hostname=" + hostname
+              + ", agentVersion=" + agentVersion
+              + ", serverVersion=" + serverVersion);
+    }
+
     String agentOsType = getOsType(register.getHardwareProfile().getOS(),
         register.getHardwareProfile().getOSRelease());
     if (!ambariMetaInfo.areOsTypesCompatible(

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
Sun Mar 31 06:06:08 2013
@@ -25,7 +25,9 @@ import org.apache.ambari.server.AmbariEx
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.StackAccessException;
 import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.resources.ResourceManager;
 import org.apache.ambari.server.state.*;
+import org.apache.ambari.server.state.Stack;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.*;
@@ -37,12 +39,7 @@ import javax.xml.parsers.ParserConfigura
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * ServiceInfo responsible getting information about cluster.
@@ -50,8 +47,10 @@ import java.util.Set;
 @Singleton
 public class AmbariMetaInfo {
 
+    private String serverVersion = "undefined";
     private List<StackInfo> stacksResult = new ArrayList<StackInfo>();
     private File stackRoot;
+    private File serverVersionFile;
     private final static Logger LOG = LoggerFactory
             .getLogger(AmbariMetaInfo.class);
     
@@ -104,13 +103,16 @@ public class AmbariMetaInfo {
      */
     @Inject
     public AmbariMetaInfo(Configuration conf) throws Exception {
-        String stackPath = conf.getMetadataPath();
-        this.stackRoot = new File(stackPath);
+      String stackPath = conf.getMetadataPath();
+      String serverVersionFilePath = conf.getServerVersionFilePath();
+      this.stackRoot = new File(stackPath);
+      this.serverVersionFile = new File(serverVersionFilePath);
     }
 
     @Inject
-    public AmbariMetaInfo(File stackRoot) throws Exception {
-        this.stackRoot = stackRoot;
+    public AmbariMetaInfo(File stackRoot, File serverVersionFile) throws Exception {
+      this.stackRoot = stackRoot;
+      this.serverVersionFile = serverVersionFile;
     }
 
 
@@ -121,6 +123,7 @@ public class AmbariMetaInfo {
      */
     @Inject
     public void init() throws Exception {
+        readServerVersion();
         getConfigurationInformation(stackRoot);
     }
 
@@ -587,8 +590,16 @@ public class AmbariMetaInfo {
       return resultOperatingSystem;
   }
 
-   
-    
+
+    private void readServerVersion() throws  Exception{
+      File versionFile = this.serverVersionFile;
+      String t = (new File(".")).getAbsolutePath();
+      if (! versionFile.exists()) {
+        throw new AmbariException("Server version file does not exist");
+      }
+      serverVersion = new Scanner(versionFile).useDelimiter("\\Z").next();
+    }
+
     private void getConfigurationInformation(File stackRoot) throws Exception {
 
         if (LOG.isDebugEnabled()) {
@@ -676,6 +687,10 @@ public class AmbariMetaInfo {
         }
     }
 
+  public String getServerVersion() {
+    return serverVersion;
+  }
+
   private StackInfo getStackInfo(File stackVersionFolder) {
 
     StackInfo stackInfo = new StackInfo();

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
Sun Mar 31 06:06:08 2013
@@ -67,6 +67,8 @@ public class Configuration {
   public static final String PASSPHRASE_KEY = "security.server.passphrase";
   public static final String RESOURCES_DIR_KEY = "resources.dir";
   public static final String METADETA_DIR_PATH = "metadata.path";
+  public static final String SERVER_VERSION_FILE = "server.version.file";
+  public static final String SERVER_VERSION_KEY = "version";
 
 
   public static final String CLIENT_SECURITY_KEY = "client.security";
@@ -358,6 +360,10 @@ public class Configuration {
     return properties.getProperty(METADETA_DIR_PATH);
   }
 
+  public String getServerVersionFilePath() {
+    return properties.getProperty(SERVER_VERSION_FILE);
+  }
+
   /**
    * Check to see if the API should be authenticated or not
    * @return false if not, true if the authentication is enabled.

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
Sun Mar 31 06:06:08 2013
@@ -36,6 +36,7 @@ import org.apache.ambari.server.bootstra
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.PersistenceType;
+import org.apache.ambari.server.orm.dao.MetainfoDAO;
 import org.apache.ambari.server.resources.ResourceManager;
 import org.apache.ambari.server.resources.api.rest.GetResource;
 import org.apache.ambari.server.security.CertificateManager;
@@ -96,6 +97,8 @@ public class AmbariServer {
   Injector injector;
   @Inject
   AmbariMetaInfo ambariMetaInfo;
+  @Inject
+  MetainfoDAO metainfoDAO;
 
   public String getServerOsType() {
     return configs.getServerOsType();
@@ -114,6 +117,8 @@ public class AmbariServer {
     server = new Server();
     serverForAgent = new Server();
 
+    checkDBVersion();
+
     try {
       ClassPathXmlApplicationContext parentSpringAppContext =
           new ClassPathXmlApplicationContext();
@@ -371,6 +376,21 @@ public class AmbariServer {
     }
   }
 
+  protected void checkDBVersion() throws AmbariException {
+    LOG.info("Checking DB store version");
+    String databaseVersion = metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY).getMetainfoValue();
+    String serverVersion = ambariMetaInfo.getServerVersion();
+    if (! databaseVersion.equals(serverVersion)) {
+      String error = "Current database store version is not compatible with " +
+              "current server version"
+              + ", serverVersion=" + serverVersion
+              + ", databaseVersion=" + databaseVersion;
+      LOG.warn(error);
+      throw new AmbariException(error);
+    }
+    LOG.info("DB store version is compatible");
+  }
+
   public void stop() throws Exception {
     try {
       server.stop();

Modified: incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
Sun Mar 31 06:06:08 2013
@@ -115,7 +115,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.key
 CREATE TABLE ambari.hostconfigmapping (cluster_id bigint NOT NULL, host_name VARCHAR(255)
NOT NULL, type_name VARCHAR(255) NOT NULL, version_tag VARCHAR(255) NOT NULL, service_name
VARCHAR(255), create_timestamp BIGINT NOT NULL, selected INTEGER NOT NULL DEFAULT 0, PRIMARY
KEY (cluster_id, host_name, type_name, create_timestamp));
 GRANT ALL PRIVILEGES ON TABLE ambari.hostconfigmapping TO :username;
 
-CREATE TABLE ambari.metainfo ("metadata_name" VARCHAR(255), "metadata_value" VARCHAR, PRIMARY
KEY("metadata_name"));
+CREATE TABLE ambari.metainfo ("metainfo_key" VARCHAR(255), "metainfo_value" VARCHAR, PRIMARY
KEY("metainfo_key"));
 GRANT ALL PRIVILEGES ON TABLE ambari.metainfo TO :username;
 
 ALTER TABLE ambari.clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id)
REFERENCES ambari.clusters (cluster_id);
@@ -172,7 +172,7 @@ select 'admin','538916f8943ec225d97a9a86
 insert into ambari.user_roles(role_name, user_id)
 select 'admin',(select user_id from ambari.users where user_name='admin' and ldap_user=false);
 
-insert into ambari.metainfo(metadata_name, metadata_value)
+insert into ambari.metainfo(metainfo_key, metainfo_value)
 select 'version','1.3.0';
 
 COMMIT;

Modified: incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
Sun Mar 31 06:06:08 2013
@@ -25,7 +25,7 @@ ALTER TABLE ambari.hosts
 ALTER TABLE ambari.clusterstate
   ADD COLUMN current_stack_version VARCHAR(255) NOT NULL;
 
-CREATE TABLE ambari.metainfo ("metadata_name" VARCHAR(255), "metadata_value" VARCHAR, PRIMARY
KEY("metadata_name"));
+CREATE TABLE ambari.metainfo ("metainfo_key" VARCHAR(255), "metainfo_value" VARCHAR, PRIMARY
KEY("metainfo_key"));
 GRANT ALL PRIVILEGES ON TABLE ambari.metainfo TO :username;
 
 CREATE TABLE ambari.clusterconfigmapping (cluster_id bigint NOT NULL, type_name VARCHAR(255)
NOT NULL, version_tag VARCHAR(255) NOT NULL, create_timestamp BIGINT NOT NULL, selected INTEGER
NOT NULL DEFAULT 0, PRIMARY KEY (cluster_id, type_name, create_timestamp));
@@ -44,7 +44,7 @@ ALTER TABLE ambari.stage ADD COLUMN requ
 
 BEGIN;
 
-insert into ambari.metainfo(metadata_name, metadata_value)
+insert into ambari.metainfo(metainfo_key, metainfo_value)
 select 'version','1.3.0';
 
 COMMIT;

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/LocalAgentSimulator.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/LocalAgentSimulator.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/LocalAgentSimulator.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/LocalAgentSimulator.java
Sun Mar 31 06:06:08 2013
@@ -36,6 +36,7 @@ public class LocalAgentSimulator impleme
   private long responseId = 1;
 
   private String hostname = "localhost";
+  private String agentVersion = "1.3.0";
 
   public LocalAgentSimulator(HeartBeatHandler hbh) {
     this.handler = hbh;
@@ -95,6 +96,7 @@ public class LocalAgentSimulator impleme
       reg = new Register();
       reg.setTimestamp(System.currentTimeMillis());
       reg.setHostname(this.hostname);
+      reg.setAgentVersion(this.agentVersion);
     }
     RegistrationResponse response;
     try {

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
Sun Mar 31 06:06:08 2013
@@ -139,6 +139,7 @@ public class TestHeartbeatHandler {
     hi.setOSRelease(DummyOSRelease);
     reg.setHostname(DummyHostname1);
     reg.setHardwareProfile(hi);
+    reg.setAgentVersion(metaInfo.getServerVersion());
     handler.handleRegistration(reg);
 
     hostObject.setState(HostState.UNHEALTHY);
@@ -424,6 +425,7 @@ public class TestHeartbeatHandler {
     hi.setOS(DummyOsType);
     reg.setHostname(DummyHostname1);
     reg.setHardwareProfile(hi);
+    reg.setAgentVersion(metaInfo.getServerVersion());
     handler.handleRegistration(reg);
     assertEquals(hostObject.getState(), HostState.HEALTHY);
     assertEquals(DummyOsType, hostObject.getOsType());
@@ -450,6 +452,7 @@ public class TestHeartbeatHandler {
     reg.setHostname(DummyHostname1);
     reg.setHardwareProfile(hi);
     reg.setPublicHostname(DummyHostname1 + "-public");
+    reg.setAgentVersion(metaInfo.getServerVersion());
     handler.handleRegistration(reg);
     assertEquals(hostObject.getState(), HostState.HEALTHY);
     assertEquals(DummyOsType, hostObject.getOsType());
@@ -480,6 +483,7 @@ public class TestHeartbeatHandler {
     hi.setOS("MegaOperatingSystem");
     reg.setHostname(DummyHostname1);
     reg.setHardwareProfile(hi);
+    reg.setAgentVersion(metaInfo.getServerVersion());
     try {
       handler.handleRegistration(reg);
       fail ("Expected failure for non matching os type");
@@ -488,6 +492,34 @@ public class TestHeartbeatHandler {
     }
   }
 
+  @Test
+  public void testIncompatibleAgentRegistration() throws AmbariException,
+          InvalidStateTransitionException {
+
+    ActionManager am = getMockActionManager();
+    Clusters fsm = clusters;
+    HeartBeatHandler handler = new HeartBeatHandler(fsm, new ActionQueue(), am,
+            injector);
+    clusters.addHost(DummyHostname1);
+    Host hostObject = clusters.getHost(DummyHostname1);
+    hostObject.setIPv4("ipv4");
+    hostObject.setIPv6("ipv6");
+
+    Register reg = new Register();
+    HostInfo hi = new HostInfo();
+    hi.setHostName(DummyHostname1);
+    hi.setOS(DummyOsType);
+    reg.setHostname(DummyHostname1);
+    reg.setHardwareProfile(hi);
+    reg.setAgentVersion("0.0.0"); // Invalid agent version
+    try {
+      handler.handleRegistration(reg);
+      fail ("Expected failure for non compatible agent version");
+    } catch (AmbariException e) {
+      // Expected
+    }
+  }
+
 
   @Test
   public void testRegisterNewNode()
@@ -507,6 +539,7 @@ public class TestHeartbeatHandler {
     hi.setOS("redhat5");
     reg.setHostname(DummyHostname1);
     reg.setHardwareProfile(hi);
+    reg.setAgentVersion(metaInfo.getServerVersion());
     RegistrationResponse response = handler.handleRegistration(reg);
 
     assertEquals(hostObject.getState(), HostState.HEALTHY);
@@ -530,6 +563,7 @@ public class TestHeartbeatHandler {
     hi.setHostName(DummyHostname1);
     hi.setOS("redhat5");
     register.setHardwareProfile(hi);
+    register.setAgentVersion(metaInfo.getServerVersion());
     RegistrationResponse registrationResponse = heartBeatHandler.handleRegistration(register);
 
     assertEquals("ResponseId should start from zero", 0L, registrationResponse.getResponseId());
@@ -597,6 +631,7 @@ public class TestHeartbeatHandler {
     hi.setOS(DummyOsType);
     reg.setHostname(DummyHostname1);
     reg.setHardwareProfile(hi);
+    reg.setAgentVersion(metaInfo.getServerVersion());
     RegistrationResponse registrationResponse = handler.handleRegistration(reg);
     registrationResponse.getStatusCommands();
     assertTrue(registrationResponse.getStatusCommands().size() == 1);
@@ -1081,6 +1116,7 @@ public class TestHeartbeatHandler {
     reg.setHostname(DummyHostname1);
     reg.setResponseId(0);
     reg.setHardwareProfile(hi);
+    reg.setAgentVersion(metaInfo.getServerVersion());
     handler.handleRegistration(reg);
     return handler;
   }

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
Sun Mar 31 06:06:08 2013
@@ -111,6 +111,7 @@ public class TestHeartbeatMonitor {
     reg.setHostname(hostname1);
     reg.setResponseId(12);
     reg.setTimestamp(System.currentTimeMillis() - 300);
+    reg.setAgentVersion(ambariMetaInfo.getServerVersion());
     HostInfo hi = new HostInfo();
     hi.setOS("Centos5");
     reg.setHardwareProfile(hi);
@@ -180,6 +181,7 @@ public class TestHeartbeatMonitor {
     reg.setHostname(hostname1);
     reg.setResponseId(12);
     reg.setTimestamp(System.currentTimeMillis() - 15);
+    reg.setAgentVersion(ambariMetaInfo.getServerVersion());
     HostInfo hi = new HostInfo();
     hi.setOS("Centos5");
     reg.setHardwareProfile(hi);
@@ -223,6 +225,7 @@ public class TestHeartbeatMonitor {
     reg.setHostname(hostname);
     reg.setResponseId(12);
     reg.setTimestamp(System.currentTimeMillis() - 300);
+    reg.setAgentVersion(ambariMetaInfo.getServerVersion());
     HostInfo hi = new HostInfo();
     hi.setOS("Centos5");
     reg.setHardwareProfile(hi);

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
Sun Mar 31 06:06:08 2013
@@ -81,7 +81,7 @@ public class AmbariMetaInfoTest {
   public void before() throws Exception {
     File stackRoot = new File("src/test/resources/stacks");
    LOG.info("Stacks file " + stackRoot.getAbsolutePath());
-    metaInfo = new AmbariMetaInfo(stackRoot);
+    metaInfo = new AmbariMetaInfo(stackRoot, new File("../version"));
     try {
       metaInfo.init();
     } catch(Exception e) {
@@ -246,7 +246,7 @@ public class AmbariMetaInfoTest {
     File stackRoot = new File("src/test/resources/stacks");
     File stackRootTmp = new File(buildDir + "/ambari-metaInfo"); stackRootTmp.mkdir();
     FileUtils.copyDirectory(stackRoot, stackRootTmp);
-    AmbariMetaInfo ambariMetaInfo = new AmbariMetaInfo(stackRootTmp);
+    AmbariMetaInfo ambariMetaInfo = new AmbariMetaInfo(stackRootTmp, new File("../version"));
     File f1, f2, f3;
     f1 = new File(stackRootTmp.getAbsolutePath() + "/001.svn"); f1.createNewFile();
     f2 = new File(stackRootTmp.getAbsolutePath() + "/abcd.svn/001.svn"); f2.mkdirs(); f2.createNewFile();

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaServiceTest.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaServiceTest.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaServiceTest.java
Sun Mar 31 06:06:08 2013
@@ -67,7 +67,7 @@ public class AmbariMetaServiceTest exten
     AmbariMetaInfo ambariMetaInfo;
     
     public MockModule() throws Exception {
-      this.ambariMetaInfo = new AmbariMetaInfo(stackRoot);
+      this.ambariMetaInfo = new AmbariMetaInfo(stackRoot, new File("../version"));
     }
 
     @Override

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
Sun Mar 31 06:06:08 2013
@@ -1477,6 +1477,8 @@ public class AmbariManagementControllerI
         properties.setProperty(Configuration.PERSISTENCE_IN_MEMORY_KEY, "true");
         properties.setProperty(Configuration.METADETA_DIR_PATH,
             "src/main/resources/stacks");
+        properties.setProperty(Configuration.SERVER_VERSION_FILE,
+                "../version");
         properties.setProperty(Configuration.OS_VERSION_KEY,
             "centos5");
         try {

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java?rev=1462883&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
(added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
Sun Mar 31 06:06:08 2013
@@ -0,0 +1,80 @@
+package org.apache.ambari.server.controller;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.MetainfoDAO;
+import org.apache.ambari.server.orm.entities.MetainfoEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.fail;
+
+public class AmbariServerTest {
+
+  private static final Logger log = LoggerFactory.getLogger(AmbariServerTest.class);
+  private Injector injector;
+
+  @Inject
+  private AmbariMetaInfo ambariMetaInfo;
+
+  @Before
+  public void setup() throws Exception {
+    injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    injector.injectMembers(this);
+  }
+
+  @After
+  public void teardown() throws AmbariException {
+  }
+
+  @Test
+  public void testCheckDBVersion_Valid() throws Exception {
+    MetainfoDAO metainfoDAO =  createMock(MetainfoDAO.class);
+    MetainfoEntity metainfoEntity = new MetainfoEntity();
+    String serverVersion = ambariMetaInfo.getServerVersion();
+    metainfoEntity.setMetainfoName(Configuration.SERVER_VERSION_KEY);
+    metainfoEntity.setMetainfoValue(serverVersion);
+    expect(metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY)).
+            andReturn(metainfoEntity);
+    replay(metainfoDAO);
+    AmbariServer ambariServer = new AmbariServer();
+    ambariServer.metainfoDAO = metainfoDAO;
+    ambariServer.ambariMetaInfo = ambariMetaInfo;
+    ambariServer.checkDBVersion();
+  }
+
+  @Test
+  public void testCheckDBVersion_Invalid() throws Exception {
+    MetainfoDAO metainfoDAO =  createMock(MetainfoDAO.class);
+    MetainfoEntity metainfoEntity = new MetainfoEntity();
+    metainfoEntity.setMetainfoName(Configuration.SERVER_VERSION_KEY);
+    metainfoEntity.setMetainfoValue("0.0.0"); // Incompatible version
+    expect(metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY)).
+            andReturn(metainfoEntity);
+    replay(metainfoDAO);
+    AmbariServer ambariServer = new AmbariServer();
+    ambariServer.metainfoDAO = metainfoDAO;
+    ambariServer.ambariMetaInfo = ambariMetaInfo;
+
+    try {
+      ambariServer.checkDBVersion();
+      fail();
+    } catch(AmbariException e) {
+      // Expected
+    }
+  }
+
+
+}

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java?rev=1462883&r1=1462882&r2=1462883&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
Sun Mar 31 06:06:08 2013
@@ -31,6 +31,8 @@ public class InMemoryDefaultTestModule e
     properties.setProperty(Configuration.PERSISTENCE_IN_MEMORY_KEY, "true");
     properties.setProperty(Configuration.METADETA_DIR_PATH,
         "src/test/resources/stacks");
+    properties.setProperty(Configuration.SERVER_VERSION_FILE,
+            "../version");
     properties.setProperty(Configuration.OS_VERSION_KEY,
         "centos5");
     try {

Added: incubator/ambari/trunk/version
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/version?rev=1462883&view=auto
==============================================================================
--- incubator/ambari/trunk/version (added)
+++ incubator/ambari/trunk/version Sun Mar 31 06:06:08 2013
@@ -0,0 +1 @@
+1.3.0
\ No newline at end of file



Mime
View raw message