+++ /dev/null
-/*
- * 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();
- }
- }
-}
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) {
}
}
--- /dev/null
+/*
+ * 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();
+ }
+ }
+}
*/
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);
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;
private static final Logger LOG = LoggerFactory.getLogger(DbSession.class);
- private List<ClusterAction> actions;
+ private List<QueueAction> actions;
private WorkQueue queue;
private SqlSession session;
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);
}
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;
}
@Override
- public void enqueue(ClusterAction action) {
+ public void enqueue(QueueAction action) {
try {
this.offer(action, 1000,TimeUnit.SECONDS);
} catch (InterruptedException e) {
}
@Override
- public void enqueue(Iterable<ClusterAction> actions) {
- for (ClusterAction action : actions) {
+ public void enqueue(Iterable<QueueAction> actions) {
+ for (QueueAction action : actions) {
enqueue(action);
}
}
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
+ //TODO throw throwable
}
@Override
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;
}
@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
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
public static Rule fromHit(Hit hit) {
return new RuleImpl(hit.getFields());
}
-
}
}
}
- /* 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();
String getIndexName();
- boolean executeAction(IndexAction<K> action);
-
@CheckForNull
Hit getByKey(K key);
*/
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
@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")