From: Stephane Gamard Date: Wed, 30 Apr 2014 07:33:37 +0000 (+0200) Subject: SONAR-5237 - Rename ClusterAction to QueueAction X-Git-Tag: 4.4-RC1~1327 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c856282f033d4360ae7315d60d25886413b341b9;p=sonarqube.git SONAR-5237 - Rename ClusterAction to QueueAction --- diff --git a/sonar-core/src/main/java/org/sonar/core/cluster/ClusterAction.java b/sonar-core/src/main/java/org/sonar/core/cluster/ClusterAction.java deleted file mode 100644 index c40526345fb..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/cluster/ClusterAction.java +++ /dev/null @@ -1,49 +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.core.cluster; - -import java.util.concurrent.CountDownLatch; - -public abstract class ClusterAction implements Runnable { - - private CountDownLatch latch; - - public ClusterAction(CountDownLatch latch){ - this.latch = latch; - } - - public ClusterAction() { - this.latch = null; - } - - public void setLatch(CountDownLatch latch){ - this.latch = latch; - } - - public abstract void doExecute(); - - @Override - public void run(){ - this.doExecute(); - if(latch != null){ - latch.countDown(); - } - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/cluster/NullQueue.java b/sonar-core/src/main/java/org/sonar/core/cluster/NullQueue.java index 54df2784faa..4e1aebf0043 100644 --- a/sonar-core/src/main/java/org/sonar/core/cluster/NullQueue.java +++ b/sonar-core/src/main/java/org/sonar/core/cluster/NullQueue.java @@ -24,12 +24,12 @@ package org.sonar.core.cluster; public class NullQueue implements WorkQueue { @Override - public void enqueue(ClusterAction action) { + public void enqueue(QueueAction action) { } @Override - public void enqueue(Iterable actions) { + public void enqueue(Iterable actions) { } } diff --git a/sonar-core/src/main/java/org/sonar/core/cluster/QueueAction.java b/sonar-core/src/main/java/org/sonar/core/cluster/QueueAction.java new file mode 100644 index 00000000000..60b31ee6baa --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/cluster/QueueAction.java @@ -0,0 +1,49 @@ +/* + * 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.core.cluster; + +import java.util.concurrent.CountDownLatch; + +public abstract class QueueAction implements Runnable { + + private CountDownLatch latch; + + public QueueAction(CountDownLatch latch){ + this.latch = latch; + } + + public QueueAction() { + this.latch = null; + } + + public void setLatch(CountDownLatch latch){ + this.latch = latch; + } + + public abstract void doExecute(); + + @Override + public void run(){ + this.doExecute(); + if(latch != null){ + latch.countDown(); + } + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java b/sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java index cee9c63265e..c75d5b38e3b 100644 --- a/sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java +++ b/sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java @@ -19,17 +19,14 @@ */ package org.sonar.core.cluster; -import org.sonar.core.db.Dto; - -import java.io.Serializable; public interface WorkQueue { - void enqueue(ClusterAction action); + void enqueue(QueueAction action); - void enqueue(Iterable actions); + void enqueue(Iterable actions); /* This is because of core vs server packages... */ // void enqueue(ClusterAction.Type type, ClusterAction.Method method, String ref, Serializable key); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DbSession.java b/sonar-core/src/main/java/org/sonar/core/persistence/DbSession.java index 7653f694696..3e9ee5a996c 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DbSession.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DbSession.java @@ -26,7 +26,7 @@ import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.core.cluster.ClusterAction; +import org.sonar.core.cluster.QueueAction; import org.sonar.core.cluster.WorkQueue; import java.sql.Connection; @@ -39,7 +39,7 @@ public class DbSession implements SqlSession { private static final Logger LOG = LoggerFactory.getLogger(DbSession.class); - private List actions; + private List actions; private WorkQueue queue; private SqlSession session; @@ -47,16 +47,16 @@ public class DbSession implements SqlSession { DbSession(WorkQueue queue, SqlSession session) { this.session = session; this.queue = queue; - this.actions = new ArrayList(); + this.actions = new ArrayList(); } - public void enqueue(ClusterAction action) { + public void enqueue(QueueAction action) { this.actions.add(action); } private void enqueueActions(){ CountDownLatch latch = new CountDownLatch(actions.size()); - for(ClusterAction action:actions){ + for(QueueAction action:actions){ action.setLatch(latch); queue.enqueue(action); } diff --git a/sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java b/sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java index dc2e29f2247..8afcdb10c64 100644 --- a/sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java +++ b/sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java @@ -20,7 +20,7 @@ package org.sonar.server.cluster; import org.sonar.api.ServerComponent; -import org.sonar.core.cluster.ClusterAction; +import org.sonar.core.cluster.QueueAction; import org.sonar.core.cluster.WorkQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -34,7 +34,7 @@ public class LocalNonBlockingWorkQueue extends LinkedBlockingQueue } @Override - public void enqueue(ClusterAction action) { + public void enqueue(QueueAction action) { try { this.offer(action, 1000,TimeUnit.SECONDS); } catch (InterruptedException e) { @@ -43,8 +43,8 @@ public class LocalNonBlockingWorkQueue extends LinkedBlockingQueue } @Override - public void enqueue(Iterable actions) { - for (ClusterAction action : actions) { + public void enqueue(Iterable actions) { + for (QueueAction action : actions) { enqueue(action); } } diff --git a/sonar-server/src/main/java/org/sonar/server/cluster/LocalQueueWorker.java b/sonar-server/src/main/java/org/sonar/server/cluster/LocalQueueWorker.java index 1cbc2a9b440..ba4c60ff7b0 100644 --- a/sonar-server/src/main/java/org/sonar/server/cluster/LocalQueueWorker.java +++ b/sonar-server/src/main/java/org/sonar/server/cluster/LocalQueueWorker.java @@ -60,6 +60,7 @@ public class LocalQueueWorker extends ThreadPoolExecutor protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); + //TODO throw throwable } @Override diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java index c3633d38c55..5aa76480e8a 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java +++ b/sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java @@ -20,7 +20,7 @@ package org.sonar.server.rule2; import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; +import org.sonar.api.rule.RuleStatus; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.server.search.Hit; @@ -64,14 +64,13 @@ public class RuleImpl implements Rule { } @Override - public Severity severity() { - //FIXME missign Severity.of(String) or Severity.of(int); - return null; + public String severity() { + return (String) this.fields.get("severity"); } @Override - public String status() { - return (String) this.fields.get("status"); + public RuleStatus status() { + return RuleStatus.valueOf( (String) this.fields.get("status")); } @Override @@ -86,6 +85,12 @@ public class RuleImpl implements Rule { return (List) this.fields.get("tags"); } + @Override + @SuppressWarnings("unchecked") + public List systemTags() { + return (List) this.fields.get("systemTags"); + } + @Override public List params() { //FIXME not yet Implemented in ES @@ -121,5 +126,4 @@ public class RuleImpl implements Rule { public static Rule fromHit(Hit hit) { return new RuleImpl(hit.getFields()); } - } diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java index e7916ca6402..339df70ac82 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java @@ -162,23 +162,6 @@ public abstract class BaseIndex> implem } } - /* Index Action Methods */ - - @Override - public boolean executeAction(IndexAction action) { - long start = System.currentTimeMillis(); - if (action.getMethod().equals(Method.DELETE)) { - this.delete(action.getKey()); - } else if (action.getMethod().equals(Method.INSERT)) { - this.insert(action.getKey()); - } else if (action.getMethod().equals(Method.UPDATE)) { - this.update(action.getKey()); - } - LOG.debug("Action {} in {} took {}ms", action.getMethod(), - this.getIndexName(), (System.currentTimeMillis() - start)); - return true; - } - /* Index management methods */ protected abstract XContentBuilder getIndexSettings(); diff --git a/sonar-server/src/main/java/org/sonar/server/search/Index.java b/sonar-server/src/main/java/org/sonar/server/search/Index.java index d0046510e79..b81427f9b0c 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/Index.java +++ b/sonar-server/src/main/java/org/sonar/server/search/Index.java @@ -29,8 +29,6 @@ public interface Index extends Startable { String getIndexName(); - boolean executeAction(IndexAction action); - @CheckForNull Hit getByKey(K key); diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexAction.java b/sonar-server/src/main/java/org/sonar/server/search/IndexAction.java index c882941fe65..0ab9744a2f3 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/IndexAction.java +++ b/sonar-server/src/main/java/org/sonar/server/search/IndexAction.java @@ -19,11 +19,16 @@ */ package org.sonar.server.search; -import org.sonar.core.cluster.ClusterAction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.core.cluster.QueueAction; import java.io.Serializable; -public class IndexAction extends ClusterAction { +public class IndexAction extends QueueAction { + + private static final Logger LOG = LoggerFactory.getLogger(IndexAction.class); + public enum Method { INSERT, UPDATE, DELETE @@ -68,7 +73,17 @@ public class IndexAction extends ClusterAction { @Override public void doExecute() { - index.executeAction(this); + long start = System.currentTimeMillis(); + if (this.getMethod().equals(Method.DELETE)) { + index.delete(this.getKey()); + } else if (this.getMethod().equals(Method.INSERT)) { + index.insert(this.getKey()); + } else if (this.getMethod().equals(Method.UPDATE)) { + index.update(this.getKey()); + } + //TODO execute ACtion when DTO available + LOG.debug("Action {} in {} took {}ms", this.getMethod(), + this.getIndexName(), (System.currentTimeMillis() - start)); } @SuppressWarnings("unchecked")