]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6831 move remaining classes out of package computation
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 28 Sep 2015 09:01:36 +0000 (11:01 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 28 Sep 2015 10:22:13 +0000 (12:22 +0200)
ComputeEngineProcessingModule will be moved in a separate commit which will refactor CE's modules

29 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/CePropertyDefinitions.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStepExecutor.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationTempFolderProvider.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/ComputeEngineProcessingModule.java
server/sonar-server/src/main/java/org/sonar/server/computation/PurgeCeActivities.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/ReportFiles.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java
server/sonar-server/src/main/java/org/sonar/server/computation/filesystem/ComputationTempFolderProvider.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/filesystem/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/property/CePropertyDefinitions.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/property/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeQueueCleaner.java
server/sonar-server/src/main/java/org/sonar/server/computation/queue/PurgeCeActivities.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/queue/report/CleanReportQueueListener.java
server/sonar-server/src/main/java/org/sonar/server/computation/queue/report/ReportFiles.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/queue/report/ReportSubmitter.java
server/sonar-server/src/main/java/org/sonar/server/computation/queue/report/ReportTaskProcessor.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputationStepExecutor.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/step/ExtractReportStep.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
server/sonar-server/src/test/java/org/sonar/server/computation/CePropertyDefinitionsTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/PurgeCeActivitiesTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ReportFilesTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueCleanerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueInitializerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/queue/report/CleanReportQueueListenerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/queue/report/ReportSubmitterTest.java

diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/CePropertyDefinitions.java b/server/sonar-server/src/main/java/org/sonar/server/computation/CePropertyDefinitions.java
deleted file mode 100644 (file)
index 6ccf89f..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.computation;
-
-import java.util.List;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.PropertyType;
-import org.sonar.api.config.PropertyDefinition;
-import org.sonar.server.computation.log.CeLogging;
-
-import static java.util.Arrays.asList;
-
-public class CePropertyDefinitions {
-  private CePropertyDefinitions() {
-    // only statics
-  }
-
-  public static List<PropertyDefinition> all() {
-    return asList(
-      PropertyDefinition.builder(CeLogging.MAX_LOGS_PROPERTY)
-        .name("Compute Engine Log Retention")
-        .description("Number of tasks to keep logs for a given project. Once the number of logs exceeds this limit, oldest logs are purged.")
-        .type(PropertyType.INTEGER)
-        .defaultValue("10")
-        .category(CoreProperties.CATEGORY_GENERAL)
-        .build());
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStepExecutor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStepExecutor.java
deleted file mode 100644 (file)
index 8fb79cc..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.computation;
-
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.core.util.logs.Profiler;
-import org.sonar.server.computation.step.ComputationStep;
-import org.sonar.server.computation.step.ComputationSteps;
-
-public final class ComputationStepExecutor {
-  private static final Logger LOGGER = Loggers.get(ComputationStepExecutor.class);
-
-  private final ComputationSteps steps;
-
-  public ComputationStepExecutor(ComputationSteps steps) {
-    this.steps = steps;
-  }
-
-  public void execute() {
-    Profiler stepProfiler = Profiler.create(LOGGER);
-    for (ComputationStep step : steps.instances()) {
-      stepProfiler.start();
-      step.execute();
-      stepProfiler.stopInfo(step.getDescription());
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationTempFolderProvider.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationTempFolderProvider.java
deleted file mode 100644 (file)
index d74d9c9..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.computation;
-
-import java.io.File;
-import java.io.IOException;
-import javax.annotation.CheckForNull;
-import org.apache.commons.io.FileUtils;
-import org.picocontainer.ComponentLifecycle;
-import org.picocontainer.PicoContainer;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.platform.ServerFileSystem;
-import org.sonar.api.utils.TempFolder;
-import org.sonar.api.utils.internal.DefaultTempFolder;
-
-/**
- * Provides a TempFolder instance pointing to a directory dedicated to the processing of a specific item.
- * This directory will be deleted at the end of the processing.
- * This directory is located in the "ce" directory of the temp directory of the SonarQube instance.
- */
-public class ComputationTempFolderProvider extends ProviderAdapter implements ComponentLifecycle<TempFolder> {
-  private boolean started = false;
-  @CheckForNull
-  private DefaultTempFolder tempFolder;
-
-  public TempFolder provide(ServerFileSystem fs) {
-    if (this.tempFolder == null) {
-      File tempDir = new File(fs.getTempDir(), "ce");
-      try {
-        FileUtils.forceMkdir(tempDir);
-      } catch (IOException e) {
-        throw new IllegalStateException("Unable to create computation temp directory " + tempDir, e);
-      }
-      File computationDir = new DefaultTempFolder(tempDir).newDir();
-      this.tempFolder = new DefaultTempFolder(computationDir, true);
-    }
-    return this.tempFolder;
-  }
-
-  @Override
-  public void start(PicoContainer container) {
-    this.started = true;
-  }
-
-  @Override
-  public void stop(PicoContainer container) {
-    if (tempFolder != null) {
-      tempFolder.stop();
-    }
-  }
-
-  @Override
-  public void dispose(PicoContainer container) {
-    // nothing to do
-  }
-
-  @Override
-  public boolean componentHasLifecycle() {
-    return true;
-  }
-
-  @Override
-  public boolean isStarted() {
-    return started;
-  }
-
-}
index 3cd9c0684dd21d16906878ab70a7866497dcc947..eb30f047a1665f2ae284d06c91ba3e41d3841ad6 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.server.computation.queue.CeProcessingSchedulerExecutorServiceIm
 import org.sonar.server.computation.queue.CeProcessingSchedulerImpl;
 import org.sonar.server.computation.queue.CeWorkerRunnableImpl;
 import org.sonar.server.computation.queue.report.ReportTaskProcessor;
+import org.sonar.server.computation.step.ComputationStepExecutor;
 
 public class ComputeEngineProcessingModule extends Module {
   @Override
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/PurgeCeActivities.java b/server/sonar-server/src/main/java/org/sonar/server/computation/PurgeCeActivities.java
deleted file mode 100644 (file)
index e7856aa..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.computation;
-
-import java.util.Calendar;
-import org.sonar.api.platform.Server;
-import org.sonar.api.platform.ServerStartHandler;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.System2;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-
-@ServerSide
-public class PurgeCeActivities implements ServerStartHandler {
-
-  private static final Logger LOGGER = Loggers.get(PurgeCeActivities.class);
-
-  private final DbClient dbClient;
-  private final System2 system2;
-
-  public PurgeCeActivities(DbClient dbClient, System2 system2) {
-    this.dbClient = dbClient;
-    this.system2 = system2;
-  }
-
-  @Override
-  public void onServerStart(Server server) {
-    DbSession dbSession = dbClient.openSession(false);
-    try {
-      Calendar sixMonthsAgo = Calendar.getInstance();
-      sixMonthsAgo.setTimeInMillis(system2.now());
-      sixMonthsAgo.add(Calendar.DATE, -180);
-
-      LOGGER.info("Delete the Compute Engine tasks created before " + sixMonthsAgo.getTime());
-      dbClient.ceActivityDao().deleteOlderThan(dbSession, sixMonthsAgo.getTimeInMillis());
-      dbSession.commit();
-
-    } finally {
-      dbClient.closeSession(dbSession);
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ReportFiles.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ReportFiles.java
deleted file mode 100644 (file)
index 13ad4bd..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.computation;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.config.Settings;
-import org.sonar.api.server.ServerSide;
-import org.sonar.process.ProcessProperties;
-
-import static java.lang.String.format;
-
-@ServerSide
-public class ReportFiles {
-
-  private static final String ZIP_EXTENSION = "zip";
-
-  private final Settings settings;
-
-  public ReportFiles(Settings settings) {
-    this.settings = settings;
-  }
-
-  public void save(String taskUuid, InputStream reportInput) {
-    File file = fileForUuid(taskUuid);
-    try {
-      FileUtils.copyInputStreamToFile(reportInput, file);
-    } catch (Exception e) {
-      FileUtils.deleteQuietly(file);
-      IOUtils.closeQuietly(reportInput);
-      throw new IllegalStateException(format("Fail to copy report to file: %s", file.getAbsolutePath()), e);
-    }
-  }
-
-  public void deleteIfExists(String taskUuid) {
-    FileUtils.deleteQuietly(fileForUuid(taskUuid));
-  }
-
-  public void deleteAll() {
-    File dir = reportDir();
-    if (dir.exists()) {
-      try {
-        FileUtils.cleanDirectory(dir);
-      } catch (Exception e) {
-        throw new IllegalStateException(format("Fail to clean directory: %s", dir.getAbsolutePath()), e);
-      }
-    }
-  }
-
-  private File reportDir() {
-    return new File(settings.getString(ProcessProperties.PATH_DATA), "ce/reports");
-  }
-
-  /**
-   * The analysis report to be processed. Can't be null
-   * but may no exist on file system.
-   */
-  public File fileForUuid(String taskUuid) {
-    return new File(reportDir(), format("%s.%s", taskUuid, ZIP_EXTENSION));
-  }
-
-  public List<String> listUuids() {
-    List<String> uuids = new ArrayList<>();
-    File dir = reportDir();
-    if (dir.exists()) {
-      Collection<File> files = FileUtils.listFiles(dir, new String[]{ZIP_EXTENSION}, false);
-      for (File file : files) {
-        uuids.add(FilenameUtils.getBaseName(file.getName()));
-      }
-    }
-    return uuids;
-  }
-}
index bea465579420bb64cbc66a1a1672f378b210df50..654f601a5c4f54252edce4360c6af81737de8e14 100644 (file)
@@ -24,8 +24,8 @@ import java.util.List;
 import org.sonar.core.issue.tracking.Tracker;
 import org.sonar.core.platform.ContainerPopulator;
 import org.sonar.server.computation.queue.CeTask;
-import org.sonar.server.computation.ComputationStepExecutor;
-import org.sonar.server.computation.ComputationTempFolderProvider;
+import org.sonar.server.computation.step.ComputationStepExecutor;
+import org.sonar.server.computation.filesystem.ComputationTempFolderProvider;
 import org.sonar.server.computation.analysis.ReportAnalysisMetadataHolder;
 import org.sonar.server.computation.batch.BatchReportDirectoryHolderImpl;
 import org.sonar.server.computation.batch.BatchReportReaderImpl;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/filesystem/ComputationTempFolderProvider.java b/server/sonar-server/src/main/java/org/sonar/server/computation/filesystem/ComputationTempFolderProvider.java
new file mode 100644 (file)
index 0000000..bb70b96
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.computation.filesystem;
+
+import java.io.File;
+import java.io.IOException;
+import javax.annotation.CheckForNull;
+import org.apache.commons.io.FileUtils;
+import org.picocontainer.ComponentLifecycle;
+import org.picocontainer.PicoContainer;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.platform.ServerFileSystem;
+import org.sonar.api.utils.TempFolder;
+import org.sonar.api.utils.internal.DefaultTempFolder;
+
+/**
+ * Provides a TempFolder instance pointing to a directory dedicated to the processing of a specific item.
+ * This directory will be deleted at the end of the processing.
+ * This directory is located in the "ce" directory of the temp directory of the SonarQube instance.
+ */
+public class ComputationTempFolderProvider extends ProviderAdapter implements ComponentLifecycle<TempFolder> {
+  private boolean started = false;
+  @CheckForNull
+  private DefaultTempFolder tempFolder;
+
+  public TempFolder provide(ServerFileSystem fs) {
+    if (this.tempFolder == null) {
+      File tempDir = new File(fs.getTempDir(), "ce");
+      try {
+        FileUtils.forceMkdir(tempDir);
+      } catch (IOException e) {
+        throw new IllegalStateException("Unable to create computation temp directory " + tempDir, e);
+      }
+      File computationDir = new DefaultTempFolder(tempDir).newDir();
+      this.tempFolder = new DefaultTempFolder(computationDir, true);
+    }
+    return this.tempFolder;
+  }
+
+  @Override
+  public void start(PicoContainer container) {
+    this.started = true;
+  }
+
+  @Override
+  public void stop(PicoContainer container) {
+    if (tempFolder != null) {
+      tempFolder.stop();
+    }
+  }
+
+  @Override
+  public void dispose(PicoContainer container) {
+    // nothing to do
+  }
+
+  @Override
+  public boolean componentHasLifecycle() {
+    return true;
+  }
+
+  @Override
+  public boolean isStarted() {
+    return started;
+  }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/filesystem/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/filesystem/package-info.java
new file mode 100644 (file)
index 0000000..6b9cc1e
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.computation.filesystem;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/property/CePropertyDefinitions.java b/server/sonar-server/src/main/java/org/sonar/server/computation/property/CePropertyDefinitions.java
new file mode 100644 (file)
index 0000000..5d6c195
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.computation.property;
+
+import java.util.List;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.PropertyType;
+import org.sonar.api.config.PropertyDefinition;
+import org.sonar.server.computation.log.CeLogging;
+
+import static java.util.Arrays.asList;
+
+public class CePropertyDefinitions {
+  private CePropertyDefinitions() {
+    // only statics
+  }
+
+  public static List<PropertyDefinition> all() {
+    return asList(
+      PropertyDefinition.builder(CeLogging.MAX_LOGS_PROPERTY)
+        .name("Compute Engine Log Retention")
+        .description("Number of tasks to keep logs for a given project. Once the number of logs exceeds this limit, oldest logs are purged.")
+        .type(PropertyType.INTEGER)
+        .defaultValue("10")
+        .category(CoreProperties.CATEGORY_GENERAL)
+        .build());
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/property/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/property/package-info.java
new file mode 100644 (file)
index 0000000..c991dbd
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.computation.property;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 6ac6a8928e4e3b95e997f3b5bcbba2cf4f880f42..8864d422654150a0def5667bf2b2884b0122fa9f 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskTypes;
-import org.sonar.server.computation.ReportFiles;
+import org.sonar.server.computation.queue.report.ReportFiles;
 
 /**
  * Cleans-up the Compute Engine queue and resets the JMX counters.
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/queue/PurgeCeActivities.java b/server/sonar-server/src/main/java/org/sonar/server/computation/queue/PurgeCeActivities.java
new file mode 100644 (file)
index 0000000..e92f7d1
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.computation.queue;
+
+import java.util.Calendar;
+import org.sonar.api.platform.Server;
+import org.sonar.api.platform.ServerStartHandler;
+import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.System2;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+
+@ServerSide
+public class PurgeCeActivities implements ServerStartHandler {
+
+  private static final Logger LOGGER = Loggers.get(PurgeCeActivities.class);
+
+  private final DbClient dbClient;
+  private final System2 system2;
+
+  public PurgeCeActivities(DbClient dbClient, System2 system2) {
+    this.dbClient = dbClient;
+    this.system2 = system2;
+  }
+
+  @Override
+  public void onServerStart(Server server) {
+    DbSession dbSession = dbClient.openSession(false);
+    try {
+      Calendar sixMonthsAgo = Calendar.getInstance();
+      sixMonthsAgo.setTimeInMillis(system2.now());
+      sixMonthsAgo.add(Calendar.DATE, -180);
+
+      LOGGER.info("Delete the Compute Engine tasks created before " + sixMonthsAgo.getTime());
+      dbClient.ceActivityDao().deleteOlderThan(dbSession, sixMonthsAgo.getTimeInMillis());
+      dbSession.commit();
+
+    } finally {
+      dbClient.closeSession(dbSession);
+    }
+  }
+}
index 7a0b38cc8dd24ed720e46a11f586c75eee1a84b3..91978629339d5fb007a40a91bafddb8ac2d59e1b 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.computation.queue.report;
 
 import org.sonar.db.ce.CeActivityDto;
-import org.sonar.server.computation.ReportFiles;
 import org.sonar.server.computation.queue.CeQueueListener;
 import org.sonar.server.computation.queue.CeTask;
 
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/queue/report/ReportFiles.java b/server/sonar-server/src/main/java/org/sonar/server/computation/queue/report/ReportFiles.java
new file mode 100644 (file)
index 0000000..d1a2dac
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.computation.queue.report;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
+import org.sonar.api.config.Settings;
+import org.sonar.api.server.ServerSide;
+import org.sonar.process.ProcessProperties;
+
+import static java.lang.String.format;
+
+@ServerSide
+public class ReportFiles {
+
+  private static final String ZIP_EXTENSION = "zip";
+
+  private final Settings settings;
+
+  public ReportFiles(Settings settings) {
+    this.settings = settings;
+  }
+
+  public void save(String taskUuid, InputStream reportInput) {
+    File file = fileForUuid(taskUuid);
+    try {
+      FileUtils.copyInputStreamToFile(reportInput, file);
+    } catch (Exception e) {
+      FileUtils.deleteQuietly(file);
+      IOUtils.closeQuietly(reportInput);
+      throw new IllegalStateException(format("Fail to copy report to file: %s", file.getAbsolutePath()), e);
+    }
+  }
+
+  public void deleteIfExists(String taskUuid) {
+    FileUtils.deleteQuietly(fileForUuid(taskUuid));
+  }
+
+  public void deleteAll() {
+    File dir = reportDir();
+    if (dir.exists()) {
+      try {
+        FileUtils.cleanDirectory(dir);
+      } catch (Exception e) {
+        throw new IllegalStateException(format("Fail to clean directory: %s", dir.getAbsolutePath()), e);
+      }
+    }
+  }
+
+  private File reportDir() {
+    return new File(settings.getString(ProcessProperties.PATH_DATA), "ce/reports");
+  }
+
+  /**
+   * The analysis report to be processed. Can't be null
+   * but may no exist on file system.
+   */
+  public File fileForUuid(String taskUuid) {
+    return new File(reportDir(), format("%s.%s", taskUuid, ZIP_EXTENSION));
+  }
+
+  public List<String> listUuids() {
+    List<String> uuids = new ArrayList<>();
+    File dir = reportDir();
+    if (dir.exists()) {
+      Collection<File> files = FileUtils.listFiles(dir, new String[]{ZIP_EXTENSION}, false);
+      for (File file : files) {
+        uuids.add(FilenameUtils.getBaseName(file.getName()));
+      }
+    }
+    return uuids;
+  }
+}
index f8489f639bdb57caf490c25c9410372dcee3cfb0..5f5387742caa2679021cddf8f2d5890a12cf5d00 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.server.component.ComponentService;
 import org.sonar.server.component.NewComponent;
-import org.sonar.server.computation.ReportFiles;
 import org.sonar.server.computation.queue.CeQueue;
 import org.sonar.server.computation.queue.CeTask;
 import org.sonar.server.computation.queue.CeTaskSubmit;
index 21b64ed186d52835f4624c56a58f1c6beb73c1bb..ed4693f6d42923823be07814c015117ac65cb488 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.computation.queue.report;
 
 import org.sonar.core.platform.ComponentContainer;
-import org.sonar.server.computation.ComputationStepExecutor;
+import org.sonar.server.computation.step.ComputationStepExecutor;
 import org.sonar.server.computation.container.ComputeEngineContainer;
 import org.sonar.server.computation.container.ContainerFactory;
 import org.sonar.server.computation.queue.CeTask;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputationStepExecutor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputationStepExecutor.java
new file mode 100644 (file)
index 0000000..66dfe3a
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.computation.step;
+
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.core.util.logs.Profiler;
+
+public final class ComputationStepExecutor {
+  private static final Logger LOGGER = Loggers.get(ComputationStepExecutor.class);
+
+  private final ComputationSteps steps;
+
+  public ComputationStepExecutor(ComputationSteps steps) {
+    this.steps = steps;
+  }
+
+  public void execute() {
+    Profiler stepProfiler = Profiler.create(LOGGER);
+    for (ComputationStep step : steps.instances()) {
+      stepProfiler.start();
+      step.execute();
+      stepProfiler.stopInfo(step.getDescription());
+    }
+  }
+}
index 878ee5aeaa53b62ebf330d54267e6be26c490b1e..fad6a3223f7bb9387b82dba36987cae3958f30fc 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.utils.ZipUtils;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.server.computation.queue.CeTask;
-import org.sonar.server.computation.ReportFiles;
+import org.sonar.server.computation.queue.report.ReportFiles;
 import org.sonar.server.computation.batch.MutableBatchReportDirectoryHolder;
 
 /**
index 1c755e96f51ce0ed3fca2bbf7f658311982b86bf..1418ce274b3c32e545f858b85f8b27b9b0c25393 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.db.semaphore.SemaphoresImpl;
 import org.sonar.db.version.DatabaseVersion;
 import org.sonar.db.version.MigrationStepModule;
-import org.sonar.server.computation.CePropertyDefinitions;
+import org.sonar.server.computation.property.CePropertyDefinitions;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.db.EmbeddedDatabaseFactory;
 import org.sonar.server.issue.index.IssueIndex;
index efacdd7b99bd917f5071feb33216f26b451f10d5..fee9b4782184b4d903709ced37e8455ad231b64b 100644 (file)
@@ -67,7 +67,7 @@ import org.sonar.server.computation.queue.CeQueueCleaner;
 import org.sonar.server.computation.queue.CeQueueInitializer;
 import org.sonar.server.computation.queue.report.CleanReportQueueListener;
 import org.sonar.server.computation.ComputeEngineProcessingModule;
-import org.sonar.server.computation.ReportFiles;
+import org.sonar.server.computation.queue.report.ReportFiles;
 import org.sonar.server.computation.queue.report.ReportSubmitter;
 import org.sonar.server.computation.dbcleaner.IndexPurgeListener;
 import org.sonar.server.computation.dbcleaner.ProjectCleaner;
index 5f94331b0b9d2e14f64d156657096caee4639004..2d8da8594b29926586b9ef27a65bb01cd53d05f7 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.platform.platformlevel;
 
-import org.sonar.server.computation.PurgeCeActivities;
+import org.sonar.server.computation.queue.PurgeCeActivities;
 import org.sonar.server.issue.filter.RegisterIssueFilters;
 import org.sonar.server.platform.ServerLifecycleNotifier;
 import org.sonar.server.qualitygate.RegisterQualityGates;
index 1d2deab9ae00c19fa797dc8b7fbe03a7aa414345..9814b1dff915559cca93047b5b6e7dcdc40a7207 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.computation;
 
 import org.junit.Test;
+import org.sonar.server.computation.property.CePropertyDefinitions;
 import org.sonar.test.TestUtils;
 
 import static org.assertj.core.api.Assertions.assertThat;
index a79936137e33b61b684c9dd2b38bd748fb36e601..b31ae60d2a6fc0b5c8a29266b1fe4ca5ad982aee 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.api.utils.internal.TestSystem2;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
+import org.sonar.server.computation.queue.PurgeCeActivities;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index b8a8a5a46139af7cb0691d20baa08bebc386bdf3..c02db55ae093de189b93c0d3fc2072b849d89e56 100644 (file)
@@ -29,6 +29,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.config.Settings;
 import org.sonar.process.ProcessProperties;
+import org.sonar.server.computation.queue.report.ReportFiles;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
index 2aecacba19cbbfec8d35fb89daf777712a400b58..bcf86e350742bb39f55a5f586dafed8d6fec4979 100644 (file)
@@ -31,9 +31,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskTypes;
-import org.sonar.server.computation.ReportFiles;
-import org.sonar.server.computation.queue.CeQueueCleaner;
-import org.sonar.server.computation.queue.CeQueueImpl;
+import org.sonar.server.computation.queue.report.ReportFiles;
 
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
index 79c30700f1217c0cfeb37fd736fb76dde890f9bb..9c09fe0610baaeb3b99c4cf553fb089e7f75b545 100644 (file)
@@ -31,12 +31,9 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskTypes;
-import org.sonar.server.computation.ReportFiles;
+import org.sonar.server.computation.queue.report.ReportFiles;
 import org.sonar.server.computation.monitoring.CEQueueStatus;
 import org.sonar.server.computation.monitoring.CEQueueStatusImpl;
-import org.sonar.server.computation.queue.CeProcessingScheduler;
-import org.sonar.server.computation.queue.CeQueueCleaner;
-import org.sonar.server.computation.queue.CeQueueInitializer;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.any;
index 6bd893f4677bdf3b6751c6dc3cae367a5cafa213..83e3d34b396af6cfbdb14b5e9bfb9dde78cb8377 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.computation.queue.report;
 import org.junit.Test;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeTaskTypes;
-import org.sonar.server.computation.ReportFiles;
 import org.sonar.server.computation.queue.CeTask;
 
 import static org.mockito.Mockito.mock;
index 14a43069951445fafdc8bef0a386219bc379a37a..3ccd758453bc4ce8decd70ec138bb9a5802a77a0 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.server.component.ComponentService;
 import org.sonar.server.component.NewComponent;
-import org.sonar.server.computation.ReportFiles;
 import org.sonar.server.computation.queue.CeQueue;
 import org.sonar.server.computation.queue.CeQueueImpl;
 import org.sonar.server.computation.queue.CeTaskSubmit;