Search in sources :

Example 71 with AdminClient

use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.

the class AdminStoreSwapper method main.

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    parser.accepts("help", "print usage information");
    parser.accepts("cluster", "[REQUIRED] the voldemort cluster.xml file ").withRequiredArg().describedAs("cluster.xml");
    parser.accepts("name", "[REQUIRED] the name of the store to swap").withRequiredArg().describedAs("store-name");
    parser.accepts("file", "[REQUIRED] uri of a directory containing the new store files").withRequiredArg().describedAs("uri");
    parser.accepts("timeout", "http timeout for the fetch in ms").withRequiredArg().describedAs("timeout ms").ofType(Integer.class);
    parser.accepts("rollback", "Rollback store to older version");
    parser.accepts("push-version", "[REQUIRED] Version of push to fetch / rollback-to").withRequiredArg().ofType(Long.class);
    OptionSet options = parser.parse(args);
    if (options.has("help")) {
        parser.printHelpOn(System.out);
        System.exit(0);
    }
    Set<String> missing = CmdUtils.missing(options, "cluster", "name", "file", "push-version");
    if (missing.size() > 0) {
        if (!(missing.equals(ImmutableSet.of("file")) && (options.has("rollback")))) {
            System.err.println("Missing required arguments: " + Joiner.on(", ").join(missing));
            parser.printHelpOn(System.err);
            System.exit(1);
        }
    }
    String clusterXml = (String) options.valueOf("cluster");
    String storeName = (String) options.valueOf("name");
    String filePath = (String) options.valueOf("file");
    int timeoutMs = CmdUtils.valueOf(options, "timeout", (int) (3 * Time.SECONDS_PER_HOUR * Time.MS_PER_SECOND));
    boolean rollbackStore = options.has("rollback");
    Long pushVersion = (Long) options.valueOf("push-version");
    String clusterStr = FileUtils.readFileToString(new File(clusterXml));
    Cluster cluster = new ClusterMapper().readCluster(new StringReader(clusterStr));
    ExecutorService executor = Executors.newFixedThreadPool(cluster.getNumberOfNodes());
    AdminClient adminClient = new AdminClient(cluster);
    AdminStoreSwapper swapper = new AdminStoreSwapper(executor, adminClient, timeoutMs);
    try {
        long start = System.currentTimeMillis();
        if (rollbackStore) {
            swapper.invokeRollback(storeName, pushVersion.longValue());
        } else {
            swapper.fetchAndSwapStoreData(storeName, filePath, pushVersion.longValue());
        }
        long end = System.currentTimeMillis();
        swapper.logger.info("Succeeded on all nodes in " + ((end - start) / Time.MS_PER_SECOND) + " seconds.");
    } finally {
        if (adminClient != null)
            adminClient.close();
        executor.shutdownNow();
        executor.awaitTermination(1, TimeUnit.SECONDS);
    }
    System.exit(0);
}
Also used : Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) OptionParser(joptsimple.OptionParser) StringReader(java.io.StringReader) ExecutorService(java.util.concurrent.ExecutorService) OptionSet(joptsimple.OptionSet) File(java.io.File) AdminClient(voldemort.client.protocol.admin.AdminClient)

Example 72 with AdminClient

use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.

the class ZoneShrinkageClientTest method setup.

@Before
public void setup() throws IOException {
    ClusterTestUtils.reset();
    sourceCluster = ClusterTestUtils.getZZZCluster();
    targetCluster = RebalanceUtils.vacateZone(sourceCluster, DROP_ZONE_ID);
    sourceStoreDefs = ClusterTestUtils.getZZZStoreDefsBDB();
    targetStoreDefs = RebalanceUtils.dropZone(sourceStoreDefs, DROP_ZONE_ID);
    File sourceStoreDefsXml = ServerTestUtils.createTempFile("zzz-stores-", ".xml");
    FileUtils.writeStringToFile(sourceStoreDefsXml, new StoreDefinitionsMapper().writeStoreList(sourceStoreDefs));
    servers = new VoldemortServer[sourceCluster.getNumberOfNodes()];
    ServerTestUtils.startVoldemortCluster(servers, null, null, sourceStoreDefsXml.getAbsolutePath(), new Properties(), sourceCluster);
    Properties adminProperties = new Properties();
    adminProperties.setProperty("max_connections", "2");
    adminClient = new AdminClient(servers[0].getMetadataStore().getCluster(), new AdminClientConfig(adminProperties));
}
Also used : AdminClientConfig(voldemort.client.protocol.admin.AdminClientConfig) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Properties(java.util.Properties) File(java.io.File) AdminClient(voldemort.client.protocol.admin.AdminClient) Before(org.junit.Before)

