Skip to content
Snippets Groups Projects
Commit 8b5d02b4 authored by Alok Joshi's avatar Alok Joshi
Browse files

Merge branch 'index-delete' into 'master'

use index delete api for IT post clean-up

See merge request !307
parents abb0dec4 a8f04727
No related branches found
No related tags found
2 merge requests!346Merge branch 'aws-integration' into 'master',!307use index delete api for IT post clean-up
Pipeline #106590 failed
......@@ -53,7 +53,7 @@ public class RecordSteps extends TestsBase {
public void tearDown() {
for (String kind : inputIndexMap.keySet()) {
TestIndex testIndex = inputIndexMap.get(kind);
testIndex.cleanupIndex();
testIndex.cleanupIndex(kind);
testIndex.deleteSchema(kind);
}
......
......@@ -17,12 +17,11 @@ public class SchemaServiceRecordSteps extends RecordSteps {
public void the_schema_is_created_with_the_following_kind(DataTable dataTable) {
List<Setup> inputList = dataTable.asList(Setup.class);
inputList.forEach(this::createSchema);
inputList.forEach(s -> deleteIndex(generateActualNameWithoutTs(s.getIndex())));
inputList.forEach(this::setup);
super.addShutDownHook();
}
private void createSchema(Setup input) {
private void setup(Setup input) {
PersistentSchemaTestIndex testIndex = new PersistentSchemaTestIndex(super.elasticUtils, super.httpClient, this);
testIndex.setIndex(generateActualName(input.getIndex(), super.getTimeStamp()));
testIndex.setSchemaFile(input.getSchemaFile());
......@@ -31,10 +30,12 @@ public class SchemaServiceRecordSteps extends RecordSteps {
testIndex.setKind(testIndex.getSchemaModel().getSchemaInfo().getSchemaIdentity().getId());
super.getInputIndexMap().put(testIndex.getKind(), testIndex);
deleteIndex(testIndex.getKind());
}
private void deleteIndex(String index) {
this.elasticUtils.deleteIndex(index);
private void deleteIndex(String kind) {
this.indexerClientUtil.deleteIndex(kind);
}
@Override
......
......@@ -12,6 +12,7 @@ import org.opengroup.osdu.util.HTTPClient;
import com.sun.jersey.api.client.ClientResponse;
import cucumber.api.Scenario;
import lombok.extern.java.Log;
import org.opengroup.osdu.util.IndexerClientUtil;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
......@@ -28,6 +29,7 @@ public abstract class TestsBase {
protected Map<String, String> tenantMap = new HashMap<>();
protected Map<String, TestIndex> inputRecordMap = new HashMap<>();
protected ElasticUtils elasticUtils;
protected IndexerClientUtil indexerClientUtil;
public TestsBase(HTTPClient httpClient) {
this.httpClient = httpClient;
......@@ -36,6 +38,7 @@ public abstract class TestsBase {
tenantMap.put("common", "common");
elasticUtils = new ElasticUtils();
this.indexerClientUtil = new IndexerClientUtil(this.httpClient);
}
public TestsBase(HTTPClient httpClient, ElasticUtils elasticUtils) {
......@@ -45,6 +48,7 @@ public abstract class TestsBase {
tenantMap.put("common", "common");
this.elasticUtils = elasticUtils;
this.indexerClientUtil = new IndexerClientUtil(this.httpClient);
}
protected TestIndex getTextIndex(){
......@@ -94,7 +98,7 @@ public abstract class TestsBase {
public void tearDown() {
for (String kind : inputRecordMap.keySet()) {
TestIndex testIndex = inputRecordMap.get(kind);
testIndex.cleanupIndex();
testIndex.cleanupIndex(kind);
}
}
......
......@@ -13,6 +13,7 @@ import org.opengroup.osdu.core.common.model.legal.Legal;
import org.opengroup.osdu.util.ElasticUtils;
import org.opengroup.osdu.util.FileHandler;
import org.opengroup.osdu.util.HTTPClient;
import org.opengroup.osdu.util.IndexerClientUtil;
import java.util.HashSet;
import java.util.List;
......@@ -38,6 +39,7 @@ public class TestIndex {
private HTTPClient httpClient;
private Map<String, String> headers;
private ElasticUtils elasticUtils;
private IndexerClientUtil indexerClientUtil;
private Gson gson = new Gson();
public TestIndex(ElasticUtils elasticUtils){
......@@ -47,6 +49,7 @@ public class TestIndex {
public void setHttpClient(HTTPClient httpClient) {
this.httpClient = httpClient;
headers = httpClient.getCommonHeader();
this.indexerClientUtil = new IndexerClientUtil(this.httpClient);
}
public void setupIndex() {
......@@ -72,8 +75,8 @@ public class TestIndex {
this.elasticUtils.createIndex(this.index, this.getIndexMappingFromJson());
}
public void cleanupIndex() {
this.elasticUtils.deleteIndex(index);
public void cleanupIndex(String kind) {
this.indexerClientUtil.deleteIndex(kind);
}
private String getRecordFile() {
......
package org.opengroup.osdu.util;
import static org.opengroup.osdu.util.Config.getDataPartitionIdTenant1;
import static org.opengroup.osdu.util.Config.getIndexerBaseURL;
import com.google.gson.Gson;
import com.sun.jersey.api.client.ClientResponse;
import java.util.Map;
import javax.ws.rs.HttpMethod;
import lombok.extern.java.Log;
import org.opengroup.osdu.core.common.model.search.RecordChangedMessages;
import javax.ws.rs.HttpMethod;
import java.util.Map;
import static org.opengroup.osdu.util.Config.getIndexerBaseURL;
@Log
public class IndexerClientUtil {
private final String purgeMessage = "{\"data\":\"[{\\\"kind\\\":\\\"%s\\\",\\\"op\\\":\\\"purge_schema\\\"}]\",\"attributes\":{\"account-id\":\"%s\"}}";
private final HTTPClient httpClient;
private Map<String, String> headers;
......@@ -24,15 +20,9 @@ public class IndexerClientUtil {
}
public void deleteIndex(String kind) {
String url = getIndexerBaseURL() + "index-cleanup";
String url = getIndexerBaseURL() + "index?kind=" + kind;
log.info("URL: " + url);
ClientResponse response = httpClient.send(HttpMethod.POST, url, convertMessageIntoJson(kind), headers, httpClient.getAccessToken());
ClientResponse response = httpClient.send(HttpMethod.DELETE, url, "", headers, httpClient.getAccessToken());
log.info(response.toString());
}
private String convertMessageIntoJson(String kind) {
RecordChangedMessages
recordChangedMessages = (new Gson()).fromJson(String.format(purgeMessage, kind, getDataPartitionIdTenant1()), RecordChangedMessages.class);
return new Gson().toJson(recordChangedMessages);
}
}
......@@ -10,7 +10,6 @@ import lombok.extern.java.Log;
import org.opengroup.osdu.common.SchemaServiceRecordSteps;
import org.opengroup.osdu.util.ElasticUtils;
import org.opengroup.osdu.util.GCPHTTPClient;
import org.opengroup.osdu.util.GcpElasticUtils;
@Log
public class Steps extends SchemaServiceRecordSteps {
......@@ -23,7 +22,6 @@ public class Steps extends SchemaServiceRecordSteps {
public void before(Scenario scenario) {
this.scenario = scenario;
this.httpClient = new GCPHTTPClient();
this.elasticUtils = new GcpElasticUtils(this.httpClient);
}
@Given("^the schema is created with the following kind$")
......
package org.opengroup.osdu.util;
public class GcpElasticUtils extends ElasticUtils {
private IndexerClientUtil indexerClientUtil;
public GcpElasticUtils(HTTPClient httpClient) {
super();
this.indexerClientUtil = new IndexerClientUtil(httpClient);
}
@Override
public void deleteIndex(String index) {
indexerClientUtil.deleteIndex(convertIndexToKindName(index));
}
private String convertIndexToKindName(String index) {
return index.replaceAll("-",":");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment