Handle d2 markup case when not only announcing leader
@@ -297,7 +297,8 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
* @param changeContext notification context
*/
private void handleLeadershipChange(NotificationContext changeContext) {
- if (this.helixManager.isPresent() && this.helixManager.get().isLeader()) {
+ if (this.helixManager.isPresent()) {
+ if (this.helixManager.get().isLeader()) {
LOGGER.info("Leader notification for {} HM.isLeader {}", this.helixManager.get().getInstanceName(),
this.helixManager.get().isLeader());
@@ -325,7 +326,7 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
if (configuration.isOnlyAnnounceLeader()) {
this.d2Announcer.markUpServer();
}
- } else if (this.helixManager.isPresent()) {
+ } else {
LOGGER.info("Leader lost notification for {} HM.isLeader {}", this.helixManager.get().getInstanceName(),
this.helixManager.get().isLeader());
@@ -352,6 +353,7 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
}
}
}
+ }
private void registerServicesInLauncher(){
if (configuration.isTopologyCatalogEnabled()) {
@@ -476,6 +478,11 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
}
}
+ // Announce to d2 after services are initialized regardless of leadership if configuration is not enabled
+ if (!this.configuration.isOnlyAnnounceLeader()) {
+ this.d2Announcer.markUpServer();
+ }
+
// Populate TopologyCatalog with all Topologies generated by TopologySpecFactory
// This has to be done after the topologyCatalog service is launched
if (configuration.isTopologySpecFactoryEnabled()) {
@@ -515,6 +522,10 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
LOGGER.info("Stopping the Gobblin Service Manager");
this.stopInProgress = true;
try {
+ // Stop announcing GaaS instances to d2 when services are stopped
+ if (!configuration.isOnlyAnnounceLeader()) {
+ this.d2Announcer.markDownServer();
+ }
this.serviceLauncher.stop();
} catch (ApplicationException ae) {
LOGGER.error("Error while stopping Gobblin Service Manager", ae);
