Skip to content

Commit cc89cd8

Browse files
committed
replace thrift with new entities
1 parent e0704d1 commit cc89cd8

File tree

108 files changed

+5923
-14738
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+5923
-14738
lines changed

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ googleJavaFormat {
4444
exclude '**/generated-sources/*'
4545
}
4646

47-
tasks.googleJavaFormat.dependsOn 'license'
47+
tasks.googleJavaFormat.dependsOn 'licenseFormat'
4848

4949
group = 'com.uber.cadence'
5050

@@ -89,6 +89,10 @@ dependencies {
8989
compile group: 'com.google.api.grpc', name: 'proto-google-common-protos', version: '2.10.0'
9090
compile group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.21.9'
9191
compile group: 'com.google.oauth-client', name: 'google-oauth-client', version: '1.35.0'
92+
compileOnly 'org.projectlombok:lombok:1.18.30'
93+
annotationProcessor 'org.projectlombok:lombok:1.18.30'
94+
testCompileOnly 'org.projectlombok:lombok:1.18.30'
95+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
9296

9397
implementation 'io.grpc:grpc-netty-shaded:1.54.2'
9498
implementation 'io.grpc:grpc-protobuf:1.54.2'
@@ -139,6 +143,7 @@ sourceSets {
139143
}
140144
java {
141145
srcDir 'src/main'
146+
srcDir 'src/gen/java'
142147
}
143148
}
144149
}

src/main/java/com/uber/cadence/client/WorkflowClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.uber.cadence.client;
1919

20+
import com.uber.cadence.CadenceError;
2021
import com.uber.cadence.RefreshWorkflowTasksRequest;
2122
import com.uber.cadence.WorkflowExecution;
2223
import com.uber.cadence.activity.Activity;
@@ -35,7 +36,6 @@
3536
import com.uber.cadence.workflow.WorkflowMethod;
3637
import java.util.Optional;
3738
import java.util.concurrent.CompletableFuture;
38-
import org.apache.thrift.TException;
3939

4040
/**
4141
* Client to the Cadence service used to start and query workflows by external processes. Also it
@@ -260,7 +260,7 @@ WorkflowStub newUntypedWorkflowStub(
260260
* @param refreshWorkflowTasksRequest that contains WorkflowID and RunID of the started workflow.
261261
*/
262262
void refreshWorkflowTasks(RefreshWorkflowTasksRequest refreshWorkflowTasksRequest)
263-
throws TException;
263+
throws CadenceError;
264264

265265
/**
266266
* Executes zero argument workflow with void return type

src/main/java/com/uber/cadence/common/WorkflowExecutionHistory.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.uber.cadence.HistoryEvent;
3333
import com.uber.cadence.WorkflowExecution;
3434
import java.lang.reflect.Type;
35-
import java.nio.ByteBuffer;
3635
import java.util.Base64;
3736
import java.util.List;
3837

@@ -47,7 +46,7 @@ public WorkflowExecutionHistory(List<HistoryEvent> events) {
4746

4847
public static WorkflowExecutionHistory fromJson(String serialized) {
4948
GsonBuilder gsonBuilder = new GsonBuilder();
50-
gsonBuilder.registerTypeAdapter(ByteBuffer.class, new ByteBufferJsonDeserializer());
49+
gsonBuilder.registerTypeAdapter(byte[].class, new ByteArrayJsonDeserializer());
5150
Gson gson = gsonBuilder.create();
5251
Type eventsType = new TypeToken<List<HistoryEvent>>() {}.getType();
5352
List<HistoryEvent> events = gson.fromJson(serialized, eventsType);
@@ -85,21 +84,21 @@ public List<HistoryEvent> getEvents() {
8584
return events;
8685
}
8786

88-
private static final class ByteBufferJsonDeserializer
89-
implements JsonDeserializer<ByteBuffer>, JsonSerializer<ByteBuffer> {
87+
private static final class ByteArrayJsonDeserializer
88+
implements JsonDeserializer<byte[]>, JsonSerializer<byte[]> {
9089

9190
@Override
92-
public JsonElement serialize(ByteBuffer value, Type type, JsonSerializationContext ctx) {
93-
if (value.arrayOffset() > 0) {
94-
throw new IllegalArgumentException("non zero value array offset: " + value.arrayOffset());
91+
public JsonElement serialize(byte[] value, Type type, JsonSerializationContext ctx) {
92+
if (value.length > 0) {
93+
throw new IllegalArgumentException("non zero value array offset: " + value.length);
9594
}
96-
return new JsonPrimitive(Base64.getEncoder().encodeToString(value.array()));
95+
return new JsonPrimitive(Base64.getEncoder().encodeToString(value));
9796
}
9897

9998
@Override
100-
public ByteBuffer deserialize(JsonElement e, Type type, JsonDeserializationContext ctx)
99+
public byte[] deserialize(JsonElement e, Type type, JsonDeserializationContext ctx)
101100
throws JsonParseException {
102-
return ByteBuffer.wrap(Base64.getDecoder().decode(e.getAsString()));
101+
return Base64.getDecoder().decode(e.getAsString());
103102
}
104103
}
105104
}

src/main/java/com/uber/cadence/converter/JsonDataConverter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@
3333
import java.lang.reflect.Type;
3434
import java.nio.charset.StandardCharsets;
3535
import java.util.function.Function;
36-
import org.apache.thrift.protocol.TJSONProtocol;
3736

3837
/**
3938
* Implements conversion through GSON JSON processor. To extend use {@link
40-
* #JsonDataConverter(Function)} constructor. Thrift structures are converted using {@link
41-
* TJSONProtocol}. When using thrift only one argument of a method is expected.
39+
* #JsonDataConverter(Function)} constructor.
4240
*
4341
* @author fateev
4442
*/

