From 6498f0d5985788ca27bb0d5718e8a97408704913 Mon Sep 17 00:00:00 2001 From: pjrm Date: Wed, 28 Feb 2018 18:29:17 +0000 Subject: [PATCH 1/3] Add health check endpoint support for load balancers Add a new endpoint that will give the state of the current node. It will return 200 (OK) code case the node is serving and present in the cluster, otherwise will return 503 (Service Unavailable). --- .../exhibitor/core/rest/ClusterResource.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/exhibitor-core/src/main/java/com/netflix/exhibitor/core/rest/ClusterResource.java b/exhibitor-core/src/main/java/com/netflix/exhibitor/core/rest/ClusterResource.java index 41994165..d83903e4 100644 --- a/exhibitor-core/src/main/java/com/netflix/exhibitor/core/rest/ClusterResource.java +++ b/exhibitor-core/src/main/java/com/netflix/exhibitor/core/rest/ClusterResource.java @@ -32,6 +32,7 @@ import com.netflix.exhibitor.core.state.ServerList; import com.netflix.exhibitor.core.state.ServerSpec; import com.netflix.exhibitor.core.state.StartInstance; +import com.netflix.exhibitor.core.state.UsState; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.node.ArrayNode; import org.codehaus.jackson.node.JsonNodeFactory; @@ -347,6 +348,27 @@ public String getStatus() throws Exception return JsonUtil.writeValueAsString(mainNode); } + @Path("node/serving") + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response nodeIsServing() throws Exception + { + MonitorRunningInstance monitorRunningInstance = context.getExhibitor().getMonitorRunningInstance(); + InstanceStateTypes state = monitorRunningInstance.getCurrentInstanceState(); + + InstanceConfig config = context.getExhibitor().getConfigManager().getConfig(); + ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC)); + ServerSpec us = UsState.findUs(context.getExhibitor(), serverList.getSpecs()); + + Integer serverId = (us != null) ? us.getServerId() : -1; + + if (state == InstanceStateTypes.SERVING && serverId != -1) { + return Response.ok().build(); + } + + return Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); + } + @Path("list") @GET @Produces(MediaType.APPLICATION_JSON) From 248ede15d869704ae0dec18245c4d94d86b5bc8b Mon Sep 17 00:00:00 2001 From: Xiaochuan Yu Date: Sat, 16 Jun 2018 19:08:30 -0400 Subject: [PATCH 2/3] fix issue where backup provider not configured --- .../exhibitor/core/backup/BackupManager.java | 109 ++++++++---------- 1 file changed, 48 insertions(+), 61 deletions(-) diff --git a/exhibitor-core/src/main/java/com/netflix/exhibitor/core/backup/BackupManager.java b/exhibitor-core/src/main/java/com/netflix/exhibitor/core/backup/BackupManager.java index e6a8635d..c996d97a 100644 --- a/exhibitor-core/src/main/java/com/netflix/exhibitor/core/backup/BackupManager.java +++ b/exhibitor-core/src/main/java/com/netflix/exhibitor/core/backup/BackupManager.java @@ -55,7 +55,7 @@ public class BackupManager implements Closeable private final AtomicLong lastRollCheck = new AtomicLong(0); /** - * @param exhibitor main instance + * @param exhibitor main instance * @param backupProvider provider */ public BackupManager(final Exhibitor exhibitor, BackupProvider backupProvider) @@ -79,17 +79,17 @@ public Boolean call() throws Exception }; repeatingActivity = new OnOffRepeatingActivity - ( - new OnOffRepeatingActivity.Factory() - { - @Override - public RepeatingActivity newRepeatingActivity(long timePeriodMs) + ( + new OnOffRepeatingActivity.Factory() { - return new RepeatingActivityImpl(exhibitor.getLog(), exhibitor.getActivityQueue(), QueueGroups.IO, activity, getBackupPeriodMs()); - } - }, - getBackupPeriodMs() - ); + @Override + public RepeatingActivity newRepeatingActivity(long timePeriodMs) + { + return new RepeatingActivityImpl(exhibitor.getLog(), exhibitor.getActivityQueue(), QueueGroups.IO, activity, getBackupPeriodMs()); + } + }, + getBackupPeriodMs() + ); } private int getBackupPeriodMs() @@ -103,8 +103,7 @@ private int getBackupPeriodMs() */ public void start() { - if ( isActive() ) - { + if (isActive()) { repeatingActivity.start(); exhibitor.getConfigManager().addConfigListener ( @@ -123,8 +122,7 @@ public void configUpdated() @Override public void close() throws IOException { - if ( isActive() ) - { + if (isActive()) { repeatingActivity.close(); } } @@ -147,7 +145,7 @@ public boolean isActive() */ public List getAvailableBackups() throws Exception { - Map config = getBackupConfig(); + Map config = getBackupConfig(); return backupProvider.get().getAvailableBackups(exhibitor, config); } @@ -186,7 +184,13 @@ public List getConfigSpecs() /** * Restore all known logs */ - public void restoreAll() throws Exception { + public void restoreAll() throws Exception + { + + if (!backupProvider.isPresent()) { + log.info("No backup provider configured. Skipping restore."); + return; + } ZooKeeperLogFiles logFiles = new ZooKeeperLogFiles(exhibitor); log.info("Restoring log files from backup."); @@ -211,17 +215,16 @@ public void restoreAll() throws Exception { /** * Restore the given key to the given file * - * @param backup the backup to pull down + * @param backup the backup to pull down * @param destinationFile the file * @throws Exception errors */ public void restore(BackupMetaData backup, File destinationFile) throws Exception { - File tempFile = File.createTempFile("exhibitor-backup", ".tmp"); - OutputStream out = new FileOutputStream(tempFile); + File tempFile = File.createTempFile("exhibitor-backup", ".tmp"); + OutputStream out = new FileOutputStream(tempFile); InputStream in = null; - try - { + try { backupProvider.get().downloadBackup(exhibitor, backup, out, getBackupConfig()); CloseableUtils.closeQuietly(out); out = null; @@ -231,12 +234,10 @@ public void restore(BackupMetaData backup, File destinationFile) throws Exceptio ByteStreams.copy(in, out); } - finally - { + finally { CloseableUtils.closeQuietly(in); CloseableUtils.closeQuietly(out); - if ( !tempFile.delete() ) - { + if (!tempFile.delete()) { exhibitor.getLog().add(ActivityLog.Type.ERROR, "Could not delete temp file (for restore): " + tempFile); } } @@ -244,59 +245,48 @@ public void restore(BackupMetaData backup, File destinationFile) throws Exceptio private void doBackup() throws Exception { - if ( !exhibitor.getControlPanelValues().isSet(ControlPanelTypes.BACKUPS) ) - { + if (!exhibitor.getControlPanelValues().isSet(ControlPanelTypes.BACKUPS)) { return; } ZooKeeperLogFiles zooKeeperLogFiles = new ZooKeeperLogFiles(exhibitor); - if ( !zooKeeperLogFiles.isValid() ) - { + if (!zooKeeperLogFiles.isValid()) { return; } Map config = getBackupConfig(); - BackupProvider provider = backupProvider.get(); - if ( !provider.isValidConfig(exhibitor, config) ) - { + BackupProvider provider = backupProvider.get(); + if (!provider.isValidConfig(exhibitor, config)) { return; } - for ( File f : zooKeeperLogFiles.getPaths() ) - { - TempCompressedFile tempCompressedFile = new TempCompressedFile(f); - try - { + for (File f : zooKeeperLogFiles.getPaths()) { + TempCompressedFile tempCompressedFile = new TempCompressedFile(f); + try { tempCompressedFile.compress(); - BackupMetaData metaData = new BackupMetaData(f.getName(), f.lastModified()); + BackupMetaData metaData = new BackupMetaData(f.getName(), f.lastModified()); BackupProvider.UploadResult result = provider.uploadBackup(exhibitor, metaData, tempCompressedFile.getTempFile(), config); - switch ( result ) - { - case SUCCEEDED: - { + switch (result) { + case SUCCEEDED: { exhibitor.getLog().add(ActivityLog.Type.DEBUG, "Backing up: " + f); break; } - case DUPLICATE: - { + case DUPLICATE: { // ignore break; } - case REPLACED_OLD_VERSION: - { + case REPLACED_OLD_VERSION: { exhibitor.getLog().add(ActivityLog.Type.DEBUG, "Updated back up for: " + f); break; } } } - finally - { - if ( !tempCompressedFile.getTempFile().delete() ) - { + finally { + if (!tempCompressedFile.getTempFile().delete()) { exhibitor.getLog().add(ActivityLog.Type.ERROR, "Could not delete temp file: " + tempCompressedFile.getTempFile()); } } @@ -307,27 +297,24 @@ private void doBackup() throws Exception private Map getBackupConfig() { - String backupExtra = exhibitor.getConfigManager().getConfig().getString(StringConfigs.BACKUP_EXTRA); + String backupExtra = exhibitor.getConfigManager().getConfig().getString(StringConfigs.BACKUP_EXTRA); EncodedConfigParser encodedConfigParser = new EncodedConfigParser(backupExtra); return encodedConfigParser.getSortedMap(); } private void doRoll(Map config) throws Exception { - long elapsed = System.currentTimeMillis() - lastRollCheck.get(); - if ( elapsed < (exhibitor.getConfigManager().getConfig().getInt(IntConfigs.BACKUP_MAX_STORE_MS) / 3) ) - { + long elapsed = System.currentTimeMillis() - lastRollCheck.get(); + if (elapsed < (exhibitor.getConfigManager().getConfig().getInt(IntConfigs.BACKUP_MAX_STORE_MS) / 3)) { return; } exhibitor.getLog().add(ActivityLog.Type.DEBUG, "Checking for elapsed backups"); - List availableBackups = backupProvider.get().getAvailableBackups(exhibitor, config); - for ( BackupMetaData backup : availableBackups ) - { - long age = System.currentTimeMillis() - backup.getModifiedDate(); - if ( age > exhibitor.getConfigManager().getConfig().getInt(IntConfigs.BACKUP_MAX_STORE_MS) ) - { + List availableBackups = backupProvider.get().getAvailableBackups(exhibitor, config); + for (BackupMetaData backup : availableBackups) { + long age = System.currentTimeMillis() - backup.getModifiedDate(); + if (age > exhibitor.getConfigManager().getConfig().getInt(IntConfigs.BACKUP_MAX_STORE_MS)) { exhibitor.getLog().add(ActivityLog.Type.DEBUG, "Cleaning backup: " + backup); backupProvider.get().deleteBackup(exhibitor, backup, config); } From 446812f97820c716b706b0d0b9403f8858644dd8 Mon Sep 17 00:00:00 2001 From: Xiaochuan Yu Date: Tue, 24 Jul 2018 20:40:29 -0400 Subject: [PATCH 3/3] [maven-release-plugin] prepare release exhibitor-1.7.1 --- exhibitor-core/pom.xml | 2 +- exhibitor-standalone/pom.xml | 2 +- pom.xml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exhibitor-core/pom.xml b/exhibitor-core/pom.xml index 9a4bf99f..767a5dc9 100644 --- a/exhibitor-core/pom.xml +++ b/exhibitor-core/pom.xml @@ -3,7 +3,7 @@ exhibitor io.soabase.exhibitor - 1.7.1-SNAPSHOT + 1.7.1 4.0.0 diff --git a/exhibitor-standalone/pom.xml b/exhibitor-standalone/pom.xml index 69af2915..7be9d8ca 100644 --- a/exhibitor-standalone/pom.xml +++ b/exhibitor-standalone/pom.xml @@ -3,7 +3,7 @@ exhibitor io.soabase.exhibitor - 1.7.1-SNAPSHOT + 1.7.1 4.0.0 diff --git a/pom.xml b/pom.xml index 4069f1fc..9b30a31d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.soabase.exhibitor exhibitor - 1.7.1-SNAPSHOT + 1.7.1 pom @@ -91,7 +91,7 @@ https://github.com/soabase/exhibitor scm:git:https://github.com/soabase/exhibitor.git scm:git:git@github.com:soabase/exhibitor.git - HEAD + exhibitor-1.7.1