@@ -25,6 +25,7 @@ import java.util.Optional; | |||
import javax.annotation.Nullable; | |||
import org.sonar.ce.task.CeTask; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.ce.CeActivityDto; | |||
import org.sonar.db.ce.CeQueueDto; | |||
/** | |||
@@ -112,6 +113,16 @@ public interface CeQueue { | |||
WorkersPauseStatus getWorkersPauseStatus(); | |||
/** | |||
* Removes all the tasks from the queue, whatever their status. They are marked | |||
* as {@link CeActivityDto.Status#CANCELED} in past activity. | |||
* This method can NOT be called when workers are being executed, as in progress | |||
* tasks can't be killed. | |||
* | |||
* @return the number of canceled tasks | |||
*/ | |||
int clear(); | |||
enum SubmitOption { | |||
UNIQUE_QUEUE_PER_MAIN_COMPONENT | |||
} |
@@ -340,6 +340,11 @@ public class CeQueueImpl implements CeQueue { | |||
} | |||
} | |||
@Override | |||
public int clear() { | |||
return cancelAll(true); | |||
} | |||
CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable ComponentDto mainComponent) { | |||
CeTask.Builder builder = new CeTask.Builder() | |||
.setUuid(taskDto.getUuid()) |
@@ -59,7 +59,6 @@ import org.sonar.ce.monitoring.DistributedCEQueueStatusImpl; | |||
import org.sonar.ce.platform.CECoreExtensionsInstaller; | |||
import org.sonar.ce.platform.ComputeEngineExtensionInstaller; | |||
import org.sonar.ce.platform.DatabaseCompatibility; | |||
import org.sonar.ce.queue.CeQueueCleaner; | |||
import org.sonar.ce.queue.PurgeCeActivities; | |||
import org.sonar.ce.task.projectanalysis.ProjectAnalysisTaskModule; | |||
import org.sonar.ce.task.projectanalysis.analysis.ProjectConfigurationFactory; | |||
@@ -117,7 +116,6 @@ import org.sonar.server.notification.email.EmailNotificationChannel; | |||
import org.sonar.server.organization.BillingValidationsProxyImpl; | |||
import org.sonar.server.organization.DefaultOrganizationProviderImpl; | |||
import org.sonar.server.organization.OrganizationFlagsImpl; | |||
import org.sonar.server.platform.DefaultServerUpgradeStatus; | |||
import org.sonar.server.platform.OfficialDistribution; | |||
import org.sonar.server.platform.ServerFileSystemImpl; | |||
import org.sonar.server.platform.ServerImpl; | |||
@@ -330,7 +328,6 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { | |||
// add ReadOnlyPropertiesDao at level2 again so that it shadows PropertiesDao | |||
ReadOnlyPropertiesDao.class, | |||
DefaultServerUpgradeStatus.class, | |||
// plugins | |||
PluginClassloaderFactory.class, | |||
@@ -485,8 +482,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { | |||
private static Object[] startupComponents() { | |||
return new Object[] { | |||
ServerLifecycleNotifier.class, | |||
PurgeCeActivities.class, | |||
CeQueueCleaner.class | |||
PurgeCeActivities.class | |||
}; | |||
} | |||
@@ -49,16 +49,6 @@ public interface InternalCeQueue extends CeQueue { | |||
*/ | |||
Optional<CeTask> peek(String workerUuid); | |||
/** | |||
* Removes all the tasks from the queue, whatever their status. They are marked | |||
* as {@link Status#CANCELED} in past activity. | |||
* This method can NOT be called when workers are being executed, as in progress | |||
* tasks can't be killed. | |||
* | |||
* @return the number of canceled tasks | |||
*/ | |||
int clear(); | |||
/** | |||
* Removes a task from the queue and registers it to past activities. This method | |||
* is called by Compute Engine workers when task is processed and can include an option {@link CeTaskResult} object. |
@@ -103,11 +103,6 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue | |||
} | |||
} | |||
@Override | |||
public int clear() { | |||
return cancelAll(true); | |||
} | |||
@Override | |||
public void remove(CeTask task, CeActivityDto.Status status, @Nullable CeTaskResult taskResult, @Nullable Throwable error) { | |||
checkArgument(error == null || status == CeActivityDto.Status.FAILED, "Error can be provided only when status is FAILED"); |
@@ -123,7 +123,7 @@ public class ComputeEngineContainerImplTest { | |||
assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize( | |||
CONTAINER_ITSELF | |||
+ 25 // MigrationConfigurationModule | |||
+ 17 // level 2 | |||
+ 16 // level 2 | |||
); | |||
assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize( | |||
COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION |
@@ -17,34 +17,34 @@ | |||
* 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.queue; | |||
package org.sonar.server.ce.queue; | |||
import java.util.List; | |||
import org.picocontainer.Startable; | |||
import org.sonar.api.ce.ComputeEngineSide; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.platform.ServerUpgradeStatus; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.ce.queue.CeQueue; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.process.ProcessProperties; | |||
/** | |||
* Cleans-up the Compute Engine queue. | |||
* CE workers must not be started before execution of this class. | |||
*/ | |||
@ComputeEngineSide | |||
@ServerSide | |||
public class CeQueueCleaner implements Startable { | |||
private static final Logger LOGGER = Loggers.get(CeQueueCleaner.class); | |||
private final DbClient dbClient; | |||
private final ServerUpgradeStatus serverUpgradeStatus; | |||
private final InternalCeQueue queue; | |||
private final CeQueue queue; | |||
private final Configuration configuration; | |||
public CeQueueCleaner(DbClient dbClient, ServerUpgradeStatus serverUpgradeStatus, InternalCeQueue queue, Configuration configuration) { | |||
public CeQueueCleaner(DbClient dbClient, ServerUpgradeStatus serverUpgradeStatus, CeQueue queue, Configuration configuration) { | |||
this.dbClient = dbClient; | |||
this.serverUpgradeStatus = serverUpgradeStatus; | |||
this.queue = queue; |
@@ -23,6 +23,7 @@ import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.core.platform.EditionProvider; | |||
import org.sonar.core.platform.PlatformEditionProvider; | |||
import org.sonar.server.app.ProcessCommandWrapper; | |||
import org.sonar.server.ce.queue.CeQueueCleaner; | |||
import org.sonar.server.es.IndexerStartupTask; | |||
import org.sonar.server.organization.DefaultOrganizationEnforcer; | |||
import org.sonar.server.platform.ServerLifecycleNotifier; | |||
@@ -68,7 +69,8 @@ public class PlatformLevelStartup extends PlatformLevel { | |||
BuiltInQProfileUpdateImpl.class, | |||
RegisterQualityProfiles.class, | |||
RegisterPermissionTemplates.class, | |||
RenameDeprecatedPropertyKeys.class); | |||
RenameDeprecatedPropertyKeys.class, | |||
CeQueueCleaner.class); | |||
// RegisterServletFilters makes the WebService engine of Level4 served by the MasterServletFilter, therefor it | |||
// must be started after all the other startup tasks |
@@ -17,7 +17,7 @@ | |||
* 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.queue; | |||
package org.sonar.server.ce.queue; | |||
import java.util.Optional; | |||
import org.apache.commons.io.IOUtils; | |||
@@ -26,6 +26,7 @@ import org.junit.Test; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.platform.ServerUpgradeStatus; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.queue.CeQueue; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.ce.CeQueueDto; | |||
import org.sonar.db.ce.CeTaskInputDao; | |||
@@ -44,7 +45,7 @@ public class CeQueueCleanerTest { | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
private ServerUpgradeStatus serverUpgradeStatus = mock(ServerUpgradeStatus.class); | |||
private InternalCeQueue queue = mock(InternalCeQueue.class); | |||
private CeQueue queue = mock(CeQueue.class); | |||
private MapSettings settings = new MapSettings(); | |||
@Test |