Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arnett, stu committed Jul 8, 2016
1 parent ab4e2cd commit 98db4b9
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 68 deletions.
27 changes: 27 additions & 0 deletions 3rd-party-licenses/LICENSE-slf4j-api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Library: slf4j-api
Copyright 2004-2013 QOS.ch
License: MIT
Full License Text:
-----------------------------------------------------------------------------------------------------------------------

Copyright (c) 2004-2013 QOS.ch
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions 3rd-party-licenses/LICENSE-slf4j-log4j12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Library: slf4j-log4j12
Copyright 2004-2013 QOS.ch
License: MIT
Full License Text:
-----------------------------------------------------------------------------------------------------------------------

Copyright (c) 2004-2013 QOS.ch
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -29,7 +29,7 @@ description = 'Smart REST Client - JAX-RS (Jersey) REST client that provides cli
ext.githubProjectName = 'smart-client-java'

buildscript {
ext.commonBuildVersion = '1.3.3'
ext.commonBuildVersion = '1.5'
ext.commonBuildDir = "https://raw.githubusercontent.com/emcvipr/ecs-common-build/v$commonBuildVersion"
apply from: "$commonBuildDir/ecs-publish.buildscript.gradle", to: buildscript
}
Expand All @@ -40,6 +40,8 @@ dependencies {
compile 'com.sun.jersey:jersey-client:1.19',
'com.sun.jersey.contribs:jersey-apache-client4:1.19',
'org.apache.httpcomponents:httpclient:4.2.6',
'org.slf4j:slf4j-api:1.7.5'
runtime 'org.slf4j:slf4j-log4j12:1.7.5'
testCompile 'junit:junit:4.12',
'log4j:log4j:1.2.17'
testCompile 'junit:junit:4.12'
}
17 changes: 9 additions & 8 deletions src/main/java/com/emc/rest/smart/Host.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand All @@ -26,11 +26,11 @@
*/
package com.emc.rest.smart;

