use of com.github.ambry.network.NetworkClientErrorCode in project ambry by linkedin.
the class DeleteManager method extractDeleteResponseAndNotifyResponseHandler.
/**
* Extract the {@link DeleteResponse} from the given {@link ResponseInfo}
* @param responseInfo the {@link ResponseInfo} from which the {@link DeleteResponse} is to be extracted.
* @return the extracted {@link DeleteResponse} if there is one; null otherwise.
*/
private DeleteResponse extractDeleteResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
DeleteResponse deleteResponse = null;
ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
if (networkClientErrorCode == null) {
try {
deleteResponse = DeleteResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())));
responseHandler.onEvent(replicaId, deleteResponse.getError());
} catch (Exception e) {
// Ignore. There is no value in notifying the response handler.
logger.error("Response deserialization received unexpected error", e);
routerMetrics.responseDeserializationErrorCount.inc();
}
} else {
responseHandler.onEvent(replicaId, networkClientErrorCode);
}
return deleteResponse;
}
use of com.github.ambry.network.NetworkClientErrorCode in project ambry by linkedin.
the class GetBlobResultInternal method extractGetResponseAndNotifyResponseHandler.
/**
* Extract the {@link GetResponse} from the given {@link ResponseInfo}
* @param responseInfo the {@link ResponseInfo} from which the {@link GetResponse} is to be extracted.
* @return the extracted {@link GetResponse} if there is one; null otherwise.
*/
private GetResponse extractGetResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
GetResponse getResponse = null;
ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
if (networkClientErrorCode == null) {
try {
getResponse = GetResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())), clusterMap);
ServerErrorCode serverError = getResponse.getError();
if (serverError == ServerErrorCode.No_Error) {
serverError = getResponse.getPartitionResponseInfoList().get(0).getErrorCode();
}
responseHandler.onEvent(replicaId, serverError);
} catch (Exception e) {
// Ignore. There is no value in notifying the response handler.
logger.error("Response deserialization received unexpected error", e);
routerMetrics.responseDeserializationErrorCount.inc();
}
} else {
responseHandler.onEvent(replicaId, networkClientErrorCode);
}
return getResponse;
}
use of com.github.ambry.network.NetworkClientErrorCode in project ambry by linkedin.
the class PutManager method extractPutResponseAndNotifyResponseHandler.
/**
* Extract the {@link PutResponse} from the given {@link ResponseInfo}
* @param responseInfo the {@link ResponseInfo} from which the {@link PutResponse} is to be extracted.
* @return the extracted {@link PutResponse} if there is one; null otherwise.
*/
private PutResponse extractPutResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
PutResponse putResponse = null;
ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
if (networkClientErrorCode == null) {
try {
putResponse = PutResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())));
responseHandler.onEvent(replicaId, putResponse.getError());
} catch (Exception e) {
// Ignore. There is no value in notifying the response handler.
logger.error("Response deserialization received unexpected error", e);
routerMetrics.responseDeserializationErrorCount.inc();
}
} else {
responseHandler.onEvent(replicaId, networkClientErrorCode);
}
return putResponse;
}
use of com.github.ambry.network.NetworkClientErrorCode in project ambry by linkedin.
the class RouterUtils method extractResponseAndNotifyResponseHandler.
/**
* Extract the {@link Response} from the given {@link ResponseInfo}
* @param <R> the {@link Response} type.
* @param responseHandler the {@link ResponseHandler} instance to use.
* @param routerMetrics the {@link NonBlockingRouterMetrics} instance to use.
* @param responseInfo the {@link ResponseInfo} from which the {@link Response} is to be extracted.
* @param deserializer the {@link Deserializer} to use.
* @param errorExtractor extract the {@link ServerErrorCode} to send to {@link ResponseHandler#onEvent}.
* @return the extracted {@link Response} if there is one; null otherwise.
*/
@SuppressWarnings("unchecked")
static <R extends Response> R extractResponseAndNotifyResponseHandler(ResponseHandler responseHandler, NonBlockingRouterMetrics routerMetrics, ResponseInfo responseInfo, Deserializer<R> deserializer, Function<R, ServerErrorCode> errorExtractor) {
R response = null;
ReplicaId replicaId = responseInfo.getRequestInfo().getReplicaId();
NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
if (networkClientErrorCode == null) {
try {
if (responseInfo.getResponse() != null) {
// If this responseInfo already has the deserialized java object, we can reference it directly. This is
// applicable when we are receiving responses from Azure APIs in frontend. The responses from Azure are
// handled in {@code AmbryRequest} class methods using a thread pool running with in the frontend. These
// responses are then sent using local queues in {@code LocalRequestResponseChannel}.
response = (R) mapToReceivedResponse((Response) responseInfo.getResponse());
} else {
DataInputStream dis = new NettyByteBufDataInputStream(responseInfo.content());
response = deserializer.readFrom(dis);
}
responseHandler.onEvent(replicaId, errorExtractor.apply(response));
} catch (Exception e) {
// Ignore. There is no value in notifying the response handler.
logger.error("Response deserialization received unexpected error", e);
routerMetrics.responseDeserializationErrorCount.inc();
}
} else {
responseHandler.onEvent(replicaId, networkClientErrorCode);
}
return response;
}
Aggregations