Re: Java detector for mess masters and leader

2015-07-09 Thread Nikolaos Ballas neXus
Hi Adam,
all the code relating with hitting endpoints implies that you are aware of the 
cluster names/ip’s. In a really distributed environment I wouldn’t take that 
into account. I would discover the service from Zookeeper.
Nikolaos Ballas  |  Software Development Manager

Technology Nexus S.a.r.l.
2-4 Rue Eugene Rupert
2453 Luxembourg
Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
Tel: + 3522619113580
cont...@nexusgroup.com<mailto:contact...@nexusgroup.com> | 
nexusgroup.com<http://www.nexusgroup.com/>
LinkedIn.com<http://www.linkedin.com/company/nexus-technology> | 
Twitter<http://www.twitter.com/technologynexus> | 
Facebook.com<https://www.facebook.com/pages/Technology-Nexus/133756470003189>


[cid:19B646FC-B8E7-4F77-BBD3-75DD7B4B5BF7]

On 09 Jul 2015, at 07:19, Adam Bordelon 
mailto:a...@mesosphere.io>> wrote:

Sorry for showing up late to the party. Good answers so far. I just want to add 
that if you know any master, you can hit http:///master/redirect to 
get a 307 Temporary Redirect which you can unpack to find the leading master's 
hostname:port.

On Wed, Jul 8, 2015 at 10:59 AM, Nikolaos Ballas neXus 
mailto:nikolaos.bal...@nexusgroup.com>> wrote:
Great



Sent from my Samsung device


 Original message 
From: Donald Laidlaw mailto:donlaid...@me.com>>
Date: 08/07/2015 19:57 (GMT+01:00)
To: user@mesos.apache.org<mailto:user@mesos.apache.org>
Subject: Re: Java detector for mess masters and leader

@Nicolaos

Thanks for the offer. But I am almost finished writing what I outlined below. I 
am good to go.

Best regards,
-Don

On Jul 8, 2015, at 2:51 PM, Nikolaos Ballas neXus 
mailto:nikolaos.bal...@nexusgroup.com>> wrote:

I have code without curator if you want.I will send it to you that does exactly 
what you described



Sent from my Samsung device


 Original message 
From: Donald Laidlaw mailto:donlaid...@me.com>>
Date: 08/07/2015 19:49 (GMT+01:00)
To: user@mesos.apache.org<mailto:user@mesos.apache.org>
Subject: Re: Java detector for mess masters and leader

@ Nicolaos
I really don’t think that will work.

When you use this code, it creates a node under /mesos named like: 
_c_e7007a30-1eaf-4826-bb99-011e8a33ac111-lock-99 because it is gaining 
leadership. It does not create nodes like mesos does, with names like 
info_000123. It therefore does not play well with mesos.

I don’t think the Curator code matches the mesos code in exactly how it does 
leadership election.

I’ll just scan the mesos-created children of /mesos, they all begin with the 
string “info” and are ephemeral sequence nodes. Their contents contains the 
info I need, which I can parse using the mesos protocol buffer definition for 
MasterInfo. Although I think your substring method would work just as well. At 
least it will until 0.24 when the content is changed to a JSON string.

Best regards,
-Don


On Jul 8, 2015, at 11:49 AM, Ken Sipe 
mailto:kens...@gmail.com>> wrote:

awesome sharing of code!

I’ll add that if you are using Mesos-DNS, that the dns name master.mesos will 
resolve to the masters and leader.mesos will resolve to the leader.

if you are looking to resolve to marathon leader you would have to use the code 
below against zk at the moment.

- ken

On Jul 8, 2015, at 9:42 AM, Nikolaos Ballas neXus 
mailto:nikolaos.bal...@nexusgroup.com>> wrote:

Don…the bellow code will return leader node for mesos & marathon framework.

import …
public class SomeClass {
CuratorFramework client;
public void init(){
 client = CuratorFrameworkFactory.newClient(connectionString, new 
ExponentialBackoffRetry(1000, 3))
}
public String getMasterNodeIP(){
if(client!=null){

client.start();
LeaderSelectorListener listener = new LeaderSelectorListenerAdapter() {
public void takeLeadership(CuratorFramework client) throws 
Exception {
}
};

LeaderSelector selector = new LeaderSelector(client, path, listener);
selector.autoRequeue();
selector.start();

Participant participant = selector.getLeader();
String id = 
participant.getId().substring(participant.getId().indexOf("@") + 1, 
participant.getId().indexOf("*"));
masterNode.add(id);
}
} catch (Exception e) {
logger.error("Failed find out master node", e.getCause());
}

}
}
Nikolaos Ballas  |  Software Development Manager

Technology Nexus S.a.r.l.
2-4 Rue Eugene Rupert
2453 Luxembourg
Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
Tel: + 3522619113580
cont...@nexusgroup.com<mailto:contact...@nexusgroup.com> | 
nexusgroup.com<http://www.nexusgroup.com/>
LinkedIn.com<http://www.linkedin.com/company/nexus-technology> | 
Twitter<http://www.twitter.com/technologynexus> | 
Facebook.com<https://www.facebook.com/pages/Technology-Nexus/133756

Re: Java detector for mess masters and leader

2015-07-08 Thread Adam Bordelon
Sorry for showing up late to the party. Good answers so far. I just want to
add that if you know any master, you can hit
http:///master/redirect
to get a 307 Temporary Redirect which you can unpack to find the leading
master's hostname:port.

On Wed, Jul 8, 2015 at 10:59 AM, Nikolaos Ballas neXus <
nikolaos.bal...@nexusgroup.com> wrote:

