use of org.apache.solr.common.SolrException 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);
}
}
}
}
use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class CollectionsHandler method forceLeaderElection.
private static void forceLeaderElection(SolrQueryRequest req, CollectionsHandler handler) {
ClusterState clusterState = handler.coreContainer.getZkController().getClusterState();
String collectionName = req.getParams().required().get(COLLECTION_PROP);
String sliceId = req.getParams().required().get(SHARD_ID_PROP);
log.info("Force leader invoked, state: {}", clusterState);
DocCollection collection = clusterState.getCollection(collectionName);
Slice slice = collection.getSlice(sliceId);
if (slice == null) {
throw new SolrException(ErrorCode.BAD_REQUEST, "No shard with name " + sliceId + " exists for collection " + collectionName);
}
try {
// if an active replica is the leader, then all is fine already
Replica leader = slice.getLeader();
if (leader != null && leader.getState() == State.ACTIVE) {
throw new SolrException(ErrorCode.SERVER_ERROR, "The shard already has an active leader. Force leader is not applicable. State: " + slice);
}
// Clear out any LIR state
String lirPath = handler.coreContainer.getZkController().getLeaderInitiatedRecoveryZnodePath(collectionName, sliceId);
if (handler.coreContainer.getZkController().getZkClient().exists(lirPath, true)) {
StringBuilder sb = new StringBuilder();
handler.coreContainer.getZkController().getZkClient().printLayout(lirPath, 4, sb);
log.info("Cleaning out LIR data, which was: {}", sb);
handler.coreContainer.getZkController().getZkClient().clean(lirPath);
}
// state to active.
for (Replica rep : slice.getReplicas()) {
if (clusterState.getLiveNodes().contains(rep.getNodeName())) {
ShardHandler shardHandler = handler.coreContainer.getShardHandlerFactory().getShardHandler();
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, CoreAdminAction.FORCEPREPAREFORLEADERSHIP.toString());
params.set(CoreAdminParams.CORE, rep.getStr("core"));
String nodeName = rep.getNodeName();
OverseerCollectionMessageHandler.sendShardRequest(nodeName, params, shardHandler, null, null, CommonParams.CORES_HANDLER_PATH, // synchronous request
handler.coreContainer.getZkController().getZkStateReader());
}
}
// Wait till we have an active leader
boolean success = false;
for (int i = 0; i < 9; i++) {
Thread.sleep(5000);
clusterState = handler.coreContainer.getZkController().getClusterState();
collection = clusterState.getCollection(collectionName);
slice = collection.getSlice(sliceId);
if (slice.getLeader() != null && slice.getLeader().getState() == State.ACTIVE) {
success = true;
break;
}
log.warn("Force leader attempt {}. Waiting 5 secs for an active leader. State of the slice: {}", (i + 1), slice);
}
if (success) {
log.info("Successfully issued FORCELEADER command for collection: {}, shard: {}", collectionName, sliceId);
} else {
log.info("Couldn't successfully force leader, collection: {}, shard: {}. Cluster state: {}", collectionName, sliceId, clusterState);
}
} catch (SolrException e) {
throw e;
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Error executing FORCELEADER operation for collection: " + collectionName + " shard: " + sliceId, e);
}
}
use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class UpdateRequestHandlerApi method getApiImpl.
private Api getApiImpl() {
return new Api(ApiBag.getSpec("core.Update")) {
@Override
public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
String path = req.getPath();
String target = mapping.get(path);
if (target != null)
req.getContext().put("path", target);
try {
handleRequest(req, rsp);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
};
}
use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class ReplicationHandler method readIntervalNs.
private static Long readIntervalNs(String interval) {
if (interval == null)
return null;
int result = 0;
Matcher m = INTERVAL_PATTERN.matcher(interval.trim());
if (m.find()) {
String hr = m.group(1);
String min = m.group(2);
String sec = m.group(3);
result = 0;
try {
if (sec != null && sec.length() > 0)
result += Integer.parseInt(sec);
if (min != null && min.length() > 0)
result += (60 * Integer.parseInt(min));
if (hr != null && hr.length() > 0)
result += (60 * 60 * Integer.parseInt(hr));
return TimeUnit.NANOSECONDS.convert(result, TimeUnit.SECONDS);
} catch (NumberFormatException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, INTERVAL_ERR_MSG);
}
} else {
throw new SolrException(ErrorCode.SERVER_ERROR, INTERVAL_ERR_MSG);
}
}
use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class PingRequestHandler method handleRequestBody.
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
SolrParams params = req.getParams();
// in this case, we want to default distrib to false so
// we only ping the single node
Boolean distrib = params.getBool(DISTRIB);
if (distrib == null) {
ModifiableSolrParams mparams = new ModifiableSolrParams(params);
mparams.set(DISTRIB, false);
req.setParams(mparams);
}
String actionParam = params.get("action");
ACTIONS action = null;
if (actionParam == null) {
action = ACTIONS.PING;
} else {
try {
action = ACTIONS.valueOf(actionParam.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException iae) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " + actionParam);
}
}
switch(action) {
case PING:
if (isPingDisabled()) {
SolrException e = new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Service disabled");
rsp.setException(e);
return;
}
handlePing(req, rsp);
break;
case ENABLE:
handleEnable(true);
break;
case DISABLE:
handleEnable(false);
break;
case STATUS:
if (healthcheck == null) {
SolrException e = new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "healthcheck not configured");
rsp.setException(e);
} else {
rsp.add("status", isPingDisabled() ? "disabled" : "enabled");
}
}
}
Aggregations