]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5237 - Rename ClusterAction to QueueAction
authorStephane Gamard <stephane.gamard@searchbox.com>
Wed, 30 Apr 2014 07:33:37 +0000 (09:33 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Wed, 30 Apr 2014 08:31:17 +0000 (10:31 +0200)
sonar-core/src/main/java/org/sonar/core/cluster/ClusterAction.java [deleted file]
sonar-core/src/main/java/org/sonar/core/cluster/NullQueue.java
sonar-core/src/main/java/org/sonar/core/cluster/QueueAction.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java
sonar-core/src/main/java/org/sonar/core/persistence/DbSession.java
sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java
sonar-server/src/main/java/org/sonar/server/cluster/LocalQueueWorker.java
sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java
sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
sonar-server/src/main/java/org/sonar/server/search/Index.java
sonar-server/src/main/java/org/sonar/server/search/IndexAction.java

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 (file)
index c405263..0000000
+++ /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();
-    }
-  }
-}
index 54df2784faa569ed9b67ddf8519250e98e61d834..4e1aebf00439e39d7c720204acfe90eca54d83c3 100644 (file)
@@ -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<ClusterAction> actions) {
+  public void enqueue(Iterable<QueueAction> 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 (file)
index 0000000..60b31ee
--- /dev/null
@@ -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();
+    }
+  }
+}
index cee9c63265e1d214dcd139bc964e0f97cfa5e25b..c75d5b38e3b04e03405deccd617cd3f5db5e458f 100644 (file)
  */
 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<ClusterAction> actions);
+  void enqueue(Iterable<QueueAction> actions);
 
   /* This is because of core vs server packages... */
 //  void enqueue(ClusterAction.Type type, ClusterAction.Method method, String ref, Serializable key);
index 7653f69469660b0bfb379ad060be69c70bbf7167..3e9ee5a996c0e61f9fe17bb50b84824a7b792b2f 100644 (file)
@@ -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<ClusterAction> actions;
+  private List<QueueAction> 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<ClusterAction>();
+    this.actions = new ArrayList<QueueAction>();
   }
 
-  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);
     }
index dc2e29f224780e2e455d015fd7286f691dccd574..8afcdb10c647a5a8d7249d03c85dd34718dc84e0 100644 (file)
@@ -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<Runnable>
   }
 
   @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<Runnable>
   }
 
   @Override
-  public void enqueue(Iterable<ClusterAction> actions) {
-    for (ClusterAction action : actions) {
+  public void enqueue(Iterable<QueueAction> actions) {
+    for (QueueAction action : actions) {
       enqueue(action);
     }
   }
index 1cbc2a9b44070ea1d5f88dd1dbe0c25af701311e..ba4c60ff7b0c1b04af3de587f7b90ea977322228 100644 (file)
@@ -60,6 +60,7 @@ public class LocalQueueWorker extends ThreadPoolExecutor
 
   protected void afterExecute(Runnable r, Throwable t) {
     super.afterExecute(r, t);
+    //TODO throw throwable
   }
 
   @Override
index c3633d38c55c2b911ebb40c23e6fcdd0ab29ed4f..5aa76480e8af77607f31494b9a251b30ab00f212 100644 (file)
@@ -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<String>) this.fields.get("tags");
   }
 
+  @Override
+  @SuppressWarnings("unchecked")
+  public List<String> systemTags() {
+    return (List<String>) this.fields.get("systemTags");
+  }
+
   @Override
   public List<RuleParam> 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());
   }
-
 }
index e7916ca6402ee3bea6d490db2716d900ffb663df..339df70ac82ef9d6fd05e96de8790f12964eb5dd 100644 (file)
@@ -162,23 +162,6 @@ public abstract class BaseIndex<K extends Serializable, E extends Dto<K>> implem
     }
   }
 
-  /* Index Action Methods */
-
-  @Override
-  public boolean executeAction(IndexAction<K> 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();
index d0046510e7970950b7e9aedfdb885ff17facfc49..b81427f9b0cfe7f1b31d2169690e14dccc51b098 100644 (file)
@@ -29,8 +29,6 @@ public interface Index<K extends Serializable> extends Startable {
 
   String getIndexName();
 
-  boolean executeAction(IndexAction<K> action);
-
   @CheckForNull
   Hit getByKey(K key);
 
index c882941fe651844543daa49450b8c14e634f55e0..0ab9744a2f3a51ccee0e3353372990c1237c5b3a 100644 (file)
  */
 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<K extends Serializable> extends ClusterAction {
+public class IndexAction<K extends Serializable> extends QueueAction {
+
+  private static final Logger LOG = LoggerFactory.getLogger(IndexAction.class);
+
 
   public enum Method {
     INSERT, UPDATE, DELETE
@@ -68,7 +73,17 @@ public class IndexAction<K extends Serializable> 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")