Skip to content

Commit

Permalink
Merge pull request #946 from rax-maas/centralize-es-mgmt
Browse files Browse the repository at this point in the history
migrate all ES tests to ES test server
  • Loading branch information
iWebi committed Sep 23, 2022
2 parents 998b496 + bd8f312 commit 2064d8f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 236 deletions.
8 changes: 0 additions & 8 deletions blueflood-elasticsearch/pom.xml
Expand Up @@ -57,14 +57,6 @@
</dependency>

<!-- testing dependencies -->
<dependency>
<groupId>com.github.tlrx</groupId>
<artifactId>elasticsearch-test</artifactId>
<version>1.2.1</version>
<scope>test</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
8 changes: 0 additions & 8 deletions blueflood-http/pom.xml
Expand Up @@ -84,14 +84,6 @@
<version>1.3.2</version>
</dependency>

<!-- testing dependencies -->
<dependency>
<groupId>com.github.tlrx</groupId>
<artifactId>elasticsearch-test</artifactId>
<version>1.2.1</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
</dependencies>

</project>
Expand Up @@ -19,7 +19,7 @@
import static com.rackspacecloud.blueflood.utils.TestUtils.*;
import static org.mockito.Mockito.spy;

import com.github.tlrx.elasticsearch.test.EsSetup;
import com.rackspacecloud.blueflood.utils.ElasticsearchTestServer;
import com.rackspacecloud.blueflood.io.IntegrationTestBase;
import com.rackspacecloud.blueflood.inputs.handlers.HttpEventsIngestionHandler;
import com.rackspacecloud.blueflood.inputs.handlers.HttpMetricsIngestionServer;
Expand Down Expand Up @@ -79,7 +79,6 @@ public class HttpIntegrationTestBase extends IntegrationTestBase {
protected static Map <String, String> parameterMap;
protected static ElasticIO elasticIO;
protected static EventsIO eventsSearchIO;
protected static EsSetup esSetup;

protected static String configAllowedOrigins = "test.domain1.com, test.domain2.com, test.domain3.com";
protected static String configAllowedHeaders = "XYZ, ABC";
Expand Down Expand Up @@ -135,10 +134,6 @@ public static void shutdown() throws IOException {
if (httpIngestionService != null) {
httpIngestionService.shutdownService();
}

if (esSetup != null) {
esSetup.terminate();
}
}

private static void setupElasticSearch() {
Expand All @@ -147,17 +142,9 @@ private static void setupElasticSearch() {
// setup config
System.setProperty(CoreConfig.DISCOVERY_MODULES.name(), "com.rackspacecloud.blueflood.io.ElasticIO");
System.setProperty(CoreConfig.EVENTS_MODULES.name(), "com.rackspacecloud.blueflood.io.EventElasticSearchIO");

// setup elasticsearch test clusters with blueflood mappings
esSetup = new EsSetup();
esSetup.execute(EsSetup.deleteAll());
esSetup.execute(EsSetup.createIndex(ElasticIO.ELASTICSEARCH_INDEX_NAME_WRITE)
.withSettings(EsSetup.fromClassPath("index_settings.json"))
.withMapping("metrics", EsSetup.fromClassPath("metrics_mapping.json")));
esSetup.execute(EsSetup.createIndex(EventElasticSearchIO.EVENT_INDEX)
.withSettings(EsSetup.fromClassPath("index_settings.json"))
.withMapping("graphite_event", EsSetup.fromClassPath("events_mapping.json")));

ElasticsearchTestServer.getInstance().ensureStarted();
ElasticsearchTestServer.getInstance().reset();
// create elaticsearch client and link it to ModuleLoader
elasticIO = new ElasticIO();
eventsSearchIO = new EventElasticSearchIO();
Expand Down
Expand Up @@ -17,7 +17,7 @@

import static org.mockito.Mockito.spy;

import com.github.tlrx.elasticsearch.test.EsSetup;
import com.rackspacecloud.blueflood.utils.ElasticsearchTestServer;
import com.rackspacecloud.blueflood.http.HttpClientVendor;
import com.rackspacecloud.blueflood.io.EventElasticSearchIO;
import com.rackspacecloud.blueflood.io.EventsIO;
Expand All @@ -41,7 +41,6 @@
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
Expand All @@ -66,7 +65,6 @@ public class HttpAnnotationsEndToEndIntegrationTest {
private static EventsIO eventsSearchIO;
private static HttpQueryService httpQueryService;
private final String tenant_id = "333333";
private static EsSetup esSetup;
//A time stamp 2 days ago
private final long baseMillis = Calendar.getInstance().getTimeInMillis() - 172800000;

Expand All @@ -79,11 +77,8 @@ public static void setUp() throws Exception {
manageShards.add(1); manageShards.add(5); manageShards.add(6);
context = spy(new ScheduleContext(System.currentTimeMillis(), manageShards));

esSetup = new EsSetup();
esSetup.execute(EsSetup.deleteAll());
esSetup.execute(EsSetup.createIndex(EventElasticSearchIO.EVENT_INDEX)
.withSettings(EsSetup.fromClassPath("index_settings.json"))
.withMapping("graphite_event", EsSetup.fromClassPath("events_mapping.json")));
ElasticsearchTestServer.getInstance().ensureStarted();
ElasticsearchTestServer.getInstance().reset();
eventsSearchIO = new EventElasticSearchIO();
HttpMetricsIngestionServer server = new HttpMetricsIngestionServer(context);
server.setHttpEventsIngestionHandler(new HttpEventsIngestionHandler(eventsSearchIO));
Expand Down Expand Up @@ -166,17 +161,6 @@ public static void tearDownClass() throws Exception{
Configuration.getInstance().setProperty(CoreConfig.EVENTS_MODULES.name(), "");
System.clearProperty(CoreConfig.EVENTS_MODULES.name());

URIBuilder builder = new URIBuilder().setScheme("http").setHost("127.0.0.1").setPort(9200).setPath("/events");
HttpDelete delete = new HttpDelete(builder.build());
HttpResponse response = client.execute(delete);
if(response.getStatusLine().getStatusCode() != 200)
{
System.out.println("Couldn't delete 'events' index after running tests.");
}
else {
System.out.println("Successfully deleted 'events' index after running tests.");
}

if (vendor != null) {
vendor.shutdown();
}
Expand Down
Expand Up @@ -17,11 +17,8 @@
import java.util.List;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.AfterClass;
import org.junit.Test;

/**
Expand Down Expand Up @@ -181,18 +178,4 @@ private void createAndInsertTestEvents(final String tenant, int eventCount) thro
private ErrorResponse getErrorResponse(HttpResponse response) throws IOException {
return new ObjectMapper().readValue(response.getEntity().getContent(), ErrorResponse.class);
}

@AfterClass
public static void tearDownClass() throws Exception{
URIBuilder builder = new URIBuilder().setScheme("http").setHost("127.0.0.1").setPort(9200).setPath("/events");
HttpDelete delete = new HttpDelete(builder.build());
HttpResponse response = client.execute(delete);
if(response.getStatusLine().getStatusCode() != 200)
{
System.out.println("Couldn't delete 'events' index after running tests.");
}
else {
System.out.println("Successfully deleted 'events' index after running tests.");
}
}
}
Expand Up @@ -20,7 +20,7 @@
import static com.rackspacecloud.blueflood.utils.TestUtils.*;
import static org.mockito.Mockito.spy;

import com.github.tlrx.elasticsearch.test.EsSetup;
import com.rackspacecloud.blueflood.utils.ElasticsearchTestServer;
import com.rackspacecloud.blueflood.http.HttpClientVendor;
import com.rackspacecloud.blueflood.io.EventElasticSearchIO;
import com.rackspacecloud.blueflood.io.EventsIO;
Expand Down Expand Up @@ -55,7 +55,6 @@ public class HttpMetricsIngestionServerShutdownIntegrationTest {
private static int httpPort;
private static ScheduleContext context;
private static EventsIO eventsSearchIO;
private static EsSetup esSetup;
//A time stamp 2 days ago
private final long baseMillis = Calendar.getInstance().getTimeInMillis() - 172800000;

Expand All @@ -68,11 +67,8 @@ public static void setUp() throws Exception{
manageShards.add(1); manageShards.add(5); manageShards.add(6);
context = spy(new ScheduleContext(System.currentTimeMillis(), manageShards));

esSetup = new EsSetup();
esSetup.execute(EsSetup.deleteAll());
esSetup.execute(EsSetup.createIndex(EventElasticSearchIO.EVENT_INDEX)
.withSettings(EsSetup.fromClassPath("index_settings.json"))
.withMapping("graphite_event", EsSetup.fromClassPath("events_mapping.json")));
ElasticsearchTestServer.getInstance().ensureStarted();
ElasticsearchTestServer.getInstance().reset();
eventsSearchIO = new EventElasticSearchIO();
server = new HttpMetricsIngestionServer(context);
server.setHttpEventsIngestionHandler(new HttpEventsIngestionHandler(eventsSearchIO));
Expand Down Expand Up @@ -132,13 +128,10 @@ private URIBuilder getMetricsURIBuilder() throws URISyntaxException {
public static void shutdown() {
Configuration.getInstance().setProperty(CoreConfig.EVENTS_MODULES.name(), "");
System.clearProperty(CoreConfig.EVENTS_MODULES.name());
if (esSetup != null) {
esSetup.terminate();
}

if (vendor != null) {
vendor.shutdown();
}
}

}
}
Expand Up @@ -16,18 +16,9 @@

package com.rackspacecloud.blueflood.io;

import com.github.tlrx.elasticsearch.test.EsSetup;
import com.rackspacecloud.blueflood.utils.ElasticsearchTestServer;
import com.rackspacecloud.blueflood.types.Event;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.nio.entity.NStringEntity;
import org.joda.time.DateTime;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -36,7 +27,6 @@

public class EventElasticSearchIOIntegrationTest {
private static EventElasticSearchIO searchIO;
private static EsSetup esSetup;

private static final String TENANT_1 = "tenant1";
private static final String TENANT_2 = "otheruser2";
Expand Down Expand Up @@ -126,11 +116,8 @@ public void testRangeOnlySearch() throws Exception {

@BeforeClass
public static void setup() throws Exception {
esSetup = new EsSetup();
esSetup.execute(EsSetup.deleteAll());
esSetup.execute(EsSetup
.createIndex(EventElasticSearchIO.EVENT_INDEX)
.withMapping(EventElasticSearchIO.ES_TYPE, EsSetup.fromClassPath("events_mapping.json")));
ElasticsearchTestServer.getInstance().ensureStarted();
ElasticsearchTestServer.getInstance().reset();
searchIO = new EventElasticSearchIO();

createTestEvents(TENANT_1, TENANT_1_EVENTS_NUM);
Expand Down Expand Up @@ -175,37 +162,4 @@ private static void createRangeEvents(String tenant, int eventCount, int stepInS
searchIO.insert(tenant, eventMap);
}
}

/*
Once done testing, delete all of the records of the given type and index.
NOTE: Don't delete the index or the type, because that messes up the ES settings.
*/
@AfterClass
public static void tearDownClass() throws Exception {
URIBuilder builder = new URIBuilder().setScheme("http")
.setHost("127.0.0.1").setPort(9200)
.setPath("/events/graphite_event/_query");

HttpEntityEnclosingRequestBase delete = new HttpEntityEnclosingRequestBase() {
@Override
public String getMethod() {
return "DELETE";
}
};
delete.setURI(builder.build());

String deletePayload = "{\"query\":{\"match_all\":{}}}";
HttpEntity entity = new NStringEntity(deletePayload, ContentType.APPLICATION_JSON);
delete.setEntity(entity);

HttpClient client = HttpClientBuilder.create().build();
HttpResponse response = client.execute(delete);
if(response.getStatusLine().getStatusCode() != 200)
{
System.out.println("Couldn't delete index after running tests.");
}
else {
System.out.println("Successfully deleted index after running tests.");
}
}
}
Expand Up @@ -20,20 +20,12 @@
import com.rackspacecloud.blueflood.types.Event;
import java.util.Calendar;
import java.util.HashMap;
import org.apache.http.HttpEntity;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.util.EntityUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand Down Expand Up @@ -168,37 +160,4 @@ private static void createAndInsertTestEvents(final String tenant, int eventCoun
eventsSearchIO.insert(tenant, event.toMap());
}
}

/*
Once done testing, delete all of the records of the given type and index.
NOTE: Don't delete the index or the type, because that messes up the ES settings.
*/
@AfterClass
public static void tearDownClass() throws Exception {
URIBuilder builder = new URIBuilder().setScheme("http")
.setHost("127.0.0.1").setPort(9200)
.setPath("/events/graphite_event/_query");

HttpEntityEnclosingRequestBase delete = new HttpEntityEnclosingRequestBase() {
@Override
public String getMethod() {
return "DELETE";
}
};
delete.setURI(builder.build());

String deletePayload = "{\"query\":{\"match_all\":{}}}";
HttpEntity entity = new NStringEntity(deletePayload, ContentType.APPLICATION_JSON);
delete.setEntity(entity);

HttpClient client = HttpClientBuilder.create().build();
HttpResponse response = client.execute(delete);
if(response.getStatusLine().getStatusCode() != 200)
{
System.out.println("Couldn't delete index after running tests.");
}
else {
System.out.println("Successfully deleted index after running tests.");
}
}
}

0 comments on commit 2064d8f

Please sign in to comment.