Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Add health check endpoint support for load balancers #371

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exhibitor-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>exhibitor</artifactId>
<groupId>io.soabase.exhibitor</groupId>
<version>1.7.1-SNAPSHOT</version>
<version>1.7.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -103,8 +103,7 @@ private int getBackupPeriodMs()
*/
public void start()
{
if ( isActive() )
{
if (isActive()) {
repeatingActivity.start();
exhibitor.getConfigManager().addConfigListener
(
Expand All @@ -123,8 +122,7 @@ public void configUpdated()
@Override
public void close() throws IOException
{
if ( isActive() )
{
if (isActive()) {
repeatingActivity.close();
}
}
Expand All @@ -147,7 +145,7 @@ public boolean isActive()
*/
public List<BackupMetaData> getAvailableBackups() throws Exception
{
Map<String, String> config = getBackupConfig();
Map<String, String> config = getBackupConfig();
return backupProvider.get().getAvailableBackups(exhibitor, config);
}

Expand Down Expand Up @@ -186,7 +184,13 @@ public List<BackupConfigSpec> 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.");
Expand All @@ -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;
Expand All @@ -231,72 +234,59 @@ 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);
}
}
}

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<String, String> 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());
}
}
Expand All @@ -307,27 +297,24 @@ private void doBackup() throws Exception

private Map<String, String> 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<String, String> 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<BackupMetaData> 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<BackupMetaData> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion exhibitor-standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>exhibitor</artifactId>
<groupId>io.soabase.exhibitor</groupId>
<version>1.7.1-SNAPSHOT</version>
<version>1.7.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.soabase.exhibitor</groupId>
<artifactId>exhibitor</artifactId>
<version>1.7.1-SNAPSHOT</version>
<version>1.7.1</version>
<packaging>pom</packaging>

<modules>
Expand Down Expand Up @@ -91,7 +91,7 @@
<url>https://github.com/soabase/exhibitor</url>
<connection>scm:git:https://github.com/soabase/exhibitor.git</connection>
<developerConnection>scm:git:[email protected]:soabase/exhibitor.git</developerConnection>
<tag>HEAD</tag>
<tag>exhibitor-1.7.1</tag>
</scm>

<issueManagement>
Expand Down