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

Core updates #194

Merged
merged 10 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
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"() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these test removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it compared specific serialization for JSON like removing empty values etc - this is likely to break and is breaking after object mapper changes. Not relevant to the feature but I guess was added in the past for some unknown reason.

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());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this module removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Found issues with JDK17 + SB3 and other dependencies.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

/**
* A Factory class for creating a customized {@link ObjectMapper}. This is only used by the
Expand All @@ -26,6 +27,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,15 +42,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 AfterburnerModule());
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
}
}
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
Loading