Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;
import org.apache.http.entity.InputStreamEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

/**
* Interface for interacting with Databricks Unity Catalog (UC) Volumes. Provides methods for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import org.apache.http.entity.InputStreamEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

public class DatabricksResultSet implements IDatabricksResultSet, IDatabricksResultSetInternal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;
import org.apache.http.entity.InputStreamEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

public class DatabricksStatement implements IDatabricksStatement, IDatabricksStatementInternal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.sql.*;
import java.util.Calendar;
import java.util.Map;
import org.apache.http.entity.InputStreamEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

/** Empty implementation of ResultSet */
public class EmptyResultSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.time.Instant;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.http.client.utils.URIBuilder;

public class ArrowResultChunk extends AbstractArrowResultChunk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
import org.apache.hc.client5.http.async.methods.*;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
import org.apache.hc.core5.http.nio.AsyncRequestProducer;
import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
import org.apache.hc.core5.http.nio.entity.AsyncEntityProducers;
import org.apache.hc.core5.http.nio.support.AsyncRequestBuilder;
import org.apache.http.HttpEntity;
import org.apache.http.entity.InputStreamEntity;

/** Implementation of Volume Client that directly calls SQL Exec API for the Volume Operations */
public class DBFSVolumeClient implements IDatabricksVolumeClient, Closeable {
Expand Down Expand Up @@ -416,7 +416,8 @@ public boolean putObject(
CreateUploadUrlResponse response =
getCreateUploadUrlResponse(getObjectFullPath(catalog, schema, volume, objectPath));

InputStreamEntity inputStreamEntity = new InputStreamEntity(inputStream, contentLength);
InputStreamEntity inputStreamEntity =
new InputStreamEntity(inputStream, org.apache.hc.core5.http.ContentType.DEFAULT_BINARY);
// Uploading the object to the Pre Signed Url
VolumeOperationProcessor volumeOperationProcessor =
VolumeOperationProcessor.Builder.createBuilder()
Expand Down Expand Up @@ -582,7 +583,8 @@ public void setVolumeOperationEntityStream(HttpEntity httpEntity) throws IOExcep
}

public InputStreamEntity getVolumeOperationInputStream() {
return new InputStreamEntity(this.volumeInputStream, this.volumeStreamContentLength);
return new InputStreamEntity(
this.volumeInputStream, org.apache.hc.core5.http.ContentType.DEFAULT_BINARY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.entity.InputStreamEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

/** Implementation of the VolumeClient that uses SQL query to perform the Volume Operations */
public class DatabricksUCVolumeClient implements IDatabricksVolumeClient {
Expand Down Expand Up @@ -418,7 +418,7 @@ public boolean putObject(
statement.unwrap(IDatabricksStatementInternal.class);
databricksStatement.allowInputStreamForVolumeOperation(true);
databricksStatement.setInputStreamForUCVolume(
new InputStreamEntity(inputStream, contentLength));
new InputStreamEntity(inputStream, org.apache.hc.core5.http.ContentType.DEFAULT_BINARY));

try (ResultSet resultSet = statement.executeQuery(putObjectQueryForInputStream)) {
LOGGER.info("PUT query executed successfully");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;

public class VolumeInputStream extends InputStream {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import java.io.*;
import java.util.*;
import java.util.function.Consumer;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpDelete;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.FileEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

/** Executor for volume operations */
class VolumeOperationProcessor {
Expand Down Expand Up @@ -264,8 +264,7 @@ void executeGetOperation() {
errorMessage =
String.format(
"Failed to fetch content from volume with error code {%s} for input stream and error {%s}",
responseStream.getStatusLine().getStatusCode(),
responseStream.getStatusLine().getReasonPhrase());
responseStream.getCode(), responseStream.getReasonPhrase());
LOGGER.error(errorMessage);
closeResponse(responseStream);
return;
Expand Down Expand Up @@ -295,7 +294,7 @@ void executeGetOperation() {
if (!HttpUtil.isSuccessfulHttpResponse(response)) {
LOGGER.error(
"Failed to fetch content from volume with error {%s} for local file {%s}",
response.getStatusLine().getStatusCode(), localFilePath);
response.getCode(), localFilePath);
status = VolumeOperationStatus.FAILED;
errorMessage = "Failed to download file";
return;
Expand Down Expand Up @@ -367,12 +366,10 @@ void executePutOperation() {
status = VolumeOperationStatus.SUCCEEDED;
} else {
LOGGER.error(
"Failed to upload file {%s} with error code: {%s}",
localFilePath, response.getStatusLine().getStatusCode());
"Failed to upload file {%s} with error code: {%s}", localFilePath, response.getCode());
// TODO: Add retries
status = VolumeOperationStatus.FAILED;
errorMessage =
"Failed to upload file with error code: " + response.getStatusLine().getStatusCode();
errorMessage = "Failed to upload file with error code: " + response.getCode();
}
} catch (IOException | DatabricksHttpException e) {
LOGGER.error("Failed to upload file {} with error {}", localFilePath, e.getMessage());
Expand Down Expand Up @@ -412,9 +409,7 @@ private void executeDeleteOperation() {
if (HttpUtil.isSuccessfulHttpResponse(response)) {
status = VolumeOperationStatus.SUCCEEDED;
} else {
LOGGER.error(
"Failed to delete volume with error code: {%s}",
response.getStatusLine().getStatusCode());
LOGGER.error("Failed to delete volume with error code: {%s}", response.getCode());
status = VolumeOperationStatus.FAILED;
errorMessage = "Failed to delete volume";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

/** Class to handle the result of a volume operation */
public class VolumeOperationResult implements IExecutionResult {
Expand Down Expand Up @@ -226,7 +226,8 @@ public void setVolumeOperationEntityStream(HttpEntity httpEntity) throws IOExcep
}

public InputStreamEntity getVolumeOperationInputStream() {
return new InputStreamEntity(this.volumeInputStream, this.volumeStreamContentLength);
return new InputStreamEntity(
this.volumeInputStream, org.apache.hc.core5.http.ContentType.DEFAULT_BINARY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.databricks.jdbc.api.internal;

import java.sql.SQLException;
import org.apache.http.entity.InputStreamEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

/** Extended callback handle for java.sql.ResultSet interface */
public interface IDatabricksResultSetInternal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.databricks.jdbc.dbclient.impl.common.StatementId;
import com.databricks.jdbc.exception.DatabricksSQLException;
import java.sql.Statement;
import org.apache.http.entity.InputStreamEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;

/** Extended callback handle for java.sql.Statement interface */
public interface IDatabricksStatementInternal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.http.HttpHeaders;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

/**
* Production-ready Azure U2M OAuth provider for Databricks SQL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;

/**
Expand Down Expand Up @@ -137,7 +136,8 @@ private static Token retrieveToken(
HttpGet getRequest = new HttpGet(uriBuilder.build());
headers.forEach(getRequest::setHeader);
LOGGER.debug("Executing GET request to retrieve Azure MSI token");
HttpResponse response = hc.execute(getRequest);
org.apache.hc.client5.http.impl.classic.CloseableHttpResponse response =
(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse) hc.execute(getRequest);
OAuthResponse resp =
JsonUtil.getMapper().readValue(response.getEntity().getContent(), OAuthResponse.class);
Instant expiry = Instant.now().plus(resp.getExpiresIn(), ChronoUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.message.BasicNameValuePair;

/**
* Implementation of the Credential Provider that exchanges the third party access token for a
Expand Down Expand Up @@ -215,7 +214,8 @@ Token retrieveToken(
.collect(Collectors.toList()),
StandardCharsets.UTF_8));
headers.forEach(postRequest::setHeader);
HttpResponse response = hc.execute(postRequest);
org.apache.hc.client5.http.impl.classic.CloseableHttpResponse response =
(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse) hc.execute(postRequest);
OAuthResponse resp =
JsonUtil.getMapper().readValue(response.getEntity().getContent(), OAuthResponse.class);
return createToken(resp.getAccessToken(), resp.getTokenType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.PEMException;
Expand Down Expand Up @@ -180,7 +179,8 @@ protected static Token retrieveToken(
.collect(Collectors.toList()),
StandardCharsets.UTF_8));
headers.forEach(postRequest::setHeader);
HttpResponse response = hc.execute(postRequest);
org.apache.hc.client5.http.impl.classic.CloseableHttpResponse response =
(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse) hc.execute(postRequest);
OAuthResponse resp =
JsonUtil.getMapper().readValue(response.getEntity().getContent(), OAuthResponse.class);
Instant expiry = Instant.now().plus(resp.getExpiresIn(), ChronoUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;

/** Context for dynamic feature flags that control the behavior of the driver. */
public class DatabricksDriverFeatureFlagsContext {
Expand Down Expand Up @@ -106,9 +106,9 @@ private void refreshAllFeatureFlags() {

@VisibleForTesting
void fetchAndSetFlagsFromServer(IDatabricksHttpClient httpClient, HttpGet request)
throws DatabricksHttpException, IOException {
throws DatabricksHttpException, IOException, org.apache.hc.core5.http.ParseException {
try (CloseableHttpResponse response = httpClient.execute(request)) {
if (response.getStatusLine().getStatusCode() == 200) {
if (response.getCode() == 200) {
String responseBody = EntityUtils.toString(response.getEntity());
FeatureFlagsResponse featureFlagsResponse =
JsonUtil.getMapper().readValue(responseBody, FeatureFlagsResponse.class);
Expand All @@ -127,7 +127,7 @@ void fetchAndSetFlagsFromServer(IDatabricksHttpClient httpClient, HttpGet reques
LOGGER.trace(
"Failed to fetch feature flags. Context: {}, Status code: {}",
connectionContext,
response.getStatusLine().getStatusCode());
response.getCode());
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/databricks/jdbc/common/util/HttpUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.databricks.jdbc.common.util;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;

public class HttpUtil {
/** Check if the HTTP response is successful */
public static boolean isSuccessfulHttpResponse(CloseableHttpResponse response) {
return response.getStatusLine().getStatusCode() >= 200
&& response.getStatusLine().getStatusCode() < 300;
return response.getCode() >= 200 && response.getCode() < 300;
}
}
Loading
Loading