Search in sources :

Example 11 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class BookkeeperCommandsTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    baseConf.setLedgerManagerFactoryClassName("org.apache.bookkeeper.meta.FlatLedgerManagerFactory");
    baseClientConf.setLedgerManagerFactoryClassName("org.apache.bookkeeper.meta.FlatLedgerManagerFactory");
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    boolean successfulSetup = false;
    while (interfaces.hasMoreElements()) {
        try {
            super.setUp();
            successfulSetup = true;
            break;
        } catch (Exception e) {
            // On some environments, using default interface does not allow to resolve the host name. We keep
            // iterating over existing interfaces to start the Bookkeeper cluster.
            super.tearDown();
            baseConf.setListeningInterface(interfaces.nextElement().getName());
        }
    }
    assert successfulSetup;
    STATE.set(new AdminCommandState());
    Properties bkProperties = new Properties();
    bkProperties.setProperty("pravegaservice.container.count", "4");
    bkProperties.setProperty("pravegaservice.zk.connect.uri", zkUtil.getZooKeeperConnectString());
    bkProperties.setProperty("bookkeeper.ledger.path", "/ledgers");
    bkProperties.setProperty("bookkeeper.zk.metadata.path", "ledgers");
    bkProperties.setProperty("bookkeeper.ensemble.size", "1");
    bkProperties.setProperty("bookkeeper.ack.quorum.size", "1");
    bkProperties.setProperty("bookkeeper.write.quorum.size", "1");
    bkProperties.setProperty("pravegaservice.clusterName", "");
    STATE.get().getConfigBuilder().include(bkProperties);
    System.setOut(new PrintStream(outContent));
}
Also used : PrintStream(java.io.PrintStream) NetworkInterface(java.net.NetworkInterface) Properties(java.util.Properties) AdminCommandState(io.pravega.cli.admin.AdminCommandState) DataLogNotAvailableException(io.pravega.segmentstore.storage.DataLogNotAvailableException) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) DataCorruptionException(io.pravega.segmentstore.server.DataCorruptionException) Before(org.junit.Before)

Example 12 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class ConfigUtilsTest method testConfigUtilsWithInValidFile.

@Test
public void testConfigUtilsWithInValidFile() throws IOException {
    @Cleanup AdminCommandState commandState = new AdminCommandState();
    System.setProperty("pravega.configurationFile", "dummy");
    System.setProperty("pravegaservice", "pravegaservice");
    ConfigUtils.loadProperties(commandState);
}
Also used : Cleanup(lombok.Cleanup) AdminCommandState(io.pravega.cli.admin.AdminCommandState) Test(org.junit.Test)

Example 13 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class AbstractSegmentStoreCommandsTest method setup.

