Skip to content

Commit

Permalink
Adding support to run CI against opensearch and cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Jindal <[email protected]>
  • Loading branch information
Aditya Jindal authored and VijayanB committed Aug 28, 2021
1 parent dd4938b commit 966c0e1
Show file tree
Hide file tree
Showing 54 changed files with 118 additions and 234 deletions.
6 changes: 3 additions & 3 deletions .ci/DockerFile.Repository
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ COPY Cargo.toml ./Cargo.toml
COPY Makefile.toml ./Makefile.toml
COPY README.md ./README.md
COPY api_generator ./api_generator
COPY elasticsearch/Cargo.toml ./elasticsearch/Cargo.toml
COPY elasticsearch/src ./elasticsearch/src
COPY elasticsearch/build.rs ./elasticsearch/build.rs
COPY opensearch/Cargo.toml ./opensearch/Cargo.toml
COPY opensearch/src ./opensearch/src
COPY opensearch/build.rs ./opensearch/build.rs
COPY yaml_test_runner ./yaml_test_runner

RUN cargo build --tests
2 changes: 1 addition & 1 deletion .github/workflows/test-integrations.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Integration tests against Opensearch and Opendistro Cluster
name: Integration tests against OpenSearch and Opendistro Cluster

on:
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"api_generator",
"elasticsearch",
"opensearch",
"yaml_test_runner"
]
2 changes: 1 addition & 1 deletion api_generator/src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() -> Result<(), failure::Error> {

// This must be run from the repo root directory, with cargo make generate-api
let download_dir = fs::canonicalize(PathBuf::from("./api_generator/rest_specs"))?;
let generated_dir = fs::canonicalize(PathBuf::from("./elasticsearch/src"))?;
let generated_dir = fs::canonicalize(PathBuf::from("./opensearch/src"))?;
let last_downloaded_version =
PathBuf::from("./api_generator/rest_specs/last_downloaded_version");

Expand Down
2 changes: 1 addition & 1 deletion api_generator/src/generator/code_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn use_declarations() -> Tokens {
#![allow(unused_imports)]

use crate::{
client::Elasticsearch,
client::OpenSearch,
params::*,
error::Error,
http::{
Expand Down
2 changes: 1 addition & 1 deletion api_generator/src/generator/code_gen/namespace_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn generate(api: &Api, docs_dir: &PathBuf) -> Result<Vec<(String, String)>,
}

#cfg_attr
impl Elasticsearch {
impl OpenSearch {
#namespace_fn_doc
pub fn #namespace_name(&self) -> #namespace_client_name {
#namespace_client_name::new(self.transport())
Expand Down
4 changes: 2 additions & 2 deletions api_generator/src/generator/code_gen/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn generate(api: &Api, docs_dir: &PathBuf) -> Result<String, failure::Error>
let builder_name = name.to_pascal_case();
RequestBuilder::new(
docs_dir,
"Elasticsearch",
"OpenSearch",
name,
&builder_name,
&api.common_params,
Expand All @@ -52,7 +52,7 @@ pub fn generate(api: &Api, docs_dir: &PathBuf) -> Result<String, failure::Error>
tokens.append(quote!(
#(#builders)*

impl Elasticsearch {
impl OpenSearch {
#(#methods)*
}
));
Expand Down
6 changes: 2 additions & 4 deletions api_generator/src/rest_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn download_specs(branch: &str, download_dir: &PathBuf) -> Result<(), failur
let mut headers = HeaderMap::new();
headers.append(
USER_AGENT,
HeaderValue::from_str(&format!("elasticsearch-rs/{}", env!("CARGO_PKG_NAME")))?,
HeaderValue::from_str(&format!("opensearch-rs/{}", env!("CARGO_PKG_NAME")))?,
);
let client = reqwest::ClientBuilder::new()
.default_headers(headers)
Expand All @@ -46,13 +46,11 @@ pub fn download_specs(branch: &str, download_dir: &PathBuf) -> Result<(), failur

let oss_spec = Glob::new("**/rest-api-spec/src/main/resources/rest-api-spec/api/*.json")?
.compile_matcher();
let xpack_spec = Glob::new("**/x-pack/plugin/src/test/resources/rest-api-spec/api/*.json")?
.compile_matcher();

for entry in archive.entries()? {
let file = entry?;
let path = file.path()?;
if oss_spec.is_match(&path) || xpack_spec.is_match(&path) {
if oss_spec.is_match(&path) {
write_spec_file(download_dir, file)?;
}
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use elasticsearch::{
auth::Credentials,
cat::CatIndicesParts,
http::transport::{SingleNodeConnectionPool, TransportBuilder},
Elasticsearch, Error, DEFAULT_ADDRESS,
Error, OpenSearch, DEFAULT_ADDRESS,
};
use sysinfo::SystemExt;
use url::Url;
Expand All @@ -55,7 +55,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

fn create_client() -> Result<Elasticsearch, Error> {
fn create_client() -> Result<OpenSearch, Error> {
fn cluster_addr() -> String {
match std::env::var("OPENSEARCH_URL") {
Ok(server) => server,
Expand Down Expand Up @@ -118,5 +118,5 @@ fn create_client() -> Result<Elasticsearch, Error> {
}

let transport = builder.build()?;
Ok(Elasticsearch::new(transport))
Ok(OpenSearch::new(transport))
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ extern crate serde_json;

use clap::{App, Arg};
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
use elasticsearch::cert::CertificateValidation;
use elasticsearch::{
use opensearch::cert::CertificateValidation;
use opensearch::{
auth::Credentials,
http::transport::{SingleNodeConnectionPool, TransportBuilder},
indices::{
IndicesCreateParts, IndicesDeleteParts, IndicesExistsParts, IndicesPutSettingsParts,
},
BulkOperation, BulkParts, Elasticsearch, Error, DEFAULT_ADDRESS,
BulkOperation, BulkParts, Error, OpenSearch, DEFAULT_ADDRESS,
};
use serde_json::Value;
use sysinfo::SystemExt;
Expand Down Expand Up @@ -157,7 +157,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

async fn set_refresh_interval(client: &Elasticsearch, interval: Value) -> Result<(), Error> {
async fn set_refresh_interval(client: &OpenSearch, interval: Value) -> Result<(), Error> {
let response = client
.indices()
.put_settings(IndicesPutSettingsParts::Index(&[POSTS_INDEX]))
Expand All @@ -176,7 +176,7 @@ async fn set_refresh_interval(client: &Elasticsearch, interval: Value) -> Result
Ok(())
}

async fn index_posts(client: &Elasticsearch, posts: &[Post]) -> Result<(), Error> {
async fn index_posts(client: &OpenSearch, posts: &[Post]) -> Result<(), Error> {
let body: Vec<BulkOperation<_>> = posts
.iter()
.map(|p| {
Expand Down Expand Up @@ -208,7 +208,7 @@ async fn index_posts(client: &Elasticsearch, posts: &[Post]) -> Result<(), Error
Ok(())
}

async fn create_index_if_not_exists(client: &Elasticsearch, delete: bool) -> Result<(), Error> {
async fn create_index_if_not_exists(client: &OpenSearch, delete: bool) -> Result<(), Error> {
let exists = client
.indices()
.exists(IndicesExistsParts::Index(&[POSTS_INDEX]))
Expand Down Expand Up @@ -372,7 +372,7 @@ async fn create_index_if_not_exists(client: &Elasticsearch, delete: bool) -> Res
Ok(())
}

fn create_client() -> Result<Elasticsearch, Error> {
fn create_client() -> Result<OpenSearch, Error> {
fn cluster_addr() -> String {
match std::env::var("OPENSEARCH_URL") {
Ok(server) => server,
Expand Down Expand Up @@ -435,5 +435,5 @@ fn create_client() -> Result<Elasticsearch, Error> {
}

let transport = builder.build()?;
Ok(Elasticsearch::new(transport))
Ok(OpenSearch::new(transport))
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use elasticsearch::cert::CertificateValidation;
use elasticsearch::{
auth::Credentials,
http::transport::{SingleNodeConnectionPool, TransportBuilder},
Elasticsearch, Error, SearchParts, DEFAULT_ADDRESS,
Error, OpenSearch, SearchParts, DEFAULT_ADDRESS,
};
use serde_json::{json, Value};
use std::env;
Expand Down Expand Up @@ -122,7 +122,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

fn create_client() -> Result<Elasticsearch, Error> {
fn create_client() -> Result<OpenSearch, Error> {
fn cluster_addr() -> String {
match std::env::var("OPENSEARCH_URL") {
Ok(server) => server,
Expand Down Expand Up @@ -185,5 +185,5 @@ fn create_client() -> Result<Elasticsearch, Error> {
}

let transport = builder.build()?;
Ok(Elasticsearch::new(transport))
Ok(OpenSearch::new(transport))
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use elasticsearch::cert::CertificateValidation;
use elasticsearch::{
auth::Credentials,
http::transport::{SingleNodeConnectionPool, TransportBuilder},
Elasticsearch, Error, SearchParts, DEFAULT_ADDRESS,
Error, OpenSearch, SearchParts, DEFAULT_ADDRESS,
};
use serde_json::Value;
use std::env;
Expand Down Expand Up @@ -109,7 +109,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

fn create_client() -> Result<Elasticsearch, Error> {
fn create_client() -> Result<OpenSearch, Error> {
fn cluster_addr() -> String {
match std::env::var("OPENSEARCH_URL") {
Ok(server) => server,
Expand Down Expand Up @@ -172,5 +172,5 @@ fn create_client() -> Result<Elasticsearch, Error> {
}

let transport = builder.build()?;
Ok(Elasticsearch::new(transport))
Ok(OpenSearch::new(transport))
}
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions elasticsearch/src/cat.rs → opensearch/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
//! and accept headers, returning plain text responses
//!
//! ```rust,no_run
//! # use elasticsearch::{Elasticsearch, Error, SearchParts};
//! # use elasticsearch::{OpenSearch, Error, SearchParts};
//! # use url::Url;
//! # use elasticsearch::auth::Credentials;
//! # use serde_json::{json, Value};
//! # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
//! # let client = Elasticsearch::default();
//! # let client = OpenSearch::default();
//! let response = client
//! .cat()
//! .nodes()
Expand All @@ -58,12 +58,12 @@
//! JSON responses can be returned from Cat APIs either by using `.format("json")`
//!
//! ```rust,no_run
//! # use elasticsearch::{Elasticsearch, Error, SearchParts};
//! # use elasticsearch::{OpenSearch, Error, SearchParts};
//! # use url::Url;
//! # use elasticsearch::auth::Credentials;
//! # use serde_json::{json, Value};
//! # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
//! # let client = Elasticsearch::default();
//! # let client = OpenSearch::default();
//! let response = client
//! .cat()
//! .nodes()
Expand All @@ -79,11 +79,11 @@
//! Or by setting an accept header using `.headers()`
//!
//! ```rust,no_run
//! # use elasticsearch::{Elasticsearch, Error, SearchParts, http::headers::{HeaderValue, DEFAULT_ACCEPT, ACCEPT}};
//! # use elasticsearch::{OpenSearch, Error, SearchParts, http::headers::{HeaderValue, DEFAULT_ACCEPT, ACCEPT}};
//! # use url::Url;
//! # use serde_json::{json, Value};
//! # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
//! # let client = Elasticsearch::default();
//! # let client = OpenSearch::default();
//! let response = client
//! .cat()
//! .nodes()
Expand All @@ -101,11 +101,11 @@
//! The column headers to return can be controlled with `.h()`
//!
//! ```rust,no_run
//! # use elasticsearch::{Elasticsearch, Error, SearchParts};
//! # use elasticsearch::{OpenSearch, Error, SearchParts};
//! # use url::Url;
//! # use serde_json::{json, Value};
//! # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
//! # let client = Elasticsearch::default();
//! # let client = OpenSearch::default();
//! let response = client
//! .cat()
//! .nodes()
Expand All @@ -121,7 +121,7 @@
#![allow(unused_imports)]
use crate::{
client::Elasticsearch,
client::OpenSearch,
error::Error,
http::{
headers::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE},
Expand Down Expand Up @@ -4058,7 +4058,7 @@ impl<'a> Cat<'a> {
CatThreadPool::new(self.transport(), parts)
}
}
impl Elasticsearch {
impl OpenSearch {
#[doc = "Creates a namespace client for Cat APIs"]
pub fn cat(&self) -> Cat {
Cat::new(self.transport())
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch/src/cert.rs → opensearch/src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ let _response = client.ping().send().await?;
/// # use elasticsearch::{
/// # auth::Credentials,
/// # cert::{Certificate,CertificateValidation},
/// # Error, Elasticsearch,
/// # Error, OpenSearch,
/// # http::transport::{TransportBuilder,SingleNodeConnectionPool},
/// # };
/// # use std::fs::File;
Expand All @@ -148,7 +148,7 @@ let _response = client.ping().send().await?;
/// let transport = TransportBuilder::new(conn_pool)
/// .cert_validation(CertificateValidation::None)
/// .build()?;
/// let client = Elasticsearch::new(transport);
/// let client = OpenSearch::new(transport);
/// let _response = client.ping().send().await?;
/// # Ok(())
/// # }
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/src/client.rs → opensearch/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ where

/// Root client for top level APIs
#[derive(Clone, Debug, Default)]
pub struct Elasticsearch {
pub struct OpenSearch {
transport: Transport,
}

impl Elasticsearch {
impl OpenSearch {
/// Creates a new instance of the root client
pub fn new(transport: Transport) -> Self {
Elasticsearch { transport }
OpenSearch { transport }
}

/// Gets the transport of the client
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch/src/cluster.rs → opensearch/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#![allow(unused_imports)]
use crate::{
client::Elasticsearch,
client::OpenSearch,
error::Error,
http::{
headers::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE},
Expand Down Expand Up @@ -2497,7 +2497,7 @@ impl<'a> Cluster<'a> {
ClusterStats::new(self.transport(), parts)
}
}
impl Elasticsearch {
impl OpenSearch {
#[doc = "Creates a namespace client for Cluster APIs"]
pub fn cluster(&self) -> Cluster {
Cluster::new(self.transport())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#![allow(unused_imports)]
use crate::{
client::Elasticsearch,
client::OpenSearch,
error::Error,
http::{
headers::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE},
Expand Down Expand Up @@ -516,7 +516,7 @@ impl<'a> DanglingIndices<'a> {
DanglingIndicesListDanglingIndices::new(self.transport())
}
}
impl Elasticsearch {
impl OpenSearch {
#[doc = "Creates a namespace client for DanglingIndices APIs"]
pub fn dangling_indices(&self) -> DanglingIndices {
DanglingIndices::new(self.transport())
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// cargo run -p api_generator
// -----------------------------------------------
# ! [ allow ( unused_imports ) ]use crate::{
client::Elasticsearch,
client::OpenSearch,
error::Error,
http::{
headers::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 966c0e1

Please sign in to comment.