>  Great
>
>
>
>  Sent from my Samsung device
>
>
>  Original message 
> From: Donald Laidlaw 
> Date: 08/07/2015 19:57 (GMT+01:00)
> To: user@mesos.apache.org
> Subject: Re: Java detector for mess masters and leader
>
> @Nicolaos
>
>  Thanks for the offer. But I am almost finished writing what I outlined
> below. I am good to go.
>
>  Best regards,
> -Don
>
>  On Jul 8, 2015, at 2:51 PM, Nikolaos Ballas neXus <
> nikolaos.bal...@nexusgroup.com> wrote:
>
>  I have code without curator if you want.I will send it to you that does
> exactly what you described
>
>
>
>  Sent from my Samsung device
>
>
>  Original message ----
> From: Donald Laidlaw 
> Date: 08/07/2015 19:49 (GMT+01:00)
> To: user@mesos.apache.org
> Subject: Re: Java detector for mess masters and leader
>
>  @ Nicolaos
> I really don’t think that will work.
>
>  When you use this code, it creates a node under /mesos named like:
> _c_e7007a30-1eaf-4826-bb99-011e8a33ac111-lock-99 because it is
> gaining leadership. It does not create nodes like mesos does, with names
> like info_000123. It therefore does not play well with mesos.
>
>  I don’t think the Curator code matches the mesos code in exactly how it
> does leadership election.
>
>  I’ll just scan the mesos-created children of /mesos, they all begin with
> the string “info” and are ephemeral sequence nodes. Their contents contains
> the info I need, which I can parse using the mesos protocol buffer
> definition for MasterInfo. Although I think your substring method would
> work just as well. At least it will until 0.24 when the content is changed
> to a JSON string.
>
>  Best regards,
> -Don
>
>
>  On Jul 8, 2015, at 11:49 AM, Ken Sipe  wrote:
>
>  awesome sharing of code!
>
>  I’ll add that if you are using Mesos-DNS, that the dns name master.mesos
> will resolve to the masters and leader.mesos will resolve to the leader.
>
>  if you are looking to resolve to marathon leader you would have to use
> the code below against zk at the moment.
>
>  - ken
>
>  On Jul 8, 2015, at 9:42 AM, Nikolaos Ballas neXus <
> nikolaos.bal...@nexusgroup.com> wrote:
>
>  Don…the bellow code will return leader node for mesos & marathon
> framework.
>
>  import …
> public class SomeClass {
> CuratorFramework client;
> public void init(){
>  client = CuratorFrameworkFactory.newClient(connectionString, new
> ExponentialBackoffRetry(1000, 3))
> }
> public String getMasterNodeIP(){
> if(client!=null){
>
> client.start();
> LeaderSelectorListener listener = new LeaderSelectorListenerAdapter() 
> {
> public void takeLeadership(CuratorFramework client) throws 
> Exception {
> }
> };
>
> LeaderSelector selector = new LeaderSelector(client, path, listener);
> selector.autoRequeue();
> selector.start();
>
> Participant participant = selector.getLeader();
> String id = 
> participant.getId().substring(participant.getId().indexOf("@") + 1, 
> participant.getId().indexOf("*"));
> masterNode.add(id);
> }
> } catch (Exception e) {
> logger.error("Failed find out master node", e.getCause());
> }
>
>
>  }
> }
>   *Nikolaos Ballas*  |  Software Development Manager
>
>  Technology Nexus S.a.r.l.
>  2-4 Rue Eugene Rupert
>  2453 Luxembourg
>  Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
>  Tel: + 3522619113580
>  cont...@nexusgroup.com  | nexusgroup.com
> <http://www.nexusgroup.com/>
>  *LinkedIn.com <http://www.linkedin.com/company/nexus-technology>* | *Twitter
> <http://www.twitter.com/technologynexus>* | *Facebook.com
> <https://www.facebook.com/pages/Technology-Nexus/133756470003189>*
>
>
> 
>
>  On 08 Jul 2015, at 16:27, Donald Laidlaw  wrote:
>
> @Nikolaos Ballas neXus
> I can see no way to instantiate the Curator LeaderSelector without
> actually becoming a participant in leader election. If I do instantiate
> that class, it does not accept a null value for the LeaderSelectorListener
> and so anything instantiating LeaderSelector must also become a participant.
>
> Even then, that class provides no way to listen for 

RE: Java detector for mess masters and leader

2015-07-08 Thread Nikolaos Ballas neXus
Great



Sent from my Samsung device


 Original message 
From: Donald Laidlaw 
Date: 08/07/2015 19:57 (GMT+01:00)
To: user@mesos.apache.org
Subject: Re: Java detector for mess masters and leader

@Nicolaos

Thanks for the offer. But I am almost finished writing what I outlined below. I 
am good to go.

Best regards,
-Don

On Jul 8, 2015, at 2:51 PM, Nikolaos Ballas neXus 
mailto:nikolaos.bal...@nexusgroup.com>> wrote:

I have code without curator if you want.I will send it to you that does exactly 
what you described



Sent from my Samsung device


 Original message 
From: Donald Laidlaw mailto:donlaid...@me.com>>
Date: 08/07/2015 19:49 (GMT+01:00)
To: user@mesos.apache.org<mailto:user@mesos.apache.org>
Subject: Re: Java detector for mess masters and leader

@ Nicolaos
I really don't think that will work.

When you use this code, it creates a node under /mesos named like: 
_c_e7007a30-1eaf-4826-bb99-011e8a33ac111-lock-99 because it is gaining 
leadership. It does not create nodes like mesos does, with names like 
info_000123. It therefore does not play well with mesos.

I don't think the Curator code matches the mesos code in exactly how it does 
leadership election.

I'll just scan the mesos-created children of /mesos, they all begin with the 
string "info" and are ephemeral sequence nodes. Their contents contains the 
info I need, which I can parse using the mesos protocol buffer definition for 
MasterInfo. Although I think your substring method would work just as well. At 
least it will until 0.24 when the content is changed to a JSON string.

Best regards,
-Don


On Jul 8, 2015, at 11:49 AM, Ken Sipe 
mailto:kens...@gmail.com>> wrote:

awesome sharing of code!

I'll add that if you are using Mesos-DNS, that the dns name master.mesos will 
resolve to the masters and leader.mesos will resolve to the leader.

if you are looking to resolve to marathon leader you would have to use the code 
below against zk at the moment.

- ken

