Search in sources :

Example 16 with VoldemortApplicationException

use of voldemort.VoldemortApplicationException in project voldemort by voldemort.

the class ReplaceNodeCLI method verifyPreConditions.

private void verifyPreConditions() {
    // Verify node id exists in the current cluster
    if (cluster.hasNodeWithId(nodeId) == false) {
        throw new VoldemortApplicationException(" Node " + nodeId + " could not be found in the existing cluster. Please check the node id ");
    }
    verifyAdminPort(cluster.getNodes(), url);
    verifyAdminPort(Arrays.asList(newCluster.getNodeById(newNodeId)), newUrl);
    List<StoreDefinition> newStoreDefinitions = this.newAdminClient.metadataMgmtOps.getRemoteStoreDefList().getValue();
    Set<StoreDefinition> existingStores = new HashSet<StoreDefinition>();
    existingStores.addAll(storeDefinitions);
    Set<StoreDefinition> newStores = new HashSet<StoreDefinition>();
    newStores.addAll(newStoreDefinitions);
    if (skipRestore) {
        if (existingStores.equals(newStores) == false) {
            throw new VoldemortApplicationException("Command called with skip data restore, but store definitions do not match... aborting ");
        }
        // number of nodes as the old cluster.
        if (newCluster.getNumberOfNodes() > 1) {
            // something fishy, abort
            if (cluster.getNumberOfNodes() != newCluster.getNumberOfNodes()) {
                throw new VoldemortApplicationException("number of nodes in new " + newCluster.getNumberOfNodes() + " and old cluster " + cluster.getNumberOfNodes() + " not the same. New cluster can have one or equal number of nodes ... aborting");
            }
            for (Node oldNode : cluster.getNodes()) {
                Node newNode = newCluster.getNodeById(oldNode.getId());
                if (oldNode.getId() == nodeId) {
                    // with new host names, report error and abort
                    if (oldNode.isEqualState(newNode)) {
                        // command is restarted.
                        throw new VoldemortApplicationException(" node in the new cluster has the same metadata as the node being replaced. \n" + "fix the new cluster to have the correct host and ports... aborting");
                    }
                } else {
                    if (oldNode.isEqualState(newNode) == false) {
                        throw new VoldemortApplicationException(" node in the old and new cluster should be the same except for the one being replaced. " + "Node id : " + oldNode.getId() + "... aborting");
                    }
                }
                if (oldNode.getPartitionIds().equals(newNode.getPartitionIds()) == false) {
                    throw new VoldemortApplicationException("old node and new node has different partition ids, is this a correct replacement for node Id" + oldNode.getId() + " ... aborting");
                }
            }
        }
    } else {
        // cluster is edited to contain only the single node to be replaced.
        if (newCluster.getNumberOfNodes() != 1) {
            // restarted.
            throw new VoldemortApplicationException("needs data restore and new cluster has more than one nodes... aborting");
        }
        List<StoreDefinition> readOnlyStoreDefs = StoreDefinitionUtils.filterStores(storeDefinitions, true);
        if (readOnlyStoreDefs.size() > 0) {
            throw new VoldemortApplicationException("data restore not supported for clusters with read only stores. Read only store name " + readOnlyStoreDefs.get(0));
        }
        if (existingStores.equals(newStores) == false) {
            if (newStores.size() != 0) {
                throw new VoldemortApplicationException(" Stores xml in the new cluster should either match the old cluster or should be empty ");
            }
        }
    }
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) StoreDefinition(voldemort.store.StoreDefinition) Node(voldemort.cluster.Node) HashSet(java.util.HashSet)

Example 17 with VoldemortApplicationException

use of voldemort.VoldemortApplicationException in project voldemort by voldemort.

the class ReplaceNodeCLI method getStoresXML.

