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 2016/09/21 13:29:23 UTC
[01/21] ambari git commit: AMBARI-18417. Improve agent logging to add
more relevant message (aonishuk)
Repository: ambari
Updated Branches:
refs/heads/branch-dev-patch-upgrade 79e678653 -> c8edd3c8a
AMBARI-18417. Improve agent logging to add more relevant message (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0c6c1419
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0c6c1419
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0c6c1419
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 0c6c141993740065892a608fc0a7cd5c197d3d85
Parents: d1ac8bd
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Mon Sep 19 18:59:54 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Mon Sep 19 18:59:54 2016 +0300
----------------------------------------------------------------------
ambari-agent/src/main/python/ambari_agent/Controller.py | 4 +++-
ambari-agent/src/main/python/ambari_agent/Hardware.py | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/0c6c1419/ambari-agent/src/main/python/ambari_agent/Controller.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Controller.py b/ambari-agent/src/main/python/ambari_agent/Controller.py
index 7100656..2a4d384 100644
--- a/ambari-agent/src/main/python/ambari_agent/Controller.py
+++ b/ambari-agent/src/main/python/ambari_agent/Controller.py
@@ -232,12 +232,14 @@ class Controller(threading.Thread):
logger.debug("No commands received from %s", self.serverHostname)
else:
"""Only add to the queue if not empty list """
+ logger.info("Adding %s commands. Heartbeat id = %s", len(commands), self.responseId)
self.actionQueue.put(commands)
def addToStatusQueue(self, commands):
if not commands:
logger.debug("No status commands received from %s", self.serverHostname)
else:
+ logger.info("Adding %s status commands. Heartbeat id = %s", len(commands), self.responseId)
if not LiveStatus.SERVICES:
self.updateComponents(commands[0]['clusterName'])
self.recovery_manager.process_status_commands(commands)
@@ -278,7 +280,7 @@ class Controller(threading.Thread):
try:
crt_time = time.time()
if crt_time - heartbeat_running_msg_timestamp > int(state_interval):
- logger.info("Heartbeat with server is running...")
+ logger.info("Heartbeat (response id = %s) with server is running...", self.responseId)
heartbeat_running_msg_timestamp = crt_time
send_state = False
http://git-wip-us.apache.org/repos/asf/ambari/blob/0c6c1419/ambari-agent/src/main/python/ambari_agent/Hardware.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Hardware.py b/ambari-agent/src/main/python/ambari_agent/Hardware.py
index 17acdf2..3ab7700 100644
--- a/ambari-agent/src/main/python/ambari_agent/Hardware.py
+++ b/ambari-agent/src/main/python/ambari_agent/Hardware.py
@@ -102,7 +102,7 @@ class Hardware:
@staticmethod
def _chk_mount(mountpoint):
try:
- return call(['test', '-w', mountpoint], sudo=True, timeout=int(Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_DEFAULT)/2)[0] == 0
+ return call(['test', '-w', mountpoint], sudo=True, timeout=int(Hardware.CHECK_REMOTE_MOUNTS_TIMEOUT_DEFAULT)/2, quiet=(not logger.isEnabledFor(logging.DEBUG)))[0] == 0
except ExecuteTimeoutException:
logger.exception("Exception happened while checking mount {0}".format(mountpoint))
return False
[20/21] ambari git commit: AMBARI-18266. Ambari Capacity Scheduler
View fails to launch with 'Read Timeout' error.(Akhil PB via gauravn7)
Posted by nc...@apache.org.
AMBARI-18266. Ambari Capacity Scheduler View fails to launch with 'Read Timeout' error.(Akhil PB via gauravn7)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6038e012
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6038e012
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6038e012
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 6038e0120989111fff2f8703216abffb96c93136
Parents: 0f77413
Author: Gaurav Nagar <gn...@hortonworks.com>
Authored: Wed Sep 21 18:16:22 2016 +0530
Committer: Gaurav Nagar <gn...@hortonworks.com>
Committed: Wed Sep 21 18:16:22 2016 +0530
----------------------------------------------------------------------
.../apache/ambari/view/capacityscheduler/ConfigurationService.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/6038e012/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java b/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java
index a20893a..6784317 100644
--- a/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java
+++ b/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java
@@ -153,7 +153,7 @@ public class ConfigurationService {
LOG.debug("Reading cluster info.");
Response response = null;
try {
- JSONObject configurations = readFromCluster("");
+ JSONObject configurations = readFromCluster("?fields=Clusters/version");
response = Response.ok(configurations).build();
} catch (AmbariHttpException ex) {
LOG.error("Error occurred : ", ex);
[02/21] ambari git commit: AMBARI-18416. Optimize stack manager
initialization for Ambari Server Unit Tests (aonishuk)
Posted by nc...@apache.org.
AMBARI-18416. Optimize stack manager initialization for Ambari Server Unit Tests (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/536bf049
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/536bf049
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/536bf049
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 536bf049a52a3433a2a990286d9e5c3d387c3224
Parents: 0c6c141
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Mon Sep 19 19:14:25 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Mon Sep 19 19:14:25 2016 +0300
----------------------------------------------------------------------
.../ambari/server/stack/StackManager.java | 17 +-
.../server/api/services/AmbariMetaInfoTest.java | 41 +++--
.../AmbariManagementControllerTest.java | 4 +
...ClusterStackVersionResourceProviderTest.java | 1 +
.../server/orm/InMemoryDefaultTestModule.java | 14 +-
.../ambari/server/stack/StackManagerMock.java | 166 +++++++++++++++++++
.../ambari/server/state/UpgradeHelperTest.java | 26 +++
7 files changed, 251 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/536bf049/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
index 6c0d5e4..0e2e0d8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
@@ -99,7 +99,10 @@ public class StackManager {
/**
* Map of stack id to stack info
*/
- private Map<String, StackInfo> stackMap = new HashMap<String, StackInfo>();
+ protected Map<String, StackInfo> stackMap = new HashMap<String, StackInfo>();
+ protected Map<String, ServiceModule> commonServiceModules;
+ protected Map<String, StackModule> stackModules;
+ protected Map<String, ExtensionModule> extensionModules;
/**
* Map of extension id to extension info
@@ -152,11 +155,7 @@ public class StackManager {
stackContext = new StackContext(metaInfoDAO, actionMetadata, osFamily);
extensionMap = new HashMap<String, ExtensionInfo>();
- Map<String, ServiceModule> commonServiceModules = parseCommonServicesDirectory(commonServicesRoot);
- Map<String, StackModule> stackModules = parseStackDirectory(stackRoot);
- LOG.info("About to parse extension directories");
- Map<String, ExtensionModule> extensionModules = null;
- extensionModules = parseExtensionDirectory(extensionRoot);
+ parseDirectories(stackRoot, commonServicesRoot, extensionRoot);
//Read the extension links from the DB
for (StackModule module : stackModules.values()) {
@@ -183,6 +182,12 @@ public class StackManager {
populateDB(stackDao, extensionDao);
}
+ protected void parseDirectories(File stackRoot, File commonServicesRoot, File extensionRoot) throws AmbariException {
+ commonServiceModules = parseCommonServicesDirectory(commonServicesRoot);
+ stackModules = parseStackDirectory(stackRoot);
+ LOG.info("About to parse extension directories");
+ extensionModules = parseExtensionDirectory(extensionRoot);
+ }
private void populateDB(StackDAO stackDao, ExtensionDAO extensionDao) throws AmbariException {
// for every stack read in, ensure that we have a database entry for it;
// don't put try/catch logic around this since a failure here will
http://git-wip-us.apache.org/repos/asf/ambari/blob/536bf049/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
index 5dfc094..4b7826e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
@@ -248,7 +248,7 @@ public class AmbariMetaInfoTest {
// Scenario: user has no internet and does nothing to repos via api
// use the default
String buildDir = tmpFolder.getRoot().getAbsolutePath();
- AmbariMetaInfo ambariMetaInfo = setupTempAmbariMetaInfo(buildDir);
+ setupTempAmbariMetaInfoDirs(buildDir);
// The current stack already has (HDP, 2.1.1, redhat6).
// Deleting the json file referenced by the latestBaseUrl to simulate No
@@ -261,7 +261,7 @@ public class AmbariMetaInfoTest {
FileUtils.deleteQuietly(latestUrlFile);
assertTrue(!latestUrlFile.exists());
}
- ambariMetaInfo.init();
+ AmbariMetaInfo ambariMetaInfo = setupTempAmbariMetaInfoExistingDirs(buildDir);
List<RepositoryInfo> redhat6Repo = ambariMetaInfo.getRepositories(
STACK_NAME_HDP, "2.1.1", "redhat6");
@@ -643,9 +643,9 @@ public class AmbariMetaInfoTest {
stackRoot = new File(ClassLoader.getSystemClassLoader().getResource("stacks").getPath());
version = new File(new File(ClassLoader.getSystemClassLoader().getResource("").getPath()).getParent(), "version");
}
- File stackRootTmp = new File(buildDir + "/ambari-metaInfo"); stackRootTmp.mkdir();
+ File stackRootTmp = getStackRootTmp(buildDir);
+ stackRootTmp.mkdir();
FileUtils.copyDirectory(stackRoot, stackRootTmp);
- AmbariMetaInfo ambariMetaInfo = createAmbariMetaInfo(stackRootTmp, version);
//todo
//ambariMetaInfo.injector = injector;
File f1, f2, f3;
@@ -656,7 +656,7 @@ public class AmbariMetaInfoTest {
f3.createNewFile();
}
- ambariMetaInfo.init();
+ AmbariMetaInfo ambariMetaInfo = createAmbariMetaInfo(stackRootTmp, version);
// Tests the stack is loaded as expected
getServices();
@@ -2044,21 +2044,42 @@ public class AmbariMetaInfoTest {
Assert.assertNotNull(descriptor.getService("HDFS"));
}
+ private File getStackRootTmp(String buildDir) {
+ return new File(buildDir + "/ambari-metaInfo");
+ }
- private TestAmbariMetaInfo setupTempAmbariMetaInfo(String buildDir) throws Exception {
- File stackRootTmp = new File(buildDir + "/ambari-metaInfo");
- File stackRoot = new File("src/test/resources/stacks");
+ private File getVersion() {
File version = new File("src/test/resources/version");
if (System.getProperty("os.name").contains("Windows")) {
- stackRoot = new File(ClassLoader.getSystemClassLoader().getResource("stacks").getPath());
version = new File(new File(ClassLoader.getSystemClassLoader().getResource("").getPath()).getParent(), "version");
}
+ return version;
+ }
+
+ private void setupTempAmbariMetaInfoDirs(String buildDir) throws Exception {
+ File stackRootTmp = getStackRootTmp(buildDir);
+ File stackRoot = new File("src/test/resources/stacks");
+
+ if (System.getProperty("os.name").contains("Windows")) {
+ stackRoot = new File(ClassLoader.getSystemClassLoader().getResource("stacks").getPath());
+ }
+
stackRootTmp.mkdir();
FileUtils.copyDirectory(stackRoot, stackRootTmp);
- TestAmbariMetaInfo ambariMetaInfo = createAmbariMetaInfo(stackRootTmp, version);
+ }
+
+ private TestAmbariMetaInfo setupTempAmbariMetaInfo(String buildDir) throws Exception {
+ setupTempAmbariMetaInfoDirs(buildDir);
+ TestAmbariMetaInfo ambariMetaInfo = setupTempAmbariMetaInfoExistingDirs(buildDir);
+ return ambariMetaInfo;
+ }
+ private TestAmbariMetaInfo setupTempAmbariMetaInfoExistingDirs(String buildDir) throws Exception {
+ File version = getVersion();
+ File stackRootTmp = getStackRootTmp(buildDir);
+ TestAmbariMetaInfo ambariMetaInfo = createAmbariMetaInfo(stackRootTmp, version);
return ambariMetaInfo;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/536bf049/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index a33a412..db5adff 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -117,6 +117,7 @@ import org.apache.ambari.server.orm.entities.WidgetLayoutUserWidgetEntity;
import org.apache.ambari.server.security.TestAuthenticationFactory;
import org.apache.ambari.server.security.authorization.AuthorizationException;
import org.apache.ambari.server.serveraction.ServerAction;
+import org.apache.ambari.server.stack.StackManagerMock;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
@@ -233,6 +234,7 @@ public class AmbariManagementControllerTest {
private HostDAO hostDAO;
private TopologyHostInfoDAO topologyHostInfoDAO;
private HostRoleCommandDAO hostRoleCommandDAO;
+ private StackManagerMock stackManagerMock;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -273,6 +275,7 @@ public class AmbariManagementControllerTest {
hostDAO = injector.getInstance(HostDAO.class);
topologyHostInfoDAO = injector.getInstance(TopologyHostInfoDAO.class);
hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
+ stackManagerMock = (StackManagerMock) ambariMetaInfo.getStackManager();
EasyMock.replay(injector.getInstance(AuditLogger.class));
}
@@ -8653,6 +8656,7 @@ public class AmbariManagementControllerTest {
assertTrue(INCORRECT_BASE_URL.equals(repositoryInfo.getBaseUrl()));
}
+ stackManagerMock.invalidateCurrentPaths();
controller.updateStacks();
stackInfo = ambariMetaInfo.getStack(STACK_NAME, STACK_VERSION);
http://git-wip-us.apache.org/repos/asf/ambari/blob/536bf049/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
index dd2feb4..9837b0f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
@@ -1544,6 +1544,7 @@ public class ClusterStackVersionResourceProviderTest {
TopologyManager topologyManager = injector.getInstance(TopologyManager.class);
StageUtils.setTopologyManager(topologyManager);
+ StageUtils.setConfiguration(injector.getInstance(Configuration.class));
// !!! make it look like there is already a versioned installed that is less than the one being installed
http://git-wip-us.apache.org/repos/asf/ambari/blob/536bf049/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
index e327a04..7f5842f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
@@ -23,10 +23,14 @@ import java.util.Collections;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
-
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.util.Modules;
import org.apache.ambari.server.audit.AuditLogger;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.ControllerModule;
+import org.apache.ambari.server.stack.StackManager;
+import org.apache.ambari.server.stack.StackManagerFactory;
+import org.apache.ambari.server.stack.StackManagerMock;
import org.easymock.EasyMock;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -92,7 +96,13 @@ public class InMemoryDefaultTestModule extends AbstractModule {
}
try {
- install(new BeanDefinitionsCachingTestControllerModule(properties));
+ install(Modules.override(new BeanDefinitionsCachingTestControllerModule(properties)).with(new AbstractModule() {
+ @Override
+ protected void configure() {
+ // Cache parsed stacks.
+ install(new FactoryModuleBuilder().implement(StackManager.class, StackManagerMock.class).build(StackManagerFactory.class));
+ }
+ }));
AuditLogger al = EasyMock.createNiceMock(AuditLogger.class);
EasyMock.expect(al.isEnabled()).andReturn(false).anyTimes();
bind(AuditLogger.class).toInstance(al);
http://git-wip-us.apache.org/repos/asf/ambari/blob/536bf049/ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.java b/ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.java
new file mode 100644
index 0000000..1b9e15f
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.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.stack;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import javax.annotation.Nullable;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.metadata.ActionMetadata;
+import org.apache.ambari.server.orm.dao.ExtensionDAO;
+import org.apache.ambari.server.orm.dao.ExtensionLinkDAO;
+import org.apache.ambari.server.orm.dao.MetainfoDAO;
+import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.state.StackInfo;
+import org.apache.ambari.server.state.stack.OsFamily;
+
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+
+/**
+ * Directory tree rescans and stack modules parsing take much time on every module init.
+ * This class enhances {@code}StackManager{@code} to reuse already parsed modules.
+ */
+public class StackManagerMock extends StackManager {
+
+ // Ensure correct behavior during the parallel test execution.
+ private static final Lock lock = new ReentrantLock();
+
+ // Some tests use different stack locations.
+ private static final Map<ModulesPathsKey, CachedModules> pathsToCachedModulesMap = new HashMap<>();
+
+ public static void invalidateKey(File stackRoot, File commonServicesRoot, File extensionRoot) {
+ ModulesPathsKey pathsKey = new ModulesPathsKey(stackRoot, commonServicesRoot, extensionRoot);
+ pathsToCachedModulesMap.remove(pathsKey);
+ }
+
+ // Paths for this instance.
+ private File currentStackRoot;
+ private File currentCommonServicesRoot;
+ private File currentExtensionRoot;
+
+ public void invalidateCurrentPaths() {
+ invalidateKey(currentStackRoot, currentCommonServicesRoot, currentExtensionRoot);
+ }
+
+ private static class ModulesPathsKey {
+ private String stackRoot;
+ private String commonServicesRoot;
+ private String extensionRoot;
+
+ public ModulesPathsKey(File stackRoot, File commonServicesRoot, File extensionRoot) {
+ this.stackRoot = stackRoot == null ? "" : stackRoot.getPath();
+ this.commonServicesRoot = commonServicesRoot == null ? "" : commonServicesRoot.getPath();
+ this.extensionRoot = extensionRoot == null ? "" : extensionRoot.getPath();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ModulesPathsKey that = (ModulesPathsKey) o;
+
+ if (stackRoot != null ? !stackRoot.equals(that.stackRoot) : that.stackRoot != null) return false;
+ if (commonServicesRoot != null ? !commonServicesRoot.equals(that.commonServicesRoot) : that.commonServicesRoot != null)
+ return false;
+ return !(extensionRoot != null ? !extensionRoot.equals(that.extensionRoot) : that.extensionRoot != null);
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result = stackRoot != null ? stackRoot.hashCode() : 0;
+ result = 31 * result + (commonServicesRoot != null ? commonServicesRoot.hashCode() : 0);
+ result = 31 * result + (extensionRoot != null ? extensionRoot.hashCode() : 0);
+ return result;
+ }
+ }
+
+ private static class CachedModules {
+ private Map<String, ServiceModule> cachedCommonServiceModules;
+ private Map<String, StackModule> cachedStackModules;
+ private Map<String, ExtensionModule> cachedExtensionModules;
+ private Map<String, StackInfo> cachedStackMap;
+
+ public CachedModules(Map<String, ServiceModule> cachedCommonServiceModules, Map<String, StackModule> cachedStackModules,
+ Map<String, ExtensionModule> cachedExtensionModules, Map<String, StackInfo> cachedStackMap) {
+ this.cachedCommonServiceModules = cachedCommonServiceModules;
+ this.cachedStackModules = cachedStackModules;
+ this.cachedExtensionModules = cachedExtensionModules;
+ this.cachedStackMap = cachedStackMap;
+ }
+
+ public Map<String, ServiceModule> getCachedCommonServiceModules() {
+ return cachedCommonServiceModules;
+ }
+
+ public Map<String, StackModule> getCachedStackModules() {
+ return cachedStackModules;
+ }
+
+ public Map<String, ExtensionModule> getCachedExtensionModules() {
+ return cachedExtensionModules;
+ }
+
+ public Map<String, StackInfo> getCachedStackMap() {
+ return cachedStackMap;
+ }
+ }
+
+ @Inject
+ public StackManagerMock(@Assisted("stackRoot") File stackRoot, @Nullable @Assisted("commonServicesRoot")
+ File commonServicesRoot, @Assisted("extensionRoot") @Nullable File extensionRoot,
+ @Assisted OsFamily osFamily, @Assisted boolean validate, MetainfoDAO metaInfoDAO,
+ ActionMetadata actionMetadata, StackDAO stackDao, ExtensionDAO extensionDao,
+ ExtensionLinkDAO linkDao) throws AmbariException {
+ super(stackRoot, commonServicesRoot, extensionRoot, osFamily, validate, metaInfoDAO, actionMetadata, stackDao, extensionDao, linkDao);
+ currentStackRoot = stackRoot;
+ currentCommonServicesRoot = commonServicesRoot;
+ currentExtensionRoot = extensionRoot;
+ }
+
+ @Override
+ protected void parseDirectories(File stackRoot, File commonServicesRoot, File extensionRoot) throws AmbariException {
+ try {
+ // Ensure correct behavior during the parallel test execution.
+ lock.lock();
+
+ ModulesPathsKey pathsKey = new ModulesPathsKey(stackRoot, commonServicesRoot, extensionRoot);
+ CachedModules cachedModules = pathsToCachedModulesMap.get(pathsKey);
+
+ if (cachedModules == null) {
+ super.parseDirectories(stackRoot, commonServicesRoot, extensionRoot);
+ CachedModules newEntry = new CachedModules(commonServiceModules, stackModules, extensionModules, stackMap);
+ pathsToCachedModulesMap.put(pathsKey, newEntry);
+ } else {
+ commonServiceModules = cachedModules.getCachedCommonServiceModules();
+ stackModules = cachedModules.getCachedStackModules();
+ extensionModules = cachedModules.getCachedExtensionModules();
+ stackMap = cachedModules.getCachedStackMap();
+ }
+ } finally {
+ lock.unlock();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/536bf049/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
index 34bac2a..c2e1f75 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
@@ -48,6 +48,7 @@ import org.apache.ambari.server.security.TestAuthenticationFactory;
import org.apache.ambari.server.security.authorization.AuthorizationException;
import org.apache.ambari.server.stack.HostsType;
import org.apache.ambari.server.stack.MasterHostResolver;
+import org.apache.ambari.server.stack.StackManagerMock;
import org.apache.ambari.server.state.UpgradeHelper.UpgradeGroupHolder;
import org.apache.ambari.server.state.stack.ConfigUpgradePack;
import org.apache.ambari.server.state.stack.UpgradePack;
@@ -92,6 +93,7 @@ public class UpgradeHelperTest {
private Injector injector;
private AmbariMetaInfo ambariMetaInfo;
+ private StackManagerMock stackManagerMock;
private OrmTestHelper helper;
private MasterHostResolver m_masterHostResolver;
private UpgradeHelper m_upgradeHelper;
@@ -134,6 +136,7 @@ public class UpgradeHelperTest {
helper = injector.getInstance(OrmTestHelper.class);
ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+ stackManagerMock = (StackManagerMock) ambariMetaInfo.getStackManager();
m_upgradeHelper = injector.getInstance(UpgradeHelper.class);
m_masterHostResolver = EasyMock.createMock(MasterHostResolver.class);
m_managementController = injector.getInstance(AmbariManagementController.class);
@@ -242,6 +245,10 @@ public class UpgradeHelperTest {
assertEquals(6, groups.get(1).items.size());
assertEquals(9, groups.get(2).items.size());
assertEquals(8, groups.get(3).items.size());
+
+ // Do stacks cleanup
+ stackManagerMock.invalidateCurrentPaths();
+ ambariMetaInfo.init();
}
@Test
@@ -295,6 +302,10 @@ public class UpgradeHelperTest {
assertEquals(3, groups.get(0).items.size());
assertEquals(7, groups.get(1).items.size());
assertEquals(2, groups.get(2).items.size());
+
+ // Do stacks cleanup
+ stackManagerMock.invalidateCurrentPaths();
+ ambariMetaInfo.init();
}
@Test
@@ -349,6 +360,10 @@ public class UpgradeHelperTest {
assertEquals(3, groups.get(0).items.size());
assertEquals(6, groups.get(1).items.size());
assertEquals(1, groups.get(2).items.size());
+
+ // Do stacks cleanup
+ stackManagerMock.invalidateCurrentPaths();
+ ambariMetaInfo.init();
}
@Test
@@ -383,6 +398,9 @@ public class UpgradeHelperTest {
assertEquals("Calculating Properties", stageWrappers.get(4).getText());
assertEquals("Calculating HDFS Properties", stageWrappers.get(5).getText());
+ // Do stacks cleanup
+ stackManagerMock.invalidateCurrentPaths();
+ ambariMetaInfo.init();
}
/**
@@ -427,6 +445,10 @@ public class UpgradeHelperTest {
assertFalse(hosts.contains(hostInMaintenanceMode.getHostName()));
}
}
+
+ // Do stacks cleanup
+ stackManagerMock.invalidateCurrentPaths();
+ ambariMetaInfo.init();
}
/**
@@ -1156,6 +1178,10 @@ public class UpgradeHelperTest {
assertEquals(5, groups.get(1).items.size());
assertEquals(9, groups.get(2).items.size());
assertEquals(8, groups.get(3).items.size());
+
+ // Do stacks cleanup
+ stackManagerMock.invalidateCurrentPaths();
+ ambariMetaInfo.init();
}
[09/21] ambari git commit: AMBARI-18420. Analyze and Optimize Ambari
Server Unit Tests - Group 6.(vbrodetskyi)
Posted by nc...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index afcc90e..bf58967 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
@@ -65,6 +65,7 @@ import org.apache.ambari.server.state.configgroup.ConfigGroup;
import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -90,6 +91,8 @@ public class ServiceComponentHostTest {
private static OrmTestHelper helper;
private static ClusterDAO clusterDAO;
private static HostDAO hostDAO;
+ private static HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
+ private static HostComponentStateDAO hostComponentStateDAO;
private String clusterName = "c1";
private String hostName1 = "h1";
@@ -108,11 +111,13 @@ public class ServiceComponentHostTest {
helper = injector.getInstance(OrmTestHelper.class);
clusterDAO = injector.getInstance(ClusterDAO.class);
hostDAO = injector.getInstance(HostDAO.class);
+ hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class);
+ hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
}
@Before
public void setup() throws Exception {
-
+ cleanup();
if (clusters.getClusters().size() == 0) {
StackId stackId = new StackId("HDP-0.1");
@@ -136,11 +141,15 @@ public class ServiceComponentHostTest {
cleanup();
}
+ @AfterClass
+ public static void afterClass() throws Exception {
+ injector.getInstance(PersistService.class).stop();
+ }
+
private void cleanup() throws AmbariException {
try {
Map<String, Cluster> clusterMap = clusters.getClusters();
- HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class);
List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
if (hostComponentDesiredStateEntities != null) {
for (HostComponentDesiredStateEntity hcdse : hostComponentDesiredStateEntities) {
@@ -148,7 +157,6 @@ public class ServiceComponentHostTest {
}
}
- HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
List<HostComponentStateEntity> hostComponentStateEntities = hostComponentStateDAO.findAll();
if (hostComponentStateEntities != null) {
for (HostComponentStateEntity hcse : hostComponentStateEntities) {
@@ -163,6 +171,10 @@ public class ServiceComponentHostTest {
for (Host host : clusters.getHosts()) {
clusters.deleteHost(host.getHostName());
}
+
+ for (String clusterName : clusterMap.keySet()) {
+ clusters.deleteCluster(clusterName);
+ }
} catch (IllegalStateException ise) {}
}
@@ -955,9 +967,6 @@ public class ServiceComponentHostTest {
tags.remove(id.toString());
sch3.updateActualConfigs(actual);
Assert.assertFalse(sch3.convertToResponse(null).isStaleConfig());
-
- injector.getInstance(PersistService.class).stop();
- classSetUp();
}
@Test
@@ -1076,8 +1085,6 @@ public class ServiceComponentHostTest {
Assert.assertTrue(sch2.convertToResponse(null).isStaleConfig());
Assert.assertFalse(sch3.convertToResponse(null).isStaleConfig());
- injector.getInstance(PersistService.class).stop();
- classSetUp();
}
/**
@@ -1126,15 +1133,14 @@ public class ServiceComponentHostTest {
pk.setServiceName(sch1.getServiceName());
pk.setHostId(hostEntity.getHostId());
- HostComponentDesiredStateDAO dao = injector.getInstance(HostComponentDesiredStateDAO.class);
- HostComponentDesiredStateEntity entity = dao.findByPK(pk);
+ HostComponentDesiredStateEntity entity = hostComponentDesiredStateDAO.findByPK(pk);
Assert.assertEquals(MaintenanceState.OFF, entity.getMaintenanceState());
Assert.assertEquals(MaintenanceState.OFF, sch1.getMaintenanceState());
sch1.setMaintenanceState(MaintenanceState.ON);
Assert.assertEquals(MaintenanceState.ON, sch1.getMaintenanceState());
- entity = dao.findByPK(pk);
+ entity = hostComponentDesiredStateDAO.findByPK(pk);
Assert.assertEquals(MaintenanceState.ON, entity.getMaintenanceState());
}
@@ -1160,7 +1166,6 @@ public class ServiceComponentHostTest {
HostEntity hostEntity = hostDAO.findByName(hostName);
ServiceComponentHost sch1 = createNewServiceComponentHost(cluster, "HDFS", "NAMENODE", hostName);
- HostComponentDesiredStateDAO daoHostComponentDesiredState = injector.getInstance(HostComponentDesiredStateDAO.class);
HostComponentDesiredStateEntity entityHostComponentDesiredState;
HostComponentDesiredStateEntityPK pkHostComponentDesiredState = new HostComponentDesiredStateEntityPK();
pkHostComponentDesiredState.setClusterId(cluster.getClusterId());
@@ -1168,12 +1173,11 @@ public class ServiceComponentHostTest {
pkHostComponentDesiredState.setServiceName(sch1.getServiceName());
pkHostComponentDesiredState.setHostId(hostEntity.getHostId());
- HostComponentStateDAO daoHostComponentState = injector.getInstance(HostComponentStateDAO.class);
HostComponentStateEntity entityHostComponentState;
for(SecurityState state: SecurityState.values()) {
sch1.setSecurityState(state);
- entityHostComponentState = daoHostComponentState.findByIndex(cluster.getClusterId(),
+ entityHostComponentState = hostComponentStateDAO.findByIndex(cluster.getClusterId(),
sch1.getServiceName(), sch1.getServiceComponentName(), hostEntity.getHostId());
Assert.assertNotNull(entityHostComponentState);
@@ -1182,7 +1186,7 @@ public class ServiceComponentHostTest {
try {
sch1.setDesiredSecurityState(state);
Assert.assertTrue(state.isEndpoint());
- entityHostComponentDesiredState = daoHostComponentDesiredState.findByPK(pkHostComponentDesiredState);
+ entityHostComponentDesiredState = hostComponentDesiredStateDAO.findByPK(pkHostComponentDesiredState);
Assert.assertNotNull(entityHostComponentDesiredState);
Assert.assertEquals(state, entityHostComponentDesiredState.getSecurityState());
} catch (AmbariException e) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
index 50ba3ef..e151d73 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
@@ -89,6 +89,7 @@ import org.easymock.Capture;
import org.easymock.CaptureType;
import org.easymock.EasyMockSupport;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -100,6 +101,7 @@ 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.UpgradeCatalog210} unit tests.
@@ -138,6 +140,11 @@ public class UpgradeCatalog210Test {
}
+ @AfterClass
+ public static void afterClass() throws Exception {
+ injector.getInstance(PersistService.class).stop();
+ }
+
@Test
public void testExecuteDDLUpdates() throws Exception {
final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
[16/21] ambari git commit: AMBARI-18418. StackServiceDirectory debug
messages are logged with placeholders. (Attila Doroszlai via stoader)
Posted by nc...@apache.org.
AMBARI-18418. StackServiceDirectory debug messages are logged with placeholders. (Attila Doroszlai via stoader)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/159546ad
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/159546ad
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/159546ad
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 159546ad988f5ff3eab26256bcb36cc660d8a839
Parents: e2e8c13
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Wed Sep 21 10:09:50 2016 +0200
Committer: Toader, Sebastian <st...@hortonworks.com>
Committed: Wed Sep 21 10:09:50 2016 +0200
----------------------------------------------------------------------
.../ambari/server/stack/StackServiceDirectory.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/159546ad/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java
index a8b4632..8656896 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java
@@ -148,15 +148,15 @@ public class StackServiceDirectory extends ServiceDirectory {
int fileCount = files.length;
if (fileCount > 0) {
packageDir = absPackageDir.getPath().substring(stackDir.getParentFile().getParentFile().getPath().length() + 1);
- LOG.debug("Service package folder for service %s for stack %s has been resolved to %s",
+ LOG.debug("Service package folder for service {} for stack {} has been resolved to {}",
serviceDir.getName(), stackId, packageDir);
}
else {
- LOG.debug("Service package folder %s for service %s for stack %s is empty.",
+ LOG.debug("Service package folder {} for service {} for stack {} is empty.",
absPackageDir, serviceDir.getName(), stackId);
}
} else {
- LOG.debug("Service package folder %s for service %s for stack %s does not exist.",
+ LOG.debug("Service package folder {} for service {} for stack {} does not exist.",
absPackageDir, serviceDir.getName(), stackId);
}
@@ -166,15 +166,15 @@ public class StackServiceDirectory extends ServiceDirectory {
int fileCount = files.length;
if (fileCount > 0) {
upgradesDir = absUpgradesDir;
- LOG.debug("Service upgrades folder for service %s for stack %s has been resolved to %s",
+ LOG.debug("Service upgrades folder for service {} for stack {} has been resolved to {}",
serviceDir.getName(), stackId, packageDir);
}
else {
- LOG.debug("Service upgrades folder %s for service %s for stack %s is empty.",
+ LOG.debug("Service upgrades folder {} for service {} for stack {} is empty.",
absUpgradesDir, serviceDir.getName(), stackId);
}
} else {
- LOG.debug("Service upgrades folder %s for service %s for stack %s does not exist.",
+ LOG.debug("Service upgrades folder {} for service {} for stack {} does not exist.",
absUpgradesDir, serviceDir.getName(), stackId);
}
}
[03/21] ambari git commit: AMBARI-18360. ambari-agent check for unset
variables (AMBARI-18317) (aonishuk)
Posted by nc...@apache.org.
AMBARI-18360. ambari-agent check for unset variables (AMBARI-18317) (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/468764ea
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/468764ea
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/468764ea
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 468764ea289092f95d013a84496605a3a8fc10dc
Parents: 536bf04
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Mon Sep 19 19:40:19 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Mon Sep 19 19:40:19 2016 +0300
----------------------------------------------------------------------
ambari-agent/conf/unix/ambari-agent | 36 ++++++++++++++++----------------
ambari-server/sbin/ambari-server | 16 +++++++-------
2 files changed, 27 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/468764ea/ambari-agent/conf/unix/ambari-agent
----------------------------------------------------------------------
diff --git a/ambari-agent/conf/unix/ambari-agent b/ambari-agent/conf/unix/ambari-agent
index 978e5c6..ccb0b7a 100755
--- a/ambari-agent/conf/unix/ambari-agent
+++ b/ambari-agent/conf/unix/ambari-agent
@@ -18,11 +18,11 @@
# processname: ambari-agent
# /etc/init.d/ambari-agent
-
+set -u # fail on unset variables
VERSION="${ambariVersion}"
HASH="${buildNumber}"
-case "$1" in
+case "${1:-}" in
--version)
echo -e $VERSION
exit 0
@@ -35,7 +35,7 @@ esac
get_agent_property() {
property_name="$1"
- value=$(awk -F "=" "/$property_name/ {print \$2}" /etc/ambari-agent/conf/ambari-agent.ini)
+ value=$(awk -F "=" "/^$property_name/ {print \$2}" /etc/ambari-agent/conf/ambari-agent.ini)
echo $value
}
@@ -43,7 +43,7 @@ export PATH=/usr/sbin:/sbin:/usr/lib/ambari-server/*:$PATH
export AMBARI_CONF_DIR=/etc/ambari-server/conf:$PATH
# Because Ambari rpm unpacks modules here on all systems
-export PYTHONPATH=/usr/lib/python2.6/site-packages:$PYTHONPATH
+export PYTHONPATH=/usr/lib/python2.6/site-packages:${PYTHONPATH:-}
export AMBARI_PID_DIR=`get_agent_property piddir`
export AMBARI_AGENT_LOG_DIR=`get_agent_property logdir`
@@ -58,8 +58,8 @@ AGENT_SCRIPT=/usr/lib/python2.6/site-packages/ambari_agent/main.py
AGENT_TMP_DIR=/var/lib/ambari-agent/tmp
AGENT_WORKING_DIR=/var/lib/ambari-agent
AMBARI_AGENT_PY_SCRIPT=/usr/lib/python2.6/site-packages/ambari_agent/AmbariAgent.py
-OK=1
-NOTOK=0
+OK=0
+NOTOK=1
current_user=`id -u -n`
current_group=`id -g -n`
@@ -79,22 +79,22 @@ change_files_permissions() {
if [ ! -z "$KEYSDIR" ]; then
ambari-sudo.sh chown -R $current_user "$KEYSDIR"
fi
- ambari-sudo.sh mkdir -p "$AMBARI_PID_DIR"
- ambari-sudo.sh chown -R $current_user "$AMBARI_PID_DIR/"
- ambari-sudo.sh mkdir -p "$AMBARI_AGENT_LOG_DIR"
- ambari-sudo.sh chown -R $current_user:$current_group "$AMBARI_AGENT_LOG_DIR/"
+ ambari-sudo.sh mkdir -p "${AMBARI_PID_DIR:?}"
+ ambari-sudo.sh chown -R $current_user "${AMBARI_PID_DIR:?}/"
+ ambari-sudo.sh mkdir -p "${AMBARI_AGENT_LOG_DIR:?}"
+ ambari-sudo.sh chown -R $current_user:$current_group "${AMBARI_AGENT_LOG_DIR:?}/"
ambari-sudo.sh chown -R $current_user "/var/lib/ambari-agent/data/"
ambari-sudo.sh chown -R $current_user "/var/lib/ambari-agent/cache/"
ambari-sudo.sh chown $current_user "/usr/lib/ambari-agent/"
}
-if [ -z "$PYTHON" ] ; then
+if [ -z "${PYTHON:-}" ] ; then
export PYTHON=`readlink $PYTHON_WRAP`
fi
# Trying to read the passphrase from an environment
-if [ ! -z $AMBARI_PASSPHRASE ]; then
+if [ ! -z ${AMBARI_PASSPHRASE:-} ]; then
RESOLVED_AMBARI_PASSPHRASE=$AMBARI_PASSPHRASE
fi
@@ -108,14 +108,14 @@ if [ ! -z $AMBARI_AGENT_LOG_DIR ]; then
LOGFILE=$AMBARI_AGENT_LOG_DIR/ambari-agent.log
fi
-if [ ! -z $AMBARI_AGENT_OUT_DIR ]; then
+if [ ! -z ${AMBARI_AGENT_OUT_DIR:-} ]; then
OUTFILE=$AMBARI_AGENT_OUT_DIR/ambari-agent.out
fi
-if [ -z $RESOLVED_AMBARI_PASSPHRASE ] && [ ! -z $AMBARI_PASSPHRASE ]; then
- RESOLVED_AMBARI_PASSPHRASE=$AMBARI_PASSPHRASE
+if [ -z ${RESOLVED_AMBARI_PASSPHRASE:-} ] && [ ! -z ${AMBARI_PASSPHRASE:-} ]; then
+ RESOLVED_AMBARI_PASSPHRASE=${AMBARI_PASSPHRASE:-}
# If the passphrase is not defined yet, use the value from the env file
-elif [ -z $RESOLVED_AMBARI_PASSPHRASE ]; then
+elif [ -z ${RESOLVED_AMBARI_PASSPHRASE:-} ]; then
# Passphrase is not defined anywhere, set the default value
RESOLVED_AMBARI_PASSPHRASE="DEV"
fi
@@ -141,7 +141,7 @@ check_python_version ()
retcode=0
-case "$1" in
+case "${1:-}" in
start)
check_python_version
if [ "$?" -eq "$NOTOK" ]; then
@@ -165,7 +165,7 @@ case "$1" in
echo "Starting ambari-agent"
- if [ "$AMBARI_AGENT_RUN_IN_FOREGROUND" == true ] ; then
+ if [ "${AMBARI_AGENT_RUN_IN_FOREGROUND:-}" == true ] ; then
$PYTHON $AMBARI_AGENT_PY_SCRIPT "$@" > $OUTFILE 2>&1
exit $?
fi
http://git-wip-us.apache.org/repos/asf/ambari/blob/468764ea/ambari-server/sbin/ambari-server
----------------------------------------------------------------------
diff --git a/ambari-server/sbin/ambari-server b/ambari-server/sbin/ambari-server
index f52a598..762ae19 100755
--- a/ambari-server/sbin/ambari-server
+++ b/ambari-server/sbin/ambari-server
@@ -28,11 +28,11 @@
### END INIT INFO
# /etc/init.d/ambari-server
-
+set -u # fail on unset variables
VERSION="${ambariFullVersion}"
HASH="${buildNumber}"
-case "$1" in
+case "${1:-}" in
--version)
echo -e $VERSION
exit 0
@@ -62,19 +62,21 @@ if [ "$?" != "0" ] && [ "$EUID" -ne 0 ] ; then
exit -1
fi
-if [ -z "$PYTHON" ] ; then
+if [ -z "${PYTHON:-}" ] ; then
export PYTHON=`readlink $PYTHON_WRAP`
fi
if [ -a "$AMBARI_ENV" ]; then
+ set +u # temporary disable variables checking for env
. "$AMBARI_ENV"
+ set -u
fi
-if [ -z "$AMBARI_PASSPHRASE" ]; then
+if [ -z "${AMBARI_PASSPHRASE:-}" ]; then
AMBARI_PASSPHRASE="DEV"
fi
-if [ -n "$JAVA_HOME" ]; then
+if [ -n "${JAVA_HOME:-}" ]; then
export JAVA_HOME=$JAVA_HOME
fi
@@ -91,7 +93,7 @@ fi
echo "Using python " $PYTHON
ret=0
-case "$1" in
+case "${1:-}" in
start)
echo -e "Starting ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
@@ -186,7 +188,7 @@ case "$1" in
;;
*)
echo "Usage: $AMBARI_EXECUTABLE
- {start|stop|restart|setup|setup-jce|upgrade|status|upgradestack|setup-ldap|sync-ldap|set-current|setup-security|setup-sso|refresh-stack-hash|backup|restore|update-host-names|enable-stack|check-database|db-cleanup|install-mpack|upgrade-mpack} [options]
+ {start|stop|reset|restart|upgrade|status|upgradestack|setup|setup-jce|setup-ldap|sync-ldap|set-current|setup-security|refresh-stack-hash|backup|restore|update-host-names|check-database|enable-stack|setup-sso|db-cleanup|install-mpack|upgrade-mpack} [options]
Use $AMBARI_PYTHON_EXECUTABLE <action> --help to get details on options available.
Or, simply invoke ambari-server.py --help to print the options."
exit 1
[15/21] ambari git commit: AMBARI-15059 - UI for user home directory
creation fix1 (rzang)
Posted by nc...@apache.org.
AMBARI-15059 - UI for user home directory creation fix1 (rzang)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e2e8c138
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e2e8c138
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e2e8c138
Branch: refs/heads/branch-dev-patch-upgrade
Commit: e2e8c138649fca25a6c164c51bc439ef19219f43
Parents: 875f1ef
Author: Richard Zang <rz...@apache.org>
Authored: Tue Sep 20 17:21:04 2016 -0700
Committer: Richard Zang <rz...@apache.org>
Committed: Tue Sep 20 17:21:04 2016 -0700
----------------------------------------------------------------------
.../loginActivities/HomeDirectoryCtrl.js | 73 +++++++++++++-------
.../views/loginActivities/homeDirectory.html | 2 +-
2 files changed, 49 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e2e8c138/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/HomeDirectoryCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/HomeDirectoryCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/HomeDirectoryCtrl.js
index 582b68b..42f9367 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/HomeDirectoryCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/HomeDirectoryCtrl.js
@@ -1,31 +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.
- */
-'use strict';
-
-angular.module('ambariAdminConsole')
- .controller('HomeDirectoryCtrl',['$scope', function($scope) {
+ /**
+ * 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.
+ */
+ 'use strict';
+
+ angular.module('ambariAdminConsole')
+ .controller('HomeDirectoryCtrl', ['$scope', '$location', 'UnsavedDialog', function($scope, $location, UnsavedDialog) {
$scope.TEMPLATE_PLACEHOLER = '/user/{{username}}';
-
$scope.autoCreate = false;
$scope.template = '';
$scope.group = '';
$scope.permissions = '';
-
- $scope.save = function () {}
- }]);
+
+ $scope.save = function (targetUrl) {
+ targetUrl ? $location.path(targetUrl) : "";
+ }
+
+ $scope.$on('$locationChangeStart', function(event, __targetUrl) {
+ if( $scope.form.$dirty ){
+ UnsavedDialog().then(function(action) {
+ var targetUrl = __targetUrl.split('#').pop();
+ switch(action){
+ case 'save':
+ $scope.save(targetUrl);
+ $scope.form.$setPristine();
+ break;
+ case 'discard':
+ $scope.form.$setPristine();
+ $location.path(targetUrl);
+ break;
+ case 'cancel':
+ targetUrl = '/homeDirectory';
+ break;
+ }
+ });
+ event.preventDefault();
+ }
+ });
+ }]);
http://git-wip-us.apache.org/repos/asf/ambari/blob/e2e8c138/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/homeDirectory.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/homeDirectory.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/homeDirectory.html
index ee5d860..913bc0f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/homeDirectory.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/homeDirectory.html
@@ -71,7 +71,7 @@
</div>
<button
class="btn btn-primary pull-right"
- ng-click="save()">
+ ng-click="save()" ng-disabled="!(autoCreate && form.$dirty)">
{{'common.controls.save' | translate}}
</button>
</fieldset>
[21/21] ambari git commit: Merge branch 'trunk' into
branch-dev-patch-upgrade
Posted by nc...@apache.org.
Merge branch 'trunk' into branch-dev-patch-upgrade
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c8edd3c8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c8edd3c8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c8edd3c8
Branch: refs/heads/branch-dev-patch-upgrade
Commit: c8edd3c8aa061d7be3a11c76dd79e9e65801a72b
Parents: 79e6786 6038e01
Author: Nate Cole <nc...@hortonworks.com>
Authored: Wed Sep 21 09:29:10 2016 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Wed Sep 21 09:29:10 2016 -0400
----------------------------------------------------------------------
.../ambariViews/CreateViewInstanceCtrl.js | 35 ++-
.../loginActivities/HomeDirectoryCtrl.js | 73 ++++--
.../ui/admin-web/app/scripts/i18n.config.js | 4 +
.../ui/admin-web/app/scripts/routes.js | 5 +
.../admin-web/app/views/ambariViews/create.html | 2 +-
.../app/views/ambariViews/listTable.html | 3 +
.../views/loginActivities/homeDirectory.html | 2 +-
.../ui/admin-web/app/views/users/create.html | 18 +-
.../unit/controllers/CreateViewInstanceCtrl.js | 40 ++++
ambari-agent/conf/unix/ambari-agent | 36 +--
.../src/main/python/ambari_agent/Controller.py | 4 +-
.../src/main/python/ambari_agent/Hardware.py | 2 +-
.../ambari_commons/ambari_metrics_helper.py | 5 +-
.../ambari_commons/parallel_processing.py | 95 ++++++++
ambari-project/pom.xml | 5 +
ambari-server/pom.xml | 9 +-
ambari-server/sbin/ambari-server | 16 +-
.../server/configuration/Configuration.java | 30 ++-
.../server/controller/KerberosHelper.java | 2 +
.../server/controller/KerberosHelperImpl.java | 18 +-
.../server/orm/dao/HostConfigMappingDAO.java | 4 +-
.../server/security/AmbariEntryPoint.java | 15 +-
.../AmbariAuthToLocalUserDetailsService.java | 139 +++++++++++
.../AmbariKerberosAuthenticationFilter.java | 172 ++++++++++++++
.../kerberos/AmbariKerberosTicketValidator.java | 93 ++++++++
.../AbstractPrepareKerberosServerAction.java | 10 +-
.../ConfigureAmbariIdentitiesServerAction.java | 235 +++++++++++++++++++
.../ConfigureAmbariIndetityServerAction.java | 208 ----------------
.../kerberos/CreatePrincipalsServerAction.java | 5 +-
.../kerberos/KerberosServerAction.java | 12 +-
.../ambari/server/stack/StackManager.java | 17 +-
.../server/stack/StackServiceDirectory.java | 12 +-
.../package/scripts/metrics_grafana_util.py | 50 +++-
.../0.1.0/package/scripts/params.py | 3 +
.../0.1.0/package/scripts/service_check.py | 225 ++++++++++--------
.../metrics_grafana_datasource.json.j2 | 2 +-
.../package/alerts/alert_hive_metastore.py | 2 +-
.../stacks/HDP/2.0.6/services/stack_advisor.py | 106 +++++++--
.../webapp/WEB-INF/spring-security.xml | 32 ++-
.../server/agent/TestHeartbeatMonitor.java | 14 +-
.../server/api/services/AmbariMetaInfoTest.java | 41 +++-
.../AmbariManagementControllerTest.java | 4 +
.../server/controller/KerberosHelperTest.java | 6 +-
...ClusterStackVersionResourceProviderTest.java | 1 +
...ThreadPoolExecutorCompletionServiceTest.java | 6 +-
.../server/orm/InMemoryDefaultTestModule.java | 14 +-
.../apache/ambari/server/orm/TestOrmImpl.java | 116 ++++++---
.../server/orm/dao/AlertDispatchDAOTest.java | 235 ++++++++++++-------
...AmbariAuthToLocalUserDetailsServiceTest.java | 92 ++++++++
.../AmbariKerberosAuthenticationFilterTest.java | 133 +++++++++++
.../AmbariKerberosTicketValidatorTest.java | 49 ++++
.../security/authorization/TestUsers.java | 7 +
.../upgrades/ConfigureActionTest.java | 212 ++++++++++-------
.../upgrades/UpgradeActionTest.java | 153 ++++++------
.../ambari/server/stack/StackManagerMock.java | 166 +++++++++++++
.../apache/ambari/server/state/ServiceTest.java | 124 ++++++----
.../ambari/server/state/UpgradeHelperTest.java | 26 ++
.../svccomphost/ServiceComponentHostTest.java | 34 +--
.../server/upgrade/UpgradeCatalog210Test.java | 7 +
.../HAWQ/test_service_advisor.py | 10 +-
.../resourceManager/step3_controller.js | 1 -
.../service/manage_config_groups_controller.js | 36 +++
.../mixins/common/configs/enhanced_configs.js | 24 +-
ambari-web/app/mixins/common/serverValidator.js | 7 +-
.../manage_configuration_groups_popup.hbs | 2 +-
ambari-web/app/utils/ajax/ajax.js | 4 +-
ambari-web/app/utils/blueprint.js | 10 +-
ambari-web/app/utils/config.js | 45 ++--
.../views/common/widget/graph_widget_view.js | 7 +-
ambari-web/brunch-config.js | 125 ++++++++++
ambari-web/config.coffee | 112 ---------
ambari-web/package.json | 1 +
.../common/configs/enhanced_configs_test.js | 79 +------
.../capacityscheduler/ConfigurationService.java | 2 +-
.../main/resources/ui/pig-web/app/initialize.js | 5 +
75 files changed, 2605 insertions(+), 1051 deletions(-)
----------------------------------------------------------------------
[06/21] ambari git commit: AMBARI-18408 Configuration Groups popup:
Tooltip over properties number has too much content (Vivek Ratnavel
Subramanian via zhewang)
Posted by nc...@apache.org.
AMBARI-18408 Configuration Groups popup: Tooltip over properties number has too much content (Vivek Ratnavel Subramanian via zhewang)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e54c31e8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e54c31e8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e54c31e8
Branch: refs/heads/branch-dev-patch-upgrade
Commit: e54c31e8900773dc46a80b2f18e111798709d536
Parents: 5d31b70
Author: Zhe (Joe) Wang <zh...@apache.org>
Authored: Mon Sep 19 14:41:54 2016 -0700
Committer: Zhe (Joe) Wang <zh...@apache.org>
Committed: Mon Sep 19 14:41:54 2016 -0700
----------------------------------------------------------------------
.../service/manage_config_groups_controller.js | 36 ++++++++++++++++++++
.../manage_configuration_groups_popup.hbs | 2 +-
2 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e54c31e8/ambari-web/app/controllers/main/service/manage_config_groups_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js
index e6e21bc..ad44b9c 100644
--- a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js
+++ b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js
@@ -138,6 +138,42 @@ App.ManageConfigGroupsController = Em.Controller.extend(App.ConfigOverridable, {
hostsModifiedConfigGroups: {},
/**
+ * Trim the tooltip text to show first 500 characters of properties list
+ * @type {string}
+ */
+ tooltipText: function() {
+ var selectedConfigGroup = this.get('selectedConfigGroup'),
+ propertiesList = selectedConfigGroup.get('propertiesList'),
+ trimLength = 500,
+ trimmedText = "",
+ noOfRemainingProperties = 0,
+ index = 0,
+ propertyText = "",
+ addDots = false;
+ if(propertiesList.length > trimLength) {
+ // Adjust trim length based on occurrence of <br/> around trim length
+ index = propertiesList.substring(trimLength-10, trimLength+10).indexOf("<br/>");
+ if(index > -1) {
+ trimLength = trimLength - 10 + index;
+ } else {
+ addDots = true;
+ }
+ trimmedText = propertiesList.substring(0, trimLength);
+ if(addDots) {
+ trimmedText += " ...";
+ }
+ noOfRemainingProperties = (propertiesList.substring(trimLength).match(new RegExp("<br/>", "g")) || []).length - 1;
+ if(noOfRemainingProperties > 0) {
+ propertyText = (noOfRemainingProperties > 1) ? "properties" : "property";
+ trimmedText += "<br/> and " + noOfRemainingProperties + " more " + propertyText;
+ }
+ } else {
+ trimmedText = propertiesList;
+ }
+ return trimmedText;
+ }.property('selectedConfigGroup.propertiesList'),
+
+ /**
* Check when some config group was changed and updates <code>hostsModifiedConfigGroups</code> once
* @method hostsModifiedConfigGroupsObs
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/e54c31e8/ambari-web/app/templates/main/service/manage_configuration_groups_popup.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/service/manage_configuration_groups_popup.hbs b/ambari-web/app/templates/main/service/manage_configuration_groups_popup.hbs
index d0fd103..2c9dfa6 100644
--- a/ambari-web/app/templates/main/service/manage_configuration_groups_popup.hbs
+++ b/ambari-web/app/templates/main/service/manage_configuration_groups_popup.hbs
@@ -69,7 +69,7 @@
<div class="span2">{{t common.overrides}}</div>
<div class="span10">
<a href="" class="properties-link" {{action showProperties target="controller"}}
- {{bindAttr data-original-title="selectedConfigGroup.propertiesList" }}>{{selectedConfigGroup.properties.length}} {{t common.properties}}</a>
+ {{bindAttr data-original-title="tooltipText" }}>{{selectedConfigGroup.properties.length}} {{t common.properties}}</a>
</div>
</div>
<div class="clearfix"></div>
[11/21] ambari git commit: AMBARI-18406. Create authentication filter
to perform Kerberos authentication for Ambari (rlevas)
Posted by nc...@apache.org.
AMBARI-18406. Create authentication filter to perform Kerberos authentication for Ambari (rlevas)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b4320b5a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b4320b5a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b4320b5a
Branch: refs/heads/branch-dev-patch-upgrade
Commit: b4320b5a8d29b812e9fe86da69a219a17d5e4ea7
Parents: 8425f1f
Author: Robert Levas <rl...@hortonworks.com>
Authored: Tue Sep 20 14:45:23 2016 -0400
Committer: Robert Levas <rl...@hortonworks.com>
Committed: Tue Sep 20 14:45:23 2016 -0400
----------------------------------------------------------------------
ambari-project/pom.xml | 5 +
ambari-server/pom.xml | 6 +-
.../server/configuration/Configuration.java | 30 ++-
.../server/controller/KerberosHelper.java | 2 +
.../server/controller/KerberosHelperImpl.java | 18 +-
.../server/security/AmbariEntryPoint.java | 15 +-
.../AmbariAuthToLocalUserDetailsService.java | 139 +++++++++++
.../AmbariKerberosAuthenticationFilter.java | 172 ++++++++++++++
.../kerberos/AmbariKerberosTicketValidator.java | 93 ++++++++
.../AbstractPrepareKerberosServerAction.java | 10 +-
.../ConfigureAmbariIdentitiesServerAction.java | 235 +++++++++++++++++++
.../ConfigureAmbariIndetityServerAction.java | 208 ----------------
.../kerberos/CreatePrincipalsServerAction.java | 5 +-
.../kerberos/KerberosServerAction.java | 12 +-
.../webapp/WEB-INF/spring-security.xml | 32 ++-
.../server/controller/KerberosHelperTest.java | 6 +-
...AmbariAuthToLocalUserDetailsServiceTest.java | 92 ++++++++
.../AmbariKerberosAuthenticationFilterTest.java | 133 +++++++++++
.../AmbariKerberosTicketValidatorTest.java | 49 ++++
19 files changed, 1021 insertions(+), 241 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-project/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-project/pom.xml b/ambari-project/pom.xml
index 2615b46..4f045fe 100644
--- a/ambari-project/pom.xml
+++ b/ambari-project/pom.xml
@@ -132,6 +132,11 @@
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
+ <groupId>org.springframework.security.kerberos</groupId>
+ <artifactId>spring-security-kerberos-web</artifactId>
+ <version>1.0.1.RELEASE</version>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 323ce22..32267c8 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -44,7 +44,7 @@
<stacksSrcLocation>src/main/resources/stacks/${stack.distribution}</stacksSrcLocation>
<tarballResourcesFolder>src/main/resources</tarballResourcesFolder>
<skipPythonTests>false</skipPythonTests>
- <hadoop.version>2.7.1</hadoop.version>
+ <hadoop.version>2.7.2</hadoop.version>
<empty.dir>src/main/package</empty.dir> <!-- any directory in project with not very big amount of files (not to waste-load them) -->
</properties>
<build>
@@ -985,6 +985,10 @@
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
+ <groupId>org.springframework.security.kerberos</groupId>
+ <artifactId>spring-security-kerberos-web</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index b2fa4c0..f1058b6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -5284,9 +5284,11 @@ public class Configuration {
try {
orderedUserTypes.add(UserType.valueOf(type.toUpperCase()));
} catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(String.format("While processing ordered user types from %s, " +
+ String message = String.format("While processing ordered user types from %s, " +
"%s was found to be an invalid user type.",
- KERBEROS_AUTH_USER_TYPES.getKey(), type), e);
+ KERBEROS_AUTH_USER_TYPES.getKey(), type);
+ LOG.error(message);
+ throw new IllegalArgumentException(message, e);
}
}
}
@@ -5320,9 +5322,11 @@ public class Configuration {
// Validate the SPNEGO principal name to ensure it was set.
// Log any found issues.
if (StringUtils.isEmpty(kerberosAuthProperties.getSpnegoPrincipalName())) {
- throw new IllegalArgumentException(String.format("The SPNEGO principal name specified in %s is empty. " +
+ String message = String.format("The SPNEGO principal name specified in %s is empty. " +
"This will cause issues authenticating users using Kerberos.",
- KERBEROS_AUTH_SPNEGO_PRINCIPAL.getKey()));
+ KERBEROS_AUTH_SPNEGO_PRINCIPAL.getKey());
+ LOG.error(message);
+ throw new IllegalArgumentException(message);
}
// Get the SPNEGO keytab file. There is nothing special to process for this value.
@@ -5331,19 +5335,25 @@ public class Configuration {
// Validate the SPNEGO keytab file to ensure it was set, it exists and it is readable by Ambari.
// Log any found issues.
if (StringUtils.isEmpty(kerberosAuthProperties.getSpnegoKeytabFilePath())) {
- throw new IllegalArgumentException(String.format("The SPNEGO keytab file path specified in %s is empty. " +
+ String message = String.format("The SPNEGO keytab file path specified in %s is empty. " +
"This will cause issues authenticating users using Kerberos.",
- KERBEROS_AUTH_SPNEGO_KEYTAB_FILE.getKey()));
+ KERBEROS_AUTH_SPNEGO_KEYTAB_FILE.getKey());
+ LOG.error(message);
+ throw new IllegalArgumentException(message);
} else {
File keytabFile = new File(kerberosAuthProperties.getSpnegoKeytabFilePath());
if (!keytabFile.exists()) {
- throw new IllegalArgumentException(String.format("The SPNEGO keytab file path (%s) specified in %s does not exist. " +
+ String message = String.format("The SPNEGO keytab file path (%s) specified in %s does not exist. " +
"This will cause issues authenticating users using Kerberos.",
- keytabFile.getAbsolutePath(), KERBEROS_AUTH_SPNEGO_KEYTAB_FILE.getKey()));
+ keytabFile.getAbsolutePath(), KERBEROS_AUTH_SPNEGO_KEYTAB_FILE.getKey());
+ LOG.error(message);
+ throw new IllegalArgumentException(message);
} else if (!keytabFile.canRead()) {
- throw new IllegalArgumentException(String.format("The SPNEGO keytab file path (%s) specified in %s cannot be read. " +
+ String message = String.format("The SPNEGO keytab file path (%s) specified in %s cannot be read. " +
"This will cause issues authenticating users using Kerberos.",
- keytabFile.getAbsolutePath(), KERBEROS_AUTH_SPNEGO_KEYTAB_FILE.getKey()));
+ keytabFile.getAbsolutePath(), KERBEROS_AUTH_SPNEGO_KEYTAB_FILE.getKey());
+ LOG.error(message);
+ throw new IllegalArgumentException(message);
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
index c4d21fc..1153d01 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
@@ -70,6 +70,8 @@ public interface KerberosHelper {
String AMBARI_IDENTITY_NAME = "ambari-server";
+ String SPNEGO_IDENTITY_NAME = "spnego";
+
String CREATE_AMBARI_PRINCIPAL = "create_ambari_principal";
String MANAGE_IDENTITIES = "manage_identities";
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelperImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelperImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelperImpl.java
index 5bc5cd8..a3c6fd4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelperImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelperImpl.java
@@ -61,7 +61,7 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
import org.apache.ambari.server.serveraction.ActionLog;
import org.apache.ambari.server.serveraction.ServerAction;
import org.apache.ambari.server.serveraction.kerberos.CleanupServerAction;
-import org.apache.ambari.server.serveraction.kerberos.ConfigureAmbariIndetityServerAction;
+import org.apache.ambari.server.serveraction.kerberos.ConfigureAmbariIdentitiesServerAction;
import org.apache.ambari.server.serveraction.kerberos.CreateKeytabFilesServerAction;
import org.apache.ambari.server.serveraction.kerberos.CreatePrincipalsServerAction;
import org.apache.ambari.server.serveraction.kerberos.DestroyPrincipalsServerAction;
@@ -761,7 +761,7 @@ public class KerberosHelperImpl implements KerberosHelper {
* @param ambariServerIdentity the ambari server's {@link KerberosIdentityDescriptor}
* @param configurations a map of compiled configrations used for variable replacment
* @throws AmbariException
- * @see ConfigureAmbariIndetityServerAction#installAmbariServerIdentity(String, String, String, ActionLog)
+ * @see ConfigureAmbariIdentitiesServerAction#installAmbariServerIdentity(String, String, String, ActionLog)
*/
private void installAmbariIdentity(KerberosIdentityDescriptor ambariServerIdentity,
Map<String, Map<String, String>> configurations) throws AmbariException {
@@ -775,7 +775,7 @@ public class KerberosHelperImpl implements KerberosHelper {
if(keytabDescriptor != null) {
String keytabFilePath = variableReplacementHelper.replaceVariables(keytabDescriptor.getFile(), configurations);
- injector.getInstance(ConfigureAmbariIndetityServerAction.class)
+ injector.getInstance(ConfigureAmbariIdentitiesServerAction.class)
.installAmbariServerIdentity(principal, ambariServerPrincipalEntity.getCachedKeytabPath(), keytabFilePath, null);
}
}
@@ -1259,7 +1259,7 @@ public class KerberosHelperImpl implements KerberosHelper {
serviceName, componentName, kerberosDescriptor, filterContext);
if (hostname.equals(ambariServerHostname)) {
- addAmbariServerIdentity(kerberosEnvConfig.getProperties(), kerberosDescriptor, identities);
+ addAmbariServerIdentities(kerberosEnvConfig.getProperties(), kerberosDescriptor, identities);
}
if (!identities.isEmpty()) {
@@ -1346,7 +1346,7 @@ public class KerberosHelperImpl implements KerberosHelper {
* @param kerberosDescriptor the kerberos descriptor
* @param identities the collection of identities to add to
*/
- void addAmbariServerIdentity(Map<String, String> kerberosEnvProperties, KerberosDescriptor kerberosDescriptor, List<KerberosIdentityDescriptor> identities) {
+ void addAmbariServerIdentities(Map<String, String> kerberosEnvProperties, KerberosDescriptor kerberosDescriptor, List<KerberosIdentityDescriptor> identities) {
// Determine if we should _calculate_ the Ambari service identity.
// If kerberos-env/create_ambari_principal is not set to false the identity should be calculated.
boolean createAmbariPrincipal = (kerberosEnvProperties == null) || !"false".equalsIgnoreCase(kerberosEnvProperties.get(CREATE_AMBARI_PRINCIPAL));
@@ -1357,6 +1357,12 @@ public class KerberosHelperImpl implements KerberosHelper {
if (ambariServerIdentity != null) {
identities.add(ambariServerIdentity);
}
+
+ // Add the spnego principal for the Ambari server host....
+ KerberosIdentityDescriptor spnegoIdentity = kerberosDescriptor.getIdentity(KerberosHelper.SPNEGO_IDENTITY_NAME);
+ if (spnegoIdentity != null) {
+ identities.add(spnegoIdentity);
+ }
}
}
@@ -2799,7 +2805,7 @@ public class KerberosHelperImpl implements KerberosHelper {
clusterHostInfoJson,
"{}",
hostParamsJson,
- ConfigureAmbariIndetityServerAction.class,
+ ConfigureAmbariIdentitiesServerAction.class,
event,
commandParameters,
"Configure Ambari Identity",
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariEntryPoint.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariEntryPoint.java b/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariEntryPoint.java
index 2028f46..e37976f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariEntryPoint.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariEntryPoint.java
@@ -28,6 +28,19 @@ import java.io.IOException;
public class AmbariEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
- response.sendError(HttpServletResponse.SC_FORBIDDEN, authException.getMessage());
+ /* *****************************************************************************************
+ * To maintain backward compatibility and respond with the appropriate response when
+ * authentication is needed, by default return an HTTP 403 status.
+ *
+ * However if requested by the user, respond such that the client is challenged to Negotiate
+ * and reissue the request with a Kerberos token. This response is an HTTP 401 status with the
+ * WWW-Authenticate: Negotiate" header.
+ * ****************************************************************************************** */
+ if ("true".equalsIgnoreCase(request.getHeader("X-Negotiate-Authentication"))) {
+ response.setHeader("WWW-Authenticate", "Negotiate");
+ response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication requested");
+ } else {
+ response.sendError(HttpServletResponse.SC_FORBIDDEN, authException.getMessage());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsService.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsService.java
new file mode 100644
index 0000000..3c62646
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsService.java
@@ -0,0 +1,139 @@
+/*
+ * 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.security.authentication.kerberos;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.security.authorization.AmbariGrantedAuthority;
+import org.apache.ambari.server.security.authorization.UserType;
+import org.apache.ambari.server.security.authorization.Users;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.security.authentication.util.KerberosName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * AmbariAuthToLocalUserDetailsService is a {@link UserDetailsService} that translates
+ * a Kerberos principal name into a local username that may be used when looking up
+ * and Ambari user account.
+ */
+public class AmbariAuthToLocalUserDetailsService implements UserDetailsService {
+ private static final Logger LOG = LoggerFactory.getLogger(AmbariAuthToLocalUserDetailsService.class);
+
+ private final Users users;
+
+ private final List<UserType> userTypeOrder;
+
+ /**
+ * Constructor.
+ * <p>
+ * Given the Ambari {@link Configuration}, initializes the {@link KerberosName} class using
+ * the <code>auth-to-local</code> rules from {@link AmbariKerberosAuthenticationProperties#getAuthToLocalRules()}.
+ *
+ * @param configuration the Ambari configuration data
+ * @param users the Ambari users access object
+ * @throws AmbariException if an error occurs parsing the user-provided auth-to-local rules
+ */
+ public AmbariAuthToLocalUserDetailsService(Configuration configuration, Users users) throws AmbariException {
+ String authToLocalRules = null;
+ List<UserType> orderedUserTypes = null;
+
+ if (configuration != null) {
+ AmbariKerberosAuthenticationProperties properties = configuration.getKerberosAuthenticationProperties();
+
+ if (properties != null) {
+ authToLocalRules = properties.getAuthToLocalRules();
+ orderedUserTypes = properties.getOrderedUserTypes();
+ }
+ }
+
+ if (StringUtils.isEmpty(authToLocalRules)) {
+ authToLocalRules = "DEFAULT";
+ }
+
+ if ((orderedUserTypes == null) || orderedUserTypes.isEmpty()) {
+ orderedUserTypes = Collections.singletonList(UserType.LDAP);
+ }
+
+ KerberosName.setRules(authToLocalRules);
+
+ this.users = users;
+ this.userTypeOrder = orderedUserTypes;
+ }
+
+ @Override
+ public UserDetails loadUserByUsername(String principal) throws UsernameNotFoundException {
+ KerberosName kerberosName = new KerberosName(principal);
+
+ try {
+ String username = kerberosName.getShortName();
+
+ if (username == null) {
+ String message = String.format("Failed to translate %s to a local username during Kerberos authentication.", principal);
+ LOG.warn(message);
+ throw new UsernameNotFoundException(message);
+ }
+
+ LOG.info("Translated {} to {} using auth-to-local rules during Kerberos authentication.", principal, username);
+ return createUser(username);
+ } catch (IOException e) {
+ String message = String.format("Failed to translate %s to a local username during Kerberos authentication: %s", principal, e.getLocalizedMessage());
+ LOG.warn(message);
+ throw new UsernameNotFoundException(message, e);
+ }
+ }
+
+ /**
+ * Given a username, finds an appropriate account in the Ambari database.
+ * <p>
+ * User accounts are searched in order of preferred user type as specified in the Ambari configuration
+ * ({@link Configuration#KERBEROS_AUTH_USER_TYPES}).
+ *
+ * @param username a username
+ * @return the user details of the found user, or <code>null</code> if an appropriate user was not found
+ */
+ private UserDetails createUser(String username) {
+ // Iterate over the ordered user types... when an account for the username/type combination is
+ // found, build the related AmbariUserAuthentication instance and return it. Only the first
+ // match matters... this may be an issue and cause some ambiguity in the event multiple user
+ // types are specified in the configuration and multiple accounts for the same username, but
+ // different types (LOCAL vs LDAP, etc...).
+ for (UserType userType : userTypeOrder) {
+ org.apache.ambari.server.security.authorization.User user = users.getUser(username, userType);
+
+ if (user != null) {
+ Collection<AmbariGrantedAuthority> userAuthorities = users.getUserAuthorities(user.getUserName(), user.getUserType());
+ return new User(username, "", userAuthorities);
+ }
+ }
+
+ String message = String.format("Failed find user account for user with username of %s during Kerberos authentication.", username);
+ LOG.warn(message);
+ throw new UsernameNotFoundException(message);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationFilter.java
new file mode 100644
index 0000000..a5a3922
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationFilter.java
@@ -0,0 +1,172 @@
+/*
+ * 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.security.authentication.kerberos;
+
+import org.apache.ambari.server.audit.AuditLogger;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.LoginAuditEvent;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.security.authentication.AmbariAuthenticationFilter;
+import org.apache.ambari.server.security.authorization.AuthorizationHelper;
+import org.apache.ambari.server.security.authorization.PermissionHelper;
+import org.apache.ambari.server.utils.RequestUtils;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * AmbariKerberosAuthenticationFilter extends the {@link SpnegoAuthenticationProcessingFilter} class
+ * to perform Kerberos-based authentication for Ambari.
+ * <p>
+ * If configured, auditing is performed using {@link AuditLogger}.
+ */
+public class AmbariKerberosAuthenticationFilter extends SpnegoAuthenticationProcessingFilter implements AmbariAuthenticationFilter {
+
+ /**
+ * Audit logger
+ */
+ private final AuditLogger auditLogger;
+
+ /**
+ * A Boolean value indicating whether Kerberos authentication is enabled or not.
+ */
+ private final boolean kerberosAuthenticationEnabled;
+
+ /**
+ * Constructor.
+ * <p>
+ * Given supplied data, sets up the the {@link SpnegoAuthenticationProcessingFilter} to perform
+ * authentication and audit logging if configured do to so.
+ *
+ * @param authenticationManager the Spring authentication manager
+ * @param entryPoint the Spring entry point
+ * @param configuration the Ambari configuration data
+ * @param auditLogger an audit logger
+ * @param permissionHelper a permission helper to aid in audit logging
+ */
+ public AmbariKerberosAuthenticationFilter(AuthenticationManager authenticationManager, final AuthenticationEntryPoint entryPoint, Configuration configuration, final AuditLogger auditLogger, final PermissionHelper permissionHelper) {
+ AmbariKerberosAuthenticationProperties kerberosAuthenticationProperties = (configuration == null)
+ ? null
+ : configuration.getKerberosAuthenticationProperties();
+
+ kerberosAuthenticationEnabled = (kerberosAuthenticationProperties != null) && kerberosAuthenticationProperties.isKerberosAuthenticationEnabled();
+
+ this.auditLogger = auditLogger;
+
+ setAuthenticationManager(authenticationManager);
+
+ setFailureHandler(new AuthenticationFailureHandler() {
+ @Override
+ public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
+ if (auditLogger.isEnabled()) {
+ AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(httpServletRequest))
+ .withTimestamp(System.currentTimeMillis())
+ .withReasonOfFailure(e.getLocalizedMessage())
+ .build();
+ auditLogger.log(loginFailedAuditEvent);
+ }
+
+ entryPoint.commence(httpServletRequest, httpServletResponse, e);
+ }
+ });
+
+ setSuccessHandler(new AuthenticationSuccessHandler() {
+ @Override
+ public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
+ if (auditLogger.isEnabled()) {
+ AuditEvent loginSucceededAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(httpServletRequest))
+ .withUserName(authentication.getName())
+ .withTimestamp(System.currentTimeMillis())
+ .withRoles(permissionHelper.getPermissionLabels(authentication))
+ .build();
+ auditLogger.log(loginSucceededAuditEvent);
+ }
+ }
+ });
+ }
+
+ /**
+ * Tests to determine if this authentication filter is applicable given the Ambari configuration
+ * and the user's HTTP request.
+ * <p>
+ * If the Ambari configuration indicates the Kerberos authentication is enabled and the HTTP request
+ * contains the appropriate <code>Authorization</code> header, than this filter may be applied;
+ * otherwise it should be skipped.
+ *
+ * @param httpServletRequest the request
+ * @return true if this filter should be applied; false otherwise
+ */
+ @Override
+ public boolean shouldApply(HttpServletRequest httpServletRequest) {
+ if (kerberosAuthenticationEnabled) {
+ String header = httpServletRequest.getHeader("Authorization");
+ return (header != null) && (header.startsWith("Negotiate ") || header.startsWith("Kerberos "));
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Performs the logic for this filter.
+ * <p>
+ * Checks whether the authentication information is filled. If it is not, then a login failed audit event is logged.
+ * <p>
+ * Then, forwards the workflow to {@link SpnegoAuthenticationProcessingFilter#doFilter(ServletRequest, ServletResponse, FilterChain)}
+ *
+ * @param servletRequest the request
+ * @param servletResponse the response
+ * @param filterChain the Spring filter chain
+ * @throws IOException
+ * @throws ServletException
+ */
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+
+ if (shouldApply(httpServletRequest)) {
+ if (auditLogger.isEnabled() && (AuthorizationHelper.getAuthenticatedName() == null)) {
+ AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(httpServletRequest))
+ .withTimestamp(System.currentTimeMillis())
+ .withReasonOfFailure("Authentication required")
+ .withUserName(null)
+ .build();
+ auditLogger.log(loginFailedAuditEvent);
+ }
+
+ super.doFilter(servletRequest, servletResponse, filterChain);
+ } else {
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosTicketValidator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosTicketValidator.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosTicketValidator.java
new file mode 100644
index 0000000..bb57108
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosTicketValidator.java
@@ -0,0 +1,93 @@
+/*
+ * 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.security.authentication.kerberos;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.kerberos.authentication.KerberosTicketValidation;
+import org.springframework.security.kerberos.authentication.KerberosTicketValidator;
+import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
+
+/**
+ * AmbariKerberosTicketValidator is a {@link KerberosTicketValidator} implementation that delegates
+ * to a {@link SunJaasKerberosTicketValidator}, if Kerberos authentication is enabled.
+ * <p>
+ * If Kerberos authentication is enabled, the following properties are set:
+ * <ul>
+ * <li>{@link SunJaasKerberosTicketValidator#setServicePrincipal(String)} using the Ambari server property from {@link Configuration#KERBEROS_AUTH_SPNEGO_PRINCIPAL}</li>
+ * <li>{@link SunJaasKerberosTicketValidator#setKeyTabLocation(Resource)} using the Ambari server property from {@link Configuration#KERBEROS_AUTH_SPNEGO_KEYTAB_FILE}</li>
+ * </ul>
+ */
+public class AmbariKerberosTicketValidator implements KerberosTicketValidator, InitializingBean {
+
+ private final SunJaasKerberosTicketValidator kerberosTicketValidator;
+
+ /**
+ * Creates a new AmbariKerberosTicketValidator
+ *
+ * @param configuration the Ambari server configuration
+ */
+ public AmbariKerberosTicketValidator(Configuration configuration) {
+
+ AmbariKerberosAuthenticationProperties properties = (configuration == null)
+ ? null
+ : configuration.getKerberosAuthenticationProperties();
+
+ if ((properties != null) && properties.isKerberosAuthenticationEnabled()) {
+ kerberosTicketValidator = new SunJaasKerberosTicketValidator();
+ kerberosTicketValidator.setServicePrincipal(properties.getSpnegoPrincipalName());
+
+ if (properties.getSpnegoKeytabFilePath() != null) {
+ kerberosTicketValidator.setKeyTabLocation(new FileSystemResource(properties.getSpnegoKeytabFilePath()));
+ }
+ } else {
+ // Don't create the SunJaasKerberosTicketValidator if Kerberos authentication is not enabled.
+ kerberosTicketValidator = null;
+ }
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ // If Kerberos authentication is enabled, forward this method invocation to the backing
+ // SunJaasKerberosTicketValidator instance.
+ if (kerberosTicketValidator != null) {
+ kerberosTicketValidator.afterPropertiesSet();
+ }
+ }
+
+ @Override
+ public KerberosTicketValidation validateTicket(byte[] bytes) throws BadCredentialsException {
+ // If Kerberos authentication is enabled, forward this method invocation to the backing
+ // SunJaasKerberosTicketValidator instance.
+ return (kerberosTicketValidator == null)
+ ? null
+ : kerberosTicketValidator.validateTicket(bytes);
+ }
+
+ public void setDebug(boolean debug) {
+ // If Kerberos authentication is enabled, forward this method invocation to the backing
+ // SunJaasKerberosTicketValidator instance.
+ if (kerberosTicketValidator != null) {
+ kerberosTicketValidator.setDebug(debug);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/AbstractPrepareKerberosServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/AbstractPrepareKerberosServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/AbstractPrepareKerberosServerAction.java
index b6b0713..c283a65 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/AbstractPrepareKerberosServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/AbstractPrepareKerberosServerAction.java
@@ -156,7 +156,15 @@ public abstract class AbstractPrepareKerberosServerAction extends KerberosServer
if (ambariServerIdentity != null) {
List<KerberosIdentityDescriptor> componentIdentities = Collections.singletonList(ambariServerIdentity);
kerberosHelper.addIdentities(kerberosIdentityDataFileWriter, componentIdentities,
- identityFilter, KerberosHelper.AMBARI_SERVER_HOST_NAME, "AMBARI_SEVER", "AMBARI_SEVER", kerberosConfigurations, configurations);
+ identityFilter, KerberosHelper.AMBARI_SERVER_HOST_NAME, "AMBARI_SERVER", "AMBARI_SERVER", kerberosConfigurations, configurations);
+ propertiesToIgnore = gatherPropertiesToIgnore(componentIdentities, propertiesToIgnore);
+ }
+
+ KerberosIdentityDescriptor spnegoIdentity = kerberosDescriptor.getIdentity(KerberosHelper.SPNEGO_IDENTITY_NAME);
+ if (spnegoIdentity != null) {
+ List<KerberosIdentityDescriptor> componentIdentities = Collections.singletonList(spnegoIdentity);
+ kerberosHelper.addIdentities(kerberosIdentityDataFileWriter, componentIdentities,
+ identityFilter, KerberosHelper.AMBARI_SERVER_HOST_NAME, "AMBARI_SERVER", "SPNEGO", kerberosConfigurations, configurations);
propertiesToIgnore = gatherPropertiesToIgnore(componentIdentities, propertiesToIgnore);
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ConfigureAmbariIdentitiesServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ConfigureAmbariIdentitiesServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ConfigureAmbariIdentitiesServerAction.java
new file mode 100644
index 0000000..9c2c622
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ConfigureAmbariIdentitiesServerAction.java
@@ -0,0 +1,235 @@
+/*
+ * 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.serveraction.kerberos;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+
+import com.google.inject.Inject;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.agent.CommandReport;
+import org.apache.ambari.server.controller.KerberosHelper;
+import org.apache.ambari.server.controller.utilities.KerberosChecker;
+import org.apache.ambari.server.orm.dao.HostDAO;
+import org.apache.ambari.server.orm.dao.KerberosPrincipalHostDAO;
+import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.serveraction.ActionLog;
+import org.apache.ambari.server.utils.ShellCommandUtil;
+import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ConfigureAmbariIdentitiesServerAction is a ServerAction implementation that creates keytab files as
+ * instructed.
+ * <p/>
+ * This class mainly relies on the KerberosServerAction to iterate through metadata identifying
+ * the Kerberos keytab files that need to be created. For each identity in the metadata, this
+ * implementation's
+ * {@link KerberosServerAction#processIdentity(Map, String, KerberosOperationHandler, Map, Map)}
+ * is invoked attempting the creation of the relevant keytab file.
+ */
+public class ConfigureAmbariIdentitiesServerAction extends KerberosServerAction {
+
+
+ private static final String KEYTAB_PATTERN = "keyTab=\"(.+)?\"";
+ private static final String PRINCIPAL_PATTERN = "principal=\"(.+)?\"";
+
+ private final static Logger LOG = LoggerFactory.getLogger(ConfigureAmbariIdentitiesServerAction.class);
+
+ @Inject
+ private KerberosPrincipalHostDAO kerberosPrincipalHostDAO;
+
+ @Inject
+ private HostDAO hostDAO;
+
+ /**
+ * Called to execute this action. Upon invocation, calls
+ * {@link KerberosServerAction#processIdentities(Map)} )}
+ * to iterate through the Kerberos identity metadata and call
+ * {@link ConfigureAmbariIdentitiesServerAction#processIdentities(Map)}
+ * for each identity to process.
+ *
+ * @param requestSharedDataContext a Map to be used a shared data among all ServerActions related
+ * to a given request
+ * @return a CommandReport indicating the result of this action
+ * @throws AmbariException
+ * @throws InterruptedException
+ */
+ @Override
+ public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws
+ AmbariException, InterruptedException {
+ return processIdentities(requestSharedDataContext);
+ }
+
+
+ /**
+ * Creates keytab file for ambari-server identity.
+ * <p/>
+ * It is expected that the {@link CreatePrincipalsServerAction}
+ * (or similar) and {@link CreateKeytabFilesServerAction} has executed before this action.
+ *
+ * @param identityRecord a Map containing the data for the current identity record
+ * @param evaluatedPrincipal a String indicating the relevant principal
+ * @param operationHandler a KerberosOperationHandler used to perform Kerberos-related
+ * tasks for specific Kerberos implementations
+ * (MIT, Active Directory, etc...)
+ * @param kerberosConfiguration a Map of configuration properties from kerberos-env
+ * @param requestSharedDataContext a Map to be used a shared data among all ServerActions related
+ * to a given request @return a CommandReport, indicating an error
+ * condition; or null, indicating a success condition
+ * @throws AmbariException if an error occurs while processing the identity record
+ */
+ @Override
+ protected CommandReport processIdentity(Map<String, String> identityRecord, String evaluatedPrincipal,
+ KerberosOperationHandler operationHandler,
+ Map<String, String> kerberosConfiguration,
+ Map<String, Object> requestSharedDataContext)
+ throws AmbariException {
+ CommandReport commandReport = null;
+
+ if (identityRecord != null) {
+ String message;
+ String dataDirectory = getDataDirectoryPath();
+
+ if (dataDirectory == null) {
+ message = "The data directory has not been set. Generated keytab files can not be stored.";
+ LOG.error(message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
+ } else {
+
+ String hostName = identityRecord.get(KerberosIdentityDataFileReader.HOSTNAME);
+ if (hostName != null && hostName.equalsIgnoreCase(KerberosHelper.AMBARI_SERVER_HOST_NAME)) {
+ String destKeytabFilePath = identityRecord.get(KerberosIdentityDataFileReader.KEYTAB_FILE_PATH);
+ File hostDirectory = new File(dataDirectory, hostName);
+ File srcKeytabFile = new File(hostDirectory, DigestUtils.sha1Hex(destKeytabFilePath));
+
+ if (srcKeytabFile.exists()) {
+ installAmbariServerIdentity(evaluatedPrincipal, srcKeytabFile.getAbsolutePath(), destKeytabFilePath, actionLog);
+
+ if ("AMBARI_SERVER".equals(identityRecord.get(KerberosIdentityDataFileReader.COMPONENT))) {
+ // Create/update the JAASFile...
+ configureJAAS(evaluatedPrincipal, destKeytabFilePath, actionLog);
+ }
+ }
+ }
+ }
+ }
+
+ return commandReport;
+ }
+
+ /**
+ * Installs the Ambari Server Kerberos identity by copying its keytab file to the specified location
+ * and then creating the Ambari Server JAAS File.
+ *
+ * @param principal the ambari server principal name
+ * @param srcKeytabFilePath the source location of the ambari server keytab file
+ * @param destKeytabFilePath the destination location of the ambari server keytab file
+ * @param actionLog the logger
+ * @return true if success; false otherwise
+ * @throws AmbariException
+ */
+ public boolean installAmbariServerIdentity(String principal,
+ String srcKeytabFilePath,
+ String destKeytabFilePath,
+ ActionLog actionLog) throws AmbariException {
+
+ // Use sudo to copy the file into place....
+ try {
+ ShellCommandUtil.Result result;
+
+ // Ensure the parent directory exists...
+ File destKeytabFile = new File(destKeytabFilePath);
+ result = ShellCommandUtil.mkdir(destKeytabFile.getParent(), true);
+ if (!result.isSuccessful()) {
+ throw new AmbariException(result.getStderr());
+ }
+
+ // Copy the keytab file into place...
+ result = ShellCommandUtil.copyFile(srcKeytabFilePath, destKeytabFilePath, true, true);
+ if (!result.isSuccessful()) {
+ throw new AmbariException(result.getStderr());
+ } else {
+ String ambariServerHostName = StageUtils.getHostName();
+ HostEntity ambariServerHostEntity = hostDAO.findByName(ambariServerHostName);
+ Long ambariServerHostID = (ambariServerHostEntity == null)
+ ? null
+ : ambariServerHostEntity.getHostId();
+
+ if (ambariServerHostID == null) {
+ String message = String.format("Failed to add the kerberos_principal_host record for %s on " +
+ "the Ambari server host since the host id for Ambari server host, %s, was not found." +
+ " This is not an error if an Ambari agent is not installed on the Ambari server host.",
+ principal, ambariServerHostName);
+ LOG.warn(message);
+ actionLog.writeStdErr(message);
+ } else if (!kerberosPrincipalHostDAO.exists(principal, ambariServerHostID)) {
+ kerberosPrincipalHostDAO.create(principal, ambariServerHostID);
+ }
+
+ actionLog.writeStdOut(String.format("Created Ambari server keytab file for %s at %s", principal, destKeytabFile));
+ }
+ } catch (InterruptedException | IOException e) {
+ throw new AmbariException(e.getLocalizedMessage(), e);
+ }
+
+ return true;
+ }
+
+ private void configureJAAS(String evaluatedPrincipal, String keytabFilePath, ActionLog actionLog) {
+ String jaasConfPath = System.getProperty(KerberosChecker.JAVA_SECURITY_AUTH_LOGIN_CONFIG);
+ if (jaasConfPath != null) {
+ File jaasConfigFile = new File(jaasConfPath);
+ try {
+ String jaasConfig = FileUtils.readFileToString(jaasConfigFile);
+ File oldJaasConfigFile = new File(jaasConfPath + ".bak");
+ FileUtils.writeStringToFile(oldJaasConfigFile, jaasConfig);
+ jaasConfig = jaasConfig.replaceFirst(KEYTAB_PATTERN, "keyTab=\"" + keytabFilePath + "\"");
+ jaasConfig = jaasConfig.replaceFirst(PRINCIPAL_PATTERN, "principal=\"" + evaluatedPrincipal + "\"");
+ FileUtils.writeStringToFile(jaasConfigFile, jaasConfig);
+ String message = String.format("JAAS config file %s modified successfully for principal %s.", jaasConfigFile
+ .getName(), evaluatedPrincipal);
+ if (actionLog != null) {
+ actionLog.writeStdOut(message);
+ }
+ } catch (IOException e) {
+ String message = String.format("Failed to configure JAAS file %s for %s - %s", jaasConfigFile,
+ evaluatedPrincipal, e.getMessage());
+ if (actionLog != null) {
+ actionLog.writeStdErr(message);
+ }
+ LOG.error(message, e);
+ }
+ } else {
+ String message = String.format("Failed to configure JAAS, config file should be passed to Ambari server as: " +
+ "%s.", KerberosChecker.JAVA_SECURITY_AUTH_LOGIN_CONFIG);
+ if (actionLog != null) {
+ actionLog.writeStdErr(message);
+ }
+ LOG.error(message);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ConfigureAmbariIndetityServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ConfigureAmbariIndetityServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ConfigureAmbariIndetityServerAction.java
deleted file mode 100644
index 96540ef..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ConfigureAmbariIndetityServerAction.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * 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.serveraction.kerberos;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.actionmanager.HostRoleStatus;
-import org.apache.ambari.server.agent.CommandReport;
-import org.apache.ambari.server.controller.KerberosHelper;
-import org.apache.ambari.server.controller.utilities.KerberosChecker;
-import org.apache.ambari.server.serveraction.ActionLog;
-import org.apache.ambari.server.utils.ShellCommandUtil;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.io.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * ConfigureAmbariIndetityServerAction is a ServerAction implementation that creates keytab files as
- * instructed.
- * <p/>
- * This class mainly relies on the KerberosServerAction to iterate through metadata identifying
- * the Kerberos keytab files that need to be created. For each identity in the metadata, this
- * implementation's
- * {@link KerberosServerAction#processIdentity(Map, String, KerberosOperationHandler, Map, Map)}
- * is invoked attempting the creation of the relevant keytab file.
- */
-public class ConfigureAmbariIndetityServerAction extends KerberosServerAction {
-
-
- private static final String KEYTAB_PATTERN = "keyTab=\"(.+)?\"";
- private static final String PRINCIPAL_PATTERN = "principal=\"(.+)?\"";
-
- private final static Logger LOG = LoggerFactory.getLogger(ConfigureAmbariIndetityServerAction.class);
-
- /**
- * Called to execute this action. Upon invocation, calls
- * {@link KerberosServerAction#processIdentities(Map)} )}
- * to iterate through the Kerberos identity metadata and call
- * {@link ConfigureAmbariIndetityServerAction#processIdentities(Map)}
- * for each identity to process.
- *
- * @param requestSharedDataContext a Map to be used a shared data among all ServerActions related
- * to a given request
- * @return a CommandReport indicating the result of this action
- * @throws AmbariException
- * @throws InterruptedException
- */
- @Override
- public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws
- AmbariException, InterruptedException {
- return processIdentities(requestSharedDataContext);
- }
-
-
- /**
- * Creates keytab file for ambari-server identity.
- * <p/>
- * It is expected that the {@link CreatePrincipalsServerAction}
- * (or similar) and {@link CreateKeytabFilesServerAction} has executed before this action.
- *
- * @param identityRecord a Map containing the data for the current identity record
- * @param evaluatedPrincipal a String indicating the relevant principal
- * @param operationHandler a KerberosOperationHandler used to perform Kerberos-related
- * tasks for specific Kerberos implementations
- * (MIT, Active Directory, etc...)
- * @param kerberosConfiguration a Map of configuration properties from kerberos-env
- * @param requestSharedDataContext a Map to be used a shared data among all ServerActions related
- * to a given request @return a CommandReport, indicating an error
- * condition; or null, indicating a success condition
- * @throws AmbariException if an error occurs while processing the identity record
- */
- @Override
- protected CommandReport processIdentity(Map<String, String> identityRecord, String evaluatedPrincipal,
- KerberosOperationHandler operationHandler,
- Map<String, String> kerberosConfiguration,
- Map<String, Object> requestSharedDataContext)
- throws AmbariException {
- CommandReport commandReport = null;
-
- if (identityRecord != null) {
- String message;
- String dataDirectory = getDataDirectoryPath();
-
- if (operationHandler == null) {
- message = String.format("Failed to create keytab file for %s, missing KerberosOperationHandler", evaluatedPrincipal);
- actionLog.writeStdErr(message);
- LOG.error(message);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
- } else if (dataDirectory == null) {
- message = "The data directory has not been set. Generated keytab files can not be stored.";
- LOG.error(message);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
- } else {
-
- String hostName = identityRecord.get(KerberosIdentityDataFileReader.HOSTNAME);
- if (hostName != null && hostName.equalsIgnoreCase(KerberosHelper.AMBARI_SERVER_HOST_NAME)) {
- String destKeytabFilePath = identityRecord.get(KerberosIdentityDataFileReader.KEYTAB_FILE_PATH);
- File hostDirectory = new File(dataDirectory, hostName);
- File srcKeytabFile = new File(hostDirectory, DigestUtils.sha1Hex(destKeytabFilePath));
-
- if(srcKeytabFile.exists()) {
- installAmbariServerIdentity(evaluatedPrincipal, srcKeytabFile.getAbsolutePath(), destKeytabFilePath, actionLog);
- }
- }
- }
- }
-
- return commandReport;
- }
-
- /**
- * Installs the Ambari Server Kerberos identity by copying its keytab file to the specified location
- * and then creating the Ambari Server JAAS File.
- *
- * @param principal the ambari server principal name
- * @param srcKeytabFilePath the source location of the ambari server keytab file
- * @param destKeytabFilePath the destination location of the ambari server keytab file
- * @param actionLog the logger
- * @return true if success; false otherwise
- * @throws AmbariException
- */
- public boolean installAmbariServerIdentity(String principal,
- String srcKeytabFilePath,
- String destKeytabFilePath,
- ActionLog actionLog) throws AmbariException {
-
- // Use sudo to copy the file into place....
- try {
- ShellCommandUtil.Result result;
-
- // Ensure the parent directory exists...
- File destKeytabFile = new File(destKeytabFilePath);
- result = ShellCommandUtil.mkdir(destKeytabFile.getParent(), true);
- if (!result.isSuccessful()) {
- throw new AmbariException(result.getStderr());
- }
-
- // Copy the keytab file into place...
- result = ShellCommandUtil.copyFile(srcKeytabFilePath, destKeytabFilePath, true, true);
- if (!result.isSuccessful()) {
- throw new AmbariException(result.getStderr());
- }
- } catch (InterruptedException | IOException e) {
- throw new AmbariException(e.getLocalizedMessage(), e);
- }
-
- // Create/update the JAASFile...
- configureJAAS(principal, destKeytabFilePath, actionLog);
-
- return true;
- }
-
- private void configureJAAS(String evaluatedPrincipal, String keytabFilePath, ActionLog actionLog) {
- String jaasConfPath = System.getProperty(KerberosChecker.JAVA_SECURITY_AUTH_LOGIN_CONFIG);
- if (jaasConfPath != null) {
- File jaasConfigFile = new File(jaasConfPath);
- try {
- String jaasConfig = FileUtils.readFileToString(jaasConfigFile);
- File oldJaasConfigFile = new File(jaasConfPath + ".bak");
- FileUtils.writeStringToFile(oldJaasConfigFile, jaasConfig);
- jaasConfig = jaasConfig.replaceFirst(KEYTAB_PATTERN, "keyTab=\"" + keytabFilePath + "\"");
- jaasConfig = jaasConfig.replaceFirst(PRINCIPAL_PATTERN, "principal=\"" + evaluatedPrincipal + "\"");
- FileUtils.writeStringToFile(jaasConfigFile, jaasConfig);
- String message = String.format("JAAS config file %s modified successfully for principal %s.", jaasConfigFile
- .getName(), evaluatedPrincipal);
- if (actionLog != null) {
- actionLog.writeStdOut(message);
- }
- } catch (IOException e) {
- String message = String.format("Failed to configure JAAS file %s for %s - %s", jaasConfigFile,
- evaluatedPrincipal, e.getMessage());
- if (actionLog != null) {
- actionLog.writeStdErr(message);
- }
- LOG.error(message, e);
- }
- } else {
- String message = String.format("Failed to configure JAAS, config file should be passed to Ambari server as: " +
- "%s.", KerberosChecker.JAVA_SECURITY_AUTH_LOGIN_CONFIG);
- if (actionLog != null) {
- actionLog.writeStdErr(message);
- }
- LOG.error(message);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
index e31e6ff..b99c25a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
@@ -18,7 +18,6 @@
package org.apache.ambari.server.serveraction.kerberos;
-import com.google.common.base.Optional;
import com.google.inject.Inject;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
@@ -145,7 +144,7 @@ public class CreatePrincipalsServerAction extends KerberosServerAction {
// This principal has been processed and a keytab file has been distributed... do not process it.
processPrincipal = false;
} else {
- // This principal has been processed but a keytab file for it has been distributed... process it.
+ // This principal has been processed but a keytab file for it has not been distributed... process it.
processPrincipal = true;
}
}
@@ -232,7 +231,7 @@ public class CreatePrincipalsServerAction extends KerberosServerAction {
String password = securePasswordHelper.createSecurePassword(length, minLowercaseLetters, minUppercaseLetters, minDigits, minPunctuation, minWhitespace);
try {
- /**
+ /*
* true indicates a new principal was created, false indicates an existing principal was updated
*/
boolean created;
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
index db210e0..1d8c1ca 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
@@ -28,6 +28,7 @@ import org.apache.ambari.server.security.credential.PrincipalKeyCredential;
import org.apache.ambari.server.serveraction.AbstractServerAction;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.utils.StageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -514,12 +515,19 @@ public abstract class KerberosServerAction extends AbstractServerAction {
if (record != null) {
String principal = record.get(KerberosIdentityDataFileReader.PRINCIPAL);
- String host = record.get(KerberosIdentityDataFileReader.HOSTNAME);
if (principal != null) {
+ String hostname = record.get(KerberosIdentityDataFileReader.HOSTNAME);
+
+ if(KerberosHelper.AMBARI_SERVER_HOST_NAME.equals(hostname)) {
+ // Replace KerberosHelper.AMBARI_SERVER_HOST_NAME with the actual hostname where the Ambari
+ // server is... this host
+ hostname = StageUtils.getHostName();
+ }
+
// Evaluate the principal "pattern" found in the record to generate the "evaluated principal"
// by replacing the _HOST and _REALM variables.
- String evaluatedPrincipal = principal.replace("_HOST", host).replace("_REALM", defaultRealm);
+ String evaluatedPrincipal = principal.replace("_HOST", hostname).replace("_REALM", defaultRealm);
commandReport = processIdentity(record, evaluatedPrincipal, operationHandler, kerberosConfiguration, requestSharedDataContext);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml b/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml
index a86973c..500c0bf 100644
--- a/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml
+++ b/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml
@@ -30,16 +30,11 @@
<custom-filter ref="ambariAuthorizationFilter" before="FILTER_SECURITY_INTERCEPTOR"/>
</http>
- <!--<ldap-server id="ldapServer" root="dc=ambari,dc=apache,dc=org"/>-->
-
<authentication-manager alias="authenticationManager">
-
<authentication-provider ref="ambariLocalAuthenticationProvider"/>
-
<authentication-provider ref="ambariLdapAuthenticationProvider"/>
-
<authentication-provider ref="ambariInternalAuthenticationProvider"/>
-
+ <authentication-provider ref="kerberosServiceAuthenticationProvider"/>
</authentication-manager>
<beans:bean id="ambariEntryPoint" class="org.apache.ambari.server.security.AmbariEntryPoint">
@@ -49,6 +44,7 @@
<beans:constructor-arg>
<beans:list>
<beans:ref bean="ambariBasicAuthenticationFilter"/>
+ <beans:ref bean="ambariKerberosAuthenticationFilter"/>
<beans:ref bean="ambariJwtAuthenticationFilter"/>
</beans:list>
</beans:constructor-arg>
@@ -69,6 +65,14 @@
<beans:constructor-arg ref="permissionHelper"/>
</beans:bean>
+ <beans:bean id="ambariKerberosAuthenticationFilter" class="org.apache.ambari.server.security.authentication.kerberos.AmbariKerberosAuthenticationFilter">
+ <beans:constructor-arg ref="authenticationManager"/>
+ <beans:constructor-arg ref="ambariEntryPoint"/>
+ <beans:constructor-arg ref="ambariConfiguration"/>
+ <beans:constructor-arg ref="auditLogger"/>
+ <beans:constructor-arg ref="permissionHelper"/>
+ </beans:bean>
+
<beans:bean id="ambariAuthorizationFilter" class="org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter">
<beans:constructor-arg ref="ambariEntryPoint"/>
<beans:constructor-arg ref="ambariConfiguration"/>
@@ -77,4 +81,20 @@
<beans:constructor-arg ref="permissionHelper"/>
</beans:bean>
+ <beans:bean id="kerberosServiceAuthenticationProvider" class="org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider">
+ <beans:property name="ticketValidator">
+ <beans:bean class="org.apache.ambari.server.security.authentication.kerberos.AmbariKerberosTicketValidator">
+ <beans:constructor-arg ref="ambariConfiguration"/>
+ <beans:property name="debug" value="false"/>
+ </beans:bean>
+ </beans:property>
+
+ <beans:property name="userDetailsService" ref="authToLocalUserDetailsService"/>
+ </beans:bean>
+
+ <beans:bean id="authToLocalUserDetailsService" class="org.apache.ambari.server.security.authentication.kerberos.AmbariAuthToLocalUserDetailsService">
+ <beans:constructor-arg ref="ambariConfiguration"/>
+ <beans:constructor-arg ref="ambariUsers"/>
+ </beans:bean>
+
</beans:beans>
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
index 3c97ce9..7e6a056 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
@@ -104,7 +104,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
-import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -3755,6 +3754,7 @@ public class KerberosHelperTest extends EasyMockSupport {
KerberosDescriptor kerberosDescriptor = createMock(KerberosDescriptor.class);
if (createAmbariPrincipal) {
expect(kerberosDescriptor.getIdentity(KerberosHelper.AMBARI_IDENTITY_NAME)).andReturn(ambariKerberosIdentity).once();
+ expect(kerberosDescriptor.getIdentity(KerberosHelper.SPNEGO_IDENTITY_NAME)).andReturn(ambariKerberosIdentity).once();
}
List<KerberosIdentityDescriptor> identities = new ArrayList<KerberosIdentityDescriptor>();
@@ -3764,12 +3764,12 @@ public class KerberosHelperTest extends EasyMockSupport {
// Needed by infrastructure
injector.getInstance(AmbariMetaInfo.class).init();
- kerberosHelper.addAmbariServerIdentity(kerberosEnvProperties, kerberosDescriptor, identities);
+ kerberosHelper.addAmbariServerIdentities(kerberosEnvProperties, kerberosDescriptor, identities);
verifyAll();
if (createAmbariPrincipal) {
- Assert.assertEquals(1, identities.size());
+ Assert.assertEquals(2, identities.size());
Assert.assertSame(ambariKerberosIdentity, identities.get(0));
} else {
Assert.assertTrue(identities.isEmpty());
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java
new file mode 100644
index 0000000..e980808
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.security.authentication.kerberos;
+
+import junit.framework.Assert;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.security.authorization.AmbariGrantedAuthority;
+import org.apache.ambari.server.security.authorization.User;
+import org.apache.ambari.server.security.authorization.UserType;
+import org.apache.ambari.server.security.authorization.Users;
+import org.easymock.EasyMockSupport;
+import org.junit.Test;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.easymock.EasyMock.expect;
+
+public class AmbariAuthToLocalUserDetailsServiceTest extends EasyMockSupport {
+ @Test
+ public void loadUserByUsernameSuccess() throws Exception {
+ AmbariKerberosAuthenticationProperties properties = new AmbariKerberosAuthenticationProperties();
+
+ Configuration configuration = createMock(Configuration.class);
+ expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once();
+
+ User user = createMock(User.class);
+ expect(user.getUserName()).andReturn("user1").once();
+ expect(user.getUserType()).andReturn(UserType.LDAP).once();
+
+ Collection<AmbariGrantedAuthority> userAuthorities = Collections.singletonList(createNiceMock(AmbariGrantedAuthority.class));
+
+ Users users = createMock(Users.class);
+ expect(users.getUser("user1", UserType.LDAP)).andReturn(user).once();
+ expect(users.getUserAuthorities("user1", UserType.LDAP)).andReturn(userAuthorities).once();
+
+ replayAll();
+
+ UserDetailsService userdetailsService = new AmbariAuthToLocalUserDetailsService(configuration, users);
+
+ UserDetails userDetails = userdetailsService.loadUserByUsername("user1@EXAMPLE.COM");
+
+ verifyAll();
+
+ Assert.assertNotNull(userDetails);
+ Assert.assertEquals("user1", userDetails.getUsername());
+ Assert.assertEquals(userAuthorities.size(), userDetails.getAuthorities().size());
+ Assert.assertEquals("", userDetails.getPassword());
+ }
+
+ @Test(expected = UsernameNotFoundException.class)
+ public void loadUserByUsernameUserNotFound() throws Exception {
+ AmbariKerberosAuthenticationProperties properties = new AmbariKerberosAuthenticationProperties();
+
+ Configuration configuration = createMock(Configuration.class);
+ expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once();
+
+ Users users = createMock(Users.class);
+ expect(users.getUser("user1", UserType.LDAP)).andReturn(null).once();
+ expect(users.getUser("user1", UserType.LOCAL)).andReturn(null).once();
+
+ replayAll();
+
+ UserDetailsService userdetailsService = new AmbariAuthToLocalUserDetailsService(configuration, users);
+
+ userdetailsService.loadUserByUsername("user1@EXAMPLE.COM");
+
+ verifyAll();
+
+ Assert.fail("UsernameNotFoundException was not thrown");
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationFilterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationFilterTest.java
new file mode 100644
index 0000000..d855cda
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationFilterTest.java
@@ -0,0 +1,133 @@
+/*
+ * 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.security.authentication.kerberos;
+
+import org.apache.ambari.server.audit.AuditLogger;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.security.authorization.PermissionHelper;
+import org.easymock.EasyMockSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.web.AuthenticationEntryPoint;
+
+import javax.servlet.http.HttpServletRequest;
+
+import static org.easymock.EasyMock.expect;
+
+public class AmbariKerberosAuthenticationFilterTest extends EasyMockSupport {
+ @Test
+ public void shouldApplyTrue() throws Exception {
+ HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
+ expect(httpServletRequest.getHeader("Authorization")).andReturn("Negotiate .....").once();
+
+ AmbariKerberosAuthenticationProperties properties = createMock(AmbariKerberosAuthenticationProperties.class);
+ expect(properties.isKerberosAuthenticationEnabled()).andReturn(true).once();
+
+ Configuration configuration = createMock(Configuration.class);
+ expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once();
+
+ AuthenticationManager authenticationManager = createMock(AuthenticationManager.class);
+ AuthenticationEntryPoint entryPoint = createMock(AuthenticationEntryPoint.class);
+ AuditLogger auditLogger = createMock(AuditLogger.class);
+ PermissionHelper permissionHelper = createMock(PermissionHelper.class);
+
+ replayAll();
+
+ AmbariKerberosAuthenticationFilter filter = new AmbariKerberosAuthenticationFilter(
+ authenticationManager,
+ entryPoint,
+ configuration,
+ auditLogger,
+ permissionHelper
+ );
+
+ Assert.assertTrue(filter.shouldApply(httpServletRequest));
+
+ verifyAll();
+ }
+
+ @Test
+ public void shouldApplyFalseMissingHeader() throws Exception {
+ HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
+ expect(httpServletRequest.getHeader("Authorization")).andReturn(null).once();
+
+ AmbariKerberosAuthenticationProperties properties = createMock(AmbariKerberosAuthenticationProperties.class);
+ expect(properties.isKerberosAuthenticationEnabled()).andReturn(true).once();
+
+ Configuration configuration = createMock(Configuration.class);
+ expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once();
+
+ AuthenticationManager authenticationManager = createMock(AuthenticationManager.class);
+ AuthenticationEntryPoint entryPoint = createMock(AuthenticationEntryPoint.class);
+ AuditLogger auditLogger = createMock(AuditLogger.class);
+ PermissionHelper permissionHelper = createMock(PermissionHelper.class);
+
+ replayAll();
+
+ AmbariKerberosAuthenticationFilter filter = new AmbariKerberosAuthenticationFilter(
+ authenticationManager,
+ entryPoint,
+ configuration,
+ auditLogger,
+ permissionHelper
+ );
+
+ Assert.assertFalse(filter.shouldApply(httpServletRequest));
+
+ verifyAll();
+ }
+
+ @Test
+ public void shouldApplyNotFalseEnabled() throws Exception {
+ HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
+
+ AmbariKerberosAuthenticationProperties properties = createMock(AmbariKerberosAuthenticationProperties.class);
+ expect(properties.isKerberosAuthenticationEnabled()).andReturn(false).once();
+
+ Configuration configuration = createMock(Configuration.class);
+ expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once();
+
+ AuthenticationManager authenticationManager = createMock(AuthenticationManager.class);
+ AuthenticationEntryPoint entryPoint = createMock(AuthenticationEntryPoint.class);
+ AuditLogger auditLogger = createMock(AuditLogger.class);
+ PermissionHelper permissionHelper = createMock(PermissionHelper.class);
+
+ replayAll();
+
+ AmbariKerberosAuthenticationFilter filter = new AmbariKerberosAuthenticationFilter(
+ authenticationManager,
+ entryPoint,
+ configuration,
+ auditLogger,
+ permissionHelper
+ );
+
+ Assert.assertFalse(filter.shouldApply(httpServletRequest));
+
+ verifyAll();
+ }
+
+ @Test
+ public void doFilter() throws Exception {
+ // Skip this test since the real work is being done by SpnegoAuthenticationProcessingFilter, which
+ // is a class in the Spring libraries.
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4320b5a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosTicketValidatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosTicketValidatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosTicketValidatorTest.java
new file mode 100644
index 0000000..9bc87a4
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosTicketValidatorTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.security.authentication.kerberos;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.easymock.EasyMockSupport;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.expect;
+
+public class AmbariKerberosTicketValidatorTest extends EasyMockSupport {
+
+ /**
+ * Tests an {@link AmbariKerberosTicketValidator} to ensure that the Spnego identity is properly
+ * set in the base class during construction.
+ */
+ @Test
+ public void testConstructor() throws NoSuchMethodException {
+ AmbariKerberosAuthenticationProperties properties = createMock(AmbariKerberosAuthenticationProperties.class);
+ expect(properties.isKerberosAuthenticationEnabled()).andReturn(true).once();
+ expect(properties.getSpnegoPrincipalName()).andReturn("HTTP/somehost.example.com").times(1);
+ expect(properties.getSpnegoKeytabFilePath()).andReturn("/etc/security/keytabs/spnego.service.keytab").times(2);
+
+ Configuration configuration = createMock(Configuration.class);
+ expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once();
+
+ replayAll();
+
+ new AmbariKerberosTicketValidator(configuration);
+
+ verifyAll();
+ }
+}
\ No newline at end of file
[14/21] ambari git commit: AMBARI-17457 : Modify the AMS stack
scripts to support distributed collector (dsen via avijayan)
Posted by nc...@apache.org.
AMBARI-17457 : Modify the AMS stack scripts to support distributed collector (dsen via avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/875f1efb
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/875f1efb
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/875f1efb
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 875f1efb63cbbe81259a79c0b1530eba7ef2a3ec
Parents: 3b30de0
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Tue Sep 20 15:54:32 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Tue Sep 20 15:54:32 2016 -0700
----------------------------------------------------------------------
.../ambari_commons/ambari_metrics_helper.py | 5 +-
.../ambari_commons/parallel_processing.py | 95 ++++++++
.../package/scripts/metrics_grafana_util.py | 50 ++++-
.../0.1.0/package/scripts/params.py | 3 +
.../0.1.0/package/scripts/service_check.py | 225 ++++++++++---------
.../metrics_grafana_datasource.json.j2 | 2 +-
6 files changed, 266 insertions(+), 114 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/875f1efb/ambari-common/src/main/python/ambari_commons/ambari_metrics_helper.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/ambari_metrics_helper.py b/ambari-common/src/main/python/ambari_commons/ambari_metrics_helper.py
index 7b4e8f5..2eb0b6d 100644
--- a/ambari-common/src/main/python/ambari_commons/ambari_metrics_helper.py
+++ b/ambari-common/src/main/python/ambari_commons/ambari_metrics_helper.py
@@ -33,6 +33,9 @@ def select_metric_collector_for_sink(sink_name):
return select_metric_collector_hosts_from_hostnames(all_collectors_list)
def select_metric_collector_hosts_from_hostnames(hosts):
+ return get_random_host(hosts)
+
+def get_random_host(hosts):
return random.choice(hosts)
def get_metric_collectors_from_properties_file(sink_name):
@@ -53,4 +56,4 @@ def load_properties_from_file(filepath, sep='=', comment_char='#'):
key = key_value[0].strip()
value = sep.join(key_value[1:]).strip('" \t')
props[key] = value
- return props
\ No newline at end of file
+ return props
http://git-wip-us.apache.org/repos/asf/ambari/blob/875f1efb/ambari-common/src/main/python/ambari_commons/parallel_processing.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/parallel_processing.py b/ambari-common/src/main/python/ambari_commons/parallel_processing.py
new file mode 100644
index 0000000..c5a95de
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/parallel_processing.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+
+'''
+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.
+'''
+
+import logging
+from multiprocessing import Process, Queue
+
+logger = logging.getLogger()
+
+SUCCESS = "SUCCESS"
+FAILED = "FAILED"
+
+class PrallelProcessResult(object):
+ def __init__(self, element, status, result):
+ self.result = result
+ self.status = status
+ self.element = element
+
+class ParallelProcess(Process):
+
+
+ def __init__(self, function, element, params, queue):
+ self.function = function
+ self.element = element
+ self.params = params
+ self.queue = queue
+ super(ParallelProcess, self).__init__()
+
+ def return_name(self):
+ ## NOTE: self.name is an attribute of multiprocessing.Process
+ return "Process running function '%s' for element '%s'" % (self.function, self.element)
+
+ def run(self):
+ try:
+ result = self.function(self.element, self.params)
+ self.queue.put(PrallelProcessResult(self.element, SUCCESS, result))
+ except Exception as e:
+ self.queue.put(PrallelProcessResult(self.element, FAILED,
+ "Exception while running function '%s' for '%s'. Reason : %s" % (self.function, self.element, str(e))))
+ return
+
+def execute_in_parallel(function, array, params, wait_for_all = False):
+ logger.info("Started running %s for %s" % (function, array))
+ processs = []
+ q = Queue()
+ counter = len(array)
+ results = {}
+
+ for element in array:
+ process = ParallelProcess(function, element, params, q)
+ process.start()
+ processs.append(process)
+
+ while counter > 0:
+ tmp = q.get()
+ counter-=1
+ results[tmp.element] = tmp
+ if tmp.status == SUCCESS and not wait_for_all:
+ counter = 0
+
+ for process in processs:
+ process.terminate()
+
+ logger.info("Finished running %s for %s" % (function, array))
+
+ return results
+
+def func (elem, params):
+ if elem == 'S':
+ return "lalala"
+ else :
+ raise Exception('Exception')
+
+if __name__ == "__main__":
+ results = execute_in_parallel(func, ['F', 'BF', 'S'], None)
+ for result in results:
+ print results[result].element
+ print results[result].status
+ print results[result].result
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/875f1efb/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
index e8c12ed..b98dc1d 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
@@ -18,16 +18,21 @@ limitations under the License.
"""
import httplib
+
+from ambari_commons.parallel_processing import PrallelProcessResult, execute_in_parallel, SUCCESS
+from service_check import post_metrics_to_collector
from resource_management.core.logger import Logger
from resource_management.core.base import Fail
from resource_management import Template
from collections import namedtuple
from urlparse import urlparse
from base64 import b64encode
+import random
import time
import socket
import ambari_simplejson as json
import network
+import os
GRAFANA_CONNECT_TRIES = 5
GRAFANA_CONNECT_TIMEOUT = 10
@@ -171,20 +176,32 @@ def perform_grafana_delete_call(url, server):
return response
-def is_unchanged_datasource_url(datasource_url):
+def is_unchanged_datasource_url(grafana_datasource_url, new_datasource_host):
import params
- parsed_url = urlparse(datasource_url)
+ parsed_url = urlparse(grafana_datasource_url)
Logger.debug("parsed url: scheme = %s, host = %s, port = %s" % (
parsed_url.scheme, parsed_url.hostname, parsed_url.port))
Logger.debug("collector: scheme = %s, host = %s, port = %s" %
- (params.metric_collector_protocol, params.metric_collector_host,
+ (params.metric_collector_protocol, new_datasource_host,
params.metric_collector_port))
return parsed_url.scheme.strip() == params.metric_collector_protocol.strip() and \
- parsed_url.hostname.strip() == params.metric_collector_host.strip() and \
+ parsed_url.hostname.strip() == new_datasource_host.strip() and \
str(parsed_url.port) == params.metric_collector_port
+def do_ams_collector_post(metric_collector_host, params):
+ ams_metrics_post_url = "/ws/v1/timeline/metrics/"
+ random_value1 = random.random()
+ headers = {"Content-type": "application/json"}
+ ca_certs = os.path.join(params.ams_collector_conf_dir,
+ params.metric_truststore_ca_certs)
+
+ current_time = int(time.time()) * 1000
+ metric_json = Template('smoketest_metrics.json.j2', hostname=params.hostname, random1=random_value1,
+ current_time=current_time).get_content()
+ post_metrics_to_collector(ams_metrics_post_url, metric_collector_host, params.metric_collector_port, params.metric_collector_https_enabled,
+ metric_json, headers, ca_certs)
def create_ams_datasource():
import params
server = Server(protocol = params.ams_grafana_protocol.strip(),
@@ -196,11 +213,28 @@ def create_ams_datasource():
"""
Create AMS datasource in Grafana, if exsists make sure the collector url is accurate
"""
- ams_datasource_json = Template('metrics_grafana_datasource.json.j2',
- ams_datasource_name=METRICS_GRAFANA_DATASOURCE_NAME).get_content()
+ Logger.info("Trying to find working metric collector")
+ results = execute_in_parallel(do_ams_collector_post, params.ams_collector_hosts, params)
+ new_datasource_host = ""
+
+ for host in params.ams_collector_hosts:
+ if host in results:
+ if results[host].status == SUCCESS:
+ new_datasource_host = host
+ Logger.info("Found working collector on host %s" % new_datasource_host)
+ break
+ else:
+ Logger.warning(results[host].result)
- Logger.info("Checking if AMS Grafana datasource already exists")
+ if new_datasource_host == "":
+ Logger.warning("All metric collectors are unavailable. Will use random collector as datasource host.")
+ new_datasource_host = params.random_metric_collector_host
+
+ Logger.info("New datasource host will be %s" % new_datasource_host)
+ ams_datasource_json = Template('metrics_grafana_datasource.json.j2',
+ ams_datasource_name=METRICS_GRAFANA_DATASOURCE_NAME, ams_datasource_host=new_datasource_host).get_content()
+ Logger.info("Checking if AMS Grafana datasource already exists")
response = perform_grafana_get_call(GRAFANA_DATASOURCE_URL, server)
create_datasource = True
@@ -215,7 +249,7 @@ def create_ams_datasource():
Logger.info("Ambari Metrics Grafana datasource already present. Checking Metrics Collector URL")
datasource_url = datasources_json[i]["url"]
- if is_unchanged_datasource_url(datasource_url):
+ if is_unchanged_datasource_url(datasource_url, new_datasource_host):
Logger.info("Metrics Collector URL validation succeeded.")
return
else: # Metrics datasource present, but collector host is wrong.
http://git-wip-us.apache.org/repos/asf/ambari/blob/875f1efb/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
index 22024bb..6934924 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
@@ -120,6 +120,9 @@ if 'cluster-env' in config['configurations'] and \
metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
else:
metric_collector_host = select_metric_collector_hosts_from_hostnames(ams_collector_hosts)
+
+random_metric_collector_host = select_metric_collector_hosts_from_hostnames(ams_collector_hosts)
+
if 'cluster-env' in config['configurations'] and \
'metrics_collector_vip_port' in config['configurations']['cluster-env']:
metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
http://git-wip-us.apache.org/repos/asf/ambari/blob/875f1efb/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_check.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_check.py b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_check.py
index ddd3e42..56ca4a1 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_check.py
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_check.py
@@ -25,6 +25,7 @@ from resource_management import Template
from ambari_commons import OSConst
from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
+from ambari_commons.parallel_processing import PrallelProcessResult, execute_in_parallel, SUCCESS
import httplib
import network
@@ -39,10 +40,10 @@ import socket
class AMSServiceCheck(Script):
AMS_METRICS_POST_URL = "/ws/v1/timeline/metrics/"
AMS_METRICS_GET_URL = "/ws/v1/timeline/metrics?%s"
- AMS_CONNECT_TRIES = 30
- AMS_CONNECT_TIMEOUT = 15
- AMS_READ_TRIES = 10
- AMS_READ_TIMEOUT = 5
+ AMS_CONNECT_TRIES = 10
+ AMS_CONNECT_TIMEOUT = 10
+ AMS_READ_TRIES = 5
+ AMS_READ_TIMEOUT = 10
@OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
def service_check(self, env):
@@ -62,124 +63,140 @@ class AMSServiceCheck(Script):
if not check_windows_service_exists(params.ams_collector_win_service_name):
raise Fail("Metrics Collector service was not properly installed. Check the logs and retry the installation.")
- @OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
- def service_check(self, env):
- import params
-
- Logger.info("Ambari Metrics service check was started.")
- env.set_params(params)
-
+ def service_check_for_single_host(self, metric_collector_host, params):
random_value1 = random.random()
headers = {"Content-type": "application/json"}
ca_certs = os.path.join(params.ams_collector_conf_dir,
params.metric_truststore_ca_certs)
- for i in xrange(0, self.AMS_CONNECT_TRIES):
- try:
- current_time = int(time.time()) * 1000
- metric_json = Template('smoketest_metrics.json.j2', hostname=params.hostname, random1=random_value1,
+ current_time = int(time.time()) * 1000
+ metric_json = Template('smoketest_metrics.json.j2', hostname=params.hostname, random1=random_value1,
current_time=current_time).get_content()
- Logger.info("Generated metrics:\n%s" % metric_json)
-
- Logger.info("Connecting (POST) to %s:%s%s" % (params.metric_collector_host,
- params.metric_collector_port,
- self.AMS_METRICS_POST_URL))
- conn = network.get_http_connection(params.metric_collector_host,
+ try:
+ post_metrics_to_collector(self.AMS_METRICS_POST_URL, metric_collector_host, params.metric_collector_port, params.metric_collector_https_enabled,
+ metric_json, headers, ca_certs, self.AMS_CONNECT_TRIES, self.AMS_CONNECT_TIMEOUT)
+
+ get_metrics_parameters = {
+ "metricNames": "AMBARI_METRICS.SmokeTest.FakeMetric",
+ "appId": "amssmoketestfake",
+ "hostname": params.hostname,
+ "startTime": current_time - 60000,
+ "endTime": current_time + 61000,
+ "precision": "seconds",
+ "grouped": "false",
+ }
+ encoded_get_metrics_parameters = urllib.urlencode(get_metrics_parameters)
+
+ Logger.info("Connecting (GET) to %s:%s%s" % (metric_collector_host,
+ params.metric_collector_port,
+ self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters))
+ for i in xrange(0, self.AMS_READ_TRIES):
+ conn = network.get_http_connection(metric_collector_host,
int(params.metric_collector_port),
params.metric_collector_https_enabled,
ca_certs)
- conn.request("POST", self.AMS_METRICS_POST_URL, metric_json, headers)
-
+ conn.request("GET", self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters)
response = conn.getresponse()
- Logger.info("Http response: %s %s" % (response.status, response.reason))
- except (httplib.HTTPException, socket.error) as ex:
- if i < self.AMS_CONNECT_TRIES - 1: #range/xrange returns items from start to end-1
- time.sleep(self.AMS_CONNECT_TIMEOUT)
- Logger.info("Connection failed. Next retry in %s seconds."
- % (self.AMS_CONNECT_TIMEOUT))
- continue
- else:
- raise Fail("Metrics were not saved. Service check has failed. "
- "\nConnection failed.")
+ Logger.info("Http response for host %s : %s %s" % (metric_collector_host, response.status, response.reason))
- data = response.read()
- Logger.info("Http data: %s" % data)
- conn.close()
+ data = response.read()
+ Logger.info("Http data: %s" % data)
+ conn.close()
- if response.status == 200:
- Logger.info("Metrics were saved.")
- break
- else:
- Logger.info("Metrics were not saved. Service check has failed.")
- if i < self.AMS_CONNECT_TRIES - 1: #range/xrange returns items from start to end-1
- time.sleep(self.AMS_CONNECT_TIMEOUT)
- Logger.info("Next retry in %s seconds."
- % (self.AMS_CONNECT_TIMEOUT))
+ if response.status == 200:
+ Logger.info("Metrics were retrieved from host %s" % metric_collector_host)
+ else:
+ raise Fail("Metrics were not retrieved from host %s. GET request status: %s %s \n%s" %
+ (metric_collector_host, response.status, response.reason, data))
+ data_json = json.loads(data)
+
+ def floats_eq(f1, f2, delta):
+ return abs(f1-f2) < delta
+
+ values_are_present = False
+ for metrics_data in data_json["metrics"]:
+ if (str(current_time) in metrics_data["metrics"] and str(current_time + 1000) in metrics_data["metrics"]
+ and floats_eq(metrics_data["metrics"][str(current_time)], random_value1, 0.0000001)
+ and floats_eq(metrics_data["metrics"][str(current_time + 1000)], current_time, 1)):
+ Logger.info("Values %s and %s were found in the response from host %s." % (metric_collector_host, random_value1, current_time))
+ values_are_present = True
+ break
+ pass
+
+ if not values_are_present:
+ if i < self.AMS_READ_TRIES - 1: #range/xrange returns items from start to end-1
+ Logger.info("Values weren't stored yet. Retrying in %s seconds."
+ % (self.AMS_READ_TIMEOUT))
+ time.sleep(self.AMS_READ_TIMEOUT)
+ else:
+ raise Fail("Values %s and %s were not found in the response." % (random_value1, current_time))
else:
- raise Fail("Metrics were not saved. Service check has failed. POST request status: %s %s \n%s" %
- (response.status, response.reason, data))
-
- get_metrics_parameters = {
- "metricNames": "AMBARI_METRICS.SmokeTest.FakeMetric",
- "appId": "amssmoketestfake",
- "hostname": params.hostname,
- "startTime": current_time - 60000,
- "endTime": current_time + 61000,
- "precision": "seconds",
- "grouped": "false",
- }
- encoded_get_metrics_parameters = urllib.urlencode(get_metrics_parameters)
-
- Logger.info("Connecting (GET) to %s:%s%s" % (params.metric_collector_host,
- params.metric_collector_port,
- self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters))
- for i in xrange(0, self.AMS_READ_TRIES):
- conn = network.get_http_connection(params.metric_collector_host,
- int(params.metric_collector_port),
- params.metric_collector_https_enabled,
- ca_certs)
- conn.request("GET", self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters)
- response = conn.getresponse()
- Logger.info("Http response: %s %s" % (response.status, response.reason))
-
- data = response.read()
- Logger.info("Http data: %s" % data)
- conn.close()
-
- if response.status == 200:
- Logger.info("Metrics were retrieved.")
- else:
- Logger.info("Metrics were not retrieved. Service check has failed.")
- raise Fail("Metrics were not retrieved. Service check has failed. GET request status: %s %s \n%s" %
- (response.status, response.reason, data))
- data_json = json.loads(data)
-
- def floats_eq(f1, f2, delta):
- return abs(f1-f2) < delta
-
- values_are_present = False
- for metrics_data in data_json["metrics"]:
- if (str(current_time) in metrics_data["metrics"] and str(current_time + 1000) in metrics_data["metrics"]
- and floats_eq(metrics_data["metrics"][str(current_time)], random_value1, 0.0000001)
- and floats_eq(metrics_data["metrics"][str(current_time + 1000)], current_time, 1)):
- Logger.info("Values %s and %s were found in the response." % (random_value1, current_time))
- values_are_present = True
break
pass
+ except Fail as ex:
+ Logger.warning("Ambari Metrics service check failed on collector host %s. Reason : %s" % (metric_collector_host, str(ex)))
+ raise Fail("Ambari Metrics service check failed on collector host %s. Reason : %s" % (metric_collector_host, str(ex)))
+
+ @OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
+ def service_check(self, env):
+ import params
+
+ Logger.info("Ambari Metrics service check was started.")
+ env.set_params(params)
+
+ results = execute_in_parallel(self.service_check_for_single_host, params.ams_collector_hosts, params)
- if not values_are_present:
- if i < self.AMS_READ_TRIES - 1: #range/xrange returns items from start to end-1
- Logger.info("Values weren't stored yet. Retrying in %s seconds."
- % (self.AMS_READ_TIMEOUT))
- time.sleep(self.AMS_READ_TIMEOUT)
+ for host in params.ams_collector_hosts:
+ if host in results:
+ if results[host].status == SUCCESS:
+ Logger.info("Ambari Metrics service check passed on host " + host)
+ return
else:
- Logger.info("Values %s and %s were not found in the response." % (random_value1, current_time))
- raise Fail("Values %s and %s were not found in the response." % (random_value1, current_time))
- else:
- break
- pass
- Logger.info("Ambari Metrics service check is finished.")
+ Logger.warning(results[host].result)
+ raise Fail("All metrics collectors are unavailable.")
+
+def post_metrics_to_collector(ams_metrics_post_url, metric_collector_host, metric_collector_port, metric_collector_https_enabled,
+ metric_json, headers, ca_certs, tries = 1, connect_timeout = 10):
+ for i in xrange(0, tries):
+ try:
+ Logger.info("Generated metrics for host %s :\n%s" % (metric_collector_host, metric_json))
+
+ Logger.info("Connecting (POST) to %s:%s%s" % (metric_collector_host,
+ metric_collector_port,
+ ams_metrics_post_url))
+ conn = network.get_http_connection(metric_collector_host,
+ int(metric_collector_port),
+ metric_collector_https_enabled,
+ ca_certs)
+ conn.request("POST", ams_metrics_post_url, metric_json, headers)
+ response = conn.getresponse()
+ Logger.info("Http response for host %s: %s %s" % (metric_collector_host, response.status, response.reason))
+ except (httplib.HTTPException, socket.error) as ex:
+ if i < tries - 1: #range/xrange returns items from start to end-1
+ time.sleep(connect_timeout)
+ Logger.info("Connection failed for host %s. Next retry in %s seconds."
+ % (metric_collector_host, connect_timeout))
+ continue
+ else:
+ raise Fail("Metrics were not saved. Connection failed.")
+
+ data = response.read()
+ Logger.info("Http data: %s" % data)
+ conn.close()
+
+ if response.status == 200:
+ Logger.info("Metrics were saved.")
+ break
+ else:
+ Logger.info("Metrics were not saved.")
+ if i < tries - 1: #range/xrange returns items from start to end-1
+ time.sleep(tries)
+ Logger.info("Next retry in %s seconds."
+ % (tries))
+ else:
+ raise Fail("Metrics were not saved. POST request status: %s %s \n%s" %
+ (response.status, response.reason, data))
if __name__ == "__main__":
AMSServiceCheck().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/875f1efb/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metrics_grafana_datasource.json.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metrics_grafana_datasource.json.j2 b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metrics_grafana_datasource.json.j2
index 678d769..30870c4 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metrics_grafana_datasource.json.j2
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metrics_grafana_datasource.json.j2
@@ -20,7 +20,7 @@
"name": "{{ams_datasource_name}}",
"type": "ambarimetrics",
"access": "proxy",
- "url": "{{metric_collector_protocol}}://{{metric_collector_host}}:{{metric_collector_port}}",
+ "url": "{{metric_collector_protocol}}://{{ams_datasource_host}}:{{metric_collector_port}}",
"password": "",
"user": "",
"database": "",
[04/21] ambari git commit: AMBARI-18421. Link Creation of user with
special character passes but on loading user page,
there is a warning message displayed. (alexantonenko)
Posted by nc...@apache.org.
AMBARI-18421. Link Creation of user with special character passes but on loading user page, there is a warning message displayed. (alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b4f3809e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b4f3809e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b4f3809e
Branch: refs/heads/branch-dev-patch-upgrade
Commit: b4f3809e4c32e9c9aa8a6700608413fc89a23c63
Parents: 468764e
Author: Alex Antonenko <hi...@gmail.com>
Authored: Mon Sep 19 21:25:54 2016 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Mon Sep 19 21:26:08 2016 +0300
----------------------------------------------------------------------
.../ui/admin-web/app/scripts/i18n.config.js | 2 ++
.../ui/admin-web/app/views/users/create.html | 18 ++++++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4f3809e/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
index 0aefaba..bc16f0e 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
@@ -336,6 +336,8 @@ angular.module('ambariAdminConsole')
'showAll': 'Show all users',
'showAdmin': 'Show only admin users',
'groupMembership': 'Group Membership',
+ 'userNameTip': 'Only alpha-numeric characters, up to 80 characters',
+
'changeStatusConfirmation': {
'title': 'Change Status',
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4f3809e/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html
index bc86819..cc5d8d4 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html
@@ -23,8 +23,22 @@
<form class="form-horizontal create-user-form" role="form" novalidate name="form" autocomplete="off">
<div class="form-group" ng-class="{'has-error' : form.user_name.$error.required && form.submitted}">
<label for="username" class="col-sm-2 control-label">{{'users.username' | translate}}</label>
- <div class="col-sm-10">
- <input type="text" id="username" class="form-control username-input" name="user_name" placeholder="{{'users.userName' | translate}}" ng-model="user.user_name" required autocomplete="off">
+ <div class="col-sm-10"
+ ng-class="{'has-error': form.user_name.$error.pattern}">
+ <input
+ autofocus
+ type="text"
+ id="username"
+ class="form-control username-input"
+ name="user_name"
+ placeholder="{{'users.userName' | translate}}"
+ ng-model="user.user_name"
+ ng-required="true"
+ ng-pattern="/^\w*$/"
+ ng-maxlength="80"
+ tooltip="{{'users.userNameTip' | translate}}"
+ autocomplete="off"
+ tooltip-trigger="focus">
<div class="alert alert-danger top-margin" ng-show="form.user_name.$error.required && form.submitted">{{'common.alerts.fieldIsRequired' | translate}}</div>
</div>
</div>
[08/21] ambari git commit: AMBARI-18180 Add ES6 support to Ambari
Web. (ababiichuk)
Posted by nc...@apache.org.
AMBARI-18180 Add ES6 support to Ambari Web. (ababiichuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a9bbf464
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a9bbf464
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a9bbf464
Branch: refs/heads/branch-dev-patch-upgrade
Commit: a9bbf4644890690c45e9879f7bda9ff9d0ec7000
Parents: f90b55a
Author: ababiichuk <ab...@hortonworks.com>
Authored: Thu Aug 25 16:15:22 2016 +0300
Committer: ababiichuk <ab...@hortonworks.com>
Committed: Tue Sep 20 11:19:32 2016 +0300
----------------------------------------------------------------------
.../views/common/widget/graph_widget_view.js | 7 +-
ambari-web/brunch-config.js | 125 +++++++++++++++++++
ambari-web/config.coffee | 112 -----------------
ambari-web/package.json | 1 +
4 files changed, 129 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/a9bbf464/ambari-web/app/views/common/widget/graph_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/widget/graph_widget_view.js b/ambari-web/app/views/common/widget/graph_widget_view.js
index 2ee76be..324358e 100644
--- a/ambari-web/app/views/common/widget/graph_widget_view.js
+++ b/ambari-web/app/views/common/widget/graph_widget_view.js
@@ -351,12 +351,11 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, App.ExportMetricsMixin, {
if (!arguments.length || this.get('parentView.data.length')) {
this.loadData();
}
- var self = this;
Em.run.next(function () {
if (self.get('isPreview')) {
- App.tooltip(this.$("[rel='ZoomInTooltip']"), 'disable');
+ App.tooltip(self.$("[rel='ZoomInTooltip']"), 'disable');
} else {
- App.tooltip(this.$("[rel='ZoomInTooltip']"), {
+ App.tooltip(self.$("[rel='ZoomInTooltip']"), {
placement: 'left',
template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner graph-tooltip"></div></div>'
});
@@ -382,4 +381,4 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, App.ExportMetricsMixin, {
App.showAlertPopup(Em.I18n.t('graphs.noData.title'), Em.I18n.t('graphs.noData.tooltip.title'));
}
}
-});
\ No newline at end of file
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/a9bbf464/ambari-web/brunch-config.js
----------------------------------------------------------------------
diff --git a/ambari-web/brunch-config.js b/ambari-web/brunch-config.js
new file mode 100644
index 0000000..64ac946
--- /dev/null
+++ b/ambari-web/brunch-config.js
@@ -0,0 +1,125 @@
+/**
+ * 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.
+ */
+
+
+module.exports.config = {
+ plugins: {
+ babel: {
+ ignore: [
+ /^(vendor|app\/data|app\/assets|test)/
+ ],
+ pattern: /\.(js)$/
+ }
+ },
+ files: {
+ javascripts: {
+ joinTo: {
+ 'javascripts/app.js': /^app/,
+ 'javascripts/vendor.js': /^vendor/,
+ 'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/,
+ 'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
+ },
+ order: {
+ before: [
+ 'vendor/scripts/console-helper.js',
+ 'vendor/scripts/jquery-1.7.2.min.js',
+ 'vendor/scripts/handlebars-1.0.0.beta.6.js',
+ 'vendor/scripts/ember-latest.js',
+ 'vendor/scripts/ember-data-latest.js',
+ 'vendor/scripts/ember-i18n-1.4.1.js',
+ 'vendor/scripts/bootstrap.js',
+ 'vendor/scripts/bootstrap-combobox.js',
+ 'vendor/scripts/bootstrap-checkbox.js',
+ 'vendor/scripts/bootstrap-slider.min.js',
+ 'vendor/scripts/bootstrap-switch.min.js',
+ 'vendor/scripts/d3.v2.js',
+ 'vendor/scripts/cubism.v1.js',
+ 'vendor/scripts/jquery.ui.core.js',
+ 'vendor/scripts/jquery.ui.position.js',
+ 'vendor/scripts/jquery.ui.widget.js',
+ 'vendor/scripts/jquery.ui.autocomplete.js',
+ 'vendor/scripts/jquery.ui.mouse.js',
+ 'vendor/scripts/jquery.ui.datepicker.js',
+ 'vendor/scripts/jquery-ui-timepicker-addon.js',
+ 'vendor/scripts/jquery.ui.slider.js',
+ 'vendor/scripts/jquery.ui.sortable.js',
+ 'vendor/scripts/jquery.ui.custom-effects.js',
+ 'vendor/scripts/jquery.timeago.js',
+ 'vendor/scripts/jquery.ajax-retry.js',
+ 'vendor/scripts/jquery.sticky-kit.js',
+ 'vendor/scripts/underscore.js',
+ 'vendor/scripts/backbone.js',
+ 'vendor/scripts/difflib.js',
+ 'vendor/scripts/diffview.js',
+ 'vendor/scripts/visualsearch.js',
+ 'vendor/scripts/moment.min.js',
+ 'vendor/scripts/moment-timezone-with-data-2010-2020.js',
+ 'vendor/scripts/workflow_visualization.js',
+ 'vendor/scripts/rickshaw.js',
+ 'vendor/scripts/spin.js',
+ 'vendor/scripts/jquery.flexibleArea.js',
+ 'vendor/scripts/FileSaver.js',
+ 'vendor/scripts/Blob.js'
+ ]
+ }
+ },
+ stylesheets: {
+ defaultExtension: 'css',
+ joinTo: {
+ 'stylesheets/app.css': /^app/,
+ 'stylesheets/vendor.css': /^vendor/
+ },
+ order: {
+ before: [
+ 'vendor/styles/bootstrap.css',
+ 'vendor/styles/font-awesome.css',
+ 'vendor/styles/font-awesome-ie7.css',
+ 'vendor/styles/cubism.css',
+ 'vendor/styles/rickshaw.css',
+ 'vendor/styles/bootstrap-combobox.css',
+ 'vendor/styles/bootstrap-checkbox.css',
+ 'vendor/styles/bootstrap-slider.min.css',
+ 'vendor/styles/bootstrap-switch.min.css',
+ 'vendor/styles/diffview.css',
+ 'vendor/styles/visualsearch-datauri.css'
+ ],
+ after: ['app/styles/custom-ui.css']
+ }
+ },
+
+
+ templates: {
+ precompile: true,
+ defaultExtensions: ['hbs'],
+ joinTo: {'javascripts/app.js': /^app/},
+ paths: {
+ jquery: 'vendor/scripts/jquery-1.7.2.min.js',
+ handlebars: 'vendor/scripts/handlebars-1.0.0.beta.6.js',
+ ember: 'vendor/scripts/ember-latest.js'
+ }
+ }
+ },
+
+ server: {
+ port: 3333,
+ base: '/',
+ run: 'no'
+ },
+
+ sourceMaps: false
+};
http://git-wip-us.apache.org/repos/asf/ambari/blob/a9bbf464/ambari-web/config.coffee
----------------------------------------------------------------------
diff --git a/ambari-web/config.coffee b/ambari-web/config.coffee
deleted file mode 100644
index 6a3f5ef..0000000
--- a/ambari-web/config.coffee
+++ /dev/null
@@ -1,112 +0,0 @@
-# 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.
-
-
-fs = require 'fs'
-path = require 'path'
-
-# See docs at http://brunch.readthedocs.org/en/latest/config.html.
-
-exports.config =
-
- files:
-
- javascripts:
- joinTo:
- 'javascripts/app.js': /^app/
- 'javascripts/vendor.js': /^vendor/
- 'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/
- 'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
- order:
- before: [
- 'vendor/scripts/console-helper.js',
- 'vendor/scripts/jquery-1.7.2.min.js',
- 'vendor/scripts/handlebars-1.0.0.beta.6.js',
- 'vendor/scripts/ember-latest.js',
- 'vendor/scripts/ember-data-latest.js',
- 'vendor/scripts/ember-i18n-1.4.1.js',
- 'vendor/scripts/bootstrap.js',
- 'vendor/scripts/bootstrap-combobox.js',
- 'vendor/scripts/bootstrap-checkbox.js',
- 'vendor/scripts/bootstrap-slider.min.js',
- 'vendor/scripts/bootstrap-switch.min.js',
- 'vendor/scripts/d3.v2.js',
- 'vendor/scripts/cubism.v1.js',
- 'vendor/scripts/jquery.ui.core.js',
- 'vendor/scripts/jquery.ui.position.js',
- 'vendor/scripts/jquery.ui.widget.js',
- 'vendor/scripts/jquery.ui.autocomplete.js',
- 'vendor/scripts/jquery.ui.mouse.js',
- 'vendor/scripts/jquery.ui.datepicker.js',
- 'vendor/scripts/jquery-ui-timepicker-addon.js',
- 'vendor/scripts/jquery.ui.slider.js',
- 'vendor/scripts/jquery.ui.sortable.js',
- 'vendor/scripts/jquery.ui.custom-effects.js',
- 'vendor/scripts/jquery.timeago.js',
- 'vendor/scripts/jquery.ajax-retry.js',
- 'vendor/scripts/jquery.sticky-kit.js',
- 'vendor/scripts/underscore.js',
- 'vendor/scripts/backbone.js',
- 'vendor/scripts/difflib.js',
- 'vendor/scripts/diffview.js',
- 'vendor/scripts/visualsearch.js',
- 'vendor/scripts/moment.min.js',
- 'vendor/scripts/moment-timezone-with-data-2010-2020.js',
- 'vendor/scripts/workflow_visualization.js',
- 'vendor/scripts/rickshaw.js',
- 'vendor/scripts/spin.js',
- 'vendor/scripts/jquery.flexibleArea.js',
- 'vendor/scripts/FileSaver.js',
- 'vendor/scripts/Blob.js'
-
- ]
-
- stylesheets:
- defaultExtension: 'css'
- joinTo:
- 'stylesheets/app.css': /^app/
- 'stylesheets/vendor.css': /^vendor/
- order:
- before: [
- 'vendor/styles/bootstrap.css',
- 'vendor/styles/font-awesome.css',
- 'vendor/styles/font-awesome-ie7.css',
- 'vendor/styles/cubism.css',
- 'vendor/styles/rickshaw.css',
- 'vendor/styles/bootstrap-combobox.css',
- 'vendor/styles/bootstrap-checkbox.css',
- 'vendor/styles/bootstrap-slider.min.css',
- 'vendor/styles/bootstrap-switch.min.css',
- 'vendor/styles/diffview.css',
- 'vendor/styles/visualsearch-datauri.css'
- ],
- after: ['app/styles/custom-ui.css']
-
- templates:
- precompile: true
- defaultExtension: 'hbs'
- joinTo: 'javascripts/app.js' : /^app/
- paths:
- jquery: 'vendor/scripts/jquery-1.7.2.min.js'
- handlebars: 'vendor/scripts/handlebars-1.0.0.beta.6.js'
- ember: 'vendor/scripts/ember-latest.js'
-
- server:
- port: 3333
- base: '/'
- run: no
-
- sourceMaps: false
http://git-wip-us.apache.org/repos/asf/ambari/blob/a9bbf464/ambari-web/package.json
----------------------------------------------------------------------
diff --git a/ambari-web/package.json b/ambari-web/package.json
index 550d293..6702471 100644
--- a/ambari-web/package.json
+++ b/ambari-web/package.json
@@ -8,6 +8,7 @@
"url": "https://git-wip-us.apache.org/repos/asf/ambari/repo?p=ambari.git;a=summary"
},
"dependencies": {
+ "babel-brunch": "^5.1.2",
"javascript-brunch": ">= 1.0 < 1.5",
"css-brunch": ">= 1.0 < 1.5",
"uglify-js-brunch": ">= 1.0 < 1.5",
[07/21] ambari git commit: AMBARI-18369. Make Execute timeout to be
able to kill process trees which doesn't respond to SIGTERM (aonishuk)
Posted by nc...@apache.org.
AMBARI-18369. Make Execute timeout to be able to kill process trees which doesn't respond to SIGTERM (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f90b55a8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f90b55a8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f90b55a8
Branch: refs/heads/branch-dev-patch-upgrade
Commit: f90b55a8bde1baa6cf2321d63596f3b8329292d9
Parents: e54c31e
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Tue Sep 20 10:43:45 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Tue Sep 20 10:49:13 2016 +0300
----------------------------------------------------------------------
.../HIVE/0.12.0.2.0/package/alerts/alert_hive_metastore.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/f90b55a8/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_hive_metastore.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_hive_metastore.py b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_hive_metastore.py
index cd1eded..0873730 100644
--- a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_hive_metastore.py
+++ b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_hive_metastore.py
@@ -196,7 +196,7 @@ def execute(configurations={}, parameters={}, host_name=None):
try:
Execute(cmd, user=smokeuser,
path=["/bin/", "/usr/bin/", "/usr/sbin/", bin_dir],
- timeout=5,
+ timeout=int(check_command_timeout),
timeout_kill_strategy=TerminateStrategy.KILL_PROCESS_TREE,
)
[12/21] ambari git commit: AMBARI-18390 : Configuration warnings
during Add Service Wizard includes seemingly nonsensical heapsize
recommendations for AMS heap sizes. (avijayan)
Posted by nc...@apache.org.
AMBARI-18390 : Configuration warnings during Add Service Wizard includes seemingly nonsensical heapsize recommendations for AMS heap sizes. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/382eba15
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/382eba15
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/382eba15
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 382eba15e351df86da96e8d63cbdaf2fe8f4d867
Parents: b4320b5
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Tue Sep 20 13:56:57 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Tue Sep 20 13:56:57 2016 -0700
----------------------------------------------------------------------
.../stacks/HDP/2.0.6/services/stack_advisor.py | 106 ++++++++++++++-----
1 file changed, 81 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/382eba15/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py
index fd0dfed..800bfa2 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py
@@ -949,7 +949,8 @@ class HDP206StackAdvisor(DefaultStackAdvisor):
"STORM": {"storm-site": self.validateStormConfigurations},
"AMBARI_METRICS": {"ams-hbase-site": self.validateAmsHbaseSiteConfigurations,
"ams-hbase-env": self.validateAmsHbaseEnvConfigurations,
- "ams-site": self.validateAmsSiteConfigurations}
+ "ams-site": self.validateAmsSiteConfigurations,
+ "ams-env": self.validateAmsEnvConfigurations}
}
def validateMinMax(self, items, recommendedDefaults, configurations):
@@ -1139,7 +1140,6 @@ class HDP206StackAdvisor(DefaultStackAdvisor):
if logDirItem:
validationItems.extend([{"config-name": "hbase_log_dir", "item": logDirItem}])
- collector_heapsize = to_number(ams_env.get("metrics_collector_heapsize"))
hbase_master_heapsize = to_number(properties["hbase_master_heapsize"])
hbase_master_xmn_size = to_number(properties["hbase_master_xmn_size"])
hbase_regionserver_heapsize = to_number(properties["hbase_regionserver_heapsize"])
@@ -1230,27 +1230,25 @@ class HDP206StackAdvisor(DefaultStackAdvisor):
requiredMemory = getMemorySizeRequired(hostComponents, configurations)
unusedMemory = host["Hosts"]["total_mem"] * 1024 - requiredMemory # in bytes
- if unusedMemory > 4*gb: # warn user, if more than 4GB RAM is unused
- heapPropertyToIncrease = "hbase_regionserver_heapsize" if is_hbase_distributed else "hbase_master_heapsize"
- xmnPropertyToIncrease = "regionserver_xmn_size" if is_hbase_distributed else "hbase_master_xmn_size"
- recommended_collector_heapsize = int((unusedMemory - 4*gb)/5) + collector_heapsize*mb
+
+ heapPropertyToIncrease = "hbase_regionserver_heapsize" if is_hbase_distributed else "hbase_master_heapsize"
+ xmnPropertyToIncrease = "regionserver_xmn_size" if is_hbase_distributed else "hbase_master_xmn_size"
+ hbase_needs_increase = to_number(properties[heapPropertyToIncrease]) * mb < 32 * gb
+
+ if unusedMemory > 4*gb and hbase_needs_increase: # warn user, if more than 4GB RAM is unused
+
recommended_hbase_heapsize = int((unusedMemory - 4*gb)*4/5) + to_number(properties.get(heapPropertyToIncrease))*mb
recommended_hbase_heapsize = min(32*gb, recommended_hbase_heapsize) #Make sure heapsize <= 32GB
- recommended_xmn_size = round_to_n(0.12*recommended_hbase_heapsize/mb,128)
-
- if collector_heapsize < recommended_collector_heapsize or \
- to_number(properties[heapPropertyToIncrease]) < recommended_hbase_heapsize:
- collectorHeapsizeItem = self.getWarnItem("{0} MB RAM is unused on the host {1} based on components " \
- "assigned. Consider allocating {2} MB to " \
- "metrics_collector_heapsize in ams-env, " \
- "{3} MB to {4} in ams-hbase-env"
- .format(unusedMemory/mb, collectorHostName,
- recommended_collector_heapsize/mb,
- recommended_hbase_heapsize/mb,
+ recommended_hbase_heapsize = round_to_n(recommended_hbase_heapsize/mb,128) # Round to 128m multiple
+ if to_number(properties[heapPropertyToIncrease]) < recommended_hbase_heapsize:
+ hbaseHeapsizeItem = self.getWarnItem("Consider allocating {0} MB to {1} in ams-hbase-env to use up some "
+ "unused memory on host"
+ .format(recommended_hbase_heapsize,
heapPropertyToIncrease))
- validationItems.extend([{"config-name": heapPropertyToIncrease, "item": collectorHeapsizeItem}])
+ validationItems.extend([{"config-name": heapPropertyToIncrease, "item": hbaseHeapsizeItem}])
- if to_number(properties[xmnPropertyToIncrease]) < recommended_hbase_heapsize:
+ recommended_xmn_size = round_to_n(0.15*recommended_hbase_heapsize,128)
+ if to_number(properties[xmnPropertyToIncrease]) < recommended_xmn_size:
xmnPropertyToIncreaseItem = self.getWarnItem("Consider allocating {0} MB to use up some unused memory "
"on host".format(recommended_xmn_size))
validationItems.extend([{"config-name": xmnPropertyToIncrease, "item": xmnPropertyToIncreaseItem}])
@@ -1258,6 +1256,38 @@ class HDP206StackAdvisor(DefaultStackAdvisor):
return self.toConfigurationValidationProblems(validationItems, "ams-hbase-env")
+ def validateAmsEnvConfigurations(self, properties, recommendedDefaults, configurations, services, hosts):
+
+ ams_env = getSiteProperties(configurations, "ams-env")
+ mb = 1024 * 1024
+ gb = 1024 * mb
+ validationItems = []
+ collector_heapsize = to_number(ams_env.get("metrics_collector_heapsize"))
+ amsCollectorHosts = self.getComponentHostNames(services, "AMBARI_METRICS", "METRICS_COLLECTOR")
+ for collectorHostName in amsCollectorHosts:
+ for host in hosts["items"]:
+ if host["Hosts"]["host_name"] == collectorHostName:
+ hostComponents = []
+ for service in services["services"]:
+ for component in service["components"]:
+ if component["StackServiceComponents"]["hostnames"] is not None:
+ if collectorHostName in component["StackServiceComponents"]["hostnames"]:
+ hostComponents.append(component["StackServiceComponents"]["component_name"])
+
+ requiredMemory = getMemorySizeRequired(hostComponents, configurations)
+ unusedMemory = host["Hosts"]["total_mem"] * 1024 - requiredMemory # in bytes
+ collector_needs_increase = collector_heapsize * mb < 16 * gb
+
+ if unusedMemory > 4*gb and collector_needs_increase: # warn user, if more than 4GB RAM is unused
+ recommended_collector_heapsize = int((unusedMemory - 4*gb)/5) + collector_heapsize * mb
+ recommended_collector_heapsize = round_to_n(recommended_collector_heapsize/mb,128) # Round to 128m multiple
+ if collector_heapsize < recommended_collector_heapsize:
+ validation_msg = "Consider allocating {0} MB to metrics_collector_heapsize in ams-env to use up some " \
+ "unused memory on host"
+ collectorHeapsizeItem = self.getWarnItem(validation_msg.format(recommended_collector_heapsize))
+ validationItems.extend([{"config-name": "metrics_collector_heapsize", "item": collectorHeapsizeItem}])
+ pass
+ return self.toConfigurationValidationProblems(validationItems, "ams-env")
def getPreferredMountPoints(self, hostInfo):
@@ -1883,6 +1913,9 @@ def getHeapsizeProperties():
return { "NAMENODE": [{"config-name": "hadoop-env",
"property": "namenode_heapsize",
"default": "1024m"}],
+ "SECONDARY_NAMENODE": [{"config-name": "hadoop-env",
+ "property": "namenode_heapsize",
+ "default": "1024m"}],
"DATANODE": [{"config-name": "hadoop-env",
"property": "dtnode_heapsize",
"default": "1024m"}],
@@ -1892,9 +1925,15 @@ def getHeapsizeProperties():
"HBASE_MASTER": [{"config-name": "hbase-env",
"property": "hbase_master_heapsize",
"default": "1024m"}],
- "HIVE_CLIENT": [{"config-name": "hive-site",
- "property": "hive.heapsize",
- "default": "1024m"}],
+ "HIVE_CLIENT": [{"config-name": "hive-env",
+ "property": "hive.client.heapsize",
+ "default": "1024"}],
+ "HIVE_METASTORE": [{"config-name": "hive-env",
+ "property": "hive.metastore.heapsize",
+ "default": "1024"}],
+ "HIVE_SERVER": [{"config-name": "hive-env",
+ "property": "hive.heapsize",
+ "default": "1024"}],
"HISTORYSERVER": [{"config-name": "mapred-env",
"property": "jobhistory_heapsize",
"default": "1024m"}],
@@ -1911,7 +1950,7 @@ def getHeapsizeProperties():
"property": "apptimelineserver_heapsize",
"default": "1024m"}],
"ZOOKEEPER_SERVER": [{"config-name": "zookeeper-env",
- "property": "zookeeper_heapsize",
+ "property": "zk_server_heapsize",
"default": "1024m"}],
"METRICS_COLLECTOR": [{"config-name": "ams-hbase-env",
"property": "hbase_master_heapsize",
@@ -1924,7 +1963,19 @@ def getHeapsizeProperties():
"default": "512"}],
"ATLAS_SERVER": [{"config-name": "atlas-env",
"property": "atlas_server_xmx",
- "default": "2048"}]
+ "default": "2048"}],
+ "LOGSEARCH_SERVER": [{"config-name": "logsearch-env",
+ "property": "logsearch_app_max_memory",
+ "default": "1024"}],
+ "LOGSEARCH_LOGFEEDER": [{"config-name": "logfeeder-env",
+ "property": "logfeeder_max_mem",
+ "default": "512"}],
+ "SPARK_JOBHISTORYSERVER": [{"config-name": "spark-env",
+ "property": "spark_daemon_memory",
+ "default": "1024"}],
+ "SPARK2_JOBHISTORYSERVER": [{"config-name": "spark2-env",
+ "property": "spark_daemon_memory",
+ "default": "1024"}]
}
def getMemorySizeRequired(components, configurations):
@@ -1944,7 +1995,12 @@ def getMemorySizeRequired(components, configurations):
heapsize = str(heapsize) + "m"
totalMemoryRequired += formatXmxSizeToBytes(heapsize)
-
+ else:
+ if component == "METRICS_MONITOR" or "CLIENT" in component:
+ heapsize = '512m'
+ else:
+ heapsize = '1024m'
+ totalMemoryRequired += formatXmxSizeToBytes(heapsize)
return totalMemoryRequired
def round_to_n(mem_size, n=128):
[17/21] ambari git commit: AMBARI-18419. Allow setting EclipseLink
weave log level in build process. (Attila Doroszali via stoader)
Posted by nc...@apache.org.
AMBARI-18419. Allow setting EclipseLink weave log level in build process. (Attila Doroszali via stoader)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/20997630
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/20997630
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/20997630
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 20997630d5be2a0d684a779b0daecb33ec54a4d6
Parents: 159546a
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Wed Sep 21 11:26:49 2016 +0200
Committer: Toader, Sebastian <st...@hortonworks.com>
Committed: Wed Sep 21 11:26:49 2016 +0200
----------------------------------------------------------------------
ambari-server/pom.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/20997630/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 32267c8..5731c9d 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -46,6 +46,7 @@
<skipPythonTests>false</skipPythonTests>
<hadoop.version>2.7.2</hadoop.version>
<empty.dir>src/main/package</empty.dir> <!-- any directory in project with not very big amount of files (not to waste-load them) -->
+ <el.log>ALL</el.log> <!-- log level for EclipseLink eclipselink-staticweave-maven-plugin -->
</properties>
<build>
<plugins>
@@ -337,7 +338,7 @@
</goals>
<phase>process-classes</phase>
<configuration>
- <logLevel>ALL</logLevel>
+ <logLevel>${el.log}</logLevel>
<includeProjectClasspath>true</includeProjectClasspath>
</configuration>
</execution>
[05/21] ambari git commit: AMBARI-18378. View instance cloning
functionality (alexantonenko)
Posted by nc...@apache.org.
AMBARI-18378. View instance cloning functionality (alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5d31b70c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5d31b70c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5d31b70c
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 5d31b70cf76789e2744ada68a547f71d87addbb8
Parents: b4f3809
Author: Alex Antonenko <hi...@gmail.com>
Authored: Mon Sep 19 21:32:18 2016 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Mon Sep 19 21:32:18 2016 +0300
----------------------------------------------------------------------
.../ambariViews/CreateViewInstanceCtrl.js | 35 ++++++++++++++++-
.../ui/admin-web/app/scripts/i18n.config.js | 2 +
.../ui/admin-web/app/scripts/routes.js | 5 +++
.../admin-web/app/views/ambariViews/create.html | 2 +-
.../app/views/ambariViews/listTable.html | 3 ++
.../unit/controllers/CreateViewInstanceCtrl.js | 40 ++++++++++++++++++++
6 files changed, 85 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
index 20bd25c..94b8cc1 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
@@ -24,6 +24,7 @@ angular.module('ambariAdminConsole')
$scope.constants = {
props: $t('views.properties')
};
+ $scope.isClone = $routeParams.instanceId ? true : false;
var targetUrl = '';
function loadMeta(){
@@ -56,11 +57,42 @@ angular.module('ambariAdminConsole')
description: '',
clusterType: 'NONE'
};
+
+ //if cloning view instance, then get the instance data and populate settings and properties
+ if($scope.isClone) {
+ View.getInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId)
+ .then(function(instance) {
+ $scope.instanceClone = instance;
+ $scope.instance.version = instance.ViewInstanceInfo.version;
+ $scope.version = instance.ViewInstanceInfo.version;
+ $scope.instance.instance_name = instance.ViewInstanceInfo.instance_name + $t('common.copy');
+ $scope.instance.label = instance.ViewInstanceInfo.label + $t('common.copy');
+ $scope.instance.visible = instance.ViewInstanceInfo.visible;
+ $scope.instance.description = instance.ViewInstanceInfo.description;
+ $scope.instance.clusterType=instance.ViewInstanceInfo.cluster_type;
+
+ initConfigurations(parameters);
+ })
+ .catch(function(data) {
+ Alert.error($t('views.alerts.cannotLoadInstanceInfo'), data.data.message);
+ });
+ }
+
loadClusters();
loadRemoteClusters();
+
});
}
+ function initConfigurations(parameters) {
+ var configuration = angular.copy($scope.instanceClone.ViewInstanceInfo.properties);
+
+ //iterate through the view parameters and get the values from the instance being cloned
+ for (var i = 0; i < parameters.length; i++) {
+ parameters[i].value = configuration[parameters[i].name];
+ parameters[i].clusterConfig = !!parameters[i].clusterConfig;
+ }
+ }
$scope.$watch(function(scope) {
return scope.version;
@@ -111,7 +143,8 @@ angular.module('ambariAdminConsole')
})
});
$scope.noLocalClusterAvailible = false;
- if($scope.clusterConfigurable){
+ //do not set to default Local Cluster configuration when cloning instance
+ if($scope.clusterConfigurable && !$scope.isClone){
$scope.instance.clusterType = "LOCAL_AMBARI";
}
}else{
http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
index bc16f0e..af22d7f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
@@ -95,6 +95,7 @@ angular.module('ambariAdminConsole')
'important': 'Important',
'undo': 'Undo',
'fromGroupMark': '(from group)',
+ 'copy': '_Copy',
'clusterNameChangeConfirmation': {
'title': 'Confirm Cluster Name Change',
@@ -198,6 +199,7 @@ angular.module('ambariAdminConsole')
'instance': 'Instance',
'viewInstance': 'View Instance',
'create': 'Create Instance',
+ 'clone': 'Clone Instance',
'createViewInstance': 'Create View Instance',
'edit': 'Edit',
'viewName': 'View Name',
http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
index 239e39e..a1ca59c 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
@@ -108,6 +108,11 @@ angular.module('ambariAdminConsole')
templateUrl: 'views/urls/edit.html',
controller: 'ViewUrlEditCtrl'
},
+ clone: {
+ url: '/views/:viewId/versions/:version/instances/:instanceId/clone',
+ templateUrl: 'views/ambariViews/create.html',
+ controller: 'CreateViewInstanceCtrl'
+ },
edit: {
url: '/views/:viewId/versions/:version/instances/:instanceId/edit',
templateUrl: 'views/ambariViews/edit.html',
http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
index 924885f..25f1487 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
@@ -17,7 +17,7 @@
-->
<ol class="breadcrumb">
<li><a href="#/views">{{'common.views' | translate}}</a></li>
- <li class="active">{{'views.create' | translate}}</li>
+ <li class="active"> {{isClone ? 'views.clone' : 'views.create' | translate}}</li>
</ol>
<hr>
<form class="form-horizontal create-view-form" role="form" name="form.instanceCreateForm" novalidate>
http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
index bc441cd..e03f035 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
@@ -78,6 +78,9 @@
<td class="col-sm-5">{{instance.ViewInstanceInfo.version}}</td>
<td class="col-sm-5 " ><div class="description-column" tooltip="{{instance.ViewInstanceInfo.description}}">{{instance.ViewInstanceInfo.description || 'No description'}}</div>
</td>
+ <td class="col-sm-1">
+ <a class="instance-link ng-scope ng-binding" href="#/views/{{view.view_name}}/versions/{{instance.ViewInstanceInfo.version}}/instances/{{instance.ViewInstanceInfo.instance_name}}/clone"><i class="fa fa-copy"></i></a>
+ </td>
</tr>
</tbody>
<tfoot>
http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
index 117021e..f8ccc24 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
@@ -31,6 +31,7 @@ describe('#CreateViewInstanceCtrl', function () {
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, _View_, $q) {
View = _View_;
spyOn(View, 'createInstance').andReturn($q.defer().promise);
+ spyOn(View, 'getInstance').andReturn($q.defer().promise);
$httpBackend = _$httpBackend_;
$httpBackend.whenGET(/\/api\/v1\/views\/TestView\?.+/).respond(200, {
@@ -66,6 +67,7 @@ describe('#CreateViewInstanceCtrl', function () {
};
scope.instance = {};
scope.version = '1.0.0';
+ scope.isClone=false;
$httpBackend.expectGET('template/modal/backdrop.html');
$httpBackend.expectGET('template/modal/window.html');
$httpBackend.whenGET(/\/api\/v1\/clusters\?fields=Clusters\/cluster_id&_=\d+/).respond(200, {
@@ -91,5 +93,43 @@ describe('#CreateViewInstanceCtrl', function () {
scope.$digest();
$httpBackend.flush();
chai.expect(scope.view.ViewVersionInfo.parameters[0].value).to.equal('d');
+ expect(View.getInstance).not.toHaveBeenCalled();
});
+
+ it('before cloning view instance confirm that View.getInstance is called', function () {
+ scope.form = {
+ instanceCreateForm: {
+ $dirty: true
+ }
+ };
+ scope.instance = {};
+ scope.version = '1.0.0';
+ scope.isClone=true;
+ $httpBackend.expectGET('template/modal/backdrop.html');
+ $httpBackend.expectGET('template/modal/window.html');
+ $httpBackend.whenGET(/\/api\/v1\/clusters\?fields=Clusters\/cluster_id&_=\d+/).respond(200, {
+ "items" : [
+ {
+ "Clusters" : {
+ "cluster_name" : "c1",
+ "version" : "HDP-2.2"
+ }
+ }
+ ]
+ });
+ $httpBackend.whenGET(/\/api\/v1\/remoteclusters\?fields=ClusterInfo\/services,ClusterInfo\/cluster_id&_=\d+/).respond(200, {
+ "items" : [
+ {
+ "ClusterInfo" : {
+ "name" : "c1",
+ "services" : ["HDFS"]
+ }
+ }
+ ]
+ });
+ scope.$digest();
+ $httpBackend.flush();
+ expect(View.getInstance).toHaveBeenCalled();
+ });
+
});
[13/21] ambari git commit: AMBARI-18337: Syntax Error in Ambari HAWQ
Unit test with Python 2.6 (Masahiro Tanaka via lavjain)
Posted by nc...@apache.org.
AMBARI-18337: Syntax Error in Ambari HAWQ Unit test with Python 2.6 (Masahiro Tanaka via lavjain)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3b30de0a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3b30de0a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3b30de0a
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 3b30de0a8ad939768e9194fb63ef19f07eaabaee
Parents: 382eba1
Author: ljainpivotalio <lj...@pivotal.io>
Authored: Tue Sep 20 14:34:14 2016 -0700
Committer: ljainpivotalio <lj...@pivotal.io>
Committed: Tue Sep 20 14:34:14 2016 -0700
----------------------------------------------------------------------
.../python/common-services/HAWQ/test_service_advisor.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/3b30de0a/ambari-server/src/test/python/common-services/HAWQ/test_service_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/common-services/HAWQ/test_service_advisor.py b/ambari-server/src/test/python/common-services/HAWQ/test_service_advisor.py
index 71c109f..b9e542d 100644
--- a/ambari-server/src/test/python/common-services/HAWQ/test_service_advisor.py
+++ b/ambari-server/src/test/python/common-services/HAWQ/test_service_advisor.py
@@ -643,7 +643,7 @@ class TestHAWQ200ServiceAdvisor(TestCase):
recommendations["recommendations"]["blueprint"]["host_groups"]]
for sublist in componentsListList:
hostComponents = [item["name"] for item in sublist]
- self.assertFalse({'HAWQMASTER', 'HAWQSTANDBY'}.issubset(hostComponents))
+ self.assertFalse(set(['HAWQMASTER', 'HAWQSTANDBY']).issubset(hostComponents))
def test_createComponentLayoutRecommendations_hawq_1_Host(self):
@@ -721,7 +721,7 @@ class TestHAWQ200ServiceAdvisor(TestCase):
]
}
- hawqSegmentHosts = {"c6401.ambari.apache.org", "c6402.ambari.apache.org", "c6403.ambari.apache.org"}
+ hawqSegmentHosts = set(["c6401.ambari.apache.org", "c6402.ambari.apache.org", "c6403.ambari.apache.org"])
self.insertHAWQServiceAdvisorInfo(services)
recommendations = self.serviceAdvisor.createComponentLayoutRecommendations(services, hosts)
hostNames = self.getHostsFromRecommendations(recommendations, "HAWQSEGMENT")
@@ -766,7 +766,7 @@ class TestHAWQ200ServiceAdvisor(TestCase):
]
}
- hawqSegmentHosts = {"c6401.ambari.apache.org", "c6403.ambari.apache.org"}
+ hawqSegmentHosts = set(["c6401.ambari.apache.org", "c6403.ambari.apache.org"])
self.insertHAWQServiceAdvisorInfo(services)
recommendations = self.serviceAdvisor.createComponentLayoutRecommendations(services, hosts)
hostNames = self.getHostsFromRecommendations(recommendations, "HAWQSEGMENT")
@@ -826,7 +826,7 @@ class TestHAWQ200ServiceAdvisor(TestCase):
]
}
- hawqSegmentHosts = {"c6402.ambari.apache.org"}
+ hawqSegmentHosts = set(["c6402.ambari.apache.org"])
self.insertHAWQServiceAdvisorInfo(services)
recommendations = self.serviceAdvisor.createComponentLayoutRecommendations(services, hosts)
hostNames = self.getHostsFromRecommendations(recommendations, "HAWQSEGMENT")
@@ -1326,4 +1326,4 @@ class TestHAWQ200ServiceAdvisor(TestCase):
configurations["core-site"]["properties"].pop("ipc.server.listen.queue.size")
problems = self.serviceAdvisor.validateCORESiteConfigurations(configurations["core-site"]["properties"], defaults, configurations, services, hosts)
self.assertEqual(len(problems), 1)
- self.assertEqual(problems[0], expected)
\ No newline at end of file
+ self.assertEqual(problems[0], expected)
[19/21] ambari git commit: AMBARI-18250. Pig View Caching issue
causes File does not exist: /user//pig/jobs/job_id/stdout and stderr. (Jay
Sen Sharma via gauravn7)
Posted by nc...@apache.org.
AMBARI-18250. Pig View Caching issue causes File does not exist: /user//pig/jobs/job_id/stdout and stderr. (Jay Sen Sharma via gauravn7)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0f774139
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0f774139
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0f774139
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 0f774139ec6d4dd85075e0227b59c6ded75d262e
Parents: 04b4dc2
Author: Gaurav Nagar <gn...@hortonworks.com>
Authored: Wed Sep 21 16:36:56 2016 +0530
Committer: Gaurav Nagar <gn...@hortonworks.com>
Committed: Wed Sep 21 16:41:45 2016 +0530
----------------------------------------------------------------------
.../views/pig/src/main/resources/ui/pig-web/app/initialize.js | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/0f774139/contrib/views/pig/src/main/resources/ui/pig-web/app/initialize.js
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/resources/ui/pig-web/app/initialize.js b/contrib/views/pig/src/main/resources/ui/pig-web/app/initialize.js
index 38ee093..6df3604 100644
--- a/contrib/views/pig/src/main/resources/ui/pig-web/app/initialize.js
+++ b/contrib/views/pig/src/main/resources/ui/pig-web/app/initialize.js
@@ -19,6 +19,11 @@
window.App = require('app');
App.ApplicationAdapter = DS.RESTAdapter.extend({
+ init: function() {
+ Ember.$.ajaxSetup({
+ cache: false
+ })
+ },
namespace: App.getNamespaceUrl(),
headers: {
'X-Requested-By': 'ambari'
[18/21] ambari git commit: AMBARI-18424. Core-site should be provided
for every stack advisor call (e.g. when deleting services) (akovalenko)
Posted by nc...@apache.org.
AMBARI-18424. Core-site should be provided for every stack advisor call (e.g. when deleting services) (akovalenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/04b4dc2a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/04b4dc2a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/04b4dc2a
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 04b4dc2a5d57f9b092ae336c2ba089c259b8a56e
Parents: 2099763
Author: Aleksandr Kovalenko <ak...@hortonworks.com>
Authored: Tue Sep 20 18:04:10 2016 +0300
Committer: Aleksandr Kovalenko <ak...@hortonworks.com>
Committed: Wed Sep 21 13:33:23 2016 +0300
----------------------------------------------------------------------
.../resourceManager/step3_controller.js | 1 -
.../mixins/common/configs/enhanced_configs.js | 24 +++---
ambari-web/app/mixins/common/serverValidator.js | 7 +-
ambari-web/app/utils/ajax/ajax.js | 4 +-
ambari-web/app/utils/blueprint.js | 10 +--
ambari-web/app/utils/config.js | 45 ++++++-----
.../common/configs/enhanced_configs_test.js | 79 +++-----------------
7 files changed, 60 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/04b4dc2a/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js b/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js
index 36dcfb8..08e0b73 100644
--- a/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js
+++ b/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js
@@ -182,7 +182,6 @@ App.RMHighAvailabilityWizardStep3Controller = Em.Controller.extend(App.Blueprint
},
loadRecommendations: function(blueprintConfigurations) {
- var dfd = $.Deferred();
var blueprint = this.getCurrentMasterSlaveBlueprint();
// host group where new ResourceManager will be added
var hostGroupName = blueprintUtils.getHostGroupByFqdn(blueprint, this.get('content.rmHosts.additionalRM'));
http://git-wip-us.apache.org/repos/asf/ambari/blob/04b4dc2a/ambari-web/app/mixins/common/configs/enhanced_configs.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/configs/enhanced_configs.js b/ambari-web/app/mixins/common/configs/enhanced_configs.js
index a99d835..f53b45d 100644
--- a/ambari-web/app/mixins/common/configs/enhanced_configs.js
+++ b/ambari-web/app/mixins/common/configs/enhanced_configs.js
@@ -179,17 +179,26 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP
loadConfigRecommendations: function (changedConfigs, onComplete) {
var updateDependencies = Em.isArray(changedConfigs) && changedConfigs.length > 0;
var stepConfigs = this.get('stepConfigs');
+ var requiredTags = [];
if (updateDependencies || Em.isNone(this.get('recommendationsConfigs'))) {
var recommendations = this.get('hostGroups');
var dataToSend = this.getConfigRecommendationsParams(updateDependencies, changedConfigs);
this.modifyRecommendationConfigGroups(recommendations);
- if (stepConfigs.someProperty('serviceName', 'MISC')) {
+ if (!stepConfigs.someProperty('serviceName', 'MISC')) {
+ requiredTags.push({site: 'cluster-env', serviceName: 'MISC'});
+ }
+
+ if (App.Service.find().someProperty('serviceName', 'HDFS') && !stepConfigs.someProperty('serviceName', 'HDFS')) {
+ requiredTags.push({site: 'core-site', serviceName: 'HDFS'});
+ }
+
+ if (requiredTags.length) {
+ this.loadAdditionalSites(requiredTags, stepConfigs, recommendations, dataToSend, onComplete);
+ } else {
this.addRecommendationRequestParams(recommendations, dataToSend, stepConfigs);
return this.getRecommendationsRequest(dataToSend, onComplete);
- } else {
- this.requestRecommendationsWithEnv(stepConfigs, recommendations, dataToSend, onComplete);
}
} else {
if (onComplete) {
@@ -217,13 +226,10 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP
* @param {object} dataToSend
* @param {Function} onComplete
*/
- requestRecommendationsWithEnv: function(stepConfigs, recommendations, dataToSend, onComplete) {
+ loadAdditionalSites: function(sites, stepConfigs, recommendations, dataToSend, onComplete) {
var self = this;
- App.config.getClusterEnvConfigs().done(function (clusterEnvConfigs) {
- stepConfigs = stepConfigs.concat(Em.Object.create({
- serviceName: 'MISC',
- configs: clusterEnvConfigs
- }));
+ App.config.getConfigsByTypes(sites).done(function (configs) {
+ stepConfigs = stepConfigs.concat(configs);
self.addRecommendationRequestParams(recommendations, dataToSend, stepConfigs);
self.getRecommendationsRequest(dataToSend, onComplete);
http://git-wip-us.apache.org/repos/asf/ambari/blob/04b4dc2a/ambari-web/app/mixins/common/serverValidator.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/serverValidator.js b/ambari-web/app/mixins/common/serverValidator.js
index 9fb5ae3..d8747d3 100644
--- a/ambari-web/app/mixins/common/serverValidator.js
+++ b/ambari-web/app/mixins/common/serverValidator.js
@@ -153,11 +153,8 @@ App.ServerValidatorMixin = Em.Mixin.create({
// check if we have configs from 'cluster-env', if not, then load them, as they are mandatory for validation request
if (!stepConfigs.findProperty('serviceName', 'MISC')) {
- App.config.getClusterEnvConfigs().done(function(clusterEnvConfigs){
- stepConfigs = stepConfigs.concat(Em.Object.create({
- serviceName: 'MISC',
- configs: clusterEnvConfigs
- }));
+ App.config.getConfigsByTypes([{site: 'cluster-env', serviceName: 'MISC'}]).done(function (configs) {
+ stepConfigs = stepConfigs.concat(configs);
dfd.resolve(blueprintUtils.buildConfigsJSON(stepConfigs));
});
} else {
http://git-wip-us.apache.org/repos/asf/ambari/blob/04b4dc2a/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index 70c73be..7eb9c9e 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -850,8 +850,8 @@ var urls = {
'mock': '/data/configurations/host_level_overrides_configs.json?{params}'
},
- 'config.cluster_env_site': {
- 'real': '/clusters/{clusterName}/configurations?type=cluster-env',
+ 'config.tags.selected': {
+ 'real': '/clusters/{clusterName}/configurations?type.in({tags})',
'mock': '/data/configuration/cluster_env_site.json'
},
http://git-wip-us.apache.org/repos/asf/ambari/blob/04b4dc2a/ambari-web/app/utils/blueprint.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/blueprint.js b/ambari-web/app/utils/blueprint.js
index 696f7a4..1148d3d 100644
--- a/ambari-web/app/utils/blueprint.js
+++ b/ambari-web/app/utils/blueprint.js
@@ -320,13 +320,11 @@ module.exports = {
var configurations = {};
stepConfigs.forEach(function (stepConfig) {
stepConfig.get('configs').forEach(function (config) {
- if (config.get('filename') === 'cluster-env.xml' || config.get('isRequiredByAgent')) {
- var type = App.config.getConfigTagFromFileName(config.get('filename'));
- if (!configurations[type]) {
- configurations[type] = {properties: {}}
- }
- configurations[type]['properties'][config.get('name')] = config.get('value');
+ var type = App.config.getConfigTagFromFileName(config.get('filename'));
+ if (!configurations[type]) {
+ configurations[type] = {properties: {}}
}
+ configurations[type]['properties'][config.get('name')] = config.get('value');
});
});
return configurations;
http://git-wip-us.apache.org/repos/asf/ambari/blob/04b4dc2a/ambari-web/app/utils/config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js
index ae09b82..abb2fbf 100644
--- a/ambari-web/app/utils/config.js
+++ b/ambari-web/app/utils/config.js
@@ -1287,28 +1287,37 @@ App.config = Em.Object.create({
* Load cluster-env configs mapped to array
* @return {*|{then}}
*/
- getClusterEnvConfigs: function () {
+ getConfigsByTypes: function (sites) {
var dfd = $.Deferred();
App.ajax.send({
- name: 'config.cluster_env_site',
- sender: this
+ name: 'config.tags.selected',
+ sender: this,
+ data: {
+ tags: sites.mapProperty('site').join(',')
+ }
}).done(function (data) {
- App.router.get('configurationController').getConfigsByTags([{
- siteName: data.items[data.items.length - 1].type,
- tagName: data.items[data.items.length - 1].tag
- }]).done(function (clusterEnvConfigs) {
- var configsObject = clusterEnvConfigs[0].properties;
- var configsArray = [];
- for (var property in configsObject) {
- if (configsObject.hasOwnProperty(property)) {
- configsArray.push(Em.Object.create({
- name: property,
- value: configsObject[property],
- filename: 'cluster-env.xml'
- }));
+ App.router.get('configurationController').getConfigsByTags(data.items.map(function (item) {
+ return {siteName: item.type, tagName: item.tag};
+ })).done(function (configs) {
+ var result = [];
+ configs.forEach(function(config){
+ var configsArray = [];
+ var configsObject = config.properties;
+ for (var property in configsObject) {
+ if (configsObject.hasOwnProperty(property)) {
+ configsArray.push(Em.Object.create({
+ name: property,
+ value: configsObject[property],
+ filename: App.config.getOriginalFileName(config.type)
+ }));
+ }
}
- }
- dfd.resolve(configsArray);
+ result.push(Em.Object.create({
+ serviceName: sites.findProperty('site', config.type).serviceName,
+ configs: configsArray
+ }));
+ });
+ dfd.resolve(result);
});
});
return dfd.promise();
http://git-wip-us.apache.org/repos/asf/ambari/blob/04b4dc2a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js b/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
index 79a7ef7..a9c9770 100644
--- a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
+++ b/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
@@ -164,60 +164,6 @@ describe('App.EnhancedConfigsMixin', function () {
});
});
- describe("#loadConfigRecommendations", function () {
- var mixinInstance;
-
- beforeEach(function () {
- mixinInstance = mixinClass.create({
- recommendationsConfigs: {},
- stepConfigs: [],
- hostGroups: {
- blueprint: {
- configurations: {}
- }
- }
- });
- this.mockedCallback = sinon.stub();
- sinon.stub(App.config, 'getClusterEnvConfigs').returns({
- done: function (callback) {
- callback([]);
- }
- });
- });
-
- afterEach(function () {
- App.config.getClusterEnvConfigs.restore();
- });
-
- it("should call callback if changedConfigs is empty array", function () {
- mixinInstance.loadConfigRecommendations([], this.mockedCallback);
- expect(testHelpers.findAjaxRequest('name', 'config.recommendations')).to.not.exist;
- expect(this.mockedCallback.calledOnce).to.be.true;
- });
-
- it("should call callback from ajax callback if changedConfigs is not empty", function () {
- mixinInstance.loadConfigRecommendations([{}], this.mockedCallback);
- var args = testHelpers.findAjaxRequest('name', 'config.recommendations');
- expect(args[0]).exists;
- args[0].callback();
- expect(this.mockedCallback.calledOnce).to.be.true;
- });
-
- it("should call getClusterEnvConfigs if there is no cluster-env configs in stepConfigs", function () {
- mixinInstance.loadConfigRecommendations([{}]);
- expect(App.config.getClusterEnvConfigs.calledOnce).to.be.true;
- });
-
- it("should not call getClusterEnvConfigs if there is cluster-env configs in stepConfigs", function () {
- mixinInstance.set('stepConfigs', [Em.Object.create({
- serviceName: 'MISC',
- configs: []
- })]);
- mixinInstance.loadConfigRecommendations([{}]);
- expect(App.config.getClusterEnvConfigs.calledOnce).to.be.false;
- });
- });
-
describe("#changedDependentGroup", function () {
var mixinInstance;
@@ -559,7 +505,7 @@ describe('App.EnhancedConfigsMixin', function () {
sinon.stub(mixin, 'modifyRecommendationConfigGroups');
sinon.stub(mixin, 'addRecommendationRequestParams');
sinon.stub(mixin, 'getRecommendationsRequest');
- sinon.stub(mixin, 'requestRecommendationsWithEnv');
+ sinon.stub(mixin, 'loadAdditionalSites');
});
afterEach(function() {
@@ -568,7 +514,7 @@ describe('App.EnhancedConfigsMixin', function () {
mixin.modifyRecommendationConfigGroups.restore();
mixin.addRecommendationRequestParams.restore();
mixin.getRecommendationsRequest.restore();
- mixin.requestRecommendationsWithEnv.restore();
+ mixin.loadAdditionalSites.restore();
});
it("changedConfigs is null", function() {
@@ -589,7 +535,7 @@ describe('App.EnhancedConfigsMixin', function () {
mixin.loadConfigRecommendations([], mock.onComplete);
expect(mixin.getConfigRecommendationsParams.calledWith(false)).to.be.true;
expect(mixin.modifyRecommendationConfigGroups.calledOnce).to.be.true;
- expect(mixin.requestRecommendationsWithEnv.calledOnce).to.be.true;
+ expect(mixin.loadAdditionalSites.calledOnce).to.be.true;
});
it("changedConfigs is correct, MISC service present", function() {
@@ -628,34 +574,29 @@ describe('App.EnhancedConfigsMixin', function () {
});
});
- describe("#requestRecommendationsWithEnv()", function () {
+ describe("#loadAdditionalSites()", function () {
beforeEach(function() {
- sinon.stub(App.config, 'getClusterEnvConfigs').returns({
+ sinon.stub(App.config, 'getConfigsByTypes').returns({
done: function(callback) {callback([]);}
});
sinon.stub(mixin, 'addRecommendationRequestParams');
sinon.stub(mixin, 'getRecommendationsRequest');
- mixin.requestRecommendationsWithEnv([], {}, {}, Em.K);
+ mixin.loadAdditionalSites([], [], {}, {}, Em.K);
});
afterEach(function() {
- App.config.getClusterEnvConfigs.restore();
+ App.config.getConfigsByTypes.restore();
mixin.addRecommendationRequestParams.restore();
mixin.getRecommendationsRequest.restore();
});
- it("App.config.getClusterEnvConfigs should be called", function() {
- expect(App.config.getClusterEnvConfigs.calledOnce).to.be.true;
+ it("App.config.getConfigsByTypes should be called", function() {
+ expect(App.config.getConfigsByTypes.calledOnce).to.be.true;
});
it("addRecommendationRequestParams should be called", function() {
- expect(mixin.addRecommendationRequestParams.calledWith({}, {}, [
- Em.Object.create({
- serviceName: 'MISC',
- configs: []
- })
- ])).to.be.true;
+ expect(mixin.addRecommendationRequestParams.calledWith({}, {}, [])).to.be.true;
});
it("getRecommendationsRequest should be called", function() {
[10/21] ambari git commit: AMBARI-18420. Analyze and Optimize Ambari
Server Unit Tests - Group 6.(vbrodetskyi)
Posted by nc...@apache.org.
AMBARI-18420. Analyze and Optimize Ambari Server Unit Tests - Group 6.(vbrodetskyi)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8425f1fa
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8425f1fa
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8425f1fa
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 8425f1fa714718e32a05e8fcd005047c6de46451
Parents: a9bbf46
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Tue Sep 20 17:44:21 2016 +0300
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Tue Sep 20 17:44:21 2016 +0300
----------------------------------------------------------------------
.../server/orm/dao/HostConfigMappingDAO.java | 4 +-
.../server/agent/TestHeartbeatMonitor.java | 14 +-
...ThreadPoolExecutorCompletionServiceTest.java | 6 +-
.../apache/ambari/server/orm/TestOrmImpl.java | 116 ++++++---
.../server/orm/dao/AlertDispatchDAOTest.java | 235 ++++++++++++-------
.../security/authorization/TestUsers.java | 7 +
.../upgrades/ConfigureActionTest.java | 212 ++++++++++-------
.../upgrades/UpgradeActionTest.java | 153 ++++++------
.../apache/ambari/server/state/ServiceTest.java | 124 ++++++----
.../svccomphost/ServiceComponentHostTest.java | 34 +--
.../server/upgrade/UpgradeCatalog210Test.java | 7 +
11 files changed, 557 insertions(+), 355 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
index 77ff4a2..f8392d9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
@@ -301,9 +301,7 @@ public class HostConfigMappingDAO {
List<HostConfigMappingEntity> hostConfigMappingEntities = daoUtils.selectList(query);
- List<HostConfigMappingEntity> list = daoUtils.selectList(query, hostEntity.getHostId());
-
- for (HostConfigMappingEntity entity : list) {
+ for (HostConfigMappingEntity entity : hostConfigMappingEntities) {
entityManagerProvider.get().remove(entity);
}
// Update the cache
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
index b6f5ec2..63460a2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
@@ -57,6 +57,7 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEve
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceededEvent;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartedEvent;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -66,6 +67,8 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
+import com.google.inject.persist.UnitOfWork;
public class TestHeartbeatMonitor {
@@ -73,6 +76,7 @@ public class TestHeartbeatMonitor {
private String hostname1 = "host1";
private String hostname2 = "host2";
+ private String hostname3 = "host3";
private String clusterName = "cluster1";
private String serviceName = "HDFS";
private int heartbeatMonitorWakeupIntervalMS = 30;
@@ -93,11 +97,17 @@ public class TestHeartbeatMonitor {
@Before
public void setup() throws Exception {
cleanup();
+ injector.getInstance(UnitOfWork.class).begin();
}
@After
public void teardown() {
+ injector.getInstance(UnitOfWork.class).end();
+ }
+ @AfterClass
+ public static void afterClass() throws Exception {
+ injector.getInstance(PersistService.class).stop();
}
private void cleanup() throws AmbariException {
@@ -154,7 +164,7 @@ public class TestHeartbeatMonitor {
Thread.sleep(1);
}
assertEquals(fsm.getHost(hostname).getState(), HostState.HEARTBEAT_LOST);
- classSetUp();
+ hm.shutdown();
}
@Test
@@ -468,7 +478,7 @@ public class TestHeartbeatMonitor {
helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
- RepositoryVersionState.INSTALLING);
+ RepositoryVersionState.INSTALLING);
Set<String> hostNames = new HashSet<String>(){{
add(hostname1);
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java
index ede1f1f..ec99ab0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java
@@ -17,6 +17,8 @@
*/
package org.apache.ambari.server.controller.test;
+import junit.framework.Assert;
+
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -26,12 +28,10 @@ import org.apache.ambari.server.controller.utilities.BufferedThreadPoolExecutorC
import org.apache.ambari.server.controller.utilities.ScalingThreadPoolExecutor;
import org.junit.Test;
-import junit.framework.Assert;
-
public class BufferedThreadPoolExecutorCompletionServiceTest {
private void longOp() throws InterruptedException {
- Thread.sleep(3000);
+ Thread.sleep(1000);
System.out.println("Completed " + Thread.currentThread());
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java
index ce1c7e6..e72692a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java
@@ -18,14 +18,14 @@
package org.apache.ambari.server.orm;
+import javax.persistence.EntityManager;
+import javax.persistence.RollbackException;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.RollbackException;
-
import org.apache.ambari.server.Role;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
@@ -48,8 +48,11 @@ import org.apache.ambari.server.orm.entities.StackEntity;
import org.apache.ambari.server.orm.entities.StageEntity;
import org.apache.ambari.server.security.authorization.ResourceType;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,28 +60,86 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
+import com.google.inject.persist.UnitOfWork;
public class TestOrmImpl extends Assert {
private static final Logger log = LoggerFactory.getLogger(TestOrmImpl.class);
private static Injector injector;
-
- @Before
- public void setup() {
+ private static StackDAO stackDAO;
+ private static ResourceTypeDAO resourceTypeDAO;
+ private static ClusterDAO clusterDAO;
+ private static OrmTestHelper ormTestHelper;
+ private static ClusterServiceDAO clusterServiceDAO;
+ private static HostRoleCommandDAO hostRoleCommandDAO;
+ private static HostDAO hostDAO;
+ private static StageDAO stageDAO;
+ private static EntityManager entityManager;
+ private static RequestDAO requestDAO;
+
+ @BeforeClass
+ public static void classSetUp() throws Exception {
injector = Guice.createInjector(new InMemoryDefaultTestModule());
injector.getInstance(GuiceJpaInitializer.class);
// required to load stack information into the DB
injector.getInstance(AmbariMetaInfo.class);
+ stackDAO = injector.getInstance(StackDAO.class);
+ resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);
+ clusterDAO = injector.getInstance(ClusterDAO.class);
+ ormTestHelper = injector.getInstance(OrmTestHelper.class);
+ clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
+ hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
+ hostDAO = injector.getInstance(HostDAO.class);
+ stageDAO = injector.getInstance(StageDAO.class);
+ entityManager = injector.getInstance(EntityManager.class);
+ requestDAO = injector.getInstance(RequestDAO.class);
+
+ ormTestHelper.createDefaultData();
+ injector.getInstance(UnitOfWork.class).end();
+ }
- injector.getInstance(OrmTestHelper.class).createDefaultData();
+ @Before
+ public void setup() {
+ injector.getInstance(UnitOfWork.class).begin();
}
@After
public void teardown() {
+ injector.getInstance(UnitOfWork.class).end();
+ cleanup();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
injector.getInstance(PersistService.class).stop();
}
+ private void cleanup() {
+
+
+ List<HostRoleCommandEntity> hostRoleCommandEntities = hostRoleCommandDAO.findAll();
+ if (hostRoleCommandEntities != null) {
+ for (HostRoleCommandEntity hostRoleCommandEntity : hostRoleCommandEntities) {
+ hostRoleCommandDAO.remove(hostRoleCommandEntity);
+ }
+ }
+
+ List<StageEntity> stageEntities = stageDAO.findAll();
+ if (stageEntities != null) {
+ for (StageEntity stageEntity : stageEntities) {
+ stageDAO.remove(stageEntity);
+ }
+ }
+
+ List<RequestEntity> requestEntities = requestDAO.findAll();
+ if (requestEntities != null) {
+ for (RequestEntity requestEntity : requestEntities) {
+ requestDAO.remove(requestEntity);
+ }
+ }
+ }
+
/**
* persistence provider is responsible for returning empty collection if relation doesn't exists
*/
@@ -86,8 +147,6 @@ public class TestOrmImpl extends Assert {
public void testEmptyPersistentCollection() {
String testClusterName = "test_cluster2";
- StackDAO stackDAO = injector.getInstance(StackDAO.class);
- ResourceTypeDAO resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);
// create an admin resource to represent this cluster
ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findById(ResourceType.CLUSTER.getId());
@@ -107,7 +166,6 @@ public class TestOrmImpl extends Assert {
clusterEntity.setResource(resourceEntity);
clusterEntity.setDesiredStack(stackEntity);
- ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
clusterDAO.create(clusterEntity);
clusterEntity = clusterDAO.findByName(clusterEntity.getClusterName());
@@ -120,7 +178,7 @@ public class TestOrmImpl extends Assert {
*/
@Test(expected = RollbackException.class)
public void testRollbackException() throws Throwable{
- injector.getInstance(OrmTestHelper.class).performTransactionMarkedForRollback();
+ ormTestHelper.performTransactionMarkedForRollback();
}
/**
@@ -130,14 +188,14 @@ public class TestOrmImpl extends Assert {
public void testSafeRollback() {
String testClusterName = "don't save";
- EntityManager entityManager = injector.getInstance(OrmTestHelper.class).getEntityManager();
+ EntityManager entityManager = ormTestHelper.getEntityManager();
entityManager.getTransaction().begin();
ClusterEntity clusterEntity = new ClusterEntity();
clusterEntity.setClusterName(testClusterName);
entityManager.persist(clusterEntity);
entityManager.getTransaction().rollback();
- assertNull("transaction was not rolled back", injector.getInstance(ClusterDAO.class).findByName(testClusterName));
+ assertNull("transaction was not rolled back", clusterDAO.findByName(testClusterName));
}
/**
@@ -145,7 +203,6 @@ public class TestOrmImpl extends Assert {
*/
@Test
public void testAutoIncrementedField() {
- ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
Date currentTime = new Date();
String serviceName = "MapReduce1";
String clusterName = "test_cluster1";
@@ -161,8 +218,6 @@ public class TestOrmImpl extends Assert {
}
private void createService(Date currentTime, String serviceName, String clusterName) {
- ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
- ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
ClusterEntity cluster = clusterDAO.findByName(clusterName);
ClusterServiceEntity clusterServiceEntity = new ClusterServiceEntity();
@@ -185,7 +240,6 @@ public class TestOrmImpl extends Assert {
*/
@Test
public void testCascadeRemoveFail() {
- ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
Date currentTime = new Date();
String serviceName = "MapReduce2";
String clusterName = "test_cluster1";
@@ -215,13 +269,12 @@ public class TestOrmImpl extends Assert {
log.info("command '{}' - taskId '{}'", list.get(1).getRoleCommand(),
list.get(1).getTaskId());
assertTrue(list.get(0).getTaskId() < list.get(1).getTaskId());
+
}
@Test
public void testFindHostsByStage() {
- injector.getInstance(OrmTestHelper.class).createStageCommands();
- HostDAO hostDAO = injector.getInstance(HostDAO.class);
- StageDAO stageDAO = injector.getInstance(StageDAO.class);
+ ormTestHelper.createStageCommands();
StageEntity stageEntity = stageDAO.findByActionId("1-1");
log.info("StageEntity {} {}" + stageEntity.getRequestId() + " "
+ stageEntity.getStageId());
@@ -231,8 +284,7 @@ public class TestOrmImpl extends Assert {
@Test
public void testAbortHostRoleCommands() {
- injector.getInstance(OrmTestHelper.class).createStageCommands();
- HostRoleCommandDAO hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
+ ormTestHelper.createStageCommands();
int result = hostRoleCommandDAO.updateStatusByRequestId(
1L, HostRoleStatus.ABORTED, Arrays.asList(HostRoleStatus.QUEUED,
HostRoleStatus.IN_PROGRESS, HostRoleStatus.PENDING));
@@ -249,17 +301,14 @@ public class TestOrmImpl extends Assert {
@Test
public void testFindStageByHostRole() {
- injector.getInstance(OrmTestHelper.class).createStageCommands();
- HostRoleCommandDAO hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
+ ormTestHelper.createStageCommands();
List<HostRoleCommandEntity> list = hostRoleCommandDAO.findByHostRole("test_host1", 1L, 1L, Role.DATANODE.toString());
assertEquals(1, list.size());
}
@Test
public void testLastRequestId() {
- injector.getInstance(OrmTestHelper.class).createStageCommands();
- ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
- StageDAO stageDAO = injector.getInstance(StageDAO.class);
+ ormTestHelper.createStageCommands();
RequestDAO requestDAO = injector.getInstance(RequestDAO.class);
RequestEntity requestEntity = requestDAO.findByPK(1L);
@@ -284,12 +333,9 @@ public class TestOrmImpl extends Assert {
assertEquals(1L, stageDAO.getLastRequestId());
}
+ @Ignore
@Test
public void testConcurrentModification() throws InterruptedException {
- final StackDAO stackDAO = injector.getInstance(StackDAO.class);
- final ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
- final ResourceTypeDAO resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);
-
final StackEntity stackEntity = stackDAO.find("HDP", "2.2.0");
// create an admin resource to represent this cluster
@@ -323,14 +369,14 @@ public class TestOrmImpl extends Assert {
clusterEntity1 = clusterDAO.findById(clusterEntity1.getClusterId());
assertEquals("anotherName", clusterEntity1.getClusterName());
- injector.getInstance(EntityManager.class).clear();
+ entityManager.clear();
}
};
thread.start();
thread.join();
- injector.getInstance(EntityManager.class).clear();
+ entityManager.clear();
clusterEntity = clusterDAO.findById(clusterEntity.getClusterId());
assertEquals("anotherName", clusterEntity.getClusterName());
@@ -339,14 +385,14 @@ public class TestOrmImpl extends Assert {
@Override
public void run() {
clusterDAO.removeByName("anotherName");
- injector.getInstance(EntityManager.class).clear();
+ entityManager.clear();
}
};
thread.start();
thread.join();
- injector.getInstance(EntityManager.class).clear();
+ entityManager.clear();
assertNull(clusterDAO.findById(clusterEntity.getClusterId()));
List<ClusterEntity> result = clusterDAO.findAll();
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
index 2518e0a..5697ba0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
@@ -32,9 +32,7 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
-import com.google.inject.persist.UnitOfWork;
import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AlertNoticeRequest;
import org.apache.ambari.server.controller.internal.AlertNoticeResourceProvider;
import org.apache.ambari.server.controller.internal.PageRequestImpl;
@@ -54,9 +52,12 @@ import org.apache.ambari.server.orm.entities.AlertGroupEntity;
import org.apache.ambari.server.orm.entities.AlertHistoryEntity;
import org.apache.ambari.server.orm.entities.AlertNoticeEntity;
import org.apache.ambari.server.orm.entities.AlertTargetEntity;
+import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
import org.apache.ambari.server.state.AlertState;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.NotificationState;
import org.apache.ambari.server.state.ServiceComponentFactory;
import org.apache.ambari.server.state.ServiceComponentHostFactory;
@@ -65,7 +66,9 @@ import org.apache.ambari.server.state.alert.Scope;
import org.apache.ambari.server.state.alert.SourceType;
import org.apache.ambari.server.utils.EventBusSynchronizer;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import com.google.inject.Guice;
@@ -73,12 +76,6 @@ import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
import com.google.inject.persist.UnitOfWork;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
/**
* Tests {@link AlertDispatchDAO}.
*/
@@ -86,27 +83,25 @@ public class AlertDispatchDAOTest {
private final static String HOSTNAME = "c6401.ambari.apache.org";
- private Clusters m_clusters;
- private Cluster m_cluster;
- private Injector m_injector;
- private AlertDispatchDAO m_dao;
- private AlertDefinitionDAO m_definitionDao;
- private AlertsDAO m_alertsDao;
- private OrmTestHelper m_helper;
-
- private ServiceFactory m_serviceFactory;
- private ServiceComponentFactory m_componentFactory;
- private ServiceComponentHostFactory m_schFactory;
- private AlertDaoHelper m_alertHelper;
-
- /**
- *
- */
- @Before
- public void setup() throws Exception {
+ private static Clusters m_clusters;
+ private static Cluster m_cluster;
+ private static Injector m_injector;
+ private static AlertDispatchDAO m_dao;
+ private static AlertDefinitionDAO m_definitionDao;
+ private static AlertsDAO m_alertsDao;
+ private static OrmTestHelper m_helper;
+ private static HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
+ private static HostComponentStateDAO hostComponentStateDAO;
+
+ private static ServiceFactory m_serviceFactory;
+ private static ServiceComponentFactory m_componentFactory;
+ private static ServiceComponentHostFactory m_schFactory;
+ private static AlertDaoHelper m_alertHelper;
+
+ @BeforeClass
+ public static void classSetUp() throws Exception {
m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
m_injector.getInstance(GuiceJpaInitializer.class);
- m_injector.getInstance(UnitOfWork.class).begin();
m_dao = m_injector.getInstance(AlertDispatchDAO.class);
m_alertsDao = m_injector.getInstance(AlertsDAO.class);
@@ -117,13 +112,85 @@ public class AlertDispatchDAOTest {
m_schFactory = m_injector.getInstance(ServiceComponentHostFactory.class);
m_clusters = m_injector.getInstance(Clusters.class);
m_alertHelper = m_injector.getInstance(AlertDaoHelper.class);
+ hostComponentDesiredStateDAO = m_injector.getInstance(HostComponentDesiredStateDAO.class);
+ hostComponentStateDAO = m_injector.getInstance(HostComponentStateDAO.class);
// !!! need a synchronous op for testing
EventBusSynchronizer.synchronizeAmbariEventPublisher(m_injector);
m_cluster = m_clusters.getClusterById(m_helper.createCluster());
m_helper.initializeClusterWithStack(m_cluster);
+ }
+
+ /**
+ *
+ */
+ @Before
+ public void setup() throws Exception {
+ m_injector.getInstance(UnitOfWork.class).begin();
+ }
+
+ /**
+ * @throws Exception
+ */
+ @After
+ public void teardown() throws Exception {
+ m_injector.getInstance(UnitOfWork.class).end();
+ cleanup();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ m_injector.getInstance(PersistService.class).stop();
+ }
+
+ private void cleanup() throws AmbariException {
+ List<AlertGroupEntity> alertGroupEntities = m_dao.findAllGroups();
+ if (alertGroupEntities != null) {
+ for (AlertGroupEntity alertGroupEntity : alertGroupEntities) {
+ m_dao.remove(alertGroupEntity);
+ }
+ }
+ List<AlertTargetEntity> alertTargetEntities = m_dao.findAllTargets();
+ if (alertTargetEntities != null) {
+ for (AlertTargetEntity alertTargetEntity : alertTargetEntities) {
+ m_dao.remove(alertTargetEntity);
+ }
+ }
+
+ List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
+ if (hostComponentDesiredStateEntities != null) {
+ for (HostComponentDesiredStateEntity hcdse : hostComponentDesiredStateEntities) {
+ hostComponentDesiredStateDAO.remove(hcdse);
+ }
+ }
+
+ List<HostComponentStateEntity> hostComponentStateEntities = hostComponentStateDAO.findAll();
+ if (hostComponentStateEntities != null) {
+ for (HostComponentStateEntity hcse : hostComponentStateEntities) {
+ hostComponentStateDAO.remove(hcse);
+ }
+ }
+
+ List<AlertDefinitionEntity> alertDefinitionEntities = m_definitionDao.findAll();
+ if (alertDefinitionEntities != null) {
+ for (AlertDefinitionEntity alertDefinitionEntity : alertDefinitionEntities) {
+ m_definitionDao.remove(alertDefinitionEntity);
+ }
+ }
+
+ m_cluster.deleteAllServices();
+
+ List<Host> hosts = m_clusters.getHosts();
+ if (hosts != null) {
+ for (Host host : hosts) {
+ m_clusters.deleteHost(host.getHostName());
+ }
+ }
+ }
+
+ private void initTestData() throws Exception {
Set<AlertTargetEntity> targets = createTargets();
for (int i = 0; i < 10; i++) {
@@ -140,20 +207,11 @@ public class AlertDispatchDAOTest {
}
/**
- * @throws Exception
- */
- @After
- public void teardown() throws Exception {
- m_injector.getInstance(UnitOfWork.class).end();
- m_injector.getInstance(PersistService.class).stop();
- m_injector = null;
- }
-
- /**
*
*/
@Test
public void testFindAllTargets() throws Exception {
+ initTestData();
List<AlertTargetEntity> targets = m_dao.findAllTargets();
assertNotNull(targets);
assertEquals(5, targets.size());
@@ -180,17 +238,21 @@ public class AlertDispatchDAOTest {
*
*/
@Test
- public void testFindAllGlobalTargets() throws Exception {
+ public void testCreateAndFindAllGlobalTargets() throws Exception {
List<AlertTargetEntity> targets = m_dao.findAllGlobalTargets();
assertNotNull(targets);
assertEquals(0, targets.size());
- m_helper.createGlobalAlertTarget();
+ AlertTargetEntity target = m_helper.createGlobalAlertTarget();
m_helper.createGlobalAlertTarget();
m_helper.createGlobalAlertTarget();
targets = m_dao.findAllGlobalTargets();
+ assertTrue(target.isGlobal());
assertEquals(3, targets.size());
+
+ m_dao.findTargetByName(target.getTargetName());
+ assertTrue( target.isGlobal() );
}
/**
@@ -198,6 +260,7 @@ public class AlertDispatchDAOTest {
*/
@Test
public void testFindTargetByName() throws Exception {
+ initTestData();
List<AlertTargetEntity> targets = m_dao.findAllTargets();
assertNotNull(targets);
AlertTargetEntity target = targets.get(3);
@@ -211,6 +274,7 @@ public class AlertDispatchDAOTest {
*/
@Test
public void testFindAllGroups() throws Exception {
+ initTestData();
List<AlertGroupEntity> groups = m_dao.findAllGroups();
assertNotNull(groups);
assertEquals(10, groups.size());
@@ -221,6 +285,7 @@ public class AlertDispatchDAOTest {
*/
@Test
public void testFindGroupByName() throws Exception {
+ initTestData();
List<AlertGroupEntity> groups = m_dao.findAllGroups();
assertNotNull(groups);
AlertGroupEntity group = groups.get(3);
@@ -236,6 +301,7 @@ public class AlertDispatchDAOTest {
*/
@Test
public void testFindGroupsByIds() throws Exception {
+ initTestData();
List<AlertGroupEntity> groups = m_dao.findAllGroups();
assertNotNull(groups);
assertEquals(10, groups.size());
@@ -269,43 +335,7 @@ public class AlertDispatchDAOTest {
assertEquals(group.getAlertDefinitions(), actual.getAlertDefinitions());
}
- /**
- *
- */
- @Test
- public void testGroupDefinitions() throws Exception {
- List<AlertDefinitionEntity> definitions = createDefinitions();
- AlertGroupEntity group = m_helper.createAlertGroup(
- m_cluster.getClusterId(), null);
-
- group = m_dao.findGroupById(group.getGroupId());
- assertNotNull(group);
-
- for (AlertDefinitionEntity definition : definitions) {
- group.addAlertDefinition(definition);
- }
-
- m_dao.merge(group);
-
- group = m_dao.findGroupByName(group.getGroupName());
- assertEquals(definitions.size(), group.getAlertDefinitions().size());
-
- for (AlertDefinitionEntity definition : definitions) {
- assertTrue(group.getAlertDefinitions().contains(definition));
- }
-
- m_definitionDao.refresh(definitions.get(0));
- m_definitionDao.remove(definitions.get(0));
- definitions.remove(0);
-
- group = m_dao.findGroupByName(group.getGroupName());
- assertEquals(definitions.size(), group.getAlertDefinitions().size());
-
- for (AlertDefinitionEntity definition : definitions) {
- assertTrue(group.getAlertDefinitions().contains(definition));
- }
- }
/**
*
@@ -343,18 +373,6 @@ public class AlertDispatchDAOTest {
*
*/
@Test
- public void testCreateGlobalTarget() throws Exception {
- AlertTargetEntity target = m_helper.createGlobalAlertTarget();
- assertTrue( target.isGlobal() );
-
- target = m_dao.findTargetByName(target.getTargetName());
- assertTrue( target.isGlobal() );
- }
-
- /**
- *
- */
- @Test
public void testGlobalTargetAssociations() throws Exception {
AlertGroupEntity group = m_helper.createAlertGroup(
m_cluster.getClusterId(), null);
@@ -598,6 +616,7 @@ public class AlertDispatchDAOTest {
*/
@Test
public void testFindTargetsViaGroupsByDefinition() throws Exception {
+ initTestData();
List<AlertDefinitionEntity> definitions = createDefinitions();
AlertGroupEntity group = m_helper.createAlertGroup(
m_cluster.getClusterId(), null);
@@ -849,6 +868,7 @@ public class AlertDispatchDAOTest {
*/
@Test
public void testFindDefaultGroup() throws Exception {
+ initTestData();
List<AlertGroupEntity> groups = m_dao.findAllGroups();
assertNotNull(groups);
assertEquals(10, groups.size());
@@ -873,6 +893,7 @@ public class AlertDispatchDAOTest {
*/
@Test
public void testDefaultGroupAutomaticCreation() throws Exception {
+ initTestData();
List<AlertGroupEntity> groups = m_dao.findAllGroups();
assertNotNull(groups);
assertEquals(10, groups.size());
@@ -917,6 +938,7 @@ public class AlertDispatchDAOTest {
*/
@Test(expected = AmbariException.class)
public void testDefaultGroupInvalidServiceNoCreation() throws Exception {
+ initTestData();
List<AlertGroupEntity> groups = m_dao.findAllGroups();
assertNotNull(groups);
assertEquals(10, groups.size());
@@ -947,6 +969,7 @@ public class AlertDispatchDAOTest {
} finally {
// assert no group was added
assertEquals(12, m_dao.findAllGroups().size());
+ teardown();
}
}
@@ -999,4 +1022,42 @@ public class AlertDispatchDAOTest {
return targets;
}
+
+ /**
+ *
+ */
+ @Test
+ public void testGroupDefinitions() throws Exception {
+ List<AlertDefinitionEntity> definitions = createDefinitions();
+
+ AlertGroupEntity group = m_helper.createAlertGroup(
+ m_cluster.getClusterId(), null);
+
+ group = m_dao.findGroupById(group.getGroupId());
+ assertNotNull(group);
+
+ for (AlertDefinitionEntity definition : definitions) {
+ group.addAlertDefinition(definition);
+ }
+
+ m_dao.merge(group);
+
+ group = m_dao.findGroupByName(group.getGroupName());
+ assertEquals(definitions.size(), group.getAlertDefinitions().size());
+
+ for (AlertDefinitionEntity definition : definitions) {
+ assertTrue(group.getAlertDefinitions().contains(definition));
+ }
+
+ m_definitionDao.refresh(definitions.get(0));
+ m_definitionDao.remove(definitions.get(0));
+ definitions.remove(0);
+
+ group = m_dao.findGroupByName(group.getGroupName());
+ assertEquals(definitions.size(), group.getAlertDefinitions().size());
+
+ for (AlertDefinitionEntity definition : definitions) {
+ assertTrue(group.getAlertDefinitions().contains(definition));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
index 9b9fee5..a80cd03 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
@@ -43,6 +43,7 @@ import org.apache.ambari.server.orm.entities.ResourceEntity;
import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
import org.apache.ambari.server.orm.entities.UserEntity;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
@@ -55,6 +56,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
public class TestUsers {
private static Injector injector;
@@ -129,6 +131,11 @@ public class TestUsers {
}
+ @AfterClass
+ public static void afterClass() throws Exception {
+ injector.getInstance(PersistService.class).stop();
+ }
+
private void cleanup() throws AmbariException {
for (User user : users.getAllUsers()) {
if (!user.getUserName().equals("admin")) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
index be0aeef..bf72e0c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java
@@ -17,11 +17,17 @@
*/
package org.apache.ambari.server.serveraction.upgrades;
-import com.google.gson.Gson;
-import com.google.inject.Guice;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ServiceNotFoundException;
import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
@@ -32,11 +38,14 @@ import org.apache.ambari.server.agent.ExecutionCommand;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
import org.apache.ambari.server.orm.dao.HostDAO;
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.ClusterVersionEntity;
import org.apache.ambari.server.orm.entities.HostVersionEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.orm.entities.StackEntity;
import org.apache.ambari.server.serveraction.ServerAction;
import org.apache.ambari.server.state.Cluster;
@@ -57,19 +66,15 @@ import org.apache.ambari.server.state.stack.upgrade.PropertyKeyState;
import org.apache.ambari.server.state.stack.upgrade.TransferCoercionType;
import org.apache.ambari.server.state.stack.upgrade.TransferOperation;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import com.google.gson.Gson;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
/**
* Tests upgrade-related server side actions
@@ -81,48 +86,94 @@ public class ConfigureActionTest {
private static final StackId HDP_211_STACK = new StackId("HDP-2.1.1");
private static final StackId HDP_220_STACK = new StackId("HDP-2.2.0");
- private Injector m_injector;
-
- @Inject
- private OrmTestHelper m_helper;
-
- @Inject
- private RepositoryVersionDAO repoVersionDAO;
-
- @Inject
- private HostVersionDAO hostVersionDAO;
-
- @Inject
- private HostRoleCommandFactory hostRoleCommandFactory;
-
- @Inject
- private ServiceFactory serviceFactory;
+ private static Injector m_injector;
+ private static OrmTestHelper m_helper;
+ private static RepositoryVersionDAO repoVersionDAO;
+ private static HostVersionDAO hostVersionDAO;
+ private static HostRoleCommandFactory hostRoleCommandFactory;
+ private static ServiceFactory serviceFactory;
+ private static ConfigHelper m_configHelper;
+ private static Clusters clusters;
+ private static ClusterVersionDAO clusterVersionDAO;
+ private static ConfigFactory cf;
+ private static ConfigureAction action;
+ private static HostDAO hostDAO;
+
+ @BeforeClass
+ public static void classSetUp() throws Exception {
+ m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
+ m_injector.getInstance(GuiceJpaInitializer.class);
- @Inject
- ConfigHelper m_configHelper;
+ m_helper = m_injector.getInstance(OrmTestHelper.class);
+ repoVersionDAO = m_injector.getInstance(RepositoryVersionDAO.class);
+ hostVersionDAO = m_injector.getInstance(HostVersionDAO.class);
+ hostRoleCommandFactory = m_injector.getInstance(HostRoleCommandFactory.class);
+ serviceFactory = m_injector.getInstance(ServiceFactory.class);
+ m_configHelper = m_injector.getInstance(ConfigHelper.class);
+ clusters = m_injector.getInstance(Clusters.class);
+ clusterVersionDAO = m_injector.getInstance(ClusterVersionDAO.class);
+ cf = m_injector.getInstance(ConfigFactory.class);
+ action = m_injector.getInstance(ConfigureAction.class);
+ hostDAO = m_injector.getInstance(HostDAO.class);
+ }
@Before
public void setup() throws Exception {
- m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
- m_injector.getInstance(GuiceJpaInitializer.class);
- m_injector.injectMembers(this);
+
}
@After
public void teardown() throws Exception {
+ cleanup();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
m_injector.getInstance(PersistService.class).stop();
}
+ private void cleanup() throws AmbariException {
+ Map<String, Cluster> clusterMap = clusters.getClusters();
+
+ List<ClusterVersionEntity> clusterVersionEntities = clusterVersionDAO.findAll();
+ if (clusterVersionEntities != null) {
+ for (ClusterVersionEntity cve : clusterVersionEntities) {
+ clusterVersionDAO.remove(cve);
+ }
+ }
+
+ List<RepositoryVersionEntity> repositoryVersionEntities = repoVersionDAO.findAll();
+ if (repositoryVersionEntities != null) {
+ for (RepositoryVersionEntity rve : repositoryVersionEntities) {
+ repoVersionDAO.remove(rve);
+ }
+ }
+
+ List<HostVersionEntity> hostVersionEntities = hostVersionDAO.findAll();
+ if (clusterVersionEntities != null) {
+ for (HostVersionEntity hve : hostVersionEntities) {
+ hostVersionDAO.remove(hve);
+ }
+ }
+
+ for (String clusterName : clusterMap.keySet()) {
+ clusters.deleteCluster(clusterName);
+ }
+
+ for (Host host : clusters.getHosts()) {
+ clusters.deleteHost(host.getHostName());
+ }
+ }
+
@Test
public void testConfigActionUpgradeAcrossStack() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setCurrentStackVersion(HDP_211_STACK);
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {{
put("initLimit", "10");
}}, new HashMap<String, Map<String,String>>());
@@ -156,7 +207,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -180,14 +231,13 @@ public class ConfigureActionTest {
public void testDeletePreserveChanges() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
// create a config for zoo.cfg with two values; one is a stack value and the
// other is custom
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("tickTime", "2000");
@@ -226,7 +276,7 @@ public class ConfigureActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -250,11 +300,10 @@ public class ConfigureActionTest {
public void testConfigTransferCopy() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {{
put("initLimit", "10");
put("copyIt", "10");
@@ -332,7 +381,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -391,11 +440,10 @@ public class ConfigureActionTest {
public void testCoerceValueOnCopy() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("zoo.server.csv", "c6401,c6402, c6403");
@@ -436,7 +484,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -458,11 +506,10 @@ public class ConfigureActionTest {
public void testValueReplacement() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("key_to_replace", "My New Cat");
@@ -508,7 +555,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -534,11 +581,10 @@ public class ConfigureActionTest {
public void testValueReplacementWithMissingConfigurations() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("existing", "This exists!");
@@ -578,7 +624,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -595,12 +641,11 @@ public class ConfigureActionTest {
public void testMultipleKeyValuesPerTask() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setCurrentStackVersion(HDP_211_STACK);
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("fooKey", "barValue");
@@ -641,7 +686,7 @@ public class ConfigureActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -663,12 +708,11 @@ public class ConfigureActionTest {
public void testAllowedSet() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setCurrentStackVersion(HDP_211_STACK);
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("set.key.1", "s1");
@@ -736,7 +780,7 @@ public class ConfigureActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -762,12 +806,11 @@ public class ConfigureActionTest {
public void testDisallowedSet() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setCurrentStackVersion(HDP_211_STACK);
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("set.key.1", "s1");
@@ -825,7 +868,7 @@ public class ConfigureActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -849,12 +892,11 @@ public class ConfigureActionTest {
public void testAllowedReplacment() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setCurrentStackVersion(HDP_211_STACK);
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("replace.key.1", "r1");
@@ -924,7 +966,7 @@ public class ConfigureActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -946,12 +988,11 @@ public class ConfigureActionTest {
public void testDisallowedReplacment() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setCurrentStackVersion(HDP_211_STACK);
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("replace.key.1", "r1");
@@ -1016,7 +1057,7 @@ public class ConfigureActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -1038,11 +1079,10 @@ public class ConfigureActionTest {
public void testAllowedTransferCopy() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {{
put("initLimit", "10");
put("copy.key.1", "c1");
@@ -1126,7 +1166,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -1155,11 +1195,10 @@ public class ConfigureActionTest {
public void testDisallowedTransferCopy() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {{
put("initLimit", "10");
put("copy.key.1", "c1");
@@ -1228,7 +1267,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -1252,11 +1291,10 @@ public class ConfigureActionTest {
public void testAllowedTransferMove() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {{
put("initLimit", "10");
put("move.key.1", "m1");
@@ -1332,7 +1370,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -1362,11 +1400,10 @@ public class ConfigureActionTest {
public void testDisallowedTransferMove() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {{
put("initLimit", "10");
put("move.key.1", "m1");
@@ -1436,7 +1473,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -1467,11 +1504,10 @@ public class ConfigureActionTest {
public void testAllowedTransferDelete() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {{
put("initLimit", "10");
put("delete.key.1", "d1");
@@ -1543,7 +1579,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -1569,11 +1605,10 @@ public class ConfigureActionTest {
public void testDisallowedTransferDelete() throws Exception {
makeUpgradeCluster();
- Cluster c = m_injector.getInstance(Clusters.class).getCluster("c1");
+ Cluster c = clusters.getCluster("c1");
assertEquals(1, c.getConfigsByType("zoo.cfg").size());
c.setDesiredStackVersion(HDP_220_STACK);
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {{
put("initLimit", "10");
put("delete.key.1", "d1");
@@ -1640,7 +1675,7 @@ public class ConfigureActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
executionCommand));
- ConfigureAction action = m_injector.getInstance(ConfigureAction.class);
+
action.setExecutionCommand(executionCommand);
action.setHostRoleCommand(hostRoleCommand);
@@ -1666,7 +1701,6 @@ public class ConfigureActionTest {
String clusterName = "c1";
String hostName = "h1";
- Clusters clusters = m_injector.getInstance(Clusters.class);
clusters.addCluster(clusterName, HDP_220_STACK);
StackDAO stackDAO = m_injector.getInstance(StackDAO.class);
@@ -1682,7 +1716,6 @@ public class ConfigureActionTest {
// service properties will not run!
installService(c, "ZOOKEEPER");
- ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
Config config = cf.createNew(c, "zoo.cfg", new HashMap<String, String>() {
{
put("initLimit", "10");
@@ -1723,7 +1756,6 @@ public class ConfigureActionTest {
c.mapHostVersions(Collections.singleton(hostName), c.getCurrentClusterVersion(),
RepositoryVersionState.CURRENT);
- HostDAO hostDAO = m_injector.getInstance(HostDAO.class);
HostVersionEntity entity = new HostVersionEntity();
entity.setHostEntity(hostDAO.findByName(hostName));
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
index cb63b0f..f1013c2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
@@ -47,6 +47,8 @@ import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.OrmTestHelper;
import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
+import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
+import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
import org.apache.ambari.server.orm.dao.HostDAO;
import org.apache.ambari.server.orm.dao.HostVersionDAO;
import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
@@ -55,6 +57,8 @@ import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
import org.apache.ambari.server.orm.dao.StackDAO;
import org.apache.ambari.server.orm.dao.UpgradeDAO;
import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
+import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
import org.apache.ambari.server.orm.entities.HostVersionEntity;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.orm.entities.RequestEntity;
@@ -81,10 +85,10 @@ import org.apache.ambari.server.state.stack.UpgradePack;
import org.apache.ambari.server.state.stack.upgrade.Direction;
import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import com.google.gson.Gson;
@@ -92,7 +96,6 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.inject.Guice;
-import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
import com.google.inject.persist.UnitOfWork;
@@ -129,13 +132,17 @@ public class UpgradeActionTest {
private static RequestDAO requestDAO;
private static UpgradeDAO upgradeDAO;
private static ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO;
+ private static HostComponentDesiredStateDAO hostComponentDesiredStateDAO;
+ private static HostComponentStateDAO hostComponentStateDAO;
+ private static StackDAO stackDAO;
+ private static AmbariMetaInfo ambariMetaInfo;
+ private static FinalizeUpgradeAction finalizeUpgradeAction;
@BeforeClass
public static void classSetUp() throws NoSuchFieldException, IllegalAccessException {
m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
m_injector.getInstance(GuiceJpaInitializer.class);
- amc = m_injector.getInstance(AmbariManagementController.class);
m_helper = m_injector.getInstance(OrmTestHelper.class);
repoVersionDAO = m_injector.getInstance(RepositoryVersionDAO.class);
clusters = m_injector.getInstance(Clusters.class);
@@ -149,22 +156,35 @@ public class UpgradeActionTest {
requestDAO = m_injector.getInstance(RequestDAO.class);
upgradeDAO = m_injector.getInstance(UpgradeDAO.class);
serviceComponentDesiredStateDAO = m_injector.getInstance(ServiceComponentDesiredStateDAO.class);
-
- m_injector.getInstance(UnitOfWork.class).begin();
-
- // Initialize AmbariManagementController
+ hostComponentDesiredStateDAO = m_injector.getInstance(HostComponentDesiredStateDAO.class);
+ hostComponentStateDAO = m_injector.getInstance(HostComponentStateDAO.class);
amc = m_injector.getInstance(AmbariManagementController.class);
+ stackDAO = m_injector.getInstance(StackDAO.class);
+ ambariMetaInfo = m_injector.getInstance(AmbariMetaInfo.class);
+ finalizeUpgradeAction = m_injector.getInstance(FinalizeUpgradeAction.class);
Field field = AmbariServer.class.getDeclaredField("clusterController");
field.setAccessible(true);
field.set(null, amc);
}
+ @Before
+ public void setup() throws Exception {
+ cleanup();
+ m_injector.getInstance(UnitOfWork.class).begin();
+ }
+
@After
public void teardown() throws Exception {
+ m_injector.getInstance(UnitOfWork.class).end();
cleanup();
}
+ @AfterClass
+ public static void afterClass() throws Exception {
+ m_injector.getInstance(PersistService.class).stop();
+ }
+
private void cleanup() throws AmbariException {
Map<String, Cluster> clusterMap = clusters.getClusters();
@@ -189,6 +209,20 @@ public class UpgradeActionTest {
}
}
+ List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
+ if (hostComponentDesiredStateEntities != null) {
+ for (HostComponentDesiredStateEntity hcdse : hostComponentDesiredStateEntities) {
+ hostComponentDesiredStateDAO.remove(hcdse);
+ }
+ }
+
+ List<HostComponentStateEntity> hostComponentStateEntities = hostComponentStateDAO.findAll();
+ if (hostComponentStateEntities != null) {
+ for (HostComponentStateEntity hcse : hostComponentStateEntities) {
+ hostComponentStateDAO.remove(hcse);
+ }
+ }
+
for (String clusterName : clusterMap.keySet()) {
clusters.deleteCluster(clusterName);
}
@@ -228,7 +262,7 @@ public class UpgradeActionTest {
c.transitionClusterVersion(targetStack, targetRepo, RepositoryVersionState.INSTALLED);
c.mapHostVersions(Collections.singleton(hostName), c.getCurrentClusterVersion(),
- RepositoryVersionState.CURRENT);
+ RepositoryVersionState.CURRENT);
HostVersionEntity entity = new HostVersionEntity();
entity.setHostEntity(hostDAO.findByName(hostName));
@@ -287,7 +321,7 @@ public class UpgradeActionTest {
// Create a host version for the mid repo in CURRENT
c.mapHostVersions(Collections.singleton(hostName), c.getCurrentClusterVersion(),
- RepositoryVersionState.CURRENT);
+ RepositoryVersionState.CURRENT);
// Create a host version for the target repo in UPGRADED
HostVersionEntity entityTarget = new HostVersionEntity();
@@ -300,10 +334,8 @@ public class UpgradeActionTest {
private void makeUpgradeCluster(StackId sourceStack, String sourceRepo, StackId targetStack, String targetRepo) throws Exception {
String hostName = "h1";
- Clusters clusters = m_injector.getInstance(Clusters.class);
clusters.addCluster(clusterName, sourceStack);
- StackDAO stackDAO = m_injector.getInstance(StackDAO.class);
StackEntity stackEntitySource = stackDAO.find(sourceStack.getStackName(), sourceStack.getStackVersion());
StackEntity stackEntityTarget = stackDAO.find(targetStack.getStackName(), targetStack.getStackVersion());
assertNotNull(stackEntitySource);
@@ -347,8 +379,8 @@ public class UpgradeActionTest {
// Create the new repo version
String urlInfo = "[{'repositories':["
- + "{'Repositories/base_url':'http://foo1','Repositories/repo_name':'HDP','Repositories/repo_id':'" + targetStack.getStackId() + "'}"
- + "], 'OperatingSystems/os_type':'redhat6'}]";
+ + "{'Repositories/base_url':'http://foo1','Repositories/repo_name':'HDP','Repositories/repo_id':'" + targetStack.getStackId() + "'}"
+ + "], 'OperatingSystems/os_type':'redhat6'}]";
repoVersionDAO.create(stackEntityTarget, targetRepo, String.valueOf(System.currentTimeMillis()), urlInfo);
@@ -358,22 +390,22 @@ public class UpgradeActionTest {
c.setCurrentStackVersion(targetStack);
c.mapHostVersions(Collections.singleton(hostName), c.getCurrentClusterVersion(),
- RepositoryVersionState.CURRENT);
+ RepositoryVersionState.CURRENT);
// create a single host with the UPGRADED HostVersionEntity
HostDAO hostDAO = m_injector.getInstance(HostDAO.class);
RepositoryVersionEntity repositoryVersionEntity = repoVersionDAO.findByStackAndVersion(
- targetStack, targetRepo);
+ targetStack, targetRepo);
HostVersionEntity entity = new HostVersionEntity(hostDAO.findByName(hostName),
- repositoryVersionEntity, RepositoryVersionState.INSTALLED);
+ repositoryVersionEntity, RepositoryVersionState.INSTALLED);
hostVersionDAO.create(entity);
// verify the UPGRADED host versions were created successfully
List<HostVersionEntity> hostVersions = hostVersionDAO.findByClusterStackAndVersion(clusterName,
- targetStack, targetRepo);
+ targetStack, targetRepo);
assertEquals(1, hostVersions.size());
assertEquals(RepositoryVersionState.INSTALLED, hostVersions.get(0).getState());
@@ -382,10 +414,8 @@ public class UpgradeActionTest {
private void makeCrossStackUpgradeCluster(StackId sourceStack, String sourceRepo, StackId targetStack, String targetRepo) throws Exception {
String hostName = "h1";
- Clusters clusters = m_injector.getInstance(Clusters.class);
clusters.addCluster(clusterName, sourceStack);
- StackDAO stackDAO = m_injector.getInstance(StackDAO.class);
StackEntity stackEntitySource = stackDAO.find(sourceStack.getStackName(), sourceStack.getStackVersion());
StackEntity stackEntityTarget = stackDAO.find(targetStack.getStackName(), targetStack.getStackVersion());
@@ -415,8 +445,8 @@ public class UpgradeActionTest {
// Create the new repo version
String urlInfo = "[{'repositories':["
- + "{'Repositories/base_url':'http://foo1','Repositories/repo_name':'HDP','Repositories/repo_id':'" + targetRepo + "'}"
- + "], 'OperatingSystems/os_type':'redhat6'}]";
+ + "{'Repositories/base_url':'http://foo1','Repositories/repo_name':'HDP','Repositories/repo_id':'" + targetRepo + "'}"
+ + "], 'OperatingSystems/os_type':'redhat6'}]";
repoVersionDAO.create(stackEntityTarget, targetRepo, String.valueOf(System.currentTimeMillis()), urlInfo);
// Start upgrading the newer repo
@@ -424,7 +454,7 @@ public class UpgradeActionTest {
c.transitionClusterVersion(targetStack, targetRepo, RepositoryVersionState.INSTALLED);
c.mapHostVersions(Collections.singleton(hostName), c.getCurrentClusterVersion(),
- RepositoryVersionState.CURRENT);
+ RepositoryVersionState.CURRENT);
HostDAO hostDAO = m_injector.getInstance(HostDAO.class);
@@ -451,9 +481,7 @@ public class UpgradeActionTest {
// That upgrade pack has changes for ZK and NameNode.
String upgradePackName = "upgrade_nonrolling_new_stack";
- AmbariMetaInfo metaInfo = m_injector.getInstance(AmbariMetaInfo.class);
-
- Map<String, UpgradePack> packs = metaInfo.getUpgradePacks(sourceStack.getStackName(), sourceStack.getStackVersion());
+ Map<String, UpgradePack> packs = ambariMetaInfo.getUpgradePacks(sourceStack.getStackName(), sourceStack.getStackVersion());
Assert.assertTrue(packs.containsKey(upgradePackName));
makeCrossStackUpgradeCluster(sourceStack, sourceRepo, targetStack, targetRepo);
@@ -540,11 +568,10 @@ public class UpgradeActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- FinalizeUpgradeAction action = m_injector.getInstance(FinalizeUpgradeAction.class);
- action.setExecutionCommand(executionCommand);
- action.setHostRoleCommand(hostRoleCommand);
+ finalizeUpgradeAction.setExecutionCommand(executionCommand);
+ finalizeUpgradeAction.setHostRoleCommand(hostRoleCommand);
- CommandReport report = action.execute(null);
+ CommandReport report = finalizeUpgradeAction.execute(null);
assertNotNull(report);
assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus());
@@ -599,11 +626,10 @@ public class UpgradeActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- FinalizeUpgradeAction action = m_injector.getInstance(FinalizeUpgradeAction.class);
- action.setExecutionCommand(executionCommand);
- action.setHostRoleCommand(hostRoleCommand);
+ finalizeUpgradeAction.setExecutionCommand(executionCommand);
+ finalizeUpgradeAction.setHostRoleCommand(hostRoleCommand);
- CommandReport report = action.execute(null);
+ CommandReport report = finalizeUpgradeAction.execute(null);
assertNotNull(report);
assertEquals(HostRoleStatus.FAILED.name(), report.getStatus());
assertTrue(report.getStdErr().contains(FinalizeUpgradeAction.PREVIOUS_UPGRADE_NOT_COMPLETED_MSG));
@@ -619,12 +645,11 @@ public class UpgradeActionTest {
makeUpgradeCluster(sourceStack, sourceRepo, targetStack, targetRepo);
// Verify the repo before calling Finalize
- AmbariMetaInfo metaInfo = m_injector.getInstance(AmbariMetaInfo.class);
AmbariCustomCommandExecutionHelper helper = m_injector.getInstance(AmbariCustomCommandExecutionHelper.class);
Host host = clusters.getHost("h1");
Cluster cluster = clusters.getCluster(clusterName);
- RepositoryInfo repo = metaInfo.getRepository(sourceStack.getStackName(), sourceStack.getStackVersion(), "redhat6", sourceStack.getStackId());
+ RepositoryInfo repo = ambariMetaInfo.getRepository(sourceStack.getStackName(), sourceStack.getStackVersion(), "redhat6", sourceStack.getStackId());
assertEquals(HDP_211_CENTOS6_REPO_URL, repo.getBaseUrl());
verifyBaseRepoURL(helper, cluster, host, HDP_211_CENTOS6_REPO_URL);
@@ -640,11 +665,10 @@ public class UpgradeActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- FinalizeUpgradeAction action = m_injector.getInstance(FinalizeUpgradeAction.class);
- action.setExecutionCommand(executionCommand);
- action.setHostRoleCommand(hostRoleCommand);
+ finalizeUpgradeAction.setExecutionCommand(executionCommand);
+ finalizeUpgradeAction.setHostRoleCommand(hostRoleCommand);
- CommandReport report = action.execute(null);
+ CommandReport report = finalizeUpgradeAction.execute(null);
assertNotNull(report);
assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus());
@@ -682,13 +706,12 @@ public class UpgradeActionTest {
}
// Verify the repo before calling Finalize
- AmbariMetaInfo metaInfo = m_injector.getInstance(AmbariMetaInfo.class);
AmbariCustomCommandExecutionHelper helper = m_injector.getInstance(AmbariCustomCommandExecutionHelper.class);
Host host = clusters.getHost("h1");
Cluster cluster = clusters.getCluster(clusterName);
- RepositoryInfo repo = metaInfo.getRepository(sourceStack.getStackName(),
- sourceStack.getStackVersion(), "redhat6", sourceStack.getStackId());
+ RepositoryInfo repo = ambariMetaInfo.getRepository(sourceStack.getStackName(),
+ sourceStack.getStackVersion(), "redhat6", sourceStack.getStackId());
assertEquals(HDP_211_CENTOS6_REPO_URL, repo.getBaseUrl());
verifyBaseRepoURL(helper, cluster, host, HDP_211_CENTOS6_REPO_URL);
@@ -704,11 +727,10 @@ public class UpgradeActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- FinalizeUpgradeAction action = m_injector.getInstance(FinalizeUpgradeAction.class);
- action.setExecutionCommand(executionCommand);
- action.setHostRoleCommand(hostRoleCommand);
+ finalizeUpgradeAction.setExecutionCommand(executionCommand);
+ finalizeUpgradeAction.setHostRoleCommand(hostRoleCommand);
- CommandReport report = action.execute(null);
+ CommandReport report = finalizeUpgradeAction.execute(null);
assertNotNull(report);
assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus());
}
@@ -755,11 +777,10 @@ public class UpgradeActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- FinalizeUpgradeAction action = m_injector.getInstance(FinalizeUpgradeAction.class);
- action.setExecutionCommand(executionCommand);
- action.setHostRoleCommand(hostRoleCommand);
+ finalizeUpgradeAction.setExecutionCommand(executionCommand);
+ finalizeUpgradeAction.setHostRoleCommand(hostRoleCommand);
- CommandReport report = action.execute(null);
+ CommandReport report = finalizeUpgradeAction.execute(null);
assertNotNull(report);
assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus());
@@ -833,11 +854,10 @@ public class UpgradeActionTest {
assertTrue(hve.getState() == RepositoryVersionState.INSTALLED);
}
- FinalizeUpgradeAction action = m_injector.getInstance(FinalizeUpgradeAction.class);
- action.setExecutionCommand(executionCommand);
- action.setHostRoleCommand(hostRoleCommand);
+ finalizeUpgradeAction.setExecutionCommand(executionCommand);
+ finalizeUpgradeAction.setHostRoleCommand(hostRoleCommand);
- CommandReport report = action.execute(null);
+ CommandReport report = finalizeUpgradeAction.execute(null);
assertNotNull(report);
assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus());
@@ -900,7 +920,7 @@ public class UpgradeActionTest {
// inject an unhappy path where the cluster repo version is still UPGRADING
// even though all of the hosts are UPGRADED
ClusterVersionEntity upgradingClusterVersion = clusterVersionDAO.findByClusterAndStackAndVersion(
- clusterName, HDP_22_STACK, targetRepo);
+ clusterName, HDP_22_STACK, targetRepo);
upgradingClusterVersion.setState(RepositoryVersionState.INSTALLING);
upgradingClusterVersion = clusterVersionDAO.merge(upgradingClusterVersion);
@@ -931,11 +951,10 @@ public class UpgradeActionTest {
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- FinalizeUpgradeAction action = m_injector.getInstance(FinalizeUpgradeAction.class);
- action.setExecutionCommand(executionCommand);
- action.setHostRoleCommand(hostRoleCommand);
+ finalizeUpgradeAction.setExecutionCommand(executionCommand);
+ finalizeUpgradeAction.setHostRoleCommand(hostRoleCommand);
- CommandReport report = action.execute(null);
+ CommandReport report = finalizeUpgradeAction.execute(null);
assertNotNull(report);
assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus());
@@ -958,7 +977,6 @@ public class UpgradeActionTest {
makeUpgradeCluster(sourceStack, sourceRepo, targetStack, targetRepo);
// Verify the repo before calling Finalize
- AmbariMetaInfo metaInfo = m_injector.getInstance(AmbariMetaInfo.class);
AmbariCustomCommandExecutionHelper helper = m_injector.getInstance(AmbariCustomCommandExecutionHelper.class);
Host host = clusters.getHost("h1");
Cluster cluster = clusters.getCluster(clusterName);
@@ -997,12 +1015,12 @@ public class UpgradeActionTest {
// verify that no history exist exists yet
List<ServiceComponentHistoryEntity> historyEntites = serviceComponentDesiredStateDAO.findHistory(
- cluster.getClusterId(), nnSCH.getServiceName(),
- nnSCH.getServiceComponentName());
+ cluster.getClusterId(), nnSCH.getServiceName(),
+ nnSCH.getServiceComponentName());
assertEquals(0, historyEntites.size());
- RepositoryInfo repo = metaInfo.getRepository(sourceStack.getStackName(), sourceStack.getStackVersion(), "redhat6", sourceStack.getStackId());
+ RepositoryInfo repo = ambariMetaInfo.getRepository(sourceStack.getStackName(), sourceStack.getStackVersion(), "redhat6", sourceStack.getStackId());
assertEquals(HDP_211_CENTOS6_REPO_URL, repo.getBaseUrl());
verifyBaseRepoURL(helper, cluster, host, HDP_211_CENTOS6_REPO_URL);
@@ -1020,11 +1038,10 @@ public class UpgradeActionTest {
HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null);
hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand));
- FinalizeUpgradeAction action = m_injector.getInstance(FinalizeUpgradeAction.class);
- action.setExecutionCommand(executionCommand);
- action.setHostRoleCommand(hostRoleCommand);
+ finalizeUpgradeAction.setExecutionCommand(executionCommand);
+ finalizeUpgradeAction.setHostRoleCommand(hostRoleCommand);
- CommandReport report = action.execute(null);
+ CommandReport report = finalizeUpgradeAction.execute(null);
assertNotNull(report);
assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus());
@@ -1033,7 +1050,7 @@ public class UpgradeActionTest {
// ensure that history now exists
historyEntites = serviceComponentDesiredStateDAO.findHistory(cluster.getClusterId(),
- nnSCH.getServiceName(), nnSCH.getServiceComponentName());
+ nnSCH.getServiceName(), nnSCH.getServiceComponentName());
assertEquals(1, historyEntites.size());
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8425f1fa/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
index 79fe0e9..897e955 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
@@ -18,6 +18,7 @@
package org.apache.ambari.server.state;
+import junit.framework.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -26,8 +27,6 @@ import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.Assert;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ServiceResponse;
@@ -36,7 +35,9 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import com.google.inject.Guice;
@@ -45,25 +46,25 @@ import com.google.inject.persist.PersistService;
public class ServiceTest {
- private Clusters clusters;
- private Cluster cluster;
- private String clusterName;
- private Injector injector;
- private ServiceFactory serviceFactory;
- private ServiceComponentFactory serviceComponentFactory;
- private ServiceComponentHostFactory serviceComponentHostFactory;
- private AmbariMetaInfo metaInfo;
-
- @Before
- public void setup() throws Exception {
+ private static Clusters clusters;
+ private static Cluster cluster;
+ private static String clusterName;
+ private static Injector injector;
+ private static ServiceFactory serviceFactory;
+ private static ServiceComponentFactory serviceComponentFactory;
+ private static ServiceComponentHostFactory serviceComponentHostFactory;
+ private static AmbariMetaInfo metaInfo;
+
+ @BeforeClass
+ public static void classSetUp() throws Exception {
injector = Guice.createInjector(new InMemoryDefaultTestModule());
injector.getInstance(GuiceJpaInitializer.class);
clusters = injector.getInstance(Clusters.class);
serviceFactory = injector.getInstance(ServiceFactory.class);
serviceComponentFactory = injector.getInstance(
- ServiceComponentFactory.class);
+ ServiceComponentFactory.class);
serviceComponentHostFactory = injector.getInstance(
- ServiceComponentHostFactory.class);
+ ServiceComponentHostFactory.class);
metaInfo = injector.getInstance(AmbariMetaInfo.class);
clusterName = "foo";
clusters.addCluster(clusterName, new StackId("HDP-0.1"));
@@ -71,11 +72,67 @@ public class ServiceTest {
Assert.assertNotNull(cluster);
}
+ @Before
+ public void setup() throws Exception {
+
+ }
+
@After
public void teardown() throws AmbariException {
+ //injector.getInstance(PersistService.class).stop();
+ cleanup();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
injector.getInstance(PersistService.class).stop();
}
+ private void cleanup() throws AmbariException {
+ cluster.deleteAllServices();
+ }
+
+ @Test
+ public void testCanBeRemoved() throws Exception{
+ Service service = cluster.addService("HDFS");
+
+ for (State state : State.values()) {
+ service.setDesiredState(state);
+ // service does not have any components, so it can be removed,
+ // even if the service is in non-removable state.
+ org.junit.Assert.assertTrue(service.canBeRemoved());
+ }
+
+ ServiceComponent component = service.addServiceComponent("NAMENODE");
+
+ // component can be removed
+ component.setDesiredState(State.INSTALLED);
+
+ for (State state : State.values()) {
+ service.setDesiredState(state);
+ // should always be true if the sub component can be removed
+ org.junit.Assert.assertTrue(service.canBeRemoved());
+ }
+
+ // can remove a STARTED component as whether a service can be removed
+ // is ultimately decided based on if the host components can be removed
+ component.setDesiredState(State.INSTALLED);
+ addHostToCluster("h1", service.getCluster().getClusterName());
+ ServiceComponentHost sch = serviceComponentHostFactory.createNew(component, "h1");
+ component.addServiceComponentHost(sch);
+ sch.setDesiredState(State.STARTED);
+ sch.setState(State.STARTED);
+
+ for (State state : State.values()) {
+ service.setDesiredState(state);
+ // should always be false if the sub component can not be removed
+ org.junit.Assert.assertFalse(service.canBeRemoved());
+ }
+
+ sch.setDesiredState(State.INSTALLED);
+ sch.setState(State.INSTALLED);
+ }
+
@Test
public void testCreateService() throws AmbariException {
String serviceName = "HDFS";
@@ -260,43 +317,6 @@ public class ServiceTest {
}
- @Test
- public void testCanBeRemoved() throws Exception{
- Service service = cluster.addService("HDFS");
-
- for (State state : State.values()) {
- service.setDesiredState(state);
- // service does not have any components, so it can be removed,
- // even if the service is in non-removable state.
- org.junit.Assert.assertTrue(service.canBeRemoved());
- }
-
- ServiceComponent component = service.addServiceComponent("NAMENODE");
-
- // component can be removed
- component.setDesiredState(State.INSTALLED);
-
- for (State state : State.values()) {
- service.setDesiredState(state);
- // should always be true if the sub component can be removed
- org.junit.Assert.assertTrue(service.canBeRemoved());
- }
-
- // can remove a STARTED component as whether a service can be removed
- // is ultimately decided based on if the host components can be removed
- component.setDesiredState(State.INSTALLED);
- addHostToCluster("h1", service.getCluster().getClusterName());
- ServiceComponentHost sch = serviceComponentHostFactory.createNew(component, "h1");
- component.addServiceComponentHost(sch);
- sch.setDesiredState(State.STARTED);
- sch.setState(State.STARTED);
-
- for (State state : State.values()) {
- service.setDesiredState(state);
- // should always be false if the sub component can not be removed
- org.junit.Assert.assertFalse(service.canBeRemoved());
- }
- }
@Test
public void testServiceMaintenance() throws Exception {