-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lukasz Soszynski <lukasz.soszynski@eliatra.com>
- Loading branch information
1 parent
416e360
commit 614a87a
Showing
39 changed files
with
3,135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,344 changes: 1,344 additions & 0 deletions
1,344
src/integrationTest/java/org/opensearch/security/SearchOperationTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
src/integrationTest/java/org/opensearch/security/SnapshotSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
package org.opensearch.security; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.awaitility.Awaitility; | ||
|
||
import org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; | ||
import org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest; | ||
import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; | ||
import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; | ||
import org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; | ||
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; | ||
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; | ||
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; | ||
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; | ||
import org.opensearch.client.RestHighLevelClient; | ||
import org.opensearch.client.SnapshotClient; | ||
import org.opensearch.snapshots.SnapshotInfo; | ||
import org.opensearch.snapshots.SnapshotState; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.opensearch.client.RequestOptions.DEFAULT; | ||
|
||
class SnapshotSteps { | ||
|
||
private final SnapshotClient snapshotClient; | ||
|
||
public SnapshotSteps(RestHighLevelClient restHighLevelClient) { | ||
this.snapshotClient = requireNonNull(restHighLevelClient, "Rest high level client is required.").snapshot(); | ||
} | ||
|
||
//CS-SUPPRESS-ALL: It is not possible to use phrase "cluster manager" instead of master here | ||
public org.opensearch.action.support.master.AcknowledgedResponse createSnapshotRepository(String repositoryName, String snapshotDirPath, String type) | ||
//CS-ENFORCE-ALL | ||
throws IOException { | ||
PutRepositoryRequest createRepositoryRequest = new PutRepositoryRequest().name(repositoryName).type(type) | ||
.settings(Map.of("location", snapshotDirPath)); | ||
return snapshotClient.createRepository(createRepositoryRequest, DEFAULT); | ||
} | ||
|
||
public CreateSnapshotResponse createSnapshot(String repositoryName, String snapshotName, String...indices) throws IOException { | ||
CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest(repositoryName, snapshotName) | ||
.indices(indices); | ||
return snapshotClient.create(createSnapshotRequest, DEFAULT); | ||
} | ||
|
||
public void waitForSnapshotCreation(String repositoryName, String snapshotName) { | ||
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest(repositoryName, new String[] { snapshotName }); | ||
Awaitility.await().until(() -> { | ||
GetSnapshotsResponse snapshotsResponse = snapshotClient.get(getSnapshotsRequest, DEFAULT); | ||
SnapshotInfo snapshotInfo = snapshotsResponse.getSnapshots().get(0); | ||
return SnapshotState.SUCCESS.equals(snapshotInfo.state()); | ||
}); | ||
} | ||
|
||
//CS-SUPPRESS-ALL: It is not possible to use phrase "cluster manager" instead of master here | ||
public org.opensearch.action.support.master.AcknowledgedResponse deleteSnapshotRepository(String repositoryName) throws IOException { | ||
//CS-ENFORCE-ALL | ||
DeleteRepositoryRequest request = new DeleteRepositoryRequest(repositoryName); | ||
return snapshotClient.deleteRepository(request, DEFAULT); | ||
} | ||
|
||
//CS-SUPPRESS-ALL: It is not possible to use phrase "cluster manager" instead of master here | ||
public org.opensearch.action.support.master.AcknowledgedResponse deleteSnapshot(String repositoryName, String snapshotName) throws IOException { | ||
//CS-ENFORCE-ALL | ||
return snapshotClient.delete(new DeleteSnapshotRequest(repositoryName, snapshotName), DEFAULT); | ||
} | ||
|
||
public RestoreSnapshotResponse restoreSnapshot( | ||
String repositoryName, String snapshotName, String renamePattern, | ||
String renameReplacement) throws IOException { | ||
RestoreSnapshotRequest restoreSnapshotRequest = new RestoreSnapshotRequest(repositoryName, snapshotName) | ||
.renamePattern(renamePattern) | ||
.renameReplacement(renameReplacement); | ||
return snapshotClient.restore(restoreSnapshotRequest, DEFAULT); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/integrationTest/java/org/opensearch/security/Song.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
package org.opensearch.security; | ||
|
||
|
||
class Song { | ||
|
||
static final String FIELD_TITLE = "title"; | ||
static final String FIELD_ARTIST = "artist"; | ||
static final String FIELD_LYRICS = "lyrics"; | ||
|
||
static final String FIELD_STARS = "stars"; | ||
static final String ARTIST_FIRST = "First artist"; | ||
static final String ARTIST_STRING = "String"; | ||
static final String ARTIST_TWINS = "Twins"; | ||
static final String TITLE_MAGNUM_OPUS = "Magnum Opus"; | ||
static final String TITLE_SONG_1_PLUS_1 = "Song 1+1"; | ||
static final String TITLE_NEXT_SONG = "Next song"; | ||
static final String ARTIST_NO = "No!"; | ||
static final String TITLE_POISON = "Poison"; | ||
|
||
public static final String LYRICS_1 = "Very deep subject"; | ||
public static final String LYRICS_2 = "Once upon a time"; | ||
public static final String LYRICS_3 = "giant nonsense"; | ||
public static final String LYRICS_4 = "Much too much"; | ||
|
||
static final String QUERY_TITLE_NEXT_SONG = FIELD_TITLE + ":" + "\"" + TITLE_NEXT_SONG + "\""; | ||
static final String QUERY_TITLE_POISON = FIELD_TITLE + ":" + TITLE_POISON; | ||
static final String QUERY_TITLE_MAGNUM_OPUS = FIELD_TITLE + ":" + TITLE_MAGNUM_OPUS; | ||
|
||
static final Object[][] SONGS = { | ||
{FIELD_ARTIST, ARTIST_FIRST, FIELD_TITLE, TITLE_MAGNUM_OPUS ,FIELD_LYRICS, LYRICS_1, FIELD_STARS, 1}, | ||
{FIELD_ARTIST, ARTIST_STRING, FIELD_TITLE, TITLE_SONG_1_PLUS_1, FIELD_LYRICS, LYRICS_2, FIELD_STARS, 2}, | ||
{FIELD_ARTIST, ARTIST_TWINS, FIELD_TITLE, TITLE_NEXT_SONG, FIELD_LYRICS, LYRICS_3, FIELD_STARS, 3}, | ||
{FIELD_ARTIST, ARTIST_NO, FIELD_TITLE, TITLE_POISON, FIELD_LYRICS, LYRICS_4, FIELD_STARS, 4} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/integrationTest/java/org/opensearch/test/framework/cluster/SearchRequestFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
package org.opensearch.test.framework.cluster; | ||
|
||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.action.search.SearchScrollRequest; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.index.query.QueryBuilders; | ||
import org.opensearch.search.aggregations.AggregationBuilders; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
import org.opensearch.search.sort.FieldSortBuilder; | ||
import org.opensearch.search.sort.SortOrder; | ||
|
||
import static java.util.concurrent.TimeUnit.MINUTES; | ||
|
||
public class SearchRequestFactory { | ||
public static SearchRequest queryStringQueryRequest(String indexName, String queryString) { | ||
SearchRequest searchRequest = new SearchRequest(indexName); | ||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
searchSourceBuilder.query(QueryBuilders.queryStringQuery(queryString)); | ||
searchRequest.source(searchSourceBuilder); | ||
return searchRequest; | ||
} | ||
|
||
public static SearchRequest queryStringQueryRequest(String queryString) { | ||
SearchRequest searchRequest = new SearchRequest(); | ||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
searchSourceBuilder.query(QueryBuilders.queryStringQuery(queryString)); | ||
searchRequest.source(searchSourceBuilder); | ||
return searchRequest; | ||
} | ||
|
||
public static SearchRequest searchRequestWithScroll(String indexName, int pageSize) { | ||
SearchRequest searchRequest = new SearchRequest(indexName); | ||
searchRequest.scroll(new TimeValue(1, MINUTES)); | ||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
searchSourceBuilder.query(QueryBuilders.matchAllQuery()); | ||
searchSourceBuilder.sort(new FieldSortBuilder("_id").order(SortOrder.ASC)); | ||
searchSourceBuilder.size(pageSize); | ||
searchRequest.source(searchSourceBuilder); | ||
return searchRequest; | ||
} | ||
|
||
public static SearchScrollRequest getSearchScrollRequest(SearchResponse searchResponse) { | ||
SearchScrollRequest scrollRequest = new SearchScrollRequest(searchResponse.getScrollId()); | ||
scrollRequest.scroll(new TimeValue(1, MINUTES)); | ||
return scrollRequest; | ||
} | ||
|
||
public static SearchRequest averageAggregationRequest(String indexName, String aggregationName, String fieldName) { | ||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
searchSourceBuilder.aggregation(AggregationBuilders.avg(aggregationName).field(fieldName)); | ||
searchSourceBuilder.size(0); | ||
SearchRequest searchRequest = new SearchRequest(indexName); | ||
searchRequest.source(searchSourceBuilder); | ||
return searchRequest; | ||
} | ||
|
||
public static SearchRequest statsAggregationRequest(String indexName, String aggregationName, String fieldName) { | ||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
searchSourceBuilder.aggregation(AggregationBuilders.stats(aggregationName).field(fieldName)); | ||
searchSourceBuilder.size(0); | ||
SearchRequest searchRequest = new SearchRequest(indexName); | ||
searchRequest.source(searchSourceBuilder); | ||
return searchRequest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.