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 af263cadf4ddba0364bb51b8b7c752f9703da458..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..de31f4bcd5afacd1c8fb40ccac30e46e186e483c --- /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 f3cdb0fe1e7a5b0fbbdc42e1334bffc03d99ad20..e758ef042d45c46e4fee049ccd7f6132493ddb33 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 0000000000000000000000000000000000000000..1868fbeb2a07d97477c0881f8ad74550dc66e9a5 --- /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 2c12679dd8934984696bde9355772338cd43ae5b..8b4730d09bb308fbd4873fe3008c0c69aa8cd583 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 c269a3845a377d04b662ad7b57848898f78e0cbe..cf7b0085235ab83dd26c515d4c0145c2f4fd6e4e 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 3457807a37c1da928f95ea2e37c1a3eeb508f35e..a4c137ea63a12948a87aa67027d86aa4f2839915 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 258b2c47160967c8c3d8f44c72eb891b5ce06626..62c092c1b6ec7c695896357a05c49c5d6dce0297 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 8cc4f7f4de4a720e60b44e0bb24b78c41288654a..f44a9baf96cdd0c6715fa274cfd9e2d61a1f7c68 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 0357956ac1676f5e01251476aeee460500c04289..ec3b7643461ac694a2c78f977d919a193fcf17c6 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 97cf7a171b80fdb31f1d6fa1caf4189b85e3d24d..df095e430a96e168c6ed6c56b2aa4da8d56bb2fe 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 aa9e2d4df53426f291685e76286d308336ab9a4a..38b451c2bee42b6168c0f255767ebe52a2f1c791 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 dffd81a2402f3b1236707ecf9f0271d4fb764910..a1ebe4949309025ebed0e22ba4c320a243eab55d 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>