use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.
the class BookkeeperCommandsTest method createLedgerInBookkeeperTestCluster.
private void createLedgerInBookkeeperTestCluster(int logId) throws Exception {
BookKeeperConfig bookKeeperConfig = BookKeeperConfig.builder().with(BookKeeperConfig.BK_ENSEMBLE_SIZE, 1).with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, 1).with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, 1).with(BookKeeperConfig.ZK_METADATA_PATH, "ledgers").with(BookKeeperConfig.BK_LEDGER_PATH, "/ledgers").with(BookKeeperConfig.ZK_ADDRESS, zkUtil.getZooKeeperConnectString()).build();
@Cleanup CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(zkUtil.getZooKeeperConnectString(), new RetryOneTime(5000));
curatorFramework.start();
@Cleanup("shutdownNow") ScheduledExecutorService executorService = ExecutorServiceHelpers.newScheduledThreadPool(1, "bk-test");
@Cleanup BookKeeperLogFactory bookKeeperLogFactory = new BookKeeperLogFactory(bookKeeperConfig, curatorFramework, executorService);
bookKeeperLogFactory.initialize();
@Cleanup DurableDataLog log = bookKeeperLogFactory.createDurableDataLog(logId);
log.initialize(Duration.ofSeconds(5));
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.
the class StorageCommandsTest method testListChunksCommand.
@Test
public void testListChunksCommand() throws Exception {
int instanceId = 0;
int bookieCount = 3;
int containerCount = 1;
@Cleanup TestUtils.PravegaRunner pravegaRunner = new TestUtils.PravegaRunner(bookieCount, containerCount);
pravegaRunner.startBookKeeperRunner(instanceId++);
this.factory = new BookKeeperLogFactory(pravegaRunner.getBookKeeperRunner().getBkConfig().get(), pravegaRunner.getBookKeeperRunner().getZkClient().get(), executorService());
pravegaRunner.startControllerAndSegmentStore(this.storageFactory, this.factory, true);
String streamName = "testListChunksCommand";
TestUtils.createScopeStream(pravegaRunner.getControllerRunner().getController(), SCOPE, streamName, config);
try (val clientRunner = new TestUtils.ClientRunner(pravegaRunner.getControllerRunner(), SCOPE)) {
// Write events to the streams.
TestUtils.writeEvents(streamName, clientRunner.getClientFactory());
}
ServiceBuilder.ComponentSetup componentSetup = new ServiceBuilder.ComponentSetup(pravegaRunner.getSegmentStoreRunner().getServiceBuilder());
for (int containerId = 0; containerId < containerCount; containerId++) {
componentSetup.getContainerRegistry().getContainer(containerId).flushToStorage(TIMEOUT).join();
}
STATE.set(new AdminCommandState());
Properties pravegaProperties = new Properties();
pravegaProperties.setProperty("pravegaservice.admin.gateway.port", String.valueOf(pravegaRunner.getSegmentStoreRunner().getAdminPort()));
pravegaProperties.setProperty("pravegaservice.container.count", "1");
pravegaProperties.setProperty("pravegaservice.storage.impl.name", "FILESYSTEM");
pravegaProperties.setProperty("pravegaservice.storage.layout", "CHUNKED_STORAGE");
pravegaProperties.setProperty("filesystem.root", this.baseDir.getAbsolutePath());
STATE.get().getConfigBuilder().include(pravegaProperties);
String commandResult = TestUtils.executeCommand("storage list-chunks _system/containers/metadata_0 localhost", STATE.get());
Assert.assertTrue(commandResult.contains("List of chunks for _system/containers/metadata_0"));
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.
the class BookKeeperAdapter method shutDown.
@Override
protected void shutDown() {
for (WriteHandle lh : this.ledgers.values()) {
try {
lh.close();
} catch (Exception ex) {
System.err.println(ex);
}
}
this.ledgers.clear();
BookKeeperLogFactory lf = this.logFactory;
if (lf != null) {
lf.close();
this.logFactory = null;
}
stopBookKeeper();
CuratorFramework zkClient = this.zkClient;
if (zkClient != null) {
zkClient.close();
this.zkClient = null;
}
Runtime.getRuntime().removeShutdownHook(this.stopBookKeeperProcess);
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.
the class BookKeeperCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
protected Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin);
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.
the class ContainerCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
@Override
protected Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val containerConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ContainerConfig::builder);
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
return new Context(serviceConfig, containerConfig, bkConfig, zkClient, factory, bkAdmin);
}
Aggregations