]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18728 Remove ES User index
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Thu, 30 Mar 2023 07:25:13 +0000 (09:25 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 31 Mar 2023 20:03:27 +0000 (20:03 +0000)
28 files changed:
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-server-common/src/it/java/org/sonar/server/user/index/UserIndexIT.java [deleted file]
server/sonar-server-common/src/it/java/org/sonar/server/user/index/UserIndexerIT.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndex.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserQuery.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/user/index/package-info.java [deleted file]
server/sonar-server-common/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java [deleted file]
server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/EsTester.java
server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterCreateTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterReactivateTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/es/RecoveryIndexerTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/AnonymizeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/ChangePasswordActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/CreateActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/DeactivateActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/UpdateActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/UpdateIdentityProviderActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/UpdateLoginActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/AnonymizeAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/UserDeactivator.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java

index 797891e1d964585b9a340376f2cf6ecd6dbcda31..d9b984800831b52dd3c598c633a03a92a0cd0f23 100644 (file)
@@ -145,8 +145,6 @@ import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.setting.DatabaseSettingLoader;
 import org.sonar.server.setting.DatabaseSettingsEnabler;
 import org.sonar.server.setting.ThreadLocalSettings;
-import org.sonar.server.user.index.UserIndex;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.util.OkHttpClientProvider;
 import org.sonar.server.util.Paths2Impl;
 import org.sonar.server.view.index.ViewIndex;
@@ -381,9 +379,6 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
       MetricFinder.class,
       UnanalyzedLanguageMetrics.class,
 
-      UserIndexer.class,
-      UserIndex.class,
-
       // components,
       FavoriteUpdater.class,
       ProjectIndexersImpl.class,
diff --git a/server/sonar-server-common/src/it/java/org/sonar/server/user/index/UserIndexIT.java b/server/sonar-server-common/src/it/java/org/sonar/server/user/index/UserIndexIT.java
deleted file mode 100644 (file)
index e2d7afe..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.user.index;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.Uuids;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.SearchOptions;
-
-import static java.util.Arrays.asList;
-import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
-
-public class UserIndexIT {
-
-  private static final String USER1_LOGIN = "user1";
-  private static final String USER2_LOGIN = "user2";
-  private static final String USER3_LOGIN = "user3";
-
-  @Rule
-  public EsTester es = EsTester.create();
-
-  private UserIndex underTest = new UserIndex(es.client(), System2.INSTANCE);
-  private UserQuery.Builder userQuery = UserQuery.builder();
-
-  @Test
-  public void getAtMostThreeActiveUsersForScmAccount_returns_the_users_with_specified_scm_account() {
-    UserDoc user1 = newUser("user1", asList("user_1", "u1"));
-    UserDoc user2 = newUser("user_with_same_email_as_user1", asList("user_2")).setEmail(user1.email());
-    UserDoc user3 = newUser("inactive_user_with_same_scm_as_user1", user1.scmAccounts()).setActive(false);
-    es.putDocuments(TYPE_USER, user1);
-    es.putDocuments(TYPE_USER, user2);
-    es.putDocuments(TYPE_USER, user3);
-
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user1.scmAccounts().get(0))).extractingResultOf("login").containsOnly(user1.login());
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user1.login())).extractingResultOf("login").containsOnly(user1.login());
-
-    // both users share the same email
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user1.email())).extracting(UserDoc::login).containsOnly(user1.login(), user2.login());
-
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("")).isEmpty();
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("unknown")).isEmpty();
-  }
-
-  @Test
-  public void getAtMostThreeActiveUsersForScmAccount_ignores_inactive_user() {
-    String scmAccount = "scmA";
-    UserDoc user = newUser(USER1_LOGIN, singletonList(scmAccount)).setActive(false);
-    es.putDocuments(TYPE_USER, user);
-
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user.login())).isEmpty();
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(scmAccount)).isEmpty();
-  }
-
-  @Test
-  public void getAtMostThreeActiveUsersForScmAccount_returns_maximum_three_users() {
-    String email = "user@mail.com";
-    UserDoc user1 = newUser("user1", Collections.emptyList()).setEmail(email);
-    UserDoc user2 = newUser("user2", Collections.emptyList()).setEmail(email);
-    UserDoc user3 = newUser("user3", Collections.emptyList()).setEmail(email);
-    UserDoc user4 = newUser("user4", Collections.emptyList()).setEmail(email);
-    es.putDocuments(TYPE_USER, user1);
-    es.putDocuments(TYPE_USER, user2);
-    es.putDocuments(TYPE_USER, user3);
-    es.putDocuments(TYPE_USER, user4);
-
-    // restrict results to 3 users
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(email)).hasSize(3);
-  }
-
-  @Test
-  public void getAtMostThreeActiveUsersForScmAccount_is_case_sensitive_for_login() {
-    UserDoc user = newUser("the_login", singletonList("John.Smith"));
-    es.putDocuments(TYPE_USER, user);
-
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_login")).hasSize(1);
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_Login")).isEmpty();
-  }
-
-  @Test
-  public void getAtMostThreeActiveUsersForScmAccount_is_case_insensitive_for_email() {
-    UserDoc user = newUser("the_login", "the_EMAIL@corp.com", singletonList("John.Smith"));
-    es.putDocuments(TYPE_USER, user);
-
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_EMAIL@corp.com")).hasSize(1);
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_email@corp.com")).hasSize(1);
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("email")).isEmpty();
-  }
-
-  @Test
-  public void getAtMostThreeActiveUsersForScmAccount_is_case_insensitive_for_scm_account() {
-    UserDoc user = newUser("the_login", singletonList("John.Smith"));
-    es.putDocuments(TYPE_USER, user);
-
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("John.Smith")).hasSize(1);
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN.SMIth")).hasSize(1);
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN.SMITH")).hasSize(1);
-    assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN")).isEmpty();
-  }
-
-  @Test
-  public void searchUsers() {
-    es.putDocuments(TYPE_USER, newUser(USER1_LOGIN, asList("user_1", "u1")).setEmail("email1"));
-    es.putDocuments(TYPE_USER, newUser(USER2_LOGIN, Collections.emptyList()).setEmail("email2"));
-    es.putDocuments(TYPE_USER, newUser(USER3_LOGIN, Collections.emptyList()).setEmail("email3").setActive(false));
-
-    assertThat(underTest.search(userQuery.build(), new SearchOptions()).getDocs()).hasSize(2);
-    assertThat(underTest.search(userQuery.setTextQuery("user").build(), new SearchOptions()).getDocs()).hasSize(2);
-    assertThat(underTest.search(userQuery.setTextQuery("ser").build(), new SearchOptions()).getDocs()).hasSize(2);
-    assertThat(underTest.search(userQuery.setTextQuery(USER1_LOGIN).build(), new SearchOptions()).getDocs()).hasSize(1);
-    assertThat(underTest.search(userQuery.setTextQuery(USER2_LOGIN).build(), new SearchOptions()).getDocs()).hasSize(1);
-    assertThat(underTest.search(userQuery.setTextQuery("mail").build(), new SearchOptions()).getDocs()).hasSize(2);
-    assertThat(underTest.search(userQuery.setTextQuery("EMAIL1").build(), new SearchOptions()).getDocs()).hasSize(1);
-
-    // deactivated users
-    assertThat(underTest.search(userQuery.setActive(false).setTextQuery(null).build(), new SearchOptions()).getDocs()).hasSize(1);
-    assertThat(underTest.search(userQuery.setActive(false).setTextQuery("email3").build(), new SearchOptions()).getDocs()).hasSize(1);
-  }
-
-  private static UserDoc newUser(String login, List<String> scmAccounts) {
-    return new UserDoc()
-      .setUuid(Uuids.createFast())
-      .setLogin(login)
-      .setName(login.toUpperCase(Locale.ENGLISH))
-      .setEmail(login + "@mail.com")
-      .setActive(true)
-      .setScmAccounts(scmAccounts);
-  }
-
-  private static UserDoc newUser(String login, String email, List<String> scmAccounts) {
-    return new UserDoc()
-      .setUuid(Uuids.createFast())
-      .setLogin(login)
-      .setName(login.toUpperCase(Locale.ENGLISH))
-      .setEmail(email)
-      .setActive(true)
-      .setScmAccounts(scmAccounts);
-  }
-}
diff --git a/server/sonar-server-common/src/it/java/org/sonar/server/user/index/UserIndexerIT.java b/server/sonar-server-common/src/it/java/org/sonar/server/user/index/UserIndexerIT.java
deleted file mode 100644 (file)
index 69d809e..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.user.index;
-
-import java.util.HashSet;
-import java.util.List;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.es.EsTester;
-
-import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
-
-public class UserIndexerIT {
-
-  private final System2 system2 = System2.INSTANCE;
-
-  @Rule
-  public DbTester db = DbTester.create(system2);
-
-  @Rule
-  public EsTester es = EsTester.create();
-
-  private final UserIndexer underTest = new UserIndexer(db.getDbClient(), es.client());
-
-  @Test
-  public void index_nothing_on_startup() {
-    underTest.indexOnStartup(new HashSet<>());
-
-    assertThat(es.countDocuments(TYPE_USER)).isZero();
-  }
-
-  @Test
-  public void indexOnStartup_adds_all_users_to_index() {
-    UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("user_1", "u1")));
-
-    underTest.indexOnStartup(new HashSet<>());
-
-    List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
-    assertThat(docs).hasSize(1);
-    UserDoc doc = docs.get(0);
-    assertThat(doc.uuid()).isEqualTo(user.getUuid());
-    assertThat(doc.login()).isEqualTo(user.getLogin());
-    assertThat(doc.name()).isEqualTo(user.getName());
-    assertThat(doc.email()).isEqualTo(user.getEmail());
-    assertThat(doc.active()).isEqualTo(user.isActive());
-    assertThat(doc.scmAccounts()).isEqualTo(user.getSortedScmAccounts());
-  }
-
-  @Test
-  public void indexAll_adds_all_users_to_index() {
-    UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("user_1", "u1")));
-
-    underTest.indexAll();
-
-    List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
-    assertThat(docs).hasSize(1);
-    UserDoc doc = docs.get(0);
-    assertThat(doc.uuid()).isEqualTo(user.getUuid());
-    assertThat(doc.login()).isEqualTo(user.getLogin());
-    assertThat(doc.name()).isEqualTo(user.getName());
-    assertThat(doc.email()).isEqualTo(user.getEmail());
-    assertThat(doc.active()).isEqualTo(user.isActive());
-    assertThat(doc.scmAccounts()).isEqualTo(user.getSortedScmAccounts());
-  }
-
-  @Test
-  public void indexOnStartup_adds_all_users() {
-    UserDto user = db.users().insertUser();
-
-    underTest.indexOnStartup(new HashSet<>());
-
-    List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
-    assertThat(docs).hasSize(1);
-    UserDoc doc = docs.get(0);
-    assertThat(doc.uuid()).isEqualTo(user.getUuid());
-    assertThat(doc.login()).isEqualTo(user.getLogin());
-  }
-
-  @Test
-  public void commitAndIndex_single_user() {
-    UserDto user = db.users().insertUser();
-    UserDto anotherUser = db.users().insertUser();
-
-    underTest.commitAndIndex(db.getSession(), user);
-
-    List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
-    assertThat(docs)
-      .extracting(UserDoc::uuid)
-      .containsExactlyInAnyOrder(user.getUuid())
-      .doesNotContain(anotherUser.getUuid());
-  }
-
-  @Test
-  public void commitAndIndex_multiple_users() {
-    UserDto user1 = db.users().insertUser();
-    UserDto user2 = db.users().insertUser();
-
-    underTest.commitAndIndex(db.getSession(), asList(user1, user2));
-
-    List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
-    assertThat(docs)
-      .extracting(UserDoc::login)
-      .containsExactlyInAnyOrder(
-        user1.getLogin(),
-        user2.getLogin());
-    assertThat(db.countRowsOfTable(db.getSession(), "users")).isEqualTo(2);
-  }
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java
deleted file mode 100644 (file)
index ff8d032..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.user.index;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.server.es.BaseDoc;
-
-import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
-
-public class UserDoc extends BaseDoc {
-
-  public UserDoc(Map<String, Object> fields) {
-    super(TYPE_USER, fields);
-  }
-
-  public UserDoc() {
-    this(new HashMap<>());
-  }
-
-  @Override
-  public String getId() {
-    return uuid();
-  }
-
-  public String uuid() {
-    return getField(UserIndexDefinition.FIELD_UUID);
-  }
-
-  public String login() {
-    return getField(UserIndexDefinition.FIELD_LOGIN);
-  }
-
-  public String name() {
-    return getField(UserIndexDefinition.FIELD_NAME);
-  }
-
-  @Nullable
-  public String email() {
-    return getNullableField(UserIndexDefinition.FIELD_EMAIL);
-  }
-
-  public boolean active() {
-    return getField(UserIndexDefinition.FIELD_ACTIVE);
-  }
-
-  public List<String> scmAccounts() {
-    return getField(UserIndexDefinition.FIELD_SCM_ACCOUNTS);
-  }
-
-  public UserDoc setUuid(@Nullable String s) {
-    setField(UserIndexDefinition.FIELD_UUID, s);
-    return this;
-  }
-
-  public UserDoc setLogin(@Nullable String s) {
-    setField(UserIndexDefinition.FIELD_LOGIN, s);
-    return this;
-  }
-
-  public UserDoc setName(@Nullable String s) {
-    setField(UserIndexDefinition.FIELD_NAME, s);
-    return this;
-  }
-
-  public UserDoc setEmail(@Nullable String s) {
-    setField(UserIndexDefinition.FIELD_EMAIL, s);
-    return this;
-  }
-
-  public UserDoc setActive(boolean b) {
-    setField(UserIndexDefinition.FIELD_ACTIVE, b);
-    return this;
-  }
-
-  public UserDoc setScmAccounts(@Nullable List<String> s) {
-    setField(UserIndexDefinition.FIELD_SCM_ACCOUNTS, s);
-    return this;
-  }
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndex.java
deleted file mode 100644 (file)
index 4592822..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.user.index;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.search.SearchRequest;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.Operator;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.SearchHit;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.elasticsearch.search.sort.SortOrder;
-import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.System2;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.SearchOptions;
-import org.sonar.server.es.SearchResult;
-
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
-import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
-import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termQuery;
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.USER_SEARCH_GRAMS_ANALYZER;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_ACTIVE;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_EMAIL;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_LOGIN;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_NAME;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_SCM_ACCOUNTS;
-
-@ServerSide
-@ComputeEngineSide
-public class UserIndex {
-
-  private final EsClient esClient;
-  private final System2 system2;
-
-  public UserIndex(EsClient esClient, System2 system2) {
-    this.esClient = esClient;
-    this.system2 = system2;
-  }
-
-  /**
-   * Returns the active users (at most 3) who are associated to the given SCM account. This method can be used
-   * to detect user conflicts.
-   */
-  public List<UserDoc> getAtMostThreeActiveUsersForScmAccount(String scmAccount) {
-    List<UserDoc> result = new ArrayList<>();
-    if (!StringUtils.isEmpty(scmAccount)) {
-      SearchResponse response = esClient.search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
-        .source(new SearchSourceBuilder()
-          .query(boolQuery().must(matchAllQuery()).filter(
-            boolQuery()
-              .must(termQuery(FIELD_ACTIVE, true))
-              .should(termQuery(FIELD_LOGIN, scmAccount))
-              .should(matchQuery(SORTABLE_ANALYZER.subField(FIELD_EMAIL), scmAccount))
-              .should(matchQuery(SORTABLE_ANALYZER.subField(FIELD_SCM_ACCOUNTS), scmAccount))
-              .minimumShouldMatch(1)))
-          .size(3)));
-      for (SearchHit hit : response.getHits().getHits()) {
-        result.add(new UserDoc(hit.getSourceAsMap()));
-      }
-    }
-    return result;
-  }
-
-  public SearchResult<UserDoc> search(UserQuery userQuery, SearchOptions options) {
-    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
-      .size(options.getLimit())
-      .from(options.getOffset())
-      .sort(FIELD_NAME, SortOrder.ASC);
-
-    BoolQueryBuilder filter = boolQuery().must(termQuery(FIELD_ACTIVE, userQuery.isActive()));
-    QueryBuilder esQuery = matchAllQuery();
-    Optional<String> textQuery = userQuery.getTextQuery();
-    if (textQuery.isPresent()) {
-      esQuery = QueryBuilders.multiMatchQuery(textQuery.get(),
-        FIELD_LOGIN,
-        USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_LOGIN),
-        FIELD_NAME,
-        USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_NAME),
-        FIELD_EMAIL,
-        USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_EMAIL))
-        .operator(Operator.AND);
-    }
-
-    SearchRequest request = EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
-      .source(searchSourceBuilder.query(boolQuery().must(esQuery).filter(filter)));
-    return new SearchResult<>(esClient.search(request), UserDoc::new, system2.getDefaultTimeZone().toZoneId());
-  }
-
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java
deleted file mode 100644 (file)
index b2c1788..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.user.index;
-
-import org.sonar.api.config.Configuration;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.server.es.Index;
-import org.sonar.server.es.IndexDefinition;
-import org.sonar.server.es.IndexType;
-import org.sonar.server.es.IndexType.IndexMainType;
-import org.sonar.server.es.newindex.NewRegularIndex;
-import org.sonar.server.es.newindex.TypeMapping;
-
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.USER_SEARCH_GRAMS_ANALYZER;
-import static org.sonar.server.es.newindex.SettingsConfiguration.newBuilder;
-
-/**
- * Definition of ES index "users", including settings and fields.
- */
-public class UserIndexDefinition implements IndexDefinition {
-
-  public static final Index DESCRIPTOR = Index.simple("users");
-  public static final IndexMainType TYPE_USER = IndexType.main(DESCRIPTOR, "user");
-  public static final String FIELD_UUID = "uuid";
-  public static final String FIELD_LOGIN = "login";
-  public static final String FIELD_NAME = "name";
-  public static final String FIELD_EMAIL = "email";
-  public static final String FIELD_ACTIVE = "active";
-  public static final String FIELD_SCM_ACCOUNTS = "scmAccounts";
-
-  private final Configuration config;
-
-  public UserIndexDefinition(Configuration config) {
-    this.config = config;
-  }
-
-  public static UserIndexDefinition createForTest() {
-    return new UserIndexDefinition(new MapSettings().asConfig());
-  }
-
-  @Override
-  public void define(IndexDefinitionContext context) {
-    NewRegularIndex index = context.create(
-      DESCRIPTOR,
-      newBuilder(config)
-        .setDefaultNbOfShards(1)
-        .build())
-      // all information is retrieved from the index, not only IDs
-      .setEnableSource(true);
-
-    TypeMapping mapping = index.createTypeMapping(TYPE_USER);
-    mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
-    mapping.keywordFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
-    mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
-    mapping.keywordFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build();
-    mapping.createBooleanField(FIELD_ACTIVE);
-    mapping.keywordFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
-  }
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java
deleted file mode 100644 (file)
index 41142f7..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.user.index;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import org.elasticsearch.action.index.IndexRequest;
-import org.sonar.core.util.stream.MoreCollectors;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.es.EsQueueDto;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.es.BulkIndexer;
-import org.sonar.server.es.BulkIndexer.Size;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.IndexType;
-import org.sonar.server.es.IndexingListener;
-import org.sonar.server.es.IndexingResult;
-import org.sonar.server.es.OneToOneResilientIndexingListener;
-import org.sonar.server.es.ResilientIndexer;
-
-import static java.util.Collections.singletonList;
-import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
-import static org.sonar.core.util.stream.MoreCollectors.toList;
-import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
-
-public class UserIndexer implements ResilientIndexer {
-  private final DbClient dbClient;
-  private final EsClient esClient;
-
-  public UserIndexer(DbClient dbClient, EsClient esClient) {
-    this.dbClient = dbClient;
-    this.esClient = esClient;
-  }
-
-  @Override
-  public Set<IndexType> getIndexTypes() {
-    return ImmutableSet.of(TYPE_USER);
-  }
-
-  @Override
-  public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) {
-    indexAll(Size.LARGE);
-  }
-
-  public void indexAll() {
-    indexAll(Size.REGULAR);
-  }
-
-  private void indexAll(Size bulkSize) {
-    try (DbSession dbSession = dbClient.openSession(false)) {
-      BulkIndexer bulkIndexer = newBulkIndexer(bulkSize, IndexingListener.FAIL_ON_ERROR);
-      bulkIndexer.start();
-
-      dbClient.userDao().scrollAll(dbSession,
-        // only index requests, no deletion requests.
-        // Deactivated users are not deleted but updated.
-        u -> bulkIndexer.add(newIndexRequest(u)));
-      bulkIndexer.stop();
-    }
-  }
-
-  public void commitAndIndex(DbSession dbSession, UserDto user) {
-    commitAndIndex(dbSession, singletonList(user));
-  }
-
-  public void commitAndIndex(DbSession dbSession, Collection<UserDto> users) {
-    List<String> uuids = users.stream().map(UserDto::getUuid).collect(toList());
-    List<EsQueueDto> items = uuids.stream()
-      .map(uuid -> EsQueueDto.create(TYPE_USER.format(), uuid))
-      .collect(MoreCollectors.toArrayList());
-
-    dbClient.esQueueDao().insert(dbSession, items);
-    dbSession.commit();
-    postCommit(dbSession, users.stream().map(UserDto::getLogin).collect(toList()), items);
-  }
-
-  /**
-   * Entry point for Byteman tests. See directory tests/resilience.
-   * The parameter "logins" is used only by the Byteman script.
-   */
-  private void postCommit(DbSession dbSession, Collection<String> logins, Collection<EsQueueDto> items) {
-    index(dbSession, items);
-  }
-
-  /**
-   * @return the number of items that have been successfully indexed
-   */
-  @Override
-  public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
-    if (items.isEmpty()) {
-      return new IndexingResult();
-    }
-    Set<String> uuids = items
-      .stream()
-      .map(EsQueueDto::getDocId)
-      .collect(toHashSet(items.size()));
-
-    BulkIndexer bulkIndexer = newBulkIndexer(Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items));
-    bulkIndexer.start();
-
-    dbClient.userDao().scrollByUuids(dbSession, uuids,
-      // only index requests, no deletion requests.
-      // Deactivated users are not deleted but updated.
-      u -> {
-        uuids.remove(u.getUuid());
-        bulkIndexer.add(newIndexRequest(u));
-      });
-
-    // the remaining uuids reference rows that don't exist in db. They must
-    // be deleted from index.
-    uuids.forEach(uuid -> bulkIndexer.addDeletion(TYPE_USER, uuid));
-    return bulkIndexer.stop();
-  }
-
-  private BulkIndexer newBulkIndexer(Size bulkSize, IndexingListener listener) {
-    return new BulkIndexer(esClient, TYPE_USER, bulkSize, listener);
-  }
-
-  private static IndexRequest newIndexRequest(UserDto user) {
-    UserDoc doc = new UserDoc(Maps.newHashMapWithExpectedSize(8));
-    // all the keys must be present, even if value is null
-    doc.setUuid(user.getUuid());
-    doc.setLogin(user.getLogin());
-    doc.setName(user.getName());
-    doc.setEmail(user.getEmail());
-    doc.setActive(user.isActive());
-    doc.setScmAccounts(user.getSortedScmAccounts());
-
-    return doc.toIndexRequest();
-  }
-
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserQuery.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserQuery.java
deleted file mode 100644 (file)
index 6bdc696..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.user.index;
-
-import java.util.Optional;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.Immutable;
-
-import static org.apache.commons.lang.StringUtils.isBlank;
-
-@Immutable
-public class UserQuery {
-  private final String textQuery;
-  private final boolean active;
-
-  private UserQuery(Builder builder) {
-    this.textQuery = builder.textQuery;
-    this.active = builder.active;
-  }
-
-  public Optional<String> getTextQuery() {
-    return Optional.ofNullable(textQuery);
-  }
-
-  public boolean isActive() {
-    return active;
-  }
-
-  public static Builder builder() {
-    return new Builder();
-  }
-
-  public static class Builder {
-    private String textQuery;
-    private boolean active = true;
-
-    private Builder() {
-      // enforce factory method
-    }
-
-    public UserQuery build() {
-      return new UserQuery(this);
-    }
-
-    public Builder setTextQuery(@Nullable String textQuery) {
-      this.textQuery = isBlank(textQuery) ? null : textQuery;
-      return this;
-    }
-
-    public Builder setActive(boolean active) {
-      this.active = active;
-      return this;
-    }
-  }
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/package-info.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/package-info.java
deleted file mode 100644 (file)
index 399c314..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.user.index;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java
deleted file mode 100644 (file)
index 3480219..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.user.index;
-
-import org.junit.Test;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.server.es.Index;
-import org.sonar.server.es.IndexDefinition;
-import org.sonar.server.es.IndexType;
-import org.sonar.server.es.newindex.NewIndex;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class UserIndexDefinitionTest {
-
-  private IndexDefinition.IndexDefinitionContext underTest = new IndexDefinition.IndexDefinitionContext();
-
-  @Test
-  public void define() {
-    UserIndexDefinition def = new UserIndexDefinition(new MapSettings().asConfig());
-    def.define(underTest);
-
-    assertThat(underTest.getIndices()).hasSize(1);
-    NewIndex index = underTest.getIndices().get("users");
-    assertThat(index.getMainType())
-      .isEqualTo(IndexType.main(Index.simple("users"), "user"));
-    assertThat(index.getRelationsStream()).isEmpty();
-
-    // no cluster by default
-    assertThat(index.getSetting("index.number_of_shards")).isEqualTo("1");
-    assertThat(index.getSetting("index.number_of_replicas")).isEqualTo("0");
-  }
-}
index 90a64349095d93b2e3165c57db8933b56337fe15..5b304813d719071bfafb44c64a12eb52618cf9f4 100644 (file)
@@ -96,7 +96,6 @@ import org.sonar.server.es.newindex.NewIndex;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.measure.index.ProjectMeasuresIndexDefinition;
 import org.sonar.server.rule.index.RuleIndexDefinition;
-import org.sonar.server.user.index.UserIndexDefinition;
 import org.sonar.server.view.index.ViewIndexDefinition;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -152,7 +151,6 @@ public class EsTester extends ExternalResource {
         IssueIndexDefinition.createForTest(),
         ProjectMeasuresIndexDefinition.createForTest(),
         RuleIndexDefinition.createForTest(),
-        UserIndexDefinition.createForTest(),
         ViewIndexDefinition.createForTest());
 
       CORE_INDICES_CREATED.set(true);
index 366e681e201c56b5d398e2652e0add82329351c4..8b062afa65690d23641c91dcd4c98d2e4bd3dd7e 100644 (file)
@@ -27,7 +27,6 @@ import java.util.List;
 import java.util.Objects;
 import java.util.function.Consumer;
 import java.util.regex.Pattern;
-import java.util.stream.Stream;
 import javax.annotation.Nullable;
 import javax.inject.Inject;
 import org.apache.commons.lang.math.RandomUtils;
@@ -42,7 +41,6 @@ import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.db.user.UserGroupDto;
 import org.sonar.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 import org.sonar.server.util.Validation;
 
@@ -50,9 +48,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Strings.isNullOrEmpty;
 import static com.google.common.collect.Lists.newArrayList;
 import static java.lang.String.format;
-import static java.util.Arrays.stream;
 import static java.util.Collections.emptyList;
-import static java.util.stream.Stream.concat;
 import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE;
 import static org.sonar.core.util.Slug.slugify;
 import static org.sonar.core.util.stream.MoreCollectors.toList;
@@ -77,17 +73,15 @@ public class UserUpdater {
 
   private final NewUserNotifier newUserNotifier;
   private final DbClient dbClient;
-  private final UserIndexer userIndexer;
   private final DefaultGroupFinder defaultGroupFinder;
   private final AuditPersister auditPersister;
   private final CredentialsLocalAuthentication localAuthentication;
 
   @Inject
-  public UserUpdater(NewUserNotifier newUserNotifier, DbClient dbClient, UserIndexer userIndexer, DefaultGroupFinder defaultGroupFinder, Configuration config,
+  public UserUpdater(NewUserNotifier newUserNotifier, DbClient dbClient, DefaultGroupFinder defaultGroupFinder, Configuration config,
     AuditPersister auditPersister, CredentialsLocalAuthentication localAuthentication) {
     this.newUserNotifier = newUserNotifier;
     this.dbClient = dbClient;
-    this.userIndexer = userIndexer;
     this.defaultGroupFinder = defaultGroupFinder;
     this.auditPersister = auditPersister;
     this.localAuthentication = localAuthentication;
@@ -138,7 +132,7 @@ public class UserUpdater {
 
   private UserDto commitUser(DbSession dbSession, UserDto userDto, Consumer<UserDto> beforeCommit, UserDto... otherUsersToIndex) {
     beforeCommit.accept(userDto);
-    userIndexer.commitAndIndex(dbSession, concat(Stream.of(userDto), stream(otherUsersToIndex)).collect(toList()));
+    dbSession.commit();
     notifyNewUser(userDto.getLogin(), userDto.getName(), userDto.getEmail());
     return userDto;
   }
index 4e8a3d82facd9376cc1d309722bebd3b1beea406..0e1975a2f4dad13075031f9cb1f892de8e39058c 100644 (file)
@@ -44,7 +44,6 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.management.ManagedInstanceService;
 import org.sonar.server.user.NewUserNotifier;
 import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 
 import static java.util.Arrays.stream;
@@ -93,11 +92,9 @@ public class HttpHeadersAuthenticationTest {
   private final System2 system2 = mock(System2.class);
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
 
-  private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
-
   private final DefaultGroupFinder defaultGroupFinder = new DefaultGroupFinder(db.getDbClient());
   private final UserRegistrarImpl userIdentityAuthenticator = new UserRegistrarImpl(db.getDbClient(),
-    new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, defaultGroupFinder, settings.asConfig(), mock(AuditPersister.class), localAuthentication),
+    new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), defaultGroupFinder, settings.asConfig(), mock(AuditPersister.class), localAuthentication),
     defaultGroupFinder, mock(ManagedInstanceService.class));
   private final HttpServletResponse response = mock(HttpServletResponse.class);
   private final JwtHttpHandler jwtHttpHandler = mock(JwtHttpHandler.class);
index 070f9a6b33088d1d701f8efe411d66d004119438..ef0bc0b076cabe8aece6b4e9b44678b610e814bc 100644 (file)
@@ -42,7 +42,6 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.management.ManagedInstanceService;
 import org.sonar.server.user.NewUserNotifier;
 import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 
 import static java.util.Arrays.stream;
@@ -86,12 +85,11 @@ public class UserRegistrarImplTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
   private final DefaultGroupFinder groupFinder = new DefaultGroupFinder(db.getDbClient());
   private final AuditPersister auditPersister = mock(AuditPersister.class);
   private final ManagedInstanceService managedInstanceService = mock(ManagedInstanceService.class);
-  private final UserUpdater userUpdater = new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, groupFinder, settings.asConfig(), auditPersister, localAuthentication);
+  private final UserUpdater userUpdater = new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), groupFinder, settings.asConfig(), auditPersister, localAuthentication);
 
   private final UserRegistrarImpl underTest = new UserRegistrarImpl(db.getDbClient(), userUpdater, groupFinder, managedInstanceService);
   private GroupDto defaultGroup;