On Jul 8, 2015, at 9:42 AM, Nikolaos Ballas neXus 
mailto:nikolaos.bal...@nexusgroup.com>> wrote:

Don...the bellow code will return leader node for mesos & marathon framework.

import ...
public class SomeClass {
CuratorFramework client;
public void init(){
 client = CuratorFrameworkFactory.newClient(connectionString, new 
ExponentialBackoffRetry(1000, 3))
}
public String getMasterNodeIP(){
if(client!=null){

client.start();
LeaderSelectorListener listener = new LeaderSelectorListenerAdapter() {
public void takeLeadership(CuratorFramework client) throws 
Exception {
}
};

LeaderSelector selector = new LeaderSelector(client, path, listener);
selector.autoRequeue();
selector.start();

Participant participant = selector.getLeader();
String id = 
participant.getId().substring(participant.getId().indexOf("@") + 1, 
participant.getId().indexOf("*"));
masterNode.add(id);
}
} catch (Exception e) {
logger.error("Failed find out master node", e.getCause());
}

}
}
Nikolaos Ballas  |  Software Development Manager

Technology Nexus S.a.r.l.
2-4 Rue Eugene Rupert
2453 Luxembourg
Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
Tel: + 3522619113580
cont...@nexusgroup.com<mailto:contact...@nexusgroup.com> | 
nexusgroup.com<http://www.nexusgroup.com/>
LinkedIn.com<http://www.linkedin.com/company/nexus-technology> | 
Twitter<http://www.twitter.com/technologynexus> | 
Facebook.com<https://www.facebook.com/pages/Technology-Nexus/133756470003189>




On 08 Jul 2015, at 16:27, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:

@Nikolaos Ballas neXus
I can see no way to instantiate the Curator LeaderSelector without actually 
becoming a participant in leader election. If I do instantiate that class, it 
does not accept a null value for the LeaderSelectorListener and so anything 
instantiating LeaderSelector must also become a participant.

Even then, that class provides no way to listen for leadership change. The only 
listening it does is to discover when it itself becomes the leader. I suppose 
it would be possible to participate in the leadership election, but immediately 
relinquish leadership causing a real mesos master to become the leader, but 
that seems a little too invasive to do.

The only solution I can see is to monitor the children of the mesos leader 
node, and parse through the contents of the ones whose name begins with "info" 
as per @Marco Massenzio.

Best regards,
-Don

On Jul 7, 2015, at 12:16 PM, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:

Thank you all.

I will use the Curator recipe, since I already use Curator for a bunch of other 
things.

If curator can find the leader and the participants that is good enough. 
Otherwise I will parse th

Re: Java detector for mess masters and leader

2015-07-08 Thread Donald Laidlaw
@Nicolaos

Thanks for the offer. But I am almost finished writing what I outlined below. I 
am good to go.

Best regards,
-Don

> On Jul 8, 2015, at 2:51 PM, Nikolaos Ballas neXus 
>  wrote:
> 
> I have code without curator if you want.I will send it to you that does 
> exactly what you described 
> 
> 
> 
> Sent from my Samsung device
> 
> 
>  Original message 
> From: Donald Laidlaw  
> Date: 08/07/2015 19:49 (GMT+01:00) 
> To: user@mesos.apache.org 
> Subject: Re: Java detector for mess masters and leader 
> 
> @ Nicolaos
> I really don’t think that will work.
> 
> When you use this code, it creates a node under /mesos named like: 
> _c_e7007a30-1eaf-4826-bb99-011e8a33ac111-lock-99 because it is 
> gaining leadership. It does not create nodes like mesos does, with names like 
> info_000123. It therefore does not play well with mesos.
> 
> I don’t think the Curator code matches the mesos code in exactly how it does 
> leadership election.
> 
> I’ll just scan the mesos-created children of /mesos, they all begin with the 
> string “info” and are ephemeral sequence nodes. Their contents contains the 
> info I need, which I can parse using the mesos protocol buffer definition for 
> MasterInfo. Although I think your substring method would work just as well. 
> At least it will until 0.24 when the content is changed to a JSON string.
> 
> Best regards,
> -Don
> 
> 
>> On Jul 8, 2015, at 11:49 AM, Ken Sipe > <mailto:kens...@gmail.com>> wrote:
>> 
>> awesome sharing of code!
>> 
>> I’ll add that if you are using Mesos-DNS, that the dns name master.mesos 
>> will resolve to the masters and leader.mesos will resolve to the leader.
>> 
>> if you are looking to resolve to marathon leader you would have to use the 
>> code below against zk at the moment.
>> 
>> - ken
>> 
>>> On Jul 8, 2015, at 9:42 AM, Nikolaos Ballas neXus 
>>> mailto:nikolaos.bal...@nexusgroup.com>> 
>>> wrote:
>>> 
>>> Don…the bellow code will return leader node for mesos & marathon framework.
>>> 
>>> import …
>>> public class SomeClass {
>>> CuratorFramework client;
>>> public void init(){
>>>  client = CuratorFrameworkFactory.newClient(connectionString, new 
>>> ExponentialBackoffRetry(1000, 3))
>>> }
>>> public String getMasterNodeIP(){
>>> if(client!=null){
>>> client.start();
>>> LeaderSelectorListener listener = new 
>>> LeaderSelectorListenerAdapter() {
>>> public void takeLeadership(CuratorFramework client) throws 
>>> Exception {
>>> }
>>> };
>>> 
>>> LeaderSelector selector = new LeaderSelector(client, path, 
>>> listener);
>>> selector.autoRequeue();
>>> selector.start();
>>> 
>>> Participant participant = selector.getLeader();
>>> String id = 
>>> participant.getId().substring(participant.getId().indexOf("@") + 1, 
>>> participant.getId().indexOf("*"));
>>> masterNode.add(id);
>>> }
>>> } catch (Exception e) {
>>> logger.error("Failed find out master node", e.getCause());
>>> }
>>> 
>>> }
>>> }
>>> Nikolaos Ballas  |  Software Development Manager 
>>> 
>>> Technology Nexus S.a.r.l.
>>> 2-4 Rue Eugene Rupert
>>> 2453 Luxembourg
>>> Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
>>> Tel: + 3522619113580
>>> cont...@nexusgroup.com <mailto:contact...@nexusgroup.com> | nexusgroup.com 
>>> <http://www.nexusgroup.com/> 
>>> LinkedIn.com <http://www.linkedin.com/company/nexus-technology> | Twitter 
>>> <http://www.twitter.com/technologynexus> | Facebook.com 
>>> <https://www.facebook.com/pages/Technology-Nexus/133756470003189>
>>> 
>>> 
>>> 
>>> 
>>>> On 08 Jul 2015, at 16:27, Donald Laidlaw >>> <mailto:donlaid...@me.com>> wrote:
>>>> 
>>>> @Nikolaos Ballas neXus
>>>> I can see no way to instantiate the Curator LeaderSelector without 
>>>> actually becoming a participant in leader election. If I do instantiate 
>>>> that class, it does not accept a null value for the LeaderSelectorListener 
>>>> and so anything instantiating LeaderSelector must also become a 
>>>> participant.
>>>> 
>&g

