From 99401d0ed14faa21ac3610448ce94d5727266f15 Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Tue, 24 May 2022 06:21:50 +0200 Subject: [PATCH] Deployment with DMN metadata (#177) * 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 --- .../exporter/proto/RecordTransformer.java | 44 +++++++++-- src/main/proto/schema.proto | 66 +++++++++------- .../exporter/proto/RecordTransformTest.java | 78 +++++++++++++++++-- 3 files changed, 146 insertions(+), 42 deletions(-) diff --git a/src/main/java/io/zeebe/exporter/proto/RecordTransformer.java b/src/main/java/io/zeebe/exporter/proto/RecordTransformer.java index b4888a0..092323c 100644 --- a/src/main/java/io/zeebe/exporter/proto/RecordTransformer.java +++ b/src/main/java/io/zeebe/exporter/proto/RecordTransformer.java @@ -218,6 +218,16 @@ private static Schema.DeploymentRecord toDeploymentRecord(Record record) { return Schema.DeploymentDistributionRecord.newBuilder() @@ -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)); @@ -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)); @@ -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()) diff --git a/src/main/proto/schema.proto b/src/main/proto/schema.proto index 74f9e7d..e3af5ae 100644 --- a/src/main/proto/schema.proto +++ b/src/main/proto/schema.proto @@ -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 { @@ -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; diff --git a/src/test/java/io/zeebe/exporter/proto/RecordTransformTest.java b/src/test/java/io/zeebe/exporter/proto/RecordTransformTest.java index 754599b..0af41a5 100644 --- a/src/test/java/io/zeebe/exporter/proto/RecordTransformTest.java +++ b/src/test/java/io/zeebe/exporter/proto/RecordTransformTest.java @@ -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; @@ -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 @@ -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()); @@ -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()); @@ -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 decisionRequirementsMetadata = new ArrayList<>(); + decisionRequirementsMetadata.add(mockDecisionRequirementsRecordValue()); + when(deploymentRecordValue.getDecisionRequirementsMetadata()) + .thenReturn(decisionRequirementsMetadata); + + final List decisionRecordValues = new ArrayList<>(); + decisionRecordValues.add(mockDecisionRecordValue()); + when(deploymentRecordValue.getDecisionsMetadata()).thenReturn(decisionRecordValues); + final List resources = new ArrayList<>(); final DeploymentResource deploymentResource = mock(DeploymentResource.class); when(deploymentResource.getResource()).thenReturn("resourceContent".getBytes());