Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 4512f5525 -> f90f09346


AMBARI-18532. Part_2.Getting errors with max length 1000byte, when using Mysql 
db with charset UTF8.(vbrodetskyi)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f90f0934
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f90f0934
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f90f0934

Branch: refs/heads/branch-2.5
Commit: f90f09346e58a84ec3b40d9d2743014280b19680
Parents: 4512f55
Author: Vitaly Brodetskyi <vbrodets...@hortonworks.com>
Authored: Thu Oct 13 04:03:30 2016 +0300
Committer: Vitaly Brodetskyi <vbrodets...@hortonworks.com>
Committed: Thu Oct 13 04:03:30 2016 +0300

----------------------------------------------------------------------
 .../server/upgrade/SchemaUpgradeHelper.java     |   1 +
 .../server/upgrade/UpgradeCatalog242.java       | 124 ++++++++++
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |   2 +-
 .../server/upgrade/UpgradeCatalog242Test.java   | 226 +++++++++++++++++++
 4 files changed, 352 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f90f0934/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 2256acf..aa557b1 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
@@ -192,6 +192,7 @@ public class SchemaUpgradeHelper {
       catalogBinder.addBinding().to(UpgradeCatalog222.class);
       catalogBinder.addBinding().to(UpgradeCatalog230.class);
       catalogBinder.addBinding().to(UpgradeCatalog240.class);
+      catalogBinder.addBinding().to(UpgradeCatalog242.class);
       catalogBinder.addBinding().to(UpgradeCatalog250.class);
       catalogBinder.addBinding().to(FinalUpgradeCatalog.class);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f90f0934/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
new file mode 100644
index 0000000..6fa3e68
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
@@ -0,0 +1,124 @@
+/*
+ * 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.configuration.Configuration;
+import org.apache.ambari.server.orm.DBAccessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+/**
+ * Upgrade catalog for version 2.4.2.
+ */
+public class UpgradeCatalog242 extends AbstractUpgradeCatalog {
+
+  protected static final String EXTENSION_TABLE = "extension";
+  protected static final String USERS_TABLE = "users";
+  protected static final String HOST_ROLE_COMMAND_TABLE = "host_role_command";
+  protected static final String BLUEPRINT_TABLE = "blueprint";
+
+  protected static final String BLUEPRINT_NAME_COLUMN = "blueprint_name";
+  protected static final String EXTENSION_NAME_COLUMN = "extension_name";
+  protected static final String EXTENSION_VERSION_COLUMN = "extension_version";
+  protected static final String USER_TYPE_COLUMN = "user_type";
+  protected static final String USER_NAME_COLUMN = "user_name";
+  protected static final String ROLE_COLUMN = "role";
+  protected static final String STATUS_COLUMN = "status";
+
+
+  /**
+   * Logger.
+   */
+  private static final Logger LOG = 
LoggerFactory.getLogger(UpgradeCatalog242.class);
+
+
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Don't forget to register new UpgradeCatalogs in {@link 
org.apache.ambari.server.upgrade.SchemaUpgradeHelper.UpgradeHelperModule#configure()}
+   *
+   * @param injector Guice injector to track dependencies and uses bindings to 
inject them.
+   */
+  @Inject
+  public UpgradeCatalog242(Injector injector) {
+    super(injector);
+    this.injector = injector;
+  }
+
+  // ----- UpgradeCatalog ----------------------------------------------------
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String getTargetVersion() {
+    return "2.4.2";
+  }
+
+  // ----- AbstractUpgradeCatalog --------------------------------------------
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String getSourceVersion() {
+    return "2.4.0";
+  }
+
+
+  @Override
+  protected void executeDDLUpdates() throws AmbariException, SQLException {
+    updateTablesForMysql();
+  }
+
+  @Override
+  protected void executePreDMLUpdates() throws AmbariException, SQLException {
+    //To change body of implemented methods use File | Settings | File 
Templates.
+  }
+
+  @Override
+  protected void executeDMLUpdates() throws AmbariException, SQLException {
+    addNewConfigurationsFromXml();
+  }
+
+  protected void updateTablesForMysql() throws SQLException {
+    final Configuration.DatabaseType databaseType = 
configuration.getDatabaseType();
+    if (databaseType == Configuration.DatabaseType.MYSQL) {
+      dbAccessor.alterColumn(EXTENSION_TABLE, new 
DBAccessor.DBColumnInfo(EXTENSION_NAME_COLUMN, String.class, 100, null, false));
+      dbAccessor.alterColumn(EXTENSION_TABLE, new 
DBAccessor.DBColumnInfo(EXTENSION_VERSION_COLUMN, String.class, 100, null, 
false));
+
+      dbAccessor.alterColumn(USERS_TABLE, new 
DBAccessor.DBColumnInfo(USER_TYPE_COLUMN, String.class, 100, null, false));
+      dbAccessor.alterColumn(USERS_TABLE, new 
DBAccessor.DBColumnInfo(USER_NAME_COLUMN, String.class, 100, null, false));
+
+      dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new 
DBAccessor.DBColumnInfo(ROLE_COLUMN, String.class, 100, null, true));
+      dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new 
DBAccessor.DBColumnInfo(STATUS_COLUMN, String.class, 100, null, true));
+
+      dbAccessor.alterColumn(BLUEPRINT_TABLE, new 
DBAccessor.DBColumnInfo(BLUEPRINT_NAME_COLUMN, String.class, 100, null, false));
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f90f0934/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 1c17e1a..f28cdc9 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -508,7 +508,7 @@ CREATE TABLE requestschedulebatchrequest (
   CONSTRAINT FK_rsbatchrequest_schedule_id FOREIGN KEY (schedule_id) 
REFERENCES requestschedule (schedule_id));
 
 CREATE TABLE blueprint (
-  blueprint_name VARCHAR(255) NOT NULL,
+  blueprint_name VARCHAR(100) NOT NULL,
   stack_id BIGINT NOT NULL,
   security_type VARCHAR(32) NOT NULL DEFAULT 'NONE',
   security_descriptor_reference VARCHAR(255),

http://git-wip-us.apache.org/repos/asf/ambari/blob/f90f0934/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog242Test.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog242Test.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog242Test.java
new file mode 100644
index 0000000..81f8451
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog242Test.java
@@ -0,0 +1,226 @@
+/*
+ * 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 javax.persistence.EntityManager;
+import junit.framework.Assert;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+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.lang.reflect.Method;
+
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.orm.DBAccessor;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.ClusterDAO;
+import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
+import org.apache.ambari.server.orm.dao.HostVersionDAO;
+import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
+import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.state.stack.OsFamily;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+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;
+import com.google.inject.persist.PersistService;
+/**
+ * {@link org.apache.ambari.server.upgrade.UpgradeCatalog242} unit tests.
+ */
+public class UpgradeCatalog242Test {
+  private Injector injector;
+  private Provider<EntityManager> entityManagerProvider = 
createStrictMock(Provider.class);
+  private EntityManager entityManager = createNiceMock(EntityManager.class);
+  private UpgradeCatalogHelper upgradeCatalogHelper;
+  private StackEntity desiredStackEntity;
+  private AmbariManagementController amc = 
createNiceMock(AmbariManagementController.class);
+  private AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+  private StackDAO stackDAO = createNiceMock(StackDAO.class);
+  private RepositoryVersionDAO repositoryVersionDAO = 
createNiceMock(RepositoryVersionDAO.class);
+  private ClusterVersionDAO clusterVersionDAO = 
createNiceMock(ClusterVersionDAO.class);
+  private HostVersionDAO hostVersionDAO = createNiceMock(HostVersionDAO.class);
+  private ClusterDAO clusterDAO = createNiceMock(ClusterDAO.class);
+
+  private IMocksControl mocksControl = EasyMock.createControl();
+
+  @Before
+  public void init() {
+    reset(entityManagerProvider);
+    expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
+    replay(entityManagerProvider);
+    injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    injector.getInstance(GuiceJpaInitializer.class);
+
+    upgradeCatalogHelper = injector.getInstance(UpgradeCatalogHelper.class);
+    // inject AmbariMetaInfo to ensure that stacks get populated in the DB
+    injector.getInstance(AmbariMetaInfo.class);
+    // load the stack entity
+    StackDAO stackDAO = injector.getInstance(StackDAO.class);
+    desiredStackEntity = stackDAO.find("HDP", "2.2.0");
+  }
+
+  @After
+  public void tearDown() {
+    injector.getInstance(PersistService.class).stop();
+  }
+
+  @Test
+  public void testUpdateTablesForMysql() throws Exception{
+    final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
+    final Configuration configuration = createNiceMock(Configuration.class);
+
+    Capture<DBAccessor.DBColumnInfo> extensionExtensionNameColumnChangeSize = 
newCapture();
+    Capture<DBAccessor.DBColumnInfo> extensionExtensionVersionColumnChangeSize 
= newCapture();
+    Capture<DBAccessor.DBColumnInfo> usersUserTypeColumnChangeSize = 
newCapture();
+    Capture<DBAccessor.DBColumnInfo> usersUserNameColumnChangeSize = 
newCapture();
+    Capture<DBAccessor.DBColumnInfo> hostRoleCommandRoleColumnChangeSize = 
newCapture();
+    Capture<DBAccessor.DBColumnInfo> hostRoleCommandStatusColumnChangeSize = 
newCapture();
+    Capture<DBAccessor.DBColumnInfo> blueprintBlueprintNameColumnChangeSize = 
newCapture();
+
+
+    
expect(configuration.getDatabaseType()).andReturn(Configuration.DatabaseType.MYSQL).once();
+
+    dbAccessor.alterColumn(eq(UpgradeCatalog242.EXTENSION_TABLE), 
capture(extensionExtensionNameColumnChangeSize));
+    dbAccessor.alterColumn(eq(UpgradeCatalog242.EXTENSION_TABLE), 
capture(extensionExtensionVersionColumnChangeSize));
+
+    dbAccessor.alterColumn(eq(UpgradeCatalog242.USERS_TABLE), 
capture(usersUserTypeColumnChangeSize));
+    dbAccessor.alterColumn(eq(UpgradeCatalog242.USERS_TABLE), 
capture(usersUserNameColumnChangeSize));
+
+    dbAccessor.alterColumn(eq(UpgradeCatalog242.HOST_ROLE_COMMAND_TABLE), 
capture(hostRoleCommandRoleColumnChangeSize));
+    dbAccessor.alterColumn(eq(UpgradeCatalog242.HOST_ROLE_COMMAND_TABLE), 
capture(hostRoleCommandStatusColumnChangeSize));
+
+    dbAccessor.alterColumn(eq(UpgradeCatalog242.BLUEPRINT_TABLE), 
capture(blueprintBlueprintNameColumnChangeSize));
+
+
+    replay(dbAccessor, configuration);
+    Module module = new Module() {
+      @Override
+      public void configure(Binder binder) {
+        binder.bind(DBAccessor.class).toInstance(dbAccessor);
+        binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+        binder.bind(EntityManager.class).toInstance(entityManager);
+        binder.bind(Configuration.class).toInstance(configuration);
+      }
+    };
+
+    Injector injector = Guice.createInjector(module);
+    UpgradeCatalog242 upgradeCatalog242 = 
injector.getInstance(UpgradeCatalog242.class);
+    upgradeCatalog242.executeDDLUpdates();
+
+    DBAccessor.DBColumnInfo extensionExtensionNameInfo = 
extensionExtensionNameColumnChangeSize.getValue();
+    Assert.assertNotNull(extensionExtensionNameInfo);
+    Assert.assertEquals(UpgradeCatalog242.EXTENSION_NAME_COLUMN, 
extensionExtensionNameInfo.getName());
+    Assert.assertEquals(new Integer(100), 
extensionExtensionNameInfo.getLength());
+    Assert.assertEquals(String.class, extensionExtensionNameInfo.getType());
+    Assert.assertEquals(null, extensionExtensionNameInfo.getDefaultValue());
+    Assert.assertEquals(false, extensionExtensionNameInfo.isNullable());
+
+    DBAccessor.DBColumnInfo extensionExtensionVersionInfo = 
extensionExtensionVersionColumnChangeSize.getValue();
+    Assert.assertNotNull(extensionExtensionVersionInfo);
+    Assert.assertEquals(UpgradeCatalog242.EXTENSION_VERSION_COLUMN, 
extensionExtensionVersionInfo.getName());
+    Assert.assertEquals(new Integer(100), 
extensionExtensionVersionInfo.getLength());
+    Assert.assertEquals(String.class, extensionExtensionVersionInfo.getType());
+    Assert.assertEquals(null, extensionExtensionVersionInfo.getDefaultValue());
+    Assert.assertEquals(false, extensionExtensionVersionInfo.isNullable());
+
+    DBAccessor.DBColumnInfo usersUserTypeInfo = 
usersUserTypeColumnChangeSize.getValue();
+    Assert.assertNotNull(usersUserTypeInfo);
+    Assert.assertEquals(UpgradeCatalog242.USER_TYPE_COLUMN, 
usersUserTypeInfo.getName());
+    Assert.assertEquals(new Integer(100), usersUserTypeInfo.getLength());
+    Assert.assertEquals(String.class, usersUserTypeInfo.getType());
+    Assert.assertEquals(null, usersUserTypeInfo.getDefaultValue());
+    Assert.assertEquals(false, usersUserTypeInfo.isNullable());
+
+    DBAccessor.DBColumnInfo usersUserNameInfo = 
usersUserNameColumnChangeSize.getValue();
+    Assert.assertNotNull(usersUserNameInfo);
+    Assert.assertEquals(UpgradeCatalog242.USER_NAME_COLUMN, 
usersUserNameInfo.getName());
+    Assert.assertEquals(new Integer(100), usersUserNameInfo.getLength());
+    Assert.assertEquals(String.class, usersUserNameInfo.getType());
+    Assert.assertEquals(null, usersUserNameInfo.getDefaultValue());
+    Assert.assertEquals(false, usersUserNameInfo.isNullable());
+
+    DBAccessor.DBColumnInfo hostRoleCommandRoleInfo = 
hostRoleCommandRoleColumnChangeSize.getValue();
+    Assert.assertNotNull(hostRoleCommandRoleInfo);
+    Assert.assertEquals(UpgradeCatalog242.ROLE_COLUMN, 
hostRoleCommandRoleInfo.getName());
+    Assert.assertEquals(new Integer(100), hostRoleCommandRoleInfo.getLength());
+    Assert.assertEquals(String.class, hostRoleCommandRoleInfo.getType());
+    Assert.assertEquals(null, hostRoleCommandRoleInfo.getDefaultValue());
+    Assert.assertEquals(true, hostRoleCommandRoleInfo.isNullable());
+
+    DBAccessor.DBColumnInfo hostRoleCommandStatusInfo = 
hostRoleCommandStatusColumnChangeSize.getValue();
+    Assert.assertNotNull(hostRoleCommandStatusInfo);
+    Assert.assertEquals(UpgradeCatalog242.STATUS_COLUMN, 
hostRoleCommandStatusInfo.getName());
+    Assert.assertEquals(new Integer(100), 
hostRoleCommandStatusInfo.getLength());
+    Assert.assertEquals(String.class, hostRoleCommandStatusInfo.getType());
+    Assert.assertEquals(null, hostRoleCommandStatusInfo.getDefaultValue());
+    Assert.assertEquals(true, hostRoleCommandStatusInfo.isNullable());
+
+    DBAccessor.DBColumnInfo blueprintBlueprintNameInfo = 
blueprintBlueprintNameColumnChangeSize.getValue();
+    Assert.assertNotNull(blueprintBlueprintNameInfo);
+    Assert.assertEquals(UpgradeCatalog242.BLUEPRINT_NAME_COLUMN, 
blueprintBlueprintNameInfo.getName());
+    Assert.assertEquals(new Integer(100), 
blueprintBlueprintNameInfo.getLength());
+    Assert.assertEquals(String.class, blueprintBlueprintNameInfo.getType());
+    Assert.assertEquals(null, blueprintBlueprintNameInfo.getDefaultValue());
+    Assert.assertEquals(false, blueprintBlueprintNameInfo.isNullable());
+
+
+    verify(dbAccessor, configuration);
+  }
+
+  @Test
+  public void testExecuteDMLUpdates() throws Exception {
+    Method addNewConfigurationsFromXml = 
AbstractUpgradeCatalog.class.getDeclaredMethod("addNewConfigurationsFromXml");
+
+
+    UpgradeCatalog242 upgradeCatalog242 = 
createMockBuilder(UpgradeCatalog242.class)
+            .addMockedMethod(addNewConfigurationsFromXml)
+            .createMock();
+
+
+    upgradeCatalog242.addNewConfigurationsFromXml();
+    expectLastCall().once();
+
+
+    replay(upgradeCatalog242);
+
+    upgradeCatalog242.executeDMLUpdates();
+
+    verify(upgradeCatalog242);
+  }
+}

Reply via email to