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

Support multi-tenancy in Zeebe 8.3 #323

Merged
merged 2 commits into from
Jan 11, 2024
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<license.header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</license.header>

<!-- project dependencies -->
<version.zeebe>8.2.3</version.zeebe>
<version.zeebe>8.3.5</version.zeebe>

<version.protobuf>3.25.1</version.protobuf>
<version.protoc>3.9.1</version.protoc>
Expand Down
56 changes: 40 additions & 16 deletions src/main/java/io/zeebe/exporter/proto/RecordTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,21 @@
*/
package io.zeebe.exporter.proto;

import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.ListValue;
import com.google.protobuf.NullValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.*;
import io.camunda.zeebe.protocol.record.Record;
import io.camunda.zeebe.protocol.record.RecordType;
import io.camunda.zeebe.protocol.record.ValueType;
import io.camunda.zeebe.protocol.record.value.*;
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.*;
import io.camunda.zeebe.protocol.record.value.deployment.Process;
import io.camunda.zeebe.protocol.record.value.deployment.ProcessMetadataValue;
import io.camunda.zeebe.protocol.record.value.management.CheckpointRecordValue;
import io.zeebe.exporter.proto.Schema.RecordMetadata;
import io.zeebe.exporter.proto.Schema.VariableDocumentRecord;
import io.zeebe.exporter.proto.Schema.VariableDocumentRecord.UpdateSemantics;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -226,6 +216,8 @@ private static Schema.DeploymentRecord toDeploymentRecord(Record<DeploymentRecor
builder.addDecisionMetadata(toDecisionMetadata(decisionMetadata));
}

builder.setTenantId(toTenantId(record.getValue()));

return builder.build();
}

Expand All @@ -246,6 +238,8 @@ private static Schema.DeploymentRecord.ProcessMetadata toProcessMetadata(
.setVersion(processMetadata.getVersion())
.setProcessDefinitionKey(processMetadata.getProcessDefinitionKey())
.setChecksum(ByteString.copyFrom(processMetadata.getChecksum()))
.setIsDuplicate(processMetadata.isDuplicate())
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Good catch.

.setTenantId(toTenantId(processMetadata))
.build();
}

Expand All @@ -259,6 +253,7 @@ private static Schema.DeploymentRecord.DecisionMetadata toDecisionMetadata(
.setDecisionRequirementsId(decision.getDecisionRequirementsId())
.setDecisionRequirementsKey(decision.getDecisionRequirementsKey())
.setIsDuplicate(decision.isDuplicate())
.setTenantId(toTenantId(decision))
.build();
}

