Skip to content

Commit

Permalink
SIDM-3692 Migrate HealthProve interface to abstract class to reduce c…
Browse files Browse the repository at this point in the history
…ode repetition.
  • Loading branch information
dfourn committed Feb 13, 2020
1 parent 74015f9 commit 98e6861
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.idam.health.probe.HealthProbe;

import javax.annotation.Nullable;

@Component
@Profile("am")
@Slf4j
public class AmIsAliveHealthProbe implements HealthProbe {
public class AmIsAliveHealthProbe extends HealthProbe {

private static final String TAG = "AM IsAlive: ";

private static final String ALIVE = "ALIVE";

private final AmProvider amProvider;

private String details = null;

public AmIsAliveHealthProbe(AmProvider amProvider) {
this.amProvider = amProvider;
}
Expand All @@ -33,21 +29,11 @@ public boolean probe() {
log.info(TAG + "success");
return true;
} else {
String msg = TAG + "response did not contain expected value";
log.error(msg);
details = msg;
setDetails(TAG + "response did not contain expected value");
}
} catch (Exception e) {
String msg = TAG + e.getMessage() + " [" + e.getClass().getSimpleName() + "]";
log.error(msg);
details = msg;
setDetails(TAG + e.getMessage());
}
return false;
}

@Nullable
@Override
public String getDetails() {
return details;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Component
@Profile("am")
@Slf4j
public class AmPasswordGrantHealthProbe implements HealthProbe {
public class AmPasswordGrantHealthProbe extends HealthProbe {

private static final String TAG = "AM PasswordGrant: ";

Expand All @@ -26,8 +26,6 @@ public class AmPasswordGrantHealthProbe implements HealthProbe {
private final ProbeUserProperties probeUserProperties;
private final String authorization;

private String details = null;

public AmPasswordGrantHealthProbe(
AmProvider amProvider,
AmHealthProbeProperties healthProbeProperties,
Expand All @@ -40,11 +38,6 @@ public AmPasswordGrantHealthProbe(
this.authorization = "Basic " + encode(agentProperties.getName(), agentProperties.getSecret());
}

@Override
public String getDetails() {
return details;
}

@Override
public boolean probe() {
try {
Expand All @@ -59,14 +52,10 @@ public boolean probe() {
log.info(TAG + "success");
return true;
} else {
String msg = TAG + "response did not contain expected value";
log.error(msg);
details = msg;
setDetails(TAG + "response did not contain expected value");
}
} catch (Exception e) {
String msg = TAG + e.getMessage() + " [" + e.getClass().getSimpleName() + "]";
log.error(msg);
details = msg;
setDetails(TAG + e.getMessage());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.time.temporal.ChronoUnit;

@Slf4j
public class FileFreshnessProbe implements HealthProbe {
public class FileFreshnessProbe extends HealthProbe {

private final String probeName;
private final Path checkPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Component
@Profile({"userstore","tokenstore","replication"})
@Slf4j
public class ReplicationCommandProbe implements HealthProbe {
public class ReplicationCommandProbe extends HealthProbe {

private static final String SPACE = " ";
private static final String RESULT_DELIM = "\t";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Component
@Profile("idm")
@Slf4j
public class IdmPingHealthProbe implements HealthProbe {
public class IdmPingHealthProbe extends HealthProbe {

private static final String TAG = "IDM Ping: ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@Component
@Slf4j
@Profile({"tokenstore", "userstore", "ldap"})
public class LdapReplicationHealthProbe implements HealthProbe {
public class LdapReplicationHealthProbe extends HealthProbe {

private static final String TAG = "LDAP Replication: ";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
package uk.gov.hmcts.reform.idam.health.probe;

import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public interface HealthProbe {
@Slf4j
public abstract class HealthProbe {

private String details;

boolean probe();
abstract public boolean probe();

default String getName() {
@Nonnull
public String getName() {
return this.getClass().getSimpleName();
};
}

@Nullable
default String getDetails() {
return null;
public String getDetails() {
return details;
}

public void setDetails(@Nullable String details) {
log.info(details + " [" + getName() + "]");
this.details = details;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Component
@Profile("tokenstore")
@Slf4j
public class TokenStoreSearchHealthProbe implements HealthProbe {
public class TokenStoreSearchHealthProbe extends HealthProbe {

private final String TAG = "TokenStore Search: ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Component
@Profile("userstore")
@Slf4j
public class UserStoreAuthenticationHealthProbe implements HealthProbe {
public class UserStoreAuthenticationHealthProbe extends HealthProbe {

private static final String LDAP_CN_ATTRIBUTE = "cn";
private final String TAG = "UserStore Auth: ";
Expand Down

0 comments on commit 98e6861

Please sign in to comment.