org.apache.solr.handler.component.StandaloneReplicaSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-core Show documentation
Show all versions of solr-core Show documentation
Apache Solr (module: core)
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.component;
import java.lang.reflect.Array;
import java.util.Collections;
import java.util.List;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.security.AllowListUrlChecker;
/** A replica source for solr stand alone mode */
class StandaloneReplicaSource implements ReplicaSource {
private final List[] replicas;
@SuppressWarnings("unchecked")
public StandaloneReplicaSource(Builder builder) {
List list = StrUtils.splitSmart(builder.shardsParam, ",", true);
replicas = (List[]) Array.newInstance(List.class, list.size());
for (int i = 0; i < list.size(); i++) {
replicas[i] = StrUtils.splitSmart(list.get(i), "|", true);
// todo do we really not need to transform in non-cloud mode?!
// builder.replicaListTransformer.transform(replicas[i]);
CloudReplicaSource.checkUrlsAllowList(
builder.urlChecker, null, builder.shardsParam, replicas[i]);
}
}
@Override
public List getSliceNames() {
// there are no logical slice names in non-cloud
return Collections.emptyList();
}
@Override
public int getSliceCount() {
return replicas.length;
}
@Override
public List getReplicasBySlice(int sliceNumber) {
assert sliceNumber >= 0 && sliceNumber < replicas.length;
return replicas[sliceNumber];
}
static class Builder {
private String shardsParam;
private AllowListUrlChecker urlChecker;
public Builder shards(String shardsParam) {
this.shardsParam = shardsParam;
return this;
}
public Builder allowListUrlChecker(AllowListUrlChecker urlChecker) {
this.urlChecker = urlChecker;
return this;
}
public StandaloneReplicaSource build() {
return new StandaloneReplicaSource(this);
}
}
}