Expand All @@ -281,6 +276,7 @@ private static Schema.ProcessRecord toProcessRecord(Record<Process> record) {
.setProcessDefinitionKey(value.getProcessDefinitionKey())
.setChecksum(ByteString.copyFrom(value.getChecksum()))
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -298,6 +294,7 @@ private static Schema.IncidentRecord toIncidentRecord(Record<IncidentRecordValue
.setProcessDefinitionKey(value.getProcessDefinitionKey())
.setVariableScopeKey(value.getVariableScopeKey())
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -320,7 +317,8 @@ private static Schema.JobRecord.Builder toJobRecord(JobRecordValue value) {
.setElementInstanceKey(value.getElementInstanceKey())
.setWorkflowDefinitionVersion(value.getProcessDefinitionVersion())
.setProcessInstanceKey(value.getProcessInstanceKey())
.setProcessDefinitionKey(value.getProcessDefinitionKey());
.setProcessDefinitionKey(value.getProcessDefinitionKey())
.setTenantId(toTenantId(value));
}

private static Schema.JobBatchRecord toJobBatchRecord(Record<JobBatchRecordValue> record) {
Expand All @@ -337,6 +335,10 @@ private static Schema.JobBatchRecord toJobBatchRecord(Record<JobBatchRecordValue
builder.addAllJobKeys(value.getJobKeys());
}

if (!value.getTenantIds().isEmpty()) {
builder.addAllTenantIds(value.getTenantIds());
}

return builder
.setMaxJobsToActivate(value.getMaxJobsToActivate())
.setTimeout(value.getTimeout())
Expand All @@ -357,6 +359,7 @@ private static Schema.MessageRecord toMessageRecord(Record<MessageRecordValue> r
.setTimeToLive(value.getTimeToLive())
.setVariables(toStruct(value.getVariables()))
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -374,6 +377,7 @@ private static Schema.MessageSubscriptionRecord toMessageSubscriptionRecord(
.setVariables(toStruct(value.getVariables()))
.setIsInterrupting(value.isInterrupting())
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -391,7 +395,8 @@ private static Schema.MessageStartEventSubscriptionRecord toMessageStartEventSub
.setCorrelationKey(value.getCorrelationKey())
.setMessageKey(value.getMessageKey())
.setProcessInstanceKey(value.getProcessInstanceKey())
.setVariables(toStruct(value.getVariables()));
.setVariables(toStruct(value.getVariables()))
.setTenantId(toTenantId(value));

return builder.setMetadata(toMetadata(record)).build();
}
Expand All @@ -406,7 +411,8 @@ private static Schema.VariableRecord toVariableRecord(Record<VariableRecordValue
.setProcessDefinitionKey(value.getProcessDefinitionKey())
.setBpmnProcessId(value.getBpmnProcessId())
.setName(value.getName())
.setValue(value.getValue());
.setValue(value.getValue())
.setTenantId(toTenantId(value));

return builder.setMetadata(toMetadata(record)).build();
}
Expand All @@ -422,6 +428,7 @@ private static Schema.TimerRecord toTimerRecord(Record<TimerRecordValue> record)
.setProcessInstanceKey(value.getProcessInstanceKey())
.setProcessDefinitionKey(value.getProcessDefinitionKey())
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -441,6 +448,7 @@ private static Schema.ProcessInstanceRecord toProcessInstanceRecord(
.setParentProcessInstanceKey(value.getParentProcessInstanceKey())
.setParentElementInstanceKey(value.getParentElementInstanceKey())
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -459,6 +467,7 @@ private static Schema.ProcessMessageSubscriptionRecord toProcessMessageSubscript
.setElementId(value.getElementId())
.setIsInterrupting(value.isInterrupting())
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -473,6 +482,7 @@ private static Schema.ProcessInstanceCreationRecord toProcessInstanceCreationRec
.setProcessDefinitionKey(value.getProcessDefinitionKey())
.setVariables(toStruct(value.getVariables()))
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -485,6 +495,7 @@ private static Schema.VariableDocumentRecord toVariableDocumentRecord(
.setUpdateSemantics(toUpdateSemantics(value.getUpdateSemantics()))
.setVariables(toStruct(value.getVariables()))
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand Down Expand Up @@ -516,6 +527,7 @@ private static Schema.ProcessEventRecord toProcessEventRecord(
.setTargetElementId(value.getTargetElementId())
.setVariables(toStruct(value.getVariables()))
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -531,6 +543,7 @@ private static Schema.DecisionRecord toDecisionRecord(Record<DecisionRecordValue
.setDecisionRequirementsKey(value.getDecisionRequirementsKey())
.setIsDuplicate(value.isDuplicate())
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -542,6 +555,7 @@ private static Schema.DecisionRequirementsRecord toDecisionRequirementsRecord(
.setResource(ByteString.copyFrom(value.getResource()))
.setDecisionRequirementsMetadata(toDecisionRequirementsMetadata(value))
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -556,6 +570,7 @@ private static Schema.DecisionRequirementsMetadata toDecisionRequirementsMetadat
.setResourceName(metadataValue.getResourceName())
.setChecksum(ByteString.copyFrom(metadataValue.getChecksum()))
.setIsDuplicate(metadataValue.isDuplicate())
.setTenantId(toTenantId(metadataValue))
.build();
}

Expand Down Expand Up @@ -588,6 +603,7 @@ private static Schema.DecisionEvaluationRecord toDecisionEvaluationRecord(
.setEvaluationFailureMessage(value.getEvaluationFailureMessage())
.setFailedDecisionId(value.getFailedDecisionId())
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -612,6 +628,7 @@ private static Schema.DecisionEvaluationRecord.EvaluatedDecision toEvaluatedDeci
.setDecisionVersion(value.getDecisionVersion())
.setDecisionType(value.getDecisionType())
.setDecisionOutput(value.getDecisionOutput())
.setTenantId(toTenantId(value))
.build();
}

Expand Down Expand Up @@ -687,6 +704,7 @@ private static Schema.ProcessInstanceModificationRecord toProcessInstanceModific
.addAllActivateInstructions(activateInstructions)
.addAllTerminateInstructions(terminateInstructions)
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -705,6 +723,7 @@ private static Schema.SignalRecord toSignalRecord(Record<SignalRecordValue> reco
.setSignalName(value.getSignalName())
.setVariables(toStruct(value.getVariables()))
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand All @@ -718,6 +737,7 @@ private static Schema.SignalSubscriptionRecord toSignalSubscriptionRecord(
.setCatchEventId(value.getCatchEventId())
.setCatchEventInstanceKey(value.getCatchEventInstanceKey())
.setMetadata(toMetadata(record))
.setTenantId(toTenantId(value))
.build();
}

Expand Down Expand Up @@ -762,4 +782,8 @@ private static Value toValue(Object object) {

return builder.build();
}

private static String toTenantId(TenantOwned value) {
return Optional.ofNullable(value.getTenantId()).orElse(TenantOwned.DEFAULT_TENANT_IDENTIFIER);
}
}
Loading
Loading