use of org.opensearch.index.IndexNotFoundException in project ml-commons by opensearch-project.
the class GetModelTransportAction method doExecute.
@Override
protected void doExecute(Task task, ActionRequest request, ActionListener<MLModelGetResponse> actionListener) {
MLModelGetRequest mlModelGetRequest = MLModelGetRequest.fromActionRequest(request);
String modelId = mlModelGetRequest.getModelId();
GetRequest getRequest = new GetRequest(ML_MODEL_INDEX).id(modelId);
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
client.get(getRequest, ActionListener.wrap(r -> {
log.info("Completed Get Model Request, id:{}", modelId);
if (r != null && r.isExists()) {
try (XContentParser parser = createXContentParserFromRegistry(xContentRegistry, r.getSourceAsBytesRef())) {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
MLModel mlModel = MLModel.parse(parser);
actionListener.onResponse(MLModelGetResponse.builder().mlModel(mlModel).build());
} catch (Exception e) {
log.error("Failed to parse ml model" + r.getId(), e);
actionListener.onFailure(e);
}
} else {
actionListener.onFailure(new MLResourceNotFoundException("Fail to find model"));
}
}, e -> {
if (e instanceof IndexNotFoundException) {
actionListener.onFailure(new MLResourceNotFoundException("Fail to find model"));
} else {
log.error("Failed to get ML model " + modelId, e);
actionListener.onFailure(e);
}
}));
} catch (Exception e) {
log.error("Failed to get ML model " + modelId, e);
actionListener.onFailure(e);
}
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class AutoCreateIndexTests method testAutoCreationDisabled.
public void testAutoCreationDisabled() {
Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), false).build();
AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
String randomIndex = randomAlphaOfLengthBetween(1, 10);
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(randomIndex, buildClusterState()));
assertEquals("no such index [" + randomIndex + "] and [action.auto_create_index] is [false]", e.getMessage());
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class AutoCreateIndexTests method expectNotMatch.
private void expectNotMatch(ClusterState clusterState, AutoCreateIndex autoCreateIndex, String index) {
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(index, clusterState));
assertEquals("no such index [" + index + "] and [action.auto_create_index] ([" + autoCreateIndex.getAutoCreate() + "]) doesn't match", e.getMessage());
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class TransportBulkActionIndicesThatCannotBeCreatedTests method testSomeFail.
public void testSomeFail() {
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(new IndexRequest("ok"));
bulkRequest.add(new IndexRequest("bad"));
// Emulate auto_create_index=-bad,+*
indicesThatCannotBeCreatedTestCase(singleton("bad"), bulkRequest, index -> {
if (index.equals("bad")) {
throw new IndexNotFoundException("Can't make it because I say so");
}
return true;
});
// Emulate auto_create_index=false but the "ok" index already exists
indicesThatCannotBeCreatedTestCase(singleton("bad"), bulkRequest, index -> {
if (index.equals("bad")) {
throw new IndexNotFoundException("Can't make it because I say so");
}
return false;
});
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class TransportBulkActionIndicesThatCannotBeCreatedTests method testAllFail.
public void testAllFail() {
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(new IndexRequest("no"));
bulkRequest.add(new IndexRequest("can't"));
bulkRequest.add(new DeleteRequest("do").version(0).versionType(VersionType.EXTERNAL));
bulkRequest.add(new UpdateRequest("nothin", randomAlphaOfLength(5)));
indicesThatCannotBeCreatedTestCase(new HashSet<>(Arrays.asList("no", "can't", "do", "nothin")), bulkRequest, index -> {
throw new IndexNotFoundException("Can't make it because I say so");
});
}
Aggregations