Skip to content

Commit

Permalink
Merge pull request #194 from conductor-oss/core_updates
Browse files Browse the repository at this point in the history
Core updates
  • Loading branch information
v1r3n authored Jul 2, 2024
2 parents 896a12e + bf024b8 commit 17b790e
Show file tree
Hide file tree
Showing 47 changed files with 1,315 additions and 336 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ allprojects {
implementation('org.apache.logging.log4j:log4j-api')
implementation('org.apache.logging.log4j:log4j-slf4j-impl')
implementation('org.apache.logging.log4j:log4j-jul')
implementation('org.apache.logging.log4j:log4j-web')
implementation('org.apache.logging.log4j:log4j-web')
compileOnly 'org.projectlombok:lombok:1.18.34'

annotationProcessor 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'

testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('org.springframework.boot:spring-boot-starter-log4j2')
testImplementation 'junit:junit'
testImplementation "org.junit.vintage:junit-vintage-engine"
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'
}

// processes additional configuration metadata json file as described here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,44 +403,6 @@ class CassandraExecutionDAOSpec extends CassandraSpec {
eventExecutionList != null && eventExecutionList.empty
}

def "verify workflow serialization"() {
given: 'define a workflow'
String workflowId = new IDGenerator().generate()
WorkflowTask workflowTask = new WorkflowTask(taskDefinition: new TaskDef(concurrentExecLimit: 2))
WorkflowDef workflowDef = new WorkflowDef(name: UUID.randomUUID().toString(), version: 1, tasks: [workflowTask])
WorkflowModel workflow = new WorkflowModel(workflowDefinition: workflowDef, workflowId: workflowId, status: WorkflowModel.Status.RUNNING, createTime: System.currentTimeMillis())

when: 'serialize workflow'
def workflowJson = objectMapper.writeValueAsString(workflow)

then:
!workflowJson.contains('failedReferenceTaskNames')
// workflowTask
!workflowJson.contains('decisionCases')
!workflowJson.contains('defaultCase')
!workflowJson.contains('forkTasks')
!workflowJson.contains('joinOn')
!workflowJson.contains('defaultExclusiveJoinTask')
!workflowJson.contains('loopOver')
}

def "verify task serialization"() {
given: 'define a workflow and tasks for this workflow'
String workflowId = new IDGenerator().generate()
WorkflowTask workflowTask = new WorkflowTask(taskDefinition: new TaskDef(concurrentExecLimit: 2))
TaskModel task = new TaskModel(workflowInstanceId: workflowId, taskType: UUID.randomUUID().toString(), referenceTaskName: UUID.randomUUID().toString(), status: TaskModel.Status.SCHEDULED, taskId: new IDGenerator().generate(), workflowTask: workflowTask)

when: 'serialize task'
def taskJson = objectMapper.writeValueAsString(task)

then:
!taskJson.contains('decisionCases')
!taskJson.contains('defaultCase')
!taskJson.contains('forkTasks')
!taskJson.contains('joinOn')
!taskJson.contains('defaultExclusiveJoinTask')
}