private String getStoresXML() {
    StoreDefinitionsMapper storeMapper = new StoreDefinitionsMapper();
    Map<Integer, String> storeXMLInNodes = getMetadataXML(MetadataStore.STORES_KEY);
    List<StoreDefinition> storeList = null;
    String storeXML = null;
    for (Map.Entry<Integer, String> storeNodeId : storeXMLInNodes.entrySet()) {
        String xml = storeNodeId.getValue();
        List<StoreDefinition> storeDefinitions = storeMapper.readStoreList(new StringReader(xml), false);
        if (storeList == null) {
            storeList = storeDefinitions;
            storeXML = xml;
        } else if (storeList.equals(storeDefinitions) == false) {
            throw new VoldemortApplicationException("Store XMLs are different across nodes, fix that before the node swap...aborting " + storeNodeId.getKey());
        }
    }
    return storeXML;
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with VoldemortApplicationException

use of voldemort.VoldemortApplicationException in project voldemort by voldemort.

the class ReplaceNodeCLI method updateClusterXML.

private String updateClusterXML() {
    Node nodeToAdd = newCluster.getNodeById(newNodeId);
    List<Node> nodes = new ArrayList<Node>(cluster.getNodes());
    List<Zone> zones = new ArrayList<Zone>(cluster.getZones());
    Node nodeToRemove = cluster.getNodeById(nodeId);
    Node newNode = new Node(nodeId, nodeToAdd.getHost(), nodeToAdd.getHttpPort(), nodeToAdd.getSocketPort(), nodeToAdd.getAdminPort(), nodeToRemove.getZoneId(), nodeToRemove.getPartitionIds(), nodeToAdd.getRestPort());
    boolean isInserted = false;
    for (int i = 0; i < nodes.size(); i++) {
        if (nodes.get(i).getId() == nodeId) {
            nodes.remove(i);
            nodes.add(i, newNode);
            isInserted = true;
            break;
        }
    }
    if (isInserted == false) {
        logger.error("Unable to insert the new node, something odd happened");
        throw new VoldemortApplicationException("Unable to insert the new node, something odd happened");
    }
    Cluster updatedCluster = new Cluster(cluster.getName(), nodes, zones);
    return new ClusterMapper().writeCluster(updatedCluster);
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) Zone(voldemort.cluster.Zone) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper)

Example 19 with VoldemortApplicationException

use of voldemort.VoldemortApplicationException in project voldemort by voldemort.

the class ReplaceNodeCLI method main.

public static void main(String[] args) throws Exception {
    OptionParser parser = null;
    OptionSet options = null;
    try {
        parser = getParser();
        options = parser.parse(args);
    } catch (OptionException oe) {
        parser.printHelpOn(System.out);
        printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
        return;
    }
    /* validate options */
    if (options.hasArgument("help")) {
        parser.printHelpOn(System.out);
        printUsage();
        return;
    }
    if (!options.hasArgument("url") || !options.hasArgument("node") || !options.hasArgument("newurl")) {
        parser.printHelpOn(System.out);
        printUsageAndDie("Missing a required argument.");
        return;
    }
    String url = (String) options.valueOf("url");
    String newUrl = (String) options.valueOf("newurl");
    int nodeId = ((Integer) options.valueOf("node")).intValue();
    boolean skipRestore = options.has("skip-restore");
    int parallelism = ((Integer) options.valueOf("parallelism")).intValue();
    if (parallelism <= 0) {
        Utils.croak(" parallelism " + parallelism + " should be a positive integer ");
    }
    ReplaceNodeCLI nodeReplacer = new ReplaceNodeCLI(url, nodeId, newUrl, skipRestore, parallelism);
    try {
        nodeReplacer.execute();
    } catch (VoldemortApplicationException e) {
        logger.error("Error during node replace", e);
        Utils.croak(e.getMessage());
    }
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Aggregations

VoldemortApplicationException (voldemort.VoldemortApplicationException)19 Node (voldemort.cluster.Node)10 UnreachableStoreException (voldemort.store.UnreachableStoreException)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)4 OptionException (joptsimple.OptionException)4 VoldemortException (voldemort.VoldemortException)4 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)4 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Cluster (voldemort.cluster.Cluster)3 StoreDefinition (voldemort.store.StoreDefinition)3 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Callable (java.util.concurrent.Callable)2 Future (java.util.concurrent.Future)2 Semaphore (java.util.concurrent.Semaphore)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2