From d1eb61d4512d24093bb8d0ceb412a9dba9f00352 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Tue, 19 Mar 2013 10:47:26 -0700 Subject: [PATCH] TaskAction: - Add isAudited - Generally straighten out Jackson annotations --- .../common/actions/LocalTaskActionClient.java | 20 ++++++++++--------- .../common/actions/LockAcquireAction.java | 8 ++++++++ .../merger/common/actions/LockListAction.java | 12 ++++++----- .../common/actions/LockReleaseAction.java | 8 ++++++++ .../common/actions/SegmentInsertAction.java | 6 ++++++ .../actions/SegmentListUnusedAction.java | 10 ++++++++++ .../common/actions/SegmentListUsedAction.java | 10 ++++++++++ .../common/actions/SegmentNukeAction.java | 8 ++++++++ .../common/actions/SpawnTasksAction.java | 8 ++++++++ .../merger/common/actions/TaskAction.java | 1 + 10 files changed, 77 insertions(+), 14 deletions(-) diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/LocalTaskActionClient.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/LocalTaskActionClient.java index 4dd0cc8fe2d..1083dfcbed5 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/LocalTaskActionClient.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/LocalTaskActionClient.java @@ -28,15 +28,17 @@ public class LocalTaskActionClient implements TaskActionClient final RetType ret = taskAction.perform(task, toolbox); - // Add audit log - try { - storage.addAuditLog(task, taskAction); - } - catch (Exception e) { - log.makeAlert(e, "Failed to record action in audit log") - .addData("task", task.getId()) - .addData("actionClass", taskAction.getClass().getName()) - .emit(); + if (taskAction.isAudited()) { + // Add audit log + try { + storage.addAuditLog(task, taskAction); + } + catch (Exception e) { + log.makeAlert(e, "Failed to record action in audit log") + .addData("task", task.getId()) + .addData("actionClass", taskAction.getClass().getName()) + .emit(); + } } return ret; diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/LockAcquireAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/LockAcquireAction.java index 0a353dc5024..18441ea54c2 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/LockAcquireAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/LockAcquireAction.java @@ -1,6 +1,7 @@ package com.metamx.druid.merger.common.actions; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.base.Throwables; @@ -10,6 +11,7 @@ import org.joda.time.Interval; public class LockAcquireAction implements TaskAction { + @JsonIgnore private final Interval interval; @JsonCreator @@ -44,6 +46,12 @@ public class LockAcquireAction implements TaskAction } } + @Override + public boolean isAudited() + { + return true; + } + @Override public String toString() { diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/LockListAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/LockListAction.java index 2d58a883d93..4ea12ae6d13 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/LockListAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/LockListAction.java @@ -1,12 +1,8 @@ package com.metamx.druid.merger.common.actions; -import com.google.common.base.Optional; -import com.google.common.base.Throwables; +import com.fasterxml.jackson.core.type.TypeReference; import com.metamx.druid.merger.common.TaskLock; import com.metamx.druid.merger.common.task.Task; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.type.TypeReference; import java.util.List; @@ -23,6 +19,12 @@ public class LockListAction implements TaskAction> return toolbox.getTaskLockbox().findLocksForTask(task); } + @Override + public boolean isAudited() + { + return false; + } + @Override public String toString() { diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/LockReleaseAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/LockReleaseAction.java index 42a6bbb40c9..0ee33691104 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/LockReleaseAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/LockReleaseAction.java @@ -1,6 +1,7 @@ package com.metamx.druid.merger.common.actions; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.metamx.druid.merger.common.task.Task; @@ -8,6 +9,7 @@ import org.joda.time.Interval; public class LockReleaseAction implements TaskAction { + @JsonIgnore private final Interval interval; @JsonCreator @@ -36,6 +38,12 @@ public class LockReleaseAction implements TaskAction return null; } + @Override + public boolean isAudited() + { + return true; + } + @Override public String toString() { diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentInsertAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentInsertAction.java index 2844a8bd93a..2d2ac9ef02a 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentInsertAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentInsertAction.java @@ -80,6 +80,12 @@ public class SegmentInsertAction implements TaskAction> return retVal; } + @Override + public boolean isAudited() + { + return true; + } + @Override public String toString() { diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentListUnusedAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentListUnusedAction.java index c5cf8f306b5..90efbaf1b1c 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentListUnusedAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentListUnusedAction.java @@ -1,6 +1,7 @@ package com.metamx.druid.merger.common.actions; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.metamx.druid.client.DataSegment; @@ -12,7 +13,10 @@ import java.util.List; public class SegmentListUnusedAction implements TaskAction> { + @JsonIgnore private final String dataSource; + + @JsonIgnore private final Interval interval; @JsonCreator @@ -48,6 +52,12 @@ public class SegmentListUnusedAction implements TaskAction> return toolbox.getMergerDBCoordinator().getUnusedSegmentsForInterval(dataSource, interval); } + @Override + public boolean isAudited() + { + return false; + } + @Override public String toString() { diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentListUsedAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentListUsedAction.java index c2a3b8fbc3a..ca8fc3a888b 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentListUsedAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentListUsedAction.java @@ -1,6 +1,7 @@ package com.metamx.druid.merger.common.actions; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.metamx.druid.client.DataSegment; @@ -12,7 +13,10 @@ import java.util.List; public class SegmentListUsedAction implements TaskAction> { + @JsonIgnore private final String dataSource; + + @JsonIgnore private final Interval interval; @JsonCreator @@ -48,6 +52,12 @@ public class SegmentListUsedAction implements TaskAction> return toolbox.getMergerDBCoordinator().getUsedSegmentsForInterval(dataSource, interval); } + @Override + public boolean isAudited() + { + return false; + } + @Override public String toString() { diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentNukeAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentNukeAction.java index c4b2a2f7044..3d4f453a670 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentNukeAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/SegmentNukeAction.java @@ -1,6 +1,7 @@ package com.metamx.druid.merger.common.actions; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.collect.ImmutableSet; @@ -14,6 +15,7 @@ import java.util.Set; public class SegmentNukeAction implements TaskAction { + @JsonIgnore private final Set segments; @JsonCreator @@ -57,6 +59,12 @@ public class SegmentNukeAction implements TaskAction return null; } + @Override + public boolean isAudited() + { + return true; + } + @Override public String toString() { diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/SpawnTasksAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/SpawnTasksAction.java index 6f0c7402640..870a15ba25f 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/SpawnTasksAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/SpawnTasksAction.java @@ -1,6 +1,7 @@ package com.metamx.druid.merger.common.actions; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.collect.ImmutableList; @@ -10,6 +11,7 @@ import java.util.List; public class SpawnTasksAction implements TaskAction { + @JsonIgnore private final List newTasks; @JsonCreator @@ -41,6 +43,12 @@ public class SpawnTasksAction implements TaskAction return null; } + @Override + public boolean isAudited() + { + return true; + } + @Override public String toString() { diff --git a/merger/src/main/java/com/metamx/druid/merger/common/actions/TaskAction.java b/merger/src/main/java/com/metamx/druid/merger/common/actions/TaskAction.java index dac6fce597f..b3ac3b72d5d 100644 --- a/merger/src/main/java/com/metamx/druid/merger/common/actions/TaskAction.java +++ b/merger/src/main/java/com/metamx/druid/merger/common/actions/TaskAction.java @@ -22,4 +22,5 @@ public interface TaskAction { public TypeReference getReturnTypeReference(); // T_T public RetType perform(Task task, TaskActionToolbox toolbox) throws IOException; + public boolean isAudited(); }