src/main/java/com/uber/cadence/internal/common/InternalUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.uber.cadence.internal.worker.Shutdownable;
2828
import com.uber.cadence.workflow.WorkflowMethod;
2929
import java.lang.reflect.Method;
30-
import java.nio.ByteBuffer;
3130
import java.util.HashMap;
3231
import java.util.Map;
3332
import java.util.concurrent.ExecutorService;
@@ -135,21 +134,21 @@ public static Object getValueOrDefault(Object value, Class<?> valueClass) {
135134

136135
public static Memo convertMapToMemo(Map<String, Object> memo) {
137136
DataConverter converter = JsonDataConverter.getInstance();
138-
Map<String, ByteBuffer> mapOfByteBuffer = new HashMap<>();
137+
Map<String, byte[]> mapOfByteBuffer = new HashMap<>();
139138
memo.forEach(
140139
(key, value) -> {
141-
mapOfByteBuffer.put(key, ByteBuffer.wrap(converter.toData(value)));
140+
mapOfByteBuffer.put(key, converter.toData(value));
142141
});
143142
return new Memo().setFields(mapOfByteBuffer);
144143
}
145144

146145
public static SearchAttributes convertMapToSearchAttributes(
147146
Map<String, Object> searchAttributes) {
148147
DataConverter converter = JsonDataConverter.getInstance();
149-
Map<String, ByteBuffer> mapOfByteBuffer = new HashMap<>();
148+
Map<String, byte[]> mapOfByteBuffer = new HashMap<>();
150149
searchAttributes.forEach(
151150
(key, value) -> {
152-
mapOfByteBuffer.put(key, ByteBuffer.wrap(converter.toData(value)));
151+
mapOfByteBuffer.put(key, converter.toData(value));
153152
});
154153
return new SearchAttributes().setIndexedFields(mapOfByteBuffer);
155154
}

src/main/java/com/uber/cadence/internal/common/LocalActivityMarkerData.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.uber.cadence.RespondActivityTaskFailedRequest;
2626
import com.uber.cadence.converter.DataConverter;
2727
import com.uber.m3.util.ImmutableMap;
28-
import java.nio.ByteBuffer;
2928
import java.nio.charset.StandardCharsets;
3029
import java.time.Duration;
3130

@@ -190,14 +189,13 @@ public boolean getIsCancelled() {
190189
public Header getHeader(DataConverter converter) {
191190
byte[] headerData = converter.toData(headers);
192191
Header header = new Header();
193-
header.setFields(ImmutableMap.of(LOCAL_ACTIVITY_HEADER_KEY, ByteBuffer.wrap(headerData)));
192+
header.setFields(ImmutableMap.of(LOCAL_ACTIVITY_HEADER_KEY, headerData));
194193
return header;
195194
}
196195

197196
public static LocalActivityMarkerData fromEventAttributes(
198197
MarkerRecordedEventAttributes attributes, DataConverter converter) {
199-
ByteBuffer byteBuffer = attributes.getHeader().getFields().get(LOCAL_ACTIVITY_HEADER_KEY);
200-
byte[] bytes = org.apache.thrift.TBaseHelper.byteBufferToByteArray(byteBuffer);
198+
byte[] bytes = attributes.getHeader().getFields().get(LOCAL_ACTIVITY_HEADER_KEY);
201199
LocalActivityMarkerHeader header =
202200
converter.fromData(bytes, LocalActivityMarkerHeader.class, LocalActivityMarkerHeader.class);
203201
return new LocalActivityMarkerData(header, attributes.getDetails());

src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,12 @@
2626
import com.google.gson.JsonObject;
2727
import com.google.gson.JsonParser;
2828
import com.google.gson.JsonPrimitive;
29-
import com.uber.cadence.ActivityType;
30-
import com.uber.cadence.Decision;
31-
import com.uber.cadence.DecisionType;
32-
import com.uber.cadence.EntityNotExistsError;
33-
import com.uber.cadence.EventType;
34-
import com.uber.cadence.GetWorkflowExecutionHistoryRequest;
35-
import com.uber.cadence.GetWorkflowExecutionHistoryResponse;
36-
import com.uber.cadence.History;
37-
import com.uber.cadence.HistoryEvent;
38-
import com.uber.cadence.HistoryEventFilterType;
39-
import com.uber.cadence.TaskList;
40-
import com.uber.cadence.WorkflowExecution;
41-
import com.uber.cadence.WorkflowExecutionCloseStatus;
42-
import com.uber.cadence.WorkflowExecutionFailedEventAttributes;
43-
import com.uber.cadence.WorkflowExecutionTerminatedEventAttributes;
44-
import com.uber.cadence.WorkflowExecutionTimedOutEventAttributes;
45-
import com.uber.cadence.WorkflowType;
29+
import com.uber.cadence.*;
4630
import com.uber.cadence.client.WorkflowTerminatedException;
4731
import com.uber.cadence.client.WorkflowTimedOutException;
4832
import com.uber.cadence.common.RetryOptions;
4933
import com.uber.cadence.common.WorkflowExecutionHistory;
34+
import com.uber.cadence.serviceclient.AsyncMethodCallback;
5035
import com.uber.cadence.serviceclient.IWorkflowService;
5136
import java.io.File;
5237
import java.io.IOException;
@@ -63,8 +48,6 @@
6348
import java.util.concurrent.CompletableFuture;
6449
import java.util.concurrent.TimeUnit;
6550
import java.util.concurrent.TimeoutException;
66-
import org.apache.thrift.TException;
67-
import org.apache.thrift.async.AsyncMethodCallback;
6851

6952
/**
7053
* Convenience methods to be used by unit tests and during development.
@@ -200,9 +183,9 @@ private static HistoryEvent getInstanceCloseEvent(
200183
retryOptions,
201184
() -> service.GetWorkflowExecutionHistoryWithTimeout(r, unit.toMillis(timeout)));
202185
} catch (EntityNotExistsError e) {
203-
if (e.activeCluster != null
204-
&& e.currentCluster != null
205-
&& !e.activeCluster.equals(e.currentCluster)) {
186+
if (e.getActiveCluster() != null
187+
&& e.getCurrentCluster() != null
188+
&& !e.getActiveCluster().equals(e.getCurrentCluster())) {
206189
// Current cluster is passive cluster. Execution might not exist because of replication
207190
// lag. If we are still within timeout, wait for a little bit and retry.
208191
if (timeout != 0
@@ -220,7 +203,7 @@ private static HistoryEvent getInstanceCloseEvent(
220203
continue;
221204
}
222205
throw e;
223-
} catch (TException e) {
206+
} catch (CadenceError e) {
224207
throw CheckedExceptionWrapper.wrap(e);
225208
}
226209

@@ -356,7 +339,7 @@ public void onError(Exception exception) {
356339
}
357340
},
358341
unit.toMillis(timeout));
359-
} catch (TException e) {
342+
} catch (CadenceError e) {
360343
result.completeExceptionally(e);
361344
}
362345
return result;
@@ -425,7 +408,7 @@ public static GetWorkflowExecutionHistoryResponse getHistoryPage(
425408
GetWorkflowExecutionHistoryResponse history;
426409
try {
427410
history = service.GetWorkflowExecutionHistory(getHistoryRequest);
428-
} catch (TException e) {
411+
} catch (CadenceError e) {
429412
throw new Error(e);
430413
}
431414
if (history == null) {

0 commit comments

Comments
 (0)