public void setup(boolean enableAuth, boolean enableTls) throws Exception {
    ClientConfig.ClientConfigBuilder clientConfigBuilder = ClientConfig.builder().controllerURI(SETUP_UTILS.getControllerUri());
    STATE.set(new AdminCommandState());
    SETUP_UTILS.startAllServices(enableAuth, enableTls);
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("cli.controller.rest.uri", SETUP_UTILS.getControllerRestUri().toString());
    pravegaProperties.setProperty("cli.controller.grpc.uri", SETUP_UTILS.getControllerUri().toString());
    pravegaProperties.setProperty("pravegaservice.zk.connect.uri", SETUP_UTILS.getZkTestServer().getConnectString());
    pravegaProperties.setProperty("pravegaservice.container.count", String.valueOf(CONTAINER_COUNT));
    pravegaProperties.setProperty("pravegaservice.admin.gateway.port", String.valueOf(SETUP_UTILS.getAdminPort()));
    if (enableAuth) {
        clientConfigBuilder = clientConfigBuilder.credentials(new DefaultCredentials(SecurityConfigDefaults.AUTH_ADMIN_PASSWORD, SecurityConfigDefaults.AUTH_ADMIN_USERNAME));
        pravegaProperties.setProperty("cli.channel.auth", Boolean.toString(true));
        pravegaProperties.setProperty("cli.credentials.username", SecurityConfigDefaults.AUTH_ADMIN_USERNAME);
        pravegaProperties.setProperty("cli.credentials.pwd", SecurityConfigDefaults.AUTH_ADMIN_PASSWORD);
    }
    if (enableTls) {
        clientConfigBuilder = clientConfigBuilder.trustStore(pathToConfig() + SecurityConfigDefaults.TLS_CA_CERT_FILE_NAME).validateHostName(false);
        pravegaProperties.setProperty("cli.channel.tls", Boolean.toString(true));
        pravegaProperties.setProperty("cli.trustStore.location", "../../config/" + SecurityConfigDefaults.TLS_CA_CERT_FILE_NAME);
        pravegaProperties.setProperty("cli.trustStore.access.token.ttl.seconds", Integer.toString(300));
    }
    STATE.get().getConfigBuilder().include(pravegaProperties);
    clientConfig = clientConfigBuilder.build();
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ClientConfig(io.pravega.client.ClientConfig) Properties(java.util.Properties) AdminCommandState(io.pravega.cli.admin.AdminCommandState)

Example 14 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class DataRecoveryTest method testLogEditOperationObject.

@Test
public void testLogEditOperationObject() throws IOException {
    // Setup command object.
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.clusterName", "pravega0");
    STATE.get().getConfigBuilder().include(pravegaProperties);
    // Delete Edit Operations should not take into account the newOperation field doing equality.
    Assert.assertEquals(new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.DELETE_OPERATION, 1, 2, null), new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.DELETE_OPERATION, 1, 2, new DeleteSegmentOperation(1)));
    Assert.assertEquals(new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.DELETE_OPERATION, 1, 2, null).hashCode(), new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.DELETE_OPERATION, 1, 2, new DeleteSegmentOperation(1)).hashCode());
    // Other cases for equality of operations.
    Assert.assertEquals(new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, null), new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, null));
    Assert.assertEquals(new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(1)), new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(1)));
    // Equality of payload operations are checked by type and sequence number, which are the common attributes of Operation class.
    DurableDataLogRepairCommand.LogEditOperation deleteOp = new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(2));
    Assert.assertEquals(deleteOp, new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(1)));
    deleteOp.getNewOperation().resetSequenceNumber(123);
    Assert.assertNotEquals(deleteOp, new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(1)));
    // Test the cases for the same object reference and for null comparison.
    DurableDataLogRepairCommand.LogEditOperation sameOp = new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(1));
    Assert.assertEquals(sameOp, sameOp);
    Assert.assertNotEquals(sameOp, null);
    Assert.assertNotEquals(new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, null), new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(1)));
    Assert.assertNotEquals(new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.REPLACE_OPERATION, 1, 2, null), new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(1)));
    Assert.assertNotEquals(new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, null), new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 2, 2, new DeleteSegmentOperation(1)));
    Assert.assertNotEquals(new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 2, new DeleteSegmentOperation(1)), new DurableDataLogRepairCommand.LogEditOperation(DurableDataLogRepairCommand.LogEditType.ADD_OPERATION, 1, 1, new DeleteSegmentOperation(1)));
}
Also used : DeleteSegmentOperation(io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) Properties(java.util.Properties) AdminCommandState(io.pravega.cli.admin.AdminCommandState) Test(org.junit.Test)

Example 15 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class DataRecoveryTest method testDataRecoveryCommand.

/**
 * Tests DurableLog recovery command.
 * @throws Exception    In case of any exception thrown while execution.
 */
