import org.sonar.core.platform.Module;
import org.sonar.server.computation.monitoring.CEQueueStatusImpl;
import org.sonar.server.computation.monitoring.CeTasksMBeanImpl;
-import org.sonar.server.computation.queue.CeQueueCleaner;
import org.sonar.server.computation.queue.CeQueueInitializer;
import org.sonar.server.computation.queue.InternalCeQueueImpl;
// queue monitoring
CEQueueStatusImpl.class,
CeTasksMBeanImpl.class,
-
- // queue cleaning
- CeQueueCleaner.class,
// init queue state and queue processing
CeQueueInitializer.class);
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.index.ComponentIndexer;
+import org.sonar.server.computation.queue.CeQueueCleaner;
import org.sonar.server.computation.queue.PurgeCeActivities;
import org.sonar.server.computation.task.projectanalysis.ProjectAnalysisTaskModule;
import org.sonar.server.computation.taskprocessor.CeTaskProcessorModule;
LogServerId.class,
ServerLifecycleNotifier.class,
PurgeCeActivities.class,
+ CeQueueCleaner.class
};
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.ce.queue;
+
+import javax.annotation.ParametersAreNonnullByDefault;
CONTAINER_ITSELF
+ 74 // level 4
+ 4 // content of CeConfigurationModule
- + 5 // content of CeQueueModule
+ + 4 // content of CeQueueModule
+ 3 // content of CeHttpModule
+ 3 // content of CeTaskCommonsModule
+ 4 // content of ProjectAnalysisTaskModule
package org.sonar.server.computation.queue;
import java.util.List;
+import org.picocontainer.Startable;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.platform.ServerUpgradeStatus;
import org.sonar.api.utils.log.Logger;
* CE workers must not be started before execution of this class.
*/
@ComputeEngineSide
-public class CeQueueCleaner {
+public class CeQueueCleaner implements Startable {
private static final Logger LOGGER = Loggers.get(CeQueueCleaner.class);
this.queue = queue;
}
- public void clean(DbSession dbSession) {
+ @Override
+ public void start() {
if (serverUpgradeStatus.isUpgraded()) {
cleanOnUpgrade();
} else {
- verifyConsistency(dbSession);
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ verifyConsistency(dbSession);
+ }
}
}
dbClient.ceTaskInputDao().deleteByUuids(dbSession, uuids);
dbSession.commit();
}
+
+ @Override
+ public void stop() {
+ // nothing to do
+ }
}
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerStartHandler;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.server.computation.taskprocessor.CeProcessingScheduler;
/**
@ComputeEngineSide
public class CeQueueInitializer implements ServerStartHandler {
- private final DbClient dbClient;
- private final CeQueueCleaner cleaner;
private final CeProcessingScheduler scheduler;
private boolean done = false;
- public CeQueueInitializer(DbClient dbClient, CeQueueCleaner cleaner, CeProcessingScheduler scheduler) {
- this.dbClient = dbClient;
- this.cleaner = cleaner;
+ public CeQueueInitializer(CeProcessingScheduler scheduler) {
this.scheduler = scheduler;
}
}
private void initCe() {
- try (DbSession dbSession = dbClient.openSession(false)) {
- cleaner.clean(dbSession);
- scheduler.startScheduling();
- }
+ scheduler.startScheduling();
}
}
private CeQueueCleaner underTest = new CeQueueCleaner(dbTester.getDbClient(), serverUpgradeStatus, queue);
@Test
- public void reset_in_progress_tasks_to_pending() throws IOException {
+ public void start_resets_in_progress_tasks_to_pending() throws IOException {
insertInQueue("TASK_1", CeQueueDto.Status.PENDING);
insertInQueue("TASK_2", CeQueueDto.Status.IN_PROGRESS);
- underTest.clean(dbTester.getSession());
+ underTest.start();
assertThat(dbTester.getDbClient().ceQueueDao().countByStatus(dbTester.getSession(), CeQueueDto.Status.PENDING)).isEqualTo(2);
assertThat(dbTester.getDbClient().ceQueueDao().countByStatus(dbTester.getSession(), CeQueueDto.Status.IN_PROGRESS)).isEqualTo(0);
}
@Test
- public void clear_queue_if_version_upgrade() {
+ public void start_clears_queue_if_version_upgrade() {
when(serverUpgradeStatus.isUpgraded()).thenReturn(true);
- underTest.clean(dbTester.getSession());
+ underTest.start();
verify(queue).clear();
}
@Test
- public void delete_orphan_report_files() throws Exception {
+ public void start_deletes_orphan_report_files() throws Exception {
// analysis reports are persisted but the associated
// task is not in the queue
insertInQueue("TASK_1", CeQueueDto.Status.PENDING);
insertTaskData("TASK_1");
insertTaskData("TASK_2");
- underTest.clean(dbTester.getSession());
+ underTest.start();
CeTaskInputDao dataDao = dbTester.getDbClient().ceTaskInputDao();
Optional<CeTaskInputDao.DataStream> task1Data = dataDao.selectData(dbTester.getSession(), "TASK_1");
package org.sonar.server.computation.queue;
import java.io.IOException;
-import org.junit.Rule;
import org.junit.Test;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
import org.sonar.api.platform.Server;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
import org.sonar.server.computation.taskprocessor.CeProcessingScheduler;
-import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
public class CeQueueInitializerTest {
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- Server server = mock(Server.class);
- CeQueueCleaner cleaner = mock(CeQueueCleaner.class);
- CeProcessingScheduler scheduler = mock(CeProcessingScheduler.class);
- CeQueueInitializer underTest = new CeQueueInitializer(dbTester.getDbClient(), cleaner, scheduler);
+ private Server server = mock(Server.class);
+ private CeProcessingScheduler scheduler = mock(CeProcessingScheduler.class);
+ private CeQueueInitializer underTest = new CeQueueInitializer(scheduler);
@Test
public void clean_queue_then_start_scheduler_of_workers() throws IOException {
- InOrder inOrder = Mockito.inOrder(cleaner, scheduler);
-
underTest.onServerStart(server);
- inOrder.verify(cleaner).clean(any(DbSession.class));
- inOrder.verify(scheduler).startScheduling();
+ verify(scheduler).startScheduling();
}
@Test
underTest.onServerStart(server);
- reset(cleaner, scheduler);
+ reset(scheduler);
underTest.onServerStart(server);
- verifyZeroInteractions(cleaner, scheduler);
+ verifyZeroInteractions(scheduler);
}
}