use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.
the class GrpcClientTestBase method setUp.
@Before
public void setUp() throws Exception {
fakeServer = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start();
scheduler = OrderedScheduler.newSchedulerBuilder().name("scheduler-" + getClass()).numThreads(Runtime.getRuntime().availableProcessors()).build();
settings = StorageClientSettings.newBuilder().managedChannelBuilder(InProcessChannelBuilder.forName(serverName).directExecutor()).usePlaintext(true).build();
serverManager = new StorageServerClientManagerImpl(settings, resources.scheduler(), endpoint -> new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty()));
StorageContainerServiceImplBase scService = new StorageContainerServiceImplBase() {
@Override
public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
GetStorageContainerEndpointResponse.Builder respBuilder = GetStorageContainerEndpointResponse.newBuilder();
respBuilder.setStatusCode(StatusCode.SUCCESS);
for (OneStorageContainerEndpointRequest oneReq : request.getRequestsList()) {
OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(oneReq.getStorageContainer()).setRevision(oneReq.getRevision() + 1).setRwEndpoint(ENDPOINT)).build();
respBuilder.addResponses(oneResp);
}
responseObserver.onNext(respBuilder.build());
responseObserver.onCompleted();
}
};
serviceRegistry.addService(scService.bindService());
doSetup();
}
use of org.apache.bookkeeper.stream.proto.common.Endpoint 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);
}
}
use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.
the class StreamStorageCli method run.
boolean run(String[] args) {
setupShell();
if (args.length == 0) {
commander.usage();
return false;
}
int cmdPos;
for (cmdPos = 0; cmdPos < args.length; cmdPos++) {
if (commandMap.containsKey(args[cmdPos])) {
break;
}
}
try {
commander.parse(Arrays.copyOfRange(args, 0, Math.min(cmdPos, args.length)));
} catch (Exception e) {
System.err.println(e.getMessage());
System.err.println();
commander.usage();
return false;
}
if (shellArgs.help) {
commander.usage();
return false;
}
if (null == shellArgs.endpoint) {
System.err.println("No endpoint is provided");
commander.usage();
return false;
}
Endpoint endpoint = NetUtils.parseEndpoint(shellArgs.endpoint);
settingsBuilder.addEndpoints(endpoint);
log.info("connecting to storage service = {}", endpoint);
if (cmdPos == args.length) {
commander.usage();
return false;
} else {
String cmd = args[cmdPos];
JCommander subCmd = commander.getCommands().get(cmd);
CmdBase subCmdObj = (CmdBase) subCmd.getObjects().get(0);
String[] subCmdArgs = Arrays.copyOfRange(args, cmdPos + 1, args.length);
return subCmdObj.run(shellArgs.namespace, subCmdArgs);
}
}
use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.
the class StorageAdminClientTest method doSetup.
@Override
protected void doSetup() throws Exception {
scheduler = OrderedScheduler.newSchedulerBuilder().name("admin-client-test").numThreads(1).build();
StorageClientSettings settings = StorageClientSettings.newBuilder().addEndpoints(cluster.getRpcEndpoints().toArray(new Endpoint[cluster.getRpcEndpoints().size()])).usePlaintext(true).build();
adminClient = StorageClientBuilder.newBuilder().withSettings(settings).buildAdmin();
defaultBackendUri = URI.create("distributedlog://" + cluster.getZkServers() + "/stream/storage");
}
use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.
the class TestHelixStorageContainerManager method testAddNode.
@Test
public void testAddNode() {
String clusterName = runtime.getMethodName();
controller.createCluster(clusterName, 1024, 3);
List<String> instances = controller.getAdmin().getInstancesInCluster(clusterName);
assertEquals(0, instances.size());
Endpoint endpoint = createEndpoint("127.0.0.1", 4181);
controller.addNode(clusterName, endpoint, Optional.empty());
instances = controller.getAdmin().getInstancesInCluster(clusterName);
assertEquals(1, instances.size());
assertTrue(instances.contains(HelixStorageController.getEndpointName(endpoint)));
// add the instance again
controller.addNode(clusterName, endpoint, Optional.empty());
instances = controller.getAdmin().getInstancesInCluster(clusterName);
assertEquals(1, instances.size());
assertTrue(instances.contains(HelixStorageController.getEndpointName(endpoint)));
// add a different instance
Endpoint endpoint2 = createEndpoint("127.0.0.1", 4481);
controller.addNode(clusterName, endpoint2, Optional.empty());
instances = controller.getAdmin().getInstancesInCluster(clusterName);
assertEquals(2, instances.size());
assertTrue(instances.contains(HelixStorageController.getEndpointName(endpoint)));
assertTrue(instances.contains(HelixStorageController.getEndpointName(endpoint2)));
}
Aggregations