use of org.opensearch.client.indices.ComponentTemplatesExistRequest in project OpenSearch by opensearch-project.
the class ClusterClientIT method testComponentTemplates.
public void testComponentTemplates() throws Exception {
String templateName = "my-template";
Settings settings = Settings.builder().put("index.number_of_shards", 1).build();
CompressedXContent mappings = new CompressedXContent("{\"properties\":{\"host_name\":{\"type\":\"keyword\"}}}");
AliasMetadata alias = AliasMetadata.builder("alias").writeIndex(true).build();
Template template = new Template(settings, mappings, Collections.singletonMap("alias", alias));
ComponentTemplate componentTemplate = new ComponentTemplate(template, 1L, new HashMap<>());
PutComponentTemplateRequest putComponentTemplateRequest = new PutComponentTemplateRequest().name(templateName).create(true).componentTemplate(componentTemplate);
AcknowledgedResponse response = execute(putComponentTemplateRequest, highLevelClient().cluster()::putComponentTemplate, highLevelClient().cluster()::putComponentTemplateAsync);
assertThat(response.isAcknowledged(), equalTo(true));
ComponentTemplatesExistRequest componentTemplatesExistRequest = new ComponentTemplatesExistRequest(templateName);
boolean exist = execute(componentTemplatesExistRequest, highLevelClient().cluster()::existsComponentTemplate, highLevelClient().cluster()::existsComponentTemplateAsync);
assertTrue(exist);
GetComponentTemplatesRequest getComponentTemplatesRequest = new GetComponentTemplatesRequest(templateName);
GetComponentTemplatesResponse getResponse = execute(getComponentTemplatesRequest, highLevelClient().cluster()::getComponentTemplate, highLevelClient().cluster()::getComponentTemplateAsync);
assertThat(getResponse.getComponentTemplates().size(), equalTo(1));
assertThat(getResponse.getComponentTemplates().containsKey(templateName), equalTo(true));
assertThat(getResponse.getComponentTemplates().get(templateName), equalTo(componentTemplate));
DeleteComponentTemplateRequest deleteComponentTemplateRequest = new DeleteComponentTemplateRequest(templateName);
response = execute(deleteComponentTemplateRequest, highLevelClient().cluster()::deleteComponentTemplate, highLevelClient().cluster()::deleteComponentTemplateAsync);
assertThat(response.isAcknowledged(), equalTo(true));
OpenSearchStatusException statusException = expectThrows(OpenSearchStatusException.class, () -> execute(getComponentTemplatesRequest, highLevelClient().cluster()::getComponentTemplate, highLevelClient().cluster()::getComponentTemplateAsync));
assertThat(statusException.status(), equalTo(RestStatus.NOT_FOUND));
exist = execute(componentTemplatesExistRequest, highLevelClient().cluster()::existsComponentTemplate, highLevelClient().cluster()::existsComponentTemplateAsync);
assertFalse(exist);
}
use of org.opensearch.client.indices.ComponentTemplatesExistRequest in project OpenSearch by opensearch-project.
the class ClusterRequestConverters method componentTemplatesExist.
static Request componentTemplatesExist(ComponentTemplatesExistRequest componentTemplatesRequest) {
final String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_component_template").addPathPart(componentTemplatesRequest.name()).build();
final Request request = new Request(HttpHead.METHOD_NAME, endpoint);
final RequestConverters.Params params = new RequestConverters.Params();
params.withLocal(componentTemplatesRequest.isLocal());
params.withMasterTimeout(componentTemplatesRequest.getMasterNodeTimeout());
request.addParameters(params.asMap());
return request;
}
Aggregations