Skip to content

Commit

Permalink
SONAR-6589 remove ComputationContainer (and use only CEContainer)
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb committed Jun 1, 2015
1 parent be8707e commit 71aa316
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 282 deletions.

This file was deleted.

Expand Up @@ -25,7 +25,7 @@
import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler; import org.sonar.api.utils.log.Profiler;
import org.sonar.server.computation.activity.CEActivityManager; import org.sonar.server.computation.activity.ActivityManager;
import org.sonar.server.computation.batch.BatchReportReader; import org.sonar.server.computation.batch.BatchReportReader;
import org.sonar.server.computation.component.ComponentTreeBuilders; import org.sonar.server.computation.component.ComponentTreeBuilders;
import org.sonar.server.computation.language.LanguageRepository; import org.sonar.server.computation.language.LanguageRepository;
Expand All @@ -44,12 +44,12 @@ public class ComputationService {
private final ReportQueue.Item item; private final ReportQueue.Item item;
private final ComputationSteps steps; private final ComputationSteps steps;
private final BatchReportReader reportReader; private final BatchReportReader reportReader;
private final CEActivityManager activityManager; private final ActivityManager activityManager;
private final System2 system; private final System2 system;
private final DbClient dbClient; private final DbClient dbClient;
private final LanguageRepository languageRepository; private final LanguageRepository languageRepository;


public ComputationService(ReportQueue.Item item, ComputationSteps steps, CEActivityManager activityManager, System2 system, public ComputationService(ReportQueue.Item item, ComputationSteps steps, ActivityManager activityManager, System2 system,
BatchReportReader reportReader, DbClient dbClient, LanguageRepository languageRepository) { BatchReportReader reportReader, DbClient dbClient, LanguageRepository languageRepository) {
this.item = item; this.item = item;
this.steps = steps; this.steps = steps;
Expand Down
Expand Up @@ -20,9 +20,11 @@


package org.sonar.server.computation; package org.sonar.server.computation;


import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Loggers;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.server.computation.container.ComputeEngineContainer;
import org.sonar.server.computation.container.ContainerFactory;


/** /**
* This thread pops a report from the queue and integrate it. * This thread pops a report from the queue and integrate it.
Expand All @@ -32,17 +34,13 @@ public class ComputationThread implements Runnable {
private static final Logger LOG = Loggers.get(ComputationThread.class); private static final Logger LOG = Loggers.get(ComputationThread.class);


private final ReportQueue queue; private final ReportQueue queue;
private final ComputationContainer container; private final ComponentContainer sqContainer;
private final ContainerFactory containerFactory;


public ComputationThread(ReportQueue queue) { public ComputationThread(ReportQueue queue, ComponentContainer sqContainer, ContainerFactory containerFactory) {
this.queue = queue; this.queue = queue;
this.container = new ComputationContainer(); this.sqContainer = sqContainer;
} this.containerFactory = containerFactory;

@VisibleForTesting
ComputationThread(ReportQueue queue, ComputationContainer container) {
this.queue = queue;
this.container = container;
} }


@Override @Override
Expand All @@ -53,15 +51,20 @@ public void run() {
} catch (Exception e) { } catch (Exception e) {
LOG.error("Failed to pop the queue of analysis reports", e); LOG.error("Failed to pop the queue of analysis reports", e);
} }
if (item != null) { if (item == null) {
try { return;
container.execute(item); }
} catch (Throwable e) {
LOG.error(String.format( ComputeEngineContainer computeEngineContainer = containerFactory.create(sqContainer, item);
"Failed to process analysis report %d of project %s", item.dto.getId(), item.dto.getProjectKey()), e); try {
} finally { computeEngineContainer.process();
removeSilentlyFromQueue(item); } catch (Throwable e) {
} LOG.error(String.format(
"Failed to process analysis report %d of project %s", item.dto.getId(), item.dto.getProjectKey()), e);
} finally {
computeEngineContainer.cleanup();

removeSilentlyFromQueue(item);
} }
} }


Expand Down
Expand Up @@ -22,38 +22,47 @@


import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.picocontainer.Startable;
import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerStartHandler;

import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.picocontainer.Startable;
import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerStartHandler;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.server.computation.container.ContainerFactory;
import org.sonar.server.computation.container.ContainerFactoryImpl;


public class ComputationThreadLauncher implements Startable, ServerStartHandler { public class ComputationThreadLauncher implements Startable, ServerStartHandler {


public static final String THREAD_NAME_PREFIX = "computation-"; public static final String THREAD_NAME_PREFIX = "computation-";


private final ReportQueue queue; private final ReportQueue queue;
private final ComponentContainer sqContainer;
private final ScheduledExecutorService executorService; private final ScheduledExecutorService executorService;
private final ContainerFactory containerFactory;


private final long delayBetweenTasks; private final long delayBetweenTasks;
private final long delayForFirstStart; private final long delayForFirstStart;
private final TimeUnit timeUnit; private final TimeUnit timeUnit;


public ComputationThreadLauncher(ReportQueue queue) { public ComputationThreadLauncher(ReportQueue queue, ComponentContainer sqContainer) {
this.queue = queue; this.queue = queue;
this.sqContainer = sqContainer;
this.executorService = Executors.newSingleThreadScheduledExecutor(newThreadFactory()); this.executorService = Executors.newSingleThreadScheduledExecutor(newThreadFactory());
this.containerFactory = new ContainerFactoryImpl();


this.delayBetweenTasks = 10; this.delayBetweenTasks = 10;
this.delayForFirstStart = 0; this.delayForFirstStart = 0;
this.timeUnit = TimeUnit.SECONDS; this.timeUnit = TimeUnit.SECONDS;
} }


@VisibleForTesting @VisibleForTesting
ComputationThreadLauncher(ReportQueue queue, long delayForFirstStart, long delayBetweenTasks, TimeUnit timeUnit) { ComputationThreadLauncher(ReportQueue queue, ComponentContainer sqContainer, ContainerFactory containerFactory,
long delayForFirstStart, long delayBetweenTasks, TimeUnit timeUnit) {
this.queue = queue; this.queue = queue;
this.sqContainer = sqContainer;
this.containerFactory = containerFactory;
this.executorService = Executors.newSingleThreadScheduledExecutor(newThreadFactory()); this.executorService = Executors.newSingleThreadScheduledExecutor(newThreadFactory());


this.delayBetweenTasks = delayBetweenTasks; this.delayBetweenTasks = delayBetweenTasks;
Expand All @@ -72,12 +81,12 @@ public void stop() {
} }


public void startAnalysisTaskNow() { public void startAnalysisTaskNow() {
executorService.execute(new ComputationThread(queue)); executorService.execute(new ComputationThread(queue, sqContainer, containerFactory));
} }


@Override @Override
public void onServerStart(Server server) { public void onServerStart(Server server) {
executorService.scheduleAtFixedRate(new ComputationThread(queue), delayForFirstStart, delayBetweenTasks, timeUnit); executorService.scheduleAtFixedRate(new ComputationThread(queue, sqContainer, containerFactory), delayForFirstStart, delayBetweenTasks, timeUnit);
} }


private ThreadFactory newThreadFactory() { private ThreadFactory newThreadFactory() {
Expand Down
Expand Up @@ -31,11 +31,11 @@
import static org.sonar.api.utils.DateUtils.formatDateTimeNullSafe; import static org.sonar.api.utils.DateUtils.formatDateTimeNullSafe;
import static org.sonar.api.utils.DateUtils.longToDate; import static org.sonar.api.utils.DateUtils.longToDate;


public class CEActivityManager { public class ActivityManager {
private final ActivityService activityService; private final ActivityService activityService;
private final DbClient dbClient; private final DbClient dbClient;


public CEActivityManager(ActivityService activityService, DbClient dbClient) { public ActivityManager(ActivityService activityService, DbClient dbClient) {
this.activityService = activityService; this.activityService = activityService;
this.dbClient = dbClient; this.dbClient = dbClient;
} }
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException;
import javax.annotation.CheckForNull; import javax.annotation.CheckForNull;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
Expand All @@ -35,10 +36,10 @@
import org.sonar.server.computation.ReportQueue; import org.sonar.server.computation.ReportQueue;
import org.sonar.server.util.CloseableIterator; import org.sonar.server.util.CloseableIterator;


public class CEBatchReportReader implements BatchReportReader { public class BatchReportReaderImpl implements BatchReportReader {
private final org.sonar.batch.protocol.output.BatchReportReader delegate; private final org.sonar.batch.protocol.output.BatchReportReader delegate;


public CEBatchReportReader(ReportExtractor reportExtractor, ReportQueue.Item item) { public BatchReportReaderImpl(ReportExtractor reportExtractor, ReportQueue.Item item) {
this.delegate = new org.sonar.batch.protocol.output.BatchReportReader(reportExtractor.extractReportInDir(item)); this.delegate = new org.sonar.batch.protocol.output.BatchReportReader(reportExtractor.extractReportInDir(item));
} }


Expand Down Expand Up @@ -132,10 +133,16 @@ public boolean hasNext() {
} }


@Override @Override
protected String doNext() { public String next() {
return lineIterator.next(); return lineIterator.next();
} }


@Override
protected String doNext() {
// never called anyway
throw new NoSuchElementException("Empty closeable Iterator has no element");
}

@Override @Override
protected void doClose() throws Exception { protected void doClose() throws Exception {
lineIterator.close(); lineIterator.close();
Expand Down

This file was deleted.

0 comments on commit 71aa316

Please sign in to comment.