use of org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint in project bookkeeper by apache.
the class TestProtocolInternalUtils method testCreateStorageContainerEndpointResponse.
@Test
public void testCreateStorageContainerEndpointResponse() {
List<StorageContainerEndpoint> endpoints = Lists.newArrayList(StorageContainerEndpoint.newBuilder().setStorageContainerId(1L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(2L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(3L).build());
GetStorageContainerEndpointResponse response = createGetStorageContainerEndpointResponse(endpoints);
assertEquals(3, response.getResponsesCount());
int i = 0;
for (OneStorageContainerEndpointResponse oneResp : response.getResponsesList()) {
assertEquals(StatusCode.SUCCESS, oneResp.getStatusCode());
assertTrue(endpoints.get(i) == oneResp.getEndpoint());
++i;
}
}
use of org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint in project bookkeeper by apache.
the class ProtoUtils method createGetStorageContainerEndpointResponse.
/**
* Create a {@link GetStorageContainerEndpointResponse}.
*
* @param endpoints list of storage container endpoints
* @return a get storage container endpoint response.
*/
public static GetStorageContainerEndpointResponse createGetStorageContainerEndpointResponse(List<StorageContainerEndpoint> endpoints) {
GetStorageContainerEndpointResponse.Builder builder = GetStorageContainerEndpointResponse.newBuilder();
builder.setStatusCode(StatusCode.SUCCESS);
for (StorageContainerEndpoint endpoint : endpoints) {
builder.addResponses(OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(endpoint));
}
return builder.build();
}
use of org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint in project bookkeeper by apache.
the class StorageContainerChannel method handleFetchStorageContainerInfoSuccess.
private void handleFetchStorageContainerInfoSuccess(List<OneStorageContainerEndpointResponse> storageContainerEndpoints) {
if (storageContainerEndpoints.size() != 1) {
handleFetchStorageContainerInfoFailure(new Exception("Expected only one storage container endpoint. But found " + storageContainerEndpoints.size() + " storage container endpoints."));
return;
}
OneStorageContainerEndpointResponse response = storageContainerEndpoints.get(0);
if (StatusCode.SUCCESS != response.getStatusCode()) {
handleFetchStorageContainerInfoFailure(new StorageContainerException(response.getStatusCode(), "fail to fetch location for storage container (" + scId + ")"));
return;
}
StorageContainerEndpoint endpoint = response.getEndpoint();
if (null != scInfo && scInfo.getRevision() >= endpoint.getRevision()) {
handleFetchStorageContainerInfoFailure(new StorageContainerException(StatusCode.STALE_GROUP_INFO, "Fetched a stale storage container info : current = " + scInfo.getRevision() + ", fetched = " + endpoint.getRevision() + ""));
return;
}
// we got the updated location
List<Endpoint> readEndpoints = Lists.newArrayListWithExpectedSize(1 + endpoint.getRoEndpointCount());
readEndpoints.add(endpoint.getRwEndpoint());
readEndpoints.addAll(endpoint.getRoEndpointList());
scInfo = StorageContainerInfo.of(scId, endpoint.getRevision(), endpoint.getRwEndpoint(), readEndpoints);
// get the channel from channel manager (if it doesn't exist create one)
StorageServerChannel serverChannel = channelManager.getOrCreateChannel(endpoint.getRwEndpoint());
if (null == serverChannel) {
log.info("No channel found/created for range server {}. The channel manager must be shutting down." + " Stop the process of fetching storage container ({}).", endpoint.getRwEndpoint(), scId);
synchronized (this) {
rsChannelFuture.completeExceptionally(new ObjectClosedException("StorageServerChannelManager is closed"));
}
return;
}
// update the future
synchronized (this) {
rsChannelFuture.complete(serverChannel);
}
}
Aggregations