From 257e404767cf910a1f0658974949469d47fb55b0 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Mon, 18 Dec 2023 13:09:51 +0100
Subject: [PATCH] OZG-4453 adjust naming; create Bean for elasticsearch client

---
 .../ElasticsearchRemoteService.java           | 139 ------------------
 .../OzgCloudElasticsearchClient.java          |  61 ++++++++
 ...a => OzgCloudElasticsearchProperties.java} |   2 +-
 .../OzgCloudElasticsearchRemoteService.java   |  79 ++++++++++
 ...java => OzgCloudElasticsearchService.java} |   4 +-
 .../user/ElasticsearchReconciler.java         |   4 +-
 .../user/ElasticsearchSecretHelper.java       |   4 +-
 ...gCloudElasticsearchRemoteServiceTest.java} |  12 +-
 ... => OzgCloudElasticsearchServiceTest.java} |   8 +-
 ...2.java => OzgCloudElasticsearchTest2.java} |  88 +----------
 .../user/ElasticsearchReconcilerTest.java     |   4 +-
 .../user/ElasticsearchSecretBuilderTest.java  |   4 +-
 pom.xml                                       |   2 +-
 13 files changed, 166 insertions(+), 245 deletions(-)
 delete mode 100644 ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchRemoteService.java
 create mode 100644 ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchClient.java
 rename ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/{ElasticsearchProperties.java => OzgCloudElasticsearchProperties.java} (90%)
 create mode 100644 ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchRemoteService.java
 rename ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/{ElasticsearchServerService.java => OzgCloudElasticsearchService.java} (96%)
 rename ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/{ElasticSearchRemoteServiceTest.java => OzgCloudElasticsearchRemoteServiceTest.java} (83%)
 rename ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/{ElasticSearchServiceTest.java => OzgCloudElasticsearchServiceTest.java} (95%)
 rename ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/{ElasticSearchTest2.java => OzgCloudElasticsearchTest2.java} (51%)

