Skip to content

Cdevent merge #2

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

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added echo-pubsub-core/cdevents-sdk-java-0.0.1.jar
Binary file not shown.
1 change: 1 addition & 0 deletions echo-pubsub-core/echo-pubsub-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation "com.squareup.retrofit:retrofit"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client:1.1.0"
implementation files('cdevents-sdk-java-0.0.1.jar')
Copy link
Owner

Choose a reason for hiding this comment

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

This local file can be removed and used from maven repo once this PR is fixed, cdevents/sdk-java#9


implementation "redis.clients:jedis"
implementation "io.reactivex:rxjava"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.netflix.spinnaker.echo.pipelinetriggers.orca.OrcaService;
import com.netflix.spinnaker.echo.pipelinetriggers.orca.OrcaService.TriggerResponse;
import com.netflix.spinnaker.echo.pubsub.model.CDEvent;
import dev.cdevents.CDEventEnums;
import dev.cdevents.CDEventTypes;
import io.cloudevents.CloudEvent;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -33,11 +35,16 @@
@Slf4j
public class CDEventController {

// TODO: EventTypes Should be taken from cdevents-sdk-java -
// dev.cdevents.CDEventsEnum once integrated
public static final String CD_ARTIFACT_PACKAGED_EVENT_TYPE = "cd.artifact.packaged.v1";
public static final String CD_ARTIFACT_PUBLISHED_EVENT_TYPE = "cd.artifact.published.v1";
public static final String CD_SERVICE_DEPLOYED_EVENT_TYPE = "cd.service.deployed.v1";
public static final String CD_ARTIFACT_PACKAGED_EVENT_TYPE =
CDEventEnums.ArtifactPackagedEventV1.getEventType();
public static final String CD_ARTIFACT_PUBLISHED_EVENT_TYPE =
CDEventEnums.ArtifactPublishedEventV1.getEventType();
public static final String CD_SERVICE_DEPLOYED_EVENT_TYPE =
CDEventEnums.ServiceDeployedEventV1.getEventType();
public static final String CD_PIPELINERUN_FINISHED_EVENT_TYPE =
CDEventEnums.PipelineRunFinishedEventV1.getEventType();
public static final String CD_PIPELINERUN_STARTED_EVENT_TYPE =
CDEventEnums.PipelineRunStartedEventV1.getEventType();

private static final int retryCount = 5;

Expand Down Expand Up @@ -154,7 +161,7 @@ public ResponseEntity<Void> produceEvent() throws IOException, TimeoutException
data.setSubject("cdevent");
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
CloudEvent cloudEvent =
cdEventCreator.createArtifactEvent(
CDEventTypes.createArtifactEvent(
CD_ARTIFACT_PACKAGED_EVENT_TYPE,
"123",
"produce_artifact",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.netflix.spinnaker.echo.model.Pipeline;
import com.netflix.spinnaker.echo.pubsub.model.CDEvent;
import dev.cdevents.CDEventEnums;
import dev.cdevents.CDEventTypes;
import io.cloudevents.CloudEvent;
import io.cloudevents.core.message.MessageWriter;
import io.cloudevents.core.v03.CloudEventBuilder;
import io.cloudevents.http.HttpMessageFactory;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -26,12 +23,14 @@
@Component
public class CDEventCreator {

// TODO: EventTypes Should be taken from cdevents-sdk-java - dev.cdevents.CDEventsEnum once
// integrated
private static final String CD_PIPELINERUN_FINISHED_EVENT_TYPE = "cd.pipelinerun.finished.v1";
private static final String CD_PIPELINERUN_STARTED_EVENT_TYPE = "cd.pipelinerun.started.v1";
public static final String CD_ARTIFACT_PACKAGED_EVENT_TYPE = "cd.artifact.packaged.v1";
public static final String CD_SERVICE_DEPLOYED_EVENT_TYPE = "cd.service.deployed.v1";
private static final String CD_PIPELINERUN_FINISHED_EVENT_TYPE =
CDEventEnums.PipelineRunFinishedEventV1.getEventType();
private static final String CD_PIPELINERUN_STARTED_EVENT_TYPE =
CDEventEnums.PipelineRunStartedEventV1.getEventType();
public static final String CD_ARTIFACT_PACKAGED_EVENT_TYPE =
CDEventEnums.ArtifactPackagedEventV1.getEventType();
public static final String CD_SERVICE_DEPLOYED_EVENT_TYPE =
CDEventEnums.ServiceDeployedEventV1.getEventType();

@Autowired ObjectMapper objectMapper;

Expand All @@ -48,10 +47,8 @@ public void createServiceDeployedEvent(Pipeline pipeline, String contextId, Stri
data.setContextId(contextId);
data.setTriggerId(triggerId);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
// TODO : will be invoked from sdk-java later -
// dev.cdevents.CDEventTypes.createPipelineRunEvent();
CloudEvent cloudEvent =
createServiceEvent(
CDEventTypes.createServiceEvent(
CD_SERVICE_DEPLOYED_EVENT_TYPE,
"serviceId",
"poc",
Expand All @@ -68,10 +65,8 @@ public CloudEvent createPipelineRunStartedEvent() throws IOException {
data.setPipelineId("123");
data.setSubject("PipelineRunStarted");
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
// TODO : will be invoked from sdk-java later -
// dev.cdevents.CDEventTypes.createPipelineRunEvent();
CloudEvent cloudEvent =
createPipelineRunEvent(
CDEventTypes.createPipelineRunEvent(
CD_PIPELINERUN_STARTED_EVENT_TYPE,
"pipelineRunId",
"pipelineRunName",
Expand All @@ -90,10 +85,8 @@ public void createPipelineRunFinishedEvent() throws IOException {
data.setPipelineId("123");
data.setSubject("PipelineRunFinished");
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
// TODO : will be invoked from sdk-java later -
// dev.cdevents.CDEventTypes.createPipelineRunEvent();
CloudEvent cloudEvent =
createPipelineRunEvent(
CDEventTypes.createPipelineRunEvent(
CD_PIPELINERUN_FINISHED_EVENT_TYPE,
"pipelineRunId",
"pipelineRunName",
Expand All @@ -111,9 +104,8 @@ public void createArtifactPackagedEvent() throws IOException {
data.setPipelineId("123");
data.setSubject("ArtifactPackaged");
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
// TODO : will be invoked from sdk-java later - dev.cdevents.CDEventTypes.createArtifactEvent();
CloudEvent cloudEvent =
createArtifactEvent(
CDEventTypes.createArtifactEvent(
CD_ARTIFACT_PACKAGED_EVENT_TYPE,
"artifactId",
"artifactName",
Expand Down Expand Up @@ -156,70 +148,4 @@ private MessageWriter createMessageWriter(HttpURLConnection httpUrlConnection) {
}
});
}

// TODO : will be removed once after cdevents-sdk-java integrated to echo project
public static CloudEvent createServiceEvent(
final String serviceEventType,
final String serviceId,
final String serviceName,
final String serviceVersion,
final String serviceData) {
CloudEvent ceToSend =
buildCloudEvent(serviceEventType, serviceData)
.withExtension("serviceid", serviceId)
.withExtension("servicename", serviceName)
.withExtension("serviceversion", serviceVersion)
.build();
return ceToSend;
}

// TODO : will be removed once after cdevents-sdk-java integrated to echo project
public CloudEvent createArtifactEvent(
final String artifactEventType,
final String artifactId,
final String artifactName,
final String artifactVersion,
final String artifactData) {
CloudEvent ceToSend =
buildCloudEvent(artifactEventType, artifactData)
.withExtension("artifactid", artifactId)
.withExtension("artifactname", artifactName)
.withExtension("artifactversion", artifactVersion)
.build();
return ceToSend;
}

// TODO : will be removed once after cdevents-sdk-java integrated to echo project
private static CloudEvent createPipelineRunEvent(
final String pipelineRunEventType,
final String pipelineRunId,
final String pipelineRunName,
final String pipelineRunStatus,
final String pipelineRunURL,
final String pipelineRunErrors,
final String pipelineRunData) {
CloudEvent ceToSend =
buildCloudEvent(pipelineRunEventType, pipelineRunData)
.withExtension("pipelinerunid", pipelineRunId)
.withExtension("pipelinerunname", pipelineRunName)
.withExtension("pipelinerunstatus", pipelineRunStatus)
.withExtension("pipelinerunurl", pipelineRunURL)
.withExtension("pipelinerunerrors", pipelineRunErrors)
.build();
return ceToSend;
}

// TODO : will be removed once after cdevents-sdk-java integrated to echo project
private static CloudEventBuilder buildCloudEvent(final String eventType, final String eventData) {
CloudEventBuilder ceBuilder =
new CloudEventBuilder()
.withId(UUID.randomUUID().toString())
.withSource(URI.create("cdevents-sdk-java"))
.withType(eventType)
// TODO: fix to set ContentType in cdevents-sdk-java
.withDataContentType("application/json; charset=UTF-8")
.withData(eventData.getBytes(StandardCharsets.UTF_8))
.withTime(OffsetDateTime.now());
return ceBuilder;
}
}