atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From suma...@apache.org
Subject [1/2] incubator-atlas git commit: ATLAS-571 Modify Atlas client for necessary changes in context of HA (yhemanth via sumasai)
Date Tue, 05 Apr 2016 00:16:13 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master c1d4e7c9c -> 98f4d40a1


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/98f4d40a/server-api/src/main/test/org/apache/atlas/ha/AtlasServerIdSelectorTest.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/test/org/apache/atlas/ha/AtlasServerIdSelectorTest.java b/server-api/src/main/test/org/apache/atlas/ha/AtlasServerIdSelectorTest.java
new file mode 100644
index 0000000..3321ce4
--- /dev/null
+++ b/server-api/src/main/test/org/apache/atlas/ha/AtlasServerIdSelectorTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.atlas.ha;
+
+import org.apache.atlas.AtlasConstants;
+import org.apache.atlas.AtlasException;
+import org.apache.commons.configuration.Configuration;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
+
+public class AtlasServerIdSelectorTest {
+    @Mock
+    private Configuration configuration;
+
+    @BeforeMethod
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        System.setProperty(AtlasConstants.SYSTEM_PROPERTY_APP_PORT, AtlasConstants.DEFAULT_APP_PORT_STR);
+    }
+
+    @Test
+    public void testShouldSelectRightServerAddress() throws AtlasException {
+        when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new
String[] {"id1", "id2"});
+        when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn("127.0.0.1:31000");
+        when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id2")).thenReturn("127.0.0.1:21000");
+
+        String atlasServerId = AtlasServerIdSelector.selectServerId(configuration);
+        assertEquals(atlasServerId, "id2");
+    }
+
+    @Test(expectedExceptions = AtlasException.class)
+    public void testShouldFailIfNoIDsConfiguration() throws AtlasException {
+        when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new
String[] {});
+        AtlasServerIdSelector.selectServerId(configuration);
+        fail("Should not return any server id if IDs not found in configuration");
+    }
+
+    @Test(expectedExceptions = AtlasException.class)
+    public void testShouldFailIfNoMatchingAddressForID() throws AtlasException {
+        when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new
String[] {"id1", "id2"});
+        when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn("127.0.0.1:31000");
+
+        AtlasServerIdSelector.selectServerId(configuration);
+        fail("Should not return any server id if no matching address found for any ID");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/98f4d40a/server-api/src/main/test/org/apache/atlas/ha/HAConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/test/org/apache/atlas/ha/HAConfigurationTest.java b/server-api/src/main/test/org/apache/atlas/ha/HAConfigurationTest.java
deleted file mode 100644
index a7c9f37..0000000
--- a/server-api/src/main/test/org/apache/atlas/ha/HAConfigurationTest.java
+++ /dev/null
@@ -1,90 +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.atlas.ha;
-
-import org.apache.atlas.AtlasConstants;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.security.SecurityProperties;
-import org.apache.commons.configuration.Configuration;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.fail;
-
-public class HAConfigurationTest {
-
-    @Mock
-    private Configuration configuration;
-
-    @BeforeMethod
-    public void setup() {
-        MockitoAnnotations.initMocks(this);
-        System.setProperty(AtlasConstants.SYSTEM_PROPERTY_APP_PORT, AtlasConstants.DEFAULT_APP_PORT_STR);
-    }
-
-    @Test
-    public void testShouldSelectRightServerAddress() throws AtlasException {
-        when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new
String[] {"id1", "id2"});
-        when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn("127.0.0.1:31000");
-        when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id2")).thenReturn("127.0.0.1:21000");
-
-        String atlasServerId = HAConfiguration.getAtlasServerId(configuration);
-        assertEquals(atlasServerId, "id2");
-    }
-
-    @Test(expectedExceptions = AtlasException.class)
-    public void testShouldFailIfNoIDsConfiguration() throws AtlasException {
-        when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new
String[] {});
-        HAConfiguration.getAtlasServerId(configuration);
-        fail("Should not return any server id if IDs not found in configuration");
-    }
-
-    @Test(expectedExceptions = AtlasException.class)
-    public void testShouldFailIfNoMatchingAddressForID() throws AtlasException {
-        when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new
String[] {"id1", "id2"});
-        when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn("127.0.0.1:31000");
-
-        HAConfiguration.getAtlasServerId(configuration);
-        fail("Should not return any server id if no matching address found for any ID");
-    }
-
-    @Test
-    public void testShouldReturnHTTPBoundAddress() {
-        when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn("127.0.0.1:21000");
-        when(configuration.getBoolean(SecurityProperties.TLS_ENABLED)).thenReturn(false);
-
-        String address = HAConfiguration.getBoundAddressForId(configuration, "id1");
-
-        assertEquals(address, "http://127.0.0.1:21000");
-    }
-
-    @Test
-    public void testShouldReturnHTTPSBoundAddress() {
-        when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn("127.0.0.1:21443");
-        when(configuration.getBoolean(SecurityProperties.TLS_ENABLED)).thenReturn(true);
-
-        String address = HAConfiguration.getBoundAddressForId(configuration, "id1");
-
-        assertEquals(address, "https://127.0.0.1:21443");
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/98f4d40a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java b/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
index a2d7155..79b8124 100755
--- a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
+++ b/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java
@@ -113,7 +113,8 @@ public class QuickStart {
     private final AtlasClient metadataServiceClient;
 
     QuickStart(String baseUrl) {
-        metadataServiceClient = new AtlasClient(baseUrl);
+        String[] urls = baseUrl.split(",");
+        metadataServiceClient = new AtlasClient(null, null, urls);
     }
 
     void createTypes() throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/98f4d40a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
b/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
index 9d7db6d..8ee3db0 100644
--- a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
+++ b/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
@@ -23,6 +23,7 @@ import com.google.inject.Provider;
 import com.google.inject.Singleton;
 import org.apache.atlas.ApplicationProperties;
 import org.apache.atlas.AtlasException;
+import org.apache.atlas.ha.AtlasServerIdSelector;
 import org.apache.atlas.ha.HAConfiguration;
 import org.apache.atlas.listener.ActiveStateChangeHandler;
 import org.apache.atlas.service.Service;
@@ -101,7 +102,7 @@ public class ActiveInstanceElectorService implements Service, LeaderLatchListene
             return;
         }
         cacheActiveStateChangeHandlers();
-        serverId = HAConfiguration.getAtlasServerId(configuration);
+        serverId = AtlasServerIdSelector.selectServerId(configuration);
         joinElection();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/98f4d40a/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java b/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java
index 0bee340..052deba 100644
--- a/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java
+++ b/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java
@@ -85,7 +85,7 @@ public class CuratorFactory {
      * Create a new instance {@link LeaderLatch}
      * @param serverId the ID used to register this instance with curator.
      *                 This ID should typically be obtained using
-     *                 {@link HAConfiguration#getAtlasServerId(Configuration)}
+     *                 {@link org.apache.atlas.ha.AtlasServerIdSelector#selectServerId(Configuration)}
      * @return
      */
     public LeaderLatch leaderLatchInstance(String serverId) {

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/98f4d40a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java
b/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java
index 07802fa..9aac32a 100755
--- a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java
@@ -86,7 +86,7 @@ public class NegativeSSLAndKerberosTest extends BaseSSLAndKerberosTest {
 
         dgiClient = new AtlasClient(DGI_URL) {
             @Override
-            protected PropertiesConfiguration getClientProperties() throws AtlasException
{
+            protected PropertiesConfiguration getClientProperties() {
                 return configuration;
             }
         };

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/98f4d40a/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java b/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java
index a3b3a3c..2be52e7 100755
--- a/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/security/SSLAndKerberosTest.java
@@ -102,7 +102,7 @@ public class SSLAndKerberosTest extends BaseSSLAndKerberosTest {
             public AtlasClient run() throws Exception {
                 return new AtlasClient(DGI_URL) {
                     @Override
-                    protected PropertiesConfiguration getClientProperties() throws AtlasException
{
+                    protected PropertiesConfiguration getClientProperties() {
                         return configuration;
                     }
                 };

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/98f4d40a/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java b/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java
index 480861e..521c037 100755
--- a/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java
@@ -78,7 +78,7 @@ public class SSLTest extends BaseSSLAndKerberosTest {
 
         dgiCLient = new AtlasClient(DGI_URL) {
             @Override
-            protected PropertiesConfiguration getClientProperties() throws AtlasException
{
+            protected PropertiesConfiguration getClientProperties() {
                 return configuration;
             }
         };


Mime
View raw message