index 059bd7eee3002d911f0d018a1c0e31979648cbfc..6b90010163f34b8223e1cdf5df6e753f57b0b856 100644 (file)
@@ -25,7 +25,6 @@ import com.tngtech.java.junit.dataprovider.DataProvider;
 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.util.List;
-import org.elasticsearch.search.SearchHit;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -43,8 +42,6 @@ import org.sonar.server.authentication.CredentialsLocalAuthentication;
 import org.sonar.server.authentication.CredentialsLocalAuthentication.HashMethod;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 
 import static java.util.Arrays.asList;
@@ -52,7 +49,6 @@ import static java.util.Collections.singletonList;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.data.MapEntry.entry;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
@@ -76,10 +72,9 @@ public class UserUpdaterCreateTest {
   private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
   private final ArgumentCaptor<NewUserHandler.Context> newUserHandler = ArgumentCaptor.forClass(NewUserHandler.Context.class);
   private final DbSession session = db.getSession();
-  private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private final MapSettings settings = new MapSettings().setProperty("sonar.internal.pbkdf2.iterations", "1");
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
-  private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
+  private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient,
     new DefaultGroupFinder(dbClient), settings.asConfig(), null, localAuthentication);
 
   @Test
@@ -111,13 +106,6 @@ public class UserUpdaterCreateTest {
       .isEqualTo(dto.getUpdatedAt());
 
     assertThat(dbClient.userDao().selectByLogin(session, "user").getUuid()).isEqualTo(dto.getUuid());
-    List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
-    assertThat(indexUsers).hasSize(1);
-    assertThat(indexUsers.get(0).getSourceAsMap())
-      .contains(
-        entry("login", "user"),
-        entry("name", "User"),
-        entry("email", "user@mail.com"));
   }
 
   @Test
@@ -271,22 +259,6 @@ public class UserUpdaterCreateTest {
     assertThat(dbClient.userDao().selectByLogin(session, "user").getSortedScmAccounts()).containsOnly("u1");
   }
 
-  @Test
-  public void create_user_and_index_other_user() {
-    createDefaultGroup();
-    UserDto otherUser = db.users().insertUser();
-
-    UserDto created = underTest.createAndCommit(session, NewUser.builder()
-      .setLogin("user")
-      .setName("User")
-      .setEmail("user@mail.com")
-      .setPassword("PASSWORD")
-      .build(), u -> {
-    }, otherUser);
-
-    assertThat(es.getIds(UserIndexDefinition.TYPE_USER)).containsExactlyInAnyOrder(created.getUuid(), otherUser.getUuid());
-  }
-
   @Test
   @UseDataProvider("loginWithAuthorizedSuffix")
   public void createAndCommit_should_createUserWithoutException_when_loginHasAuthorizedSuffix(String login) {
@@ -302,7 +274,7 @@ public class UserUpdaterCreateTest {
 
   @DataProvider
   public static Object[][] loginWithAuthorizedSuffix() {
-    return new Object[][]{
+    return new Object[][] {
       {"1Login"},
       {"AnotherLogin"},
       {"alogin"},
@@ -354,7 +326,7 @@ public class UserUpdaterCreateTest {
 
   @DataProvider
   public static Object[][] loginWithUnauthorizedSuffix() {
-    return new Object[][]{
+    return new Object[][] {
       {".Toto"},
       {"@Toto"},
       {"-Tutu"},
index c5ecdee63a76cda7caf5bab9ea98100ef5a4b544..3eebdcf27a04a02f0aff805c5ad1974ad43a39a8 100644 (file)
@@ -34,8 +34,6 @@ import org.sonar.db.user.GroupTesting;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.CredentialsLocalAuthentication;
 import org.sonar.server.authentication.CredentialsLocalAuthentication.HashMethod;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 
 import static java.lang.String.format;
@@ -52,19 +50,16 @@ public class UserUpdaterReactivateTest {
 
   private final System2 system2 = new AlwaysIncreasingSystem2();
 
-  @Rule
-  public EsTester es = EsTester.create();
   @Rule
   public DbTester db = DbTester.create(system2);
 
   private final DbClient dbClient = db.getDbClient();
   private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
   private final DbSession session = db.getSession();
-  private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private final MapSettings settings = new MapSettings().setProperty("sonar.internal.pbkdf2.iterations", "1");
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
   private final AuditPersister auditPersister = mock(AuditPersister.class);
-  private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
+  private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient,
     new DefaultGroupFinder(dbClient),
     settings.asConfig(), auditPersister, localAuthentication);
 
index dfdc55fd4c5294299294a37fc7154e7555c14871..2ab8be4eb7adfc99a2dd0c142241e4a4c2f2d52d 100644 (file)
@@ -20,9 +20,7 @@
 package org.sonar.server.user;
 
 import com.google.common.collect.Multimap;
-import java.util.List;
 import java.util.function.Consumer;
-import org.elasticsearch.search.SearchHit;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.internal.MapSettings;
@@ -38,10 +36,7 @@ import org.sonar.db.property.PropertyQuery;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 
 import static java.util.Arrays.asList;
@@ -49,7 +44,6 @@ import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.tuple;
-import static org.assertj.core.data.MapEntry.entry;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -68,19 +62,16 @@ public class UserUpdaterUpdateTest {
 
   private final System2 system2 = new AlwaysIncreasingSystem2();
 
-  @Rule
-  public EsTester es = EsTester.create();
   @Rule
   public DbTester db = DbTester.create(system2);
 
   private final DbClient dbClient = db.getDbClient();
   private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
   private final DbSession session = db.getSession();
-  private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private final MapSettings settings = new MapSettings().setProperty("sonar.internal.pbkdf2.iterations", "1");
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
   private final AuditPersister auditPersister = mock(AuditPersister.class);
-  private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
+  private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient,
     new DefaultGroupFinder(dbClient), settings.asConfig(), auditPersister, localAuthentication);
 
   @Test
@@ -88,7 +79,6 @@ public class UserUpdaterUpdateTest {
     UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com")
       .setScmAccounts(asList("ma", "marius33")));
     createDefaultGroup();
-    userIndexer.indexAll();
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setName("Marius2")
@@ -104,13 +94,6 @@ public class UserUpdaterUpdateTest {
     assertThat(updatedUser.getCreatedAt()).isEqualTo(user.getCreatedAt());
     assertThat(updatedUser.getUpdatedAt()).isGreaterThan(user.getCreatedAt());
 
-    List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
-    assertThat(indexUsers).hasSize(1);
-    assertThat(indexUsers.get(0).getSourceAsMap())
-      .contains(
-        entry("login", DEFAULT_LOGIN),
-        entry("name", "Marius2"),
-        entry("email", "marius2@mail.com"));
     verify(auditPersister, never()).updateUserPassword(any(), any());
   }
 
@@ -218,22 +201,6 @@ public class UserUpdaterUpdateTest {
     assertThat(userReloaded.getCryptedPassword()).isEqualTo(user.getCryptedPassword());
   }
 
-  @Test
-  public void update_index_when_updating_user_login() {
-    UserDto oldUser = db.users().insertUser();
-    createDefaultGroup();
-    userIndexer.indexAll();
-
-    underTest.updateAndCommit(session, oldUser, new UpdateUser()
-      .setLogin("new_login"), u -> {
-    });
-
-    List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
-    assertThat(indexUsers).hasSize(1);
-    assertThat(indexUsers.get(0).getSourceAsMap())
-      .contains(entry("login", "new_login"));
-  }
-
   @Test
   public void update_default_assignee_when_updating_login() {
     createDefaultGroup();
@@ -248,7 +215,6 @@ public class UserUpdaterUpdateTest {
       new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()));
     db.properties().insertProperties(oldUser.getLogin(), anotherProject.getKey(), anotherProject.name(), anotherProject.qualifier(),
       new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setComponentUuid(anotherProject.uuid()));
-    userIndexer.indexAll();
 
     underTest.updateAndCommit(session, oldUser, new UpdateUser()
       .setLogin("new_login"), u -> {
@@ -485,23 +451,6 @@ public class UserUpdaterUpdateTest {
     assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN).getUpdatedAt()).isEqualTo(user.getUpdatedAt());
   }
 
-  @Test
-  public void update_user_and_index_other_user() {
-    createDefaultGroup();
-    UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com")
-      .setScmAccounts(asList("ma", "marius33")));
-    UserDto otherUser = db.users().insertUser();
-
-    underTest.updateAndCommit(session, user, new UpdateUser()
-      .setName("Marius2")
-      .setEmail("marius2@mail.com")
-      .setPassword("password2")
-      .setScmAccounts(asList("ma2")), u -> {
-    }, otherUser);
-
-    assertThat(es.getIds(UserIndexDefinition.TYPE_USER)).containsExactlyInAnyOrder(user.getUuid(), otherUser.getUuid());
-  }
-
   @Test
   public void fail_to_set_null_password_when_local_user() {
     UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com"));
index 1731d796002db3e81789477a6d0e042c2c2efc88..024f4613c2087b4b3392f58f64179126bde9b52e 100644 (file)
@@ -45,7 +45,6 @@ import org.sonar.db.DbTester;
 import org.sonar.db.es.EsQueueDto;
 import org.sonar.server.es.IndexType.IndexMainType;
 import org.sonar.server.rule.index.RuleIndexer;
-import org.sonar.server.user.index.UserIndexer;
 
 import static java.util.stream.IntStream.rangeClosed;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -397,9 +396,8 @@ public class RecoveryIndexerTest {
   }
 
   private RecoveryIndexer newRecoveryIndexer() {
-    UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
     RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
-    return newRecoveryIndexer(userIndexer, ruleIndexer);
+    return newRecoveryIndexer(ruleIndexer);
   }
 
   private RecoveryIndexer newRecoveryIndexer(ResilientIndexer... indexers) {
index 2257f33c79c80220de0104ab924bc0d2b0f3deb7..a03f4399b57b594409509894bd545ee06000455e 100644 (file)
@@ -22,8 +22,6 @@ package org.sonar.server.user.ws;
 import java.util.List;
 import java.util.Optional;
 import javax.annotation.Nullable;
-import org.elasticsearch.search.SearchHits;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
@@ -32,17 +30,11 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.user.UserDto;
 import org.sonar.db.user.UserQuery;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.EsUtils;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.ExternalIdentity;
-import org.sonar.server.user.index.UserDoc;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
@@ -50,11 +42,7 @@ import org.sonar.server.ws.WsActionTester;
 import static java.util.Collections.emptyList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_ACTIVE;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_UUID;
 
 public class AnonymizeActionIT {
   private final System2 system2 = new AlwaysIncreasingSystem2();
@@ -62,14 +50,11 @@ public class AnonymizeActionIT {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = EsTester.create();
-  @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
   private final DbClient dbClient = db.getDbClient();
-  private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private final UserAnonymizer userAnonymizer = new UserAnonymizer(db.getDbClient());
-  private final WsActionTester ws = new WsActionTester(new AnonymizeAction(dbClient, userIndexer, userSession, userAnonymizer));
+  private final WsActionTester ws = new WsActionTester(new AnonymizeAction(dbClient, userSession, userAnonymizer));
 
   @Test
   public void anonymize_user() {
@@ -87,7 +72,6 @@ public class AnonymizeActionIT {
     TestResponse response = anonymize(user.getLogin());
 
     verifyThatUserIsAnonymized(user.getUuid());
-    verifyThatUserIsAnonymizedOnEs(user.getUuid());
     assertThat(response.getInput()).isEmpty();
   }
 
@@ -174,19 +158,6 @@ public class AnonymizeActionIT {
     return request.execute();
   }
 
-  private void verifyThatUserIsAnonymizedOnEs(String uuid) {
-    SearchHits hits = es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
-        .source(new SearchSourceBuilder()
-          .query(boolQuery()
-            .must(termQuery(FIELD_UUID, uuid))
-            .must(termQuery(FIELD_ACTIVE, "false")))))
-      .getHits();
-    List<UserDoc> userDocs = EsUtils.convertToDocs(hits, UserDoc::new);
-    assertThat(userDocs).hasSize(1);
-    assertThat(userDocs.get(0).login()).startsWith("sq-removed-");
-    assertThat(userDocs.get(0).name()).startsWith("sq-removed-");
-  }
-
   private void verifyThatUserIsAnonymized(String uuid) {
     List<UserDto> users = dbClient.userDao().selectUsers(db.getSession(), UserQuery.builder().isActive(false).build());
     assertThat(users).hasSize(1);
index 541119f52c7a2a4faca514b3fc84e2bbd0f6373c..a1fdd23020dcb726991794c4b603823b93054dc6 100644 (file)
@@ -40,14 +40,11 @@ import org.sonar.db.user.SessionTokenDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.CredentialsLocalAuthentication;
 import org.sonar.server.authentication.JwtHttpHandler;
-import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.NewUserNotifier;
 import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 import org.sonar.server.ws.ServletFilterHandler;
 
@@ -74,8 +71,6 @@ public class ChangePasswordActionIT {
   @Rule
   public DbTester db = DbTester.create();
   @Rule
-  public EsTester es = EsTester.createCustom(UserIndexDefinition.createForTest());
-  @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn();
 
   private final ArgumentCaptor<UserDto> userDtoCaptor = ArgumentCaptor.forClass(UserDto.class);
@@ -88,7 +83,7 @@ public class ChangePasswordActionIT {
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
 
   private final UserUpdater userUpdater = new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(),
-    new UserIndexer(db.getDbClient(), es.client()), new DefaultGroupFinder(db.getDbClient()),
+    new DefaultGroupFinder(db.getDbClient()),
     new MapSettings().asConfig(), new NoOpAuditPersister(), localAuthentication);
 
   private final JwtHttpHandler jwtHttpHandler = mock(JwtHttpHandler.class);
index 3f885ffefb456d203d82c134dce250403f2e702e..5af7f5a8c5ef88a86d8c412eb14fd44b4916ffce 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.user.ws;
 
 import java.util.List;
 import java.util.Optional;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -34,8 +33,6 @@ import org.sonar.db.audit.NoOpAuditPersister;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
@@ -43,8 +40,6 @@ import org.sonar.server.management.ManagedInstanceChecker;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.NewUserNotifier;
 import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.user.ws.CreateAction.CreateRequest;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 import org.sonar.server.ws.TestRequest;
@@ -57,17 +52,11 @@ import static java.util.Collections.singletonList;
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.sonar.db.user.UserTesting.newUserDto;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_EMAIL;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_LOGIN;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_NAME;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_SCM_ACCOUNTS;
 
 public class CreateActionIT {
 
@@ -77,17 +66,14 @@ public class CreateActionIT {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = EsTester.create();
-  @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
-  private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
   private GroupDto defaultGroup;
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
 
   private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
   private final WsActionTester tester = new WsActionTester(new CreateAction(db.getDbClient(), new UserUpdater(mock(NewUserNotifier.class),
-    db.getDbClient(), userIndexer, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), new NoOpAuditPersister(), localAuthentication), userSessionRule, managedInstanceChecker));
+    db.getDbClient(), new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), new NoOpAuditPersister(), localAuthentication), userSessionRule, managedInstanceChecker));
 
   @Before
   public void setUp() {
@@ -110,16 +96,6 @@ public class CreateActionIT {
       .extracting(User::getLogin, User::getName, User::getEmail, User::getScmAccountsList, User::getLocal)
       .containsOnly("john", "John", "john@email.com", singletonList("jn"), true);
 
-    // exists in index
-    assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
-      .source(new SearchSourceBuilder()
-        .query(boolQuery()
-          .must(termQuery(FIELD_LOGIN, "john"))
-          .must(termQuery(FIELD_NAME, "John"))
-          .must(termQuery(FIELD_EMAIL, "john@email.com"))
-          .must(termQuery(FIELD_SCM_ACCOUNTS, "jn")))))
-      .getHits().getHits()).hasSize(1);
-
     // exists in db
     Optional<UserDto> dbUser = db.users().selectUserByLogin("john");
     assertThat(dbUser).isPresent();
@@ -229,7 +205,6 @@ public class CreateActionIT {
     logInAsSystemAdministrator();
 
     db.users().insertUser(newUserDto("john", "John", "john@email.com").setActive(false));
-    userIndexer.indexAll();
 
     call(CreateRequest.builder()
       .setLogin("john")
index 74c0b98f237715607a7d79f1f1519e0164306de7..6ed266dfa167031ee1651b6298822e2c4d094e75 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.user.ws;
 
 import java.util.Optional;
 import javax.annotation.Nullable;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
@@ -45,8 +44,6 @@ import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.SessionTokenDto;
 import org.sonar.db.user.UserDismissedMessageDto;
 import org.sonar.db.user.UserDto;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -54,8 +51,6 @@ import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.management.ManagedInstanceChecker;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.ExternalIdentity;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
@@ -63,15 +58,11 @@ import org.sonar.server.ws.WsActionTester;
 import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.sonar.db.property.PropertyTesting.newUserPropertyDto;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_ACTIVE;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_UUID;
 import static org.sonar.test.JsonAssert.assertJson;
 
 public class DeactivateActionIT {
@@ -81,15 +72,12 @@ public class DeactivateActionIT {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = EsTester.create();
-  @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
   private final DbClient dbClient = db.getDbClient();
-  private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private final DbSession dbSession = db.getSession();
   private final UserAnonymizer userAnonymizer = new UserAnonymizer(db.getDbClient(), () -> "anonymized");
-  private final UserDeactivator userDeactivator = new UserDeactivator(dbClient, userIndexer, userSession, userAnonymizer);
+  private final UserDeactivator userDeactivator = new UserDeactivator(dbClient, userSession, userAnonymizer);
   private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
   private final WsActionTester ws = new WsActionTester(new DeactivateAction(dbClient, userSession, new UserJsonWriter(userSession), userDeactivator, managedInstanceChecker));
 
@@ -106,12 +94,6 @@ public class DeactivateActionIT {
     deactivate(user.getLogin());
 
     verifyThatUserIsDeactivated(user.getLogin());
-    assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
-        .source(new SearchSourceBuilder()
-          .query(boolQuery()
-            .must(termQuery(FIELD_UUID, user.getUuid()))
-            .must(termQuery(FIELD_ACTIVE, "false")))))
-      .getHits().getHits()).hasSize(1);
   }
 
   @Test
@@ -128,12 +110,6 @@ public class DeactivateActionIT {
 
     verifyThatUserIsDeactivated("anonymized");
     verifyThatUserIsAnomymized("anonymized");
-    assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
-        .source(new SearchSourceBuilder()
-          .query(boolQuery()
-            .must(termQuery(FIELD_UUID, user.getUuid()))
-            .must(termQuery(FIELD_ACTIVE, "false")))))
-      .getHits().getHits()).hasSize(1);
   }
 
   @Test
index d38276360871c7b712777df1295bd042e1dc712c..cf0f8bfee69a370b633d74844a7326dc04fa4556 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -41,7 +40,6 @@ import org.sonar.server.management.ManagedInstanceChecker;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.NewUserNotifier;
 import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
@@ -64,17 +62,14 @@ public class UpdateActionIT {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = EsTester.create();
-  @Rule
   public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
 
   private final DbClient dbClient = db.getDbClient();
   private final DbSession dbSession = db.getSession();
-  private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
   private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
   private final WsActionTester ws = new WsActionTester(new UpdateAction(
-    new UserUpdater(mock(NewUserNotifier.class), dbClient, userIndexer, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), null, localAuthentication),
+    new UserUpdater(mock(NewUserNotifier.class), dbClient, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), null, localAuthentication),
     userSession, new UserJsonWriter(userSession), dbClient, managedInstanceChecker));
 
   @Before
@@ -338,6 +333,6 @@ public class UpdateActionIT {
       .setExternalLogin("jo")
       .setExternalIdentityProvider("sonarqube");
     dbClient.userDao().insert(dbSession, userDto);
-    userIndexer.commitAndIndex(dbSession, userDto);
+    dbSession.commit();
   }
 }
index e5271b48c260e4102dd9dee294752dc60216c324..125339b82ba602e830467f37e1cadbbb6d622934 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.CredentialsLocalAuthentication;
 import org.sonar.server.authentication.IdentityProviderRepositoryRule;
 import org.sonar.server.authentication.TestIdentityProvider;
-import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -38,7 +37,6 @@ import org.sonar.server.management.ManagedInstanceChecker;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.NewUserNotifier;
 import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
@@ -63,20 +61,17 @@ public class UpdateIdentityProviderActionIT {
   @Rule
   public DbTester db = DbTester.create();
   @Rule
-  public EsTester es = EsTester.create();
-  @Rule
   public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
 
   private final MapSettings settings = new MapSettings().setProperty("sonar.internal.pbkdf2.iterations", "1");
   private final DbClient dbClient = db.getDbClient();
   private final DbSession dbSession = db.getSession();
-  private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(dbClient, settings.asConfig());
 
   private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
 
   private final WsActionTester underTest = new WsActionTester(new UpdateIdentityProviderAction(dbClient, identityProviderRepository,
-    new UserUpdater(mock(NewUserNotifier.class), dbClient, userIndexer, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), null, localAuthentication),
+    new UserUpdater(mock(NewUserNotifier.class), dbClient, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), null, localAuthentication),
     userSession, managedInstanceChecker));
 
   @Test
@@ -261,7 +256,7 @@ public class UpdateIdentityProviderActionIT {
       .setExternalLogin(externalLogin)
       .setExternalIdentityProvider(externalIdentityProvider);
     dbClient.userDao().insert(dbSession, userDto);
-    userIndexer.commitAndIndex(dbSession, userDto);
+    dbSession.commit();
   }
 
 }
index d3609f457608747a3e99d911e9af5d73c4584b8a..ef372d567d0ff6602314da5ae15777ceabe30f0f 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.user.UserDto;
-import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -35,7 +34,6 @@ import org.sonar.server.management.ManagedInstanceChecker;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.NewUserNotifier;
 import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
@@ -56,13 +54,11 @@ public class UpdateLoginActionIT {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = EsTester.create();
-  @Rule
   public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
 
   private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
   private final WsActionTester ws = new WsActionTester(new UpdateLoginAction(db.getDbClient(), userSession,
-    new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), new UserIndexer(db.getDbClient(), es.client()), null, null, null, null), managedInstanceChecker));
+    new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), null, null, null, null), managedInstanceChecker));
 
   @Test
   public void update_login_from_sonarqube_account_when_user_is_local() {
index 9e61155036c0c8d8c00dc909b5d2398c2c864422..d26ffd9eeeb87c7b183c86a83f66e255c7cb1475 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.user.UserSession;
-import org.sonar.server.user.index.UserIndexer;
 
 import static org.sonar.server.exceptions.NotFoundException.checkFound;
 
@@ -35,14 +34,12 @@ public class AnonymizeAction implements UsersWsAction {
   private static final String PARAM_LOGIN = "login";
 
   private final DbClient dbClient;
-  private final UserIndexer userIndexer;
   private final UserSession userSession;
   private final UserAnonymizer userAnonymizer;
 
-  public AnonymizeAction(DbClient dbClient, UserIndexer userIndexer, UserSession userSession, UserAnonymizer userAnonymizer) {
+  public AnonymizeAction(DbClient dbClient, UserSession userSession, UserAnonymizer userAnonymizer) {
     this.userAnonymizer = userAnonymizer;
     this.dbClient = dbClient;
-    this.userIndexer = userIndexer;
     this.userSession = userSession;
   }
 
@@ -74,7 +71,7 @@ public class AnonymizeAction implements UsersWsAction {
 
       userAnonymizer.anonymize(dbSession, user);
       dbClient.userDao().update(dbSession, user);
-      userIndexer.commitAndIndex(dbSession, user);
+      dbSession.commit();
     }
 
     response.noContent();
index 4512646995594be2383ed8d9624a6c68b5ee9544..6c1f438b1ab636ce926d62201ab6ab9299c4373c 100644 (file)
@@ -24,7 +24,6 @@ import org.sonar.db.DbSession;
 import org.sonar.db.property.PropertyQuery;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.user.UserSession;
-import org.sonar.server.user.index.UserIndexer;
 
 import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
@@ -33,13 +32,11 @@ import static org.sonar.server.exceptions.NotFoundException.checkFound;
 
 public class UserDeactivator {
   private final DbClient dbClient;
-  private final UserIndexer userIndexer;
   private final UserSession userSession;
   private final UserAnonymizer userAnonymizer;
 
-  public UserDeactivator(DbClient dbClient, UserIndexer userIndexer, UserSession userSession, UserAnonymizer userAnonymizer) {
+  public UserDeactivator(DbClient dbClient, UserSession userSession, UserAnonymizer userAnonymizer) {
     this.dbClient = dbClient;
-    this.userIndexer = userIndexer;
     this.userSession = userSession;
     this.userAnonymizer = userAnonymizer;
   }
@@ -98,6 +95,6 @@ public class UserDeactivator {
 
   private void deactivateUser(DbSession dbSession, UserDto user) {
     dbClient.userDao().deactivateUser(dbSession, user);
-    userIndexer.commitAndIndex(dbSession, user);
+    dbSession.commit();
   }
 }
index 10fe7bc75548a634ecfacc300c5dbe4504234a11..7590e9108b0d411182ac36d35936b9c564fa9258 100644 (file)
@@ -246,9 +246,6 @@ import org.sonar.server.user.NewUserNotifier;
 import org.sonar.server.user.SecurityRealmFactory;
 import org.sonar.server.user.UserSessionFactoryImpl;
 import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndex;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.user.ws.UsersWsModule;
 import org.sonar.server.usergroups.DefaultGroupFinder;
 import org.sonar.server.usergroups.ws.UserGroupsModule;
@@ -397,9 +394,6 @@ public class PlatformLevel4 extends PlatformLevel {
       UserSessionFactoryImpl.class,
       SecurityRealmFactory.class,
       NewUserNotifier.class,
-      UserIndexDefinition.class,
-      UserIndexer.class,
-      UserIndex.class,
       UserUpdater.class,
       new UsersWsModule(),
       new UserTokenModule(),