@@ -158,6 +158,8 @@ public String scheduleNewOrchestrationInstance(
158158 CreateInstanceRequest request = builder .build ();
159159 CreateInstanceResponse response = this .sidecarClient .startInstance (request );
160160 return response .getInstanceId ();
161+ } catch (StatusRuntimeException e ) {
162+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "scheduleNewOrchestrationInstance" );
161163 } finally {
162164 createScope .close ();
163165 createSpan .end ();
@@ -181,7 +183,11 @@ public void raiseEvent(String instanceId, String eventName, Object eventPayload)
181183 }
182184
183185 RaiseEventRequest request = builder .build ();
184- this .sidecarClient .raiseEvent (request );
186+ try {
187+ this .sidecarClient .raiseEvent (request );
188+ } catch (StatusRuntimeException e ) {
189+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "raiseEvent" );
190+ }
185191 }
186192
187193 @ Override
@@ -190,8 +196,12 @@ public OrchestrationMetadata getInstanceMetadata(String instanceId, boolean getI
190196 .setInstanceId (instanceId )
191197 .setGetInputsAndOutputs (getInputsAndOutputs )
192198 .build ();
193- GetInstanceResponse response = this .sidecarClient .getInstance (request );
194- return new OrchestrationMetadata (response , this .dataConverter , request .getGetInputsAndOutputs ());
199+ try {
200+ GetInstanceResponse response = this .sidecarClient .getInstance (request );
201+ return new OrchestrationMetadata (response , this .dataConverter , request .getGetInputsAndOutputs ());
202+ } catch (StatusRuntimeException e ) {
203+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "getInstanceMetadata" );
204+ }
195205 }
196206
197207 @ Override
@@ -216,7 +226,11 @@ public OrchestrationMetadata waitForInstanceStart(String instanceId, Duration ti
216226 if (e .getStatus ().getCode () == Status .Code .DEADLINE_EXCEEDED ) {
217227 throw new TimeoutException ("Start orchestration timeout reached." );
218228 }
219- throw e ;
229+ Exception translated = StatusRuntimeExceptionHelper .toException (e , "waitForInstanceStart" );
230+ if (translated instanceof RuntimeException ) {
231+ throw (RuntimeException ) translated ;
232+ }
233+ throw new RuntimeException (translated );
220234 }
221235 return new OrchestrationMetadata (response , this .dataConverter , request .getGetInputsAndOutputs ());
222236 }
@@ -243,7 +257,11 @@ public OrchestrationMetadata waitForInstanceCompletion(String instanceId, Durati
243257 if (e .getStatus ().getCode () == Status .Code .DEADLINE_EXCEEDED ) {
244258 throw new TimeoutException ("Orchestration instance completion timeout reached." );
245259 }
246- throw e ;
260+ Exception translated = StatusRuntimeExceptionHelper .toException (e , "waitForInstanceCompletion" );
261+ if (translated instanceof RuntimeException ) {
262+ throw (RuntimeException ) translated ;
263+ }
264+ throw new RuntimeException (translated );
247265 }
248266 return new OrchestrationMetadata (response , this .dataConverter , request .getGetInputsAndOutputs ());
249267 }
@@ -260,7 +278,11 @@ public void terminate(String instanceId, @Nullable Object output) {
260278 if (serializeOutput != null ){
261279 builder .setOutput (StringValue .of (serializeOutput ));
262280 }
263- this .sidecarClient .terminateInstance (builder .build ());
281+ try {
282+ this .sidecarClient .terminateInstance (builder .build ());
283+ } catch (StatusRuntimeException e ) {
284+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "terminate" );
285+ }
264286 }
265287
266288 @ Override
@@ -274,8 +296,12 @@ public OrchestrationStatusQueryResult queryInstances(OrchestrationStatusQuery qu
274296 instanceQueryBuilder .setMaxInstanceCount (query .getMaxInstanceCount ());
275297 query .getRuntimeStatusList ().forEach (runtimeStatus -> Optional .ofNullable (runtimeStatus ).ifPresent (status -> instanceQueryBuilder .addRuntimeStatus (OrchestrationRuntimeStatus .toProtobuf (status ))));
276298 query .getTaskHubNames ().forEach (taskHubName -> Optional .ofNullable (taskHubName ).ifPresent (name -> instanceQueryBuilder .addTaskHubNames (StringValue .of (name ))));
277- QueryInstancesResponse queryInstancesResponse = this .sidecarClient .queryInstances (QueryInstancesRequest .newBuilder ().setQuery (instanceQueryBuilder ).build ());
278- return toQueryResult (queryInstancesResponse , query .isFetchInputsAndOutputs ());
299+ try {
300+ QueryInstancesResponse queryInstancesResponse = this .sidecarClient .queryInstances (QueryInstancesRequest .newBuilder ().setQuery (instanceQueryBuilder ).build ());
301+ return toQueryResult (queryInstancesResponse , query .isFetchInputsAndOutputs ());
302+ } catch (StatusRuntimeException e ) {
303+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "queryInstances" );
304+ }
279305 }
280306
281307 private OrchestrationStatusQueryResult toQueryResult (QueryInstancesResponse queryInstancesResponse , boolean fetchInputsAndOutputs ){
@@ -288,12 +314,20 @@ private OrchestrationStatusQueryResult toQueryResult(QueryInstancesResponse quer
288314
289315 @ Override
290316 public void createTaskHub (boolean recreateIfExists ) {
291- this .sidecarClient .createTaskHub (CreateTaskHubRequest .newBuilder ().setRecreateIfExists (recreateIfExists ).build ());
317+ try {
318+ this .sidecarClient .createTaskHub (CreateTaskHubRequest .newBuilder ().setRecreateIfExists (recreateIfExists ).build ());
319+ } catch (StatusRuntimeException e ) {
320+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "createTaskHub" );
321+ }
292322 }
293323
294324 @ Override
295325 public void deleteTaskHub () {
296- this .sidecarClient .deleteTaskHub (DeleteTaskHubRequest .newBuilder ().build ());
326+ try {
327+ this .sidecarClient .deleteTaskHub (DeleteTaskHubRequest .newBuilder ().build ());
328+ } catch (StatusRuntimeException e ) {
329+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "deleteTaskHub" );
330+ }
297331 }
298332
299333 @ Override
@@ -302,8 +336,12 @@ public PurgeResult purgeInstance(String instanceId) {
302336 .setInstanceId (instanceId )
303337 .build ();
304338
305- PurgeInstancesResponse response = this .sidecarClient .purgeInstances (request );
306- return toPurgeResult (response );
339+ try {
340+ PurgeInstancesResponse response = this .sidecarClient .purgeInstances (request );
341+ return toPurgeResult (response );
342+ } catch (StatusRuntimeException e ) {
343+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "purgeInstance" );
344+ }
307345 }
308346
309347 @ Override
@@ -331,7 +369,11 @@ public PurgeResult purgeInstances(PurgeInstanceCriteria purgeInstanceCriteria) t
331369 String timeOutException = String .format ("Purge instances timeout duration of %s reached." , timeout );
332370 throw new TimeoutException (timeOutException );
333371 }
334- throw e ;
372+ Exception translated = StatusRuntimeExceptionHelper .toException (e , "purgeInstances" );
373+ if (translated instanceof RuntimeException ) {
374+ throw (RuntimeException ) translated ;
375+ }
376+ throw new RuntimeException (translated );
335377 }
336378 }
337379
@@ -342,7 +384,11 @@ public void suspendInstance(String instanceId, @Nullable String reason) {
342384 if (reason != null ) {
343385 suspendRequestBuilder .setReason (StringValue .of (reason ));
344386 }
345- this .sidecarClient .suspendInstance (suspendRequestBuilder .build ());
387+ try {
388+ this .sidecarClient .suspendInstance (suspendRequestBuilder .build ());
389+ } catch (StatusRuntimeException e ) {
390+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "suspendInstance" );
391+ }
346392 }
347393
348394 @ Override
@@ -352,7 +398,11 @@ public void resumeInstance(String instanceId, @Nullable String reason) {
352398 if (reason != null ) {
353399 resumeRequestBuilder .setReason (StringValue .of (reason ));
354400 }
355- this .sidecarClient .resumeInstance (resumeRequestBuilder .build ());
401+ try {
402+ this .sidecarClient .resumeInstance (resumeRequestBuilder .build ());
403+ } catch (StatusRuntimeException e ) {
404+ throw StatusRuntimeExceptionHelper .toRuntimeException (e , "resumeInstance" );
405+ }
356406 }
357407
358408 @ Override
@@ -374,7 +424,7 @@ public void rewindInstance(String instanceId, @Nullable String reason) {
374424 throw new IllegalStateException (
375425 "Orchestration instance '" + instanceId + "' is not in a failed state and cannot be rewound." , e );
376426 }
377- throw e ;
427+ throw StatusRuntimeExceptionHelper . toRuntimeException ( e , "rewindInstance" ) ;
378428 }
379429 }
380430
0 commit comments