-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for auth enabled Marathon #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,16 +38,23 @@ public class MarathonDiscoveryStrategy extends AbstractDiscoveryStrategy { | |
|
||
private int port; | ||
|
||
private String marathonUsername; | ||
|
||
private String marathonPassword; | ||
|
||
private ILogger logger; | ||
|
||
public MarathonDiscoveryStrategy(final ILogger logger, Map<String, Comparable> properties) { | ||
super(logger, properties); | ||
this.marathonEndpoint = getOrNull("discovery.marathon", MarathonDiscoveryConfiguration.MARATHON_ENDPOINT); | ||
this.appId = getOrNull("discovery.marathon", MarathonDiscoveryConfiguration.APP_ID); | ||
this.port = Integer.parseInt(getOrNull("discovery.marathon", MarathonDiscoveryConfiguration.PORT_INDEX)); | ||
this.marathonUsername = getOrNull("discovery.marathon", MarathonDiscoveryConfiguration.MARATHON_USERNAME); | ||
this.marathonPassword = getOrNull("discovery.marathon", MarathonDiscoveryConfiguration.MARATHON_PASSWORD); | ||
this.logger = logger; | ||
try { | ||
MarathonServiceDiscoveryHelper.start(marathonEndpoint, appId, port, logger); | ||
MarathonServiceDiscoveryHelper.start(marathonEndpoint, appId, port, marathonUsername, marathonPassword, | ||
logger); | ||
} catch (Exception e) { | ||
logger.severe("Failed to start service discovery!", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it ok to just log the exception? What is the client expectation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Service startup should not be impacted if marathon discovery fails so I guess that's why we are not rethrowing the Exception here. |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ public void testSingleMemberDiscovery() throws IOException, InterruptedException | |
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withBody(mapper.writeValueAsBytes(response)))); | ||
HazelcastInstance hazelcast = getHazelcastInstance(5701); | ||
HazelcastInstance hazelcast = getHazelcastInstanceWithoutBasicAuth(5701); | ||
assertTrue(hazelcast.getCluster().getMembers().size() > 0); | ||
hazelcast.shutdown(); | ||
} | ||
|
@@ -84,17 +84,28 @@ public void testMultiMemberDiscovery() throws UnknownHostException, InterruptedE | |
.withHeader("Content-Type", "application/json") | ||
.withBody(mapper.writeValueAsBytes(response)))); | ||
|
||
HazelcastInstance hazelcast1 = getHazelcastInstance(5701); | ||
HazelcastInstance hazelcast2 = getHazelcastInstance(5702); | ||
HazelcastInstance hazelcast3 = getHazelcastInstance(5703); | ||
HazelcastInstance hazelcast1 = getHazelcastInstanceWithoutBasicAuth(5701); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have test cases for both with and without auth There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, if you see here 87 and 88 line one's are Without Auth instances and 89th line one is With Auth. And in 91st line asserting that cluster members should be 3 |
||
HazelcastInstance hazelcast2 = getHazelcastInstanceWithoutBasicAuth(5702); | ||
HazelcastInstance hazelcast3 = getHazelcastInstanceWithBasicAuth(5703); | ||
assertTrue(hazelcast3.getCluster().getMembers().size() > 0); | ||
assertTrue(hazelcast3.getCluster().getMembers().size() == 3); | ||
hazelcast1.shutdown(); | ||
hazelcast2.shutdown(); | ||
hazelcast3.shutdown(); | ||
} | ||
|
||
private HazelcastInstance getHazelcastInstance(int port) throws UnknownHostException, InterruptedException { | ||
private HazelcastInstance getHazelcastInstanceWithoutBasicAuth(int port) | ||
throws UnknownHostException, InterruptedException { | ||
return getHazelcastInstance(port, false); | ||
} | ||
|
||
private HazelcastInstance getHazelcastInstanceWithBasicAuth(int port) | ||
throws UnknownHostException, InterruptedException { | ||
return getHazelcastInstance(port, true); | ||
} | ||
|
||
private HazelcastInstance getHazelcastInstance(int port, boolean withBasicAuthMarathon) | ||
throws UnknownHostException, InterruptedException { | ||
Config config = new Config(); | ||
config.setProperty("hazelcast.discovery.enabled", "true"); | ||
config.setProperty("hazelcast.discovery.public.ip.enabled", "true"); | ||
|
@@ -112,6 +123,10 @@ private HazelcastInstance getHazelcastInstance(int port) throws UnknownHostExcep | |
discoveryStrategyConfig.addProperty("marathon-endpoint", "http://localhost:8080"); | ||
discoveryStrategyConfig.addProperty("app-id", "test_app"); | ||
discoveryStrategyConfig.addProperty("port-index", "0"); | ||
if (withBasicAuthMarathon) { | ||
discoveryStrategyConfig.addProperty("marathon-username", "username"); | ||
discoveryStrategyConfig.addProperty("marathon-password", "password"); | ||
} | ||
discoveryConfig.addDiscoveryStrategyConfig(discoveryStrategyConfig); | ||
Thread.sleep(2000); | ||
return Hazelcast.newHazelcastInstance(config); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work if someone has upgraded the hazelcast marathon client but the marathon cluster isn't still not auth enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, if marathon username or password is null or empty we do not make auth based call inside the start method