Java Code Examples for org.elasticsearch.rest.RestStatus#INTERNAL_SERVER_ERROR
The following examples show how to use
org.elasticsearch.rest.RestStatus#INTERNAL_SERVER_ERROR .
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: ValidatingDispatcher.java From deprecated-security-ssl with Apache License 2.0 | 6 votes |
protected void checkRequest(final RestRequest request, final RestChannel channel) { if(SSLRequestHelper.containsBadHeader(threadContext, "_opendistro_security_ssl_")) { final ElasticsearchException exception = ExceptionUtils.createBadHeaderException(); errorHandler.logError(exception, request, 1); throw exception; } try { if(SSLRequestHelper.getSSLInfo(settings, configPath, request, null) == null) { logger.error("Not an SSL request"); throw new ElasticsearchSecurityException("Not an SSL request", RestStatus.INTERNAL_SERVER_ERROR); } } catch (SSLPeerUnverifiedException e) { logger.error("No client certificates found but such are needed (Security 8)."); errorHandler.logError(e, request, 0); throw ExceptionsHelper.convertToElastic(e); } }
Example 2
Source File: SnapshotShardFailure.java From crate with Apache License 2.0 | 5 votes |
private static SnapshotShardFailure constructSnapshotShardFailure(Object[] args) { String index = (String) args[0]; String indexUuid = (String) args[1]; final String nodeId = (String) args[2]; String reason = (String) args[3]; Integer intShardId = (Integer) args[4]; final String status = (String) args[5]; if (index == null) { throw new ElasticsearchParseException("index name was not set"); } if (intShardId == null) { throw new ElasticsearchParseException("index shard was not set"); } ShardId shardId = new ShardId(index, indexUuid != null ? indexUuid : IndexMetaData.INDEX_UUID_NA_VALUE, intShardId); // Workaround for https://github.com/elastic/elasticsearch/issues/25878 // Some old snapshot might still have null in shard failure reasons String nonNullReason; if (reason != null) { nonNullReason = reason; } else { nonNullReason = ""; } RestStatus restStatus; if (status != null) { restStatus = RestStatus.valueOf(status); } else { restStatus = RestStatus.INTERNAL_SERVER_ERROR; } return new SnapshotShardFailure(nodeId, shardId, nonNullReason, restStatus); }
Example 3
Source File: ExceptionsHelper.java From crate with Apache License 2.0 | 5 votes |
public static RestStatus status(Throwable t) { if (t != null) { if (t instanceof ElasticsearchException) { return ((ElasticsearchException) t).status(); } else if (t instanceof IllegalArgumentException) { return RestStatus.BAD_REQUEST; } else if (t instanceof EsRejectedExecutionException) { return RestStatus.TOO_MANY_REQUESTS; } } return RestStatus.INTERNAL_SERVER_ERROR; }
Example 4
Source File: ElasticsearchException.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Returns the rest status code associated with this exception. */ public RestStatus status() { Throwable cause = unwrapCause(); if (cause == this) { return RestStatus.INTERNAL_SERVER_ERROR; } else { return ExceptionsHelper.status(cause); } }
Example 5
Source File: ExceptionsHelper.java From Elasticsearch with Apache License 2.0 | 5 votes |
public static RestStatus status(Throwable t) { if (t != null) { if (t instanceof ElasticsearchException) { return ((ElasticsearchException) t).status(); } else if (t instanceof IllegalArgumentException) { return RestStatus.BAD_REQUEST; } } return RestStatus.INTERNAL_SERVER_ERROR; }
Example 6
Source File: ElasticsearchException.java From crate with Apache License 2.0 | 5 votes |
/** * Returns the rest status code associated with this exception. */ public RestStatus status() { Throwable cause = unwrapCause(); if (cause == this) { return RestStatus.INTERNAL_SERVER_ERROR; } else { return ExceptionsHelper.status(cause); } }
Example 7
Source File: SnapshotInfo.java From crate with Apache License 2.0 | 5 votes |
/** * Returns snapshot REST status */ public RestStatus status() { if (state == SnapshotState.FAILED) { return RestStatus.INTERNAL_SERVER_ERROR; } if (shardFailures.size() == 0) { return RestStatus.OK; } return RestStatus.status(successfulShards, totalShards, shardFailures.toArray(new ShardOperationFailedException[shardFailures.size()])); }
Example 8
Source File: SnapshotBackupManager.java From Raigad with Apache License 2.0 | 5 votes |
public void runSnapshotBackup() throws Exception { // Create or Get Repository String repositoryName = repository.createOrGetSnapshotRepository(); // StartBackup String snapshotName = getSnapshotName(config.getCommaSeparatedIndicesToBackup(), config.includeIndexNameInSnapshot()); logger.info("Repository Name : <" + repositoryName + "> Snapshot Name : <" + snapshotName + "> Indices : <" + config.getCommaSeparatedIndicesToBackup() + "> \nRunning Snapshot now ... "); Client esTransportClient = ElasticsearchTransportClient.instance(config).getTransportClient(); Stopwatch snapshotTimer = snapshotDuration.start(); //This is a blocking call. It'll wait until Snapshot is finished. CreateSnapshotResponse createSnapshotResponse = getCreateSnapshotResponse(esTransportClient, repositoryName, snapshotName); logger.info("Snapshot Status = " + createSnapshotResponse.status().toString()); if (createSnapshotResponse.status() == RestStatus.OK) { //TODO Add Servo Monitoring so that it can be verified from dashboard printSnapshotDetails(createSnapshotResponse); snapshotSuccess.incrementAndGet(); } else if (createSnapshotResponse.status() == RestStatus.INTERNAL_SERVER_ERROR) { //TODO Add Servo Monitoring so that it can be verified from dashboard logger.info("Snapshot Completely Failed"); snapshotFailure.incrementAndGet(); } //Stop the timer snapshotTimer.stop(); }
Example 9
Source File: ShardSearchFailure.java From Elasticsearch with Apache License 2.0 | 4 votes |
public ShardSearchFailure(String reason, SearchShardTarget shardTarget) { this(reason, shardTarget, RestStatus.INTERNAL_SERVER_ERROR); }
Example 10
Source File: ElasticsearchSecurityException.java From crate with Apache License 2.0 | 4 votes |
/** * Build the exception with a status of {@link RestStatus#INTERNAL_SERVER_ERROR} without a cause. */ public ElasticsearchSecurityException(String msg, Object... args) { this(msg, RestStatus.INTERNAL_SERVER_ERROR, args); }
Example 11
Source File: RepositoryVerificationException.java From crate with Apache License 2.0 | 4 votes |
@Override public RestStatus status() { return RestStatus.INTERNAL_SERVER_ERROR; }
Example 12
Source File: IndexPrimaryShardNotAllocatedException.java From crate with Apache License 2.0 | 4 votes |
@Override public RestStatus status() { return RestStatus.INTERNAL_SERVER_ERROR; }
Example 13
Source File: RestoreBackupManager.java From Raigad with Apache License 2.0 | 4 votes |
public void runRestore(String sourceRepositoryName, String repositoryType, String snapshotName, String indices, String renamePattern, String renameReplacement) throws Exception { Client esTransportClient = ElasticsearchTransportClient.instance(config).getTransportClient(); // Get Repository Name : This will serve as BasePath Suffix String sourceRepoName = StringUtils.isBlank(sourceRepositoryName) ? config.getRestoreRepositoryName() : sourceRepositoryName; if (StringUtils.isBlank(sourceRepoName)) throw new RestoreBackupException("Repository Name is Null or Empty"); //Attach suffix to the repository name so that it does not conflict with Snapshot Repository name String restoreRepositoryName = sourceRepoName + SUFFIX_SEPARATOR_TAG + config.getRestoreSourceClusterName(); String repoType = StringUtils.isBlank(repositoryType) ? config.getRestoreRepositoryType().toLowerCase() : repositoryType; if (StringUtils.isBlank(repoType)) { logger.info("RepositoryType is empty, hence Defaulting to <s3> type"); repoType = AbstractRepository.RepositoryType.s3.name(); } if (!repository.doesRepositoryExists(restoreRepositoryName, AbstractRepository.RepositoryType.valueOf(repoType.toLowerCase()))) { //If repository does not exist, create new one repository.createRestoreRepository(restoreRepositoryName, sourceRepoName); } // Get Snapshot Name String snapshotN = StringUtils.isBlank(snapshotName) ? config.getRestoreSnapshotName() : snapshotName; if (StringUtils.isBlank(snapshotN)) { //Pick the last Snapshot from the available Snapshots List<String> snapshots = ElasticsearchUtils.getAvailableSnapshots(esTransportClient, restoreRepositoryName); if (snapshots.isEmpty()) throw new RestoreBackupException("No available snapshots in <" + restoreRepositoryName + "> repository."); //Sorting Snapshot names in Reverse Order Collections.sort(snapshots, Collections.reverseOrder()); //Use the Last available snapshot snapshotN = snapshots.get(0); } logger.info("Snapshot Name : <" + snapshotN + ">"); // Get Names of Indices String commaSeparatedIndices = StringUtils.isBlank(indices) ? config.getCommaSeparatedIndicesToRestore() : indices; if (StringUtils.isBlank(commaSeparatedIndices) || commaSeparatedIndices.equalsIgnoreCase(ALL_INDICES_TAG)) { commaSeparatedIndices = null; logger.info("Restoring all Indices."); } logger.info("Indices param : <" + commaSeparatedIndices + ">"); RestoreSnapshotResponse restoreSnapshotResponse = getRestoreSnapshotResponse(esTransportClient, commaSeparatedIndices, restoreRepositoryName, snapshotN, renamePattern, renameReplacement); logger.info("Restore Status = " + restoreSnapshotResponse.status().toString()); if (restoreSnapshotResponse.status() == RestStatus.OK) { printRestoreDetails(restoreSnapshotResponse); } else if (restoreSnapshotResponse.status() == RestStatus.INTERNAL_SERVER_ERROR) logger.info("Restore Completely Failed"); }
Example 14
Source File: ElasticsearchSecurityException.java From Elasticsearch with Apache License 2.0 | 4 votes |
public ElasticsearchSecurityException(String msg, Object... args) { this(msg, RestStatus.INTERNAL_SERVER_ERROR, null, args); }
Example 15
Source File: RepositoryVerificationException.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public RestStatus status() { return RestStatus.INTERNAL_SERVER_ERROR; }
Example 16
Source File: IndexPrimaryShardNotAllocatedException.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public RestStatus status() { return RestStatus.INTERNAL_SERVER_ERROR; }
Example 17
Source File: TransportBaseSQLAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** * Create a {@link io.crate.action.sql.SQLActionException} out of a {@link java.lang.Throwable}. * If concrete {@link org.elasticsearch.ElasticsearchException} is found, first transform it * to a {@link io.crate.exceptions.CrateException} */ private SQLActionException buildSQLActionException(Throwable e) { logger.error("errors while processing sql", e); if (e instanceof SQLActionException) { return (SQLActionException) e; } e = esToCrateException(e); int errorCode = 5000; RestStatus restStatus = RestStatus.INTERNAL_SERVER_ERROR; if (e instanceof CrateException) { CrateException crateException = (CrateException) e; if (e instanceof ValidationException) { errorCode = 4000 + crateException.errorCode(); restStatus = RestStatus.BAD_REQUEST; } else if (e instanceof NoPermissionException) { errorCode = 4000 + crateException.errorCode(); restStatus = RestStatus.UNAUTHORIZED; e.setStackTrace(new StackTraceElement[0]); } else if (e instanceof ForbiddenException) { errorCode = 4030 + crateException.errorCode(); restStatus = RestStatus.FORBIDDEN; } else if (e instanceof ResourceUnknownException) { errorCode = 4040 + crateException.errorCode(); restStatus = RestStatus.NOT_FOUND; } else if (e instanceof ConflictException) { errorCode = 4090 + crateException.errorCode(); restStatus = RestStatus.CONFLICT; } else if (e instanceof UnhandledServerException) { errorCode = 5000 + crateException.errorCode(); } } else if (e instanceof ParsingException) { errorCode = 4000; restStatus = RestStatus.BAD_REQUEST; } else if (e instanceof MapperParsingException) { errorCode = 4000; restStatus = RestStatus.BAD_REQUEST; } String message = e.getMessage(); if (message == null) { if (e instanceof CrateException && e.getCause() != null) { e = e.getCause(); // use cause because it contains a more meaningful error in most cases } StackTraceElement[] stackTraceElements = e.getStackTrace(); if (stackTraceElements.length > 0) { message = String.format(Locale.ENGLISH, "%s in %s", e.getClass().getSimpleName(), stackTraceElements[0]); } else { message = "Error in " + e.getClass().getSimpleName(); } } else { message = e.getClass().getSimpleName() + ": " + message; } return new SQLActionException(message, errorCode, restStatus, e.getStackTrace()); }
Example 18
Source File: RestGetAnomalyDetectorAction.java From anomaly-detection with Apache License 2.0 | 4 votes |
private RestResponse buildInternalServerErrorResponse(Exception e, String errorMsg) { logger.error(errorMsg, e); return new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, errorMsg); }
Example 19
Source File: SnapshotShardFailure.java From Elasticsearch with Apache License 2.0 | 3 votes |
/** * Constructs new snapshot shard failure object * * @param nodeId node where failure occurred * @param index index which the shard belongs to * @param shardId shard id * @param reason failure reason */ public SnapshotShardFailure(@Nullable String nodeId, String index, int shardId, String reason) { this.nodeId = nodeId; this.index = index; this.shardId = shardId; this.reason = reason; status = RestStatus.INTERNAL_SERVER_ERROR; }
Example 20
Source File: SnapshotShardFailure.java From crate with Apache License 2.0 | 2 votes |
/** * Constructs new snapshot shard failure object * * @param nodeId node where failure occurred * @param shardId shard id * @param reason failure reason */ public SnapshotShardFailure(@Nullable String nodeId, ShardId shardId, String reason) { this(nodeId, shardId, reason, RestStatus.INTERNAL_SERVER_ERROR); }