Skip to content

Commit

Permalink
Deployment with DMN metadata (#177)
Browse files Browse the repository at this point in the history
* feat: deployment with DMN

* extend deployment record with deployed decision requirements and decision metadata

* feat: add duplicate property of process metadata

* refactor: nest DMN messages into parent messages

* move the definition of some DMN related gRPC messages into the message where they are used
  • Loading branch information
saig0 authored May 24, 2022
1 parent c866af2 commit 99401d0
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 42 deletions.
44 changes: 36 additions & 8 deletions src/main/java/io/zeebe/exporter/proto/RecordTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ private static Schema.DeploymentRecord toDeploymentRecord(Record<DeploymentRecor
builder.addProcessMetadata(toProcessMetadata(processMetadata));
}

for (DecisionRequirementsMetadataValue decisionRequirementsMetadata :
record.getValue().getDecisionRequirementsMetadata()) {
builder.addDecisionRequirementsMetadata(
toDecisionRequirementsMetadata(decisionRequirementsMetadata));
}

for (DecisionRecordValue decisionMetadata : record.getValue().getDecisionsMetadata()) {
builder.addDecisionMetadata(toDecisionMetadata(decisionMetadata));
}

return builder.build();
}

Expand All @@ -241,6 +251,19 @@ private static Schema.DeploymentRecord.ProcessMetadata toProcessMetadata(
.build();
}

private static Schema.DeploymentRecord.DecisionMetadata toDecisionMetadata(
DecisionRecordValue decision) {
return Schema.DeploymentRecord.DecisionMetadata.newBuilder()
.setDecisionId(decision.getDecisionId())
.setDecisionKey(decision.getDecisionKey())
.setVersion(decision.getVersion())
.setDecisionName(decision.getDecisionName())
.setDecisionRequirementsId(decision.getDecisionRequirementsId())
.setDecisionRequirementsKey(decision.getDecisionRequirementsKey())
.setIsDuplicate(decision.isDuplicate())
.build();
}