@Test
public void testDataRecoveryCommand() throws Exception {
    int instanceId = 0;
    int bookieCount = 3;
    int containerCount = 1;
    @Cleanup TestUtils.PravegaRunner pravegaRunner = new TestUtils.PravegaRunner(bookieCount, containerCount);
    pravegaRunner.startBookKeeperRunner(instanceId++);
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, null);
    String streamName = "testDataRecoveryCommand";
    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());
    }
    // Shut down the controller
    pravegaRunner.shutDownControllerRunner();
    // Flush all Tier 1 to LTS
    ServiceBuilder.ComponentSetup componentSetup = new ServiceBuilder.ComponentSetup(pravegaRunner.getSegmentStoreRunner().getServiceBuilder());
    for (int containerId = 0; containerId < containerCount; containerId++) {
        componentSetup.getContainerRegistry().getContainer(containerId).flushToStorage(TIMEOUT).join();
    }
    // Shutdown SegmentStore
    pravegaRunner.shutDownSegmentStoreRunner();
    // Shutdown BookKeeper & ZooKeeper
    pravegaRunner.shutDownBookKeeperRunner();
    // start a new BookKeeper and ZooKeeper.
    pravegaRunner.startBookKeeperRunner(instanceId++);
    // set pravega properties for the test
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.storage.impl.name", "FILESYSTEM");
    pravegaProperties.setProperty("pravegaservice.storage.layout", "ROLLING_STORAGE");
    pravegaProperties.setProperty("filesystem.root", this.baseDir.getAbsolutePath());
    pravegaProperties.setProperty("pravegaservice.zk.connect.uri", "localhost:" + pravegaRunner.getBookKeeperRunner().getBkPort());
    pravegaProperties.setProperty("bookkeeper.ledger.path", pravegaRunner.getBookKeeperRunner().getLedgerPath());
    pravegaProperties.setProperty("bookkeeper.zk.metadata.path", pravegaRunner.getBookKeeperRunner().getLogMetaNamespace());
    pravegaProperties.setProperty("pravegaservice.clusterName", pravegaRunner.getBookKeeperRunner().getBaseNamespace());
    STATE.get().getConfigBuilder().include(pravegaProperties);
    // Command under test
    TestUtils.executeCommand("data-recovery durableLog-recovery", STATE.get());
    // Start a new segment store and controller
    this.factory = new BookKeeperLogFactory(pravegaRunner.getBookKeeperRunner().getBkConfig().get(), pravegaRunner.getBookKeeperRunner().getZkClient().get(), executorService());
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, this.factory);
    log.info("Started a controller and segment store.");
    // Create the client with new controller.
    try (val clientRunner = new TestUtils.ClientRunner(pravegaRunner.getControllerRunner(), SCOPE)) {
        // Try reading all events to verify that the recovery was successful.
        TestUtils.readAllEvents(SCOPE, streamName, clientRunner.getClientFactory(), clientRunner.getReaderGroupManager(), "RG", "R");
        log.info("Read all events again to verify that segments were recovered.");
    }
    Assert.assertNotNull(StorageListSegmentsCommand.descriptor());
}
Also used : lombok.val(lombok.val) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) Properties(java.util.Properties) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) TestUtils(io.pravega.cli.admin.utils.TestUtils) AdminCommandState(io.pravega.cli.admin.AdminCommandState) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) Test(org.junit.Test)

Aggregations

AdminCommandState (io.pravega.cli.admin.AdminCommandState)27 Properties (java.util.Properties)23 Test (org.junit.Test)22 Cleanup (lombok.Cleanup)14 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)13 CommandArgs (io.pravega.cli.admin.CommandArgs)11 lombok.val (lombok.val)9 TestUtils (io.pravega.cli.admin.utils.TestUtils)6 BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)5 DeleteSegmentOperation (io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation)4 ClientConfig (io.pravega.client.ClientConfig)3 AttributeUpdateCollection (io.pravega.segmentstore.contracts.AttributeUpdateCollection)3 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)3 DefaultCredentials (io.pravega.shared.security.auth.DefaultCredentials)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 CompositeByteArraySegment (io.pravega.common.util.CompositeByteArraySegment)2 ImmutableDate (io.pravega.common.util.ImmutableDate)2 AttributeId (io.pravega.segmentstore.contracts.AttributeId)2