Skip to content

Commit

Permalink
Class name changed to BaseCDEvent and uing lombok.Getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalander Ramagiri committed Oct 24, 2023
1 parent 2eecfe0 commit fc31963
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,20 @@
package com.netflix.spinnaker.echo.cdevents;

import io.cloudevents.CloudEvent;
import lombok.Getter;

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

private String source;
private String subjectId;
private String subjectSource;
private String subjectUrl;
@Getter private String source;
@Getter private String subjectId;
@Getter private String subjectSource;
@Getter private String subjectUrl;

public CDEventCreator(String source, String subjectId, String subjectSource, String subjectUrl) {
public BaseCDEvent(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 @@ -21,11 +21,12 @@
import dev.cdevents.events.PipelineRunFinishedCDEvent;
import io.cloudevents.CloudEvent;
import java.net.URI;
import lombok.Getter;

public class CDEventPipelineRunFinished extends CDEventCreator {
public class CDEventPipelineRunFinished extends BaseCDEvent {

private String subjectPipelineName;
private String subjectError;
@Getter private String subjectPipelineName;
@Getter private String subjectError;

public CDEventPipelineRunFinished(
String executionId,
Expand All @@ -38,22 +39,6 @@ public CDEventPipelineRunFinished(
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,18 @@
import dev.cdevents.events.PipelineRunQueuedCDEvent;
import io.cloudevents.CloudEvent;
import java.net.URI;
import lombok.Getter;

public class CDEventPipelineRunQueued extends CDEventCreator {
public class CDEventPipelineRunQueued extends BaseCDEvent {

private String subjectPipelineName;
@Getter private String subjectPipelineName;

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

public String getSubjectPipelineName() {
return subjectPipelineName;
}

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

@Override
public CloudEvent createCDEvent() {
PipelineRunQueuedCDEvent cdEvent = new PipelineRunQueuedCDEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,18 @@
import dev.cdevents.events.PipelineRunStartedCDEvent;
import io.cloudevents.CloudEvent;
import java.net.URI;
import lombok.Getter;

public class CDEventPipelineRunStarted extends CDEventCreator {
public class CDEventPipelineRunStarted extends BaseCDEvent {

private String subjectPipelineName;
@Getter private String subjectPipelineName;

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

public String getSubjectPipelineName() {
return subjectPipelineName;
}

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

@Override
public CloudEvent createCDEvent() {
PipelineRunStartedCDEvent cdEvent = new PipelineRunStartedCDEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import dev.cdevents.events.TaskRunFinishedCDEvent;
import io.cloudevents.CloudEvent;
import java.net.URI;
import lombok.Getter;

public class CDEventTaskRunFinished extends CDEventCreator {
public class CDEventTaskRunFinished extends BaseCDEvent {

private String subjectTaskName;
private String subjectPipelineRunId;
private String subjectError;
@Getter private String subjectTaskName;
@Getter private String subjectPipelineRunId;
@Getter private String subjectError;

public CDEventTaskRunFinished(
String executionId,
Expand All @@ -40,30 +41,6 @@ public CDEventTaskRunFinished(
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import dev.cdevents.events.TaskRunStartedCDEvent;
import io.cloudevents.CloudEvent;
import java.net.URI;
import lombok.Getter;

public class CDEventTaskRunStarted extends CDEventCreator {
public class CDEventTaskRunStarted extends BaseCDEvent {

private String subjectTaskName;
private String subjectPipelineRunId;
@Getter private String subjectTaskName;
@Getter private String subjectPipelineRunId;

public CDEventTaskRunStarted(
String executionId, String executionUrl, String executionName, String spinnakerUrl) {
Expand All @@ -33,22 +34,6 @@ public CDEventTaskRunStarted(
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public CloudEvent createCDEvent(
.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
Map<String, CDEventCreator> cdEventsMap =
BaseCDEvent cdEvent = null;
// This map will be updated to add more event types that Spinnaker needs to send
Map<String, BaseCDEvent> cdEventsMap =
Map.of(
CDEventTypes.PipelineRunQueuedEvent.getEventType(),
new CDEventPipelineRunQueued(
Expand All @@ -92,19 +92,19 @@ public CloudEvent createCDEvent(
executionId, executionUrl, executionName, spinnakerUrl, status));
for (String keyType : cdEventsMap.keySet()) {
if (keyType.contains(cdEventsType)) {
cdEventCreator = cdEventsMap.get(keyType);
cdEvent = cdEventsMap.get(keyType);
break;
}
}

if (cdEventCreator == null) {
if (cdEvent == null) {
log.error("No mapping event type found for {}", cdEventsType);
log.error(
"The event type should be an event or substring of an event from the list of event types {}",
cdEventsMap.keySet());
throw new CDEventsException("No mapping eventType found to create CDEvent");
} else {
return cdEventCreator.createCDEvent();
return cdEvent.createCDEvent();
}
}
}

0 comments on commit fc31963

Please sign in to comment.