RE: Java detector for mess masters and leader

2015-07-08 Thread Nikolaos Ballas neXus
I have code without curator if you want.I will send it to you that does exactly 
what you described



Sent from my Samsung device


 Original message 
From: Donald Laidlaw 
Date: 08/07/2015 19:49 (GMT+01:00)
To: user@mesos.apache.org
Subject: Re: Java detector for mess masters and leader

@ Nicolaos
I really don't think that will work.

When you use this code, it creates a node under /mesos named like: 
_c_e7007a30-1eaf-4826-bb99-011e8a33ac111-lock-99 because it is gaining 
leadership. It does not create nodes like mesos does, with names like 
info_000123. It therefore does not play well with mesos.

I don't think the Curator code matches the mesos code in exactly how it does 
leadership election.

I'll just scan the mesos-created children of /mesos, they all begin with the 
string "info" and are ephemeral sequence nodes. Their contents contains the 
info I need, which I can parse using the mesos protocol buffer definition for 
MasterInfo. Although I think your substring method would work just as well. At 
least it will until 0.24 when the content is changed to a JSON string.

Best regards,
-Don


On Jul 8, 2015, at 11:49 AM, Ken Sipe 
mailto:kens...@gmail.com>> wrote:

awesome sharing of code!

I'll add that if you are using Mesos-DNS, that the dns name master.mesos will 
resolve to the masters and leader.mesos will resolve to the leader.

if you are looking to resolve to marathon leader you would have to use the code 
below against zk at the moment.

- ken

On Jul 8, 2015, at 9:42 AM, Nikolaos Ballas neXus 
mailto:nikolaos.bal...@nexusgroup.com>> wrote:

Don...the bellow code will return leader node for mesos & marathon framework.

import ...
public class SomeClass {
CuratorFramework client;
public void init(){
 client = CuratorFrameworkFactory.newClient(connectionString, new 
ExponentialBackoffRetry(1000, 3))
}
public String getMasterNodeIP(){
if(client!=null){

client.start();
LeaderSelectorListener listener = new LeaderSelectorListenerAdapter() {
public void takeLeadership(CuratorFramework client) throws 
Exception {
}
};

LeaderSelector selector = new LeaderSelector(client, path, listener);
selector.autoRequeue();
selector.start();

Participant participant = selector.getLeader();
String id = 
participant.getId().substring(participant.getId().indexOf("@") + 1, 
participant.getId().indexOf("*"));
masterNode.add(id);
}
} catch (Exception e) {
logger.error("Failed find out master node", e.getCause());
}

}
}
Nikolaos Ballas  |  Software Development Manager

Technology Nexus S.a.r.l.
2-4 Rue Eugene Rupert
2453 Luxembourg
Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
Tel: + 3522619113580
cont...@nexusgroup.com<mailto:contact...@nexusgroup.com> | 
nexusgroup.com<http://www.nexusgroup.com/>
LinkedIn.com<http://www.linkedin.com/company/nexus-technology> | 
Twitter<http://www.twitter.com/technologynexus> | 
Facebook.com<https://www.facebook.com/pages/Technology-Nexus/133756470003189>




On 08 Jul 2015, at 16:27, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:

@Nikolaos Ballas neXus
I can see no way to instantiate the Curator LeaderSelector without actually 
becoming a participant in leader election. If I do instantiate that class, it 
does not accept a null value for the LeaderSelectorListener and so anything 
instantiating LeaderSelector must also become a participant.

Even then, that class provides no way to listen for leadership change. The only 
listening it does is to discover when it itself becomes the leader. I suppose 
it would be possible to participate in the leadership election, but immediately 
relinquish leadership causing a real mesos master to become the leader, but 
that seems a little too invasive to do.

The only solution I can see is to monitor the children of the mesos leader 
node, and parse through the contents of the ones whose name begins with "info" 
as per @Marco Massenzio.

Best regards,
-Don

On Jul 7, 2015, at 12:16 PM, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:

Thank you all.

I will use the Curator recipe, since I already use Curator for a bunch of other 
things.

If curator can find the leader and the participants that is good enough. 
Otherwise I will parse the protocol buffer contents, and provide a way to parse 
the future son contents when that happens.

I'll reply again with the results of using the Curator recipe to get the leader 
and participants.

Best regards,
-Don

On Jul 7, 2015, at 11:04 AM, Dick Davies 
mailto:d...@hellooperator.net>> wrote:

The active master has a flag set in  /metrics/snapshot  :
"master/elected" which is 1 for the active
master and 0 otherwise, so it's easy enough to only load the metrics
from the

Re: Java detector for mess masters and leader

2015-07-08 Thread Donald Laidlaw
@ Nicolaos
I really don’t think that will work.

