2323import com .databricks .jdbc .model .client .filesystem .*;
2424import com .databricks .jdbc .model .telemetry .enums .DatabricksDriverErrorCode ;
2525import com .databricks .sdk .WorkspaceClient ;
26+ import com .databricks .sdk .core .ApiClient ;
2627import com .databricks .sdk .core .DatabricksException ;
2728import com .databricks .sdk .core .error .platform .NotFound ;
29+ import com .databricks .sdk .core .http .Request ;
2830import com .google .common .annotations .VisibleForTesting ;
2931import java .io .Closeable ;
3032import java .io .IOException ;
@@ -44,19 +46,22 @@ public class DBFSVolumeClient implements IDatabricksVolumeClient, Closeable {
4446 private VolumeInputStream volumeInputStream = null ;
4547 private long volumeStreamContentLength = -1L ;
4648 final WorkspaceClient workspaceClient ;
49+ final ApiClient apiClient ;
4750 private final String allowedVolumeIngestionPaths ;
4851
4952 @ VisibleForTesting
5053 public DBFSVolumeClient (WorkspaceClient workspaceClient ) {
5154 this .connectionContext = null ;
5255 this .workspaceClient = workspaceClient ;
56+ this .apiClient = workspaceClient .apiClient ();
5357 this .databricksHttpClient = null ;
5458 this .allowedVolumeIngestionPaths = "" ;
5559 }
5660
5761 public DBFSVolumeClient (IDatabricksConnectionContext connectionContext ) {
5862 this .connectionContext = connectionContext ;
5963 this .workspaceClient = getWorkspaceClientFromConnectionContext (connectionContext );
64+ this .apiClient = workspaceClient .apiClient ();
6065 this .databricksHttpClient =
6166 DatabricksHttpClientFactory .getInstance ()
6267 .getClient (connectionContext , HttpClientType .VOLUME );
@@ -403,10 +408,10 @@ CreateUploadUrlResponse getCreateUploadUrlResponse(String objectPath)
403408
404409 CreateUploadUrlRequest request = new CreateUploadUrlRequest (objectPath );
405410 try {
406- return workspaceClient
407- . apiClient ()
408- . POST ( CREATE_UPLOAD_URL_PATH , request , CreateUploadUrlResponse .class , JSON_HTTP_HEADERS );
409- } catch (DatabricksException e ) {
411+ Request req = new Request ( Request . POST , CREATE_UPLOAD_URL_PATH , apiClient . serialize ( request ));
412+ req . withHeaders ( JSON_HTTP_HEADERS );
413+ return apiClient . execute ( req , CreateUploadUrlResponse .class );
414+ } catch (IOException | DatabricksException e ) {
410415 String errorMessage =
411416 String .format ("Failed to get create upload url response - {%s}" , e .getMessage ());
412417 LOGGER .error (e , errorMessage );
@@ -426,14 +431,11 @@ CreateDownloadUrlResponse getCreateDownloadUrlResponse(String objectPath)
426431 CreateDownloadUrlRequest request = new CreateDownloadUrlRequest (objectPath );
427432
428433 try {
429- return workspaceClient
430- .apiClient ()
431- .POST (
432- CREATE_DOWNLOAD_URL_PATH ,
433- request ,
434- CreateDownloadUrlResponse .class ,
435- JSON_HTTP_HEADERS );
436- } catch (DatabricksException e ) {
434+ Request req =
435+ new Request (Request .POST , CREATE_DOWNLOAD_URL_PATH , apiClient .serialize (request ));
436+ req .withHeaders (JSON_HTTP_HEADERS );
437+ return apiClient .execute (req , CreateDownloadUrlResponse .class );
438+ } catch (IOException | DatabricksException e ) {
437439 String errorMessage =
438440 String .format ("Failed to get create download url response - {%s}" , e .getMessage ());
439441 LOGGER .error (e , errorMessage );
@@ -452,10 +454,10 @@ CreateDeleteUrlResponse getCreateDeleteUrlResponse(String objectPath)
452454 CreateDeleteUrlRequest request = new CreateDeleteUrlRequest (objectPath );
453455
454456 try {
455- return workspaceClient
456- . apiClient ()
457- . POST ( CREATE_DELETE_URL_PATH , request , CreateDeleteUrlResponse .class , JSON_HTTP_HEADERS );
458- } catch (DatabricksException e ) {
457+ Request req = new Request ( Request . POST , CREATE_DELETE_URL_PATH , apiClient . serialize ( request ));
458+ req . withHeaders ( JSON_HTTP_HEADERS );
459+ return apiClient . execute ( req , CreateDeleteUrlResponse .class );
460+ } catch (IOException | DatabricksException e ) {
459461 String errorMessage =
460462 String .format ("Failed to get create delete url response - {%s}" , e .getMessage ());
461463 LOGGER .error (e , errorMessage );
@@ -470,10 +472,11 @@ ListResponse getListResponse(String listPath) throws DatabricksVolumeOperationEx
470472 String .format ("Entering getListResponse method with parameters : listPath={%s}" , listPath ));
471473 ListRequest request = new ListRequest (listPath );
472474 try {
473- return workspaceClient
474- .apiClient ()
475- .GET (LIST_PATH , request , ListResponse .class , JSON_HTTP_HEADERS );
476- } catch (DatabricksException e ) {
475+ Request req = new Request (Request .GET , LIST_PATH );
476+ req .withHeaders (JSON_HTTP_HEADERS );
477+ ApiClient .setQuery (req , request );
478+ return apiClient .execute (req , ListResponse .class );
479+ } catch (IOException | DatabricksException e ) {
477480 String errorMessage = String .format ("Failed to get list response - {%s}" , e .getMessage ());
478481 LOGGER .error (e , errorMessage );
479482 throw new DatabricksVolumeOperationException (
0 commit comments