|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.xpack.inference.services.elasticsearch; |
| 9 | + |
| 10 | +import org.elasticsearch.ResourceNotFoundException; |
| 11 | +import org.elasticsearch.action.ActionListener; |
| 12 | +import org.elasticsearch.inference.ChunkingSettings; |
| 13 | +import org.elasticsearch.inference.Model; |
| 14 | +import org.elasticsearch.inference.TaskType; |
| 15 | +import org.elasticsearch.xpack.core.ml.action.CreateTrainedModelAssignmentAction; |
| 16 | +import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; |
| 17 | + |
| 18 | +public class ElasticDeployedModel extends ElasticsearchInternalModel { |
| 19 | + public ElasticDeployedModel( |
| 20 | + String inferenceEntityId, |
| 21 | + TaskType taskType, |
| 22 | + String service, |
| 23 | + ElserInternalServiceSettings serviceSettings, |
| 24 | + ElserMlNodeTaskSettings taskSettings, |
| 25 | + ChunkingSettings chunkingSettings |
| 26 | + ) { |
| 27 | + super(inferenceEntityId, taskType, service, serviceSettings, taskSettings, chunkingSettings); |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public ActionListener<CreateTrainedModelAssignmentAction.Response> getCreateTrainedModelAssignmentActionListener(Model model, ActionListener<Boolean> listener) { |
| 32 | + return new ActionListener<>() { |
| 33 | + @Override |
| 34 | + public void onResponse(CreateTrainedModelAssignmentAction.Response response) { |
| 35 | + listener.onResponse(Boolean.TRUE); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public void onFailure(Exception e) { |
| 40 | + if (ExceptionsHelper.unwrapCause(e) instanceof ResourceNotFoundException) { |
| 41 | + listener.onFailure( |
| 42 | + new ResourceNotFoundException( |
| 43 | + "Could not start the inference as the deploymend model [{0}] cannot be found." |
| 44 | + + " Trained Models must be deployed before they can be started.", |
| 45 | + internalServiceSettings.modelId() |
| 46 | + ) |
| 47 | + ); |
| 48 | + return; |
| 49 | + } |
| 50 | + listener.onFailure(e); |
| 51 | + } |
| 52 | + }; |
| 53 | + } |
| 54 | +} |
0 commit comments