Repository: ambari Updated Branches: refs/heads/trunk e302ffed4 -> ca12fe436
AMBARI-8122. Correct Issues Pointed Out In Git 32187893edabcfc29f1cfb4961146566c2215433 (dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ca12fe43 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ca12fe43 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ca12fe43 Branch: refs/heads/trunk Commit: ca12fe4360fa1c8c1efb98c27cca92e194e550b8 Parents: e302ffe Author: Lisnichenko Dmitro <[email protected]> Authored: Tue Nov 4 22:08:33 2014 +0200 Committer: Lisnichenko Dmitro <[email protected]> Committed: Tue Nov 4 22:08:33 2014 +0200 ---------------------------------------------------------------------- .../ambari/server/state/stack/OsFamily.java | 10 +- ambari-server/src/main/resources/os_family.json | 29 ----- .../ambari/server/state/stack/OSFamilyTest.java | 108 +++++++++++++++++++ ambari-server/src/test/resources/os_family.json | 12 +-- 4 files changed, 115 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/ca12fe43/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java index b024cfe..22b6005 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java @@ -34,6 +34,7 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import org.apache.ambari.server.configuration.Configuration; +import org.apache.commons.io.IOUtils; /** * Class that encapsulates OS family logic @@ -66,22 +67,23 @@ public class OsFamily { } private void init(String SharedResourcesPath){ + FileInputStream inputStream = null; try { File f = new File(SharedResourcesPath, FILE_NAME); if (!f.exists()) throw new Exception(); - FileInputStream inputStream = new FileInputStream(f); + inputStream = new FileInputStream(f); Type type = new TypeToken<Map<String, Map<String, Set<String>>>>() {}.getType(); Gson gson = new Gson(); osMap = gson.fromJson(new InputStreamReader(inputStream), type); - inputStream.close(); } catch (Exception e) { LOG.error(String.format(LOAD_CONFIG_MSG, new File(SharedResourcesPath, FILE_NAME).toString())); - throw new RuntimeException(LOAD_CONFIG_MSG); + throw new RuntimeException(e); + } finally { + IOUtils.closeQuietly(inputStream); } } - /** * Separate os name from os major version * @param os the os http://git-wip-us.apache.org/repos/asf/ambari/blob/ca12fe43/ambari-server/src/main/resources/os_family.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/os_family.json b/ambari-server/src/main/resources/os_family.json deleted file mode 100644 index 6638ea5..0000000 --- a/ambari-server/src/main/resources/os_family.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "redhat7": [ - "redhat7", - "centos7", - "oraclelinux7", - "rhel7" - ], - "redhat6": [ - "redhat6", - "centos6", - "oraclelinux6", - "rhel6" - ], - "redhat5": [ - "redhat5", - "centos5", - "oraclelinux5", - "rhel5" - ], - "suse11": [ - "suse11", - "sles11", - "opensuse11" - ], - "ubuntu12": [ - "debian12", - "ubuntu12" - ] -} http://git-wip-us.apache.org/repos/asf/ambari/blob/ca12fe43/ambari-server/src/test/java/org/apache/ambari/server/state/stack/OSFamilyTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/OSFamilyTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/OSFamilyTest.java new file mode 100644 index 0000000..e4aa8f7 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/OSFamilyTest.java @@ -0,0 +1,108 @@ +/** + * 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.state.stack; + + +import com.google.inject.Guice; +import com.google.inject.Injector; + +import junit.framework.Assert; +import org.apache.ambari.server.orm.InMemoryDefaultTestModule; +import org.junit.Before; +import org.junit.Test; +import java.lang.reflect.Method; +import java.util.*; + + +public class OSFamilyTest { + OsFamily os_family = null; + private Injector injector; + + @Before + public void setup() throws Exception { + injector = Guice.createInjector(new InMemoryDefaultTestModule()); + + os_family = injector.getInstance(OsFamily.class); + } + + @Test + public void testOSListing() throws Exception{ + Set<String> actual_oslist = os_family.os_list(); + Set<String> expected_oslist = new HashSet<String>(Arrays.asList( + "redhat6", "oraclelinux5", "suse11", "fedora6", "opensuse11", + "centos6", "fedora5","centos5", "ubuntu12", "redhat5", "sles11", + "oraclelinux6", "debian12", "sled11" + )); + + Assert.assertNotNull(actual_oslist); + Assert.assertEquals(expected_oslist, actual_oslist); + } + + @Test + public void testParsingOS() throws Exception{ + // test data + Map<String,String> expected_map = new HashMap<String,String>(); + expected_map.put("distro", "ubuntu"); + expected_map.put("versions", "12"); + + String test_value = "ubuntu12"; + + // trying to call private method + Class[] parse_os_args = { + String.class + }; + Method parse_os = os_family.getClass().getDeclaredMethod("parse_os", parse_os_args); + + // setting private method to be available + parse_os.setAccessible(true); + Object test_map = parse_os.invoke(os_family, test_value); + + // setting them back to private for the instance + parse_os.setAccessible(false); + + + // checking result + Assert.assertNotNull(test_map); + Assert.assertEquals(expected_map.getClass().getName(), test_map.getClass().getName()); + Assert.assertEquals(expected_map, test_map); + } + + @Test + public void testFindTypes() throws Exception{ + Set<String> expected_set = new HashSet<String>(Arrays.asList( + "ubuntu12", + "debian12" + )); + + Set<String> actual_set = os_family.findTypes("ubuntu12"); + Assert.assertNotNull(actual_set); + Assert.assertEquals(expected_set, actual_set); + } + + @Test + public void testFind() throws Exception{ + String expected_result = "ubuntu12"; + String actual_result = os_family.find("debian12"); + + Assert.assertNotNull(actual_result); + Assert.assertEquals(expected_result, actual_result); + } + + +} + http://git-wip-us.apache.org/repos/asf/ambari/blob/ca12fe43/ambari-server/src/test/resources/os_family.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/resources/os_family.json b/ambari-server/src/test/resources/os_family.json index 7314fd0..3cf0fed 100644 --- a/ambari-server/src/test/resources/os_family.json +++ b/ambari-server/src/test/resources/os_family.json @@ -4,17 +4,7 @@ "redhat", "fedora", "centos", - "oraclelinux", - "ascendos", - "amazon", - "xenserver", - "oel", - "ovs", - "cloudlinux", - "slc", - "scientific", - "psbm", - "centos linux" + "oraclelinux" ], "versions": [ 5,
