Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement plugin data versioning #390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import hudson.model.InvisibleAction;
import java.io.Serializable;
import org.jenkinsci.plugins.workflow.actions.PersistentAction;

/**
* Marker interface for all actions that are added by the plugin
*/
public abstract class DatadogPluginAction extends InvisibleAction implements Serializable {
public abstract class DatadogPluginAction extends InvisibleAction implements PersistentAction, Serializable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import java.util.Objects;
import org.datadog.jenkins.plugins.datadog.util.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;

/**
* Keeps the Git commit related information.
Expand Down Expand Up @@ -140,18 +141,22 @@ public String toString() {
'}';
}

public static final class ConverterImpl extends DatadogActionConverter {
public static final class ConverterImpl extends DatadogActionConverter<GitCommitAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1());
}
}

@Override
public boolean canConvert(Class type) {
return GitCommitAction.class == type;
public static final class ConverterV1 extends VersionedConverter<GitCommitAction> {

private static final int VERSION = 1;

public ConverterV1() {
super(VERSION);
}

@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
GitCommitAction action = (GitCommitAction) source;
public void marshal(GitCommitAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
if (action.tag != null) {
writeField("tag", action.tag, writer, context);
}
Expand Down Expand Up @@ -182,7 +187,7 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC
}

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
public GitCommitAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
String tag = null;
String commit = null;
String message = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import java.util.Objects;
import javax.annotation.Nullable;
import org.datadog.jenkins.plugins.datadog.util.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;

/**
* Keeps the Git repository related information.
Expand Down Expand Up @@ -78,18 +79,22 @@ public String toString() {
'}';
}

public static final class ConverterImpl extends DatadogActionConverter {
public static final class ConverterImpl extends DatadogActionConverter<GitRepositoryAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1());
}
}

@Override
public boolean canConvert(Class type) {
return GitRepositoryAction.class == type;
public static final class ConverterV1 extends VersionedConverter<GitRepositoryAction> {

private static final int VERSION = 1;

public ConverterV1() {
super(VERSION);
}

@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
GitRepositoryAction action = (GitRepositoryAction) source;
public void marshal(GitRepositoryAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
if (action.repositoryURL != null) {
writeField("repositoryURL", action.repositoryURL, writer, context);
}
Expand All @@ -102,7 +107,7 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC
}

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
public GitRepositoryAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
GitRepositoryAction gitRepositoryAction = new GitRepositoryAction();
while (reader.hasMoreChildren()) {
reader.moveDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import org.datadog.jenkins.plugins.datadog.util.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;

public class PipelineNodeInfoAction extends DatadogPluginAction {

Expand Down Expand Up @@ -63,18 +64,22 @@ public String toString() {
'}';
}

public static final class ConverterImpl extends DatadogActionConverter {
public static final class ConverterImpl extends DatadogActionConverter<PipelineNodeInfoAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1());
}
}

@Override
public boolean canConvert(Class type) {
return PipelineNodeInfoAction.class == type;
public static final class ConverterV1 extends VersionedConverter<PipelineNodeInfoAction> {

private static final int VERSION = 1;

public ConverterV1() {
super(VERSION);
}

@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
PipelineNodeInfoAction action = (PipelineNodeInfoAction) source;
public void marshal(PipelineNodeInfoAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
if (action.nodeName != null) {
writeField("nodeName", action.nodeName, writer, context);
}
Expand All @@ -90,7 +95,7 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC
}

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
public PipelineNodeInfoAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
String nodeName = null;
String nodeHostname = null;
Set<String> nodeLabels = Collections.emptySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import java.util.Objects;
import org.datadog.jenkins.plugins.datadog.util.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;

public class PipelineQueueInfoAction extends DatadogPluginAction {

Expand Down Expand Up @@ -61,18 +62,22 @@ public String toString() {
'}';
}

public static final class ConverterImpl extends DatadogActionConverter {
public static final class ConverterImpl extends DatadogActionConverter<PipelineQueueInfoAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1());
}
}

@Override
public boolean canConvert(Class type) {
return PipelineQueueInfoAction.class == type;
public static final class ConverterV1 extends VersionedConverter<PipelineQueueInfoAction> {

private static final int VERSION = 1;

public ConverterV1() {
super(VERSION);
}

@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
PipelineQueueInfoAction action = (PipelineQueueInfoAction) source;
public void marshal(PipelineQueueInfoAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
if (action.queueTimeMillis != -1) {
writeField("queueTimeMillis", action.queueTimeMillis, writer, context);
}
Expand All @@ -82,7 +87,7 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC
}

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
public PipelineQueueInfoAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
long queueTimeMillis = -1;
long propagatedQueueTimeMillis = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.datadog.jenkins.plugins.datadog.traces.IdGenerator;
import org.datadog.jenkins.plugins.datadog.util.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;

/**
* This action stores mapping between IDs of {@link org.jenkinsci.plugins.workflow.graph.FlowNode}
Expand Down Expand Up @@ -78,23 +79,27 @@ public String toString() {
'}';
}

public static final class ConverterImpl extends DatadogActionConverter {
public static final class ConverterImpl extends DatadogActionConverter<TraceInfoAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1());
}
}

@Override
public boolean canConvert(Class type) {
return TraceInfoAction.class == type;
public static final class ConverterV1 extends VersionedConverter<TraceInfoAction> {

private static final int VERSION = 1;

public ConverterV1() {
super(VERSION);
}

@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
TraceInfoAction action = (TraceInfoAction) source;
public void marshal(TraceInfoAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
writeField("infoByFlowNodeId", action.spanIdByNodeId, writer, context);
}

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
public TraceInfoAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
Map<String, Long> infoByFlowNodeId = readField(reader, context, Map.class);
return new TraceInfoAction(infoByFlowNodeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import java.util.Objects;
import org.datadog.jenkins.plugins.datadog.util.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;

public class DequeueAction extends QueueInfoAction {

Expand Down Expand Up @@ -40,24 +41,28 @@ public String toString() {
return "DequeueAction{queueTimeNanos=" + queueTimeNanos + '}';
}

public static final class ConverterImpl extends DatadogActionConverter {
public static final class ConverterImpl extends DatadogActionConverter<DequeueAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1());
}
}

@Override
public boolean canConvert(Class type) {
return DequeueAction.class == type;
public static final class ConverterV1 extends VersionedConverter<DequeueAction> {

private static final int VERSION = 1;

public ConverterV1() {
super(VERSION);
}

@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
DequeueAction action = (DequeueAction) source;
public void marshal(DequeueAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
writeField("queueTimeNanos", action.queueTimeNanos, writer, context);
context.convertAnother(action.queueTimeNanos);
}

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
public DequeueAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
long queueTimeNanos = readField(reader, context, long.class);
return new DequeueAction(queueTimeNanos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import java.util.Objects;
import org.datadog.jenkins.plugins.datadog.util.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;

public class EnqueueAction extends QueueInfoAction {

Expand Down Expand Up @@ -40,23 +41,27 @@ public String toString() {
return "EnqueueAction{timestampNanos=" + timestampNanos + '}';
}

public static final class ConverterImpl extends DatadogActionConverter {
public static final class ConverterImpl extends DatadogActionConverter<EnqueueAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1());
}
}

@Override
public boolean canConvert(Class type) {
return EnqueueAction.class == type;
public static final class ConverterV1 extends VersionedConverter<EnqueueAction> {

private static final int VERSION = 1;

public ConverterV1() {
super(VERSION);
}

@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
EnqueueAction action = (EnqueueAction) source;
public void marshal(EnqueueAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
writeField("timestampNanos", action.timestampNanos, writer, context);
}

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
public EnqueueAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
long timestampNanos = readField(reader, context, long.class);
return new EnqueueAction(timestampNanos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import java.util.Objects;
import java.util.Set;
import org.datadog.jenkins.plugins.datadog.model.DatadogPluginAction;
import org.datadog.jenkins.plugins.datadog.util.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;

public class NodeInfoAction extends DatadogPluginAction {

Expand Down Expand Up @@ -66,18 +67,22 @@ public String toString() {
'}';
}

public static final class ConverterImpl extends DatadogActionConverter {
public static final class ConverterImpl extends DatadogActionConverter<NodeInfoAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1());
}
}

@Override
public boolean canConvert(Class type) {
return NodeInfoAction.class == type;
public static final class ConverterV1 extends VersionedConverter<NodeInfoAction> {

private static final int VERSION = 1;

public ConverterV1() {
super(VERSION);
}

@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
NodeInfoAction action = (NodeInfoAction) source;
public void marshal(NodeInfoAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
if (action.nodeName != null) {
writeField("nodeName", action.nodeName, writer, context);
}
Expand All @@ -93,7 +98,7 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC
}

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
public NodeInfoAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
String nodeName = null;
String nodeHostname = null;
Set<String> nodeLabels = Collections.emptySet();
Expand Down
Loading
Loading