@Override public LayoutClient getClient(long epoch) { return new LayoutClient(router, epoch); }
private Map<String, CompletableFuture<Layout>> getLayoutFutures(List<String> layoutServers) { Map<String, CompletableFuture<Layout>> layoutFuturesMap = new HashMap<>(); // Get layout futures for layout requests from all layout servers. for (String server : layoutServers) { try { // Router creation can throw a NetworkException. IClientRouter router = runtime.getRouter(server); layoutFuturesMap.put(server, new LayoutClient(router, Layout.INVALID_EPOCH).getLayout()); } catch (NetworkException e) { log.error("getClusterStatus: Exception encountered connecting to {}. ", server, e); CompletableFuture<Layout> cf = new CompletableFuture<>(); cf.completeExceptionally(e); layoutFuturesMap.put(server, cf); } } return layoutFuturesMap; }
@Override Set<IClient> getClientsForTest() { LayoutHandler layoutHandler = new LayoutHandler(); client = new LayoutClient(router, 0L); return new ImmutableSet.Builder<IClient>() .add(new BaseHandler()) .add(layoutHandler) .build(); }
/** * Bootstraps a layout server connected to the specified router. * * @param router Router connected to the node. * @param layout Layout to bootstrap with */ private static void bootstrapLayoutServer(IClientRouter router, Layout layout) throws ExecutionException, InterruptedException, AlreadyBootstrappedException { LayoutClient layoutClient = new LayoutClient(router, layout.getEpoch()); try { CFUtils.getUninterruptibly(layoutClient.bootstrapLayout(layout), AlreadyBootstrappedException.class); } catch (AlreadyBootstrappedException abe) { if (!layoutClient.getLayout().get().equals(layout)) { log.error("BootstrapUtil: Layout Server {}:{} already bootstrapped with different " + "layout.", router.getHost(), router.getPort()); throw abe; } } }
new LayoutClient(router, Layout.INVALID_EPOCH).getLayout();
/** * Setup a cluster of 1 node. Bootstrap the node with a wrong layout. * Bootstrap the cluster using the BootstrapUtil. It should assert that the node already * bootstrapped is with the wrong layout and then fail with the AlreadyBootstrappedException. */ @Test public void test1NodeBootstrapWithWrongBootstrappedLayoutServer() throws Exception { // Set up cluster of 1 node. final int PORT_0 = 9000; Process corfuServer_1 = runPersistentServer(corfuSingleNodeHost, PORT_0, false); final Layout layout = getLayout(1); final int retries = 3; IClientRouter router = new NettyClientRouter(NodeLocator .parseString(corfuSingleNodeHost + ":" + PORT_0), CorfuRuntime.CorfuRuntimeParameters.builder().build()); router.addClient(new LayoutHandler()).addClient(new BaseHandler()); Layout wrongLayout = new Layout(layout); wrongLayout.getLayoutServers().add("localhost:9005"); retryBootstrapOperation(() -> CFUtils.getUninterruptibly( new LayoutClient(router, layout.getEpoch()).bootstrapLayout(wrongLayout))); assertThatThrownBy(() -> BootstrapUtil.bootstrap(layout, retries, PARAMETERS.TIMEOUT_SHORT)) .hasCauseInstanceOf(AlreadyBootstrappedException.class); shutdownCorfuServer(corfuServer_1); }
/** * Setup a cluster of 1 node. Bootstrap the nodes. * Bootstrap the cluster using the BootstrapUtil. It should assert that the node already * bootstrapped is with the same layout and then bootstrap the cluster. */ @Test public void test1NodeBootstrapWithBootstrappedNode() throws Exception { // Set up cluster of 1 nodes. final int PORT_0 = 9000; Process corfuServer_1 = runPersistentServer(corfuSingleNodeHost, PORT_0, false); final Layout layout = getLayout(1); final int retries = 5; IClientRouter router = new NettyClientRouter(NodeLocator .parseString(corfuSingleNodeHost + ":" + PORT_0), CorfuRuntime.CorfuRuntimeParameters.builder().build()); router.addClient(new LayoutHandler()).addClient(new BaseHandler()); retryBootstrapOperation(() -> CFUtils.getUninterruptibly( new LayoutClient(router, layout.getEpoch()).bootstrapLayout(layout))); retryBootstrapOperation(() -> CFUtils.getUninterruptibly( new ManagementClient(router, layout.getEpoch()).bootstrapManagement(layout))); BootstrapUtil.bootstrap(layout, retries, PARAMETERS.TIMEOUT_SHORT); CorfuRuntime corfuRuntime = createDefaultRuntime(); assertThat(corfuRuntime.getLayoutView().getLayout().equals(layout)).isTrue(); shutdownCorfuServer(corfuServer_1); }