diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java deleted file mode 100644 index 035116abaf4..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java +++ /dev/null @@ -1,58 +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.checks; - -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Checks if Atlas service is present. Upgrade to stack HDP 2.5 from previous stack - * must first delete Atlas from the cluster. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.DEFAULT) -public class AtlasPresenceCheck extends AbstractCheckDescriptor{ - - private static final String serviceName = "ATLAS"; - - public AtlasPresenceCheck(){ - super(CheckDescription.ATLAS_SERVICE_PRESENCE_CHECK); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet(serviceName); - } - - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - prerequisiteCheck.getFailedOn().add(serviceName); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java index 20bb1b00e4d..d1573578554 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java @@ -88,19 +88,6 @@ public class CheckDescription { .put(AbstractCheckDescriptor.DEFAULT, "The following hosts must have version {{version}} installed: {{fails}}.").build()); - public static CheckDescription SECONDARY_NAMENODE_MUST_BE_DELETED = new CheckDescription("SECONDARY_NAMENODE_MUST_BE_DELETED", - PrereqCheckType.HOST, - "The SNameNode component must be deleted from all hosts", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, "The SNameNode component must be deleted from host: %s.").build()); - - public static CheckDescription SERVICES_HIVE_MULTIPLE_METASTORES = new CheckDescription("SERVICES_HIVE_MULTIPLE_METASTORES", - PrereqCheckType.SERVICE, - "Hive Metastore Availability", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "Multiple Hive Metastore instances are recommended for Rolling Upgrade. This ensures that there is at least one Metastore running during the upgrade process.").build()); - public static CheckDescription SERVICES_MAINTENANCE_MODE = new CheckDescription("SERVICES_MAINTENANCE_MODE", PrereqCheckType.SERVICE, "No services can be in Maintenance Mode", @@ -108,46 +95,6 @@ public class CheckDescription { .put(AbstractCheckDescriptor.DEFAULT, "The following Services must not be in Maintenance Mode: {{fails}}.").build()); - public static CheckDescription SERVICES_MR_DISTRIBUTED_CACHE = new CheckDescription("SERVICES_MR_DISTRIBUTED_CACHE", - PrereqCheckType.SERVICE, - "MapReduce should reference Hadoop libraries from the distributed cache in HDFS", - new ImmutableMap.Builder() - .put(ServicesMapReduceDistributedCacheCheck.KEY_APP_CLASSPATH, - "The mapred-site.xml property mapreduce.application.classpath should be set.") - .put(ServicesMapReduceDistributedCacheCheck.KEY_FRAMEWORK_PATH, - "The mapred-site.xml property mapreduce.application.framework.path should be set.") - .put(ServicesMapReduceDistributedCacheCheck.KEY_NOT_DFS, - "The mapred-site.xml property mapreduce.application.framework.path or the core-site.xml property fs.defaultFS should point to *dfs:/ url.").build()); - - public static CheckDescription SERVICES_NAMENODE_HA = new CheckDescription("SERVICES_NAMENODE_HA", - PrereqCheckType.SERVICE, - "NameNode High Availability must be enabled", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "NameNode High Availability is not enabled. Verify that dfs.internal.nameservices property is present in hdfs-site.xml.").build()); - - public static CheckDescription SERVICES_NAMENODE_TRUNCATE = new CheckDescription("SERVICES_NAMENODE_TRUNCATE", - PrereqCheckType.SERVICE, - "NameNode Truncate must not be allowed", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "NameNode Truncate is allowed. Verify that dfs.allow.truncate is set to 'false' in hdfs-site.xml.").build()); - - public static CheckDescription SERVICES_TEZ_DISTRIBUTED_CACHE = new CheckDescription("SERVICES_TEZ_DISTRIBUTED_CACHE", - PrereqCheckType.SERVICE, - "Tez should reference Hadoop libraries from the distributed cache in HDFS", - new ImmutableMap.Builder() - .put(ServicesTezDistributedCacheCheck.KEY_LIB_URI_MISSING, - "The tez-site.xml property tez.lib.uris should be set.") - .put(ServicesTezDistributedCacheCheck.KEY_USE_HADOOP_LIBS, - "The tez-site.xml property tez.use.cluster-hadoop-libs should be set.") - .put(ServicesTezDistributedCacheCheck.KEY_LIB_NOT_DFS, - "The tez-site.xml property tez.lib.uris or the core-site.xml property fs.defaultFS should point to *dfs:/ url.") - .put(ServicesTezDistributedCacheCheck.KEY_LIB_NOT_TARGZ, - "The tez-site.xml property tez.lib.uris should point to tar.gz file.") - .put(ServicesTezDistributedCacheCheck.KEY_USE_HADOOP_LIBS_FALSE, - "The tez-site.xml property tez.use.cluster.hadoop-libs should be set to false.").build()); - public static CheckDescription SERVICES_UP = new CheckDescription("SERVICES_UP", PrereqCheckType.SERVICE, "All services must be started", @@ -176,49 +123,6 @@ public class CheckDescription { .put(AbstractCheckDescriptor.DEFAULT, "Re-run Install Packages before starting upgrade").build()); - public static CheckDescription SERVICES_YARN_WP = new CheckDescription("SERVICES_YARN_WP", - PrereqCheckType.SERVICE, - "YARN work preserving restart should be enabled", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "YARN should have work preserving restart enabled. The yarn-site.xml property yarn.resourcemanager.work-preserving-recovery.enabled property should be set to true.").build()); - - public static CheckDescription SERVICES_YARN_RM_HA = new CheckDescription("SERVICES_YARN_RM_HA", - PrereqCheckType.SERVICE, - "YARN ResourceManager High Availability is not enabled.", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "YARN ResourceManager HA should be enabled to prevent a disruption in service during the upgrade").build()); - - public static CheckDescription SERVICES_YARN_TIMELINE_ST = new CheckDescription("SERVICES_YARN_TIMELINE_ST", - PrereqCheckType.SERVICE, - "YARN Timeline state preserving restart should be enabled", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "YARN should have state preserving restart enabled for the Timeline server. The yarn-site.xml property yarn.timeline-service.recovery.enabled should be set to true.").build()); - - public static CheckDescription SERVICES_MR2_JOBHISTORY_ST = new CheckDescription("SERVICES_MR2_JOBHISTORY_ST", - PrereqCheckType.SERVICE, - "MapReduce2 JobHistory recovery should be enabled", - new ImmutableMap.Builder() - .put(MapReduce2JobHistoryStatePreservingCheck.MAPREDUCE2_JOBHISTORY_RECOVERY_ENABLE_KEY, - "MapReduce2 should have recovery enabled for the JobHistory server. The mapred-site.xml property mapreduce.jobhistory.recovery.enable should be set to true.") - .put(MapReduce2JobHistoryStatePreservingCheck.MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_KEY, - "MapReduce2 should have recovery enabled for the JobHistory server. The mapred-site.xml property mapreduce.jobhistory.recovery.store.class should be set to org.apache.hadoop.mapreduce.v2.hs.HistoryServerLeveldbStateStoreService.") - .put(MapReduce2JobHistoryStatePreservingCheck.MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_LEVELDB_PATH_KEY, - "MapReduce2 should have recovery enabled for the JobHistory server. The mapred-site.xml property mapreduce.jobhistory.recovery.store.leveldb.path should be set. Please note that \"mapreduce.jobhistory.recovery.store.leveldb.path\" should be on a mount with ~3 GB of free space.").build()); - - public static CheckDescription SERVICES_HIVE_DYNAMIC_SERVICE_DISCOVERY = new CheckDescription("SERVICES_HIVE_DYNAMIC_SERVICE_DISCOVERY", - PrereqCheckType.SERVICE, - "Hive Dynamic Service Discovery", - new ImmutableMap.Builder() - .put(HiveDynamicServiceDiscoveryCheck.HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY, - "The hive-site.xml property hive.server2.support.dynamic.service.discovery should be set to true.") - .put(HiveDynamicServiceDiscoveryCheck.HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY, - "The hive-site.xml property hive.zookeeper.quorum should be set to a comma-separate list of ZooKeeper hosts:port pairs.") - .put(HiveDynamicServiceDiscoveryCheck.HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY, - "The hive-site.xml property hive.server2.zookeeper.namespace should be set to the value for the root namespace on ZooKeeper.").build()); - public static CheckDescription CONFIG_MERGE = new CheckDescription("CONFIG_MERGE", PrereqCheckType.CLUSTER, "Configuration Merge Check", @@ -241,34 +145,6 @@ public class CheckDescription { .put(AbstractCheckDescriptor.DEFAULT, "There are components which are not reporting the expected stack version: \n%s").build()); - public static CheckDescription SERVICES_RANGER_PASSWORD_VERIFY = new CheckDescription("SERVICES_RANGER_PASSWORD_VERIFY", - PrereqCheckType.SERVICE, - "Verify Ambari and Ranger Password Synchronization", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "There was a problem verifying Ranger and Ambari users") - .put(RangerPasswordCheck.KEY_RANGER_PASSWORD_MISMATCH, - "Credentials for user '%s' in Ambari do not match Ranger.") - .put(RangerPasswordCheck.KEY_RANGER_UNKNOWN_RESPONSE, - "Could not verify credentials for user '%s'. Response code %s received from %s") - .put(RangerPasswordCheck.KEY_RANGER_COULD_NOT_ACCESS, - "Could not access Ranger to verify user '%s' against %s. %s") - .put(RangerPasswordCheck.KEY_RANGER_USERS_ELEMENT_MISSING, - "The response from Ranger received, but there is no users element. Request: %s") - .put(RangerPasswordCheck.KEY_RANGER_OTHER_ISSUE, - "The response from Ranger was malformed. %s. Request: %s") - .put(RangerPasswordCheck.KEY_RANGER_CONFIG_MISSING, - "Could not check credentials. Missing property %s/%s").build()); - - public static CheckDescription ATLAS_SERVICE_PRESENCE_CHECK = new CheckDescription("ATLAS_SERVICE_PRESENCE_CHECK", - PrereqCheckType.SERVICE, - "Atlas Is Not Supported For Upgrades", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "The Atlas service is currently installed on the cluster. " + - "This service does not support upgrades and must be removed before the upgrade can continue. " + - "After upgrading, Atlas can be reinstalled").build()); - public static CheckDescription SERVICE_PRESENCE_CHECK = new CheckDescription("SERVICE_PRESENCE_CHECK", PrereqCheckType.SERVICE, "Service Is Not Supported For Upgrades", @@ -282,35 +158,6 @@ public class CheckDescription { "This service is removed from the new release and must be removed before the upgrade can continue. " + "After upgrading, %s can be installed").build()); - public static CheckDescription RANGER_SERVICE_AUDIT_DB_CHECK = new CheckDescription("RANGER_SERVICE_AUDIT_DB_CHECK", - PrereqCheckType.SERVICE, - "Remove the Ranger Audit to Database Capability", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "After upgrading, Ranger will no longer support the Audit to Database feature. Instead, Ranger will audit to Solr. " + - "To migrate the existing audit logs to Solr, follow the steps in Apache Ranger documention for 0.6 release.").build()); - - public static CheckDescription KAFKA_KERBEROS_CHECK = new CheckDescription("KAFKA_KERBEROS_CHECK", - PrereqCheckType.SERVICE, - "Kafka upgrade on Kerberized cluster", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "Kafka is currently not Kerberized, but your cluster is. After upgrading, Kafka will automatically be Kerberized for you.").build()); - - public static CheckDescription SERVICES_HIVE_ROLLING_WARNING = new CheckDescription("SERVICES_HIVE_ROLLING_WARNING", - PrereqCheckType.SERVICE, - "HiveServer2 Downtime", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "HiveServer2 does not currently support rolling upgrades. HiveServer2 will be upgraded, however existing queries which have not completed will fail and need to be resubmitted after HiveServer2 has been upgraded.").build()); - - public static CheckDescription SERVICES_STORM_ROLLING_WARNING = new CheckDescription("SERVICES_STORM_ROLLING_WARNING", - PrereqCheckType.SERVICE, - "Storm Downtime During Upgrade", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "Storm does not support rolling upgrades on this version of the stack. If you proceed, you will be required to stop all running topologies before Storm is restarted.").build()); - public static CheckDescription AUTO_START_DISABLED = new CheckDescription("AUTO_START_DISABLED", PrereqCheckType.CLUSTER, "Auto-Start Disabled Check", @@ -319,13 +166,6 @@ public class CheckDescription { "Auto Start must be disabled before performing an Upgrade. To disable Auto Start, navigate to " + "Admin > Service Auto Start. Turn the toggle switch off to Disabled and hit Save.").build()); - public static CheckDescription RANGER_SSL_CONFIG_CHECK = new CheckDescription("RANGER_SSL_CONFIG_CHECK", - PrereqCheckType.SERVICE, - "Change Ranger SSL configuration path for Keystore and Truststore.", - new ImmutableMap.Builder() - .put(AbstractCheckDescriptor.DEFAULT, - "As Ranger is SSL enabled, Ranger SSL configurations will need to be changed from default value of /etc/ranger/*/conf folder to /etc/ranger/security. " + - "Since the certificates/keystores/truststores in this path may affect the upgrade/downgrade process, it is recommended to manually move the certificates/keystores/truststores out of the conf folders and change the appropriate config values before proceeding.").build()); public static CheckDescription LZO_CONFIG_CHECK = new CheckDescription("LZO_CONFIG_CHECK", PrereqCheckType.CLUSTER, @@ -350,25 +190,13 @@ public class CheckDescription { .put(AbstractCheckDescriptor.DEFAULT, "The following components do not exist in the target repository's stack. They must be removed from the cluster before upgrading.") .build()); - public static CheckDescription DRUID_HA_WARNING = new CheckDescription( - "DRUID_HA", - PrereqCheckType.SERVICE, - "Druid Downtime During Upgrade", - new ImmutableMap.Builder() - .put( - AbstractCheckDescriptor.DEFAULT, - "High Availability is not enabled for Druid. Druid Service may have some downtime during upgrade. Deploy multiple instances of %s in the Cluster to avoid any downtime." - ) - .build() - ); - public static CheckDescription VALID_SERVICES_INCLUDED_IN_REPOSITORY = new CheckDescription("VALID_SERVICES_INCLUDED_IN_REPOSITORY", PrereqCheckType.CLUSTER, "The repository is missing services which are required", new ImmutableMap.Builder() .put(AbstractCheckDescriptor.DEFAULT, "The following services are included in the upgrade but the repository is missing their dependencies:\n%s").build()); - + private String m_name; private PrereqCheckType m_type; diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheck.java deleted file mode 100644 index 28a3f298e84..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheck.java +++ /dev/null @@ -1,121 +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.checks; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.ServiceComponentNotFoundException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.ServiceComponent; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.commons.lang.StringUtils; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Checks that namenode high availability is enabled. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.MULTIPLE_COMPONENT_WARNING, order = 16.0f) -public class DruidHighAvailabilityCheck extends AbstractCheckDescriptor -{ - - public static final String DRUID_SERVICE_NAME = "DRUID"; - public static final String[] DRUID_COMPONENT_NAMES = new String[]{ - "DRUID_BROKER", - "DRUID_COORDINATOR", - "DRUID_HISTORICAL", - "DRUID_OVERLORD", - "DRUID_MIDDLEMANAGER", - "DRUID_ROUTER" - }; - - /** - * Constructor. - */ - public DruidHighAvailabilityCheck() - { - super(CheckDescription.DRUID_HA_WARNING); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() - { - return Sets.newHashSet(DRUID_SERVICE_NAME); - } - - /** - * {@inheritDoc} - */ - @Override - public List getQualifications() - { - return Arrays.asList( - new PriorCheckQualification(CheckDescription.DRUID_HA_WARNING)); - } - - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException - { - List haNotEnabledComponents = Lists.newArrayList(); - for (String component : DRUID_COMPONENT_NAMES) { - Set hosts = getHostsForComponent(request, component); - if (hosts.size() == 1) { - // This component is installed on only 1 host, HA is not enabled for it. - haNotEnabledComponents.add(component); - } - } - if (!haNotEnabledComponents.isEmpty()) { - prerequisiteCheck.getFailedOn().add(DRUID_SERVICE_NAME); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - String failReason = getFailReason(prerequisiteCheck, request); - prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(haNotEnabledComponents.toArray(), ", "))); - } - - } - - private Set getHostsForComponent(PrereqCheckRequest request, String componentName) - throws AmbariException - { - Set hosts = new HashSet<>(); - final String clusterName = request.getClusterName(); - final Cluster cluster = clustersProvider.get().getCluster(clusterName); - try { - ServiceComponent serviceComponent = cluster.getService(DRUID_SERVICE_NAME).getServiceComponent(componentName); - if (serviceComponent != null) { - hosts = serviceComponent.getServiceComponentHosts().keySet(); - } - } - catch (ServiceComponentNotFoundException err) { - // This exception can be ignored if the component doesn't exist because it is a best-attempt at finding it. - } - - return hosts; - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheck.java deleted file mode 100644 index c631013cf52..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheck.java +++ /dev/null @@ -1,128 +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.checks; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; -import org.apache.ambari.server.state.stack.upgrade.UpgradeType; -import org.apache.ambari.server.utils.VersionUtils; -import org.apache.commons.lang.StringUtils; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * The {@link HiveDynamicServiceDiscoveryCheck} class is used to check that HIVE - * is properly configured for dynamic discovery. - */ -@Singleton -@UpgradeCheck( - group = UpgradeCheckGroup.DEFAULT, - order = 20.0f, - required = { UpgradeType.ROLLING, UpgradeType.EXPRESS }) -public class HiveDynamicServiceDiscoveryCheck extends AbstractCheckDescriptor { - - static final String HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY = "hive.dynamic-service.discovery.enabled.key"; - static final String HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY = "hive.dynamic-service.discovery.zk-quorum.key"; - static final String HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY = "hive.dynamic-service.zk-namespace.key"; - static final String MIN_FAILURE_STACK_VERSION_PROPERTY_NAME = "min-failure-stack-version"; - - /** - * Constructor. - */ - public HiveDynamicServiceDiscoveryCheck() { - super(CheckDescription.SERVICES_HIVE_DYNAMIC_SERVICE_DISCOVERY); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("HIVE"); - } - - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - List errorMessages = new ArrayList<>(); - - String dynamicServiceDiscoveryEnabled = getProperty(request, "hive-site", "hive.server2.support.dynamic.service.discovery"); - String zookeeperQuorum = getProperty(request, "hive-site", "hive.zookeeper.quorum"); - String zookeeperNamespace = getProperty(request, "hive-site", "hive.server2.zookeeper.namespace"); - - if (null == dynamicServiceDiscoveryEnabled || !Boolean.parseBoolean(dynamicServiceDiscoveryEnabled)) { - errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY, prerequisiteCheck, request)); - } - - if (StringUtils.isBlank(zookeeperQuorum)) { - errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY, prerequisiteCheck, - request)); - } - - if (StringUtils.isBlank(zookeeperNamespace)) { - errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY, prerequisiteCheck, - request)); - } - - String minFailureStackVersion = null; - PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); - Map checkProperties = null; - if(prerequisiteCheckConfig != null) { - checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); - } - if(checkProperties != null && checkProperties.containsKey(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME)) { - minFailureStackVersion = checkProperties.get(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME); - } - - if (!errorMessages.isEmpty()) { - prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); - prerequisiteCheck.getFailedOn().add("HIVE"); - PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL; - if(minFailureStackVersion != null && !minFailureStackVersion.isEmpty()) { - String[] minStack = minFailureStackVersion.split("-"); - if (minStack.length == 2) { - String minStackName = minStack[0]; - String minStackVersion = minStack[1]; - if (minStackName.equals(request.getSourceStackId().getStackName())) { - RepositoryVersionEntity repositoryVersion = request.getTargetRepositoryVersion(); - StackId targetStackId = repositoryVersion.getStackId(); - if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), minStackVersion) < 0 - && VersionUtils.compareVersions(targetStackId.getStackVersion(), minStackVersion) < 0 - && VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), targetStackId.getStackVersion()) < 0) { - checkStatus = PrereqCheckStatus.WARNING; - } - } - } - } - prerequisiteCheck.setStatus(checkStatus); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java deleted file mode 100644 index e876696e553..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java +++ /dev/null @@ -1,83 +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.checks; - -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.ServiceComponentNotFoundException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.ServiceComponent; -import org.apache.ambari.server.state.ServiceComponentHost; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * The {@link HiveMultipleMetastoreCheck} checks that there are at least 2 Hive - * Metastore instances in the cluster. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.MULTIPLE_COMPONENT_WARNING, order = 20.1f) -public class HiveMultipleMetastoreCheck extends AbstractCheckDescriptor { - - /** - * Constructor. - */ - public HiveMultipleMetastoreCheck() { - super(CheckDescription.SERVICES_HIVE_MULTIPLE_METASTORES); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("HIVE"); - } - - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - final String clusterName = request.getClusterName(); - final Cluster cluster = clustersProvider.get().getCluster(clusterName); - - try { - Service hive = cluster.getService("HIVE"); - ServiceComponent metastore = hive.getServiceComponent("HIVE_METASTORE"); - Map metastores = metastore.getServiceComponentHosts(); - - if (metastores.size() < 2) { - prerequisiteCheck.getFailedOn().add("HIVE"); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } catch (ServiceComponentNotFoundException scnfe) { - prerequisiteCheck.getFailedOn().add("HIVE"); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveNotRollingWarning.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveNotRollingWarning.java deleted file mode 100644 index 8e862c83a77..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveNotRollingWarning.java +++ /dev/null @@ -1,71 +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.checks; - -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.upgrade.UpgradeType; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * The {@link HiveNotRollingWarning} to see if Hive is installed and if the - * upgrade type is {@link UpgradeType#ROLLING}. If so, then a - * {@link PrereqCheckStatus#WARNING} is produced which will let the operator - * know that Hive does not support rolling upgrades. - *

- * In actuality, it does, however in order to support no downtime, a new Hive - * server is spun up on a new port while the old server drains. If clients are - * not using the ZK discovery service for Hive and connecting via a URL - * directly, they will cease to function. For this reason, it's been determined - * that at this point in time, Hive will not be upgraded in a rolling fashion. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.INFORMATIONAL_WARNING, required = UpgradeType.ROLLING) -public class HiveNotRollingWarning extends AbstractCheckDescriptor { - - /** - * Constructor. - */ - public HiveNotRollingWarning() { - super(CheckDescription.SERVICES_HIVE_ROLLING_WARNING); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("HIVE"); - } - - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - prerequisiteCheck.getFailedOn().add("HIVE"); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/KafkaKerberosCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/KafkaKerberosCheck.java deleted file mode 100644 index 724feab4797..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/KafkaKerberosCheck.java +++ /dev/null @@ -1,70 +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.checks; - -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.SecurityType; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Check that cluster is kerberized while trying to upgrade Kafka. - * Will show warning for kerberized cluster with Kafka service and nothing if - * cluster is not kerberized - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.KERBEROS, order = 1.0f) -public class KafkaKerberosCheck extends AbstractCheckDescriptor { - - private final String KAFKA_SERVICE = "KAFKA"; - - /** - * Constructor. - */ - public KafkaKerberosCheck() { - super(CheckDescription.KAFKA_KERBEROS_CHECK); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet(KAFKA_SERVICE); - } - - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - final String clusterName = request.getClusterName(); - final Cluster cluster = clustersProvider.get().getCluster(clusterName); - - if (cluster.getSecurityType() == SecurityType.KERBEROS){ - prerequisiteCheck.getFailedOn().add(KAFKA_SERVICE); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheck.java deleted file mode 100644 index 2015be3b9b2..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheck.java +++ /dev/null @@ -1,101 +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.checks; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.commons.lang.StringUtils; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * The {@link MapReduce2JobHistoryStatePreservingCheck} - * is used to check that the MR2 History server has state preserving mode enabled. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.CONFIGURATION_WARNING, order = 17.0f) -public class MapReduce2JobHistoryStatePreservingCheck extends AbstractCheckDescriptor { - - final static String MAPREDUCE2_JOBHISTORY_RECOVERY_ENABLE_KEY = - "mapreduce.jobhistory.recovery.enable"; - final static String MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_KEY = - "mapreduce.jobhistory.recovery.store.class"; - final static String MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_LEVELDB_PATH_KEY = - "mapreduce.jobhistory.recovery.store.leveldb.path"; - final static String YARN_TIMELINE_SERVICE_LEVELDB_STATE_STORE_PATH_KEY = - "yarn.timeline-service.leveldb-state-store.path"; - - /** - * Constructor. - */ - public MapReduce2JobHistoryStatePreservingCheck() { - super(CheckDescription.SERVICES_MR2_JOBHISTORY_ST); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("MAPREDUCE2"); - } - - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - List errorMessages = new ArrayList<>(); - PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL; - - String enabled = - getProperty(request, "mapred-site", MAPREDUCE2_JOBHISTORY_RECOVERY_ENABLE_KEY); - String storeClass = - getProperty(request, "mapred-site", MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_KEY); - String storeLevelDbPath = - getProperty(request, "mapred-site", MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_LEVELDB_PATH_KEY); - - if (null == enabled || !Boolean.parseBoolean(enabled)) { - errorMessages.add(getFailReason(MAPREDUCE2_JOBHISTORY_RECOVERY_ENABLE_KEY, prerequisiteCheck, request)); - } - - if (StringUtils.isBlank(storeClass)) { - errorMessages.add(getFailReason(MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_KEY, prerequisiteCheck, - request)); - } - - if (StringUtils.isBlank(storeLevelDbPath)) { - errorMessages.add(getFailReason(MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_LEVELDB_PATH_KEY, prerequisiteCheck, - request)); - - } - - if (!errorMessages.isEmpty()) { - prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, "\n")); - prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); - prerequisiteCheck.setStatus(checkStatus); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerAuditDbCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerAuditDbCheck.java deleted file mode 100644 index e5f02577b4a..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerAuditDbCheck.java +++ /dev/null @@ -1,65 +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.checks; - -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Ranger Service will not support Audit to DB after upgrade to 2.5 stack. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.INFORMATIONAL_WARNING) -public class RangerAuditDbCheck extends AbstractCheckDescriptor{ - - private static final Logger LOG = LoggerFactory.getLogger(RangerAuditDbCheck.class); - private static final String serviceName = "RANGER"; - - public RangerAuditDbCheck(){ - super(CheckDescription.RANGER_SERVICE_AUDIT_DB_CHECK); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet(serviceName); - } - - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - - String propertyValue = getProperty(request, "ranger-admin-site", "ranger.audit.source.type"); - - if (null != propertyValue && propertyValue.equalsIgnoreCase("db")) { - prerequisiteCheck.getFailedOn().add(serviceName); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java deleted file mode 100644 index c5eca750b7b..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java +++ /dev/null @@ -1,378 +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.checks; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.configuration.ComponentSSLConfiguration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.controller.internal.URLStreamProvider; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.upgrade.UpgradeType; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Sets; -import com.google.gson.Gson; -import com.google.inject.Singleton; - -/** - * Used to make sure that the password in Ambari matches that for Ranger, in case the - * user had changed the password using the Ranger UI. - */ -@Singleton -@UpgradeCheck( - group = UpgradeCheckGroup.CONFIGURATION_WARNING, - order = 23.0f, - required = { UpgradeType.ROLLING, UpgradeType.EXPRESS, UpgradeType.HOST_ORDERED }) -public class RangerPasswordCheck extends AbstractCheckDescriptor { - - private static final Logger LOG = LoggerFactory.getLogger(RangerPasswordCheck.class); - - static final String KEY_RANGER_PASSWORD_MISMATCH = "could_not_verify_password"; - static final String KEY_RANGER_COULD_NOT_ACCESS = "could_not_access"; - static final String KEY_RANGER_UNKNOWN_RESPONSE = "unknown_response"; - static final String KEY_RANGER_USERS_ELEMENT_MISSING = "missing_vxusers"; - static final String KEY_RANGER_OTHER_ISSUE = "invalid_response"; - static final String KEY_RANGER_CONFIG_MISSING = "missing_config"; - - /** - * Constructor. - */ - public RangerPasswordCheck() { - super(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("RANGER"); - } - - @Override - public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException { - // !!! ComponentSSLConfiguration is an old-school singleton which doesn't - // get initialized until after Guice is done - because this check is bound - // as a singleton via Guice, we can't initialize the stream provider in the - // constructor since the SSL configuration instance hasn't been initialized - URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000, - ComponentSSLConfiguration.instance()); - - String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request); - if (null == rangerUrl) { - // !!! check results already filled - return; - } - - String adminUsername = checkEmpty("ranger-env", "admin_username", check, request); - if (null == adminUsername) { - return; - } - - String adminPassword = checkEmpty("ranger-env", "admin_password", check, request); - if (null == adminPassword) { - return; - } - - String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request); - if (null == rangerAdminUsername) { - return; - } - - String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request); - if (null == rangerAdminPassword) { - return; - } - - if (rangerUrl.endsWith("/")) { - rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1); - } - - String rangerAuthUrl = String.format("%s/%s", rangerUrl, - "service/public/api/repository/count"); - String rangerUserUrl = String.format("%s/%s", rangerUrl, - "service/xusers/users"); - - List failReasons = new ArrayList<>(); - List warnReasons = new ArrayList<>(); - - // !!! first, just try the service with the admin credentials - try { - int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword); - - switch (response) { - case 401: { - String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request); - failReasons.add(String.format(reason, adminUsername)); - break; - } - case 200: { - break; - } - default: { - String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request); - warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl)); - break; - } - } - - } catch (IOException e) { - LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e); - LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage()); - - String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request); - warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage())); - } - - // !!! shortcut when something happened with the admin user - if (!failReasons.isEmpty()) { - check.setFailReason(StringUtils.join(failReasons, '\n')); - check.getFailedOn().add("RANGER"); - check.setStatus(PrereqCheckStatus.FAIL); - return; - } else if (!warnReasons.isEmpty()) { - check.setFailReason(StringUtils.join(warnReasons, '\n')); - check.getFailedOn().add("RANGER"); - check.setStatus(PrereqCheckStatus.WARNING); - return; - } - - // !!! Check for the user, capture exceptions as a warning. - boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword, - rangerAdminUsername, check, request, warnReasons); - - if (hasUser) { - // !!! try credentials for specific user - try { - int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername, - rangerAdminPassword); - - switch (response) { - case 401: { - String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request); - failReasons.add(String.format(reason, rangerAdminUsername)); - break; - } - case 200: { - break; - } - default: { - String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request); - warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl)); - break; - } - } - - } catch (IOException e) { - LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage()); - LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e); - - String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request); - warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage())); - } - } - - if (!failReasons.isEmpty()) { - check.setFailReason(StringUtils.join(failReasons, '\n')); - check.getFailedOn().add("RANGER"); - check.setStatus(PrereqCheckStatus.FAIL); - } else if (!warnReasons.isEmpty()) { - check.setFailReason(StringUtils.join(warnReasons, '\n')); - check.getFailedOn().add("RANGER"); - check.setStatus(PrereqCheckStatus.WARNING); - } else { - check.setStatus(PrereqCheckStatus.PASS); - } - - } - - /** - * Checks the credentials. From the Ranger team, bad credentials result in a - * successful call, but the Ranger admin server will redirect to the home - * page. They recommend parsing the result. If it parses, the credentials are - * good, otherwise consider the user as unverified. - * - * @param streamProvider - * the stream provider to use when making requests - * @param url - * the url to check - * @param username - * the user to check - * @param password - * the password to check - * @return the http response code - * @throws IOException - * if there was an error reading the response - */ - private int checkLogin(URLStreamProvider streamProvider, String url, String username, - String password) throws IOException { - - Map> headers = getHeaders(username, password); - - HttpURLConnection conn = streamProvider.processURL(url, "GET", (InputStream) null, headers); - - int result = conn.getResponseCode(); - - // !!! see javadoc - if (result == 200) { - Gson gson = new Gson(); - try { - gson.fromJson(new InputStreamReader(conn.getInputStream()), Object.class); - } catch (Exception e) { - result = 401; - } - } - - return result; - } - - /** - * @param streamProvider - * the stream provider to use when making requests - * @param rangerUserUrl - * the url to use when looking for the user - * @param username - * the username to use when loading the url - * @param password - * the password for the user url - * @param userToSearch - * the user to look for - * @param check - * the check instance for loading failure reasons - * @param request - * the request instance for loading failure reasons - * @param warnReasons - * the list of warn reasons to fill - * @return {@code true} if the user was found - */ - private boolean checkRangerUser(URLStreamProvider streamProvider, String rangerUserUrl, - String username, String password, String userToSearch, PrerequisiteCheck check, - PrereqCheckRequest request, List warnReasons) throws AmbariException { - - String url = String.format("%s?name=%s", rangerUserUrl, userToSearch); - - Map> headers = getHeaders(username, password); - - try { - HttpURLConnection conn = streamProvider.processURL(url, "GET", (InputStream) null, headers); - - int result = conn.getResponseCode(); - - if (result == 200) { - - Gson gson = new Gson(); - Object o = gson.fromJson(new InputStreamReader(conn.getInputStream()), Object.class); - - Map map = (Map) o; - - if (!map.containsKey("vXUsers")) { - String reason = getFailReason(KEY_RANGER_USERS_ELEMENT_MISSING, check, request); - warnReasons.add(String.format(reason, url)); - - return false; - } - - @SuppressWarnings("unchecked") - List> list = (List>) map.get("vXUsers"); - - for (Map listMap : list) { - if (listMap.containsKey("name") && listMap.get("name").equals(userToSearch)) { - return true; - } - } - } - } catch (IOException e) { - LOG.warn("Could not determine user {}. Error is {}", userToSearch, e.getMessage()); - LOG.debug("Could not determine user {}. Error is {}", userToSearch, e.getMessage(), e); - - String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request); - warnReasons.add(String.format(reason, username, url, e.getMessage())); - - } catch (Exception e) { - LOG.warn("Could not determine user {}. Error is {}", userToSearch, e.getMessage()); - LOG.debug("Could not determine user {}. Error is {}", userToSearch, e.getMessage(), e); - - String reason = getFailReason(KEY_RANGER_OTHER_ISSUE, check, request); - warnReasons.add(String.format(reason, e.getMessage(), url)); - } - - return false; - } - - /** - * Generates a list of headers, including {@code Basic} authentication - * @param username the username - * @param password the password - * @return the map of headers - */ - private Map> getHeaders(String username, String password) { - Map> headers = new HashMap<>(); - - String base64 = Base64.encodeBase64String( - String.format("%s:%s", username, password).getBytes(Charset.forName("UTF8"))); - - headers.put("Content-Type", Arrays.asList("application/json")); - headers.put("Accept", Arrays.asList("application/json")); - headers.put("Authorization", Arrays.asList(String.format("Basic %s", base64))); - - return headers; - } - - /** - * Finds the property value. If not found, then the failure reason for the check - * is filled in and processing should not continue. - * - * @param type the type of property to find - * @param key the key in configs matching the type - * @param check the check for loading failure reasons - * @param request the request for loading failure reasons - * @return the property value, or {@code null} if the property doesn't exist - * @throws AmbariException - */ - private String checkEmpty(String type, String key, PrerequisiteCheck check, - PrereqCheckRequest request) throws AmbariException { - - String value = getProperty(request, type, key); - if (null == value) { - String reason = getFailReason(KEY_RANGER_CONFIG_MISSING, check, request); - reason = String.format(reason, type, key); - check.setFailReason(reason); - check.getFailedOn().add("RANGER"); - check.setStatus(PrereqCheckStatus.WARNING); - } - return value; - } - - -} \ No newline at end of file diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerSSLConfigCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerSSLConfigCheck.java deleted file mode 100644 index 540fd3e7fd6..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerSSLConfigCheck.java +++ /dev/null @@ -1,81 +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.checks; - - -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - - -/** - * This service check will mainly be for 2.6 stacks so as to encourage user - * to move the certificate, keystore and truststore from the default conf dir to - * an external directory untoched while RU/EU during upgrades/downgrades. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.INFORMATIONAL_WARNING) -public class RangerSSLConfigCheck extends AbstractCheckDescriptor { - - private static final Logger LOG = LoggerFactory.getLogger(RangerSSLConfigCheck.class); - private static final String serviceName = "RANGER"; - - - /** - * Constructor - */ - public RangerSSLConfigCheck() { - super(CheckDescription.RANGER_SSL_CONFIG_CHECK); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet(serviceName); - } - - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - String isRangerHTTPEnabled = getProperty(request, "ranger-admin-site", "ranger.service.http.enabled"); - String isRangerSSLEnabled = getProperty(request, "ranger-admin-site", "ranger.service.https.attrib.ssl.enabled"); - String rangerSSLKeystoreFile = getProperty(request, "ranger-admin-site", "ranger.https.attrib.keystore.file"); - - if (("false").equalsIgnoreCase(isRangerHTTPEnabled) && ("true").equalsIgnoreCase(isRangerSSLEnabled) && rangerSSLKeystoreFile.contains("/etc/ranger/admin/conf") ) { - LOG.info("Ranger is SSL enabled, need to show Configuration changes warning before upragade proceeds."); - prerequisiteCheck.getFailedOn().add(serviceName); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } else { - LOG.info("Ranger is not SSL enabled, no need to show Configuration changes warning before upragade proceeds."); - } - - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheck.java deleted file mode 100644 index 349b2609516..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheck.java +++ /dev/null @@ -1,116 +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.checks; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.ServiceComponentNotFoundException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.dao.HostComponentStateDAO; -import org.apache.ambari.server.orm.entities.HostComponentStateEntity; -import org.apache.ambari.server.stack.MasterHostResolver; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.ServiceComponent; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; - -import com.google.common.collect.Sets; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * Checks that the Secondary NameNode is not present on any of the hosts. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.NAMENODE_HA, order = 16.0f) -public class SecondaryNamenodeDeletedCheck extends AbstractCheckDescriptor { - private static final String HDFS_SERVICE_NAME = MasterHostResolver.Service.HDFS.name(); - - @Inject - HostComponentStateDAO hostComponentStateDao; - /** - * Constructor. - */ - public SecondaryNamenodeDeletedCheck() { - super(CheckDescription.SECONDARY_NAMENODE_MUST_BE_DELETED); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet(HDFS_SERVICE_NAME); - } - - /** - * {@inheritDoc} - */ - @Override - public List getQualifications() { - return Arrays.asList( - new PriorCheckQualification(CheckDescription.SERVICES_NAMENODE_HA)); - } - - // TODO AMBARI-12698, there are 2 ways to filter the prechecks. - // 1. Explictly mention them in each upgrade pack, which is more flexible, but requires adding the name of checks - // to perform in each upgrade pack. - // 2. Make each upgrade check class call a function before perform() that will determine if the check is appropriate - // given the type of upgrade. The PrereqCheckRequest object has a field for the type of upgrade. - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - Set hosts = new HashSet<>(); - final String SECONDARY_NAMENODE = "SECONDARY_NAMENODE"; - - final String clusterName = request.getClusterName(); - final Cluster cluster = clustersProvider.get().getCluster(clusterName); - try { - ServiceComponent serviceComponent = cluster.getService(HDFS_SERVICE_NAME).getServiceComponent(SECONDARY_NAMENODE); - if (serviceComponent != null) { - hosts = serviceComponent.getServiceComponentHosts().keySet(); - } - } catch (ServiceComponentNotFoundException err) { - // This exception can be ignored if the component doesn't exist because it is a best-attempt at finding it. - ; - } - - // Try another method to find references to SECONDARY_NAMENODE - if (hosts.isEmpty()) { - List allHostComponents = hostComponentStateDao.findAll(); - for(HostComponentStateEntity hc : allHostComponents) { - Service s = cluster.getService(hc.getServiceId()); - if (s.getServiceType().equalsIgnoreCase(HDFS_SERVICE_NAME) && hc.getComponentName().equalsIgnoreCase(SECONDARY_NAMENODE)) { - hosts.add(hc.getHostName()); - } - } - } - - if (!hosts.isEmpty()) { - String foundHost = hosts.toArray(new String[hosts.size()])[0]; - prerequisiteCheck.getFailedOn().add(HDFS_SERVICE_NAME); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - String failReason = getFailReason(prerequisiteCheck, request); - prerequisiteCheck.setFailReason(String.format(failReason, foundHost)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheck.java deleted file mode 100644 index e24e669863a..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheck.java +++ /dev/null @@ -1,124 +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.checks; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; -import org.apache.commons.lang.StringUtils; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Checks that MR jobs reference hadoop libraries from the distributed cache. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.NAMENODE_HA, order = 17.1f) -public class ServicesMapReduceDistributedCacheCheck extends AbstractCheckDescriptor { - - static final String KEY_APP_CLASSPATH = "app_classpath"; - static final String KEY_FRAMEWORK_PATH = "framework_path"; - static final String KEY_NOT_DFS = "not_dfs"; - static final String DFS_PROTOCOLS_REGEX_PROPERTY_NAME = "dfs-protocols-regex"; - static final String DFS_PROTOCOLS_REGEX_DEFAULT = "^([^:]*dfs|wasb|ecs):.*"; - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("YARN"); - } - - /** - * {@inheritDoc} - */ - @Override - public List getQualifications() { - return Arrays.asList( - new PriorCheckQualification(CheckDescription.SERVICES_NAMENODE_HA)); - } - - /** - * Constructor. - */ - public ServicesMapReduceDistributedCacheCheck() { - super(CheckDescription.SERVICES_MR_DISTRIBUTED_CACHE); - } - - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT; - PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); - Map checkProperties = null; - if(prerequisiteCheckConfig != null) { - checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); - } - if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) { - dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME); - } - - final String clusterName = request.getClusterName(); - final Cluster cluster = clustersProvider.get().getCluster(clusterName); - final String mrConfigType = "mapred-site"; - final String coreSiteConfigType = "core-site"; - final Map desiredConfigs = cluster.getDesiredConfigs(); - - final DesiredConfig mrDesiredConfig = desiredConfigs.get(mrConfigType); - final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType); - final Config mrConfig = cluster.getConfig(mrConfigType, mrDesiredConfig.getTag()); - final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag()); - final String applicationClasspath = mrConfig.getProperties().get("mapreduce.application.classpath"); - final String frameworkPath = mrConfig.getProperties().get("mapreduce.application.framework.path"); - final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS"); - - List errorMessages = new ArrayList<>(); - if (applicationClasspath == null || applicationClasspath.isEmpty()) { - errorMessages.add(getFailReason(KEY_APP_CLASSPATH, prerequisiteCheck, request)); - } - - if (frameworkPath == null || frameworkPath.isEmpty()) { - errorMessages.add(getFailReason(KEY_FRAMEWORK_PATH, prerequisiteCheck, request)); - } - - if (!errorMessages.isEmpty()) { - prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); - return; - } - - if (!frameworkPath.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) { - prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - prerequisiteCheck.setFailReason(getFailReason(KEY_NOT_DFS, prerequisiteCheck, request)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheck.java deleted file mode 100644 index ecd88edde01..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheck.java +++ /dev/null @@ -1,71 +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.checks; - -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Checks that namenode high availability is enabled. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.NAMENODE_HA, order = 16.1f) -public class ServicesNamenodeHighAvailabilityCheck extends AbstractCheckDescriptor { - - /** - * Constructor. - */ - public ServicesNamenodeHighAvailabilityCheck() { - super(CheckDescription.SERVICES_NAMENODE_HA); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("HDFS"); - } - - - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - final String clusterName = request.getClusterName(); - final Cluster cluster = clustersProvider.get().getCluster(clusterName); - final String configType = "hdfs-site"; - final Map desiredConfigs = cluster.getDesiredConfigs(); - final DesiredConfig desiredConfig = desiredConfigs.get(configType); - final Config config = cluster.getConfig(configType, desiredConfig.getTag()); - if (!config.getProperties().containsKey("dfs.internal.nameservices")) { - prerequisiteCheck.getFailedOn().add("HDFS"); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheck.java deleted file mode 100644 index 4d9e7d72aba..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheck.java +++ /dev/null @@ -1,80 +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.checks; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Checks that namenode high availability is enabled. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.NAMENODE_HA, order = 16.2f) -public class ServicesNamenodeTruncateCheck extends AbstractCheckDescriptor { - - /** - * Constructor. - */ - public ServicesNamenodeTruncateCheck() { - super(CheckDescription.SERVICES_NAMENODE_TRUNCATE); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("HDFS"); - } - - /** - * {@inheritDoc} - */ - @Override - public List getQualifications() { - return Arrays.asList( - new PriorCheckQualification(CheckDescription.SERVICES_NAMENODE_HA)); - } - - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - final String clusterName = request.getClusterName(); - final Cluster cluster = clustersProvider.get().getCluster(clusterName); - Config config = cluster.getDesiredConfigByType("hdfs-site"); - - String truncateEnabled = config.getProperties().get("dfs.allow.truncate"); - - if (Boolean.valueOf(truncateEnabled)) { - prerequisiteCheck.getFailedOn().add("HDFS"); - PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL; - prerequisiteCheck.setStatus(checkStatus); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheck.java deleted file mode 100644 index 8331ebf9540..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheck.java +++ /dev/null @@ -1,138 +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.checks; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; -import org.apache.commons.lang.StringUtils; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Checks that Tez jobs reference hadoop libraries from the distributed cache. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.NAMENODE_HA, order = 21.0f) -public class ServicesTezDistributedCacheCheck extends AbstractCheckDescriptor { - - static final String KEY_LIB_URI_MISSING = "tez_lib_uri_missing"; - static final String KEY_USE_HADOOP_LIBS = "tez_use_hadoop_libs"; - static final String KEY_LIB_NOT_DFS = "lib_not_dfs"; - static final String KEY_LIB_NOT_TARGZ = "lib_not_targz"; - static final String KEY_USE_HADOOP_LIBS_FALSE = "tez_use_hadoop_libs_false"; - static final String DFS_PROTOCOLS_REGEX_PROPERTY_NAME = "dfs-protocols-regex"; - static final String DFS_PROTOCOLS_REGEX_DEFAULT = "^([^:]*dfs|wasb|ecs):.*"; - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("TEZ"); - } - - /** - * {@inheritDoc} - */ - @Override - public List getQualifications() { - return Arrays.asList( - new PriorCheckQualification(CheckDescription.SERVICES_NAMENODE_HA)); - } - - /** - * Constructor. - */ - public ServicesTezDistributedCacheCheck() { - super(CheckDescription.SERVICES_TEZ_DISTRIBUTED_CACHE); - } - - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT; - PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); - Map checkProperties = null; - if(prerequisiteCheckConfig != null) { - checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); - } - if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) { - dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME); - } - - final String clusterName = request.getClusterName(); - final Cluster cluster = clustersProvider.get().getCluster(clusterName); - final String tezConfigType = "tez-site"; - final String coreSiteConfigType = "core-site"; - final Map desiredConfigs = cluster.getDesiredConfigs(); - - final DesiredConfig tezDesiredConfig = desiredConfigs.get(tezConfigType); - final Config tezConfig = cluster.getConfig(tezConfigType, tezDesiredConfig.getTag()); - final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType); - final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag()); - final String libUris = tezConfig.getProperties().get("tez.lib.uris"); - final String useHadoopLibs = tezConfig.getProperties().get("tez.use.cluster.hadoop-libs"); - final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS"); - - List errorMessages = new ArrayList<>(); - if (libUris == null || libUris.isEmpty()) { - errorMessages.add(getFailReason(KEY_LIB_URI_MISSING, prerequisiteCheck, request)); - } - - if (useHadoopLibs == null || useHadoopLibs.isEmpty()) { - errorMessages.add(getFailReason(KEY_USE_HADOOP_LIBS, prerequisiteCheck, request)); - } - - if (!errorMessages.isEmpty()) { - prerequisiteCheck.getFailedOn().add("TEZ"); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); - return; - } - - if (!libUris.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) { - errorMessages.add(getFailReason(KEY_LIB_NOT_DFS, prerequisiteCheck, request)); - } - - if (!libUris.contains("tar.gz")) { - errorMessages.add(getFailReason(KEY_LIB_NOT_TARGZ, prerequisiteCheck, request)); - } - - if (Boolean.parseBoolean(useHadoopLibs)) { - errorMessages.add(getFailReason(KEY_USE_HADOOP_LIBS_FALSE, prerequisiteCheck, request)); - } - - if (!errorMessages.isEmpty()) { - prerequisiteCheck.getFailedOn().add("TEZ"); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheck.java deleted file mode 100644 index 0b102a99c8a..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheck.java +++ /dev/null @@ -1,67 +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.checks; - -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.commons.lang.BooleanUtils; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * Checks that YARN has work-preserving restart enabled. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.DEFAULT, order = 17.1f) -public class ServicesYarnWorkPreservingCheck extends AbstractCheckDescriptor { - - /** - * Constructor. - */ - public ServicesYarnWorkPreservingCheck() { - super(CheckDescription.SERVICES_YARN_WP); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("YARN"); - } - - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - String propertyValue = getProperty(request, "yarn-site", - "yarn.resourcemanager.work-preserving-recovery.enabled"); - - if (null == propertyValue || !BooleanUtils.toBoolean(propertyValue)) { - prerequisiteCheck.getFailedOn().add("YARN"); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/StormShutdownWarning.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/StormShutdownWarning.java deleted file mode 100644 index 067cd8043a1..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/StormShutdownWarning.java +++ /dev/null @@ -1,69 +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.checks; - -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.upgrade.UpgradeType; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * The {@link StormShutdownWarning} to see if Storm is installed and if the - * upgrade type is {@link UpgradeType#ROLLING}. If so, then a - * {@link PrereqCheckStatus#WARNING} is produced which will let the operator - * know that Storm cannot be rolling on ceratin versions of the HDP stack. - *

- * The upgrade packs must include this check where it is applicable. It contains - * no logic for determine stack versions and only checks for the presence of - * Storm and the type of upgrade. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.INFORMATIONAL_WARNING, required = UpgradeType.ROLLING) -public class StormShutdownWarning extends AbstractCheckDescriptor { - - /** - * Constructor. - */ - public StormShutdownWarning() { - super(CheckDescription.SERVICES_STORM_ROLLING_WARNING); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("STORM"); - } - - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - prerequisiteCheck.getFailedOn().add("STORM"); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java deleted file mode 100644 index e0d3df7fc16..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java +++ /dev/null @@ -1,68 +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.checks; - -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.commons.lang.BooleanUtils; - -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * The {@link YarnRMHighAvailabilityCheck} checks that YARN has HA mode enabled - * for ResourceManager.. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.MULTIPLE_COMPONENT_WARNING, order = 17.2f) -public class YarnRMHighAvailabilityCheck extends AbstractCheckDescriptor { - - /** - * Constructor. - */ - public YarnRMHighAvailabilityCheck() { - super(CheckDescription.SERVICES_YARN_RM_HA); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("YARN"); - } - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - // pretty weak sauce here; probably should do a bit more, like query JMX to - // see that there is at least 1 RM active and 1 in standby - String propertyValue = getProperty(request, "yarn-site", "yarn.resourcemanager.ha.enabled"); - - if (null == propertyValue || !BooleanUtils.toBoolean(propertyValue)) { - prerequisiteCheck.getFailedOn().add("YARN"); - prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheck.java deleted file mode 100644 index 27d4ace8847..00000000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheck.java +++ /dev/null @@ -1,136 +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.checks; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; -import org.apache.ambari.server.utils.VersionUtils; -import org.apache.commons.lang.BooleanUtils; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.inject.Singleton; - -/** - * The {@link YarnTimelineServerStatePreservingCheck} is used to check that the - * YARN Timeline server has state preserving mode enabled. This value is only - * present in HDP 2.2.4.2+. - */ -@Singleton -@UpgradeCheck(group = UpgradeCheckGroup.DEFAULT, order = 17.3f) -public class YarnTimelineServerStatePreservingCheck extends AbstractCheckDescriptor { - - private final static String YARN_TIMELINE_STATE_RECOVERY_ENABLED_KEY = "yarn.timeline-service.recovery.enabled"; - private final static String MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME = "min-applicable-stack-version"; - - /** - * Constructor. - */ - public YarnTimelineServerStatePreservingCheck() { - super(CheckDescription.SERVICES_YARN_TIMELINE_ST); - } - - /** - * {@inheritDoc} - */ - @Override - public Set getApplicableServices() { - return Sets.newHashSet("YARN"); - } - - /** - * {@inheritDoc} - */ - @Override - public List getQualifications() { - return Lists.newArrayList(new YarnTimelineServerMinVersionQualification()); - } - - /** - * {@inheritDoc} - */ - @Override - public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { - String propertyValue = getProperty(request, "yarn-site", - YARN_TIMELINE_STATE_RECOVERY_ENABLED_KEY); - - if (null == propertyValue || !BooleanUtils.toBoolean(propertyValue)) { - prerequisiteCheck.getFailedOn().add("YARN"); - prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); - prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); - } - } - - /** - * The {@link YarnTimelineServerMinVersionQualification} is used to determine - * if the ATS component needs to have the - * {@value #MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME} set. - */ - private class YarnTimelineServerMinVersionQualification implements CheckQualification { - - /** - * {@inheritDoc} - */ - @Override - public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { - final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); - - String minApplicableStackVersion = null; - PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); - Map checkProperties = null; - if(prerequisiteCheckConfig != null) { - checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); - } - - if(checkProperties != null && checkProperties.containsKey(MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME)) { - minApplicableStackVersion = checkProperties.get(MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME); - } - - // Due to the introduction of YARN Timeline state recovery only from certain - // stack-versions onwards, this check is not applicable to earlier versions - // of the stack. - // Applicable only if min-applicable-stack-version config property is not defined, or - // version equals or exceeds the configured version. - if(minApplicableStackVersion != null && !minApplicableStackVersion.isEmpty()) { - String[] minStack = minApplicableStackVersion.split("-"); - if(minStack.length == 2) { - String minStackName = minStack[0]; - String minStackVersion = minStack[1]; - Service yarnService = cluster.getService("YARN"); - String stackName = yarnService.getDesiredStackId().getStackName(); - if (minStackName.equals(stackName)) { - String currentRepositoryVersion = yarnService.getDesiredRepositoryVersion().getVersion(); - return VersionUtils.compareVersions(currentRepositoryVersion, minStackVersion) >= 0; - } - } - } - - return true; - - } - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java index f50ef747d00..dd2b45a1006 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java @@ -1619,27 +1619,9 @@ public static ConfigUpgradePack build(UpgradeContext cx) { stackId = cx.getStackIdFromVersions(cx.getTargetVersions()); } - List intermediateStacks = upgradePack.getIntermediateStacks(); ConfigUpgradePack configUpgradePack = s_metaProvider.get().getConfigUpgradePack( stackId.getStackName(), stackId.getStackVersion()); - // merge in any intermediate stacks - if (null != intermediateStacks) { - - // start out with the source stack's config pack - ArrayList configPacksToMerge = Lists.newArrayList(configUpgradePack); - - for (UpgradePack.IntermediateStack intermediateStack : intermediateStacks) { - ConfigUpgradePack intermediateConfigUpgradePack = s_metaProvider.get().getConfigUpgradePack( - stackId.getStackName(), intermediateStack.version); - - configPacksToMerge.add(intermediateConfigUpgradePack); - } - - // merge all together - configUpgradePack = ConfigUpgradePack.merge(configPacksToMerge); - } - return configUpgradePack; } } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java index f576a34656a..2258bbf6466 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java @@ -1156,7 +1156,6 @@ private UpgradePack parseServiceUpgradePack(UpgradePack parent, File serviceFile * @return the child upgrade pack */ private UpgradePack parseServiceUpgradePack(UpgradePack parent, UpgradePack child) { - parent.mergePrerequisiteChecks(child); parent.mergeProcessing(child); return child; diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java index a287cb567e9..0976b15349c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java @@ -19,13 +19,13 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Pattern; +import java.util.stream.Collectors; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; @@ -39,7 +39,6 @@ import org.apache.ambari.annotations.Experimental; import org.apache.ambari.annotations.ExperimentalFeature; -import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.state.stack.upgrade.ClusterGrouping; import org.apache.ambari.server.state.stack.upgrade.ConfigureTask; import org.apache.ambari.server.state.stack.upgrade.CreateAndConfigureTask; @@ -76,8 +75,9 @@ public class UpgradePack { @XmlElement(name="lifecycle") public List lifecycles; - @XmlElement(name="prerequisite-checks") - private PrerequisiteChecks prerequisiteChecks; + @XmlElementWrapper(name="prerequisite-checks") + @XmlElement(name="check") + private List prerequisiteChecks; /** * In the case of a rolling upgrade, will specify processing logic for a particular component. @@ -124,10 +124,6 @@ public class UpgradePack { @XmlElement(name="type", defaultValue="rolling") private UpgradeType type; - @XmlElementWrapper(name="upgrade-path") - @XmlElement(name="intermediate-stack") - private List intermediateStacks; - public String getName() { return name; } @@ -156,76 +152,18 @@ public List getPrerequisiteChecks() { if (prerequisiteChecks == null) { return new ArrayList<>(); } - return new ArrayList<>(prerequisiteChecks.checks); - } - /** - * - * @return the prerequisite check configuration - */ - public PrerequisiteCheckConfig getPrerequisiteCheckConfig() { - if (prerequisiteChecks == null) { - return new PrerequisiteCheckConfig(); - } - return prerequisiteChecks.configuration; + return prerequisiteChecks.stream().map(c -> c.className).collect(Collectors.toList()); } /** - * Merges the prerequisite checks section of the upgrade xml with - * the prerequisite checks from a service's upgrade xml. - * These are added to the end of the current list of checks. + * Merges the processing section of the upgrade xml with + * the processing section from a service's upgrade xml. + * These are added to the end of the current list of services. * * @param pack * the service's upgrade pack */ - public void mergePrerequisiteChecks(UpgradePack pack) { - PrerequisiteChecks newPrereqChecks = pack.prerequisiteChecks; - if (prerequisiteChecks == null) { - prerequisiteChecks = newPrereqChecks; - return; - } - - if (newPrereqChecks == null) { - return; - } - - if (prerequisiteChecks.checks == null) { - prerequisiteChecks.checks = new ArrayList<>(); - } - if (newPrereqChecks.checks != null) { - prerequisiteChecks.checks.addAll(newPrereqChecks.checks); - } - - if (newPrereqChecks.configuration == null) { - return; - } - - if (prerequisiteChecks.configuration == null) { - prerequisiteChecks.configuration = newPrereqChecks.configuration; - return; - } - if (prerequisiteChecks.configuration.globalProperties == null) { - prerequisiteChecks.configuration.globalProperties = new ArrayList<>(); - } - if (prerequisiteChecks.configuration.prerequisiteCheckProperties == null) { - prerequisiteChecks.configuration.prerequisiteCheckProperties = new ArrayList<>(); - } - if (newPrereqChecks.configuration.globalProperties != null) { - prerequisiteChecks.configuration.globalProperties.addAll(newPrereqChecks.configuration.globalProperties); - } - if (newPrereqChecks.configuration.prerequisiteCheckProperties != null) { - prerequisiteChecks.configuration.prerequisiteCheckProperties.addAll(newPrereqChecks.configuration.prerequisiteCheckProperties); - } - } - -/** - * Merges the processing section of the upgrade xml with - * the processing section from a service's upgrade xml. - * These are added to the end of the current list of services. - * - * @param pack - * the service's upgrade pack - */ public void mergeProcessing(UpgradePack pack) { List list = pack.processing; if (list == null) { @@ -241,22 +179,6 @@ public void mergeProcessing(UpgradePack pack) { initializeProcessingComponentMappings(); } - /** - * Gets a list of stacks which are between the current stack version and the - * target stack version inclusive. For example, if upgrading from HDP-2.2 to - * HDP-2.4, this should include HDP-2.3 and HDP-2.4. - *

- * This method is used to combine the correct configuration packs for a - * specific upgrade from - * {@link AmbariMetaInfo#getConfigUpgradePack(String, String)}. - * - * @return a list of intermediate stacks (target stack inclusive) or - * {@code null} if none. - */ - public List getIntermediateStacks() { - return intermediateStacks; - } - /** * @return the target stack, or {@code null} if the upgrade is within the same stack */ @@ -630,113 +552,51 @@ private void initializeTasks(String service, List tasks) { } /** - * An intermediate stack definition in - * upgrade/upgrade-path/intermediate-stack path - */ - public static class IntermediateStack { - - @XmlAttribute - public String version; - } - - /** - * Container class to specify list of additional prerequisite checks to run in addition to the - * required prerequisite checks and configuration properties for all prerequisite checks + * @return */ - public static class PrerequisiteChecks { - /** - * List of additional prerequisite checks to run in addition to required prerequisite checks - */ - @XmlElement(name="check", type=String.class) - public List checks = new ArrayList<>(); - - /** - * Prerequisite checks configuration - */ - @XmlElement(name="configuration") - public PrerequisiteCheckConfig configuration; + public PrerequisiteCheckConfig getPrerequisiteCheckConfig() { + return new PrerequisiteCheckConfig(prerequisiteChecks); } /** - * Prerequisite checks configuration + * Holds the config properties for all the checks defined for an Upgrade Pack. */ public static class PrerequisiteCheckConfig { - /** - * Global config properties common to all prereq checks - */ - @XmlElement(name="property") - public List globalProperties; - - /** - * Config properties for individual prerequisite checks - */ - @XmlElement(name="check-properties") - public List prerequisiteCheckProperties; - - /** - * Get global config properties as a map - * @return Map of global config properties - */ - public Map getGlobalProperties() { - if(globalProperties == null) { - return null; - } - Map result = new HashMap<>(); - for (PrerequisiteProperty property : globalProperties) { - result.put(property.name, property.value); - } - return result; + private List m_checks; + private PrerequisiteCheckConfig(List checks) { + m_checks = checks; } - /** - * Get config properties for a given prerequisite check as a map - * @param checkName The prerequisite check name - * @return Map of config properties for the prerequisite check - */ public Map getCheckProperties(String checkName) { - if(prerequisiteCheckProperties == null) { - return null; + if (null == m_checks) { + return Collections.emptyMap(); } - for(PrerequisiteCheckProperties checkProperties : prerequisiteCheckProperties) { - if(checkProperties.name.equalsIgnoreCase(checkName)) { - return checkProperties.getProperties(); - } + + Optional optional = m_checks.stream() + .filter(c -> c.className.equals(checkName)).findFirst(); + + if (!optional.isPresent()) { + return Collections.emptyMap(); } - return null; + + PrerequisiteCheckDefinition checks = optional.get(); + + Map map = checks.properties.stream().collect(Collectors.toMap( + c -> c.name, c -> c.value)); + + return map; } } /** - * Config properties for a specific prerequisite check. + * The definition for each check in the Upgrade Pack. */ - public static class PrerequisiteCheckProperties { - /** - * Prereq check name - */ - @XmlAttribute - public String name; + public static class PrerequisiteCheckDefinition { + @XmlAttribute(name="class") + public String className; - /** - * Config properties for the prerequisite check - */ @XmlElement(name="property") - public List properties; - - /** - * Get config properties as a map - * @return Map of config properties - */ - public Map getProperties() { - if(properties == null) { - return null; - } - - Map result = new HashMap<>(); - for (PrerequisiteProperty property : properties) { - result.put(property.name, property.value); - } - return result; - } + public List properties = new ArrayList<>(); } /** @@ -762,4 +622,5 @@ private static class DowngradeTasks { private List tasks = new ArrayList<>(); } + } diff --git a/ambari-server/src/main/resources/upgrade-pack.xsd b/ambari-server/src/main/resources/upgrade-pack.xsd index 58f26f6117e..3e1dfebe615 100644 --- a/ambari-server/src/main/resources/upgrade-pack.xsd +++ b/ambari-server/src/main/resources/upgrade-pack.xsd @@ -111,8 +111,7 @@ - - + @@ -124,28 +123,12 @@ - - + - - - - - - - - - - - - - - - diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/AtlasPresenceCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/AtlasPresenceCheckTest.java deleted file mode 100644 index dca14ab6703..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/AtlasPresenceCheckTest.java +++ /dev/null @@ -1,42 +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.checks; - -import static org.junit.Assert.assertEquals; - -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Test; -import org.mockito.Mockito; - - -public class AtlasPresenceCheckTest { - private final AtlasPresenceCheck m_check = new AtlasPresenceCheck(); - - @Test - public void perform() throws Exception { - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(Mockito.mock(RepositoryVersionEntity.class)); - m_check.perform(check, request); - - assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - } -} \ No newline at end of file diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheckTest.java deleted file mode 100644 index efc6a80e894..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheckTest.java +++ /dev/null @@ -1,178 +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.checks; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.api.services.AmbariMetaInfo; -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.ServiceComponent; -import org.apache.ambari.server.state.ServiceComponentHost; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Provider; - -/** - * Unit tests for SecondaryNamenodeDeletedCheck - * - */ -@RunWith(MockitoJUnitRunner.class) -public class DruidHighAvailabilityCheckTest -{ - private final Clusters clusters = Mockito.mock(Clusters.class); - - private final DruidHighAvailabilityCheck druidHighAvailabilityCheck = new DruidHighAvailabilityCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - druidHighAvailabilityCheck.clustersProvider = new Provider() { - @Override - public Clusters get() { - return clusters; - } - }; - - druidHighAvailabilityCheck.ambariMetaInfo = new Provider() { - @Override - public AmbariMetaInfo get() { - return Mockito.mock(AmbariMetaInfo.class); - } - }; - - Configuration config = Mockito.mock(Configuration.class); - druidHighAvailabilityCheck.config = config; - - m_services.clear(); - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("DRUID", service); - - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(druidHighAvailabilityCheck.isApplicable(request)); - - request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - request.addResult(CheckDescription.DRUID_HA_WARNING, PrereqCheckStatus.PASS); - Assert.assertTrue(druidHighAvailabilityCheck.isApplicable(request)); - - m_services.remove("DRUID"); - Assert.assertFalse(druidHighAvailabilityCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final ServiceComponentHost serviceComponentHost= Mockito.mock(ServiceComponentHost.class); - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final Service service = Mockito.mock(Service.class); - final ServiceComponent serviceComponent = Mockito.mock(ServiceComponent.class); - final ServiceComponent haComponent = Mockito.mock(ServiceComponent.class); - Mockito.when(serviceComponent.getServiceComponentHosts()).thenReturn(Collections.singletonMap("host", null)); - Mockito.when(haComponent.getServiceComponentHosts()).thenReturn(ImmutableMap.of("host1", serviceComponentHost, "host2", serviceComponentHost)); - - // All Components Not HA - Mockito.when(cluster.getService("DRUID")).thenReturn(service); - Mockito.when(service.getServiceComponent("DRUID_COORDINATOR")).thenReturn(serviceComponent); - Mockito.when(service.getServiceComponent("DRUID_BROKER")).thenReturn(serviceComponent); - Mockito.when(service.getServiceComponent("DRUID_MIDDLEMANAGER")).thenReturn(serviceComponent); - Mockito.when(service.getServiceComponent("DRUID_HISTORICAL")).thenReturn(serviceComponent); - Mockito.when(service.getServiceComponent("DRUID_OVERLORD")).thenReturn(serviceComponent); - Mockito.when(service.getServiceComponent("DRUID_ROUTER")).thenReturn(serviceComponent); - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - druidHighAvailabilityCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - Assert.assertEquals("DRUID", check.getFailedOn().toArray(new String[1])[0]); - Assert.assertEquals("High Availability is not enabled for Druid. Druid Service may have some downtime during upgrade. Deploy multiple instances of DRUID_BROKER, DRUID_COORDINATOR, DRUID_HISTORICAL, DRUID_OVERLORD, DRUID_MIDDLEMANAGER, DRUID_ROUTER in the Cluster to avoid any downtime.", check.getFailReason()); - - // Some Components have HA - Mockito.when(cluster.getService("DRUID")).thenReturn(service); - Mockito.when(service.getServiceComponent("DRUID_COORDINATOR")).thenReturn(serviceComponent); - Mockito.when(service.getServiceComponent("DRUID_BROKER")).thenReturn(haComponent); - Mockito.when(service.getServiceComponent("DRUID_MIDDLEMANAGER")).thenReturn(serviceComponent); - Mockito.when(service.getServiceComponent("DRUID_HISTORICAL")).thenReturn(haComponent); - Mockito.when(service.getServiceComponent("DRUID_OVERLORD")).thenReturn(serviceComponent); - Mockito.when(service.getServiceComponent("DRUID_ROUTER")).thenReturn(haComponent); - check = new PrerequisiteCheck(null, null); - druidHighAvailabilityCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - Assert.assertEquals("DRUID", check.getFailedOn().toArray(new String[1])[0]); - Assert.assertEquals("High Availability is not enabled for Druid. Druid Service may have some downtime during upgrade. Deploy multiple instances of DRUID_COORDINATOR, DRUID_OVERLORD, DRUID_MIDDLEMANAGER in the Cluster to avoid any downtime.", check.getFailReason()); - - // All components have HA - Mockito.when(cluster.getService("DRUID")).thenReturn(service); - Mockito.when(service.getServiceComponent("DRUID_COORDINATOR")).thenReturn(haComponent); - Mockito.when(service.getServiceComponent("DRUID_BROKER")).thenReturn(haComponent); - Mockito.when(service.getServiceComponent("DRUID_MIDDLEMANAGER")).thenReturn(haComponent); - Mockito.when(service.getServiceComponent("DRUID_HISTORICAL")).thenReturn(haComponent); - Mockito.when(service.getServiceComponent("DRUID_OVERLORD")).thenReturn(haComponent); - Mockito.when(service.getServiceComponent("DRUID_ROUTER")).thenReturn(haComponent); - - - check = new PrerequisiteCheck(null, null); - druidHighAvailabilityCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheckTest.java deleted file mode 100644 index 606d4b73264..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveDynamicServiceDiscoveryCheckTest.java +++ /dev/null @@ -1,139 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import com.google.inject.Provider; - -/** - * Tests for {@link HiveDynamicServiceDiscoveryCheck} - */ -public class HiveDynamicServiceDiscoveryCheckTest { - private final Clusters m_clusters = Mockito.mock(Clusters.class); - - private final HiveDynamicServiceDiscoveryCheck m_check = new HiveDynamicServiceDiscoveryCheck(); - - final RepositoryVersionEntity repositoryVersion = Mockito.mock(RepositoryVersionEntity.class); - - /** - * - */ - @Before - public void setup() throws Exception { - m_check.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return m_clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - m_check.config = config; - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("hive-site", desiredConfig); - - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - Map checkProperties = new HashMap<>(); - checkProperties.put("min-failure-stack-version","HDP-2.3.0.0"); - PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); - Mockito.when(prerequisiteCheckConfig.getCheckProperties( - m_check.getClass().getName())).thenReturn(checkProperties); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - - // Check HDP-2.2.x => HDP-2.2.y - request.setSourceStackId(new StackId("HDP-2.2.4.2")); - - Mockito.when(repositoryVersion.getVersion()).thenReturn("2.2.8.4"); - Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2.8.4")); - request.setTargetRepositoryVersion(repositoryVersion); - - m_check.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - - // Check HDP-2.2.x => HDP-2.3.y - request.setSourceStackId(new StackId("HDP-2.2.4.2")); - - Mockito.when(repositoryVersion.getVersion()).thenReturn("2.3.8.4"); - Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.3.8.4")); - request.setTargetRepositoryVersion(repositoryVersion); - - m_check.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - // Check HDP-2.3.x => HDP-2.3.y - request.setSourceStackId(new StackId("HDP-2.3.4.2")); - request.setTargetRepositoryVersion(repositoryVersion); - m_check.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - // Check HDP-2.3.x => HDP-2.4.y - request.setSourceStackId(new StackId("HDP-2.3.4.2")); - - Mockito.when(repositoryVersion.getVersion()).thenReturn("2.4.8.4"); - Mockito.when(repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.4.8.4")); - request.setTargetRepositoryVersion(repositoryVersion); - - m_check.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - // Check when properties are specified - properties.put("hive.server2.support.dynamic.service.discovery", "true"); - properties.put("hive.zookeeper.quorum", "host"); - properties.put("hive.server2.zookeeper.namespace", "namespace"); - check = new PrerequisiteCheck(null, null); - m_check.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } - -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheckTest.java deleted file mode 100644 index 6bba2ea8bbb..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheckTest.java +++ /dev/null @@ -1,199 +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.checks; - -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.ServiceComponent; -import org.apache.ambari.server.state.ServiceComponentHost; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Tests {@link HiveMultipleMetastoreCheck} - */ -@RunWith(MockitoJUnitRunner.class) -public class HiveMultipleMetastoreCheckTest { - private final Clusters m_clusters = Mockito.mock(Clusters.class); - private final HiveMultipleMetastoreCheck m_check = new HiveMultipleMetastoreCheck(); - private final RepositoryVersionDAO repositoryVersionDAO = Mockito.mock( - RepositoryVersionDAO.class); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - /** - * - */ - @Before - public void setup() throws Exception { - m_check.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return m_clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - m_check.config = config; - - Mockito.when(m_repositoryVersion.getVersion()).thenReturn("1.0.0.0-1234"); - Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "1.0")); - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - /** - * Tests that the check is applicable when hive is installed. - * - * @throws Exception - */ - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); - Mockito.when(cluster.getServices()).thenReturn(m_services); - - m_services.put("HDFS", Mockito.mock(Service.class)); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - // HIVE not installed - Assert.assertFalse(m_check.isApplicable(request)); - - // install HIVE - m_services.put("HIVE", Mockito.mock(Service.class)); - - m_check.repositoryVersionDaoProvider = new Provider() { - @Override - public RepositoryVersionDAO get() { - return repositoryVersionDAO; - } - }; - - Mockito.when(repositoryVersionDAO.findByStackNameAndVersion(Mockito.anyString(), - Mockito.anyString())).thenReturn(m_repositoryVersion); - - // HIVE installed - Assert.assertTrue(m_check.isApplicable(request)); - } - - /** - * Tests that the warning is correctly tripped when there are not enough - * metastores. - * - * @throws Exception - */ - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Service hive = Mockito.mock(Service.class); - ServiceComponent metastore = Mockito.mock(ServiceComponent.class); - - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); - Mockito.when(cluster.getService("HIVE")).thenReturn(hive); - - Mockito.when(hive.getServiceComponent("HIVE_METASTORE")).thenReturn(metastore); - - Map metastores = new HashMap<>(); - Mockito.when(metastore.getServiceComponentHosts()).thenReturn(metastores); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - m_check.perform(check, request); - - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - - metastores.put("c6401", Mockito.mock(ServiceComponentHost.class)); - metastores.put("c6402", Mockito.mock(ServiceComponentHost.class)); - - check = new PrerequisiteCheck(null, null); - m_check.perform(check, request); - - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } - - @Test - public void testPerformFail() throws Exception{ - final Cluster cluster = Mockito.mock(Cluster.class); - final LinkedHashSet failedOnExpected = new LinkedHashSet<>(); - Service hive = Mockito.mock(Service.class); - ServiceComponent metastore = Mockito.mock(ServiceComponent.class); - Map metastores = new HashMap<>(); - - failedOnExpected.add("HIVE"); - - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); - Mockito.when(cluster.getService("HIVE")).thenReturn(hive); - Mockito.when(hive.getServiceComponent("HIVE_METASTORE")).thenReturn(metastore); - Mockito.when(metastore.getServiceComponentHosts()).thenReturn(metastores); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - m_check.perform(check, request); - - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - - check = new PrerequisiteCheck(null, null); - m_check.perform(check, request); - Assert.assertEquals(failedOnExpected, check.getFailedOn()); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveNotRollingWarningTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveNotRollingWarningTest.java deleted file mode 100644 index bed1b4354c0..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HiveNotRollingWarningTest.java +++ /dev/null @@ -1,128 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.upgrade.UpgradeType; -import org.easymock.EasyMock; -import org.easymock.EasyMockSupport; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Tests {@link HiveNotRollingWarning}. - */ -@RunWith(MockitoJUnitRunner.class) -public class HiveNotRollingWarningTest extends EasyMockSupport { - - private final String m_clusterName = "c1"; - private final Clusters m_clusters = niceMock(Clusters.class); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - - /** - * @throws Exception - */ - @Test - public void testIsApplicable() throws Exception { - final HiveNotRollingWarning hiveWarningCheck = new HiveNotRollingWarning(); - hiveWarningCheck.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return m_clusters; - } - }; - - final Cluster cluster = niceMock(Cluster.class); - final Service hive = niceMock(Service.class); - - m_services.put("HIVE", hive); - - EasyMock.expect(cluster.getClusterId()).andReturn(1L).anyTimes(); - - EasyMock.expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.3")).anyTimes(); - EasyMock.expect(cluster.getServices()).andReturn(m_services).anyTimes(); - EasyMock.expect(m_clusters.getCluster(m_clusterName)).andReturn(cluster).atLeastOnce(); - - PrereqCheckRequest request = niceMock(PrereqCheckRequest.class); - EasyMock.expect(request.getClusterName()).andReturn(m_clusterName).anyTimes(); - EasyMock.expect(request.getUpgradeType()).andReturn(UpgradeType.ROLLING).anyTimes(); - EasyMock.expect(request.getTargetRepositoryVersion()).andReturn(m_repositoryVersion).atLeastOnce(); - - replayAll(); - - Assert.assertTrue(hiveWarningCheck.isApplicable(request)); - - verifyAll(); - } - - /** - * @throws Exception - */ - @Test - public void testPerform() throws Exception { - final HiveNotRollingWarning hiveWarningCheck = new HiveNotRollingWarning(); - - PrereqCheckRequest request = new PrereqCheckRequest(m_clusterName); - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - - hiveWarningCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/KafkaKerberosCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/KafkaKerberosCheckTest.java deleted file mode 100644 index b4ee6ec48c6..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/KafkaKerberosCheckTest.java +++ /dev/null @@ -1,122 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.SecurityType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -@RunWith(MockitoJUnitRunner.class) -public class KafkaKerberosCheckTest { - private final Clusters clusters = Mockito.mock(Clusters.class); - - private final KafkaKerberosCheck kafkaKerberosCheck = new KafkaKerberosCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - kafkaKerberosCheck.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return clusters; - } - }; - - m_services.clear(); - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("KAFKA", service); - - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(kafkaKerberosCheck.isApplicable(request)); - - m_services.remove("KAFKA"); - Assert.assertFalse(kafkaKerberosCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Map services = new HashMap<>(); - final Service service = Mockito.mock(Service.class); - - services.put("KAFKA", service); - - Mockito.when(cluster.getServices()).thenReturn(services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(cluster.getSecurityType()).thenReturn(SecurityType.KERBEROS); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - - kafkaKerberosCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - - check = new PrerequisiteCheck(null, null); - Mockito.when(cluster.getSecurityType()).thenReturn(SecurityType.NONE); - - kafkaKerberosCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheckTest.java deleted file mode 100644 index f8ea1699486..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/MapReduce2JobHistoryStatePreservingCheckTest.java +++ /dev/null @@ -1,193 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Tests for {@link org.apache.ambari.server.checks.MapReduce2JobHistoryStatePreservingCheckTest} - */ -@RunWith(MockitoJUnitRunner.class) -public class MapReduce2JobHistoryStatePreservingCheckTest { - private final Clusters m_clusters = Mockito.mock(Clusters.class); - private final RepositoryVersionDAO m_repositoryVersionDao = Mockito.mock(RepositoryVersionDAO.class); - - private final MapReduce2JobHistoryStatePreservingCheck m_check = new MapReduce2JobHistoryStatePreservingCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - /** - * - */ - @Before - public void setup() throws Exception { - m_check.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return m_clusters; - } - }; - - m_check.repositoryVersionDaoProvider = new Provider() { - @Override - public RepositoryVersionDAO get() { - return m_repositoryVersionDao; - }; - }; - - Configuration config = Mockito.mock(Configuration.class); - m_check.config = config; - - RepositoryVersionEntity rve = Mockito.mock(RepositoryVersionEntity.class); - Mockito.when(rve.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersionDao.findByStackNameAndVersion(Mockito.anyString(), Mockito.anyString())).thenReturn(rve); - - Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.3.1.1-1234"); - Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.3")); - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - /** - * @throws Exception - */ - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); - Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.3")); - - Mockito.when(cluster.getServices()).thenReturn(m_services); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setSourceStackId(new StackId("HDP", "2.3.0.0")); - request.setTargetRepositoryVersion(m_repositoryVersion); - - // MAPREDUCE2 not installed - Assert.assertFalse(m_check.isApplicable(request)); - - // MAPREDUCE2 installed - m_services.put("MAPREDUCE2", Mockito.mock(Service.class)); - Assert.assertTrue(m_check.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("mapred-site", desiredConfig); - configMap.put("yarn-site", desiredConfig); - - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_check.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - properties.put(MapReduce2JobHistoryStatePreservingCheck.MAPREDUCE2_JOBHISTORY_RECOVERY_ENABLE_KEY, "true"); - properties.put(MapReduce2JobHistoryStatePreservingCheck.MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_KEY, "org.apache.hadoop.mapreduce.v2.hs.HistoryServerLeveldbStateStoreService"); - properties.put(MapReduce2JobHistoryStatePreservingCheck.MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_LEVELDB_PATH_KEY, ""); - check = new PrerequisiteCheck(null, null); - m_check.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - check = new PrerequisiteCheck(null, null); - properties.put(MapReduce2JobHistoryStatePreservingCheck.MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_LEVELDB_PATH_KEY, "/hadoop/yarn/timeline"); - properties.put(MapReduce2JobHistoryStatePreservingCheck.YARN_TIMELINE_SERVICE_LEVELDB_STATE_STORE_PATH_KEY, "not /hadoop/yarn/timeline"); - m_check.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - check = new PrerequisiteCheck(null, null); - properties.put(MapReduce2JobHistoryStatePreservingCheck.YARN_TIMELINE_SERVICE_LEVELDB_STATE_STORE_PATH_KEY, "/hadoop/yarn/timeline"); - m_check.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } - - @SuppressWarnings("serial") - @Test - public void testIsApplicableMinimumStackVersion() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(cluster.getServices()).thenReturn(new HashMap() { - { - put("MAPREDUCE2", null); - } - }); - Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("MYSTACK-12.2")); - Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster); - PrereqCheckRequest request = new PrereqCheckRequest("c1"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.0.0.1"); - - // MAPREDUCE2 installed - m_services.put("MAPREDUCE2", Mockito.mock(Service.class)); - - boolean isApplicable = m_check.isApplicable(request); - Assert.assertTrue(isApplicable); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerAuditDbCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerAuditDbCheckTest.java deleted file mode 100644 index 4a7e8d30213..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerAuditDbCheckTest.java +++ /dev/null @@ -1,138 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/* Tests for RangerAuditDbCheck */ -@RunWith(MockitoJUnitRunner.class) -public class RangerAuditDbCheckTest { - private final Clusters clusters = Mockito.mock(Clusters.class); - private final RangerAuditDbCheck rangerAuditDbCheck = new RangerAuditDbCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - rangerAuditDbCheck.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - rangerAuditDbCheck.config = config; - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("RANGER", service); - - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(rangerAuditDbCheck.isApplicable(request)); - - m_services.remove("RANGER"); - Assert.assertFalse(rangerAuditDbCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Map services = new HashMap<>(); - final Service service = Mockito.mock(Service.class); - - services.put("RANGER", service); - - Mockito.when(cluster.getServices()).thenReturn(services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("ranger-admin-site", desiredConfig); - - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - properties.put("ranger.audit.source.type", "db"); - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - rangerAuditDbCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - - properties.put("ranger.audit.source.type", "solr"); - check = new PrerequisiteCheck(null, null); - rangerAuditDbCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - } - -} \ No newline at end of file diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java deleted file mode 100644 index d24c73cc1da..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java +++ /dev/null @@ -1,542 +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.checks; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.controller.internal.URLStreamProvider; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import com.google.inject.Provider; - - -/** - * Unit tests for RangerPasswordCheck - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(RangerPasswordCheck.class) -public class RangerPasswordCheckTest { - - private static final String RANGER_URL = "http://foo:6080/"; - - private static final String GOOD_LOGIN_RESPONSE = "{\"count\": 0 }"; - - private static final String BAD_LOGIN_RESPONSE = "Ranger redirects to login HTML"; - - private static final String GOOD_USER_RESPONSE = - "{\"queryTimeMS\": 1446758948823," + - "\"vXUsers\": [" + - " {" + - " \"name\": \"r_admin\"" + - " }" + - "]}"; - - private static final String NO_USER_RESPONSE = - "{\"queryTimeMS\": 1446758948823," + - "\"vXUsers\": [" + - "]}"; - - private Clusters m_clusters = EasyMock.createMock(Clusters.class); - private Map m_configMap = new HashMap<>(); - private RangerPasswordCheck m_rpc = null; - private URLStreamProvider m_streamProvider = EasyMock.createMock(URLStreamProvider.class); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - MockitoAnnotations.initMocks(this); - - m_configMap.put("policymgr_external_url", RANGER_URL); - m_configMap.put("admin_username", "admin"); - m_configMap.put("admin_password", "pass"); - m_configMap.put("ranger_admin_username", "r_admin"); - m_configMap.put("ranger_admin_password", "r_pass"); - - Cluster cluster = EasyMock.createMock(Cluster.class); - - Config config = EasyMock.createMock(Config.class); - final Map services = new HashMap<>(); - final Service service = EasyMock.createMock(Service.class); - - services.put("RANGER", service); - - Map desiredMap = new HashMap<>(); - DesiredConfig dc = EasyMock.createMock(DesiredConfig.class); - desiredMap.put("admin-properties", dc); - desiredMap.put("ranger-env", dc); - - expect(dc.getTag()).andReturn("").anyTimes(); - expect(config.getProperties()).andReturn(m_configMap).anyTimes(); - expect(cluster.getServices()).andReturn(services).anyTimes(); - expect(cluster.getService("RANGER")).andReturn(service).anyTimes(); - expect(cluster.getDesiredConfigs()).andReturn(desiredMap).anyTimes(); - expect(cluster.getDesiredConfigByType((String) anyObject())).andReturn(config).anyTimes(); - expect(cluster.getConfig((String) anyObject(), (String) anyObject())).andReturn(config).anyTimes(); - expect(m_clusters.getCluster((String) anyObject())).andReturn(cluster).anyTimes(); - - replay(m_clusters, cluster, dc, config); - - m_rpc = new RangerPasswordCheck(); - m_rpc.clustersProvider = new Provider() { - @Override - public Clusters get() { - // TODO Auto-generated method stub - return m_clusters; - } - }; - - EasyMock.reset(m_streamProvider); - PowerMockito.whenNew(URLStreamProvider.class).withAnyArguments().thenReturn(m_streamProvider); - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testApplicable() throws Exception { - - final Service service = EasyMock.createMock(Service.class); - m_services.put("RANGER", service); - - expect(service.getDesiredStackId()).andReturn(new StackId("HDP-2.3")).anyTimes(); - - Cluster cluster = m_clusters.getCluster("cluster"); - EasyMock.reset(cluster); - expect(cluster.getServices()).andReturn(m_services).anyTimes(); - expect(cluster.getService("RANGER")).andReturn(service).atLeastOnce(); - - replay(cluster, service); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - assertTrue(m_rpc.isApplicable(request)); - } - - @SuppressWarnings("unchecked") - @Test - public void testMissingProps() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - m_configMap.clear(); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not check credentials. Missing property admin-properties/policymgr_external_url", check.getFailReason()); - - m_configMap.put("policymgr_external_url", RANGER_URL); - check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not check credentials. Missing property ranger-env/admin_username", check.getFailReason()); - - m_configMap.put("admin_username", "admin"); - check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not check credentials. Missing property ranger-env/admin_password", check.getFailReason()); - - - m_configMap.put("admin_password", "pass"); - check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not check credentials. Missing property ranger-env/ranger_admin_username", check.getFailReason()); - - m_configMap.put("ranger_admin_username", "r_admin"); - check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not check credentials. Missing property ranger-env/ranger_admin_password", check.getFailReason()); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())); - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - m_configMap.put("ranger_admin_password", "r_pass"); - check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - } - - @SuppressWarnings("unchecked") - @Test - public void testNormal() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once(); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testNoUser() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(NO_USER_RESPONSE.getBytes())).once(); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testBadUserParsing() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream( - "some really bad non-json".getBytes())); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - String error = "The response from Ranger was malformed. "; - error += "com.google.gson.stream.MalformedJsonException: Expected EOF at line 1 column 6. "; - error += "Request: " + RANGER_URL + "service/xusers/users?name=r_admin"; - - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals(error, check.getFailReason()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testJsonCasting() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream( - "{ \"data\": \"bad\", \"vXUsers\": \"xyz\" }".getBytes())); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - String error = "The response from Ranger was malformed. "; - error += "java.lang.String cannot be cast to java.util.List. "; - error += "Request: " + RANGER_URL + "service/xusers/users?name=r_admin"; - - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals(error, check.getFailReason()); - - verify(conn, m_streamProvider); - } - - - @SuppressWarnings("unchecked") - @Test - public void testAdminUnauthorized() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(401); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - assertEquals("Credentials for user 'admin' in Ambari do not match Ranger.", check.getFailReason()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testAdminUnauthorizedByRedirect() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(BAD_LOGIN_RESPONSE.getBytes())); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - assertEquals("Credentials for user 'admin' in Ambari do not match Ranger.", check.getFailReason()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testAdminIOException() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andThrow(new IOException("whoops")); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not access Ranger to verify user 'admin' against " + RANGER_URL + "service/public/api/repository/count. whoops", check.getFailReason()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testAdminBadResponse() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(404); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not verify credentials for user 'admin'. Response code 404 received from " + RANGER_URL + "service/public/api/repository/count", check.getFailReason()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testUserUnauthorized() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(401); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - assertEquals("Credentials for user 'r_admin' in Ambari do not match Ranger.", check.getFailReason()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testUserUnauthorizedByRedirect() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(BAD_LOGIN_RESPONSE.getBytes())).once(); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - assertEquals("Credentials for user 'r_admin' in Ambari do not match Ranger.", check.getFailReason()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testUserIOException() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andThrow(new IOException("again!")); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn(conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not access Ranger to verify user 'r_admin' against " + RANGER_URL + "service/public/api/repository/count. again!", check.getFailReason()); - - verify(conn, m_streamProvider); - } - - @SuppressWarnings("unchecked") - @Test - public void testUserBadResponse() throws Exception { - - HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class); - - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(200); - expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())).once(); - expect(conn.getResponseCode()).andReturn(500); - - expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(), - (InputStream) anyObject(), (Map>) anyObject())).andReturn( - conn).anyTimes(); - - replay(conn, m_streamProvider); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_rpc.perform(check, new PrereqCheckRequest("cluster")); - - assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - assertEquals("Could not verify credentials for user 'r_admin'. Response code 500 received from " + RANGER_URL + "service/public/api/repository/count", check.getFailReason()); - - verify(conn, m_streamProvider); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerSSLConfigCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerSSLConfigCheckTest.java deleted file mode 100644 index 50ec21c11de..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerSSLConfigCheckTest.java +++ /dev/null @@ -1,177 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - - -/* Test for RangerSSLConfigCheck */ -@RunWith(MockitoJUnitRunner.class) -public class RangerSSLConfigCheckTest { - - private final Clusters clusters = Mockito.mock(Clusters.class); - private final RangerSSLConfigCheck rangerSSLConfigCheck = new RangerSSLConfigCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - rangerSSLConfigCheck.clustersProvider = new Provider() { - @Override - public Clusters get() { - return clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - rangerSSLConfigCheck.config = config; - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("RANGER", service); - - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(rangerSSLConfigCheck.isApplicable(request)); - - m_services.remove("RANGER"); - Assert.assertFalse(rangerSSLConfigCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Map services = new HashMap<>(); - final Service service = Mockito.mock(Service.class); - - services.put("RANGER", service); - - Mockito.when(cluster.getServices()).thenReturn(services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("ranger-admin-site", desiredConfig); - - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - properties.put("ranger.service.http.enabled","true"); - properties.put("ranger.service.https.attrib.ssl.enabled","true"); - properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("ranger.service.http.enabled","true"); - properties.put("ranger.service.https.attrib.ssl.enabled","true"); - properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); - check = new PrerequisiteCheck(null, null); - rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - - properties.put("ranger.service.http.enabled","true"); - properties.put("ranger.service.https.attrib.ssl.enabled","fasle"); - properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); - check = new PrerequisiteCheck(null, null); - rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - - properties.put("ranger.service.http.enabled","false"); - properties.put("ranger.service.https.attrib.ssl.enabled","true"); - properties.put("ranger.https.attrib.keystore.file","/etc/ranger/admin/conf/ranger-admin-keystore.jks"); - check = new PrerequisiteCheck(null, null); - rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - - properties.put("ranger.service.http.enabled","false"); - properties.put("ranger.service.https.attrib.ssl.enabled","true"); - properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); - check = new PrerequisiteCheck(null, null); - rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - - properties.put("ranger.service.http.enabled","false"); - properties.put("ranger.service.https.attrib.ssl.enabled","false"); - properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); - check = new PrerequisiteCheck(null, null); - rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - - - } -} - - diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheckTest.java deleted file mode 100644 index c038c47ce4b..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/SecondaryNamenodeDeletedCheckTest.java +++ /dev/null @@ -1,150 +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.checks; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.api.services.AmbariMetaInfo; -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.dao.HostComponentStateDAO; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.ServiceComponent; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Unit tests for SecondaryNamenodeDeletedCheck - * - */ -@RunWith(MockitoJUnitRunner.class) -public class SecondaryNamenodeDeletedCheckTest { - private final Clusters clusters = Mockito.mock(Clusters.class); - private final HostComponentStateDAO hostComponentStateDAO = Mockito.mock(HostComponentStateDAO.class); - - private final SecondaryNamenodeDeletedCheck secondaryNamenodeDeletedCheck = new SecondaryNamenodeDeletedCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - secondaryNamenodeDeletedCheck.clustersProvider = new Provider() { - @Override - public Clusters get() { - return clusters; - } - }; - - secondaryNamenodeDeletedCheck.ambariMetaInfo = new Provider() { - @Override - public AmbariMetaInfo get() { - return Mockito.mock(AmbariMetaInfo.class); - } - }; - - secondaryNamenodeDeletedCheck.hostComponentStateDao = hostComponentStateDAO; - Configuration config = Mockito.mock(Configuration.class); - secondaryNamenodeDeletedCheck.config = config; - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("HDFS", service); - - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(secondaryNamenodeDeletedCheck.isApplicable(request)); - - request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - request.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL); - Assert.assertFalse(secondaryNamenodeDeletedCheck.isApplicable(request)); - - request.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.PASS); - Assert.assertTrue(secondaryNamenodeDeletedCheck.isApplicable(request)); - - m_services.remove("HDFS"); - Assert.assertFalse(secondaryNamenodeDeletedCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final Service service = Mockito.mock(Service.class); - final ServiceComponent serviceComponent = Mockito.mock(ServiceComponent.class); - Mockito.when(cluster.getService("HDFS")).thenReturn(service); - Mockito.when(service.getServiceComponent("SECONDARY_NAMENODE")).thenReturn(serviceComponent); - Mockito.when(serviceComponent.getServiceComponentHosts()).thenReturn(Collections.singletonMap("host", null)); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - secondaryNamenodeDeletedCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - Assert.assertEquals("HDFS", check.getFailedOn().toArray(new String[1])[0]); - Assert.assertEquals("The SNameNode component must be deleted from host: host.", check.getFailReason()); - - Mockito.when(serviceComponent.getServiceComponentHosts()).thenReturn(Collections.emptyMap()); - check = new PrerequisiteCheck(null, null); - secondaryNamenodeDeletedCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheckTest.java deleted file mode 100644 index b32a7821dca..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesMapReduceDistributedCacheCheckTest.java +++ /dev/null @@ -1,286 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Unit tests for ServicesMapReduceDistributedCacheCheck - * - */ -@RunWith(MockitoJUnitRunner.class) -public class ServicesMapReduceDistributedCacheCheckTest { - private final Clusters clusters = Mockito.mock(Clusters.class); - - private final ServicesMapReduceDistributedCacheCheck servicesMapReduceDistributedCacheCheck = new ServicesMapReduceDistributedCacheCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - servicesMapReduceDistributedCacheCheck.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - servicesMapReduceDistributedCacheCheck.config = config; - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("YARN", service); - - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(servicesMapReduceDistributedCacheCheck.isApplicable(request)); - - request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - request.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL); - Assert.assertFalse(servicesMapReduceDistributedCacheCheck.isApplicable(request)); - - request.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.PASS); - Assert.assertTrue(servicesMapReduceDistributedCacheCheck.isApplicable(request)); - - m_services.remove("YARN"); - Assert.assertFalse(servicesMapReduceDistributedCacheCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("mapred-site", desiredConfig); - configMap.put("core-site", desiredConfig); - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("mapreduce.application.framework.path", "hdfs://some/path"); - properties.put("mapreduce.application.classpath", "anything"); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("mapreduce.application.framework.path", "dfs://some/path"); - properties.put("mapreduce.application.classpath", "anything"); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "hdfs://ha"); - properties.put("mapreduce.application.framework.path", "/some/path"); - properties.put("mapreduce.application.classpath", "anything"); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "dfs://ha"); - properties.put("mapreduce.application.framework.path", "/some/path"); - properties.put("mapreduce.application.classpath", "anything"); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - // Fail due to no dfs - properties.put("fs.defaultFS", "anything"); - properties.put("mapreduce.application.framework.path", "/some/path"); - properties.put("mapreduce.application.classpath", "anything"); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - } - - @Test - public void testPerformWithCheckConfig() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("mapred-site", desiredConfig); - configMap.put("core-site", desiredConfig); - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - Map checkProperties = new HashMap<>(); - checkProperties.put("dfs-protocols-regex","^([^:]*dfs|wasb|ecs):.*"); - PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); - Mockito.when(prerequisiteCheckConfig.getCheckProperties( - servicesMapReduceDistributedCacheCheck.getClass().getName())).thenReturn(checkProperties); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("mapreduce.application.framework.path", "hdfs://some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("mapreduce.application.framework.path", "dfs://some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("mapreduce.application.framework.path", "wasb://some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("mapreduce.application.framework.path", "ecs://some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "hdfs://ha"); - properties.put("mapreduce.application.framework.path", "/some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "dfs://ha"); - properties.put("mapreduce.application.framework.path", "/some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "wasb://ha"); - properties.put("mapreduce.application.framework.path", "/some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "ecs://ha"); - properties.put("mapreduce.application.framework.path", "/some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - // Fail due to no dfs - properties.put("fs.defaultFS", "anything"); - properties.put("mapreduce.application.framework.path", "/some/path"); - properties.put("mapreduce.application.classpath", "anything"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesMapReduceDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java deleted file mode 100644 index 8c51add4cda..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeHighAvailabilityCheckTest.java +++ /dev/null @@ -1,131 +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.checks; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Unit tests for ServicesNamenodeHighAvailabilityCheck - * - */ -@RunWith(MockitoJUnitRunner.class) -public class ServicesNamenodeHighAvailabilityCheckTest { - private final Clusters clusters = Mockito.mock(Clusters.class); - - private final ServicesNamenodeHighAvailabilityCheck servicesNamenodeHighAvailabilityCheck = new ServicesNamenodeHighAvailabilityCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - servicesNamenodeHighAvailabilityCheck.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - servicesNamenodeHighAvailabilityCheck.config = config; - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("HDFS", service); - - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(servicesNamenodeHighAvailabilityCheck.isApplicable(request)); - - m_services.remove("HDFS"); - Assert.assertFalse(servicesNamenodeHighAvailabilityCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Mockito.when(cluster.getDesiredConfigs()).thenReturn(Collections.singletonMap("hdfs-site", desiredConfig)); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - servicesNamenodeHighAvailabilityCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - properties.put("dfs.internal.nameservices", "anything"); - check = new PrerequisiteCheck(null, null); - servicesNamenodeHighAvailabilityCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java deleted file mode 100644 index 356d2cdf6cf..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesNamenodeTruncateCheckTest.java +++ /dev/null @@ -1,164 +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.checks; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Unit tests for ServicesNamenodeTruncateCheck - * - */ -@RunWith(MockitoJUnitRunner.class) -public class ServicesNamenodeTruncateCheckTest { - - private Clusters m_clusters = EasyMock.createMock(Clusters.class); - private ServicesNamenodeTruncateCheck m_check = new ServicesNamenodeTruncateCheck(); - private final Map m_configMap = new HashMap<>(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - Cluster cluster = EasyMock.createMock(Cluster.class); - - Config config = EasyMock.createMock(Config.class); - final Service service = Mockito.mock(Service.class); - - m_services.clear(); - m_services.put("HDFS", service); - - expect(cluster.getServices()).andReturn(m_services).anyTimes(); - expect(config.getProperties()).andReturn(m_configMap).anyTimes(); - expect(cluster.getService("HDFS")).andReturn(service); - expect(cluster.getDesiredConfigByType("hdfs-site")).andReturn(config).anyTimes(); - expect(m_clusters.getCluster((String) anyObject())).andReturn(cluster).anyTimes(); - - replay(m_clusters, cluster, config); - - Configuration configuration = EasyMock.createMock(Configuration.class); - replay(configuration); - m_check.config = configuration; - - m_check.clustersProvider = new Provider() { - @Override - public Clusters get() { - return m_clusters; - } - }; - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getVersion()).thenReturn("HDP-2.2.0.0"); - Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2.0")); - - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - - @Test - public void testIsApplicable() throws Exception { - - PrereqCheckRequest checkRequest = new PrereqCheckRequest("c1"); - checkRequest.setSourceStackId(new StackId("HDP", "2.2")); - checkRequest.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(m_check.isApplicable(checkRequest)); - } - - @Test - public void testPerform() throws Exception { - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - PrereqCheckRequest request = new PrereqCheckRequest("c1"); - m_check.perform(check, request); - assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - // Check HDP-2.2.x => HDP-2.2.y is FAIL - m_configMap.put("dfs.allow.truncate", "true"); - request.setSourceStackId(new StackId("HDP-2.2.4.2")); - - Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.2.8.4"); - Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.2.8.4")); - request.setTargetRepositoryVersion(m_repositoryVersion); - - check = new PrerequisiteCheck(null, null); - m_check.perform(check, request); - assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - m_configMap.put("dfs.allow.truncate", "false"); - check = new PrerequisiteCheck(null, null); - m_check.perform(check, request); - assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - // Check HDP-2.2.x => HDP-2.3.y is FAIL - m_configMap.put("dfs.allow.truncate", "true"); - request.setSourceStackId(new StackId("HDP-2.2.4.2")); - - Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.3.8.4"); - Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.3.8.4")); - request.setTargetRepositoryVersion(m_repositoryVersion); - - check = new PrerequisiteCheck(null, null); - m_check.perform(check, request); - assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - m_configMap.put("dfs.allow.truncate", "false"); - check = new PrerequisiteCheck(null, null); - m_check.perform(check, request); - assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } -} \ No newline at end of file diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java deleted file mode 100644 index 0123f180f05..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesTezDistributedCacheCheckTest.java +++ /dev/null @@ -1,325 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Unit tests for ServicesTezDistributedCacheCheck - * - */ -@RunWith(MockitoJUnitRunner.class) -public class ServicesTezDistributedCacheCheckTest { - private final Clusters clusters = Mockito.mock(Clusters.class); - - private final ServicesTezDistributedCacheCheck servicesTezDistributedCacheCheck = new ServicesTezDistributedCacheCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - servicesTezDistributedCacheCheck.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - servicesTezDistributedCacheCheck.config = config; - - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("TEZ", service); - - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - - Assert.assertTrue(servicesTezDistributedCacheCheck.isApplicable(request)); - - PrereqCheckRequest req = new PrereqCheckRequest("cluster"); - req.setTargetRepositoryVersion(m_repositoryVersion); - - req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.FAIL); - Assert.assertFalse(servicesTezDistributedCacheCheck.isApplicable(req)); - - req.addResult(CheckDescription.SERVICES_NAMENODE_HA, PrereqCheckStatus.PASS); - Assert.assertTrue(servicesTezDistributedCacheCheck.isApplicable(req)); - - - m_services.remove("TEZ"); - Assert.assertFalse(servicesTezDistributedCacheCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("tez-site", desiredConfig); - configMap.put("core-site", desiredConfig); - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("tez.lib.uris", "hdfs://some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("tez.lib.uris", "dfs://some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "dfs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "hdfs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - // Fail due to no DFS - properties.put("fs.defaultFS", "anything"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - // Fail due to no tar.gz - properties.put("fs.defaultFS", "hdfs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.log"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - // Fail due to property set to true - properties.put("fs.defaultFS", "hdfs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "true"); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - } - - @Test - public void testPerformWithCheckConfig() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("tez-site", desiredConfig); - configMap.put("core-site", desiredConfig); - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - Map checkProperties = new HashMap<>(); - checkProperties.put("dfs-protocols-regex","^([^:]*dfs|wasb|ecs):.*"); - PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); - Mockito.when(prerequisiteCheckConfig.getCheckProperties( - servicesTezDistributedCacheCheck.getClass().getName())).thenReturn(checkProperties); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("tez.lib.uris", "hdfs://some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("tez.lib.uris", "dfs://some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("tez.lib.uris", "wasb://some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "anything"); - properties.put("tez.lib.uris", "ecs://some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "dfs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "hdfs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "wasb://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - properties.put("fs.defaultFS", "ecs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - - // Fail due to no DFS - properties.put("fs.defaultFS", "anything"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - // Fail due to no tar.gz - properties.put("fs.defaultFS", "hdfs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.log"); - properties.put("tez.use.cluster.hadoop-libs", "false"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - // Fail due to property set to true - properties.put("fs.defaultFS", "hdfs://ha"); - properties.put("tez.lib.uris", "/some/path/to/archive.tar.gz"); - properties.put("tez.use.cluster.hadoop-libs", "true"); - request = new PrereqCheckRequest("cluster"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - check = new PrerequisiteCheck(null, null); - servicesTezDistributedCacheCheck.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java deleted file mode 100644 index 5164a4f6d9b..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicesYarnWorkPreservingCheckTest.java +++ /dev/null @@ -1,129 +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.checks; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Unit tests for ServicesYarnWorkPreservingCheck - * - */ -@RunWith(MockitoJUnitRunner.class) -public class ServicesYarnWorkPreservingCheckTest { - private final Clusters clusters = Mockito.mock(Clusters.class); - - private final ServicesYarnWorkPreservingCheck servicesYarnWorkPreservingCheck = new ServicesYarnWorkPreservingCheck(); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - - @Before - public void setup() throws Exception { - servicesYarnWorkPreservingCheck.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - servicesYarnWorkPreservingCheck.config = config; - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - final Service service = Mockito.mock(Service.class); - - m_services.put("YARN", service); - - Mockito.when(cluster.getServices()).thenReturn(m_services); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - Assert.assertTrue(servicesYarnWorkPreservingCheck.isApplicable(request)); - - m_services.remove("YARN"); - Assert.assertFalse(servicesYarnWorkPreservingCheck.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Mockito.when(cluster.getDesiredConfigs()).thenReturn(Collections.singletonMap("yarn-site", desiredConfig)); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - servicesYarnWorkPreservingCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - properties.put("yarn.resourcemanager.work-preserving-recovery.enabled", "true"); - check = new PrerequisiteCheck(null, null); - servicesYarnWorkPreservingCheck.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/StormShutdownWarningTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/StormShutdownWarningTest.java deleted file mode 100644 index a5e24f1f339..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/StormShutdownWarningTest.java +++ /dev/null @@ -1,127 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.RepositoryType; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.repository.ClusterVersionSummary; -import org.apache.ambari.server.state.repository.VersionDefinitionXml; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.upgrade.UpgradeType; -import org.easymock.EasyMock; -import org.easymock.EasyMockSupport; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -import com.google.inject.Provider; - -/** - * Tests {@link StormShutdownWarning}. - */ -@RunWith(MockitoJUnitRunner.class) -public class StormShutdownWarningTest extends EasyMockSupport { - - private final String m_clusterName = "c1"; - private final Clusters m_clusters = niceMock(Clusters.class); - - @Mock - private ClusterVersionSummary m_clusterVersionSummary; - - @Mock - private VersionDefinitionXml m_vdfXml; - - @Mock - private RepositoryVersionEntity m_repositoryVersion; - - final Map m_services = new HashMap<>(); - - @Before - public void setup() throws Exception { - m_services.clear(); - - Mockito.when(m_repositoryVersion.getType()).thenReturn(RepositoryType.STANDARD); - Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml); - Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary); - Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet()); - } - - /** - * @throws Exception - */ - @Test - public void testIsApplicable() throws Exception { - final StormShutdownWarning shutdownWarning = new StormShutdownWarning(); - shutdownWarning.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return m_clusters; - } - }; - - final Cluster cluster = niceMock(Cluster.class); - final Service hive = niceMock(Service.class); - - m_services.put("STORM", hive); - - EasyMock.expect(cluster.getClusterId()).andReturn(1L).anyTimes(); - - EasyMock.expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.3")).anyTimes(); - EasyMock.expect(cluster.getServices()).andReturn(m_services).anyTimes(); - EasyMock.expect(m_clusters.getCluster(m_clusterName)).andReturn(cluster).atLeastOnce(); - - PrereqCheckRequest request = niceMock(PrereqCheckRequest.class); - EasyMock.expect(request.getClusterName()).andReturn(m_clusterName).anyTimes(); - EasyMock.expect(request.getUpgradeType()).andReturn(UpgradeType.ROLLING).anyTimes(); - EasyMock.expect(request.getTargetRepositoryVersion()).andReturn(m_repositoryVersion).anyTimes(); - - replayAll(); - - Assert.assertTrue(shutdownWarning.isApplicable(request)); - - verifyAll(); - } - - /** - * @throws Exception - */ - @Test - public void testPerform() throws Exception { - final StormShutdownWarning shutdownWarning = new StormShutdownWarning(); - - PrereqCheckRequest request = new PrereqCheckRequest(m_clusterName); - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - - shutdownWarning.perform(check, request); - Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java deleted file mode 100644 index 5de4b2a4df5..00000000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java +++ /dev/null @@ -1,214 +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.checks; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ambari.server.configuration.Configuration; -import org.apache.ambari.server.controller.PrereqCheckRequest; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.DesiredConfig; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.StackId; -import org.apache.ambari.server.state.stack.PrereqCheckStatus; -import org.apache.ambari.server.state.stack.PrerequisiteCheck; -import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mockito; - -import com.google.inject.Provider; - -/** - * Tests for {@link YarnTimelineServerStatePreservingCheckTest} - * @Deprecated - */ -@Ignore -public class YarnTimelineServerStatePreservingCheckTest { - private final Clusters m_clusters = Mockito.mock(Clusters.class); - - private final YarnTimelineServerStatePreservingCheck m_check = new YarnTimelineServerStatePreservingCheck(); - - final RepositoryVersionEntity m_repositoryVersion = Mockito.mock(RepositoryVersionEntity.class); - - /** - * - */ - @Before - public void setup() throws Exception { - m_check.clustersProvider = new Provider() { - - @Override - public Clusters get() { - return m_clusters; - } - }; - Configuration config = Mockito.mock(Configuration.class); - m_check.config = config; - - Mockito.when(m_repositoryVersion.getVersion()).thenReturn("2.3.0.0-1234"); - Mockito.when(m_repositoryVersion.getStackId()).thenReturn(new StackId("HDP", "2.3")); - } - - /** - * @throws Exception - */ - @Test - public void testIsApplicable() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); - Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.2")); - - Map services = new HashMap<>(); - Mockito.when(cluster.getServices()).thenReturn(services); - - RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class); - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2"); - - Map checkProperties = new HashMap<>(); - checkProperties.put("min-applicable-stack-version","HDP-2.2.4.2"); - PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); - Mockito.when(prerequisiteCheckConfig.getCheckProperties( - m_check.getClass().getName())).thenReturn(checkProperties); - - PrereqCheckRequest request = new PrereqCheckRequest("cluster"); - request.setTargetRepositoryVersion(m_repositoryVersion); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - - // YARN not installed - Assert.assertFalse(m_check.isApplicable(request)); - - // YARN installed - services.put("YARN", Mockito.mock(Service.class)); - Assert.assertTrue(m_check.isApplicable(request)); - - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.0.0"); - Assert.assertFalse(m_check.isApplicable(request)); - - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2"); - Assert.assertTrue(m_check.isApplicable(request)); - } - - @Test - public void testPerform() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); - - final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); - Mockito.when(desiredConfig.getTag()).thenReturn("tag"); - Map configMap = new HashMap<>(); - configMap.put("yarn-site", desiredConfig); - configMap.put("core-site", desiredConfig); - - Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); - final Config config = Mockito.mock(Config.class); - Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); - final Map properties = new HashMap<>(); - Mockito.when(config.getProperties()).thenReturn(properties); - - PrerequisiteCheck check = new PrerequisiteCheck(null, null); - m_check.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); - - properties.put("yarn.timeline-service.recovery.enabled", "true"); - check = new PrerequisiteCheck(null, null); - m_check.perform(check, new PrereqCheckRequest("cluster")); - Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); - } - - @SuppressWarnings("serial") - @Test - public void testIsApplicableMinimumHDPStackVersion() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(cluster.getServices()).thenReturn(new HashMap() { - { - put("YARN", null); - } - }); - Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.2")); - RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class); - Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster); - - Map checkProperties = new HashMap<>(); - checkProperties.put("min-applicable-stack-version","HDP-2.2.4.2"); - PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); - Mockito.when(prerequisiteCheckConfig.getCheckProperties( - m_check.getClass().getName())).thenReturn(checkProperties); - - PrereqCheckRequest request = new PrereqCheckRequest("c1"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - - // Check < 2.2.4.2 - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.1.1.1"); - boolean isApplicable = m_check.isApplicable(request); - Assert.assertFalse(isApplicable); - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.1"); - isApplicable = m_check.isApplicable(request); - Assert.assertFalse(isApplicable); - - // Check == 2.2.4.2 - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2"); - isApplicable = m_check.isApplicable(request); - Assert.assertTrue(isApplicable); - - // Check > 2.2.4.2 - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.4"); - isApplicable = m_check.isApplicable(request); - Assert.assertTrue(isApplicable); - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.3.1.1"); - isApplicable = m_check.isApplicable(request); - Assert.assertTrue(isApplicable); - } - - @SuppressWarnings("serial") - @Test - public void testIsApplicableMinimumStackVersion() throws Exception { - final Cluster cluster = Mockito.mock(Cluster.class); - Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(cluster.getServices()).thenReturn(new HashMap() { - { - put("YARN", null); - } - }); - Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("MYSTACK-12.2")); - RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class); - Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster); - - Map checkProperties = new HashMap<>(); - checkProperties.put("min-applicable-stack-version", "HDP-2.2.4.2"); - PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); - Mockito.when(prerequisiteCheckConfig.getCheckProperties( - m_check.getClass().getName())).thenReturn(checkProperties); - - PrereqCheckRequest request = new PrereqCheckRequest("c1"); - request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); - - Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.3.0.1"); - boolean isApplicable = m_check.isApplicable(request); - Assert.assertTrue(isApplicable); - } -} diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java index 44c58f095da..62616487d99 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java @@ -24,14 +24,17 @@ import java.io.File; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Optional; import org.apache.ambari.server.stack.ModuleFileUnmarshaller; +import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig; import org.apache.ambari.server.state.stack.upgrade.Grouping; import org.apache.ambari.server.state.stack.upgrade.Lifecycle; import org.apache.ambari.server.state.stack.upgrade.Lifecycle.LifecycleType; import org.apache.ambari.server.state.stack.upgrade.UpgradeType; import org.junit.Test; +import org.springframework.util.CollectionUtils; /** * Tests for the upgrade pack @@ -71,6 +74,19 @@ public void testUpgradeParsing() throws Exception { List groups = upgradeLifecycle.get().groups; assertEquals(29, groups.size()); + assertEquals(12, upgradepack.getPrerequisiteChecks().size()); + + PrerequisiteCheckConfig checkConfig = upgradepack.getPrerequisiteCheckConfig(); + Map map = checkConfig.getCheckProperties("abc"); + assertTrue(CollectionUtils.isEmpty(map)); + + map = checkConfig.getCheckProperties("org.apache.ambari.server.checks.HiveDynamicServiceDiscoveryCheck"); + assertFalse(CollectionUtils.isEmpty(map)); + assertTrue(map.containsKey("min-failure-stack-version")); + assertTrue(map.containsKey("my-property")); + assertFalse(map.containsKey("random-key")); + assertEquals("HDP-2.3.0.0", map.get("min-failure-stack-version")); + assertEquals("my-value", map.get("my-property")); } } diff --git a/ambari-server/src/test/resources/mpacks-v2/upgrade-packs/upgrade-basic.xml b/ambari-server/src/test/resources/mpacks-v2/upgrade-packs/upgrade-basic.xml index 1ebb00faa44..2f9d25d50a7 100644 --- a/ambari-server/src/test/resources/mpacks-v2/upgrade-packs/upgrade-basic.xml +++ b/ambari-server/src/test/resources/mpacks-v2/upgrade-packs/upgrade-basic.xml @@ -22,27 +22,26 @@ false false rolling + - org.apache.ambari.server.checks.HiveMultipleMetastoreCheck - org.apache.ambari.server.checks.MapReduce2JobHistoryStatePreservingCheck - org.apache.ambari.server.checks.SecondaryNamenodeDeletedCheck - org.apache.ambari.server.checks.ServicesMapReduceDistributedCacheCheck - org.apache.ambari.server.checks.ServicesNamenodeHighAvailabilityCheck - org.apache.ambari.server.checks.ServicesTezDistributedCacheCheck - org.apache.ambari.server.checks.ServicesYarnWorkPreservingCheck - org.apache.ambari.server.checks.YarnRMHighAvailabilityCheck - org.apache.ambari.server.checks.YarnTimelineServerStatePreservingCheck - org.apache.ambari.server.checks.DruidHighAvailabilityCheck - org.apache.ambari.server.checks.LZOCheck - - - - - - HDP-2.3.0.0 - - + + + + + + + + + + + + + + HDP-2.3.0.0 + my-value + +