From 67147057b804248ee897adf2a86e8895f8b1c30e Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 3 Dec 2015 10:41:44 +0100 Subject: [PATCH] SONAR-7104 CeTaskProcessor#process now returns a CeTaskResult --- .../computation/queue/CeTaskResult.java | 35 +++++++++++++++++++ .../taskprocessor/CeTaskProcessor.java | 5 ++- .../report/ReportTaskProcessor.java | 4 ++- .../CeTaskProcessorRepositoryImplTest.java | 3 +- .../CeTaskProcessorRepositoryRule.java | 3 +- 5 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeTaskResult.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeTaskResult.java b/server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeTaskResult.java new file mode 100644 index 00000000000..e84780fd2f2 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeTaskResult.java @@ -0,0 +1,35 @@ +/* + * 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 javax.annotation.CheckForNull; + +/** + * Represents the result of the processing of a {@link CeTask}. + * + * @see {@link org.sonar.server.computation.taskprocessor.CeTaskProcessor#process(CeTask)} + */ +public interface CeTaskResult { + /** + * The id of the snapshot created, if any, for the Component in {@link CeTask} + */ + @CheckForNull + Long getSnapshotId(); +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/CeTaskProcessor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/CeTaskProcessor.java index 16edeb61f1d..ea98cae3a8b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/CeTaskProcessor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/CeTaskProcessor.java @@ -20,7 +20,9 @@ package org.sonar.server.computation.taskprocessor; import java.util.Set; +import javax.annotation.CheckForNull; import org.sonar.server.computation.queue.CeTask; +import org.sonar.server.computation.queue.CeTaskResult; /** * This interface is used to provide the processing code for {@link CeTask}s of one or more type to be called by the @@ -51,5 +53,6 @@ public interface CeTaskProcessor { * @throws RuntimeException when thrown, it will be caught and logged by the Compute Engine and the processing of the * specified {@link CeTask} will be flagged as failed. */ - void process(CeTask task); + @CheckForNull + CeTaskResult process(CeTask task); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/report/ReportTaskProcessor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/report/ReportTaskProcessor.java index 8bb70587108..db4fd635f88 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/report/ReportTaskProcessor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/report/ReportTaskProcessor.java @@ -27,6 +27,7 @@ import org.sonar.db.ce.CeTaskTypes; import org.sonar.server.computation.container.ComputeEngineContainer; import org.sonar.server.computation.container.ContainerFactory; import org.sonar.server.computation.queue.CeTask; +import org.sonar.server.computation.queue.CeTaskResult; import org.sonar.server.computation.step.ComputationStepExecutor; import org.sonar.server.computation.taskprocessor.CeTaskProcessor; import org.sonar.server.devcockpit.DevCockpitBridge; @@ -64,10 +65,11 @@ public class ReportTaskProcessor implements CeTaskProcessor { } @Override - public void process(CeTask task) { + public CeTaskResult process(CeTask task) { ComputeEngineContainer ceContainer = containerFactory.create(serverContainer, task, devCockpitBridge); try { ceContainer.getComponentByType(ComputationStepExecutor.class).execute(); + return null; } finally { ceContainer.cleanup(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/taskprocessor/CeTaskProcessorRepositoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/taskprocessor/CeTaskProcessorRepositoryImplTest.java index 6b865959f86..b9fc98ad9f0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/taskprocessor/CeTaskProcessorRepositoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/taskprocessor/CeTaskProcessorRepositoryImplTest.java @@ -25,6 +25,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.server.computation.queue.CeTask; +import org.sonar.server.computation.queue.CeTaskResult; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -126,7 +127,7 @@ public class CeTaskProcessorRepositoryImplTest { } @Override - public void process(CeTask task) { + public CeTaskResult process(CeTask task) { throw new UnsupportedOperationException("Process is not implemented"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/taskprocessor/CeTaskProcessorRepositoryRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/taskprocessor/CeTaskProcessorRepositoryRule.java index 02932ed07b2..1c246b013b7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/taskprocessor/CeTaskProcessorRepositoryRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/taskprocessor/CeTaskProcessorRepositoryRule.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import org.junit.rules.ExternalResource; import org.sonar.server.computation.queue.CeTask; +import org.sonar.server.computation.queue.CeTaskResult; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; @@ -70,7 +71,7 @@ public class CeTaskProcessorRepositoryRule extends ExternalResource implements C } @Override - public void process(CeTask task) { + public CeTaskResult process(CeTask task) { throw new UnsupportedOperationException(UOE_MESSAGE); } } -- 2.39.5