-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathEncryptionStarter.java
More file actions
107 lines (99 loc) · 3.87 KB
/
Copy pathEncryptionStarter.java
File metadata and controls
107 lines (99 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.uber.cadence.samples.encryption;
import com.uber.cadence.client.WorkflowClient;
import com.uber.cadence.client.WorkflowClientOptions;
import com.uber.cadence.client.WorkflowOptions;
import com.uber.cadence.internal.compatibility.Thrift2ProtoAdapter;
import com.uber.cadence.internal.compatibility.proto.serviceclient.IGrpcServiceStubs;
import com.uber.cadence.samples.common.SampleConstants;
import java.time.Duration;
import java.util.UUID;
/**
* Starts {@link EncryptedDataConverterWorkflow} (async, fire-and-forget).
*
* <p>The workflow takes no inputs and generates its own payload, so this starter does not need the
* encryption key — the worker owns the key. The same effect can be achieved from the Cadence CLI
* via:
*
* <pre>
* cadence --domain samples-domain \
* workflow start \
* --workflow_type EncryptedDataConverterWorkflow \
* --tl data-encryption \
* --et 60
* </pre>
*/
public final class EncryptionStarter {
private EncryptionStarter() {}
public static void main(String[] args) {
try {
WorkflowClient client =
WorkflowClient.newInstance(
new Thrift2ProtoAdapter(IGrpcServiceStubs.newInstance()),
WorkflowClientOptions.newBuilder().setDomain(SampleConstants.DOMAIN).build());
WorkflowOptions options =
new WorkflowOptions.Builder()
.setTaskList(EncryptedDataConverterWorkflow.TASK_LIST)
.setExecutionStartToCloseTimeout(Duration.ofMinutes(1))
.setWorkflowId("encryption-" + UUID.randomUUID())
.build();
EncryptedDataConverterWorkflow.WorkflowIface workflow =
client.newWorkflowStub(EncryptedDataConverterWorkflow.WorkflowIface.class, options);
WorkflowClient.start(workflow::run);
System.out.println(
"Started "
+ EncryptedDataConverterWorkflow.WORKFLOW_TYPE
+ " on task list \""
+ EncryptedDataConverterWorkflow.TASK_LIST
+ "\".");
System.exit(0);
} catch (RuntimeException e) {
if (printHintIfDomainMissing(e)) {
System.exit(1);
}
throw e;
}
}
/**
* Prints a copy-paste hint when the Cadence error indicates the sample domain has not been
* registered.
*
* @return true if {@code t} was a missing-domain error and a hint was printed (caller should
* exit).
*/
static boolean printHintIfDomainMissing(Throwable t) {
for (Throwable c = t; c != null; c = c.getCause()) {
String m = c.getMessage();
if (m != null && m.contains("Domain") && m.contains("does not exist")) {
System.err.println();
System.err.println(
"Cadence reported that the domain \"" + SampleConstants.DOMAIN + "\" does not exist.");
System.err.println("Register it once against your cluster, then run this again:");
System.err.println();
System.err.println(
" ./gradlew -q execute -PmainClass=com.uber.cadence.samples.common.RegisterDomain");
System.err.println();
System.err.println("Or with Cadence CLI:");
System.err.println(" cadence --domain " + SampleConstants.DOMAIN + " domain register");
System.err.println();
return true;
}
}
return false;
}
}