diff --git a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchRemoteService.java b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchRemoteService.java
deleted file mode 100644
index af263ca..0000000
--- a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchRemoteService.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package de.ozgcloud.operator.common.elasticsearch;
-
-import java.io.IOException;
-import java.util.Objects;
-import java.util.logging.Level;
-
-import jakarta.annotation.PostConstruct;
-
-import org.apache.commons.collections.MapUtils;
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.elasticsearch.client.RestClient;
-import org.springframework.stereotype.Component;
-
-import co.elastic.clients.elasticsearch.ElasticsearchClient;
-import co.elastic.clients.elasticsearch._types.ElasticsearchException;
-import co.elastic.clients.elasticsearch.indices.ExistsRequest;
-import co.elastic.clients.elasticsearch.security.GetRoleRequest;
-import co.elastic.clients.elasticsearch.security.GetUserRequest;
-import co.elastic.clients.elasticsearch.security.PutRoleRequest;
-import co.elastic.clients.elasticsearch.security.PutUserRequest;
-import co.elastic.clients.json.jackson.JacksonJsonpMapper;
-import co.elastic.clients.transport.rest_client.RestClientTransport;
-import de.ozgcloud.operator.common.kubernetes.KubernetesService;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.java.Log;
-
-@Log
-@RequiredArgsConstructor
-@Component
-class ElasticsearchRemoteService {
-	
-	private final ElasticsearchProperties elasticSearchProperties;
-	
-	private final KubernetesService kubernetesService;
-	
-	private ElasticsearchClient client = null;
-	
-	//TOTHINK START: Als Bean umsetzen?/Kann man den Client eleganter erstellen?
-	@PostConstruct
-	private void initClient() {
-		if (Objects.isNull(client)) {
-			client = createClient(elasticSearchProperties.getSecretData(), getPassword());
-		}
-	}
-
-	ElasticsearchClient createClient(String userName, String password) {
-		var credentialsProvider = createCredentialsProvider(userName, password);
-        var restClient = buildRestClient(credentialsProvider);
-        var transport = createRestClientTransport(restClient);
-        return new ElasticsearchClient(transport);
-	}
-	
-	private BasicCredentialsProvider createCredentialsProvider(String userName, String password) {
-		var credentialsProvider = new BasicCredentialsProvider();
-        credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(userName, password));
-        return credentialsProvider;
-	}
-	
-	private RestClient buildRestClient(BasicCredentialsProvider credentialsProvider) {
-		return RestClient.builder(createHttpHost())
-				.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
-				.build();
-	}
-	
-	private HttpHost createHttpHost() {
-		return new HttpHost(elasticSearchProperties.getHost(), elasticSearchProperties.getPort());
-	}
-	
-	private RestClientTransport createRestClientTransport(RestClient restClient) {
-		return new RestClientTransport(restClient, new JacksonJsonpMapper());
-	}
-
-	String getPassword() {
-		var resource = kubernetesService.getSecretResource(elasticSearchProperties.getNamespace(), elasticSearchProperties.getSecretName());
-		var password = MapUtils.getString(resource.get().getStringData(), elasticSearchProperties.getSecretData());
-		return password;
-	}
-	//TOTHINK END
-	
-	public boolean existsIndex(String index) throws Exception {
-		try {
-			log.info("Exists index " + index + "...");
-			client = createClient(elasticSearchProperties.getSecretData(), getPassword());
-			var exists = client.indices().exists(ExistsRequest.of(builder -> builder.index(index))).value();
-			log.info("Exists index: " + exists);
-			return exists;
-		} catch (ElasticsearchException | IOException e) {
-			log.log(Level.SEVERE, "Error checking index '" + index + "': " + e);
-			throw e;
-		}
-	}
-	
-	public void createIndex(String indexName) throws Exception {
-		try {
-			log.info("Create index " + indexName + "...");
-			client = createClient(elasticSearchProperties.getSecretData(), getPassword());
-			client.indices().create(builder -> builder.index(indexName));
-			log.info("Create index successful.");
-		} catch(Exception e) {
-			log.log(Level.SEVERE, "Create index failed." + e);
-			throw e;
-		}
-	}
-	
-	public boolean existsSecurityRole(String roleName) throws Exception {
-		var role = client.security().getRole(GetRoleRequest.of(builder -> builder.name(roleName)));
-		return !role.result().isEmpty();                  
-	}
-	
-	public void createSecurityRole(PutRoleRequest request) throws Exception {
-		try {
-			log.info("Create SecurityRole " + request.name() + "...");
-			client.security().putRole(request);
-			log.info("Create SecurityRole successful.");
-		} catch(Exception e) {
-			log.log(Level.SEVERE, "Create SecurityRole failed." + e);
-			throw e;
-		}
-	}
-	
-	public boolean existsSecurityUser(String userName) throws Exception {
-		var user = client.security().getUser(GetUserRequest.of(builder -> builder.username(userName)));
-		return !user.result().isEmpty();       
-	}
-	
-	public void createSecurityUser(PutUserRequest request) throws Exception {
-		try {
-			log.info("Create SecurityUser " + request.username() + "...");
-			client.security().putUser(request);
-			log.info("Create SecurityUser successful.");
-		} catch(Exception e) {
-			log.log(Level.SEVERE, "Create SecurityUser failed." + e);
-			throw e;
-		}
-	}
-}
\ No newline at end of file
diff --git a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchClient.java b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchClient.java
new file mode 100644
index 0000000..de31f4b
--- /dev/null
+++ b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchClient.java
@@ -0,0 +1,61 @@
+package de.ozgcloud.operator.common.elasticsearch;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.http.HttpHost;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.elasticsearch.client.RestClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Scope;
+
+import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.json.jackson.JacksonJsonpMapper;
+import co.elastic.clients.transport.rest_client.RestClientTransport;
+import de.ozgcloud.operator.common.kubernetes.KubernetesService;
+
+@Configuration
+public class OzgCloudElasticsearchClient {
+
+	@Autowired
+	private KubernetesService kubernetesService;
+	@Autowired
+	private OzgCloudElasticsearchProperties elasticSearchProperties;
+
+	@Bean
+	@Scope("singleton")
+	ElasticsearchClient createElasticsearchClient() {
+		var credentialsProvider = createCredentialsProvider(elasticSearchProperties.getSecretData(), getPassword());
+		var restClient = buildRestClient(credentialsProvider);
+		var transport = createRestClientTransport(restClient);
+		return new ElasticsearchClient(transport);
+	}
+
+	private BasicCredentialsProvider createCredentialsProvider(String userName, String password) {
+		var credentialsProvider = new BasicCredentialsProvider();
+		credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
+		return credentialsProvider;
+	}
+
+	private RestClient buildRestClient(BasicCredentialsProvider credentialsProvider) {
+		return RestClient.builder(createHttpHost())
+				.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
+				.build();
+	}
+
+	private HttpHost createHttpHost() {
+		return new HttpHost(elasticSearchProperties.getHost(), elasticSearchProperties.getPort());
+	}
+
+	private RestClientTransport createRestClientTransport(RestClient restClient) {
+		return new RestClientTransport(restClient, new JacksonJsonpMapper());
+	}
+
+	String getPassword() {
+		var resource = kubernetesService.getSecretResource(elasticSearchProperties.getNamespace(), elasticSearchProperties.getSecretName());
+		var password = MapUtils.getString(resource.get().getStringData(), elasticSearchProperties.getSecretData());
+		return password;
+	}
+}
\ No newline at end of file
diff --git a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchProperties.java b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchProperties.java
similarity index 90%
rename from ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchProperties.java
rename to ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchProperties.java
index f3cdb0f..e758ef0 100644
--- a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchProperties.java
+++ b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchProperties.java
@@ -10,7 +10,7 @@ import lombok.Setter;
 @Setter
 @ConfigurationProperties("ozgcloud.elastic")
 @Configuration
