diff options
Diffstat (limited to 'aai-failover/src/main/java')
-rw-r--r-- | aai-failover/src/main/java/org/onap/aai/failover/FailoverAspect.java | 22 | ||||
-rw-r--r-- | aai-failover/src/main/java/org/onap/aai/failover/FailoverMonitor.java | 11 |
2 files changed, 16 insertions, 17 deletions
diff --git a/aai-failover/src/main/java/org/onap/aai/failover/FailoverAspect.java b/aai-failover/src/main/java/org/onap/aai/failover/FailoverAspect.java index ee21d167..660cac91 100644 --- a/aai-failover/src/main/java/org/onap/aai/failover/FailoverAspect.java +++ b/aai-failover/src/main/java/org/onap/aai/failover/FailoverAspect.java @@ -17,8 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.failover; +import java.util.Date; +import java.util.concurrent.atomic.AtomicLong; + import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -27,9 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import java.util.Date; -import java.util.concurrent.atomic.AtomicLong; - @Aspect @Component public class FailoverAspect { @@ -39,7 +40,7 @@ public class FailoverAspect { private final FailoverMonitor failoverMonitor; private final AtomicLong atomicLong; - public FailoverAspect(FailoverMonitor failoverMonitor){ + public FailoverAspect(FailoverMonitor failoverMonitor) { this.failoverMonitor = failoverMonitor; this.atomicLong = new AtomicLong(1l); } @@ -69,25 +70,22 @@ public class FailoverAspect { @Around("@annotation(org.springframework.scheduling.annotation.Scheduled)") public void preSchedule(ProceedingJoinPoint pointcut) throws Throwable { - Object target = pointcut.getTarget(); + Object target = pointcut.getTarget(); MethodSignature signature = (MethodSignature) pointcut.getSignature(); - String method = signature.getMethod().getName(); + String method = signature.getMethod().getName(); - if(failoverMonitor.shouldRun()){ + if (failoverMonitor.shouldRun()) { atomicLong.set(1l); pointcut.proceed(); } else { long currentTime = new Date().getTime(); long lastMessageTime = atomicLong.get(); - if((currentTime - lastMessageTime) > 120000){ + if ((currentTime - lastMessageTime) > 120000) { atomicLong.compareAndSet(lastMessageTime, new Date().getTime()); LOGGER.debug("Not proceeding the task {}#{} due to is_primary set to false in failover.properties", - target.getClass(), - method - ); + target.getClass(), method); } } } } - diff --git a/aai-failover/src/main/java/org/onap/aai/failover/FailoverMonitor.java b/aai-failover/src/main/java/org/onap/aai/failover/FailoverMonitor.java index cadddc24..731abe7c 100644 --- a/aai-failover/src/main/java/org/onap/aai/failover/FailoverMonitor.java +++ b/aai-failover/src/main/java/org/onap/aai/failover/FailoverMonitor.java @@ -17,10 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.failover; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; +package org.onap.aai.failover; import java.io.IOException; import java.io.InputStream; @@ -29,6 +27,9 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Properties; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + @Component public class FailoverMonitor { @@ -43,9 +44,9 @@ public class FailoverMonitor { Path failoverPath = Paths.get(failoverPropertiesPath); - if(Files.exists(failoverPath)){ + if (Files.exists(failoverPath)) { Properties properties = new Properties(); - try (InputStream is = Files.newInputStream(failoverPath)){ + try (InputStream is = Files.newInputStream(failoverPath)) { properties.load(is); // If the property is_primary is missing then it should proceed return TRUE.equals(properties.getProperty(IS_PRIMARY, DEFAULT_FOR_PRIMARY)); |