private static Schema.DeploymentDistributionRecord toDeploymentDistributionRecord(
Record<DeploymentDistributionRecordValue> record) {
return Schema.DeploymentDistributionRecord.newBuilder()
Expand Down Expand Up @@ -568,8 +591,10 @@ private static Schema.DecisionEvaluationRecord toDecisionEvaluationRecord(
.build();
}

private static Schema.EvaluatedDecision toEvaluatedDecision(EvaluatedDecisionValue value) {
final Schema.EvaluatedDecision.Builder builder = Schema.EvaluatedDecision.newBuilder();
private static Schema.DecisionEvaluationRecord.EvaluatedDecision toEvaluatedDecision(
EvaluatedDecisionValue value) {
final Schema.DecisionEvaluationRecord.EvaluatedDecision.Builder builder =
Schema.DecisionEvaluationRecord.EvaluatedDecision.newBuilder();
if (!value.getEvaluatedInputs().isEmpty()) {
for (EvaluatedInputValue item : value.getEvaluatedInputs()) {
builder.addEvaluatedInputs(toEvaluatedInput(item));
Expand All @@ -590,8 +615,9 @@ private static Schema.EvaluatedDecision toEvaluatedDecision(EvaluatedDecisionVal
.build();
}

private static Schema.MatchedRule toMatchedRule(MatchedRuleValue value) {
final Schema.MatchedRule.Builder builder = Schema.MatchedRule.newBuilder();
private static Schema.DecisionEvaluationRecord.MatchedRule toMatchedRule(MatchedRuleValue value) {
final Schema.DecisionEvaluationRecord.MatchedRule.Builder builder =
Schema.DecisionEvaluationRecord.MatchedRule.newBuilder();
if (!value.getEvaluatedOutputs().isEmpty()) {
for (EvaluatedOutputValue item : value.getEvaluatedOutputs()) {
builder.addEvaluatedOutputs(toEvaluatedOutput(item));
Expand All @@ -600,16 +626,18 @@ private static Schema.MatchedRule toMatchedRule(MatchedRuleValue value) {
return builder.setRuleId(value.getRuleId()).setRuleIndex(value.getRuleIndex()).build();
}

private static Schema.EvaluatedOutput toEvaluatedOutput(EvaluatedOutputValue value) {
return Schema.EvaluatedOutput.newBuilder()
private static Schema.DecisionEvaluationRecord.EvaluatedOutput toEvaluatedOutput(
EvaluatedOutputValue value) {
return Schema.DecisionEvaluationRecord.EvaluatedOutput.newBuilder()
.setOutputId(value.getOutputId())
.setOutputName(value.getOutputName())
.setOutputValue(value.getOutputValue())
.build();
}

private static Schema.EvaluatedInput toEvaluatedInput(EvaluatedInputValue value) {
return Schema.EvaluatedInput.newBuilder()
private static Schema.DecisionEvaluationRecord.EvaluatedInput toEvaluatedInput(
EvaluatedInputValue value) {
return Schema.DecisionEvaluationRecord.EvaluatedInput.newBuilder()
.setInputId(value.getInputId())
.setInputValue(value.getInputValue())
.setInputName(value.getInputName())
Expand Down
66 changes: 40 additions & 26 deletions src/main/proto/schema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,24 @@ message DeploymentRecord {
int64 processDefinitionKey = 3;
string resourceName = 5;
string checksum = 6;
bool isDuplicate = 7;
}

message DecisionMetadata {
string decisionId = 1;
int32 version = 2;
int64 decisionKey = 3;
string decisionName = 4;
string decisionRequirementsId = 5;
int64 decisionRequirementsKey = 6;
bool isDuplicate = 7;
}

RecordMetadata metadata = 1;
repeated Resource resources = 2;
repeated ProcessMetadata processMetadata = 3;
repeated DecisionRequirementsMetadata decisionRequirementsMetadata = 4;
repeated DecisionMetadata decisionMetadata = 5;
}

message DeploymentDistributionRecord {
Expand Down Expand Up @@ -315,36 +328,37 @@ message DecisionRequirementsRecord {
bytes resource = 3;
}

message EvaluatedInput {
string inputId = 1;
string inputName = 2;
string inputValue = 3;
}
message DecisionEvaluationRecord {

message EvaluatedOutput {
string outputId = 1;
string outputName = 2;
string outputValue = 3;
}
message EvaluatedDecision {
string decisionId = 1;
string decisionName = 2;
int64 decisionKey = 3;
int64 decisionVersion = 4;
string decisionType = 5;
string decisionOutput = 6;
repeated EvaluatedInput evaluatedInputs = 7;
repeated MatchedRule matchedRules = 8;
}

message MatchedRule {
string ruleId = 1;
int32 ruleIndex = 2;
repeated EvaluatedOutput evaluatedOutputs = 3;
}
message MatchedRule {
string ruleId = 1;
int32 ruleIndex = 2;
repeated EvaluatedOutput evaluatedOutputs = 3;
}

message EvaluatedDecision {
string decisionId = 1;
string decisionName = 2;
int64 decisionKey = 3;
int64 decisionVersion = 4;
string decisionType = 5;
string decisionOutput = 6;
repeated EvaluatedInput evaluatedInputs = 7;
repeated MatchedRule matchedRules = 8;
}
message EvaluatedInput {
string inputId = 1;
string inputName = 2;
string inputValue = 3;
}

message EvaluatedOutput {
string outputId = 1;
string outputName = 2;
string outputValue = 3;
}

message DecisionEvaluationRecord {
RecordMetadata metadata = 1;
int64 decisionKey = 2;
string decisionId = 3;
Expand Down
78 changes: 70 additions & 8 deletions src/test/java/io/zeebe/exporter/proto/RecordTransformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import io.camunda.zeebe.protocol.record.value.VariableDocumentUpdateSemantic;
import io.camunda.zeebe.protocol.record.value.VariableRecordValue;
import io.camunda.zeebe.protocol.record.value.deployment.DecisionRecordValue;
import io.camunda.zeebe.protocol.record.value.deployment.DecisionRequirementsMetadataValue;
import io.camunda.zeebe.protocol.record.value.deployment.DecisionRequirementsRecordValue;
import io.camunda.zeebe.protocol.record.value.deployment.DeploymentResource;
import io.camunda.zeebe.protocol.record.value.deployment.Process;
Expand Down Expand Up @@ -130,6 +131,51 @@ public void shouldTransformDeployment() {
assertThat(processMetadata.getProcessDefinitionKey()).isEqualTo(4L);
assertThat(processMetadata.getVersion()).isEqualTo(1);
assertThat(processMetadata.getChecksum()).isEqualTo("checksum");
assertThat(processMetadata.getIsDuplicate()).isFalse();

final var decisionRequirementsMetadataList = deployment.getDecisionRequirementsMetadataList();
assertThat(decisionRequirementsMetadataList).hasSize(1);

final var transformedDecisionRequirementsMetadata = decisionRequirementsMetadataList.get(0);
final var decisionRequirementsMetadata =
deploymentRecordValue.getDecisionRequirementsMetadata().get(0);

assertThat(transformedDecisionRequirementsMetadata.getDecisionRequirementsKey())
.isEqualTo(decisionRequirementsMetadata.getDecisionRequirementsKey());
assertThat(transformedDecisionRequirementsMetadata.getDecisionRequirementsId())
.isEqualTo(decisionRequirementsMetadata.getDecisionRequirementsId());
assertThat(transformedDecisionRequirementsMetadata.getDecisionRequirementsName())
.isEqualTo(decisionRequirementsMetadata.getDecisionRequirementsName());
assertThat(transformedDecisionRequirementsMetadata.getDecisionRequirementsVersion())
.isEqualTo(decisionRequirementsMetadata.getDecisionRequirementsVersion());
assertThat(transformedDecisionRequirementsMetadata.getNamespace())
.isEqualTo(decisionRequirementsMetadata.getNamespace());
assertThat(transformedDecisionRequirementsMetadata.getResourceName())
.isEqualTo(decisionRequirementsMetadata.getResourceName());
assertThat(transformedDecisionRequirementsMetadata.getChecksum().getBytes())
.isEqualTo(decisionRequirementsMetadata.getChecksum());
assertThat(transformedDecisionRequirementsMetadata.getIsDuplicate())
.isEqualTo(decisionRequirementsMetadata.isDuplicate());

final var decisionMetadataList = deployment.getDecisionMetadataList();
assertThat(decisionMetadataList).hasSize(1);

final var transformedDecisionMetadata = decisionMetadataList.get(0);
final var decisionMetadata = deploymentRecordValue.getDecisionsMetadata().get(0);

assertThat(transformedDecisionMetadata.getDecisionRequirementsKey())
.isEqualTo(decisionMetadata.getDecisionRequirementsKey());
assertThat(transformedDecisionMetadata.getDecisionRequirementsId())
.isEqualTo(decisionMetadata.getDecisionRequirementsId());
assertThat(transformedDecisionMetadata.getVersion()).isEqualTo(decisionMetadata.getVersion());
assertThat(transformedDecisionMetadata.getDecisionId())
.isEqualTo(decisionMetadata.getDecisionId());
assertThat(transformedDecisionMetadata.getDecisionName())
.isEqualTo(decisionMetadata.getDecisionName());
assertThat(transformedDecisionMetadata.getDecisionKey())
.isEqualTo(decisionMetadata.getDecisionKey());
assertThat(transformedDecisionMetadata.getIsDuplicate())
.isEqualTo(decisionMetadata.isDuplicate());
}

@Test
Expand Down Expand Up @@ -676,13 +722,14 @@ public void shouldTransformDecisionEvaluationRecord() {

assertThat(transformedRecord.getEvaluatedDecisionsList()).hasSize(1);
assertThat(recordValue.getEvaluatedDecisions()).hasSize(1);
final Schema.EvaluatedDecision evaluatedDecision =
final Schema.DecisionEvaluationRecord.EvaluatedDecision evaluatedDecision =
transformedRecord.getEvaluatedDecisionsList().get(0);
assertEvaluatedDecision(evaluatedDecision, recordValue.getEvaluatedDecisions().get(0));
}

private void assertEvaluatedDecision(
final Schema.EvaluatedDecision transformedRecord, final EvaluatedDecisionValue recordValue) {
final Schema.DecisionEvaluationRecord.EvaluatedDecision transformedRecord,
final EvaluatedDecisionValue recordValue) {
assertThat(transformedRecord.getDecisionId()).isEqualTo(recordValue.getDecisionId());
assertThat(transformedRecord.getDecisionName()).isEqualTo(recordValue.getDecisionName());
assertThat(transformedRecord.getDecisionKey()).isEqualTo(recordValue.getDecisionKey());
Expand All @@ -692,36 +739,41 @@ private void assertEvaluatedDecision(

assertThat(transformedRecord.getEvaluatedInputsList()).hasSize(1);
assertThat(recordValue.getEvaluatedInputs()).hasSize(1);
final Schema.EvaluatedInput evaluatedInput = transformedRecord.getEvaluatedInputsList().get(0);
final Schema.DecisionEvaluationRecord.EvaluatedInput evaluatedInput =
transformedRecord.getEvaluatedInputsList().get(0);
assertEvaluatedInput(evaluatedInput, recordValue.getEvaluatedInputs().get(0));

assertThat(transformedRecord.getMatchedRulesList()).hasSize(1);
assertThat(recordValue.getMatchedRules()).hasSize(1);
final Schema.MatchedRule matchedRule = transformedRecord.getMatchedRulesList().get(0);
final Schema.DecisionEvaluationRecord.MatchedRule matchedRule =
transformedRecord.getMatchedRulesList().get(0);
assertMatchedRule(matchedRule, recordValue.getMatchedRules().get(0));
}

private void assertMatchedRule(
final Schema.MatchedRule transformedRecord, final MatchedRuleValue recordValue) {
final Schema.DecisionEvaluationRecord.MatchedRule transformedRecord,
final MatchedRuleValue recordValue) {
assertThat(transformedRecord.getRuleId()).isEqualTo(recordValue.getRuleId());
assertThat(transformedRecord.getRuleIndex()).isEqualTo(recordValue.getRuleIndex());

assertThat(transformedRecord.getEvaluatedOutputsList()).hasSize(1);
assertThat(recordValue.getEvaluatedOutputs()).hasSize(1);
final Schema.EvaluatedOutput evaluatedOutput =
final Schema.DecisionEvaluationRecord.EvaluatedOutput evaluatedOutput =
transformedRecord.getEvaluatedOutputsList().get(0);
assertEvaluatedOutput(evaluatedOutput, recordValue.getEvaluatedOutputs().get(0));
}

private void assertEvaluatedOutput(
final Schema.EvaluatedOutput transformedRecord, final EvaluatedOutputValue recordValue) {
final Schema.DecisionEvaluationRecord.EvaluatedOutput transformedRecord,
final EvaluatedOutputValue recordValue) {
assertThat(transformedRecord.getOutputId()).isEqualTo(recordValue.getOutputId());
assertThat(transformedRecord.getOutputName()).isEqualTo(recordValue.getOutputName());
assertThat(transformedRecord.getOutputValue()).isEqualTo(recordValue.getOutputValue());
}

private void assertEvaluatedInput(
final Schema.EvaluatedInput transformedRecord, final EvaluatedInputValue recordValue) {
final Schema.DecisionEvaluationRecord.EvaluatedInput transformedRecord,
final EvaluatedInputValue recordValue) {
assertThat(transformedRecord.getInputId()).isEqualTo(recordValue.getInputId());
assertThat(transformedRecord.getInputName()).isEqualTo(recordValue.getInputName());
assertThat(transformedRecord.getInputValue()).isEqualTo(recordValue.getInputValue());
Expand Down Expand Up @@ -874,10 +926,20 @@ private DeploymentRecordValue mockDeploymentRecordValue() {
when(processMetadata.getVersion()).thenReturn(1);
when(processMetadata.getProcessDefinitionKey()).thenReturn(4L);
when(processMetadata.getChecksum()).thenReturn("checksum".getBytes());
when(processMetadata.isDuplicate()).thenReturn(false);
workflows.add(processMetadata);

when(deploymentRecordValue.getProcessesMetadata()).thenReturn(workflows);

final List<DecisionRequirementsMetadataValue> decisionRequirementsMetadata = new ArrayList<>();
decisionRequirementsMetadata.add(mockDecisionRequirementsRecordValue());
when(deploymentRecordValue.getDecisionRequirementsMetadata())
.thenReturn(decisionRequirementsMetadata);

final List<DecisionRecordValue> decisionRecordValues = new ArrayList<>();
decisionRecordValues.add(mockDecisionRecordValue());
when(deploymentRecordValue.getDecisionsMetadata()).thenReturn(decisionRecordValues);

final List<DeploymentResource> resources = new ArrayList<>();
final DeploymentResource deploymentResource = mock(DeploymentResource.class);
when(deploymentResource.getResource()).thenReturn("resourceContent".getBytes());
Expand Down

0 comments on commit 99401d0

Please sign in to comment.