-public class ElasticsearchProperties {
+public class OzgCloudElasticsearchProperties {
 
 	private String namespace;
 	private String secretName;
diff --git a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchRemoteService.java b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchRemoteService.java
new file mode 100644
index 0000000..1868fbe
--- /dev/null
+++ b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchRemoteService.java
@@ -0,0 +1,79 @@
+package de.ozgcloud.operator.common.elasticsearch;
+
+import java.io.IOException;
+import java.util.logging.Level;
+
+import org.springframework.stereotype.Component;
+
+import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.elasticsearch._types.ElasticsearchException;
+import co.elastic.clients.elasticsearch.indices.ExistsRequest;
+import co.elastic.clients.elasticsearch.security.GetRoleRequest;
+import co.elastic.clients.elasticsearch.security.GetUserRequest;
+import co.elastic.clients.elasticsearch.security.PutRoleRequest;
+import co.elastic.clients.elasticsearch.security.PutUserRequest;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.java.Log;
+
+@Log
+@RequiredArgsConstructor
+@Component
+class OzgCloudElasticsearchRemoteService {
+	
+	private final ElasticsearchClient client;
+	
+	public boolean existsIndex(String index) throws Exception {
+		try {
+			log.info("Exists index " + index + "...");
+			var exists = client.indices().exists(ExistsRequest.of(builder -> builder.index(index))).value();
+			log.info("Exists index: " + exists);
+			return exists;
+		} catch (ElasticsearchException | IOException e) {
+			log.log(Level.SEVERE, "Error checking index '" + index + "': " + e);
+			throw e;
+		}
+	}
+	
+	public void createIndex(String indexName) throws Exception {
+		try {
+			log.info("Create index " + indexName + "...");
+			client.indices().create(builder -> builder.index(indexName));
+			log.info("Create index successful.");
+		} catch(Exception e) {
+			log.log(Level.SEVERE, "Create index failed." + e);
+			throw e;
+		}
+	}
+	
+	public boolean existsSecurityRole(String roleName) throws Exception {
+		var role = client.security().getRole(GetRoleRequest.of(builder -> builder.name(roleName)));
+		return !role.result().isEmpty();                  
+	}
+	
+	public void createSecurityRole(PutRoleRequest request) throws Exception {
+		try {
+			log.info("Create SecurityRole " + request.name() + "...");
+			client.security().putRole(request);
+			log.info("Create SecurityRole successful.");
+		} catch(Exception e) {
+			log.log(Level.SEVERE, "Create SecurityRole failed." + e);
+			throw e;
+		}
+	}
+	
+	public boolean existsSecurityUser(String userName) throws Exception {
+		var user = client.security().getUser(GetUserRequest.of(builder -> builder.username(userName)));
+		return !user.result().isEmpty();       
+	}
+	
+	public void createSecurityUser(PutUserRequest request) throws Exception {
+		try {
+			log.info("Create SecurityUser " + request.username() + "...");
+			client.security().putUser(request);
+			log.info("Create SecurityUser successful.");
+		} catch(Exception e) {
+			log.log(Level.SEVERE, "Create SecurityUser failed." + e);
+			throw e;
+		}
+	}
+}
\ No newline at end of file
diff --git a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchServerService.java b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchService.java
similarity index 96%
rename from ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchServerService.java
rename to ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchService.java
index 2c12679..8b4730d 100644
--- a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/ElasticsearchServerService.java
+++ b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchService.java
@@ -11,11 +11,11 @@ import lombok.extern.java.Log;
 @Log
 @RequiredArgsConstructor
 @Component
-public class ElasticsearchServerService {
+public class OzgCloudElasticsearchService {
 	
 	static final String PRIVILEGES_ALL = "all";
 		
-	private final ElasticsearchRemoteService remoteService;
+	private final OzgCloudElasticsearchRemoteService remoteService;
 	
 //	curl -k -X PUT -u elastic:$ELASTICSEARCH_PASSWORD -H 'Content-Type: application/json' 'https://ozg-search-cluster-es-http:9200/'$ES_NS_USER
 	public void checkIndex(String namespace) throws Exception {
diff --git a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/user/ElasticsearchReconciler.java b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/user/ElasticsearchReconciler.java
index c269a38..cf7b008 100644
--- a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/user/ElasticsearchReconciler.java
+++ b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/user/ElasticsearchReconciler.java
@@ -5,7 +5,7 @@ import org.springframework.stereotype.Component;
 
 import de.ozgcloud.operator.CustomResourceStatus;
 import de.ozgcloud.operator.OperatorConfig;
-import de.ozgcloud.operator.common.elasticsearch.ElasticsearchServerService;
+import de.ozgcloud.operator.common.elasticsearch.OzgCloudElasticsearchService;
 import io.fabric8.kubernetes.api.model.Secret;
 import io.javaoperatorsdk.operator.api.reconciler.Context;
 import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
@@ -21,7 +21,7 @@ import lombok.extern.java.Log;
 public class ElasticsearchReconciler implements Reconciler<ElasticsearchCustomResource> {
 
 	private final ElasticsearchService service;
-	private final ElasticsearchServerService searchService;
+	private final OzgCloudElasticsearchService searchService;
 
 	@Override
 	public UpdateControl<ElasticsearchCustomResource> reconcile(ElasticsearchCustomResource resource, Context<ElasticsearchCustomResource> context) {
diff --git a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/user/ElasticsearchSecretHelper.java b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/user/ElasticsearchSecretHelper.java
index 3457807..a4c137e 100644
--- a/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/user/ElasticsearchSecretHelper.java
+++ b/ozgcloud-elastic-operator/src/main/java/de/ozgcloud/operator/user/ElasticsearchSecretHelper.java
@@ -3,7 +3,7 @@ package de.ozgcloud.operator.user;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.springframework.stereotype.Component;
 
-import de.ozgcloud.operator.common.elasticsearch.ElasticsearchProperties;
+import de.ozgcloud.operator.common.elasticsearch.OzgCloudElasticsearchProperties;
 import io.fabric8.kubernetes.api.model.ObjectMeta;
 import io.fabric8.kubernetes.api.model.Secret;
 import io.fabric8.kubernetes.api.model.SecretBuilder;
@@ -21,7 +21,7 @@ public class ElasticsearchSecretHelper {
 	
 	static final int PASSWORD_LENGTH = 15;
 	
-	private final ElasticsearchProperties properties;
+	private final OzgCloudElasticsearchProperties properties;
 
 	public Secret buildCredentialSecret(String namespace, String name) {
 		return new SecretBuilder()
diff --git a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchRemoteServiceTest.java b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchRemoteServiceTest.java
similarity index 83%
rename from ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchRemoteServiceTest.java
rename to ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchRemoteServiceTest.java
index 258b2c4..62c092c 100644
--- a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchRemoteServiceTest.java
+++ b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchRemoteServiceTest.java
@@ -17,13 +17,13 @@ import org.testcontainers.elasticsearch.ElasticsearchContainer;
 import de.ozgcloud.operator.common.kubernetes.KubernetesService;
 import lombok.SneakyThrows;
 
-class ElasticSearchRemoteServiceTest {
+class OzgCloudElasticsearchRemoteServiceTest {
 
 	@Spy
 	@InjectMocks
-	private ElasticsearchRemoteService service;
+	private OzgCloudElasticsearchRemoteService service;
 	@Mock
-	private ElasticsearchProperties elasticSearchProperties;
+	private OzgCloudElasticsearchProperties elasticSearchProperties;
 	@Mock
 	private KubernetesService kubernetesService;
 
@@ -42,9 +42,9 @@ class ElasticSearchRemoteServiceTest {
 			when(elasticSearchProperties.getHost()).thenReturn("localhost");
 			when(elasticSearchProperties.getPort()).thenReturn(9200);
 			when(elasticSearchProperties.getSecretData()).thenReturn(CONTAINER_NAME);
-			doReturn(CONTAINER_PASSWORD).when(service).getPassword();
+//			doReturn(CONTAINER_PASSWORD).when(service).getPassword();
 			
-			var client = service.createClient(CONTAINER_NAME, CONTAINER_PASSWORD);
+//			var client = service.createClient(CONTAINER_NAME, CONTAINER_PASSWORD);
 			
 			try (var container = createContainer()) {
 				container.getEnvMap().remove("xpack.security.enabled");
@@ -52,7 +52,7 @@ class ElasticSearchRemoteServiceTest {
 			    container.start();
 			    
 			    try {
-			    	client.indices().create(builder -> builder.index("test"));
+//			    	client.indices().create(builder -> builder.index("test"));
 			    } catch(Exception e) {
 			    	e.printStackTrace();
 			    }
diff --git a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchServiceTest.java b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchServiceTest.java
similarity index 95%
rename from ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchServiceTest.java
rename to ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchServiceTest.java
index 8cc4f7f..f44a9ba 100644
--- a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchServiceTest.java
+++ b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchServiceTest.java
@@ -16,13 +16,13 @@ import co.elastic.clients.elasticsearch.security.PutRoleRequest;
 import co.elastic.clients.elasticsearch.security.PutUserRequest;
 import lombok.SneakyThrows;
 
-class ElasticSearchServiceTest {
+class OzgCloudElasticsearchServiceTest {
 	
 	@Spy
 	@InjectMocks
-	private ElasticsearchServerService service;
+	private OzgCloudElasticsearchService service;
 	@Mock
-	private ElasticsearchRemoteService remoteService;
+	private OzgCloudElasticsearchRemoteService remoteService;
 
 	@DisplayName("Check index")
 	@Nested
@@ -105,7 +105,7 @@ class ElasticSearchServiceTest {
 				void shouldContainPrivileges() {
 					var request = service.createPutRoleRequest(NAMESPACE);
 					
-					assertThat(request.indices().get(0).privileges()).containsExactly(ElasticsearchServerService.PRIVILEGES_ALL);					
+					assertThat(request.indices().get(0).privileges()).containsExactly(OzgCloudElasticsearchService.PRIVILEGES_ALL);					
 				}
 			}
 		}
diff --git a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchTest2.java b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchTest2.java
similarity index 51%
rename from ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchTest2.java
rename to ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchTest2.java
index 0357956..ec3b764 100644
--- a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/ElasticSearchTest2.java
+++ b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/common/elasticsearch/OzgCloudElasticsearchTest2.java
@@ -20,7 +20,7 @@ import co.elastic.clients.json.jackson.JacksonJsonpMapper;
 import co.elastic.clients.transport.rest_client.RestClientTransport;
 import lombok.SneakyThrows;
 
-public class ElasticSearchTest2 {
+public class OzgCloudElasticsearchTest2 {
 
 	private static final String IMAGE_NAME = "docker.elastic.co/elasticsearch/elasticsearch:8.11.3";
 	private static final String USER = "elastic";
@@ -34,16 +34,6 @@ public class ElasticSearchTest2 {
 //			.waitingFor(Wait.forHttps("/").withStartupTimeout(Duration.of(2, ChronoUnit.MINUTES)))
 			.withStartupTimeout(Duration.of(2, ChronoUnit.MINUTES));
 
-//	private static final NodeSelector INGEST_NODE_SELECTOR = nodes -> {
-//		final Iterator<Node> iterator = nodes.iterator();
-//		while (iterator.hasNext()) {
-//			Node node = iterator.next();
-//			// roles may be null if we don't know, thus we keep the node in then...
-//			if (node.getRoles() != null && node.getRoles().isIngest() == false) {
-//				iterator.remove();
-//			}
-//		}
-//	};
 	private static final String INDEX_NAME = "test_index";
 	private static ElasticsearchClient client;
 	private static RestClient restClient;
@@ -86,23 +76,6 @@ public class ElasticSearchTest2 {
 		return new ElasticsearchClient(transport);
 	}
 
-//    @BeforeAll
-//    public static void startElasticsearchCreateCloudClient() {
-//        String cloudId = "";
-//        String user = "elastic";
-//        String password = "";
-//
-//        // basic auth, preemptive authentication
-//        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
-//        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
-//
-//        final RestClientBuilder builder = RestClient.builder(cloudId);
-//        builder.setHttpClientConfigCallback(b -> b.setDefaultCredentialsProvider(credentialsProvider));
-//
-//        client = new RestHighLevelClient(builder);
-//        productService = new ProductServiceImpl(INDEX, client);
-//    }
-
 	@DisplayName("Exists index")
 	@Nested
 	class TestExistsIndex {
@@ -131,65 +104,12 @@ public class ElasticSearchTest2 {
 	@SneakyThrows
 	@Test
 	void shouldCreateIndex() {
-		client.indices().create(builder -> builder.index("blubb"));
+		client.indices().create(builder -> builder.index(INDEX_NAME));
 	}
 
+	@SneakyThrows
 	@AfterAll
-	public static void closeResources() throws Exception {
+	public static void closeResources() {
 		restClient.close();
 	}
-
-
-//    @Test
-//    public void testClusterVersion() throws Exception {
-//        // this just exists to index some data, so the index deletion does not fail
-//        productService.save(createProducts(1));
-//
-//        final HealthResponse response = client.cluster().health();
-//        // check for yellow or green cluster health
-//        assertThat(response.status()).isNotEqualTo(HealthStatus.Red);
-//
-//        // TODO: add back one async health request request
-//        CountDownLatch latch = new CountDownLatch(1);
-//        asyncClient.cluster().health()
-//                .whenComplete((resp, throwable) -> {
-//                    assertThat(resp.status()).isNotEqualTo(HealthStatus.Red);
-//                    latch.countDown();
-//                });
-//        latch.await(10, TimeUnit.SECONDS);
-//    }
-
-//    @Test
-//    public void indexProductWithoutId() throws Exception {
-//        Product product = createProducts(1).get(0);
-//        product.setId(null);
-//        assertThat(product.getId()).isNull();
-//
-//        productService.save(product);
-//
-//        assertThat(product.getId()).isNotNull();
-//    }
-//
-//    @Test
-//    public void indexProductWithId() throws Exception {
-//        Product product = createProducts(1).get(0);
-//        assertThat(product.getId()).isEqualTo("0");
-//
-//        productService.save(product);
-//
-//        product = productService.findById("0");
-//        assertThat(product.getId()).isEqualTo("0");
-//    }
-
-//    @Test
-//    public void testFindProductById() throws Exception {
-//        productService.save(createProducts(3));
-//
-//        final Product product1 = productService.findById("0");
-//        assertThat(product1.getId()).isEqualTo("0");
-//        final Product product2 = productService.findById("1");
-//        assertThat(product2.getId()).isEqualTo("1");
-//        final Product product3 = productService.findById("2");
-//        assertThat(product3.getId()).isEqualTo("2");
-//    }
 }
\ No newline at end of file
diff --git a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/user/ElasticsearchReconcilerTest.java b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/user/ElasticsearchReconcilerTest.java
index 97cf7a1..df095e4 100644
--- a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/user/ElasticsearchReconcilerTest.java
+++ b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/user/ElasticsearchReconcilerTest.java
@@ -13,7 +13,7 @@ import org.mockito.Mock;
 import org.mockito.Spy;
 
 import de.ozgcloud.operator.CustomResourceStatus;
-import de.ozgcloud.operator.common.elasticsearch.ElasticsearchServerService;
+import de.ozgcloud.operator.common.elasticsearch.OzgCloudElasticsearchService;
 import de.ozgcloud.operator.common.kubernetes.NamespaceTestFactory;
 import de.ozgcloud.operator.common.kubernetes.SecretTestFactory;
 import io.fabric8.kubernetes.api.model.Secret;
@@ -29,7 +29,7 @@ class ElasticsearchReconcilerTest {
 	@Mock
 	private ElasticsearchService service;
 	@Mock
-	private ElasticsearchServerService searchService;
+	private OzgCloudElasticsearchService searchService;
 
 	@DisplayName("Reconcile")
 	@Nested
diff --git a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/user/ElasticsearchSecretBuilderTest.java b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/user/ElasticsearchSecretBuilderTest.java
index aa9e2d4..38b451c 100644
--- a/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/user/ElasticsearchSecretBuilderTest.java
+++ b/ozgcloud-elastic-operator/src/test/java/de/ozgcloud/operator/user/ElasticsearchSecretBuilderTest.java
@@ -11,7 +11,7 @@ import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.Spy;
 
-import de.ozgcloud.operator.common.elasticsearch.ElasticsearchProperties;
+import de.ozgcloud.operator.common.elasticsearch.OzgCloudElasticsearchProperties;
 import de.ozgcloud.operator.common.kubernetes.NamespaceTestFactory;
 import de.ozgcloud.operator.common.kubernetes.SecretTestFactory;
 import io.fabric8.kubernetes.api.model.Secret;
@@ -22,7 +22,7 @@ class ElasticsearchSecretBuilderTest {
 	@InjectMocks
 	private ElasticsearchSecretHelper builder;
 	@Mock
-	private ElasticsearchProperties properties;
+	private OzgCloudElasticsearchProperties properties;
 	
 	@DisplayName("Build credential secret")
 	@Nested
diff --git a/pom.xml b/pom.xml
index dffd81a..a1ebe49 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,7 @@
 
 	<modules>
 		<module>ozgcloud-keycloak-operator</module>
-		<module>ozgcloud-elastic-operator</module>
+		<module>ozgcloud-elasticsearch-operator</module>
 	</modules>
 
 	<properties>
-- 
GitLab