When you use this code, it creates a node under /mesos named like: 
_c_e7007a30-1eaf-4826-bb99-011e8a33ac111-lock-99 because it is gaining 
leadership. It does not create nodes like mesos does, with names like 
info_000123. It therefore does not play well with mesos.

I don’t think the Curator code matches the mesos code in exactly how it does 
leadership election.

I’ll just scan the mesos-created children of /mesos, they all begin with the 
string “info” and are ephemeral sequence nodes. Their contents contains the 
info I need, which I can parse using the mesos protocol buffer definition for 
MasterInfo. Although I think your substring method would work just as well. At 
least it will until 0.24 when the content is changed to a JSON string.

Best regards,
-Don


> On Jul 8, 2015, at 11:49 AM, Ken Sipe  wrote:
> 
> awesome sharing of code!
> 
> I’ll add that if you are using Mesos-DNS, that the dns name master.mesos will 
> resolve to the masters and leader.mesos will resolve to the leader.
> 
> if you are looking to resolve to marathon leader you would have to use the 
> code below against zk at the moment.
> 
> - ken
> 
>> On Jul 8, 2015, at 9:42 AM, Nikolaos Ballas neXus 
>> mailto:nikolaos.bal...@nexusgroup.com>> 
>> wrote:
>> 
>> Don…the bellow code will return leader node for mesos & marathon framework.
>> 
>> import …
>> public class SomeClass {
>> CuratorFramework client;
>> public void init(){
>>  client = CuratorFrameworkFactory.newClient(connectionString, new 
>> ExponentialBackoffRetry(1000, 3))
>> }
>> public String getMasterNodeIP(){
>> if(client!=null){
>> client.start();
>> LeaderSelectorListener listener = new 
>> LeaderSelectorListenerAdapter() {
>> public void takeLeadership(CuratorFramework client) throws 
>> Exception {
>> }
>> };
>> 
>> LeaderSelector selector = new LeaderSelector(client, path, listener);
>> selector.autoRequeue();
>> selector.start();
>> 
>> Participant participant = selector.getLeader();
>> String id = 
>> participant.getId().substring(participant.getId().indexOf("@") + 1, 
>> participant.getId().indexOf("*"));
>> masterNode.add(id);
>> }
>> } catch (Exception e) {
>> logger.error("Failed find out master node", e.getCause());
>> }
>> 
>> }
>> }
>> Nikolaos Ballas  |  Software Development Manager 
>> 
>> Technology Nexus S.a.r.l.
>> 2-4 Rue Eugene Rupert
>> 2453 Luxembourg
>> Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
>> Tel: + 3522619113580
>> cont...@nexusgroup.com  | nexusgroup.com 
>>  
>> LinkedIn.com  | Twitter 
>>  | Facebook.com 
>> 
>> 
>> 
>> 
>> 
>>> On 08 Jul 2015, at 16:27, Donald Laidlaw >> > wrote:
>>> 
>>> @Nikolaos Ballas neXus
>>> I can see no way to instantiate the Curator LeaderSelector without actually 
>>> becoming a participant in leader election. If I do instantiate that class, 
>>> it does not accept a null value for the LeaderSelectorListener and so 
>>> anything instantiating LeaderSelector must also become a participant.
>>> 
>>> Even then, that class provides no way to listen for leadership change. The 
>>> only listening it does is to discover when it itself becomes the leader. I 
>>> suppose it would be possible to participate in the leadership election, but 
>>> immediately relinquish leadership causing a real mesos master to become the 
>>> leader, but that seems a little too invasive to do.
>>> 
>>> The only solution I can see is to monitor the children of the mesos leader 
>>> node, and parse through the contents of the ones whose name begins with 
>>> “info” as per @Marco Massenzio.
>>> 
>>> Best regards,
>>> -Don
>>> 
 On Jul 7, 2015, at 12:16 PM, Donald Laidlaw >>> > wrote:
 
 Thank you all.
 
 I will use the Curator recipe, since I already use Curator for a bunch of 
 other things. 
 
 If curator can find the leader and the participants that is good enough. 
 Otherwise I will parse the protocol buffer contents, and provide a way to 
 parse the future son contents when that happens.
 
 I’ll reply again with the results of using the Curator recipe to get the 
 leader and participants.
 
 Best regards,
 -Don
 
