Pārlūkot izejas kodu

AMBARI-2233. Ensure version values are used appropriately throughout Ambari. (smohanty)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1488002 13f79535-47bb-0310-9956-ffa450edef68
Sumit Mohanty 12 gadi atpakaļ
vecāks
revīzija
f3e2e0c68d

+ 3 - 0
CHANGES.txt

@@ -907,6 +907,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-2233. Ensure version values are used appropriately throughout
+ Ambari. (smohanty)
+
  AMBARI-2229. Oracle driver loading broken on agent side. (smohanty)
 
  AMBARI-2228. Fix MySQL and Oracle DDL scripts according to last DB

+ 28 - 0
ambari-agent/pom.xml

@@ -60,6 +60,33 @@
   </profiles>
   <build>
     <plugins>
+      <plugin>
+         <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <version>1.8</version>
+        <executions>
+          <execution>
+            <id>parse-version</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>parse-version</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>regex-property</id>
+            <goals>
+              <goal>regex-property</goal>
+            </goals>
+            <configuration>
+              <name>ambariVersion</name>
+              <value>${project.version}</value>
+              <regex>-SNAPSHOT</regex>
+              <replacement></replacement>
+              <failIfNoMatch>false</failIfNoMatch>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
       <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>3.0</version>
@@ -298,6 +325,7 @@
               <sources>
                 <source>
                   <location>../version</location>
+                  <filter>true</filter>
                 </source>
               </sources>
             </mapping>

+ 61 - 0
ambari-server/pom.xml

@@ -32,6 +32,58 @@
   </properties>
   <build>
     <plugins>
+      <plugin>
+         <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <version>1.8</version>
+        <executions>
+          <execution>
+            <id>parse-version</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>parse-version</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>regex-property</id>
+            <goals>
+              <goal>regex-property</goal>
+            </goals>
+            <configuration>
+              <name>ambariVersion</name>
+              <value>${project.version}</value>
+              <regex>-SNAPSHOT</regex>
+              <replacement></replacement>
+              <failIfNoMatch>false</failIfNoMatch>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.6</version>
+        <executions>
+          <execution>
+            <id>copy-resources</id>
+            <phase>generate-test-resources</phase>
+            <goals>
+              <goal>copy-resources</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>${basedir}/target/</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>${basedir}/../</directory>
+                  <includes>
+                      <include>**/version</include>
+                  </includes>
+                  <filtering>true</filtering>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
       <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>3.0</version>
@@ -256,6 +308,7 @@
               <sources>
                 <source>
                   <location>src/main/resources/Ambari-DDL-Postgres-CREATE.sql</location>
+                  <filter>true</filter>
                 </source>
                 <source>
                   <location>src/main/resources/Ambari-DDL-Postgres-DROP.sql</location>
@@ -276,6 +329,7 @@
               <sources>
                 <source>
                   <location>src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql</location>
+                  <filter>true</filter>
                 </source>
                 <source>
                   <location>src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Fix.sql</location>
@@ -361,6 +415,7 @@
               <sources>
                 <source>
                   <location>../version</location>
+                  <filter>true</filter>
                 </source>
               </sources>
             </mapping>
@@ -419,6 +474,12 @@
         -->
       </plugin>
     </plugins>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+      </resource>
+    </resources>
   </build>
   <profiles>
   </profiles>

+ 1 - 1
ambari-server/src/main/conf/ambari.properties

@@ -16,4 +16,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 metadata.path=src/main/resources/stacks
-server.version.file=../version
+server.version.file=target/version

+ 1 - 1
ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql

@@ -177,7 +177,7 @@ insert into ambari.user_roles(role_name, user_id)
 select 'admin',1;
 
 insert into ambari.metainfo(metainfo_key, metainfo_value)
-select 'version','1.3.0';
+select 'version','${ambariVersion}';
 
 COMMIT;
 

+ 1 - 1
ambari-server/src/main/resources/mysql-ddl.sql

@@ -102,7 +102,7 @@ insert into ambari.user_roles(role_name, user_id)
   select 'admin',1;
 
 insert into ambari.metainfo(`metainfo_key`, `metainfo_value`)
-  select 'version','1.3.0';
+  select 'version','${ambariVersion}';
 
 
 

+ 1 - 1
ambari-server/src/main/resources/oracle-DDL.sql

@@ -117,7 +117,7 @@ GRANT ALL ON metainfo TO &1;
 INSERT INTO ambari_sequences(sequence_name, value) values ('host_role_command_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, value) values ('user_id_seq', 1);
 INSERT INTO ambari_sequences(sequence_name, value) values ('cluster_id_seq', 0);
-INSERT INTO metainfo("metainfo_key", "metainfo_value") values ('version', '1.3.0');
+INSERT INTO metainfo("metainfo_key", "metainfo_value") values ('version', '${ambariVersion}');
 
 insert into Roles(role_name)
 select 'admin' from dual

+ 40 - 6
ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql

@@ -26,8 +26,6 @@ ALTER TABLE ambari.hosts
 ALTER TABLE ambari.clusterstate
   ADD COLUMN current_stack_version VARCHAR(255) NOT NULL;
 
-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.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, user_name VARCHAR(255) NOT NULL DEFAULT '_db', PRIMARY KEY (cluster_id, host_name, type_name, create_timestamp));
 GRANT ALL PRIVILEGES ON TABLE ambari.hostconfigmapping TO :username;
