You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2017/04/17 20:18:05 UTC
[11/34] ambari git commit: AMBARI-20714 - Upgrade Catalog 2.5.1
Changes For HRC Background Task (jonathanhurley)
AMBARI-20714 - Upgrade Catalog 2.5.1 Changes For HRC Background Task (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4f419689
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4f419689
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4f419689
Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 4f419689503fb634f402e0b4c5d697b8d382006b
Parents: a5dc75e
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Tue Apr 11 12:50:55 2017 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Thu Apr 13 08:45:14 2017 -0400
----------------------------------------------------------------------
.../orm/entities/HostRoleCommandEntity.java | 2 +-
.../server/upgrade/SchemaUpgradeHelper.java | 1 +
.../server/upgrade/UpgradeCatalog251.java | 81 +++++++++
.../main/resources/Ambari-DDL-Derby-CREATE.sql | 2 +-
.../main/resources/Ambari-DDL-MySQL-CREATE.sql | 2 +-
.../main/resources/Ambari-DDL-Oracle-CREATE.sql | 2 +-
.../resources/Ambari-DDL-Postgres-CREATE.sql | 2 +-
.../resources/Ambari-DDL-SQLAnywhere-CREATE.sql | 2 +-
.../resources/Ambari-DDL-SQLServer-CREATE.sql | 2 +-
.../server/upgrade/UpgradeCatalog251Test.java | 166 +++++++++++++++++++
10 files changed, 255 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
index 6197940..86feceb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
@@ -201,7 +201,7 @@ public class HostRoleCommandEntity {
private TopologyLogicalTaskEntity topologyLogicalTaskEntity;
@Basic
- @Column(name = "is_background_command", nullable = false)
+ @Column(name = "is_background", nullable = false)
private short isBackgroundCommand = 0;
public Long getTaskId() {
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
index 590a3e8..d022f1f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
@@ -189,6 +189,7 @@ public class SchemaUpgradeHelper {
catalogBinder.addBinding().to(UpgradeCatalog2402.class);
catalogBinder.addBinding().to(UpgradeCatalog242.class);
catalogBinder.addBinding().to(UpgradeCatalog250.class);
+ catalogBinder.addBinding().to(UpgradeCatalog251.class);
catalogBinder.addBinding().to(UpgradeCatalog300.class);
catalogBinder.addBinding().to(FinalUpgradeCatalog.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
new file mode 100644
index 0000000..a5f38a9
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+package org.apache.ambari.server.upgrade;
+
+import java.sql.SQLException;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
+
+/**
+ * The {@link UpgradeCatalog251} upgrades Ambari from 2.5.0 to 2.5.1.
+ */
+public class UpgradeCatalog251 extends AbstractUpgradeCatalog {
+
+ static final String HOST_ROLE_COMMAND_TABLE = "host_role_command";
+ static final String HRC_IS_BACKGROUND_COLUMN = "is_background";
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getSourceVersion() {
+ return "2.5.0";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getTargetVersion() {
+ return "2.5.1";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void executeDDLUpdates() throws AmbariException, SQLException {
+ addBackgroundColumnToHostRoleCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void executePreDMLUpdates() throws AmbariException, SQLException {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void executeDMLUpdates() throws AmbariException, SQLException {
+ }
+
+ /**
+ * Adds the {@value #HRC_IS_BACKGROUND_COLUMN} column to the
+ * {@value #HOST_ROLE_COMMAND_TABLE} table.
+ *
+ * @throws SQLException
+ */
+ private void addBackgroundColumnToHostRoleCommand() throws SQLException {
+ dbAccessor.addColumn(HOST_ROLE_COMMAND_TABLE,
+ new DBColumnInfo(HRC_IS_BACKGROUND_COLUMN, Short.class, null, 0, false));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index 5785a9d..fd49b94 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -383,7 +383,7 @@ CREATE TABLE host_role_command (
role_command VARCHAR(255),
command_detail VARCHAR(255),
custom_command_name VARCHAR(255),
- is_background_command SMALLINT DEFAULT 0 NOT NULL,
+ is_background SMALLINT DEFAULT 0 NOT NULL,
CONSTRAINT PK_host_role_command PRIMARY KEY (task_id),
CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id),
CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 96ef0ac..9fc3209 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -404,7 +404,7 @@ CREATE TABLE host_role_command (
structured_out LONGBLOB,
command_detail VARCHAR(255),
custom_command_name VARCHAR(255),
- is_background_command SMALLINT DEFAULT 0 NOT NULL,
+ is_background SMALLINT DEFAULT 0 NOT NULL,
CONSTRAINT PK_host_role_command PRIMARY KEY (task_id),
CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id),
CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 3396ce9..310208d 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -384,7 +384,7 @@ CREATE TABLE host_role_command (
structured_out BLOB NULL,
command_detail VARCHAR2(255) NULL,
custom_command_name VARCHAR2(255) NULL,
- is_background_command SMALLINT DEFAULT 0 NOT NULL,
+ is_background SMALLINT DEFAULT 0 NOT NULL,
CONSTRAINT PK_host_role_command PRIMARY KEY (task_id),
CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id),
CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index c6bfa94..c052104 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -383,7 +383,7 @@ CREATE TABLE host_role_command (
role_command VARCHAR(255),
command_detail VARCHAR(255),
custom_command_name VARCHAR(255),
- is_background_command SMALLINT DEFAULT 0 NOT NULL,
+ is_background SMALLINT DEFAULT 0 NOT NULL,
CONSTRAINT PK_host_role_command PRIMARY KEY (task_id),
CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id),
CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index bbf5d3c..5a58ef8 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -382,7 +382,7 @@ CREATE TABLE host_role_command (
structured_out IMAGE,
command_detail VARCHAR(255),
custom_command_name VARCHAR(255),
- is_background_command SMALLINT DEFAULT 0 NOT NULL,
+ is_background SMALLINT DEFAULT 0 NOT NULL,
CONSTRAINT PK_host_role_command PRIMARY KEY (task_id),
CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id),
CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index 13ab01d..8c7a31d 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -388,7 +388,7 @@ CREATE TABLE host_role_command (
role_command VARCHAR(255),
command_detail VARCHAR(255),
custom_command_name VARCHAR(255),
- is_background_command SMALLINT DEFAULT 0 NOT NULL,
+ is_background SMALLINT DEFAULT 0 NOT NULL,
CONSTRAINT PK_host_role_command PRIMARY KEY CLUSTERED (task_id),
CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id),
CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f419689/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java
new file mode 100644
index 0000000..4575998
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+
+package org.apache.ambari.server.upgrade;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.newCapture;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import javax.persistence.EntityManager;
+
+import org.apache.ambari.server.actionmanager.ActionManager;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.KerberosHelper;
+import org.apache.ambari.server.controller.MaintenanceStateHelper;
+import org.apache.ambari.server.orm.DBAccessor;
+import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.stack.OsFamily;
+import org.easymock.Capture;
+import org.easymock.EasyMockRunner;
+import org.easymock.Mock;
+import org.easymock.MockType;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.google.gson.Gson;
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provider;
+
+/**
+ * {@link UpgradeCatalog251} unit tests.
+ */
+@RunWith(EasyMockRunner.class)
+public class UpgradeCatalog251Test {
+
+ // private Injector injector;
+ @Mock(type = MockType.STRICT)
+ private Provider<EntityManager> entityManagerProvider;
+
+ @Mock(type = MockType.NICE)
+ private EntityManager entityManager;
+
+ @Mock(type = MockType.NICE)
+ private DBAccessor dbAccessor;
+
+ @Mock(type = MockType.NICE)
+ private Configuration configuration;
+
+ @Mock(type = MockType.NICE)
+ private Connection connection;
+
+ @Mock(type = MockType.NICE)
+ private Statement statement;
+
+ @Mock(type = MockType.NICE)
+ private ResultSet resultSet;
+
+ @Mock(type = MockType.NICE)
+ private OsFamily osFamily;
+
+ @Mock(type = MockType.NICE)
+ private KerberosHelper kerberosHelper;
+
+ @Mock(type = MockType.NICE)
+ private ActionManager actionManager;
+
+ @Mock(type = MockType.NICE)
+ private Config config;
+
+ @Mock(type = MockType.STRICT)
+ private Service service;
+
+ @Mock(type = MockType.NICE)
+ private Clusters clusters;
+
+ @Mock(type = MockType.NICE)
+ private Cluster cluster;
+
+ @Mock(type = MockType.NICE)
+ private Injector injector;
+
+ @Before
+ public void init() {
+ reset(entityManagerProvider, injector);
+
+ expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
+
+ expect(injector.getInstance(Gson.class)).andReturn(null).anyTimes();
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).anyTimes();
+ expect(injector.getInstance(KerberosHelper.class)).andReturn(kerberosHelper).anyTimes();
+
+ replay(entityManagerProvider, injector);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testExecuteDDLUpdates() throws Exception {
+ Capture<DBColumnInfo> hrcBackgroundColumnCapture = newCapture();
+ dbAccessor.addColumn(eq(UpgradeCatalog251.HOST_ROLE_COMMAND_TABLE), capture(hrcBackgroundColumnCapture));
+
+ expect(dbAccessor.getConnection()).andReturn(connection).anyTimes();
+ expect(connection.createStatement()).andReturn(statement).anyTimes();
+ expect(statement.executeQuery(anyObject(String.class))).andReturn(resultSet).anyTimes();
+ expect(configuration.getDatabaseType()).andReturn(Configuration.DatabaseType.POSTGRES).anyTimes();
+
+ replay(dbAccessor, configuration, connection, statement, resultSet);
+
+ Module module = new Module() {
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(DBAccessor.class).toInstance(dbAccessor);
+ binder.bind(OsFamily.class).toInstance(osFamily);
+ binder.bind(EntityManager.class).toInstance(entityManager);
+ binder.bind(Configuration.class).toInstance(configuration);
+ }
+ };
+
+ Injector injector = Guice.createInjector(module);
+ UpgradeCatalog251 upgradeCatalog251 = injector.getInstance(UpgradeCatalog251.class);
+ upgradeCatalog251.executeDDLUpdates();
+
+ verify(dbAccessor);
+
+ DBColumnInfo captured = hrcBackgroundColumnCapture.getValue();
+ Assert.assertEquals(UpgradeCatalog251.HRC_IS_BACKGROUND_COLUMN, captured.getName());
+ Assert.assertEquals(Integer.valueOf(0), captured.getDefaultValue());
+ Assert.assertEquals(Short.class, captured.getType());
+ }
+}