> On Jul 7, 2015, at 11:04 AM, Dick Davies  > wrote:
> 
> The active master has a flag set in  /metrics/snapshot  :
> "master/elected" which is 1 for the active
> master and 0 otherwise, so it's easy enough to only load the metrics
> from the active master.
> 
> (I use the collectd plugin and push data rather than poll, 

Re: Java detector for mess masters and leader

2015-07-08 Thread Ken Sipe
awesome sharing of code!

I’ll add that if you are using Mesos-DNS, that the dns name master.mesos will 
resolve to the masters and leader.mesos will resolve to the leader.

if you are looking to resolve to marathon leader you would have to use the code 
below against zk at the moment.

- ken

> On Jul 8, 2015, at 9:42 AM, Nikolaos Ballas neXus 
>  wrote:
> 
> Don…the bellow code will return leader node for mesos & marathon framework.
> 
> import …
> public class SomeClass {
> CuratorFramework client;
> public void init(){
>  client = CuratorFrameworkFactory.newClient(connectionString, new 
> ExponentialBackoffRetry(1000, 3))
> }
> public String getMasterNodeIP(){
> if(client!=null){
> client.start();
> LeaderSelectorListener listener = new LeaderSelectorListenerAdapter() 
> {
> public void takeLeadership(CuratorFramework client) throws 
> Exception {
> }
> };
> 
> LeaderSelector selector = new LeaderSelector(client, path, listener);
> selector.autoRequeue();
> selector.start();
> 
> Participant participant = selector.getLeader();
> String id = 
> participant.getId().substring(participant.getId().indexOf("@") + 1, 
> participant.getId().indexOf("*"));
> masterNode.add(id);
> }
> } catch (Exception e) {
> logger.error("Failed find out master node", e.getCause());
> }
> 
> }
> }
> Nikolaos Ballas  |  Software Development Manager 
> 
> Technology Nexus S.a.r.l.
> 2-4 Rue Eugene Rupert
> 2453 Luxembourg
> Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
> Tel: + 3522619113580
> cont...@nexusgroup.com  | nexusgroup.com 
>  
> LinkedIn.com  | Twitter 
>  | Facebook.com 
> 
> 
> 
> 
> 
>> On 08 Jul 2015, at 16:27, Donald Laidlaw > > wrote:
>> 
>> @Nikolaos Ballas neXus
>> I can see no way to instantiate the Curator LeaderSelector without actually 
>> becoming a participant in leader election. If I do instantiate that class, 
>> it does not accept a null value for the LeaderSelectorListener and so 
>> anything instantiating LeaderSelector must also become a participant.
>> 
>> Even then, that class provides no way to listen for leadership change. The 
>> only listening it does is to discover when it itself becomes the leader. I 
>> suppose it would be possible to participate in the leadership election, but 
>> immediately relinquish leadership causing a real mesos master to become the 
>> leader, but that seems a little too invasive to do.
>> 
>> The only solution I can see is to monitor the children of the mesos leader 
>> node, and parse through the contents of the ones whose name begins with 
>> “info” as per @Marco Massenzio.
>> 
>> Best regards,
>> -Don
>> 
>>> On Jul 7, 2015, at 12:16 PM, Donald Laidlaw >> > wrote:
>>> 
>>> Thank you all.
>>> 
>>> I will use the Curator recipe, since I already use Curator for a bunch of 
>>> other things. 
>>> 
>>> If curator can find the leader and the participants that is good enough. 
>>> Otherwise I will parse the protocol buffer contents, and provide a way to 
>>> parse the future son contents when that happens.
>>> 
>>> I’ll reply again with the results of using the Curator recipe to get the 
>>> leader and participants.
>>> 
>>> Best regards,
>>> -Don
>>> 
 On Jul 7, 2015, at 11:04 AM, Dick Davies >>> > wrote:
 
 The active master has a flag set in  /metrics/snapshot  :
 "master/elected" which is 1 for the active
 master and 0 otherwise, so it's easy enough to only load the metrics
 from the active master.
 
 (I use the collectd plugin and push data rather than poll, but the
 same principle should apply).
 
 On 7 July 2015 at 14:02, Donald Laidlaw >>> > wrote:
> Has anyone ever developed Java code to detect the mesos masters and 
> leader, given a zookeeper connection?
> 
> The reason I ask is because I would like to monitor mesos to report 
> various metrics reported by the master. This requires detecting and 
> tracking the leading master to query its /metrics/snapshot REST endpoint.
> 
> Thanks,
> -Don
>>> 
>> 
> 



Re: Java detector for mess masters and leader

2015-07-08 Thread Nikolaos Ballas neXus
Don…the bellow code will return leader node for mesos & marathon framework.

import …
public class SomeClass {
CuratorFramework client;
public void init(){
 client = CuratorFrameworkFactory.newClient(connectionString, new 
ExponentialBackoffRetry(1000, 3))
}
public String getMasterNodeIP(){
if(client!=null){

client.start();
LeaderSelectorListener listener = new LeaderSelectorListenerAdapter() {
public void takeLeadership(CuratorFramework client) throws 
Exception {
}
};

LeaderSelector selector = new LeaderSelector(client, path, listener);
selector.autoRequeue();
selector.start();

Participant participant = selector.getLeader();
String id = 
participant.getId().substring(participant.getId().indexOf("@") + 1, 
participant.getId().indexOf("*"));
masterNode.add(id);
}
} catch (Exception e) {
logger.error("Failed find out master node", e.getCause());
}

}
}
Nikolaos Ballas  |  Software Development Manager

Technology Nexus S.a.r.l.
2-4 Rue Eugene Rupert
2453 Luxembourg
Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
Tel: + 3522619113580
cont...@nexusgroup.com | 
nexusgroup.com
LinkedIn.com | 
Twitter | 
Facebook.com


[cid:19B646FC-B8E7-4F77-BBD3-75DD7B4B5BF7]

On 08 Jul 2015, at 16:27, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:

@Nikolaos Ballas neXus
I can see no way to instantiate the Curator LeaderSelector without actually 
becoming a participant in leader election. If I do instantiate that class, it 
does not accept a null value for the LeaderSelectorListener and so anything 
instantiating LeaderSelector must also become a participant.

Even then, that class provides no way to listen for leadership change. The only 
listening it does is to discover when it itself becomes the leader. I suppose 
it would be possible to participate in the leadership election, but immediately 
relinquish leadership causing a real mesos master to become the leader, but 
that seems a little too invasive to do.

The only solution I can see is to monitor the children of the mesos leader 
node, and parse through the contents of the ones whose name begins with “info” 
as per @Marco Massenzio.

Best regards,
-Don

On Jul 7, 2015, at 12:16 PM, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:

Thank you all.

I will use the Curator recipe, since I already use Curator for a bunch of other 
things.

If curator can find the leader and the participants that is good enough. 
Otherwise I will parse the protocol buffer contents, and provide a way to parse 
the future son contents when that happens.

I’ll reply again with the results of using the Curator recipe to get the leader 
and participants.

Best regards,
-Don

On Jul 7, 2015, at 11:04 AM, Dick Davies 
mailto:d...@hellooperator.net>> wrote:

The active master has a flag set in  /metrics/snapshot  :
"master/elected" which is 1 for the active
master and 0 otherwise, so it's easy enough to only load the metrics
from the active master.

(I use the collectd plugin and push data rather than poll, but the
same principle should apply).

On 7 July 2015 at 14:02, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:
Has anyone ever developed Java code to detect the mesos masters and leader, 
given a zookeeper connection?

The reason I ask is because I would like to monitor mesos to report various 
metrics reported by the master. This requires detecting and tracking the 
leading master to query its /metrics/snapshot REST endpoint.

Thanks,
-Don





Re: Java detector for mess masters and leader