Example 73 with AdminClient

use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.

the class VoldemortServerTest method testInvalidNodeIdUpdateFails.

@Test
public void testInvalidNodeIdUpdateFails() throws IOException {
    Cluster localCluster = ServerTestUtils.getLocalCluster(1);
    VoldemortConfig config = getVoldemortConfig(new Properties());
    server = new VoldemortServer(config, localCluster);
    server.start();
    final int UPDATED_NODE_ID = 3;
    Node oldNode = localCluster.getNodes().iterator().next();
    // For single local node, host matcher is not used.
    config.setNodeIdImplementation(new NodeIdHostMatcher(UPDATED_NODE_ID));
    oldAdminClient = new AdminClient(localCluster);
    try {
        oldAdminClient.metadataMgmtOps.updateRemoteMetadata(oldNode.getId(), MetadataStore.NODE_ID_KEY, Integer.toString(UPDATED_NODE_ID));
        Assert.fail("Invalid node id should have failed");
    } catch (VoldemortException ex) {
    // Expected, ignore
    }
}
Also used : Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) Properties(java.util.Properties) VoldemortException(voldemort.VoldemortException) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 74 with AdminClient

use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.

the class QuotaLimitingStoreTest method setup.

@Before
public void setup() throws IOException {
    Properties props = new Properties();
    props.put("enable.quota.limiting", "true");
    server = ServerTestUtils.startStandAloneVoldemortServer(props, "test/common/voldemort/config/single-store.xml");
    adminClient = new AdminClient(server.getMetadataStore().getCluster());
    String bootStrapUrl = "tcp://" + server.getIdentityNode().getHost() + ":" + server.getIdentityNode().getSocketPort();
    factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootStrapUrl));
    storeClient = factory.getStoreClient("test");
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) Properties(java.util.Properties) ClientConfig(voldemort.client.ClientConfig) AdminClient(voldemort.client.protocol.admin.AdminClient) Before(org.junit.Before)

Example 75 with AdminClient

use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.

the class VoldemortBuildAndPushJob method allClustersEqual.

/**
 * Check if all cluster objects in the list are congruent.
 *
 * @param clusterUrls of cluster objects
 * @return
 */
private void allClustersEqual(final List<String> clusterUrls) {
    Validate.notEmpty(clusterUrls, "clusterUrls cannot be null");
    // If only one clusterUrl return immediately
    if (clusterUrls.size() == 1)
        return;
    AdminClient adminClientLhs = adminClientPerCluster.get(clusterUrls.get(0));
    Cluster clusterLhs = adminClientLhs.getAdminClientCluster();
    for (int index = 1; index < clusterUrls.size(); index++) {
        AdminClient adminClientRhs = adminClientPerCluster.get(clusterUrls.get(index));
        Cluster clusterRhs = adminClientRhs.getAdminClientCluster();
        if (!areTwoClustersEqual(clusterLhs, clusterRhs))
            throw new VoldemortException("Cluster " + clusterLhs.getName() + " is not the same as " + clusterRhs.getName());
    }
}
Also used : Cluster(voldemort.cluster.Cluster) VoldemortException(voldemort.VoldemortException) AdminClient(voldemort.client.protocol.admin.AdminClient)

Aggregations

AdminClient (voldemort.client.protocol.admin.AdminClient)80 Test (org.junit.Test)35 Cluster (voldemort.cluster.Cluster)26 Node (voldemort.cluster.Node)26 Properties (java.util.Properties)19 StoreDefinition (voldemort.store.StoreDefinition)19 ArrayList (java.util.ArrayList)18 AdminClientConfig (voldemort.client.protocol.admin.AdminClientConfig)18 VoldemortException (voldemort.VoldemortException)17 IOException (java.io.IOException)14 Before (org.junit.Before)14 ByteArray (voldemort.utils.ByteArray)14 HashMap (java.util.HashMap)13 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)13 File (java.io.File)11 VoldemortServer (voldemort.server.VoldemortServer)11 ClientConfig (voldemort.client.ClientConfig)10 VectorClock (voldemort.versioning.VectorClock)10 Versioned (voldemort.versioning.Versioned)9 ClusterMapper (voldemort.xml.ClusterMapper)9