瀏覽代碼

Set log flag's TTL witin API call

pull/37/head
Kristijan Mitrovic 4 年之前
父節點
當前提交
92cb1f435c
共有 4 個檔案被更改,包括 28 行新增10 行删除
  1. +13
    -4
      bubble-server/src/main/java/bubble/resources/cloud/LogsResource.java
  2. +4
    -1
      bubble-server/src/main/java/bubble/service/boot/SelfNodeService.java
  3. +5
    -4
      bubble-server/src/main/java/bubble/service/boot/StandardSelfNodeService.java
  4. +6
    -1
      bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSelfNodeService.java

+ 13
- 4
bubble-server/src/main/java/bubble/resources/cloud/LogsResource.java 查看文件

@@ -10,9 +10,12 @@ import lombok.NonNull;
import org.glassfish.jersey.server.ContainerRequest;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Nullable;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static bubble.ApiConstants.*;
import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON;
@@ -37,13 +40,19 @@ public class LogsResource {
}

@POST @Path(EP_START)
@NonNull public Response startLogging(@NonNull @Context final ContainerRequest ctx) { return setLogFlag(true); }
@NonNull public Response startLogging(@NonNull @Context final ContainerRequest ctx,
@Nullable @QueryParam("ttlDays") final Byte ttlDays) {
return setLogFlag(true, Optional.ofNullable(ttlDays));
}

@POST @Path(EP_STOP)
@NonNull public Response stopLogging(@NonNull @Context final ContainerRequest ctx) { return setLogFlag(false); }
@NonNull public Response stopLogging(@NonNull @Context final ContainerRequest ctx) {
return setLogFlag(false, Optional.empty());
}

@NonNull private Response setLogFlag(final boolean b) {
@NonNull private Response setLogFlag(final boolean b, @NonNull final Optional<Byte> ttlInDays) {
if (!account.admin()) throw forbiddenEx(); // caller must be admin
selfNodeService.setLogFlag(b);
selfNodeService.setLogFlag(b, ttlInDays.map(days -> (int) TimeUnit.DAYS.toSeconds(days)));
return ok();
}
}

+ 4
- 1
bubble-server/src/main/java/bubble/service/boot/SelfNodeService.java 查看文件

@@ -7,6 +7,9 @@ package bubble.service.boot;
import bubble.model.bill.BubblePlan;
import bubble.model.cloud.BubbleNetwork;
import bubble.model.cloud.BubbleNode;
import lombok.NonNull;

import java.util.Optional;

public interface SelfNodeService {

@@ -25,5 +28,5 @@ public interface SelfNodeService {
BubblePlan getThisPlan();

Boolean getLogFlag();
void setLogFlag(final boolean logFlag);
void setLogFlag(final boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds);
}

+ 5
- 4
bubble-server/src/main/java/bubble/service/boot/StandardSelfNodeService.java 查看文件

@@ -41,6 +41,7 @@ import org.springframework.stereotype.Service;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

@@ -72,8 +73,8 @@ public class StandardSelfNodeService implements SelfNodeService {
public static final long MIN_SAGE_KEY_TTL = MINUTES.toMillis(5);

private static final String REDIS_LOG_FLAG_KEY = "bubble_server_logs_enabled";
private static final long TTL_LOG_FLAG_NODE = DAYS.toSeconds(7);
private static final long TTL_LOG_FLAG_SAGE = DAYS.toSeconds(30);
private static final int TTL_LOG_FLAG_NODE = (int) DAYS.toSeconds(7);
private static final int TTL_LOG_FLAG_SAGE = (int) DAYS.toSeconds(30);

@Autowired private BubbleNodeDAO nodeDAO;
@Autowired private BubbleNodeKeyDAO nodeKeyDAO;
@@ -448,10 +449,10 @@ public class StandardSelfNodeService implements SelfNodeService {
}

@Override
public void setLogFlag(final boolean logFlag) {
public void setLogFlag(final boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds) {
if (logFlag) {
getNodeConfig().set_plaintext(REDIS_LOG_FLAG_KEY, "true", EX,
isSelfSage() ? TTL_LOG_FLAG_SAGE : TTL_LOG_FLAG_NODE);
ttlInSeconds.orElse(isSelfSage() ? TTL_LOG_FLAG_SAGE : TTL_LOG_FLAG_NODE));
} else {
// just (try to) remove the flag
getNodeConfig().del(REDIS_LOG_FLAG_KEY);


+ 6
- 1
bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSelfNodeService.java 查看文件

@@ -8,8 +8,11 @@ import bubble.model.bill.BubblePlan;
import bubble.model.cloud.BubbleNetwork;
import bubble.model.cloud.BubbleNode;
import bubble.service.boot.SelfNodeService;
import lombok.NonNull;
import org.springframework.stereotype.Service;

import java.util.Optional;

import static org.cobbzilla.util.daemon.ZillaRuntime.notSupported;

@Service
@@ -30,6 +33,8 @@ public class DbFilterSelfNodeService implements SelfNodeService {
@Override public BubblePlan getThisPlan() { return notSupported("getThisPlan"); }

@Override public Boolean getLogFlag() { return notSupported("getLogFlag"); }
@Override public void setLogFlag(boolean logFlag) { notSupported("setLogFlag"); }
@Override public void setLogFlag(boolean logFlag, @NonNull final Optional<Integer> ttlInSeconds) {
notSupported("setLogFlag");
}

}

Loading…
取消
儲存