2015-07-08 Thread Donald Laidlaw
@Nikolaos Ballas neXus
I can see no way to instantiate the Curator LeaderSelector without actually 
becoming a participant in leader election. If I do instantiate that class, it 
does not accept a null value for the LeaderSelectorListener and so anything 
instantiating LeaderSelector must also become a participant.

Even then, that class provides no way to listen for leadership change. The only 
listening it does is to discover when it itself becomes the leader. I suppose 
it would be possible to participate in the leadership election, but immediately 
relinquish leadership causing a real mesos master to become the leader, but 
that seems a little too invasive to do.

The only solution I can see is to monitor the children of the mesos leader 
node, and parse through the contents of the ones whose name begins with “info” 
as per @Marco Massenzio.

Best regards,
-Don

> On Jul 7, 2015, at 12:16 PM, Donald Laidlaw  wrote:
> 
> Thank you all.
> 
> I will use the Curator recipe, since I already use Curator for a bunch of 
> other things. 
> 
> If curator can find the leader and the participants that is good enough. 
> Otherwise I will parse the protocol buffer contents, and provide a way to 
> parse the future son contents when that happens.
> 
> I’ll reply again with the results of using the Curator recipe to get the 
> leader and participants.
> 
> Best regards,
> -Don
> 
>> On Jul 7, 2015, at 11:04 AM, Dick Davies  wrote:
>> 
>> The active master has a flag set in  /metrics/snapshot  :
>> "master/elected" which is 1 for the active
>> master and 0 otherwise, so it's easy enough to only load the metrics
>> from the active master.
>> 
>> (I use the collectd plugin and push data rather than poll, but the
>> same principle should apply).
>> 
>> On 7 July 2015 at 14:02, Donald Laidlaw  wrote:
>>> Has anyone ever developed Java code to detect the mesos masters and leader, 
>>> given a zookeeper connection?
>>> 
>>> The reason I ask is because I would like to monitor mesos to report various 
>>> metrics reported by the master. This requires detecting and tracking the 
>>> leading master to query its /metrics/snapshot REST endpoint.
>>> 
>>> Thanks,
>>> -Don
> 



Re: Java detector for mess masters and leader

2015-07-07 Thread Donald Laidlaw
Thank you all.

I will use the Curator recipe, since I already use Curator for a bunch of other 
things. 

If curator can find the leader and the participants that is good enough. 
Otherwise I will parse the protocol buffer contents, and provide a way to parse 
the future son contents when that happens.

I’ll reply again with the results of using the Curator recipe to get the leader 
and participants.

Best regards,
-Don

> On Jul 7, 2015, at 11:04 AM, Dick Davies  wrote:
> 
> The active master has a flag set in  /metrics/snapshot  :
> "master/elected" which is 1 for the active
> master and 0 otherwise, so it's easy enough to only load the metrics
> from the active master.
> 
> (I use the collectd plugin and push data rather than poll, but the
> same principle should apply).
> 
> On 7 July 2015 at 14:02, Donald Laidlaw  wrote:
>> Has anyone ever developed Java code to detect the mesos masters and leader, 
>> given a zookeeper connection?
>> 
>> The reason I ask is because I would like to monitor mesos to report various 
>> metrics reported by the master. This requires detecting and tracking the 
>> leading master to query its /metrics/snapshot REST endpoint.
>> 
>> Thanks,
>> -Don



Re: Java detector for mess masters and leader

2015-07-07 Thread Marco Massenzio
Hi Donald,

the information stored in the Zookeeper znode is a serialized Protocol
Buffer (see MasterInfo in mesos/mesos.proto
);
here is a brief explanation of what is in there, plus an example as to how
to retrieve that info (in Python - but Java would work pretty much the
same):
http://codetrips.com/2015/06/12/apache-mesos-leader-master-discovery-using-zookeeper/

Please be aware that, as of 0.24 (currently planned for mid-August), we
plan to publish that information *only* in JSON (exactly to help all the
folks like you) so the method presented there will no longer work (for all
intents and purposes, the serialized MasterInfo to ZK is considered
"deprecated" as of 0.23 which is going out any day now: we're currently
testing a RC).

Note that if you intend to "follow" the leader you will need to set a
"Watcher" on the node itself or, perhaps better, on the znode path, so as
to get a callback whenever anything changes: the elected leader will always
be the lowest-numbered ephemeral znode (I am guessing you know all this,
but feel free to ping me if you need more info).

Hope this helps.


*Marco Massenzio*
*Distributed Systems Engineer*

On Tue, Jul 7, 2015 at 6:02 AM, Donald Laidlaw  wrote:

> Has anyone ever developed Java code to detect the mesos masters and
> leader, given a zookeeper connection?
>
> The reason I ask is because I would like to monitor mesos to report
> various metrics reported by the master. This requires detecting and
> tracking the leading master to query its /metrics/snapshot REST endpoint.
>
> Thanks,
> -Don


Re: Java detector for mess masters and leader

2015-07-07 Thread Dick Davies
The active master has a flag set in  /metrics/snapshot  :
"master/elected" which is 1 for the active
master and 0 otherwise, so it's easy enough to only load the metrics
from the active master.

(I use the collectd plugin and push data rather than poll, but the
same principle should apply).

On 7 July 2015 at 14:02, Donald Laidlaw  wrote:
> Has anyone ever developed Java code to detect the mesos masters and leader, 
> given a zookeeper connection?
>
> The reason I ask is because I would like to monitor mesos to report various 
> metrics reported by the master. This requires detecting and tracking the 
> leading master to query its /metrics/snapshot REST endpoint.
>
> Thanks,
> -Don


Re: Java detector for mess masters and leader

2015-07-07 Thread Nikolaos Ballas neXus
The only downside to that approach is that you consider you have apriori 
knowledge of the ip’s of the master. But if you are doing that from an external 
application and the nodes goes up and down the same ip/master/state.json can’t 
be conceived as granted. I used to go down that path, but if you want more 
dynamic behaviour extracting this way the leader in my mind makes more sense. 
Still proposal 100% functional and working :) worked like that for several 
weeks :D

