-
Notifications
You must be signed in to change notification settings - Fork 653
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
Merged
Merged
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
483a461
feat(cdevents-notification): Implementing produce CDEvents using Noti…
3b759ee
feat(cdevents-notification): unit tests to produce CDEvents using Not…
576e7d1
feat(cdevents-notification): update variable name to cdEventsType
b943650
Merge branch 'master' into notification_cdevents
rjalander 68ff04e
Merge branch 'master' into notification_cdevents
rjalander 174e51b
Merge branch 'master' into notification_cdevents
rjalander 25e6b7a
Merge branch 'master' into notification_cdevents
rjalander 09237b9
Merge branch 'master' into notification_cdevents
rjalander de76a8c
Updating cdevents-sdk-java dependency version
02a6610
fix: unit test failure with sdk
f687deb
Merge branch 'master' into notification_cdevents
rjalander 34c40c9
Merge branch 'master' into notification_cdevents
rjalander 6ff8064
Merge branch 'master' into notification_cdevents
rjalander 71f5c8f
Merge branch 'master' into notification_cdevents
rjalander e7cf714
Merge branch 'master' into notification_cdevents
rjalander cb9e3a7
Merge branch 'master' into notification_cdevents
rjalander 6470546
using retrofit to send cdevent
ac7262a
Merge branch 'notification_cdevents' of github.com:Nordix/echo into n…
65e8b33
fixing format violations
f573844
addressing review comments
a24cabd
Interface to create CDEvents
f9fa051
update Copyright information
2eecfe0
Making CDEventCreator as an abstract
af917bb
Merge branch 'master' into notification_cdevents
rjalander 7b832ee
Merge branch 'master' into notification_cdevents
rjalander fc31963
Class name changed to BaseCDEvent and uing lombok.Getter
0ebb3ce
Merge branch 'notification_cdevents' of github.com:Nordix/echo into n…
1f783f6
addressing review comments
621da6b
addressing minor review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/cdevents/BaseCDEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
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; | ||
import lombok.Getter; | ||
|
||
public abstract class BaseCDEvent { | ||
/** | ||
* This method can be implemented to create various types of CDEvents that can return a specific | ||
* type of CDEvents in a CloudEvent format, more details on CDEvent types can be found in | ||
* Documentation at https://cdevents.dev | ||
* | ||
* @return cdEvent | ||
*/ | ||
abstract CloudEvent createCDEvent(); | ||
|
||
/** Common properties used in most of the CDEvents */ | ||
@Getter private String source; | ||
|
||
@Getter private String subjectId; | ||
@Getter private String subjectSource; | ||
@Getter private String subjectUrl; | ||
|
||
public BaseCDEvent(String source, String subjectId, String subjectSource, String subjectUrl) { | ||
this.source = source; | ||
this.subjectId = subjectId; | ||
this.subjectSource = subjectSource; | ||
this.subjectUrl = subjectUrl; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...tions/src/main/groovy/com/netflix/spinnaker/echo/cdevents/CDEventPipelineRunFinished.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
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; | ||
import lombok.Getter; | ||
|
||
public class CDEventPipelineRunFinished extends BaseCDEvent { | ||
|
||
@Getter private String subjectPipelineName; | ||
@Getter 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; | ||
} | ||
|
||
@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); | ||
} | ||
|
||
return CDEvents.cdEventAsCloudEvent(cdEvent); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...cations/src/main/groovy/com/netflix/spinnaker/echo/cdevents/CDEventPipelineRunQueued.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
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; | ||
import lombok.Getter; | ||
|
||
public class CDEventPipelineRunQueued extends BaseCDEvent { | ||
|
||
@Getter private String subjectPipelineName; | ||
|
||
public CDEventPipelineRunQueued( | ||
String executionId, String executionUrl, String executionName, String spinnakerUrl) { | ||
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl); | ||
this.subjectPipelineName = executionName; | ||
} | ||
|
||
@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); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ations/src/main/groovy/com/netflix/spinnaker/echo/cdevents/CDEventPipelineRunStarted.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
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; | ||
import lombok.Getter; | ||
|
||
public class CDEventPipelineRunStarted extends BaseCDEvent { | ||
|
||
@Getter private String subjectPipelineName; | ||
|
||
public CDEventPipelineRunStarted( | ||
String executionId, String executionUrl, String executionName, String spinnakerUrl) { | ||
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl); | ||
this.subjectPipelineName = executionName; | ||
} | ||
|
||
@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); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...fications/src/main/groovy/com/netflix/spinnaker/echo/cdevents/CDEventTaskRunFinished.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
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; | ||
import lombok.Getter; | ||
|
||
public class CDEventTaskRunFinished extends BaseCDEvent { | ||
|
||
@Getter private String subjectTaskName; | ||
@Getter private String subjectPipelineRunId; | ||
@Getter 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; | ||
} | ||
|
||
@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); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ifications/src/main/groovy/com/netflix/spinnaker/echo/cdevents/CDEventTaskRunStarted.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
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.TaskRunStartedCDEvent; | ||
import io.cloudevents.CloudEvent; | ||
import java.net.URI; | ||
import lombok.Getter; | ||
|
||
public class CDEventTaskRunStarted extends BaseCDEvent { | ||
|
||
@Getter private String subjectTaskName; | ||
@Getter private String subjectPipelineRunId; | ||
|
||
public CDEventTaskRunStarted( | ||
String executionId, String executionUrl, String executionName, String spinnakerUrl) { | ||
super(spinnakerUrl, executionId, spinnakerUrl, executionUrl); | ||
this.subjectTaskName = executionName; | ||
this.subjectPipelineRunId = executionId; | ||
} | ||
|
||
@Override | ||
public CloudEvent createCDEvent() { | ||
TaskRunStartedCDEvent cdEvent = new TaskRunStartedCDEvent(); | ||
cdEvent.setSource(URI.create(getSource())); | ||
|
||
cdEvent.setSubjectId(getSubjectId()); | ||
cdEvent.setSubjectSource(URI.create(getSubjectSource())); | ||
cdEvent.setSubjectTaskName(getSubjectTaskName()); | ||
cdEvent.setSubjectUrl(URI.create(getSubjectUrl())); | ||
cdEvent.setSubjectPipelineRunId(getSubjectPipelineRunId()); | ||
|
||
return CDEvents.cdEventAsCloudEvent(cdEvent); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
these could produce a NPE let's change them to
"complete".equals(subjectError)