Skip to content

Commit

Permalink
Making CDEventCreator as an abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalander Ramagiri committed Oct 18, 2023
1 parent f9fa051 commit 2eecfe0
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,50 @@

import io.cloudevents.CloudEvent;

public interface CDEventCreator {
CloudEvent createCDEvent();
public abstract class CDEventCreator {
abstract CloudEvent createCDEvent();

private String source;
private String subjectId;
private String subjectSource;
private String subjectUrl;

public CDEventCreator(String source, String subjectId, String subjectSource, String subjectUrl) {
this.source = source;
this.subjectId = subjectId;
this.subjectSource = subjectSource;
this.subjectUrl = subjectUrl;
}

public String getSource() {
return source;
}

public void setSource(String source) {
this.source = source;
}

public String getSubjectId() {
return subjectId;
}

public void setSubjectId(String subjectId) {
this.subjectId = subjectId;
}

public String getSubjectSource() {
return subjectSource;
}

public void setSubjectSource(String subjectSource) {
this.subjectSource = subjectSource;
}

public String getSubjectUrl() {
return subjectUrl;
}

public void setSubjectUrl(String subjectUrl) {
this.subjectUrl = subjectUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@
import io.cloudevents.CloudEvent;
import java.net.URI;

public class CDEventPipelineRunFinished implements CDEventCreator {
public class CDEventPipelineRunFinished extends CDEventCreator {

private String source;
private String subjectId;
private String subjectSource;
private String subjectPipelineName;
private String subjectUrl;

private String subjectError;

public CDEventPipelineRunFinished(
Expand All @@ -38,23 +33,36 @@ public CDEventPipelineRunFinished(
String executionName,
String spinnakerUrl,
String status) {
this.source = spinnakerUrl;
this.subjectId = executionId;
this.subjectSource = spinnakerUrl;
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl);
this.subjectPipelineName = executionName;
this.subjectUrl = executionUrl;
this.subjectError = status;
}

public String getSubjectPipelineName() {
return subjectPipelineName;
}

public void setSubjectPipelineName(String subjectPipelineName) {
this.subjectPipelineName = subjectPipelineName;
}

public String getSubjectError() {
return subjectError;
}

public void setSubjectError(String subjectError) {
this.subjectError = subjectError;
}

@Override
public CloudEvent createCDEvent() {
PipelineRunFinishedCDEvent cdEvent = new PipelineRunFinishedCDEvent();
cdEvent.setSource(URI.create(source));
cdEvent.setSubjectId(subjectId);
cdEvent.setSubjectSource(URI.create(subjectSource));
cdEvent.setSubjectPipelineName(subjectSource);
cdEvent.setSubjectUrl(URI.create(subjectUrl));
cdEvent.setSubjectErrors(subjectError);
cdEvent.setSource(URI.create(getSource()));
cdEvent.setSubjectId(getSubjectId());
cdEvent.setSubjectSource(URI.create(getSubjectSource()));
cdEvent.setSubjectPipelineName(getSubjectPipelineName());
cdEvent.setSubjectUrl(URI.create(getSubjectUrl()));
cdEvent.setSubjectErrors(getSubjectError());

if (subjectError.equals("complete")) {
cdEvent.setSubjectOutcome(CDEventConstants.Outcome.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,32 @@
import io.cloudevents.CloudEvent;
import java.net.URI;

public class CDEventPipelineRunQueued implements CDEventCreator {
public class CDEventPipelineRunQueued extends CDEventCreator {

private String source;
private String subjectId;
private String subjectSource;
private String subjectPipelineName;
private String subjectUrl;

public CDEventPipelineRunQueued(
String executionId, String executionUrl, String executionName, String spinnakerUrl) {
this.source = spinnakerUrl;
this.subjectId = executionId;
this.subjectSource = spinnakerUrl;
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl);
this.subjectPipelineName = executionName;
this.subjectUrl = executionUrl;
}

public String getSubjectPipelineName() {
return subjectPipelineName;
}

public void setSubjectPipelineName(String subjectPipelineName) {
this.subjectPipelineName = subjectPipelineName;
}

@Override
public CloudEvent createCDEvent() {
PipelineRunQueuedCDEvent cdEvent = new PipelineRunQueuedCDEvent();
cdEvent.setSource(URI.create(source));
cdEvent.setSubjectId(subjectId);
cdEvent.setSubjectSource(URI.create(subjectSource));
cdEvent.setSubjectPipelineName(subjectPipelineName);
cdEvent.setSubjectUrl(URI.create(subjectUrl));
cdEvent.setSource(URI.create(getSource()));
cdEvent.setSubjectId(getSubjectId());
cdEvent.setSubjectSource(URI.create(getSubjectSource()));
cdEvent.setSubjectPipelineName(getSubjectPipelineName());
cdEvent.setSubjectUrl(URI.create(getSubjectUrl()));

return CDEvents.cdEventAsCloudEvent(cdEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,32 @@
import io.cloudevents.CloudEvent;
import java.net.URI;

public class CDEventPipelineRunStarted implements CDEventCreator {
public class CDEventPipelineRunStarted extends CDEventCreator {

private String source;
private String subjectId;
private String subjectSource;
private String subjectPipelineName;
private String subjectUrl;

public CDEventPipelineRunStarted(
String executionId, String executionUrl, String executionName, String spinnakerUrl) {
this.source = spinnakerUrl;
this.subjectId = executionId;
this.subjectSource = spinnakerUrl;
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl);
this.subjectPipelineName = executionName;
this.subjectUrl = executionUrl;
}

public String getSubjectPipelineName() {
return subjectPipelineName;
}

public void setSubjectPipelineName(String subjectPipelineName) {
this.subjectPipelineName = subjectPipelineName;
}

@Override
public CloudEvent createCDEvent() {
PipelineRunStartedCDEvent cdEvent = new PipelineRunStartedCDEvent();
cdEvent.setSource(URI.create(source));
cdEvent.setSubjectId(subjectId);
cdEvent.setSubjectSource(URI.create(subjectSource));
cdEvent.setSubjectPipelineName(subjectPipelineName);
cdEvent.setSubjectUrl(URI.create(subjectUrl));
cdEvent.setSource(URI.create(getSource()));
cdEvent.setSubjectId(getSubjectId());
cdEvent.setSubjectSource(URI.create(getSubjectSource()));
cdEvent.setSubjectPipelineName(getSubjectPipelineName());
cdEvent.setSubjectUrl(URI.create(getSubjectUrl()));

return CDEvents.cdEventAsCloudEvent(cdEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
import io.cloudevents.CloudEvent;
import java.net.URI;

public class CDEventTaskRunFinished implements CDEventCreator {
public class CDEventTaskRunFinished extends CDEventCreator {

private String source;
private String subjectId;
private String subjectSource;
private String subjectTaskName;
private String subjectUrl;
private String subjectPipelineRunId;
private String subjectError;

Expand All @@ -38,29 +34,49 @@ public CDEventTaskRunFinished(
String executionName,
String spinnakerUrl,
String status) {
this.source = spinnakerUrl;
this.subjectId = executionId;
this.subjectSource = spinnakerUrl;
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl);
this.subjectTaskName = executionName;
this.subjectUrl = executionUrl;
this.subjectPipelineRunId = executionId;
this.subjectError = status;
}

public String getSubjectTaskName() {
return subjectTaskName;
}

public void setSubjectTaskName(String subjectTaskName) {
this.subjectTaskName = subjectTaskName;
}

public String getSubjectPipelineRunId() {
return subjectPipelineRunId;
}

public void setSubjectPipelineRunId(String subjectPipelineRunId) {
this.subjectPipelineRunId = subjectPipelineRunId;
}

public String getSubjectError() {
return subjectError;
}

public void setSubjectError(String subjectError) {
this.subjectError = subjectError;
}

@Override
public CloudEvent createCDEvent() {
TaskRunFinishedCDEvent cdEvent = new TaskRunFinishedCDEvent();
cdEvent.setSource(URI.create(source));

cdEvent.setSubjectId(subjectId);
cdEvent.setSubjectSource(URI.create(source));
cdEvent.setSubjectTaskName(subjectTaskName);
cdEvent.setSubjectUrl(URI.create(subjectUrl));
cdEvent.setSubjectErrors(subjectError);
cdEvent.setSubjectPipelineRunId(subjectPipelineRunId);
if (subjectError.equals("complete")) {
cdEvent.setSource(URI.create(getSource()));
cdEvent.setSubjectId(getSubjectId());
cdEvent.setSubjectSource(URI.create(getSubjectSource()));
cdEvent.setSubjectTaskName(getSubjectTaskName());
cdEvent.setSubjectUrl(URI.create(getSubjectUrl()));
cdEvent.setSubjectErrors(getSubjectError());
cdEvent.setSubjectPipelineRunId(getSubjectPipelineRunId());
if (getSubjectError().equals("complete")) {
cdEvent.setSubjectOutcome(CDEventConstants.Outcome.SUCCESS);
} else if (subjectError.equals("failed")) {
} else if (getSubjectError().equals("failed")) {
cdEvent.setSubjectOutcome(CDEventConstants.Outcome.FAILURE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,44 @@
import io.cloudevents.CloudEvent;
import java.net.URI;

public class CDEventTaskRunStarted implements CDEventCreator {
public class CDEventTaskRunStarted extends CDEventCreator {

private String source;
private String subjectId;
private String subjectSource;
private String subjectTaskName;
private String subjectUrl;
private String subjectPipelineRunId;

public CDEventTaskRunStarted(
String executionId, String executionUrl, String executionName, String spinnakerUrl) {
this.source = spinnakerUrl;
this.subjectId = executionId;
this.subjectSource = spinnakerUrl;
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl);
this.subjectTaskName = executionName;
this.subjectUrl = executionUrl;
this.subjectPipelineRunId = executionId;
}

public String getSubjectTaskName() {
return subjectTaskName;
}

public void setSubjectTaskName(String subjectTaskName) {
this.subjectTaskName = subjectTaskName;
}

public String getSubjectPipelineRunId() {
return subjectPipelineRunId;
}

public void setSubjectPipelineRunId(String subjectPipelineRunId) {
this.subjectPipelineRunId = subjectPipelineRunId;
}

@Override
public CloudEvent createCDEvent() {
TaskRunStartedCDEvent cdEvent = new TaskRunStartedCDEvent();
cdEvent.setSource(URI.create(source));
cdEvent.setSource(URI.create(getSource()));

cdEvent.setSubjectId(subjectId);
cdEvent.setSubjectSource(URI.create(subjectSource));
cdEvent.setSubjectTaskName(subjectTaskName);
cdEvent.setSubjectUrl(URI.create(subjectUrl));
cdEvent.setSubjectPipelineRunId(subjectPipelineRunId);
cdEvent.setSubjectId(getSubjectId());
cdEvent.setSubjectSource(URI.create(getSubjectSource()));
cdEvent.setSubjectTaskName(getSubjectTaskName());
cdEvent.setSubjectUrl(URI.create(getSubjectUrl()));
cdEvent.setSubjectPipelineRunId(getSubjectPipelineRunId());

return CDEvents.cdEventAsCloudEvent(cdEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public CloudEvent createCDEvent(
Optional.ofNullable(preference)
.map(p -> (String) p.get("cdEventsType"))
.orElseThrow(FieldNotFoundException::new);

log.info("Event type {} received to create CDEvent.", cdEventsType);
CDEventCreator cdEventCreator = null;
// This map can be added with more event types that Spinnaker needs to send
Expand Down

0 comments on commit 2eecfe0

Please sign in to comment.