Nikolaos Ballas  |  Software Development Manager

Technology Nexus S.a.r.l.
2-4 Rue Eugene Rupert
2453 Luxembourg
Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
Tel: + 3522619113580
cont...@nexusgroup.com | 
nexusgroup.com
LinkedIn.com | 
Twitter | 
Facebook.com


[cid:19B646FC-B8E7-4F77-BBD3-75DD7B4B5BF7]

On 07 Jul 2015, at 15:20, Philippe Laflamme 
mailto:phili...@hopper.com>> wrote:

Querying for /master/state.json will provide you with the master. So you can 
query any one of the hosts in your list of potential masters, extract the 
master information from that and then hit your master on the endpoint you're 
interested in.

Philippe

On Tue, Jul 7, 2015 at 9:02 AM, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:
Has anyone ever developed Java code to detect the mesos masters and leader, 
given a zookeeper connection?

The reason I ask is because I would like to monitor mesos to report various 
metrics reported by the master. This requires detecting and tracking the 
leading master to query its /metrics/snapshot REST endpoint.

Thanks,
-Don




Re: Java detector for mess masters and leader

2015-07-07 Thread Philippe Laflamme
Querying for /master/state.json will provide you with the master. So you
can query any one of the hosts in your list of potential masters, extract
the master information from that and then hit your master on the endpoint
you're interested in.

Philippe

On Tue, Jul 7, 2015 at 9:02 AM, Donald Laidlaw  wrote:

> Has anyone ever developed Java code to detect the mesos masters and
> leader, given a zookeeper connection?
>
> The reason I ask is because I would like to monitor mesos to report
> various metrics reported by the master. This requires detecting and
> tracking the leading master to query its /metrics/snapshot REST endpoint.
>
> Thanks,
> -Don


Re: Java detector for mess masters and leader

2015-07-07 Thread Nikolaos Ballas neXus
Just not to forget,
you can use the native Zookeeper API but in that case you should be aware that 
detecting the leader is a bit tricky. You ask for getPath(“/mesos/“ , true) and 
then you iterate over the children again calling getPath(). The string object 
returned contains some timestamps and a string mesos@ip:5050*ip … this will 
return you the masters but not the leader. In order to discover the leader you 
should use the number after the first - on the string you will see(timestamp) 
and the smaller number is actually the leader.If I have understood correctly. 
You can check the equivalent code in apache mesos where this prefix is added in 
case the request for registration in the zookeeper takes place.Again it looks 
for string index of (mesos@).

kind regards
Nikolaos Ballas  |  Software Development Manager

Technology Nexus S.a.r.l.
2-4 Rue Eugene Rupert
2453 Luxembourg
Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
Tel: + 3522619113580
cont...@nexusgroup.com | 
nexusgroup.com
LinkedIn.com | 
Twitter | 
Facebook.com


[cid:19B646FC-B8E7-4F77-BBD3-75DD7B4B5BF7]

On 07 Jul 2015, at 15:02, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:

Has anyone ever developed Java code to detect the mesos masters and leader, 
given a zookeeper connection?

The reason I ask is because I would like to monitor mesos to report various 
metrics reported by the master. This requires detecting and tracking the 
leading master to query its /metrics/snapshot REST endpoint.

Thanks,
-Don



Re: Java detector for mess masters and leader

2015-07-07 Thread David Greenberg
You can check out Satellite: https://github.com/twosigma/satellite which is
a complete monitoring & metrics system for Mesos. It avoids the need to
snoop the ZK connection by instead discovering that info via the rest API.

On Tue, Jul 7, 2015 at 9:03 AM Donald Laidlaw  wrote:

> Has anyone ever developed Java code to detect the mesos masters and
> leader, given a zookeeper connection?
>
> The reason I ask is because I would like to monitor mesos to report
> various metrics reported by the master. This requires detecting and
> tracking the leading master to query its /metrics/snapshot REST endpoint.
>
> Thanks,
> -Don


Re: Java detector for mess masters and leader

2015-07-07 Thread Nikolaos Ballas neXus
Hi Don,
actually you can use Apache Curator, to create a connection to Zookeeper and 
then instantiate a LeaderSelector object. If you pass as path the path under 
which you mesos master nodes register for formaming an ensemble then the that 
object you can call getLeader() or getParticipants and that is a json object 
that has an attribute calls isLeader. The participant that has this set to true 
is the leader. To receive that for Marathon you must search for 
/marathon/leader again with the same notion. Also take into consideration with 
LeaderSelector you can be notified for changes of the cluster topology(failure 
of the leader and re election).

http://curator.apache.org

http://curator.apache.org/apidocs/index.html

hope it’s clear.

kind regards
Nikolaos Ballas  |  Software Development Manager

Technology Nexus S.a.r.l.
2-4 Rue Eugene Rupert
2453 Luxembourg
Delivery address: 2-3 Rue Eugene Rupert,Vertigo Polaris Building
Tel: + 3522619113580
cont...@nexusgroup.com | 
nexusgroup.com
LinkedIn.com | 
Twitter | 
Facebook.com


[cid:19B646FC-B8E7-4F77-BBD3-75DD7B4B5BF7]

On 07 Jul 2015, at 15:02, Donald Laidlaw 
mailto:donlaid...@me.com>> wrote:

Has anyone ever developed Java code to detect the mesos masters and leader, 
given a zookeeper connection?

The reason I ask is because I would like to monitor mesos to report various 
metrics reported by the master. This requires detecting and tracking the 
leading master to query its /metrics/snapshot REST endpoint.

Thanks,
-Don



Java detector for mess masters and leader

2015-07-07 Thread Donald Laidlaw
Has anyone ever developed Java code to detect the mesos masters and leader, 
given a zookeeper connection?

The reason I ask is because I would like to monitor mesos to report various 
metrics reported by the master. This requires detecting and tracking the 
leading master to query its /metrics/snapshot REST endpoint.

Thanks,
-Don