You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/07/26 00:11:36 UTC
git commit: AMBARI-2731. Use httpcomponents-client for building url
in AmbariManagementControllerImpl. (Andrew Onischuk via smohanty)
Updated Branches:
refs/heads/trunk 8666a165e -> ba1b3bbec
AMBARI-2731. Use httpcomponents-client for building url in AmbariManagementControllerImpl. (Andrew Onischuk via smohanty)
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/ba1b3bbe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/ba1b3bbe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/ba1b3bbe
Branch: refs/heads/trunk
Commit: ba1b3bbec09c48583107a0100e143ac379025df7
Parents: 8666a16
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Thu Jul 25 15:11:20 2013 -0700
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Thu Jul 25 15:11:20 2013 -0700
----------------------------------------------------------------------
ambari-server/pom.xml | 5 ++
.../AmbariManagementControllerImpl.java | 49 +++++++++-----
.../AmbariManagementControllerImplTest.java | 68 +++++++++++++++++++-
3 files changed, 104 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ba1b3bbe/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 8a889e7..3a2dc48 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -713,6 +713,11 @@
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.2.5</version>
+ </dependency>
</dependencies>
<!--<reporting>
<plugins>
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ba1b3bbe/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 9534d61..2a1d188 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -100,6 +100,8 @@ import com.google.inject.Injector;
import com.google.inject.Singleton;
import com.google.inject.persist.Transactional;
+import org.apache.http.client.utils.URIBuilder;
+
@Singleton
public class AmbariManagementControllerImpl implements
AmbariManagementController {
@@ -145,6 +147,8 @@ public class AmbariManagementControllerImpl implements
private Configuration configs;
final private String masterHostname;
+ final private Integer masterPort;
+ final private String masterProtocol;
final private static String JDK_RESOURCE_LOCATION =
"/resources/";
@@ -168,32 +172,43 @@ public class AmbariManagementControllerImpl implements
LOG.info("Initializing the AmbariManagementControllerImpl");
this.masterHostname = InetAddress.getLocalHost().getCanonicalHostName();
- if (configs != null) {
- String protocol, port;
+ if(configs != null)
+ {
if (configs.getApiSSLAuthentication() == true) {
- protocol = "https";
- port = String.valueOf(configs.getClientSSLApiPort());
+ this.masterProtocol = "https";
+ this.masterPort = configs.getClientSSLApiPort();
} else {
- protocol = "http";
- port = String.valueOf(configs.getClientApiPort());
- }
-
- this.jdkResourceUrl = protocol + "://" + masterHostname + ":"
- + port
- + JDK_RESOURCE_LOCATION;
- this.ojdbcUrl = protocol + "://" + masterHostname + ":"
- + port + JDK_RESOURCE_LOCATION + "/" + configs.getOjdbcJarName();
-
- this.mysqljdbcUrl = protocol + "://" + masterHostname + ":"
- + port + JDK_RESOURCE_LOCATION + "/" + configs.getMySQLJarName();
+ this.masterProtocol = "http";
+ this.masterPort = configs.getClientApiPort();
+ }
+ this.jdkResourceUrl = getAmbariServerURI(JDK_RESOURCE_LOCATION);
+ this.ojdbcUrl = getAmbariServerURI(JDK_RESOURCE_LOCATION + "/" + configs.getOjdbcJarName());
+ this.mysqljdbcUrl = getAmbariServerURI(JDK_RESOURCE_LOCATION + "/" + configs.getMySQLJarName());
+
this.serverDB = configs.getServerDBName();
} else {
- this.jdkResourceUrl = null;
+ this.masterProtocol = null;
+ this.masterPort = null;
+
+ this.jdkResourceUrl = null;
this.ojdbcUrl = null;
this.mysqljdbcUrl = null;
this.serverDB = null;
}
}
+
+ public String getAmbariServerURI(String path) {
+ if(masterProtocol==null || masterHostname==null || masterPort==null)
+ return null;
+
+ URIBuilder uriBuilder = new URIBuilder();
+ uriBuilder.setScheme(masterProtocol);
+ uriBuilder.setHost(masterHostname);
+ uriBuilder.setPort(masterPort);
+ uriBuilder.setPath(path);
+
+ return uriBuilder.toString();
+ }
private RoleCommandOrder getRCO(Cluster cluster) {
RoleCommandOrder rco;
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ba1b3bbe/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index 2370013..da825a0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -33,6 +33,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
@@ -67,6 +68,7 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceede
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.easymock.Capture;
+import org.easymock.EasyMock;
import org.junit.Test;
import com.google.gson.Gson;
@@ -82,7 +84,71 @@ import com.google.inject.persist.PersistService;
public class AmbariManagementControllerImplTest {
+ @Test
+ public void testgetAmbariServerURI() throws Exception {
+ // create mocks
+ Injector injector = createStrictMock(Injector.class);
+ Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+
+ // set expectations
+ injector.injectMembers(capture(controllerCapture));
+ expect(injector.getInstance(Gson.class)).andReturn(null);
+
+ //replay
+ replay(injector);
+
+
+ AmbariManagementControllerImpl controller = new AmbariManagementControllerImpl(null, null, injector);
+
+ class AmbariConfigsSetter{
+ public void setConfigs(AmbariManagementController controller, String masterProtocol, String masterHostname, Integer masterPort) throws Exception{
+ // masterProtocol
+ Class<?> c = controller.getClass();
+ Field f = c.getDeclaredField("masterProtocol");
+ f.setAccessible(true);
+
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
+
+ f.set(controller, masterProtocol);
+
+ // masterHostname
+ f = c.getDeclaredField("masterHostname");
+ f.setAccessible(true);
+
+ modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
+
+ f.set(controller, masterHostname);
+
+ // masterPort
+ f = c.getDeclaredField("masterPort");
+ f.setAccessible(true);
+
+ modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
+
+ f.set(controller, masterPort);
+ }
+ }
+
+ AmbariConfigsSetter ambariConfigsSetter = new AmbariConfigsSetter();
+
+ ambariConfigsSetter.setConfigs(controller, "http", "hostname", 8080);
+ assertEquals("http://hostname:8080/jdk_path", controller.getAmbariServerURI("/jdk_path"));
+
+ ambariConfigsSetter.setConfigs(controller, "https", "somesecuredhost", 8443);
+ assertEquals("https://somesecuredhost:8443/mysql_path", controller.getAmbariServerURI("/mysql_path"));
+ ambariConfigsSetter.setConfigs(controller, "https", "othersecuredhost", 8443);
+ assertEquals("https://othersecuredhost:8443/oracle/ojdbc/", controller.getAmbariServerURI("/oracle/ojdbc/"));
+
+ verify(injector);
+ }
+
@Test
public void testGetClusters() throws Exception {
// member state mocks
@@ -1513,7 +1579,7 @@ public class AmbariManagementControllerImplTest {
protected void configure() {
Properties properties = new Properties();
properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, "in-memory");
-
+
properties.setProperty(Configuration.METADETA_DIR_PATH,
"src/main/resources/stacks");
properties.setProperty(Configuration.SERVER_VERSION_FILE,