def "serde of workflow with large number of tasks"() {
given: 'create a workflow and tasks for this workflow'
String workflowId = new IDGenerator().generate()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2022 Conductor Authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.conductor.annotations.protogen;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* ProtoEnum annotates an enum type that will be exposed via the GRPC API as a native Protocol
* Buffers enum.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ProtoEnum {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 Conductor Authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.conductor.annotations.protogen;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* ProtoField annotates a field inside an struct with metadata on how to expose it on its
* corresponding Protocol Buffers struct. For a field to be exposed in a ProtoBuf struct, the
* containing struct must also be annotated with a {@link ProtoMessage} or {@link ProtoEnum} tag.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ProtoField {
/**
* Mandatory. Sets the Protocol Buffer ID for this specific field. Once a field has been
* annotated with a given ID, the ID can never change to a different value or the resulting
* Protocol Buffer struct will not be backwards compatible.
*
* @return the numeric ID for the field
*/
int id();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2022 Conductor Authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.conductor.annotations.protogen;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* ProtoMessage annotates a given Java class so it becomes exposed via the GRPC API as a native
* Protocol Buffers struct. The annotated class must be a POJO.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ProtoMessage {
/**
* Sets whether the generated mapping code will contain a helper to translate the POJO for this
* class into the equivalent ProtoBuf object.
*
* @return whether this class will generate a mapper to ProtoBuf objects
*/
boolean toProto() default true;

/**
* Sets whether the generated mapping code will contain a helper to translate the ProtoBuf
* object for this class into the equivalent POJO.
*
* @return whether this class will generate a mapper from ProtoBuf objects
*/
boolean fromProto() default true;

/**
* Sets whether this is a wrapper class that will be used to encapsulate complex nested type
* interfaces. Wrapper classes are not directly exposed by the ProtoBuf API and must be mapped
* manually.
*
* @return whether this is a wrapper class
*/
boolean wrapper() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import jakarta.annotation.PostConstruct;

@Configuration
Expand All @@ -34,6 +33,5 @@ public void customizeDefaultObjectMapper() {
objectMapper.setDefaultPropertyInclusion(
JsonInclude.Value.construct(
JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS));
objectMapper.registerModule(new AfterburnerModule());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;

/**
Expand All @@ -26,6 +28,8 @@
*/
public class ObjectMapperProvider {

private static final ObjectMapper objectMapper = _getObjectMapper();

/**
* The customizations in this method are configured using {@link
* org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration}
Expand All @@ -39,14 +43,20 @@ public class ObjectMapperProvider {
* @see org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
*/
public ObjectMapper getObjectMapper() {
return objectMapper;
}

private static ObjectMapper _getObjectMapper() {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
objectMapper.setDefaultPropertyInclusion(
JsonInclude.Value.construct(
JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS));
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.registerModule(new JsonProtoModule());
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerModule(new AfterburnerModule());
return objectMapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setOwnerApp(String ownerApp) {
* @return the createTime
*/
public Long getCreateTime() {
return createTime;
return createTime == null ? 0 : createTime;
}

/**
Expand All @@ -56,7 +56,7 @@ public void setCreateTime(Long createTime) {
* @return the updateTime
*/
public Long getUpdateTime() {
return updateTime;
return updateTime == null ? 0 : updateTime;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* A base class for {@link com.netflix.conductor.common.metadata.workflow.WorkflowDef} and {@link
* com.netflix.conductor.common.metadata.tasks.TaskDef}.
*/
@Deprecated
public abstract class BaseDef extends Auditable {

private final Map<Permission, String> accessPolicy = new EnumMap<>(Permission.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2024 Conductor Authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.conductor.common.metadata;

import java.util.Map;

import com.netflix.conductor.annotations.protogen.ProtoEnum;
import com.netflix.conductor.annotations.protogen.ProtoField;
import com.netflix.conductor.annotations.protogen.ProtoMessage;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@EqualsAndHashCode(callSuper = true)
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@ProtoMessage
public class SchemaDef extends Auditable {

@ProtoEnum
public enum Type {
JSON,
AVRO,
PROTOBUF
}

@ProtoField(id = 1)
@NotNull
private String name;

@ProtoField(id = 2)
@NotNull
@Builder.Default
private int version = 1;

@ProtoField(id = 3)
@NotNull
private Type type;

// Schema definition stored here
private Map<String, Object> data;

// Externalized schema definition (eg. via AVRO, Protobuf registry)
// If using Orkes Schema registry, this points to the name of the schema in the registry
private String externalRef;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.netflix.conductor.annotations.protogen.ProtoEnum;

@ProtoEnum
@Deprecated
public enum Permission {
OWNER,
OPERATOR
Expand Down
Loading

0 comments on commit 17b790e

Please sign in to comment.