Search in sources :

Example 16 with ZkNodeProps

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

the class ZkNodePropsTest method testBasic.

@Test
public void testBasic() throws IOException {
    Map<String, Object> props = new HashMap<>();
    props.put("prop1", "value1");
    props.put("prop2", "value2");
    props.put("prop3", "value3");
    props.put("prop4", "value4");
    props.put("prop5", "value5");
    props.put("prop6", "value6");
    ZkNodeProps zkProps = new ZkNodeProps(props);
    byte[] bytes = Utils.toJSON(zkProps);
    ZkNodeProps props2 = ZkNodeProps.load(bytes);
    assertEquals("value1", props2.getStr("prop1"));
    assertEquals("value2", props2.getStr("prop2"));
    assertEquals("value3", props2.getStr("prop3"));
    assertEquals("value4", props2.getStr("prop4"));
    assertEquals("value5", props2.getStr("prop5"));
    assertEquals("value6", props2.getStr("prop6"));
}
Also used : HashMap(java.util.HashMap) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) Test(org.junit.Test)

Example 17 with ZkNodeProps

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

the class AbstractFullDistribZkTestBase method showCounts.

public void showCounts() {
    Set<String> theShards = shardToJetty.keySet();
    for (String shard : theShards) {
        List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
        for (CloudJettyRunner cjetty : solrJetties) {
            ZkNodeProps props = cjetty.info;
            System.err.println("PROPS:" + props);
            try {
                SolrParams query = params("q", "*:*", "rows", "0", "distrib", "false", "tests", // "tests" is just a
                "checkShardConsistency");
                // tag that won't do
                // anything except be
                // echoed in logs
                long num = cjetty.client.solrClient.query(query).getResults().getNumFound();
                System.err.println("DOCS:" + num);
            } catch (SolrServerException | SolrException | IOException e) {
                System.err.println("error contacting client: " + e.getMessage() + "\n");
                continue;
            }
            boolean live = false;
            String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
            ZkStateReader zkStateReader = cloudClient.getZkStateReader();
            if (zkStateReader.getClusterState().liveNodesContain(nodeName)) {
                live = true;
            }
            System.err.println(" live:" + live);
        }
    }
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 18 with ZkNodeProps

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

the class AbstractZkTestCase method buildZooKeeper.

// static to share with distrib test
public static void buildZooKeeper(String zkHost, String zkAddress, File solrhome, String config, String schema) throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null);
    zkClient.makePath("/solr", false, true);
    zkClient.close();
    zkClient = new SolrZkClient(zkAddress, AbstractZkTestCase.TIMEOUT);
    Map<String, Object> props = new HashMap<>();
    props.put("configName", "conf1");
    final ZkNodeProps zkProps = new ZkNodeProps(props);
    zkClient.makePath("/collections/collection1", Utils.toJSON(zkProps), CreateMode.PERSISTENT, true);
    zkClient.makePath("/collections/collection1/shards", CreateMode.PERSISTENT, true);
    zkClient.makePath("/collections/control_collection", Utils.toJSON(zkProps), CreateMode.PERSISTENT, true);
    zkClient.makePath("/collections/control_collection/shards", CreateMode.PERSISTENT, true);
    // for now, always upload the config and schema to the canonical names
    putConfig("conf1", zkClient, solrhome, config, "solrconfig.xml");
    putConfig("conf1", zkClient, solrhome, schema, "schema.xml");
    putConfig("conf1", zkClient, solrhome, "solrconfig.snippet.randomindexconfig.xml");
    putConfig("conf1", zkClient, solrhome, "stopwords.txt");
    putConfig("conf1", zkClient, solrhome, "protwords.txt");
    putConfig("conf1", zkClient, solrhome, "currency.xml");
    putConfig("conf1", zkClient, solrhome, "enumsConfig.xml");
    putConfig("conf1", zkClient, solrhome, "open-exchange-rates.json");
    putConfig("conf1", zkClient, solrhome, "mapping-ISOLatin1Accent.txt");
    putConfig("conf1", zkClient, solrhome, "old_synonyms.txt");
    putConfig("conf1", zkClient, solrhome, "synonyms.txt");
    zkClient.close();
}
Also used : HashMap(java.util.HashMap) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 19 with ZkNodeProps

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

