From c36d2eab3e2fae4d17fb60224a2dc771ce67783a Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 15 Mar 2016 16:04:38 +0100 Subject: [PATCH] SONAR-6732 add EsIndexerEnabler to Compute Engine replaced IndexSynchronizer which also triggered a full reindex (which we do not want in CE) --- .../container/ComputeEngineContainerImpl.java | 2 + .../org/sonar/ce/es/EsIndexerEnabler.java | 67 +++++++++++++++++++ .../java/org/sonar/ce/es/package-info.java | 23 +++++++ .../ComputeEngineContainerImplTest.java | 2 +- .../org/sonar/ce/es/EsIndexerEnablerTest.java | 53 +++++++++++++++ 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 server/sonar-ce/src/main/java/org/sonar/ce/es/EsIndexerEnabler.java create mode 100644 server/sonar-ce/src/main/java/org/sonar/ce/es/package-info.java create mode 100644 server/sonar-ce/src/test/java/org/sonar/ce/es/EsIndexerEnablerTest.java diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index 4afc8215683..135c9a55552 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -34,6 +34,7 @@ import org.sonar.api.server.rule.RulesDefinitionXmlLoader; import org.sonar.api.utils.Durations; import org.sonar.api.utils.System2; import org.sonar.api.utils.UriReader; +import org.sonar.ce.es.EsIndexerEnabler; import org.sonar.ce.property.CePropertyDefinitions; import org.sonar.core.component.DefaultResourceTypes; import org.sonar.core.config.CorePropertyDefinitions; @@ -565,6 +566,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { }; private static final Object[] STARTUP_COMPONENTS = new Object[] { // IndexSynchronizer.class, ES maintenance, responsibility of Web Server + EsIndexerEnabler.class, // RegisterMetrics.class, DB maintenance, responsibility of Web Server // RegisterQualityGates.class, DB maintenance, responsibility of Web Server // RegisterRules.class, DB maintenance, responsibility of Web Server diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/es/EsIndexerEnabler.java b/server/sonar-ce/src/main/java/org/sonar/ce/es/EsIndexerEnabler.java new file mode 100644 index 00000000000..bd038fa6807 --- /dev/null +++ b/server/sonar-ce/src/main/java/org/sonar/ce/es/EsIndexerEnabler.java @@ -0,0 +1,67 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.ce.es; + +import org.picocontainer.Startable; +import org.sonar.server.activity.index.ActivityIndexer; +import org.sonar.server.issue.index.IssueAuthorizationIndexer; +import org.sonar.server.issue.index.IssueIndexer; +import org.sonar.server.test.index.TestIndexer; +import org.sonar.server.user.index.UserIndexer; +import org.sonar.server.view.index.ViewIndexer; + +/** + * Replaces the {@link org.sonar.server.search.IndexSynchronizer} to enable indexers but without triggering a full + * indexation (it's the WebServer's responsibility). + */ +public class EsIndexerEnabler implements Startable { + + private final TestIndexer testIndexer; + private final IssueAuthorizationIndexer issueAuthorizationIndexer; + private final IssueIndexer issueIndexer; + private final UserIndexer userIndexer; + private final ViewIndexer viewIndexer; + private final ActivityIndexer activityIndexer; + + public EsIndexerEnabler(TestIndexer testIndexer, IssueAuthorizationIndexer issueAuthorizationIndexer, + IssueIndexer issueIndexer, UserIndexer userIndexer, ViewIndexer viewIndexer, ActivityIndexer activityIndexer) { + this.testIndexer = testIndexer; + this.issueAuthorizationIndexer = issueAuthorizationIndexer; + this.issueIndexer = issueIndexer; + this.userIndexer = userIndexer; + this.viewIndexer = viewIndexer; + this.activityIndexer = activityIndexer; + } + + @Override + public void start() { + activityIndexer.setEnabled(true); + issueAuthorizationIndexer.setEnabled(true); + issueIndexer.setEnabled(true); + testIndexer.setEnabled(true); + userIndexer.setEnabled(true); + viewIndexer.setEnabled(true); + } + + @Override + public void stop() { + // nothing to do at stop + } +} diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/es/package-info.java b/server/sonar-ce/src/main/java/org/sonar/ce/es/package-info.java new file mode 100644 index 00000000000..9a869a3cced --- /dev/null +++ b/server/sonar-ce/src/main/java/org/sonar/ce/es/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.ce.es; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 44a2b815a9e..9171be576b7 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -84,7 +84,7 @@ public class ComputeEngineContainerImplTest { + 7 // content of CeQueueModule + 4 // content of ReportProcessingModule + 4 // content of CeTaskProcessorModule - + 3 // level startup + + 4 // level startup ); } diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/es/EsIndexerEnablerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/es/EsIndexerEnablerTest.java new file mode 100644 index 00000000000..e0cae201d3c --- /dev/null +++ b/server/sonar-ce/src/test/java/org/sonar/ce/es/EsIndexerEnablerTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.ce.es; + +import org.junit.Test; +import org.sonar.server.activity.index.ActivityIndexer; +import org.sonar.server.issue.index.IssueAuthorizationIndexer; +import org.sonar.server.issue.index.IssueIndexer; +import org.sonar.server.test.index.TestIndexer; +import org.sonar.server.user.index.UserIndexer; +import org.sonar.server.view.index.ViewIndexer; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class EsIndexerEnablerTest { + private TestIndexer testIndexer = mock(TestIndexer.class); + private IssueAuthorizationIndexer issueAuthorizationIndexer = mock(IssueAuthorizationIndexer.class); + private IssueIndexer issueIndexer = mock(IssueIndexer.class); + private UserIndexer userIndexer = mock(UserIndexer.class); + private ViewIndexer viewIndexer = mock(ViewIndexer.class); + private ActivityIndexer activityIndexer = mock(ActivityIndexer.class); + private EsIndexerEnabler underTest = new EsIndexerEnabler(testIndexer, issueAuthorizationIndexer, issueIndexer, userIndexer, viewIndexer, activityIndexer); + + @Test + public void start_enables_all_indexers() { + underTest.start(); + + verify(testIndexer).setEnabled(true); + verify(issueAuthorizationIndexer).setEnabled(true); + verify(issueIndexer).setEnabled(true); + verify(userIndexer).setEnabled(true); + verify(viewIndexer).setEnabled(true); + verify(activityIndexer).setEnabled(true); + } +} -- 2.39.5