Repository: ambari Updated Branches: refs/heads/trunk c45b5497e -> cb45ef92a
AMBARI-18341. Need to validate behaviour and show warn message for user after hcat user was removed.(vbrodetskyi) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cb45ef92 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cb45ef92 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cb45ef92 Branch: refs/heads/trunk Commit: cb45ef92a7292115406c47eab6d5c5949621c368 Parents: c45b549 Author: Vitaly Brodetskyi <vbrodets...@hortonworks.com> Authored: Fri Sep 9 14:27:37 2016 +0300 Committer: Vitaly Brodetskyi <vbrodets...@hortonworks.com> Committed: Fri Sep 9 14:27:37 2016 +0300 ---------------------------------------------------------------------- .../server/upgrade/SchemaUpgradeHelper.java | 1 + .../server/upgrade/UpgradeCatalog300.java | 126 +++++++++++++++++++ .../server/upgrade/UpgradeCatalog300Test.java | 54 ++++++++ 3 files changed, 181 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/cb45ef92/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..54ffec5 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 @@ -193,6 +193,7 @@ public class SchemaUpgradeHelper { catalogBinder.addBinding().to(UpgradeCatalog230.class); catalogBinder.addBinding().to(UpgradeCatalog240.class); catalogBinder.addBinding().to(UpgradeCatalog250.class); + catalogBinder.addBinding().to(UpgradeCatalog300.class); catalogBinder.addBinding().to(FinalUpgradeCatalog.class); EventBusSynchronizer.synchronizeAmbariEventPublisher(binder()); http://git-wip-us.apache.org/repos/asf/ambari/blob/cb45ef92/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java new file mode 100644 index 0000000..64c98b7 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java @@ -0,0 +1,126 @@ +/* + * 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 java.util.Map; + +import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.controller.AmbariManagementController; +import org.apache.ambari.server.orm.dao.DaoUtils; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Clusters; +import org.apache.ambari.server.state.Config; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.inject.Inject; +import com.google.inject.Injector; + +public class UpgradeCatalog300 extends AbstractUpgradeCatalog { + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog300.class); + + @Inject + DaoUtils daoUtils; + + // ----- 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 UpgradeCatalog300(Injector injector) { + super(injector); + + daoUtils = injector.getInstance(DaoUtils.class); + } + + // ----- UpgradeCatalog ---------------------------------------------------- + + /** + * {@inheritDoc} + */ + @Override + public String getTargetVersion() { + return "3.0.0"; + } + + // ----- AbstractUpgradeCatalog -------------------------------------------- + + /** + * {@inheritDoc} + */ + @Override + public String getSourceVersion() { + return "2.5.0"; + } + + /** + * {@inheritDoc} + */ + @Override + protected void executeDDLUpdates() throws AmbariException, SQLException { + } + + /** + * {@inheritDoc} + */ + @Override + protected void executePreDMLUpdates() throws AmbariException, SQLException { + } + + /** + * {@inheritDoc} + */ + @Override + protected void executeDMLUpdates() throws AmbariException, SQLException { + addNewConfigurationsFromXml(); + showHcatDeletedUserMessage(); + } + + protected void showHcatDeletedUserMessage() { + AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); + Clusters clusters = ambariManagementController.getClusters(); + if (clusters != null) { + Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); + for (final Cluster cluster : clusterMap.values()) { + Config hiveEnvConfig = cluster.getDesiredConfigByType("hive-env"); + if (hiveEnvConfig != null) { + Map<String, String> hiveEnvProperties = hiveEnvConfig.getProperties(); + String webhcatUser = hiveEnvProperties.get("webhcat_user"); + String hcatUser = hiveEnvProperties.get("hcat_user"); + if (!StringUtils.equals(webhcatUser, hcatUser)) { + System.out.print("WARNING: In hive-env config, webhcat and hcat user are different. In current ambari release (3.0.0), hcat user was removed from stack, so potentially you could have some problems."); + LOG.warn("In hive-env config, webhcat and hcat user are different. In current ambari release (3.0.0), hcat user was removed from stack, so potentially you could have some problems."); + } + } + } + } + + } + + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/cb45ef92/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java new file mode 100644 index 0000000..dcb1fdd --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java @@ -0,0 +1,54 @@ +/* + * 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.createMockBuilder; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + +import java.lang.reflect.Method; + +import org.junit.Test; + +public class UpgradeCatalog300Test { + + @Test + public void testExecuteDMLUpdates() throws Exception { + Method addNewConfigurationsFromXml = AbstractUpgradeCatalog.class.getDeclaredMethod("addNewConfigurationsFromXml"); + Method showHcatDeletedUserMessage = UpgradeCatalog300.class.getDeclaredMethod("showHcatDeletedUserMessage"); + + UpgradeCatalog300 upgradeCatalog300 = createMockBuilder(UpgradeCatalog300.class) + .addMockedMethod(showHcatDeletedUserMessage) + .addMockedMethod(addNewConfigurationsFromXml) + .createMock(); + + + upgradeCatalog300.addNewConfigurationsFromXml(); + upgradeCatalog300.showHcatDeletedUserMessage(); + + + replay(upgradeCatalog300); + + upgradeCatalog300.executeDMLUpdates(); + + verify(upgradeCatalog300); + + + } + +}