-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zeebe): add multi-tenant support to workers (#176)
adds tenantIds: string[] to stream and polling worker config fixes #171
- Loading branch information
Showing
8 changed files
with
260 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/__tests__/testdata/multi-tenant-stream-worker-test.bpmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1o5c8zw" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0"> | ||
<bpmn:process id="multi-tenant-stream-worker-test" name="Multi-tenant Stream Worker Test" isExecutable="true"> | ||
<bpmn:startEvent id="StartEvent_1" name="Start multi-tenancy worker test"> | ||
<bpmn:outgoing>Flow_0r8p543</bpmn:outgoing> | ||
</bpmn:startEvent> | ||
<bpmn:sequenceFlow id="Flow_0r8p543" sourceRef="StartEvent_1" targetRef="Activity_1an5aay" /> | ||
<bpmn:endEvent id="Event_1hylnf3" name="Multi-tenancy worker test complete"> | ||
<bpmn:incoming>Flow_08wm3o9</bpmn:incoming> | ||
</bpmn:endEvent> | ||
<bpmn:sequenceFlow id="Flow_08wm3o9" sourceRef="Activity_1an5aay" targetRef="Event_1hylnf3" /> | ||
<bpmn:serviceTask id="Activity_1an5aay" name="multi-tenant-stream-work"> | ||
<bpmn:extensionElements> | ||
<zeebe:taskDefinition type="multi-tenant-stream-work" /> | ||
</bpmn:extensionElements> | ||
<bpmn:incoming>Flow_0r8p543</bpmn:incoming> | ||
<bpmn:outgoing>Flow_08wm3o9</bpmn:outgoing> | ||
</bpmn:serviceTask> | ||
</bpmn:process> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="multi-tenant-stream-worker-test"> | ||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> | ||
<dc:Bounds x="179" y="99" width="36" height="36" /> | ||
<bpmndi:BPMNLabel> | ||
<dc:Bounds x="160" y="142" width="75" height="40" /> | ||
</bpmndi:BPMNLabel> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Event_1hylnf3_di" bpmnElement="Event_1hylnf3"> | ||
<dc:Bounds x="432" y="99" width="36" height="36" /> | ||
<bpmndi:BPMNLabel> | ||
<dc:Bounds x="417" y="142" width="66" height="40" /> | ||
</bpmndi:BPMNLabel> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Activity_0cx6d07_di" bpmnElement="Activity_1an5aay"> | ||
<dc:Bounds x="270" y="77" width="100" height="80" /> | ||
<bpmndi:BPMNLabel /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNEdge id="Flow_0r8p543_di" bpmnElement="Flow_0r8p543"> | ||
<di:waypoint x="215" y="117" /> | ||
<di:waypoint x="270" y="117" /> | ||
</bpmndi:BPMNEdge> | ||
<bpmndi:BPMNEdge id="Flow_08wm3o9_di" bpmnElement="Flow_08wm3o9"> | ||
<di:waypoint x="370" y="117" /> | ||
<di:waypoint x="432" y="117" /> | ||
</bpmndi:BPMNEdge> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1o5c8zw" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0"> | ||
<bpmn:process id="multi-tenant-worker-test" name="Multi-tenant Worker Test" isExecutable="true"> | ||
<bpmn:startEvent id="StartEvent_1" name="Start multi-tenancy worker test"> | ||
<bpmn:outgoing>Flow_0r8p543</bpmn:outgoing> | ||
</bpmn:startEvent> | ||
<bpmn:sequenceFlow id="Flow_0r8p543" sourceRef="StartEvent_1" targetRef="Activity_1an5aay" /> | ||
<bpmn:endEvent id="Event_1hylnf3" name="Multi-tenancy worker test complete"> | ||
<bpmn:incoming>Flow_08wm3o9</bpmn:incoming> | ||
</bpmn:endEvent> | ||
<bpmn:sequenceFlow id="Flow_08wm3o9" sourceRef="Activity_1an5aay" targetRef="Event_1hylnf3" /> | ||
<bpmn:serviceTask id="Activity_1an5aay" name="multi-tenant-work"> | ||
<bpmn:extensionElements> | ||
<zeebe:taskDefinition type="multi-tenant-work" /> | ||
</bpmn:extensionElements> | ||
<bpmn:incoming>Flow_0r8p543</bpmn:incoming> | ||
<bpmn:outgoing>Flow_08wm3o9</bpmn:outgoing> | ||
</bpmn:serviceTask> | ||
</bpmn:process> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="multi-tenant-worker-test"> | ||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> | ||
<dc:Bounds x="179" y="99" width="36" height="36" /> | ||
<bpmndi:BPMNLabel> | ||
<dc:Bounds x="160" y="142" width="75" height="40" /> | ||
</bpmndi:BPMNLabel> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Event_1hylnf3_di" bpmnElement="Event_1hylnf3"> | ||
<dc:Bounds x="432" y="99" width="36" height="36" /> | ||
<bpmndi:BPMNLabel> | ||
<dc:Bounds x="417" y="142" width="66" height="40" /> | ||
</bpmndi:BPMNLabel> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Activity_0cx6d07_di" bpmnElement="Activity_1an5aay"> | ||
<dc:Bounds x="270" y="77" width="100" height="80" /> | ||
<bpmndi:BPMNLabel /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNEdge id="Flow_0r8p543_di" bpmnElement="Flow_0r8p543"> | ||
<di:waypoint x="215" y="117" /> | ||
<di:waypoint x="270" y="117" /> | ||
</bpmndi:BPMNEdge> | ||
<bpmndi:BPMNEdge id="Flow_08wm3o9_di" bpmnElement="Flow_08wm3o9"> | ||
<di:waypoint x="370" y="117" /> | ||
<di:waypoint x="432" y="117" /> | ||
</bpmndi:BPMNEdge> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |
110 changes: 110 additions & 0 deletions
110
src/__tests__/zeebe/multitenancy/multitenant-worker-mt.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { restoreZeebeLogging, suppressZeebeLogging } from '../../../lib' | ||
import { ZeebeGrpcClient } from '../../../zeebe/index' | ||
|
||
jest.setTimeout(10000) | ||
|
||
beforeAll(() => { | ||
suppressZeebeLogging() | ||
}) | ||
|
||
afterAll(() => { | ||
restoreZeebeLogging() | ||
}) | ||
|
||
test('A worker can be multi-tenant', async () => { | ||
const client = new ZeebeGrpcClient() | ||
|
||
await client.deployResource({ | ||
processFilename: './src/__tests__/testdata/multi-tenant-worker-test.bpmn', | ||
tenantId: '<default>', | ||
}) | ||
|
||
await client.deployResource({ | ||
processFilename: './src/__tests__/testdata/multi-tenant-worker-test.bpmn', | ||
tenantId: 'green', | ||
}) | ||
|
||
await client.createProcessInstance({ | ||
bpmnProcessId: 'multi-tenant-worker-test', | ||
variables: { foo: 'bar' }, | ||
tenantId: '<default>', | ||
}) | ||
|
||
await client.createProcessInstance({ | ||
bpmnProcessId: 'multi-tenant-worker-test', | ||
variables: { foo: 'bar' }, | ||
tenantId: 'green', | ||
}) | ||
|
||
let greenTenant = false, | ||
defaultTenant = false | ||
await new Promise((resolve) => | ||
client.createWorker({ | ||
taskHandler: (job) => { | ||
greenTenant = greenTenant || job.tenantId === 'green' | ||
defaultTenant = defaultTenant || job.tenantId === '<default>' | ||
if (greenTenant && defaultTenant) { | ||
resolve(null) | ||
} | ||
return job.complete() | ||
}, | ||
taskType: 'multi-tenant-work', | ||
tenantIds: ['<default>', 'green'], | ||
}) | ||
) | ||
|
||
await client.close() | ||
}) | ||
|
||
test('A stream worker can be multi-tenant', async () => { | ||
const client = new ZeebeGrpcClient() | ||
|
||
await client.deployResource({ | ||
processFilename: | ||
'./src/__tests__/testdata/multi-tenant-stream-worker-test.bpmn', | ||
tenantId: '<default>', | ||
}) | ||
|
||
await client.deployResource({ | ||
processFilename: | ||
'./src/__tests__/testdata/multi-tenant-stream-worker-test.bpmn', | ||
tenantId: 'green', | ||
}) | ||
|
||
let greenTenant = false, | ||
defaultTenant = false | ||
// eslint-disable-next-line no-async-promise-executor | ||
await new Promise(async (resolve) => { | ||
client.streamJobs({ | ||
taskHandler: async (job) => { | ||
greenTenant = greenTenant || job.tenantId === 'green' | ||
defaultTenant = defaultTenant || job.tenantId === '<default>' | ||
const res = await job.complete() | ||
if (greenTenant && defaultTenant) { | ||
resolve(null) | ||
} | ||
return res | ||
}, | ||
type: 'multi-tenant-stream-work', | ||
tenantIds: ['<default>', 'green'], | ||
worker: 'stream-worker', | ||
timeout: 2000, | ||
}) | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 2000)) | ||
|
||
await client.createProcessInstance({ | ||
bpmnProcessId: 'multi-tenant-stream-worker-test', | ||
variables: { foo: 'bar' }, | ||
tenantId: '<default>', | ||
}) | ||
|
||
await client.createProcessInstance({ | ||
bpmnProcessId: 'multi-tenant-stream-worker-test', | ||
variables: { foo: 'bar' }, | ||
tenantId: 'green', | ||
}) | ||
}) | ||
|
||
await client.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.