@@ -57,10 +55,48 @@ drop sequence ambari.host_role_command_task_id_seq;
 drop sequence ambari.users_user_id_seq;
 drop sequence ambari.clusters_cluster_id_seq;
 
+CREATE LANGUAGE plpgsql;
+
 BEGIN;
 
-insert into ambari.metainfo(metainfo_key, metainfo_value)
-select 'version','1.3.0';
+CREATE OR REPLACE FUNCTION create_or_update_metainfo_table(ambariVersion VARCHAR, userName TEXT) RETURNS text AS
+$$
+DECLARE
+    version VARCHAR(255) := 'version';
+    fqtn text := 'ambari.metainfo';
+BEGIN
+    IF NOT EXISTS (SELECT * FROM pg_tables WHERE tablename = 'metainfo') THEN
+        EXECUTE 'CREATE TABLE '
+        || fqtn
+        || ' (metainfo_key VARCHAR(255), metainfo_value VARCHAR, PRIMARY KEY(metainfo_key));';
+        EXECUTE 'GRANT ALL PRIVILEGES ON TABLE '
+        || fqtn
+        || ' TO '
+        || $2
+        || ';';
+        EXECUTE 'INSERT INTO '
+        || fqtn
+        || '(metainfo_key, metainfo_value) select '
+        || quote_literal(version)
+        || ','
+        || quote_literal($1)
+        || ';';
+        RETURN 'INFO: metainfo was created';
+    ELSE
+        EXECUTE 'UPDATE '
+        || fqtn
+        || ' SET metainfo_value = '
+        || quote_literal($1)
+        || ' WHERE metainfo_key = '
+        || quote_literal(version)
+        || ';';
+        RETURN 'INFO: metainfo was updated';
+    END IF;
+END;
+$$
+LANGUAGE 'plpgsql';
+
+SELECT create_or_update_metainfo_table('${ambariVersion}',:username);
 
 COMMIT;
 
@@ -69,8 +105,6 @@ UPDATE ambari.hostcomponentstate SET current_state = 'INSTALLED' WHERE current_s
 
 -- service to cluster level config mappings move. idempotent update
 
-CREATE LANGUAGE plpgsql;
-
 CREATE OR REPLACE FUNCTION update_clusterconfigmapping()
   RETURNS void AS
 $_$

+ 2 - 2
ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java

@@ -82,7 +82,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, new File("../version"));
+    metaInfo = new AmbariMetaInfo(stackRoot, new File("target/version"));
     try {
       metaInfo.init();
     } catch(Exception e) {
@@ -280,7 +280,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, new File("../version"));
+    AmbariMetaInfo ambariMetaInfo = new AmbariMetaInfo(stackRootTmp, new File("target/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();

+ 2 - 2
ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaServiceTest.java

@@ -67,7 +67,7 @@ public class AmbariMetaServiceTest extends JerseyTest {
     AmbariMetaInfo ambariMetaInfo;
     
     public MockModule() throws Exception {
-      this.ambariMetaInfo = new AmbariMetaInfo(stackRoot, new File("../version"));
+      this.ambariMetaInfo = new AmbariMetaInfo(stackRoot, new File("target/version"));
     }
 
     @Override
@@ -108,4 +108,4 @@ public class AmbariMetaServiceTest extends JerseyTest {
     ServiceInfo info = mapper.readValue(output, ServiceInfo.class);
     Assert.assertEquals("HDFS", info.getName());
   }
-}
+}

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java

@@ -1479,7 +1479,7 @@ public class AmbariManagementControllerImplTest {
         properties.setProperty(Configuration.METADETA_DIR_PATH,
             "src/main/resources/stacks");
         properties.setProperty(Configuration.SERVER_VERSION_FILE,
-                "../version");
+                "target/version");
         properties.setProperty(Configuration.OS_VERSION_KEY,
             "centos5");
         try {

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java

@@ -33,7 +33,7 @@ public class InMemoryDefaultTestModule extends AbstractModule {
     properties.setProperty(Configuration.METADETA_DIR_PATH,
         "src/test/resources/stacks");
     properties.setProperty(Configuration.SERVER_VERSION_FILE,
-            "../version");
+            "target/version");
     properties.setProperty(Configuration.OS_VERSION_KEY,
         "centos5");
     try {

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AuthorizationTestModule.java

@@ -35,7 +35,7 @@ public class AuthorizationTestModule extends AbstractModule {
     properties.setProperty(Configuration.METADETA_DIR_PATH,
         "src/test/resources/stacks");
     properties.setProperty(Configuration.SERVER_VERSION_FILE,
-        "../version");
+        "target/version");
     properties.setProperty(Configuration.OS_VERSION_KEY,
         "centos5");
 

+ 1 - 1
version

@@ -1 +1 @@
-1.3.0
+${ambariVersion}