org.apache.solr.core.CoreDescriptor Java Examples
The following examples show how to use
org.apache.solr.core.CoreDescriptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudDescriptor.java From lucene-solr with Apache License 2.0 | 6 votes |
public CloudDescriptor(CoreDescriptor cd, String coreName, Properties props) { this.cd = cd; this.shardId = props.getProperty(CoreDescriptor.CORE_SHARD, null); if (Strings.isNullOrEmpty(shardId)) this.shardId = null; // If no collection name is specified, we default to the core name this.collectionName = props.getProperty(CoreDescriptor.CORE_COLLECTION, coreName); this.roles = props.getProperty(CoreDescriptor.CORE_ROLES, null); this.nodeName = props.getProperty(CoreDescriptor.CORE_NODE_NAME); if (Strings.isNullOrEmpty(nodeName)) this.nodeName = null; this.numShards = PropertiesUtil.toInteger(props.getProperty(CloudDescriptor.NUM_SHARDS), null); String replicaTypeStr = props.getProperty(CloudDescriptor.REPLICA_TYPE); if (Strings.isNullOrEmpty(replicaTypeStr)) { this.replicaType = Replica.Type.NRT; } else { this.replicaType = Replica.Type.valueOf(replicaTypeStr); } for (String propName : props.stringPropertyNames()) { if (propName.startsWith(ZkController.COLLECTION_PARAM_PREFIX)) { collectionParams.put(propName.substring(ZkController.COLLECTION_PARAM_PREFIX.length()), props.getProperty(propName)); } } }
Example #2
Source File: BaseCdcrDistributedZkTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public CloudJettyRunner(JettySolrRunner jetty, Replica replica, String collection, String shard, String coreNodeName) { this.jetty = jetty; this.info = replica; this.collection = collection; Properties nodeProperties = jetty.getNodeProperties(); // we need to update the jetty's shard so that it registers itself to the right shard when restarted this.shard = shard; nodeProperties.setProperty(CoreDescriptor.CORE_SHARD, this.shard); // we need to update the jetty's shard so that it registers itself under the right core name when restarted this.coreNodeName = coreNodeName; nodeProperties.setProperty(CoreDescriptor.CORE_NODE_NAME, this.coreNodeName); this.nodeName = replica.getNodeName(); ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(info); this.url = coreNodeProps.getCoreUrl(); // strip the trailing slash as this can cause issues when executing requests this.client = createNewSolrServer(this.url.substring(0, this.url.length() - 1)); }
Example #3
Source File: TestSegmentSorting.java From lucene-solr with Apache License 2.0 | 6 votes |
@Before public void createCollection() throws Exception { final String collectionName = testName.getMethodName(); final CloudSolrClient cloudSolrClient = cluster.getSolrClient(); final Map<String, String> collectionProperties = new HashMap<>(); collectionProperties.put(CoreDescriptor.CORE_CONFIG, "solrconfig-sortingmergepolicyfactory.xml"); CollectionAdminRequest.Create cmd = CollectionAdminRequest.createCollection(collectionName, configName, NUM_SHARDS, REPLICATION_FACTOR) .setProperties(collectionProperties); if (random().nextBoolean()) { assertTrue( cmd.process(cloudSolrClient).isSuccess() ); } else { // async assertEquals(RequestStatusState.COMPLETED, cmd.processAndWait(cloudSolrClient, 30)); } ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader(); cluster.waitForActiveCollection(collectionName, NUM_SHARDS, NUM_SHARDS * REPLICATION_FACTOR); cloudSolrClient.setDefaultCollection(collectionName); }
Example #4
Source File: SharedFSAutoReplicaFailoverTest.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * After failover, ulogDir should not be changed. */ private void assertUlogDir(String... collections) { for (String collection : collections) { Collection<Slice> slices = cloudClient.getZkStateReader().getClusterState().getCollection(collection).getSlices(); for (Slice slice : slices) { for (Replica replica : slice.getReplicas()) { Map<String, Object> properties = replica.getProperties(); String coreName = replica.getCoreName(); String curUlogDir = (String) properties.get(CoreDescriptor.CORE_ULOGDIR); String prevUlogDir = collectionUlogDirMap.get(coreName); if (curUlogDir != null) { if (prevUlogDir == null) { collectionUlogDirMap.put(coreName, curUlogDir); } else { assertEquals(prevUlogDir, curUlogDir); } } } } } }
Example #5
Source File: SuggestComponentTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private void reloadCore(boolean createNewCore) throws Exception { if (createNewCore) { CoreContainer cores = h.getCoreContainer(); SolrCore core = h.getCore(); String dataDir1 = core.getDataDir(); CoreDescriptor cd = core.getCoreDescriptor(); h.close(); createCore(); SolrCore createdCore = h.getCore(); assertEquals(dataDir1, createdCore.getDataDir()); assertEquals(createdCore, h.getCore()); } else { h.reload(); // On regular reloading, wait until the new searcher is registered waitForWarming(); } assertQ(req("qt", "/select", "q", "*:*"), "//*[@numFound='11']" ); }
Example #6
Source File: MDCLoggingContext.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Sets multiple information from the params. * REMEMBER TO CALL {@link #clear()} in a finally! */ public static void setCoreDescriptor(CoreContainer coreContainer, CoreDescriptor cd) { setNode(coreContainer); int callDepth = CALL_DEPTH.get(); CALL_DEPTH.set(callDepth + 1); if (callDepth > 0) { return; } if (cd != null) { assert cd.getName() != null; setCoreName(cd.getName()); CloudDescriptor ccd = cd.getCloudDescriptor(); if (ccd != null) { setCollection(ccd.getCollectionName()); setShard(ccd.getShardId()); setReplica(ccd.getCoreNodeName()); } } }
Example #7
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * If in SolrCloud mode, upload config sets for each SolrCore in solr.xml. */ public static void bootstrapConf(SolrZkClient zkClient, CoreContainer cc) throws IOException { ZkConfigManager configManager = new ZkConfigManager(zkClient); //List<String> allCoreNames = cfg.getAllCoreNames(); List<CoreDescriptor> cds = cc.getCoresLocator().discover(cc); if (log.isInfoEnabled()) { log.info("bootstrapping config for {} cores into ZooKeeper using solr.xml from {}", cds.size(), cc.getSolrHome()); } for (CoreDescriptor cd : cds) { String coreName = cd.getName(); String confName = cd.getCollectionName(); if (StringUtils.isEmpty(confName)) confName = coreName; Path udir = cd.getInstanceDir().resolve("conf"); log.info("Uploading directory {} with name {} for solrCore {}", udir, confName, coreName); configManager.uploadConfigDir(udir, confName); } }
Example #8
Source File: RoutedAliasUpdateProcessorTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings("WeakerAccess") Set<String> getLeaderCoreNames(ClusterState clusterState) { Set<String> leaders = new TreeSet<>(); // sorted just to make it easier to read when debugging... List<JettySolrRunner> jettySolrRunners = cluster.getJettySolrRunners(); for (JettySolrRunner jettySolrRunner : jettySolrRunners) { List<CoreDescriptor> coreDescriptors = jettySolrRunner.getCoreContainer().getCoreDescriptors(); for (CoreDescriptor core : coreDescriptors) { String nodeName = jettySolrRunner.getNodeName(); String collectionName = core.getCollectionName(); DocCollection collectionOrNull = clusterState.getCollectionOrNull(collectionName); List<Replica> leaderReplicas = collectionOrNull.getLeaderReplicas(nodeName); if (leaderReplicas != null) { for (Replica leaderReplica : leaderReplicas) { leaders.add(leaderReplica.getCoreName()); } } } } return leaders; }
Example #9
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 6 votes |
private void waitForShardId(CoreDescriptor cd) { if (log.isDebugEnabled()) { log.debug("waiting to find shard id in clusterstate for {}", cd.getName()); } int retryCount = 320; while (retryCount-- > 0) { final String shardId = zkStateReader.getClusterState().getShardId(cd.getCollectionName(), getNodeName(), cd.getName()); if (shardId != null) { cd.getCloudDescriptor().setShardId(shardId); return; } try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } throw new SolrException(ErrorCode.SERVER_ERROR, "Could not get shard id for core: " + cd.getName()); }
Example #10
Source File: RoutedAliasUpdateProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
public static UpdateRequestProcessor wrap(SolrQueryRequest req, UpdateRequestProcessor next) { String aliasName = null; // Demeter please don't arrest us... hide your eyes :( // todo: a core should have a more direct way of finding a collection name, and the collection properties SolrCore core = req.getCore(); CoreDescriptor coreDescriptor = core.getCoreDescriptor(); CloudDescriptor cloudDescriptor = coreDescriptor.getCloudDescriptor(); if (cloudDescriptor != null) { String collectionName = cloudDescriptor.getCollectionName(); CoreContainer coreContainer = core.getCoreContainer(); ZkController zkController = coreContainer.getZkController(); ZkStateReader zkStateReader = zkController.getZkStateReader(); Map<String, String> collectionProperties = zkStateReader.getCollectionProperties(collectionName, CACHE_FOR_MILLIS); aliasName = collectionProperties.get(RoutedAlias.ROUTED_ALIAS_NAME_CORE_PROP); } // fall back on core properties (legacy) if (StringUtils.isBlank(aliasName)) { aliasName = coreDescriptor.getCoreProperty(RoutedAlias.ROUTED_ALIAS_NAME_CORE_PROP, null); } final DistribPhase shardDistribPhase = DistribPhase.parseParam(req.getParams().get(DISTRIB_UPDATE_PARAM)); final DistribPhase aliasDistribPhase = DistribPhase.parseParam(req.getParams().get(ALIAS_DISTRIB_UPDATE_PARAM)); if (aliasName == null || aliasDistribPhase != DistribPhase.NONE || shardDistribPhase != DistribPhase.NONE) { // if aliasDistribPhase is not NONE, then there is no further collection routing to be done here. // TODO this may eventually not be true but at the moment it is // if shardDistribPhase is not NONE, then the phase is after the scope of this URP return next; } else { try { RoutedAlias alias = RoutedAlias.fromProps(aliasName, getAliasProps(req, aliasName)); return new RoutedAliasUpdateProcessor(req, next, aliasDistribPhase, alias); } catch (Exception e) { // ensure we throw SERVER_ERROR not BAD_REQUEST at this stage throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Routed alias has invalid properties: " + e, e); } } }
Example #11
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
public boolean checkIfCoreNodeNameAlreadyExists(CoreDescriptor dcore) { DocCollection collection = zkStateReader.getClusterState().getCollectionOrNull(dcore.getCollectionName()); if (collection != null) { Collection<Slice> slices = collection.getSlices(); for (Slice slice : slices) { Collection<Replica> replicas = slice.getReplicas(); Replica r = slice.getReplica(dcore.getCloudDescriptor().getCoreNodeName()); if (r != null) { return true; } } } return false; }
Example #12
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
public void throwErrorIfReplicaReplaced(CoreDescriptor desc) { ClusterState clusterState = getZkStateReader().getClusterState(); if (clusterState != null) { DocCollection collection = clusterState.getCollectionOrNull(desc .getCloudDescriptor().getCollectionName()); if (collection != null) { CloudUtil.checkSharedFSFailoverReplaced(cc, desc); } } }
Example #13
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
private void checkStateInZk(CoreDescriptor cd) throws InterruptedException, NotInClusterStateException { CloudDescriptor cloudDesc = cd.getCloudDescriptor(); String nodeName = cloudDesc.getCoreNodeName(); if (nodeName == null) { throw new SolrException(ErrorCode.SERVER_ERROR, "No coreNodeName for " + cd); } final String coreNodeName = nodeName; if (cloudDesc.getShardId() == null) { throw new SolrException(ErrorCode.SERVER_ERROR, "No shard id for " + cd); } AtomicReference<String> errorMessage = new AtomicReference<>(); AtomicReference<DocCollection> collectionState = new AtomicReference<>(); try { zkStateReader.waitForState(cd.getCollectionName(), 10, TimeUnit.SECONDS, (c) -> { collectionState.set(c); if (c == null) return false; Slice slice = c.getSlice(cloudDesc.getShardId()); if (slice == null) { errorMessage.set("Invalid shard: " + cloudDesc.getShardId()); return false; } Replica replica = slice.getReplica(coreNodeName); if (replica == null) { errorMessage.set("coreNodeName " + coreNodeName + " does not exist in shard " + cloudDesc.getShardId() + ", ignore the exception if the replica was deleted"); return false; } return true; }); } catch (TimeoutException e) { String error = errorMessage.get(); if (error == null) error = "coreNodeName " + coreNodeName + " does not exist in shard " + cloudDesc.getShardId() + ", ignore the exception if the replica was deleted"; throw new NotInClusterStateException(ErrorCode.SERVER_ERROR, error); } }
Example #14
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
public String getCoreNodeName(CoreDescriptor descriptor) { String coreNodeName = descriptor.getCloudDescriptor().getCoreNodeName(); if (coreNodeName == null && !genericCoreNodeNames) { // it's the default return getNodeName() + "_" + descriptor.getName(); } return coreNodeName; }
Example #15
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
private void waitForCoreNodeName(CoreDescriptor descriptor) { int retryCount = 320; log.debug("look for our core node name"); while (retryCount-- > 0) { final DocCollection docCollection = zkStateReader.getClusterState() .getCollectionOrNull(descriptor.getCloudDescriptor().getCollectionName()); if (docCollection != null && docCollection.getSlicesMap() != null) { final Map<String, Slice> slicesMap = docCollection.getSlicesMap(); for (Slice slice : slicesMap.values()) { for (Replica replica : slice.getReplicas()) { // TODO: for really large clusters, we could 'index' on this String nodeName = replica.getStr(ZkStateReader.NODE_NAME_PROP); String core = replica.getStr(ZkStateReader.CORE_NAME_PROP); String msgNodeName = getNodeName(); String msgCore = descriptor.getName(); if (msgNodeName.equals(nodeName) && core.equals(msgCore)) { descriptor.getCloudDescriptor() .setCoreNodeName(replica.getName()); getCoreContainer().getCoresLocator().persist(getCoreContainer(), descriptor); return; } } } } try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
Example #16
Source File: RecoveryStrategy.java From lucene-solr with Apache License 2.0 | 5 votes |
final private void recoveryFailed(final SolrCore core, final ZkController zkController, final String baseUrl, final String shardZkNodeName, final CoreDescriptor cd) throws Exception { SolrException.log(log, "Recovery failed - I give up."); try { zkController.publish(cd, Replica.State.RECOVERY_FAILED); } finally { close(); recoveryListener.failed(); } }
Example #17
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
private void markAllAsNotLeader(final Supplier<List<CoreDescriptor>> registerOnReconnect) { List<CoreDescriptor> descriptors = registerOnReconnect.get(); if (descriptors != null) { for (CoreDescriptor descriptor : descriptors) { descriptor.getCloudDescriptor().setLeader(false); descriptor.getCloudDescriptor().setHasRegistered(false); } } }
Example #18
Source File: ZkShardTerms.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Remove the coreNodeName from terms map and also remove any expired listeners * @return Return true if this object should not be reused */ boolean removeTerm(CoreDescriptor cd) { int numListeners; synchronized (listeners) { // solrcore already closed listeners.removeIf(coreTermWatcher -> !coreTermWatcher.onTermChanged(terms.get())); numListeners = listeners.size(); } return removeTerm(cd.getCloudDescriptor().getCoreNodeName()) || numListeners == 0; }
Example #19
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
public void publishAndWaitForDownStates(int timeoutSeconds) throws KeeperException, InterruptedException { publishNodeAsDown(getNodeName()); Set<String> collectionsWithLocalReplica = ConcurrentHashMap.newKeySet(); for (CoreDescriptor descriptor : cc.getCoreDescriptors()) { collectionsWithLocalReplica.add(descriptor.getCloudDescriptor().getCollectionName()); } CountDownLatch latch = new CountDownLatch(collectionsWithLocalReplica.size()); for (String collectionWithLocalReplica : collectionsWithLocalReplica) { zkStateReader.registerDocCollectionWatcher(collectionWithLocalReplica, (collectionState) -> { if (collectionState == null) return false; boolean foundStates = true; for (CoreDescriptor coreDescriptor : cc.getCoreDescriptors()) { if (coreDescriptor.getCloudDescriptor().getCollectionName().equals(collectionWithLocalReplica)) { Replica replica = collectionState.getReplica(coreDescriptor.getCloudDescriptor().getCoreNodeName()); if (replica == null || replica.getState() != Replica.State.DOWN) { foundStates = false; } } } if (foundStates && collectionsWithLocalReplica.remove(collectionWithLocalReplica)) { latch.countDown(); } return foundStates; }); } boolean allPublishedDown = latch.await(timeoutSeconds, TimeUnit.SECONDS); if (!allPublishedDown) { log.warn("Timed out waiting to see all nodes published as DOWN in our cluster state."); } }
Example #20
Source File: RecoveryStrategy.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked"}) public RecoveryStrategy create(CoreContainer cc, CoreDescriptor cd, RecoveryStrategy.RecoveryListener recoveryListener) { final RecoveryStrategy recoveryStrategy = newRecoveryStrategy(cc, cd, recoveryListener); SolrPluginUtils.invokeSetters(recoveryStrategy, args); return recoveryStrategy; }
Example #21
Source File: RecoveryStrategy.java From lucene-solr with Apache License 2.0 | 5 votes |
protected RecoveryStrategy(CoreContainer cc, CoreDescriptor cd, RecoveryListener recoveryListener) { this.cc = cc; this.coreName = cd.getName(); this.recoveryListener = recoveryListener; zkController = cc.getZkController(); zkStateReader = zkController.getZkStateReader(); baseUrl = zkController.getBaseUrl(); coreZkNodeName = cd.getCloudDescriptor().getCoreNodeName(); replicaType = cd.getCloudDescriptor().getReplicaType(); }
Example #22
Source File: TestHarness.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public List<CoreDescriptor> discover(CoreContainer cc) { return ImmutableList.of(new CoreDescriptor(coreName, cc.getCoreRootDirectory().resolve(coreName), cc, CoreDescriptor.CORE_DATADIR, dataDir, CoreDescriptor.CORE_CONFIG, solrConfig, CoreDescriptor.CORE_SCHEMA, schema, CoreDescriptor.CORE_COLLECTION, System.getProperty("collection", "collection1"), CoreDescriptor.CORE_SHARD, System.getProperty("shard", "shard1"))); }
Example #23
Source File: CloudConfigSetService.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({"rawtypes"}) protected NamedList loadConfigSetFlags(CoreDescriptor cd, SolrResourceLoader loader) { try { return ConfigSetProperties.readFromResourceLoader(loader, "."); } catch (Exception ex) { log.debug("No configSet flags", ex); return null; } }
Example #24
Source File: ZkCollectionTerms.java From lucene-solr with Apache License 2.0 | 5 votes |
public void remove(String shardId, CoreDescriptor coreDescriptor) { synchronized (terms) { if (getShard(shardId).removeTerm(coreDescriptor)) { terms.remove(shardId).close(); } } }
Example #25
Source File: SchemaManager.java From lucene-solr with Apache License 2.0 | 5 votes |
private void waitForOtherReplicasToUpdate(TimeOut timeOut, int latestVersion) { SolrCore core = req.getCore(); CoreDescriptor cd = core.getCoreDescriptor(); String collection = cd.getCollectionName(); if (collection != null) { if (timeOut.hasTimedOut()) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Not enough time left to update replicas. However, the schema is updated already."); } ManagedIndexSchema.waitForSchemaZkVersionAgreement(collection, cd.getCloudDescriptor().getCoreNodeName(), latestVersion, core.getCoreContainer().getZkController(), (int) timeOut.timeLeft(TimeUnit.SECONDS)); } }
Example #26
Source File: RoutedAliasUpdateProcessorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void waitCoreCount(String collection, int count) { long start = System.nanoTime(); int coreFooCount; List<JettySolrRunner> jsrs = cluster.getJettySolrRunners(); do { coreFooCount = 0; // have to check all jetties... there was a very confusing bug where we only checked one and // thus might pick a jetty without a core for the collection and succeed if count = 0 when we // should have failed, or at least waited longer for (JettySolrRunner jsr : jsrs) { List<CoreDescriptor> coreDescriptors = jsr.getCoreContainer().getCoreDescriptors(); for (CoreDescriptor coreDescriptor : coreDescriptors) { String collectionName = coreDescriptor.getCollectionName(); if (collection.equals(collectionName)) { coreFooCount ++; } } } if (NANOSECONDS.toSeconds(System.nanoTime() - start) > 60) { fail("took over 60 seconds after collection creation to update aliases:"+collection + " core count=" + coreFooCount + " was looking for " + count); } else { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); fail(e.getMessage()); } } } while(coreFooCount != count); }
Example #27
Source File: TestIndexSearcher.java From lucene-solr with Apache License 2.0 | 5 votes |
private void createCoreAndValidateListeners(int numTimesCalled, int numTimesCalledFirstSearcher, int numTimesCalledAfterGetSearcher, int numTimesCalledFirstSearcherAfterGetSearcher) throws Exception { CoreContainer cores = h.getCoreContainer(); CoreDescriptor cd = h.getCore().getCoreDescriptor(); SolrCore newCore = null; // reset counters MockSearcherListener.numberOfTimesCalled = new AtomicInteger(); MockSearcherListener.numberOfTimesCalledFirstSearcher = new AtomicInteger(); try { // Create a new core, this should call all the firstSearcherListeners newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false); //validate that the new core was created with the correct solrconfig assertNotNull(newCore.getSearchComponent("mock")); assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass()); assertFalse(newCore.getSolrConfig().useColdSearcher); doQuery(newCore); assertEquals(numTimesCalled, MockSearcherListener.numberOfTimesCalled.get()); assertEquals(numTimesCalledFirstSearcher, MockSearcherListener.numberOfTimesCalledFirstSearcher.get()); addDummyDoc(newCore); // Open a new searcher, this should call the newSearcherListeners @SuppressWarnings({"rawtypes"}) Future<?>[] future = new Future[1]; newCore.getSearcher(true, false, future); future[0].get(); assertEquals(numTimesCalledAfterGetSearcher, MockSearcherListener.numberOfTimesCalled.get()); assertEquals(numTimesCalledFirstSearcherAfterGetSearcher, MockSearcherListener.numberOfTimesCalledFirstSearcher.get()); } finally { if (newCore != null) { cores.unload("core1"); } } }
Example #28
Source File: HealthCheckHandlerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private CloudDescriptor mockCD(String collection, String name, String shardId, boolean registered, Replica.State state) { Properties props = new Properties(); props.put(CoreDescriptor.CORE_SHARD, shardId); props.put(CoreDescriptor.CORE_COLLECTION, collection); props.put(CoreDescriptor.CORE_NODE_NAME, name); CloudDescriptor cd = new CloudDescriptor(null, name, props); cd.setHasRegistered(registered); cd.setLastPublished(state); return cd; }
Example #29
Source File: SentryTestBase.java From incubator-sentry with Apache License 2.0 | 5 votes |
public static void closeCore(SolrCore coreToClose, CloudDescriptor cloudDescriptor) throws Exception { if (cloudDescriptor != null) { CoreDescriptor coreDescriptor = coreToClose.getCoreDescriptor(); Field cloudDescField = CoreDescriptor.class.getDeclaredField("cloudDesc"); cloudDescField.setAccessible(true); cloudDescField.set(coreDescriptor, cloudDescriptor); } coreToClose.close(); }
Example #30
Source File: SentryTestBase.java From incubator-sentry with Apache License 2.0 | 5 votes |
protected SolrQueryRequest prepareCollAndUser(SolrCore core, SolrQueryRequest request, String collection, String user, boolean onlyOnce) throws Exception { CloudDescriptor mCloudDescriptor = EasyMock.createMock(CloudDescriptor.class); IExpectationSetters getCollNameExpect = EasyMock.expect(mCloudDescriptor.getCollectionName()).andReturn(collection); getCollNameExpect.anyTimes(); IExpectationSetters getShardIdExpect = EasyMock.expect(mCloudDescriptor.getShardId()).andReturn("shard1"); getShardIdExpect.anyTimes(); EasyMock.replay(mCloudDescriptor); CoreDescriptor coreDescriptor = core.getCoreDescriptor(); Field cloudDescField = CoreDescriptor.class.getDeclaredField("cloudDesc"); cloudDescField.setAccessible(true); cloudDescField.set(coreDescriptor, mCloudDescriptor); HttpServletRequest httpServletRequest = EasyMock.createMock(HttpServletRequest.class); IExpectationSetters getAttributeUserExpect = EasyMock.expect(httpServletRequest.getAttribute(USER_NAME)).andReturn(user); if (!onlyOnce) { getAttributeUserExpect.anyTimes(); } IExpectationSetters getAttributeDoAsUserExpect = EasyMock.expect(httpServletRequest.getAttribute(DO_AS_USER_NAME)).andReturn(null); if (!onlyOnce) { getAttributeDoAsUserExpect.anyTimes(); } EasyMock.replay(httpServletRequest); request.getContext().put("httpRequest", httpServletRequest); return request; }