• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #263

03 Jun 2024 04:14PM UTC coverage: 77.542% (+0.08%) from 77.467%
#263

push

github

web-flow
Add setWorkflowIdConflictPolicy (#2055)

Add setWorkflowIdConflictPolicy

22 of 25 new or added lines in 4 files covered. (88.0%)

1 existing line in 1 file now uncovered.

19249 of 24824 relevant lines covered (77.54%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.39
/temporal-sdk/src/main/java/io/temporal/internal/client/ScheduleProtoUtil.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.internal.client;
22

23
import static io.temporal.internal.common.HeaderUtils.toHeaderGrpc;
24
import static io.temporal.internal.common.RetryOptionsUtils.toRetryPolicy;
25

26
import com.google.common.base.MoreObjects;
27
import com.google.common.base.Preconditions;
28
import io.temporal.api.common.v1.*;
29
import io.temporal.api.schedule.v1.*;
30
import io.temporal.api.schedule.v1.Schedule;
31
import io.temporal.api.schedule.v1.ScheduleAction;
32
import io.temporal.api.schedule.v1.ScheduleActionResult;
33
import io.temporal.api.schedule.v1.ScheduleInfo;
34
import io.temporal.api.schedule.v1.ScheduleSpec;
35
import io.temporal.api.schedule.v1.ScheduleState;
36
import io.temporal.api.taskqueue.v1.TaskQueue;
37
import io.temporal.api.workflow.v1.NewWorkflowExecutionInfo;
38
import io.temporal.client.WorkflowOptions;
39
import io.temporal.client.schedules.*;
40
import io.temporal.common.RetryOptions;
41
import io.temporal.common.context.ContextPropagator;
42
import io.temporal.common.converter.DataConverter;
43
import io.temporal.common.converter.EncodedValues;
44
import io.temporal.internal.client.external.GenericWorkflowClient;
45
import io.temporal.internal.common.ProtobufTimeUtils;
46
import io.temporal.internal.common.RetryOptionsUtils;
47
import io.temporal.internal.common.SearchAttributesUtil;
48
import io.temporal.payload.context.WorkflowSerializationContext;
49
import java.time.Instant;
50
import java.util.*;
51
import java.util.stream.Collectors;
52
import javax.annotation.Nonnull;
53
import javax.annotation.Nullable;
54

55
public class ScheduleProtoUtil {
56

57
  private final GenericWorkflowClient genericClient;
58
  private final ScheduleClientOptions clientOptions;
59

60
  public ScheduleProtoUtil(
61
      GenericWorkflowClient genericClient, ScheduleClientOptions clientOptions) {
1✔
62
    this.genericClient = genericClient;
1✔
63
    this.clientOptions = clientOptions;
1✔
64
  }
1✔
65

66
  private io.temporal.common.interceptors.Header extractContextsAndConvertToBytes(
67
      List<ContextPropagator> scheduleOptionsContextPropagators) {
68
    List<ContextPropagator> scheduleClientContextPropagators =
×
69
        clientOptions.getContextPropagators();
×
70
    if ((scheduleClientContextPropagators.isEmpty() && scheduleOptionsContextPropagators == null)
×
71
        || (scheduleOptionsContextPropagators != null
72
            && scheduleOptionsContextPropagators.isEmpty())) {
×
73
      return null;
×
74
    }
75

76
    List<ContextPropagator> listToUse =
×
77
        MoreObjects.firstNonNull(
×
78
            scheduleOptionsContextPropagators, scheduleClientContextPropagators);
79
    Map<String, Payload> result = new HashMap<>();
×
80
    for (ContextPropagator propagator : listToUse) {
×
81
      result.putAll(propagator.serializeContext(propagator.getCurrentContext()));
×
82
    }
×
83
    return new io.temporal.common.interceptors.Header(result);
×
84
  }
85

86
  public ScheduleAction actionToProto(io.temporal.client.schedules.ScheduleAction action) {
87
    if (action instanceof ScheduleActionStartWorkflow) {
×
88
      ScheduleActionStartWorkflow startWorkflowAction = (ScheduleActionStartWorkflow) action;
×
89
      DataConverter dataConverterWithWorkflowContext =
×
90
          clientOptions
91
              .getDataConverter()
×
92
              .withContext(
×
93
                  new WorkflowSerializationContext(
94
                      clientOptions.getNamespace(),
×
95
                      startWorkflowAction.getOptions().getWorkflowId()));
×
96

97
      WorkflowOptions wfOptions = startWorkflowAction.getOptions();
×
98
      // Disallow some options
99
      if (wfOptions.getWorkflowIdReusePolicy() != null) {
×
100
        throw new IllegalArgumentException(
×
101
            "ID reuse policy cannot change from default for scheduled workflow");
102
      }
103
      if (wfOptions.getCronSchedule() != null) {
×
104
        throw new IllegalArgumentException("Cron schedule cannot be set on scheduled workflow");
×
105
      }
NEW
106
      if (wfOptions.getWorkflowIdConflictPolicy() != null) {
×
NEW
107
        throw new IllegalArgumentException(
×
108
            "ID conflict policy cannot change from default for scheduled workflow");
109
      }
110
      // Validate required options
111
      if (wfOptions.getWorkflowId() == null || wfOptions.getWorkflowId().isEmpty()) {
×
112
        throw new IllegalArgumentException("ID required on workflow action");
×
113
      }
114
      if (wfOptions.getTaskQueue() == null || wfOptions.getTaskQueue().isEmpty()) {
×
115
        throw new IllegalArgumentException("Task queue required on workflow action");
×
116
      }
117

118
      NewWorkflowExecutionInfo.Builder workflowRequest =
119
          NewWorkflowExecutionInfo.newBuilder()
×
120
              .setWorkflowId(wfOptions.getWorkflowId())
×
121
              .setWorkflowType(
×
122
                  WorkflowType.newBuilder().setName(startWorkflowAction.getWorkflowType()).build())
×
123
              .setWorkflowRunTimeout(
×
124
                  ProtobufTimeUtils.toProtoDuration(wfOptions.getWorkflowRunTimeout()))
×
125
              .setWorkflowExecutionTimeout(
×
126
                  ProtobufTimeUtils.toProtoDuration(wfOptions.getWorkflowExecutionTimeout()))
×
127
              .setWorkflowTaskTimeout(
×
128
                  ProtobufTimeUtils.toProtoDuration(wfOptions.getWorkflowTaskTimeout()))
×
129
              .setTaskQueue(TaskQueue.newBuilder().setName(wfOptions.getTaskQueue()).build());
×
130

131
      startWorkflowAction.getArguments().setDataConverter(dataConverterWithWorkflowContext);
×
132
      Optional<Payloads> inputArgs = startWorkflowAction.getArguments().toPayloads();
×
133
      if (inputArgs.isPresent()) {
×
134
        workflowRequest.setInput(inputArgs.get());
×
135
      }
136

137
      RetryOptions retryOptions = wfOptions.getRetryOptions();
×
138
      if (retryOptions != null) {
×
139
        workflowRequest.setRetryPolicy(toRetryPolicy(retryOptions));
×
140
      }
141

142
      if (startWorkflowAction.getOptions().getMemo() != null) {
×
143
        Map<String, Payload> memo = new HashMap<>();
×
144
        for (Map.Entry<String, Object> item :
145
            startWorkflowAction.getOptions().getMemo().entrySet()) {
×
146
          if (item.getValue() instanceof EncodedValues) {
×
147
            memo.put(
×
148
                item.getKey(), ((EncodedValues) item.getValue()).toPayloads().get().getPayloads(0));
×
149
          } else {
150
            memo.put(
×
151
                item.getKey(), dataConverterWithWorkflowContext.toPayload(item.getValue()).get());
×
152
          }
153
        }
×
154
        workflowRequest.setMemo(Memo.newBuilder().putAllFields(memo).build());
×
155
      }
156

157
      if (wfOptions.getTypedSearchAttributes() != null
×
158
          && wfOptions.getTypedSearchAttributes().size() > 0) {
×
159
        workflowRequest.setSearchAttributes(
×
160
            SearchAttributesUtil.encodeTyped(wfOptions.getTypedSearchAttributes()));
×
161
      }
162

163
      Header grpcHeader =
×
164
          toHeaderGrpc(
×
165
              startWorkflowAction.getHeader(),
×
166
              extractContextsAndConvertToBytes(wfOptions.getContextPropagators()));
×
167
      workflowRequest.setHeader(grpcHeader);
×
168

169
      return ScheduleAction.newBuilder().setStartWorkflow(workflowRequest.build()).build();
×
170
    }
171
    throw new IllegalArgumentException("Unsupported action " + action.getClass());
×
172
  }
173

174
  public SchedulePolicies policyToProto(SchedulePolicy policy) {
175
    SchedulePolicies.Builder builder = SchedulePolicies.newBuilder();
×
176
    if (policy.getCatchupWindow() != null) {
×
177
      builder.setCatchupWindow(ProtobufTimeUtils.toProtoDuration(policy.getCatchupWindow()));
×
178
    }
179
    builder.setPauseOnFailure(policy.isPauseOnFailure());
×
180
    builder.setOverlapPolicy(policy.getOverlap());
×
181
    return builder.build();
×
182
  }
183

184
  public List<Range> scheduleRangeToProto(List<ScheduleRange> scheduleRanges) {
185
    ArrayList<Range> ranges = new ArrayList<Range>(scheduleRanges.size());
×
186
    for (ScheduleRange scheduleRange : scheduleRanges) {
×
187
      ranges.add(
×
188
          Range.newBuilder()
×
189
              .setStart(scheduleRange.getStart())
×
190
              .setEnd(scheduleRange.getEnd())
×
191
              .setStep(scheduleRange.getStep())
×
192
              .build());
×
193
    }
×
194
    return ranges;
×
195
  }
196

197
  public ScheduleSpec specToProto(io.temporal.client.schedules.ScheduleSpec spec) {
198
    ScheduleSpec.Builder builder = ScheduleSpec.newBuilder();
×
199

200
    if (spec.getTimeZoneName() != null && !spec.getTimeZoneName().isEmpty()) {
×
201
      builder.setTimezoneName(spec.getTimeZoneName());
×
202
    }
203

204
    if (spec.getJitter() != null) {
×
205
      builder.setJitter(ProtobufTimeUtils.toProtoDuration(spec.getJitter()));
×
206
    }
207

208
    if (spec.getStartAt() != null) {
×
209
      builder.setStartTime(ProtobufTimeUtils.toProtoTimestamp(spec.getStartAt()));
×
210
    }
211

212
    if (spec.getEndAt() != null) {
×
213
      builder.setEndTime(ProtobufTimeUtils.toProtoTimestamp(spec.getEndAt()));
×
214
    }
215

216
    if (spec.getCalendars() != null && !spec.getCalendars().isEmpty()) {
×
217
      for (ScheduleCalendarSpec calendarSpec : spec.getCalendars()) {
×
218
        builder.addStructuredCalendar(
×
219
            StructuredCalendarSpec.newBuilder()
×
220
                .addAllSecond(this.scheduleRangeToProto(calendarSpec.getSeconds()))
×
221
                .addAllMinute(this.scheduleRangeToProto(calendarSpec.getMinutes()))
×
222
                .addAllHour(this.scheduleRangeToProto(calendarSpec.getHour()))
×
223
                .addAllDayOfMonth(this.scheduleRangeToProto(calendarSpec.getDayOfMonth()))
×
224
                .addAllMonth(this.scheduleRangeToProto(calendarSpec.getMonth()))
×
225
                .addAllYear(this.scheduleRangeToProto(calendarSpec.getYear()))
×
226
                .addAllDayOfWeek(this.scheduleRangeToProto(calendarSpec.getDayOfWeek()))
×
227
                .setComment(calendarSpec.getComment())
×
228
                .build());
×
229
      }
×
230
    }
231

232
    if (spec.getIntervals() != null && !spec.getIntervals().isEmpty()) {
×
233
      for (ScheduleIntervalSpec intervalSpec : spec.getIntervals()) {
×
234
        builder.addInterval(
×
235
            IntervalSpec.newBuilder()
×
236
                .setInterval(ProtobufTimeUtils.toProtoDuration(intervalSpec.getEvery()))
×
237
                .setPhase(ProtobufTimeUtils.toProtoDuration(intervalSpec.getOffset()))
×
238
                .build());
×
239
      }
×
240
    }
241

242
    if (spec.getCronExpressions() != null && !spec.getCronExpressions().isEmpty()) {
×
243
      builder.addAllCronString(spec.getCronExpressions());
×
244
    }
245

246
    if (spec.getSkip() != null && !spec.getSkip().isEmpty()) {
×
247
      for (ScheduleCalendarSpec calendarSpec : spec.getSkip()) {
×
248
        builder.addExcludeStructuredCalendar(
×
249
            StructuredCalendarSpec.newBuilder()
×
250
                .addAllSecond(this.scheduleRangeToProto(calendarSpec.getSeconds()))
×
251
                .addAllMinute(this.scheduleRangeToProto(calendarSpec.getMinutes()))
×
252
                .addAllHour(this.scheduleRangeToProto(calendarSpec.getHour()))
×
253
                .addAllDayOfMonth(this.scheduleRangeToProto(calendarSpec.getDayOfMonth()))
×
254
                .addAllMonth(this.scheduleRangeToProto(calendarSpec.getMonth()))
×
255
                .addAllYear(this.scheduleRangeToProto(calendarSpec.getYear()))
×
256
                .addAllDayOfWeek(this.scheduleRangeToProto(calendarSpec.getDayOfWeek()))
×
257
                .setComment(calendarSpec.getComment())
×
258
                .build());
×
259
      }
×
260
    }
261

262
    return builder.build();
×
263
  }
264

265
  public @Nonnull Schedule scheduleToProto(
266
      @Nonnull io.temporal.client.schedules.Schedule schedule) {
267
    Preconditions.checkNotNull(schedule);
×
268

269
    Schedule.Builder scheduleBuilder =
270
        Schedule.newBuilder()
×
271
            .setAction(this.actionToProto(schedule.getAction()))
×
272
            .setSpec(this.specToProto(schedule.getSpec()));
×
273

274
    if (schedule.getPolicy() != null) {
×
275
      scheduleBuilder.setPolicies(this.policyToProto(schedule.getPolicy()));
×
276
    }
277

278
    if (schedule.getState() != null) {
×
279
      scheduleBuilder.setState(this.stateToProto(schedule.getState()));
×
280
    }
281

282
    return scheduleBuilder.build();
×
283
  }
284

285
  public ScheduleState stateToProto(io.temporal.client.schedules.ScheduleState state) {
286
    ScheduleState.Builder stateBuilder =
287
        ScheduleState.newBuilder()
×
288
            .setLimitedActions(state.isLimitedAction())
×
289
            .setRemainingActions(state.getRemainingActions())
×
290
            .setPaused(state.isPaused());
×
291
    if (state.getNote() != null) {
×
292
      stateBuilder.setNotes(state.getNote());
×
293
    }
294
    return stateBuilder.build();
×
295
  }
296

297
  public ScheduleRange protoToScheduleRange(Range protoRange) {
298
    return new ScheduleRange(protoRange.getStart(), protoRange.getEnd(), protoRange.getStep());
×
299
  }
300

301
  public ScheduleIntervalSpec protoToScheduleInterval(IntervalSpec protoInterval) {
302
    return new ScheduleIntervalSpec(
×
303
        ProtobufTimeUtils.toJavaDuration(protoInterval.getInterval()),
×
304
        ProtobufTimeUtils.toJavaDuration(protoInterval.getPhase()));
×
305
  }
306

307
  public List<ScheduleRange> protoToScheduleRanges(List<Range> protoRanges) {
308
    return protoRanges.stream().map(t -> this.protoToScheduleRange(t)).collect(Collectors.toList());
×
309
  }
310

311
  public ScheduleCalendarSpec protoToScheduleCalendar(StructuredCalendarSpec protoSpec) {
312
    ScheduleCalendarSpec.Builder calendarBuilder =
313
        ScheduleCalendarSpec.newBuilder()
×
314
            .setComment(protoSpec.getComment())
×
315
            .setSeconds(protoToScheduleRanges(protoSpec.getSecondList()))
×
316
            .setMinutes(protoToScheduleRanges(protoSpec.getMinuteList()))
×
317
            .setHour(protoToScheduleRanges(protoSpec.getHourList()))
×
318
            .setDayOfMonth(protoToScheduleRanges(protoSpec.getDayOfMonthList()))
×
319
            .setMonth(protoToScheduleRanges(protoSpec.getMonthList()))
×
320
            .setYear(protoToScheduleRanges(protoSpec.getYearList()))
×
321
            .setDayOfWeek(protoToScheduleRanges(protoSpec.getDayOfWeekList()));
×
322

323
    return calendarBuilder.build();
×
324
  }
325

326
  @Nonnull
327
  public io.temporal.client.schedules.ScheduleSpec protoToScheduleSpec(
328
      @Nonnull ScheduleSpec scheduleSpec) {
329
    Objects.requireNonNull(scheduleSpec);
×
330
    io.temporal.client.schedules.ScheduleSpec.Builder specBuilder =
331
        io.temporal.client.schedules.ScheduleSpec.newBuilder()
×
332
            .setTimeZoneName(
×
333
                scheduleSpec.getTimezoneName() == null ? "" : scheduleSpec.getTimezoneName());
×
334

335
    if (scheduleSpec.hasJitter()) {
×
336
      specBuilder.setJitter(ProtobufTimeUtils.toJavaDuration(scheduleSpec.getJitter()));
×
337
    }
338

339
    if (scheduleSpec.hasStartTime()) {
×
340
      specBuilder.setStartAt(ProtobufTimeUtils.toJavaInstant(scheduleSpec.getStartTime()));
×
341
    }
342

343
    if (scheduleSpec.hasEndTime()) {
×
344
      specBuilder.setEndAt(ProtobufTimeUtils.toJavaInstant(scheduleSpec.getEndTime()));
×
345
    }
346

347
    specBuilder.setCalendars(
×
348
        scheduleSpec.getStructuredCalendarList().stream()
×
349
            .map(c -> this.protoToScheduleCalendar(c))
×
350
            .collect(Collectors.toList()));
×
351

352
    specBuilder.setCronExpressions(scheduleSpec.getCronStringList());
×
353

354
    specBuilder.setIntervals(
×
355
        scheduleSpec.getIntervalList().stream()
×
356
            .map(i -> this.protoToScheduleInterval(i))
×
357
            .collect(Collectors.toList()));
×
358

359
    specBuilder.setSkip(
×
360
        scheduleSpec.getExcludeStructuredCalendarList().stream()
×
361
            .map(c -> this.protoToScheduleCalendar(c))
×
362
            .collect(Collectors.toList()));
×
363

364
    return specBuilder.build();
×
365
  }
366

367
  public List<io.temporal.client.schedules.ScheduleActionResult> protoToActionResults(
368
      List<ScheduleActionResult> results) {
369
    return results.stream()
×
370
        .map(
×
371
            a ->
372
                new io.temporal.client.schedules.ScheduleActionResult(
×
373
                    ProtobufTimeUtils.toJavaInstant(a.getScheduleTime()),
×
374
                    ProtobufTimeUtils.toJavaInstant(a.getActualTime()),
×
375
                    new ScheduleActionExecutionStartWorkflow(
376
                        a.getStartWorkflowResult().getWorkflowId(),
×
377
                        a.getStartWorkflowResult().getRunId())))
×
378
        .collect(Collectors.toList());
×
379
  }
380

381
  public ScheduleListDescription protoToScheduleListDescription(ScheduleListEntry entry) {
382
    List<Instant> nextActionTimes =
×
383
        entry.getInfo().getFutureActionTimesList().stream()
×
384
            .map(ProtobufTimeUtils::toJavaInstant)
×
385
            .collect(Collectors.toList());
×
386

387
    io.temporal.client.schedules.ScheduleListInfo info =
×
388
        new io.temporal.client.schedules.ScheduleListInfo(
389
            this.protoToActionResults(entry.getInfo().getRecentActionsList()), nextActionTimes);
×
390

391
    ScheduleListActionStartWorkflow action =
×
392
        new ScheduleListActionStartWorkflow(entry.getInfo().getWorkflowType().getName());
×
393

394
    ScheduleListState state =
×
395
        new ScheduleListState(entry.getInfo().getNotes(), entry.getInfo().getPaused());
×
396

397
    io.temporal.client.schedules.ScheduleSpec spec = protoToScheduleSpec(entry.getInfo().getSpec());
×
398

399
    return new ScheduleListDescription(
×
400
        entry.getScheduleId(),
×
401
        new ScheduleListSchedule(action, spec, state),
402
        info,
403
        entry.getMemo().getFieldsMap(),
×
404
        this.clientOptions.getDataConverter(),
×
405
        Collections.unmodifiableMap(SearchAttributesUtil.decode(entry.getSearchAttributes())));
×
406
  }
407

408
  @Nonnull
409
  public io.temporal.client.schedules.ScheduleAction protoToAction(@Nonnull ScheduleAction action) {
410
    Objects.requireNonNull(action);
×
411
    if (action.hasStartWorkflow()) {
×
412
      NewWorkflowExecutionInfo startWfAction = action.getStartWorkflow();
×
413
      DataConverter dataConverterWithWorkflowContext =
×
414
          clientOptions
415
              .getDataConverter()
×
416
              .withContext(
×
417
                  new WorkflowSerializationContext(
418
                      clientOptions.getNamespace(), startWfAction.getWorkflowId()));
×
419

420
      ScheduleActionStartWorkflow.Builder builder = ScheduleActionStartWorkflow.newBuilder();
×
421
      builder.setWorkflowType(startWfAction.getWorkflowType().getName());
×
422

423
      builder.setRawArguments(
×
424
          new EncodedValues(
425
              Optional.of(startWfAction.getInput()), dataConverterWithWorkflowContext));
×
426

427
      WorkflowOptions.Builder wfOptionsBuilder = WorkflowOptions.newBuilder();
×
428
      // set required options
429
      wfOptionsBuilder.setWorkflowId(startWfAction.getWorkflowId());
×
430
      wfOptionsBuilder.setTaskQueue(startWfAction.getTaskQueue().getName());
×
431
      // set timeouts
432
      wfOptionsBuilder.setWorkflowExecutionTimeout(
×
433
          ProtobufTimeUtils.toJavaDuration(startWfAction.getWorkflowExecutionTimeout()));
×
434

435
      wfOptionsBuilder.setWorkflowRunTimeout(
×
436
          ProtobufTimeUtils.toJavaDuration(startWfAction.getWorkflowRunTimeout()));
×
437

438
      wfOptionsBuilder.setWorkflowTaskTimeout(
×
439
          ProtobufTimeUtils.toJavaDuration(startWfAction.getWorkflowTaskTimeout()));
×
440

441
      if (startWfAction.getRetryPolicy() != null) {
×
442
        wfOptionsBuilder.setRetryOptions(
×
443
            RetryOptionsUtils.toRetryOptions(startWfAction.getRetryPolicy()));
×
444
      }
445

446
      if (startWfAction.hasMemo()) {
×
447
        Map<String, Object> memos = new HashMap<>();
×
448
        for (Map.Entry<String, Payload> memo : startWfAction.getMemo().getFieldsMap().entrySet()) {
×
449
          EncodedValues encodedMemo =
×
450
              new EncodedValues(
451
                  Optional.of(Payloads.newBuilder().addPayloads(memo.getValue()).build()),
×
452
                  dataConverterWithWorkflowContext);
453
          memos.put(memo.getKey(), encodedMemo);
×
454
        }
×
455
        wfOptionsBuilder.setMemo(memos);
×
456
      }
457

458
      if (startWfAction.hasSearchAttributes()) {
×
459
        wfOptionsBuilder.setTypedSearchAttributes(
×
460
            SearchAttributesUtil.decodeTyped(startWfAction.getSearchAttributes()));
×
461
      }
462

463
      builder.setOptions(wfOptionsBuilder.build());
×
464
      return builder.build();
×
465
    }
466
    throw new IllegalArgumentException("Unsupported action " + action.getActionCase());
×
467
  }
468

469
  @Nullable
470
  public SchedulePolicy protoToPolicy(@Nullable SchedulePolicies policy) {
471
    if (policy == null) {
×
472
      return null;
×
473
    }
474
    SchedulePolicy.Builder policyBuilder =
475
        SchedulePolicy.newBuilder()
×
476
            .setPauseOnFailure(policy.getPauseOnFailure())
×
477
            .setOverlap(policy.getOverlapPolicy());
×
478
    if (policy.hasCatchupWindow()) {
×
479
      policyBuilder.setCatchupWindow(ProtobufTimeUtils.toJavaDuration(policy.getCatchupWindow()));
×
480
    }
481
    return policyBuilder.build();
×
482
  }
483

484
  @Nullable
485
  public io.temporal.client.schedules.ScheduleState protoToScheduleState(
486
      @Nullable ScheduleState state) {
487
    if (state == null) {
×
488
      return null;
×
489
    }
490
    return io.temporal.client.schedules.ScheduleState.newBuilder()
×
491
        .setNote(state.getNotes())
×
492
        .setPaused(state.getPaused())
×
493
        .setRemainingActions(state.getRemainingActions())
×
494
        .setLimitedAction(state.getLimitedActions())
×
495
        .build();
×
496
  }
497

498
  public io.temporal.client.schedules.Schedule protoToSchedule(Schedule schedule) {
499
    return io.temporal.client.schedules.Schedule.newBuilder()
×
500
        .setAction(protoToAction(schedule.getAction()))
×
501
        .setSpec(protoToScheduleSpec(schedule.getSpec()))
×
502
        .setPolicy(protoToPolicy(schedule.getPolicies()))
×
503
        .setState(protoToScheduleState(schedule.getState()))
×
504
        .build();
×
505
  }
506

507
  public io.temporal.client.schedules.ScheduleInfo protoToScheduleInfo(ScheduleInfo info) {
508
    return new io.temporal.client.schedules.ScheduleInfo(
×
509
        info.getActionCount(),
×
510
        info.getMissedCatchupWindow(),
×
511
        info.getOverlapSkipped(),
×
512
        info.getRunningWorkflowsList().stream()
×
513
            .map(wf -> new ScheduleActionExecutionStartWorkflow(wf.getWorkflowId(), wf.getRunId()))
×
514
            .collect(Collectors.toList()),
×
515
        this.protoToActionResults(info.getRecentActionsList()),
×
516
        info.getFutureActionTimesList().stream()
×
517
            .map(t -> ProtobufTimeUtils.toJavaInstant(t))
×
518
            .collect(Collectors.toList()),
×
519
        info.hasCreateTime() ? ProtobufTimeUtils.toJavaInstant(info.getCreateTime()) : null,
×
520
        info.hasUpdateTime() ? ProtobufTimeUtils.toJavaInstant(info.getUpdateTime()) : null);
×
521
  }
522
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc