-
Notifications
You must be signed in to change notification settings - Fork 652
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
feat(cdevents-notification): Implementing produce CDEvents using Notification #1295
Changes from 25 commits
483a461
3b759ee
576e7d1
b943650
68ff04e
174e51b
25e6b7a
09237b9
de76a8c
02a6610
f687deb
34c40c9
6ff8064
71f5c8f
e7cf714
cb9e3a7
6470546
ac7262a
65e8b33
f573844
a24cabd
f9fa051
2eecfe0
af917bb
7b832ee
fc31963
0ebb3ce
1f783f6
621da6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright (C) 2023 Nordix Foundation. | ||
For a full list of individual contributors, please see the commit history. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.netflix.spinnaker.echo.cdevents; | ||
|
||
import io.cloudevents.CloudEvent; | ||
|
||
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lombok can be used here See So you'd have something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that looks good, using Lombok in other sub classes too. |
||
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright (C) 2023 Nordix Foundation. | ||
For a full list of individual contributors, please see the commit history. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.netflix.spinnaker.echo.cdevents; | ||
|
||
import dev.cdevents.CDEvents; | ||
import dev.cdevents.constants.CDEventConstants; | ||
import dev.cdevents.events.PipelineRunFinishedCDEvent; | ||
import io.cloudevents.CloudEvent; | ||
import java.net.URI; | ||
|
||
public class CDEventPipelineRunFinished extends CDEventCreator { | ||
|
||
private String subjectPipelineName; | ||
private String subjectError; | ||
|
||
public CDEventPipelineRunFinished( | ||
String executionId, | ||
String executionUrl, | ||
String executionName, | ||
String spinnakerUrl, | ||
String status) { | ||
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl); | ||
this.subjectPipelineName = executionName; | ||
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(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); | ||
} else if (subjectError.equals("failed")) { | ||
cdEvent.setSubjectOutcome(CDEventConstants.Outcome.FAILURE); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these could produce a NPE let's change them to |
||
|
||
return CDEvents.cdEventAsCloudEvent(cdEvent); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright (C) 2023 Nordix Foundation. | ||
For a full list of individual contributors, please see the commit history. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.netflix.spinnaker.echo.cdevents; | ||
|
||
import dev.cdevents.CDEvents; | ||
import dev.cdevents.events.PipelineRunQueuedCDEvent; | ||
import io.cloudevents.CloudEvent; | ||
import java.net.URI; | ||
|
||
public class CDEventPipelineRunQueued extends CDEventCreator { | ||
|
||
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(); | ||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright (C) 2023 Nordix Foundation. | ||
For a full list of individual contributors, please see the commit history. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.netflix.spinnaker.echo.cdevents; | ||
|
||
import dev.cdevents.CDEvents; | ||
import dev.cdevents.events.PipelineRunStartedCDEvent; | ||
import io.cloudevents.CloudEvent; | ||
import java.net.URI; | ||
|
||
public class CDEventPipelineRunStarted extends CDEventCreator { | ||
|
||
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(); | ||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright (C) 2023 Nordix Foundation. | ||
For a full list of individual contributors, please see the commit history. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.netflix.spinnaker.echo.cdevents; | ||
|
||
import dev.cdevents.CDEvents; | ||
import dev.cdevents.constants.CDEventConstants; | ||
import dev.cdevents.events.TaskRunFinishedCDEvent; | ||
import io.cloudevents.CloudEvent; | ||
import java.net.URI; | ||
|
||
public class CDEventTaskRunFinished extends CDEventCreator { | ||
|
||
private String subjectTaskName; | ||
private String subjectPipelineRunId; | ||
private String subjectError; | ||
|
||
public CDEventTaskRunFinished( | ||
String executionId, | ||
String executionUrl, | ||
String executionName, | ||
String spinnakerUrl, | ||
String status) { | ||
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl); | ||
this.subjectTaskName = executionName; | ||
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(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 (getSubjectError().equals("failed")) { | ||
cdEvent.setSubjectOutcome(CDEventConstants.Outcome.FAILURE); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid NPE using |
||
|
||
return CDEvents.cdEventAsCloudEvent(cdEvent); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is a little confusing.
CDEventCreator
? It's not really creating a CDEvent. It's more of aBaseCDEvent
or something of that nature. Im sure there are better names thanBaseCDEvent
, but I think I'd much prefer that overCDEventCreator
since no creating is happening here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to
BaseCDEvent