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

feat(cdevents-notification): Implementing produce CDEvents using Notification #1295

Merged
merged 29 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 21 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…
rjalander May 15, 2023
3b759ee
feat(cdevents-notification): unit tests to produce CDEvents using Not…
rjalander May 16, 2023
576e7d1
feat(cdevents-notification): update variable name to cdEventsType
rjalander May 16, 2023
b943650
Merge branch 'master' into notification_cdevents
rjalander May 22, 2023
68ff04e
Merge branch 'master' into notification_cdevents
rjalander May 26, 2023
174e51b
Merge branch 'master' into notification_cdevents
rjalander Jun 16, 2023
25e6b7a
Merge branch 'master' into notification_cdevents
rjalander Jul 13, 2023
09237b9
Merge branch 'master' into notification_cdevents
rjalander Jul 24, 2023
de76a8c
Updating cdevents-sdk-java dependency version
rjalander Jul 26, 2023
02a6610
fix: unit test failure with sdk
rjalander Jul 26, 2023
f687deb
Merge branch 'master' into notification_cdevents
rjalander Aug 9, 2023
34c40c9
Merge branch 'master' into notification_cdevents
rjalander Aug 11, 2023
6ff8064
Merge branch 'master' into notification_cdevents
rjalander Aug 14, 2023
71f5c8f
Merge branch 'master' into notification_cdevents
rjalander Aug 28, 2023
e7cf714
Merge branch 'master' into notification_cdevents
rjalander Sep 29, 2023
cb9e3a7
Merge branch 'master' into notification_cdevents
rjalander Oct 12, 2023
6470546
using retrofit to send cdevent
rjalander Oct 12, 2023
ac7262a
Merge branch 'notification_cdevents' of github.com:Nordix/echo into n…
rjalander Oct 12, 2023
65e8b33
fixing format violations
rjalander Oct 12, 2023
f573844
addressing review comments
rjalander Oct 13, 2023
a24cabd
Interface to create CDEvents
rjalander Oct 16, 2023
f9fa051
update Copyright information
rjalander Oct 16, 2023
2eecfe0
Making CDEventCreator as an abstract
rjalander Oct 18, 2023
af917bb
Merge branch 'master' into notification_cdevents
rjalander Oct 18, 2023
7b832ee
Merge branch 'master' into notification_cdevents
rjalander Oct 23, 2023
fc31963
Class name changed to BaseCDEvent and uing lombok.Getter
rjalander Oct 24, 2023
0ebb3ce
Merge branch 'notification_cdevents' of github.com:Nordix/echo into n…
rjalander Oct 24, 2023
1f783f6
addressing review comments
rjalander Oct 24, 2023
621da6b
addressing minor review comments
rjalander Oct 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions echo-notifications/echo-notifications.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies {
implementation "org.jsoup:jsoup:1.8.3"
implementation "com.atlassian.commonmark:commonmark:0.9.0"
implementation "org.codehaus.groovy:groovy-json"
implementation "io.cloudevents:cloudevents-http-basic:2.5.0"
implementation "io.cloudevents:cloudevents-json-jackson:2.5.0"
implementation ("dev.cdevents:cdevents-sdk-java:0.1.2")
testImplementation("com.icegreen:greenmail:1.5.14") {
exclude group: "com.sun.mail", module: "javax.mail"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 Netflix, Inc.
*
* 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.
*/

package com.netflix.spinnaker.echo.cdevents;

import io.cloudevents.CloudEvent;

public interface CDEventCreator {
CloudEvent createCDEvent();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2023 Netflix, Inc.
*
* 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.
*/

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 implements CDEventCreator {

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

private String subjectError;

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

@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);

if (subjectError.equals("complete")) {
cdEvent.setSubjectOutcome(CDEventConstants.Outcome.SUCCESS);
} else if (subjectError.equals("failed")) {
cdEvent.setSubjectOutcome(CDEventConstants.Outcome.FAILURE);
}
Copy link
Member

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)


return CDEvents.cdEventAsCloudEvent(cdEvent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2023 Netflix, Inc.
*
* 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.
*/

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 implements 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;
this.subjectPipelineName = executionName;
this.subjectUrl = executionUrl;
}

@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));

return CDEvents.cdEventAsCloudEvent(cdEvent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2023 Netflix, Inc.
*
* 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.
*/

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 implements 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;
this.subjectPipelineName = executionName;
this.subjectUrl = executionUrl;
}

@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));

return CDEvents.cdEventAsCloudEvent(cdEvent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2023 Netflix, Inc.
*
* 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.
*/

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 implements CDEventCreator {

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

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

@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.setSubjectOutcome(CDEventConstants.Outcome.SUCCESS);
} else if (subjectError.equals("failed")) {
cdEvent.setSubjectOutcome(CDEventConstants.Outcome.FAILURE);
}

return CDEvents.cdEventAsCloudEvent(cdEvent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 Netflix, Inc.
*
* 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.
*/

package com.netflix.spinnaker.echo.cdevents;

import dev.cdevents.CDEvents;
import dev.cdevents.events.TaskRunStartedCDEvent;
import io.cloudevents.CloudEvent;
import java.net.URI;

public class CDEventTaskRunStarted implements CDEventCreator {

private String source;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably move a lot of these to some base CDEvent class, since I imagine some of these will always be required for all CDEventCreators.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, making CDEventCreator class as an abstract and moving the common properties to this class

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;
this.subjectTaskName = executionName;
this.subjectUrl = executionUrl;
this.subjectPipelineRunId = executionId;
}

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

cdEvent.setSubjectId(subjectId);
cdEvent.setSubjectSource(URI.create(subjectSource));
cdEvent.setSubjectTaskName(subjectTaskName);
cdEvent.setSubjectUrl(URI.create(subjectUrl));
cdEvent.setSubjectPipelineRunId(subjectPipelineRunId);

return CDEvents.cdEventAsCloudEvent(cdEvent);
}
}