|
| 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