the class CollectionsHandler method invokeAction.

void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer cores, CollectionAction action, CollectionOperation operation) throws Exception {
    if (!coreContainer.isZooKeeperAware()) {
        throw new SolrException(BAD_REQUEST, "Invalid request. collections can be accessed only in SolrCloud mode");
    }
    SolrResponse response = null;
    Map<String, Object> props = operation.execute(req, rsp, this);
    String asyncId = req.getParams().get(ASYNC);
    if (props != null) {
        if (asyncId != null) {
            props.put(ASYNC, asyncId);
        }
        props.put(QUEUE_OPERATION, operation.action.toLower());
        ZkNodeProps zkProps = new ZkNodeProps(props);
        if (operation.sendToOCPQueue) {
            response = handleResponse(operation.action.toLower(), zkProps, rsp, operation.timeOut);
        } else
            Overseer.getStateUpdateQueue(coreContainer.getZkController().getZkClient()).offer(Utils.toJSON(props));
        final String collectionName = zkProps.getStr(NAME);
        if (action.equals(CollectionAction.CREATE) && asyncId == null) {
            if (rsp.getException() == null) {
                waitForActiveCollection(collectionName, zkProps, cores, response);
            }
        }
    }
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrResponse(org.apache.solr.client.solrj.SolrResponse) OverseerSolrResponse(org.apache.solr.cloud.OverseerSolrResponse) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) SolrException(org.apache.solr.common.SolrException)

Example 20 with ZkNodeProps

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

the class AssignTest method testAssignNode.

@Test
public void testAssignNode() throws Exception {
    String cname = "collection1";
    Map<String, DocCollection> collectionStates = new HashMap<>();
    Map<String, Slice> slices = new HashMap<>();
    Map<String, Replica> replicas = new HashMap<>();
    ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, "state", ZkStateReader.STATE_PROP, Replica.State.ACTIVE.toString(), ZkStateReader.BASE_URL_PROP, "0.0.0.0", ZkStateReader.CORE_NAME_PROP, "core1", ZkStateReader.ROLES_PROP, null, ZkStateReader.NODE_NAME_PROP, "0_0_0_0", ZkStateReader.SHARD_ID_PROP, "shard1", ZkStateReader.COLLECTION_PROP, cname, ZkStateReader.NUM_SHARDS_PROP, "1", ZkStateReader.CORE_NODE_NAME_PROP, "core_node1");
    Replica replica = new Replica("core_node1", m.getProperties());
    replicas.put("core_node1", replica);
    Slice slice = new Slice("slice1", replicas, new HashMap<String, Object>(0));
    slices.put("slice1", slice);
    DocRouter router = new ImplicitDocRouter();
    DocCollection docCollection = new DocCollection(cname, slices, new HashMap<String, Object>(0), router);
    collectionStates.put(cname, docCollection);
    Set<String> liveNodes = new HashSet<>();
    ClusterState state = new ClusterState(-1, liveNodes, collectionStates);
    String nodeName = Assign.assignNode(state.getCollection("collection1"));
    assertEquals("core_node2", nodeName);
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) HashMap(java.util.HashMap) ImplicitDocRouter(org.apache.solr.common.cloud.ImplicitDocRouter) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) Replica(org.apache.solr.common.cloud.Replica) Slice(org.apache.solr.common.cloud.Slice) ImplicitDocRouter(org.apache.solr.common.cloud.ImplicitDocRouter) DocRouter(org.apache.solr.common.cloud.DocRouter) DocCollection(org.apache.solr.common.cloud.DocCollection) HashSet(java.util.HashSet) Test(org.junit.Test)

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