@@ -14,6 +14,7 @@ import javax.annotation.Nullable; | |||||
import javax.ws.rs.*; | import javax.ws.rs.*; | ||||
import javax.ws.rs.core.Context; | import javax.ws.rs.core.Context; | ||||
import javax.ws.rs.core.Response; | import javax.ws.rs.core.Response; | ||||
import java.util.HashMap; | |||||
import java.util.Optional; | import java.util.Optional; | ||||
import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||
@@ -36,7 +37,10 @@ public class LogsResource { | |||||
@GET @Path(EP_STATUS) | @GET @Path(EP_STATUS) | ||||
@NonNull public Response getLoggingStatus(@NonNull @Context final ContainerRequest ctx) { | @NonNull public Response getLoggingStatus(@NonNull @Context final ContainerRequest ctx) { | ||||
return ok(selfNodeService.getLogFlag()); | |||||
final var flag = new HashMap<String, Object>(2); | |||||
flag.put("flag", selfNodeService.getLogFlag()); | |||||
flag.put("expireAt", selfNodeService.getLogFlagExpirationTime().orElse(null)); | |||||
return ok(flag); | |||||
} | } | ||||
@POST @Path(EP_START) | @POST @Path(EP_START) | ||||
@@ -28,5 +28,12 @@ public interface SelfNodeService { | |||||
BubblePlan getThisPlan(); | BubblePlan getThisPlan(); | ||||
boolean getLogFlag(); | boolean getLogFlag(); | ||||
/** | |||||
* @return Empty if TTL for log flag is a special one (less than 0), else timestamp (milliseconds) when log flag | |||||
* will be expired (to be precise, a very close time after the real expiration time as some time is spent | |||||
* for processing here). | |||||
*/ | |||||
@NonNull Optional<Long> getLogFlagExpirationTime(); | |||||
void setLogFlag(final boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds); | void setLogFlag(final boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds); | ||||
} | } |
@@ -447,6 +447,12 @@ public class StandardSelfNodeService implements SelfNodeService { | |||||
return empty(flagStr) ? false : Boolean.valueOf(flagStr); | return empty(flagStr) ? false : Boolean.valueOf(flagStr); | ||||
} | } | ||||
@Override | |||||
@NonNull public Optional<Long> getLogFlagExpirationTime() { | |||||
var ttl = getNodeConfig().get_ttl(REDIS_LOG_FLAG_KEY); | |||||
return ttl < 0 ? Optional.empty() : Optional.of(now() + ttl * 1000); | |||||
} | |||||
@Override | @Override | ||||
public void setLogFlag(final boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds) { | public void setLogFlag(final boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds) { | ||||
if (logFlag) { | if (logFlag) { | ||||
@@ -33,6 +33,9 @@ public class DbFilterSelfNodeService implements SelfNodeService { | |||||
@Override public BubblePlan getThisPlan() { return notSupported("getThisPlan"); } | @Override public BubblePlan getThisPlan() { return notSupported("getThisPlan"); } | ||||
@Override public boolean getLogFlag() { return notSupported("getLogFlag"); } | @Override public boolean getLogFlag() { return notSupported("getLogFlag"); } | ||||
@Override @NonNull public Optional<Long> getLogFlagExpirationTime() { | |||||
return notSupported("getLogFlagExpirationTime"); | |||||
} | |||||
@Override public void setLogFlag(boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds) { | @Override public void setLogFlag(boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds) { | ||||
notSupported("setLogFlag"); | notSupported("setLogFlag"); | ||||
} | } | ||||