import org.apache.log4j.LogMF;
import org.apache.log4j.Logger;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Some basic statements about response index calculation:
* <p>
Expand All @@ -42,7 +42,8 @@
* </ul>
*/
public class Host implements HostStats {
private static final Logger l4j = Logger.getLogger(Host.class);

private static final Logger log = LoggerFactory.getLogger(Host.class);

public static final int DEFAULT_ERROR_WAIT_MS = 1500;
public static final int LOG_DELAY = 60000; // 1 minute
Expand Down Expand Up @@ -79,7 +80,7 @@ public synchronized void connectionClosed() {
if (openConnections < 0) {
long currentTime = System.currentTimeMillis();
if (currentTime - lastLogTime > LOG_DELAY) {
LogMF.warn(l4j, "openConnections for host %s is %d !", this, openConnections);
log.warn("openConnections for host {} is {} !", this.toString(), Integer.toString(openConnections));
lastLogTime = currentTime;
}
}
Expand All @@ -89,8 +90,8 @@ public synchronized void callComplete(boolean isError) {
if (isError) {
totalErrors++;
consecutiveErrors++;
LogMF.debug(l4j, "error tallied for {2}; total errors: {0}, consecutive errors: {1}",
totalErrors, consecutiveErrors, name);
log.debug("error tallied for {}; total errors: {}, consecutive errors: {}",
name, totalErrors, consecutiveErrors);
} else {
consecutiveErrors = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/emc/rest/smart/HostListProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface HostListProvider {
/**
* Destroy this provider. Any system resources associated with the provider
* will be cleaned up.
* <p/>
* <p>
* The provider must not be reused after this method is called otherwise
* undefined behavior will occur.
*/
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/emc/rest/smart/HostStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
import java.util.Date;

public interface HostStats {
@SuppressWarnings("unused")

long getTotalConnections();

@SuppressWarnings("unused")

long getTotalErrors();

@SuppressWarnings("unused")

int getOpenConnections();

@SuppressWarnings("unused")

Date getLastConnectionTime();

}
29 changes: 14 additions & 15 deletions src/main/java/com/emc/rest/smart/PollingDaemon.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand All @@ -26,16 +26,16 @@
*/
package com.emc.rest.smart;

import org.apache.log4j.LogMF;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Polling thread that will terminate automatically when the application exits
*/
public class PollingDaemon extends Thread {
public static final String PROPERTY_KEY = "com.emc.rest.smart.pollingDaemon";

private static final Logger l4j = Logger.getLogger(PollingDaemon.class);
private static final Logger log = LoggerFactory.getLogger(PollingDaemon.class);

private SmartConfig smartConfig;
private boolean running = true;
Expand All @@ -49,36 +49,36 @@ public PollingDaemon(SmartConfig smartConfig) {
public void run() {
while (running) {
long start = System.currentTimeMillis();
l4j.debug("polling daemon running");
log.debug("polling daemon running");

LoadBalancer loadBalancer = smartConfig.getLoadBalancer();
HostListProvider hostListProvider = smartConfig.getHostListProvider();

if (!smartConfig.isHostUpdateEnabled()) {
l4j.info("host update is disabled; not updating hosts");
log.info("host update is disabled; not updating hosts");
} else if (hostListProvider == null) {
l4j.info("no host list provider; not updating hosts");
log.info("no host list provider; not updating hosts");
} else {
try {
loadBalancer.updateHosts(hostListProvider.getHostList());
} catch (Throwable t) {
l4j.warn("unable to enumerate servers", t);
log.warn("unable to enumerate servers", t);
}
}

if (!smartConfig.isHealthCheckEnabled()) {
l4j.info("health check is disabled; not checking hosts");
log.info("health check is disabled; not checking hosts");
} else if (hostListProvider == null) {
l4j.info("no host list provider; not checking hosts");
log.info("no host list provider; not checking hosts");
} else {
for (Host host : loadBalancer.getAllHosts()) {
try {
hostListProvider.runHealthCheck(host);
host.setHealthy(true);
LogMF.debug(l4j, "health check successful for {0}; host is marked healthy", host.getName());
log.debug("health check successful for {}; host is marked healthy", host.getName());
} catch (Throwable t) {
host.setHealthy(false);
l4j.warn("health check failed for " + host.getName() + "; host is marked unhealthy", t);
log.warn("health check failed for " + host.getName() + "; host is marked unhealthy", t);
}
}
}
Expand All @@ -87,15 +87,14 @@ public void run() {
try {
long sleepTime = smartConfig.getPollInterval() * 1000 - callTime;
if (sleepTime < 0) sleepTime = 0;
LogMF.debug(l4j, "polling daemon finished; will poll again in {0}ms..", sleepTime);
log.debug("polling daemon finished; will poll again in {}ms..", Long.toString(sleepTime));
if (sleepTime > 0) Thread.sleep(sleepTime);
} catch (InterruptedException e) {
l4j.warn("interrupted while sleeping", e);
log.warn("interrupted while sleeping", e);
}
}
}

@SuppressWarnings("unused")
public void terminate() {
running = false;
}
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/emc/rest/smart/SmartClientFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand All @@ -26,6 +26,9 @@
*/
package com.emc.rest.smart;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandler;
import com.sun.jersey.api.client.config.ClientConfig;
Expand All @@ -36,10 +39,10 @@
import com.sun.jersey.core.impl.provider.entity.ByteArrayProvider;
import com.sun.jersey.core.impl.provider.entity.FileProvider;
import com.sun.jersey.core.impl.provider.entity.InputStreamProvider;
import org.apache.log4j.Logger;

public final class SmartClientFactory {
private static final Logger l4j = Logger.getLogger(SmartClientFactory.class);

private static final Logger log = LoggerFactory.getLogger(SmartClientFactory.class);

public static final String DISABLE_APACHE_RETRY = "com.emc.rest.smart.disableApacheRetry";

Expand Down Expand Up @@ -109,24 +112,24 @@ public static Client createStandardClient(SmartConfig smartConfig,
/**
* Destroy this client. Any system resources associated with the client
* will be cleaned up.
* <p/>
* <p>
* This method must be called when there are not responses pending otherwise
* undefined behavior will occur.
* <p/>
* <p>
* The client must not be reused after this method is called otherwise
* undefined behavior will occur.
*/
public static void destroy(Client client) {
PollingDaemon pollingDaemon = (PollingDaemon) client.getProperties().get(PollingDaemon.PROPERTY_KEY);
if (pollingDaemon != null) {
l4j.debug("terminating polling daemon");
log.debug("terminating polling daemon");
pollingDaemon.terminate();
if (pollingDaemon.getSmartConfig().getHostListProvider() != null) {
l4j.debug("destroying host list provider");
log.debug("destroying host list provider");
pollingDaemon.getSmartConfig().getHostListProvider().destroy();
}
}
l4j.debug("destroying Jersey client");
log.debug("destroying Jersey client");
client.destroy();
}

Expand Down
Loading

0 comments on commit 98db4b9

Please sign in to comment.