Search in sources :

Example 11 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class MoveReplicaCmd method moveHdfsReplica.

private void moveHdfsReplica(ClusterState clusterState, NamedList results, String dataDir, String targetNode, String async, DocCollection coll, Replica replica, Slice slice) throws Exception {
    String newCoreName = Assign.buildCoreName(coll, slice.getName(), replica.getType());
    ZkNodeProps removeReplicasProps = new ZkNodeProps(COLLECTION_PROP, coll.getName(), SHARD_ID_PROP, slice.getName(), REPLICA_PROP, replica.getName());
    removeReplicasProps.getProperties().put(CoreAdminParams.DELETE_DATA_DIR, false);
    removeReplicasProps.getProperties().put(CoreAdminParams.DELETE_INDEX, false);
    if (async != null)
        removeReplicasProps.getProperties().put(ASYNC, async);
    NamedList deleteResult = new NamedList();
    ocmh.deleteReplica(clusterState, removeReplicasProps, deleteResult, null);
    if (deleteResult.get("failure") != null) {
        String errorString = String.format(Locale.ROOT, "Failed to cleanup replica collection=%s shard=%s name=%s", coll.getName(), slice.getName(), replica.getName());
        log.warn(errorString);
        results.add("failure", errorString + ", because of : " + deleteResult.get("failure"));
        return;
    }
    ZkNodeProps addReplicasProps = new ZkNodeProps(COLLECTION_PROP, coll.getName(), SHARD_ID_PROP, slice.getName(), CoreAdminParams.NODE, targetNode, CoreAdminParams.NAME, newCoreName, CoreAdminParams.DATA_DIR, dataDir);
    if (async != null)
        addReplicasProps.getProperties().put(ASYNC, async);
    NamedList addResult = new NamedList();
    ocmh.addReplica(clusterState, addReplicasProps, addResult, null);
    if (addResult.get("failure") != null) {
        String errorString = String.format(Locale.ROOT, "Failed to create replica for collection=%s shard=%s" + " on node=%s", coll.getName(), slice.getName(), targetNode);
        log.warn(errorString);
        results.add("failure", errorString);
        return;
    } else {
        String successString = String.format(Locale.ROOT, "MOVEREPLICA action completed successfully, moved replica=%s at node=%s " + "to replica=%s at node=%s", replica.getCoreName(), replica.getNodeName(), newCoreName, targetNode);
        results.add("success", successString);
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps)

Example 12 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class MoveReplicaCmd method moveNormalReplica.

private void moveNormalReplica(ClusterState clusterState, NamedList results, String targetNode, String async, DocCollection coll, Replica replica, Slice slice) throws Exception {
    String newCoreName = Assign.buildCoreName(coll, slice.getName(), replica.getType());
    ZkNodeProps addReplicasProps = new ZkNodeProps(COLLECTION_PROP, coll.getName(), SHARD_ID_PROP, slice.getName(), CoreAdminParams.NODE, targetNode, CoreAdminParams.NAME, newCoreName);
    if (async != null)
        addReplicasProps.getProperties().put(ASYNC, async);
    NamedList addResult = new NamedList();
    ocmh.addReplica(clusterState, addReplicasProps, addResult, null);
    if (addResult.get("failure") != null) {
        String errorString = String.format(Locale.ROOT, "Failed to create replica for collection=%s shard=%s" + " on node=%s", coll.getName(), slice.getName(), targetNode);
        log.warn(errorString);
        results.add("failure", errorString);
        return;
    }
    ZkNodeProps removeReplicasProps = new ZkNodeProps(COLLECTION_PROP, coll.getName(), SHARD_ID_PROP, slice.getName(), REPLICA_PROP, replica.getName());
    if (async != null)
        removeReplicasProps.getProperties().put(ASYNC, async);
    NamedList deleteResult = new NamedList();
    ocmh.deleteReplica(clusterState, removeReplicasProps, deleteResult, null);
    if (deleteResult.get("failure") != null) {
        String errorString = String.format(Locale.ROOT, "Failed to cleanup replica collection=%s shard=%s name=%s", coll.getName(), slice.getName(), replica.getName());
        log.warn(errorString);
        results.add("failure", errorString + ", because of : " + deleteResult.get("failure"));
    } else {
        String successString = String.format(Locale.ROOT, "MOVEREPLICA action completed successfully, moved replica=%s at node=%s " + "to replica=%s at node=%s", replica.getCoreName(), replica.getNodeName(), newCoreName, targetNode);
        results.add("success", successString);
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps)

Example 13 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method cleanupCollection.

void cleanupCollection(String collectionName, NamedList results) throws Exception {
    log.error("Cleaning up collection [" + collectionName + "].");
    Map<String, Object> props = makeMap(Overseer.QUEUE_OPERATION, DELETE.toLower(), NAME, collectionName);
    commandMap.get(DELETE).call(zkStateReader.getClusterState(), new ZkNodeProps(props), results);
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps)

Example 14 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method processReplicaDeletePropertyCommand.

private void processReplicaDeletePropertyCommand(ClusterState clusterState, ZkNodeProps message, NamedList results) throws KeeperException, InterruptedException {
    checkRequired(message, COLLECTION_PROP, SHARD_ID_PROP, REPLICA_PROP, PROPERTY_PROP);
    SolrZkClient zkClient = zkStateReader.getZkClient();
    DistributedQueue inQueue = Overseer.getStateUpdateQueue(zkClient);
    Map<String, Object> propMap = new HashMap<>();
    propMap.put(Overseer.QUEUE_OPERATION, DELETEREPLICAPROP.toLower());
    propMap.putAll(message.getProperties());
    ZkNodeProps m = new ZkNodeProps(propMap);
    inQueue.offer(Utils.toJSON(m));
}
Also used : HashMap(java.util.HashMap) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 15 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method deleteCoreNode.

void deleteCoreNode(String collectionName, String replicaName, Replica replica, String core) throws KeeperException, InterruptedException {
    ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.DELETECORE.toLower(), ZkStateReader.CORE_NAME_PROP, core, ZkStateReader.NODE_NAME_PROP, replica.getStr(ZkStateReader.NODE_NAME_PROP), ZkStateReader.COLLECTION_PROP, collectionName, ZkStateReader.CORE_NODE_NAME_PROP, replicaName, ZkStateReader.BASE_URL_PROP, replica.getStr(ZkStateReader.BASE_URL_PROP));
    Overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(m));
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps)

Aggregations

ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)91 SolrException (org.apache.solr.common.SolrException)35 HashMap (java.util.HashMap)28 Replica (org.apache.solr.common.cloud.Replica)22 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)20 ArrayList (java.util.ArrayList)19 Slice (org.apache.solr.common.cloud.Slice)19 KeeperException (org.apache.zookeeper.KeeperException)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)16 Test (org.junit.Test)16 DocCollection (org.apache.solr.common.cloud.DocCollection)15 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)14 Map (java.util.Map)13 ClusterState (org.apache.solr.common.cloud.ClusterState)13 IOException (java.io.IOException)10 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)10 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)10 NamedList (org.apache.solr.common.util.NamedList)10 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)9 SolrCore (org.apache.solr.core.SolrCore)8