aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce/src/main/java
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-04 17:12:34 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-17 10:52:47 +0200
commitc818fc85b3d32c358b5149647d384cc42f4ba5a1 (patch)
treeb05ac212a5c83299e3b93857f17737f38f0fdc64 /server/sonar-ce/src/main/java
parent06cc9aae3d4195f18700a56f680299779e0d6a70 (diff)
downloadsonarqube-c818fc85b3d32c358b5149647d384cc42f4ba5a1.tar.gz
sonarqube-c818fc85b3d32c358b5149647d384cc42f4ba5a1.zip
SONAR-9507 move CeConfiguration to module ce and delete module ce-api
Diffstat (limited to 'server/sonar-ce/src/main/java')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfiguration.java45
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java110
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/configuration/package-info.java23
3 files changed, 178 insertions, 0 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfiguration.java b/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfiguration.java
new file mode 100644
index 00000000000..393ec1d6f52
--- /dev/null
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfiguration.java
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.sonar.ce.configuration;
+
+public interface CeConfiguration {
+
+ /**
+ * The number of workers to process CeTasks concurrently.
+ */
+ int getWorkerCount();
+
+ /**
+ * The delay in millisecond before a {@link org.sonar.ce.taskprocessor.CeWorker} shall try and find a task
+ * to process when it's previous execution had nothing to do.
+ */
+ long getQueuePollingDelay();
+
+ /**
+ * Delay before running job that cleans CE tasks for the first time (in minutes).
+ */
+ long getCleanCeTasksInitialDelay();
+
+ /**
+ * Delay between the end of a run and the start of the next one of the job that cleans CE tasks (in minutes).
+ */
+ long getCleanCeTasksDelay();
+
+}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java
new file mode 100644
index 00000000000..be00dbc3d08
--- /dev/null
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+package org.sonar.ce.configuration;
+
+import org.picocontainer.Startable;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+
+import static java.lang.String.format;
+
+/**
+ * Immutable implementation of {@link CeConfiguration} which takes value returned by
+ * {@link CeConfiguration#getWorkerCount()} from property {@link CeConfigurationImpl#CE_WORKERS_COUNT_PROPERTY} and
+ * always returns {@link #DEFAULT_QUEUE_POLLING_DELAY} when {@link CeConfiguration#getQueuePollingDelay()} is called.
+ */
+public class CeConfigurationImpl implements CeConfiguration, Startable {
+ private static final String CE_WORKERS_COUNT_PROPERTY = "sonar.ce.workerCount";
+
+ private static final Logger LOG = Loggers.get(CeConfigurationImpl.class);
+
+ private static final int DEFAULT_WORKER_COUNT = 1;
+ // 2 seconds
+ private static final long DEFAULT_QUEUE_POLLING_DELAY = 2 * 1000L;
+ // 1 minute
+ private static final long CANCEL_WORN_OUTS_INITIAL_DELAY = 1;
+ // 10 minutes
+ private static final long CANCEL_WORN_OUTS_DELAY = 10;
+
+ private final int workerCount;
+
+ public CeConfigurationImpl(Configuration config) {
+ String workerCountAsStr = config.get(CE_WORKERS_COUNT_PROPERTY).orElse(null);
+ if (workerCountAsStr == null || workerCountAsStr.isEmpty()) {
+ this.workerCount = DEFAULT_WORKER_COUNT;
+ } else {
+ this.workerCount = parseStringValue(workerCountAsStr);
+ }
+ }
+
+ private static int parseStringValue(String workerCountAsStr) {
+ try {
+ int value = Integer.parseInt(workerCountAsStr);
+ if (value < 1) {
+ throw parsingError(workerCountAsStr);
+ }
+ return value;
+ } catch (NumberFormatException e) {
+ throw parsingError(workerCountAsStr);
+ }
+ }
+
+ private static MessageException parsingError(String workerCountAsStr) {
+ return MessageException.of(format(
+ "value '%s' of property %s is invalid. It must an integer strictly greater than 0.",
+ workerCountAsStr,
+ CE_WORKERS_COUNT_PROPERTY));
+ }
+
+ @Override
+ public void start() {
+ if (this.workerCount > 1) {
+ LOG.info("Compute Engine will use {} concurrent workers to process tasks", this.workerCount);
+ }
+ }
+
+ @Override
+ public void stop() {
+ // nothing to do
+ }
+
+ @Override
+ public int getWorkerCount() {
+ return workerCount;
+ }
+
+ @Override
+ public long getQueuePollingDelay() {
+ return DEFAULT_QUEUE_POLLING_DELAY;
+ }
+
+ @Override
+ public long getCleanCeTasksInitialDelay() {
+ return CANCEL_WORN_OUTS_INITIAL_DELAY;
+ }
+
+ @Override
+ public long getCleanCeTasksDelay() {
+ return CANCEL_WORN_OUTS_DELAY;
+ }
+
+}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/configuration/package-info.java b/server/sonar-ce/src/main/java/org/sonar/ce/configuration/package-info.java
new file mode 100644
index 00000000000..5805ec5bddf
--- /dev/null
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/configuration/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.configuration;
+
+import javax.annotation.ParametersAreNonnullByDefault;