Skip to content

Commit 4116032

Browse files
author
Maxim Fateev
committed
Added RegisterDomain
1 parent 21b7363 commit 4116032

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ to build the samples. Verify that they actually can run:
4040
S3. The smaller data sets are assigned to workers and the results of processing are merged to
4141
produce the final result.
4242

43-
## Configuring Samples
43+
## Configuring Service and S3 Access Keys
4444

4545
If you are running local container the HelloWorld and PeriodicWorkflow samples do not need any additional configuration.
4646

@@ -75,6 +75,12 @@ The steps for configuring and building other samples for Java Cadence Client are
7575

7676
set AWS_SWF_SAMPLES_CONFIG=<Your SDK Directory>
7777

78+
## Registering Domain
79+
80+
Run it once before running any samples to register domain.
81+
82+
./gradlew execute -PmainClass=com.uber.cadence.samples.common.RegisterDomain
83+
7884
## Running the samples
7985

8086
Each sample has particular requirements for running it. Here's how to run each of the samples once
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
package com.uber.cadence.samples.common;
18+
19+
import com.uber.cadence.DomainAlreadyExistsError;
20+
import com.uber.cadence.DomainConfiguration;
21+
import com.uber.cadence.RegisterDomainRequest;
22+
import com.uber.cadence.UpdateDomainRequest;
23+
import com.uber.cadence.WorkflowExecution;
24+
import com.uber.cadence.WorkflowService;
25+
import com.uber.cadence.internal.common.WorkflowExecutionUtils;
26+
import org.apache.thrift.TException;
27+
28+
import java.io.IOException;
29+
30+
/**
31+
* Simple example utility to pretty print workflow execution history.
32+
*
33+
* @author fateev
34+
*/
35+
public class RegisterDomain {
36+
37+
public static void main(String[] args) throws TException, IOException {
38+
if (args.length == 1 && "help".equals(args[0])) {
39+
System.err.println("Usage: java " + RegisterDomain.class.getName() + " <domain-name> [<retention-days>]");
40+
System.exit(1);
41+
}
42+
ConfigHelper configHelper = ConfigHelper.createConfig();
43+
WorkflowService.Iface swfService = configHelper.createWorkflowClient();
44+
String domain;
45+
if (args.length == 1) {
46+
domain = args[0];
47+
} else {
48+
domain = configHelper.getDomain();
49+
}
50+
RegisterDomainRequest request = new RegisterDomainRequest();
51+
request.setDescription("Java Samples");
52+
request.setEmitMetric(false);
53+
request.setName(domain);
54+
int retention = 1;
55+
if (args.length > 1) {
56+
try {
57+
retention = Integer.parseInt(args[1]);
58+
} catch (Exception e) {
59+
throw new IllegalArgumentException("Cannot parse retention-days: " + args[1], e);
60+
}
61+
}
62+
request.setWorkflowExecutionRetentionPeriodInDays(retention);
63+
try {
64+
swfService.RegisterDomain(request);
65+
System.out.println("Successfully registered domain \"" + domain + "\" with retentionDays=" + retention);
66+
} catch (DomainAlreadyExistsError e) {
67+
UpdateDomainRequest update = new UpdateDomainRequest();
68+
update.setName(domain);
69+
update.setConfiguration(new DomainConfiguration().setWorkflowExecutionRetentionPeriodInDays(retention));
70+
swfService.UpdateDomain(update);
71+
System.out.println("Successfully updated domain \"" + domain + "\" with retentionDays=" + retention);
72+
}
73+
System.exit(0);
74+
}
75+
76+
}

0 commit comments

Comments
 (0)