ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbhowm...@apache.org
Subject [1/4] ambari git commit: AMBARI-16274. Views: Simplify View Configuration for Remote Ambari Managed Cluster. (Gaurav Nagar via dipayanb)
Date Wed, 11 May 2016 09:15:43 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk bc82a6eca -> c150f0ded


http://git-wip-us.apache.org/repos/asf/ambari/blob/c150f0de/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/AuthConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/AuthConfigurationBuilder.java
b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/AuthConfigurationBuilder.java
index c8ca6cd..4911455 100644
--- a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/AuthConfigurationBuilder.java
+++ b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/AuthConfigurationBuilder.java
@@ -54,13 +54,11 @@ public class AuthConfigurationBuilder {
     String auth;
     auth = context.getProperties().get("webhdfs.auth");
 
-    if (auth == null || auth.isEmpty()) {
-      try {
-        auth = getConfigurationFromAmbari();
-      } catch (NoClusterAssociatedException e) {
-        auth = "auth=SIMPLE";
-        LOG.warn(String.format("HDFS090 Authentication parameters could not be determined.
%s assumed.", auth));
-      }
+    if ((auth == null || auth.isEmpty()) && context.getCluster() != null) {
+      auth = getConfigurationFromAmbari();
+    } else  {
+      auth = "auth=SIMPLE";
+      LOG.warn(String.format("HDFS090 Authentication parameters could not be determined.
%s assumed.", auth));
     }
 
     parseAuthString(auth);
@@ -81,7 +79,7 @@ public class AuthConfigurationBuilder {
    * Determine configuration from Ambari.
    */
   private String getConfigurationFromAmbari() throws NoClusterAssociatedException {
-    String authMethod = ambariApi.getCluster().getConfigurationValue(
+    String authMethod = context.getCluster().getConfigurationValue(
         "core-site", "hadoop.security.authentication");
     return String.format("auth=%s", authMethod);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c150f0de/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/ConfigurationBuilder.java
b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/ConfigurationBuilder.java
index 4518ac6..8b45cd6 100644
--- a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/ConfigurationBuilder.java
+++ b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/ConfigurationBuilder.java
@@ -121,9 +121,10 @@ public class ConfigurationBuilder {
 
   private String getProperty(String type, String key, String instanceProperty) {
     String value;
-    try {
-      value = ambariApi.getCluster().getConfigurationValue(type, key);
-    } catch (NoClusterAssociatedException e) {
+
+    if(context.getCluster() != null) {
+      value = context.getCluster().getConfigurationValue(type, key);
+    } else {
       value = context.getProperties().get(instanceProperty);
     }
     return value;
@@ -131,15 +132,16 @@ public class ConfigurationBuilder {
 
   private void copyPropertyIfExists(String type, String key) {
     String value;
-    try {
-      value = ambariApi.getCluster().getConfigurationValue(type, key);
+
+    if(context.getCluster() != null) {
+      value = context.getCluster().getConfigurationValue(type, key);
       if (value != null) {
         conf.set(key, value);
         LOG.debug("set " + key + " = " + value);
       } else {
         LOG.debug("No such property " + type + "/" + key);
       }
-    } catch (NoClusterAssociatedException e) {
+    } else {
       LOG.debug("No such property " + type + "/" + key);
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c150f0de/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/RemoteClusterTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/RemoteClusterTest.java
b/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/RemoteClusterTest.java
deleted file mode 100644
index ec4df7d..0000000
--- a/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/RemoteClusterTest.java
+++ /dev/null
@@ -1,137 +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.view.utils.ambari;
-
-import org.apache.ambari.view.URLStreamProvider;
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.cluster.Cluster;
-import org.apache.commons.collections4.map.PassiveExpiringMap;
-import org.easymock.IAnswer;
-import org.json.simple.JSONObject;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
-
-public class RemoteClusterTest {
-  public static final String AMBARI_CLUSTER_REST_URL = "http://example.com:8080/api/v1/clusters/c1";
-
-  @Rule
-  public ExpectedException thrown= ExpectedException.none();
-
-  @Test
-  public void testGetRemoteClusterThatIsNotPresent() throws Exception {
-    ViewContext viewContext = createNiceMock(ViewContext.class);
-    Map<String, String> instanceProperties = new HashMap<String, String>();
-    expect(viewContext.getProperties()).andReturn(instanceProperties).anyTimes();
-    replay(viewContext);
-
-    AmbariApi ambariApi = new AmbariApi(viewContext);
-    Cluster cluster = ambariApi.getRemoteCluster();
-    assertNull(cluster);
-  }
-
-  @Test
-  public void testGetRemoteClusterNoCredentials() throws Exception {
-    ViewContext viewContext = createNiceMock(ViewContext.class);
-    Map<String, String> instanceProperties = new HashMap<String, String>();
-    instanceProperties.put(AmbariApi.AMBARI_SERVER_URL_INSTANCE_PROPERTY,
-        AMBARI_CLUSTER_REST_URL);
-    expect(viewContext.getProperties()).andReturn(instanceProperties).anyTimes();
-    replay(viewContext);
-
-    thrown.expect(AmbariApiException.class);
-    AmbariApi ambariApi = new AmbariApi(viewContext);
-    Cluster cluster = ambariApi.getRemoteCluster();
-  }
-
-  @Test
-  public void testGetRemoteClusterThatIsPresent() throws Exception {
-    ViewContext viewContext = createNiceMock(ViewContext.class);
-    Map<String, String> instanceProperties = new HashMap<String, String>();
-    instanceProperties.put(AmbariApi.AMBARI_SERVER_URL_INSTANCE_PROPERTY,
-        AMBARI_CLUSTER_REST_URL);
-    instanceProperties.put(AmbariApi.AMBARI_SERVER_USERNAME_INSTANCE_PROPERTY, "admin");
-    instanceProperties.put(AmbariApi.AMBARI_SERVER_PASSWORD_INSTANCE_PROPERTY, "admin");
-    expect(viewContext.getProperties()).andReturn(instanceProperties).anyTimes();
-    replay(viewContext);
-
-    AmbariApi ambariApi = new AmbariApi(viewContext);
-    Cluster cluster = ambariApi.getRemoteCluster();
-    assertNotNull(cluster);
-    assertEquals(cluster.getName(), "c1");
-  }
-
-  @Test
-  public void testGetConfigurationValue() throws Exception {
-    URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class);
-
-    final String desiredConfigsString = "{\"Clusters\": {\"desired_configs\": {\"test-site\":
{\"tag\": \"TAG\"}}}}";
-    final String configurationString = "{\"items\": [{\"properties\": {\"test.property.name\":
\"test property value\"}}]}";
-    final int[] desiredConfigPolls = {0};
-    final int[] testConfigPolls = {0};
-
-    expect(urlStreamProvider.readFrom(eq(AMBARI_CLUSTER_REST_URL + "?fields=services/ServiceInfo,hosts,Clusters"),
-        eq("GET"), (String) isNull(), (Map<String, String>) anyObject())).andAnswer(new
IAnswer<InputStream>() {
-      @Override
-      public InputStream answer() throws Throwable {
-        desiredConfigPolls[0] += 1;
-        return new ByteArrayInputStream(desiredConfigsString.getBytes());
-      }
-    }).anyTimes();
-
-    expect(urlStreamProvider.readFrom(eq(AMBARI_CLUSTER_REST_URL + "/configurations?(type=test-site&tag=TAG)"),
-        eq("GET"), (String)isNull(), (Map<String, String>) anyObject())).andAnswer(new
IAnswer<InputStream>() {
-      @Override
-      public InputStream answer() throws Throwable {
-        testConfigPolls[0] += 1;
-        return new ByteArrayInputStream(configurationString.getBytes());
-      }
-    }).anyTimes();
-
-    replay(urlStreamProvider);
-
-    RemoteCluster cluster = new RemoteCluster(AMBARI_CLUSTER_REST_URL, urlStreamProvider);
-    PassiveExpiringMap<String, JSONObject> cache = new PassiveExpiringMap<String,
JSONObject>(10000L);
-    cluster.configurationCache = cache;
-
-    String value = cluster.getConfigurationValue("test-site", "test.property.name");
-    assertEquals(value, "test property value");
-    assertEquals(desiredConfigPolls[0], 1);
-    assertEquals(testConfigPolls[0], 1);
-
-    value = cluster.getConfigurationValue("test-site", "test.property.name");
-    assertEquals(value, "test property value");
-    assertEquals(desiredConfigPolls[0], 1);  // cache hit
-    assertEquals(testConfigPolls[0], 1);
-
-    cache.clear();
-    value = cluster.getConfigurationValue("test-site", "test.property.name");
-    assertEquals(value, "test property value");
-    assertEquals(desiredConfigPolls[0], 2);
-    assertEquals(testConfigPolls[0], 2);
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/c150f0de/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/ServicesTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/ServicesTest.java
b/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/ServicesTest.java
index 455ca20..c7c0990 100644
--- a/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/ServicesTest.java
+++ b/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/ServicesTest.java
@@ -100,7 +100,7 @@ public class ServicesTest extends EasyMockSupport {
 
     expect(ambariApi.isClusterAssociated()).andReturn(true).anyTimes();
     setClusterExpectation(cluster, "HTTP_ONLY");
-    expect(ambariApi.getCluster()).andReturn(cluster).anyTimes();
+    expect(viewContext.getCluster()).andReturn(cluster).anyTimes();
     replayAll();
 
     assertEquals(HTTP_RM_URL1, services.getTimelineServerUrl());
@@ -255,7 +255,7 @@ public class ServicesTest extends EasyMockSupport {
 
     expect(ambariApi.isClusterAssociated()).andReturn(true).anyTimes();
     setClusterExpectation(cluster, "HTTP_ONLY");
-    expect(ambariApi.getCluster()).andReturn(cluster).anyTimes();
+    expect(viewContext.getCluster()).andReturn(cluster).anyTimes();
 
     replayAll();
 
@@ -283,7 +283,7 @@ public class ServicesTest extends EasyMockSupport {
 
     expect(ambariApi.isClusterAssociated()).andReturn(true).anyTimes();
     setClusterExpectationWithEmptyWebappConfig(cluster, "HTTP_ONLY");
-    expect(ambariApi.getCluster()).andReturn(cluster).anyTimes();
+    expect(viewContext.getCluster()).andReturn(cluster).anyTimes();
 
     Services services = new Services(ambariApi, viewContext);
 
@@ -307,7 +307,7 @@ public class ServicesTest extends EasyMockSupport {
 
     expect(ambariApi.isClusterAssociated()).andReturn(true).anyTimes();
     setClusterExpectationInHAWithEmptyWebappConfig(cluster, "HTTP_ONLY");
-    expect(ambariApi.getCluster()).andReturn(cluster).anyTimes();
+    expect(viewContext.getCluster()).andReturn(cluster).anyTimes();
 
     Services services = new Services(ambariApi, viewContext);
 
@@ -342,7 +342,7 @@ public class ServicesTest extends EasyMockSupport {
 
     expect(ambariApi.isClusterAssociated()).andReturn(true).anyTimes();
     setClusterExpectationInHA(cluster, "HTTP_ONLY");
-    expect(ambariApi.getCluster()).andReturn(cluster).anyTimes();
+    expect(viewContext.getCluster()).andReturn(cluster).anyTimes();
     expect(viewContext.getURLStreamProvider()).andReturn(urlStreamProvider).anyTimes();
     expect(urlStreamProvider.readFrom(eq(HTTP_RM_URL1 + RM_INFO_API_ENDPOINT), eq("GET"),
anyString(), EasyMock.<Map<String, String>>anyObject())).andReturn(inputStream);
 
@@ -385,7 +385,7 @@ public class ServicesTest extends EasyMockSupport {
 
     expect(ambariApi.isClusterAssociated()).andReturn(true).anyTimes();
     setClusterExpectationWithEmptyWebappConfig(cluster, "HTTP_ONLY");
-    expect(ambariApi.getCluster()).andReturn(cluster).anyTimes();
+    expect(viewContext.getCluster()).andReturn(cluster).anyTimes();
 
     Services services = new Services(ambariApi, viewContext);
 
@@ -432,4 +432,4 @@ public class ServicesTest extends EasyMockSupport {
     expect(viewContextMock.getProperties()).andReturn(map);
     return viewContextMock;
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/c150f0de/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/URLStreamProviderBasicAuthTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/URLStreamProviderBasicAuthTest.java
b/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/URLStreamProviderBasicAuthTest.java
deleted file mode 100644
index 27e98f2..0000000
--- a/contrib/views/utils/src/test/java/org/apache/ambari/view/utils/ambari/URLStreamProviderBasicAuthTest.java
+++ /dev/null
@@ -1,159 +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.view.utils.ambari;
-
-import org.apache.ambari.view.URLStreamProvider;
-import org.easymock.EasyMock;
-import org.easymock.IArgumentMatcher;
-
-import org.junit.Test;
-
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.easymock.EasyMock.*;
-
-public class URLStreamProviderBasicAuthTest {
-
-  @Test
-  public void testReadFrom() throws Exception {
-    URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class);
-    expect(urlStreamProvider.readFrom(anyString(), anyString(), anyString(), HeadersMatcher.mapContainsAuthHeader())).andReturn(null);
-    URLStreamProviderBasicAuth urlStreamProviderBasicAuth =
-        new URLStreamProviderBasicAuth(urlStreamProvider, "user", "pass");
-
-    replay(urlStreamProvider);
-
-    urlStreamProviderBasicAuth.readFrom("http://example.com", "GET",
-        (String) null, null);
-    urlStreamProviderBasicAuth.readFrom("http://example.com", "GET",
-        (String)null, new HashMap<String, String>());
-  }
-
-  @Test
-  public void testReadFrom1() throws Exception {
-    URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class);
-    expect(urlStreamProvider.readFrom(anyString(), anyString(), (InputStream)anyObject(),
-        HeadersMatcher.mapContainsAuthHeader())).andReturn(null);
-    URLStreamProviderBasicAuth urlStreamProviderBasicAuth =
-        new URLStreamProviderBasicAuth(urlStreamProvider, "user", "pass");
-
-    replay(urlStreamProvider);
-
-    urlStreamProviderBasicAuth.readFrom("http://example.com", "GET",
-        (InputStream) null, null);
-    urlStreamProviderBasicAuth.readFrom("http://example.com", "GET",
-        (InputStream)null, new HashMap<String, String>());
-  }
-
-  @Test
-  public void testReadAs() throws Exception {
-    URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class);
-    expect(urlStreamProvider.readAs(anyString(), anyString(), anyString(),
-        HeadersMatcher.mapContainsAuthHeader(), anyString())).andReturn(null);
-    URLStreamProviderBasicAuth urlStreamProviderBasicAuth =
-        new URLStreamProviderBasicAuth(urlStreamProvider, "user", "pass");
-
-    replay(urlStreamProvider);
-
-    urlStreamProviderBasicAuth.readAs("http://example.com", "GET",
-        (String) null, null, "admin");
-    urlStreamProviderBasicAuth.readAs("http://example.com", "GET",
-        (String) null, new HashMap<String, String>(), "admin");
-  }
-
-  @Test
-  public void testReadAs1() throws Exception {
-    URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class);
-    expect(urlStreamProvider.readAs(anyString(), anyString(), (InputStream) anyObject(),
-        HeadersMatcher.mapContainsAuthHeader(), anyString())).andReturn(null);
-    URLStreamProviderBasicAuth urlStreamProviderBasicAuth =
-        new URLStreamProviderBasicAuth(urlStreamProvider, "user", "pass");
-
-    replay(urlStreamProvider);
-
-    urlStreamProviderBasicAuth.readAs("http://example.com", "GET",
-        (InputStream) null, null, "admin");
-    urlStreamProviderBasicAuth.readAs("http://example.com", "GET",
-        (InputStream) null, new HashMap<String, String>(), "admin");
-  }
-
-  @Test
-  public void testReadAsCurrent() throws Exception {
-    URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class);
-    expect(urlStreamProvider.readAsCurrent(anyString(), anyString(), anyString(),
-        HeadersMatcher.mapContainsAuthHeader())).andReturn(null);
-    URLStreamProviderBasicAuth urlStreamProviderBasicAuth =
-        new URLStreamProviderBasicAuth(urlStreamProvider, "user", "pass");
-
-    replay(urlStreamProvider);
-
-    urlStreamProviderBasicAuth.readAsCurrent("http://example.com", "GET",
-        (String) null, null);
-    urlStreamProviderBasicAuth.readAsCurrent("http://example.com", "GET",
-        (String) null, new HashMap<String, String>());
-  }
-
-  @Test
-  public void testReadAsCurrent1() throws Exception {
-    URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class);
-    expect(urlStreamProvider.readAsCurrent(anyString(), anyString(), (InputStream) anyObject(),
-        HeadersMatcher.mapContainsAuthHeader())).andReturn(null);
-    URLStreamProviderBasicAuth urlStreamProviderBasicAuth =
-        new URLStreamProviderBasicAuth(urlStreamProvider, "user", "pass");
-
-    replay(urlStreamProvider);
-
-    urlStreamProviderBasicAuth.readAsCurrent("http://example.com", "GET",
-        (InputStream) null, null);
-    urlStreamProviderBasicAuth.readAsCurrent("http://example.com", "GET",
-        (InputStream)null, new HashMap<String, String>());
-  }
-
-
-  public static class HeadersMatcher implements IArgumentMatcher {
-
-    public static Map<String, String> mapContainsAuthHeader() {
-      EasyMock.reportMatcher(new HeadersMatcher());
-      return null;
-    }
-
-    public void appendTo(StringBuffer buffer) {
-      buffer.append("Authentication header matcher");
-    }
-
-    public boolean matches(Object headers) {
-      if (!(headers instanceof Map)) {
-        return false;
-      }
-
-      Map<String, String> headersMap = (Map<String, String>) headers;
-
-      if (!headersMap.containsKey("Authorization"))
-        return false;
-      String authHeader = headersMap.get("Authorization");
-
-      if (!authHeader.startsWith("Basic "))
-        return false;
-
-      return true;
-    }
-  }
-}
\ No newline at end of file


Mime
View raw message