software.amazon.awssdk.services.sagemakerfeaturestoreruntime.DefaultSageMakerFeatureStoreRuntimeClient Maven / Gradle / Ivy
Show all versions of sagemakerfeaturestoreruntime Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.sagemakerfeaturestoreruntime;
import java.util.Collections;
import java.util.List;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.RequestOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.client.handler.SyncClientHandler;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.metrics.CoreMetric;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.NoOpMetricCollector;
import software.amazon.awssdk.protocols.core.ExceptionMetadata;
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.AccessForbiddenException;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.BatchGetRecordRequest;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.BatchGetRecordResponse;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.DeleteRecordRequest;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.DeleteRecordResponse;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.GetRecordRequest;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.GetRecordResponse;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.InternalFailureException;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.PutRecordRequest;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.PutRecordResponse;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.ResourceNotFoundException;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.SageMakerFeatureStoreRuntimeException;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.ServiceUnavailableException;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.model.ValidationErrorException;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.transform.BatchGetRecordRequestMarshaller;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.transform.DeleteRecordRequestMarshaller;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.transform.GetRecordRequestMarshaller;
import software.amazon.awssdk.services.sagemakerfeaturestoreruntime.transform.PutRecordRequestMarshaller;
import software.amazon.awssdk.utils.Logger;
/**
* Internal implementation of {@link SageMakerFeatureStoreRuntimeClient}.
*
* @see SageMakerFeatureStoreRuntimeClient#builder()
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultSageMakerFeatureStoreRuntimeClient implements SageMakerFeatureStoreRuntimeClient {
private static final Logger log = Logger.loggerFor(DefaultSageMakerFeatureStoreRuntimeClient.class);
private final SyncClientHandler clientHandler;
private final AwsJsonProtocolFactory protocolFactory;
private final SdkClientConfiguration clientConfiguration;
protected DefaultSageMakerFeatureStoreRuntimeClient(SdkClientConfiguration clientConfiguration) {
this.clientHandler = new AwsSyncClientHandler(clientConfiguration);
this.clientConfiguration = clientConfiguration;
this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
}
@Override
public final String serviceName() {
return SERVICE_NAME;
}
/**
*
* Retrieves a batch of Records
from a FeatureGroup
.
*
*
* @param batchGetRecordRequest
* @return Result of the BatchGetRecord operation returned by the service.
* @throws ValidationErrorException
* There was an error validating your request.
* @throws InternalFailureException
* An internal failure occurred. Try your request again. If the problem persists, contact AWS customer
* support.
* @throws ServiceUnavailableException
* The service is currently unavailable.
* @throws AccessForbiddenException
* You do not have permission to perform an action.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws SageMakerFeatureStoreRuntimeException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample SageMakerFeatureStoreRuntimeClient.BatchGetRecord
* @see AWS API Documentation
*/
@Override
public BatchGetRecordResponse batchGetRecord(BatchGetRecordRequest batchGetRecordRequest) throws ValidationErrorException,
InternalFailureException, ServiceUnavailableException, AccessForbiddenException, AwsServiceException,
SdkClientException, SageMakerFeatureStoreRuntimeException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
BatchGetRecordResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
List metricPublishers = resolveMetricPublishers(clientConfiguration, batchGetRecordRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "SageMaker FeatureStore Runtime");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "BatchGetRecord");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("BatchGetRecord").withResponseHandler(responseHandler)
.withErrorResponseHandler(errorResponseHandler).withInput(batchGetRecordRequest)
.withMetricCollector(apiCallMetricCollector)
.withMarshaller(new BatchGetRecordRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
/**
*
* Deletes a Record
from a FeatureGroup
. A new record will show up in the
* OfflineStore
when the DeleteRecord
API is called. This record will have a value of
* True
in the is_deleted
column.
*
*
* @param deleteRecordRequest
* @return Result of the DeleteRecord operation returned by the service.
* @throws ValidationErrorException
* There was an error validating your request.
* @throws InternalFailureException
* An internal failure occurred. Try your request again. If the problem persists, contact AWS customer
* support.
* @throws ServiceUnavailableException
* The service is currently unavailable.
* @throws AccessForbiddenException
* You do not have permission to perform an action.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws SageMakerFeatureStoreRuntimeException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample SageMakerFeatureStoreRuntimeClient.DeleteRecord
* @see AWS API Documentation
*/
@Override
public DeleteRecordResponse deleteRecord(DeleteRecordRequest deleteRecordRequest) throws ValidationErrorException,
InternalFailureException, ServiceUnavailableException, AccessForbiddenException, AwsServiceException,
SdkClientException, SageMakerFeatureStoreRuntimeException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
DeleteRecordResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteRecordRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "SageMaker FeatureStore Runtime");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteRecord");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("DeleteRecord").withResponseHandler(responseHandler)
.withErrorResponseHandler(errorResponseHandler).withInput(deleteRecordRequest)
.withMetricCollector(apiCallMetricCollector)
.withMarshaller(new DeleteRecordRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
/**
*
* Use for OnlineStore
serving from a FeatureStore
. Only the latest records stored in the
* OnlineStore
can be retrieved. If no Record with RecordIdentifierValue
is found, then an
* empty result is returned.
*
*
* @param getRecordRequest
* @return Result of the GetRecord operation returned by the service.
* @throws ValidationErrorException
* There was an error validating your request.
* @throws ResourceNotFoundException
* A resource that is required to perform an action was not found.
* @throws InternalFailureException
* An internal failure occurred. Try your request again. If the problem persists, contact AWS customer
* support.
* @throws ServiceUnavailableException
* The service is currently unavailable.
* @throws AccessForbiddenException
* You do not have permission to perform an action.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws SageMakerFeatureStoreRuntimeException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample SageMakerFeatureStoreRuntimeClient.GetRecord
* @see AWS API Documentation
*/
@Override
public GetRecordResponse getRecord(GetRecordRequest getRecordRequest) throws ValidationErrorException,
ResourceNotFoundException, InternalFailureException, ServiceUnavailableException, AccessForbiddenException,
AwsServiceException, SdkClientException, SageMakerFeatureStoreRuntimeException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
GetRecordResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getRecordRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "SageMaker FeatureStore Runtime");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetRecord");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("GetRecord").withResponseHandler(responseHandler)
.withErrorResponseHandler(errorResponseHandler).withInput(getRecordRequest)
.withMetricCollector(apiCallMetricCollector).withMarshaller(new GetRecordRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
/**
*
* Used for data ingestion into the FeatureStore
. The PutRecord
API writes to both the
* OnlineStore
and OfflineStore
. If the record is the latest record for the
* recordIdentifier
, the record is written to both the OnlineStore
and
* OfflineStore
. If the record is a historic record, it is written only to the
* OfflineStore
.
*
*
* @param putRecordRequest
* @return Result of the PutRecord operation returned by the service.
* @throws ValidationErrorException
* There was an error validating your request.
* @throws InternalFailureException
* An internal failure occurred. Try your request again. If the problem persists, contact AWS customer
* support.
* @throws ServiceUnavailableException
* The service is currently unavailable.
* @throws AccessForbiddenException
* You do not have permission to perform an action.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws SageMakerFeatureStoreRuntimeException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample SageMakerFeatureStoreRuntimeClient.PutRecord
* @see AWS API Documentation
*/
@Override
public PutRecordResponse putRecord(PutRecordRequest putRecordRequest) throws ValidationErrorException,
InternalFailureException, ServiceUnavailableException, AccessForbiddenException, AwsServiceException,
SdkClientException, SageMakerFeatureStoreRuntimeException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
PutRecordResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
List metricPublishers = resolveMetricPublishers(clientConfiguration, putRecordRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "SageMaker FeatureStore Runtime");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PutRecord");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("PutRecord").withResponseHandler(responseHandler)
.withErrorResponseHandler(errorResponseHandler).withInput(putRecordRequest)
.withMetricCollector(apiCallMetricCollector).withMarshaller(new PutRecordRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration,
RequestOverrideConfiguration requestOverrideConfiguration) {
List publishers = null;
if (requestOverrideConfiguration != null) {
publishers = requestOverrideConfiguration.metricPublishers();
}
if (publishers == null || publishers.isEmpty()) {
publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS);
}
if (publishers == null) {
publishers = Collections.emptyList();
}
return publishers;
}
private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata) {
return protocolFactory.createErrorResponseHandler(operationMetadata);
}
private > T init(T builder) {
return builder
.clientConfiguration(clientConfiguration)
.defaultServiceExceptionSupplier(SageMakerFeatureStoreRuntimeException::builder)
.protocol(AwsJsonProtocol.REST_JSON)
.protocolVersion("1.1")
.registerModeledException(
ExceptionMetadata.builder().errorCode("ValidationError")
.exceptionBuilderSupplier(ValidationErrorException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ServiceUnavailable")
.exceptionBuilderSupplier(ServiceUnavailableException::builder).httpStatusCode(503).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("AccessForbidden")
.exceptionBuilderSupplier(AccessForbiddenException::builder).httpStatusCode(403).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InternalFailure")
.exceptionBuilderSupplier(InternalFailureException::builder).httpStatusCode(500).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ResourceNotFound")
.exceptionBuilderSupplier(ResourceNotFoundException::builder).httpStatusCode(404).build());
}
@Override
public void close() {
clientHandler.close();
}
}