From ea1b28dd6df6899d79ad1a13b34a1945483f36ee Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Fri, 25 Apr 2014 11:13:16 +0200 Subject: [PATCH] SONAR-5007 - Adding new interface for end-to-end ES integration --- .../org/sonar/server/cluster/WorkQueue.java | 44 ++++++++++++ .../main/java/org/sonar/server/db/Dao.java | 36 ++++++++++ .../main/java/org/sonar/server/db/Dto.java | 28 ++++++++ .../java/org/sonar/server/search/Hit.java | 71 +++++++++++++++++++ .../java/org/sonar/server/search/Index.java | 50 +++++++++++++ 5 files changed, 229 insertions(+) create mode 100644 sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java create mode 100644 sonar-server/src/main/java/org/sonar/server/db/Dao.java create mode 100644 sonar-server/src/main/java/org/sonar/server/db/Dto.java create mode 100644 sonar-server/src/main/java/org/sonar/server/search/Hit.java create mode 100644 sonar-server/src/main/java/org/sonar/server/search/Index.java diff --git a/sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java b/sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java new file mode 100644 index 00000000000..d7ffbd5d448 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java @@ -0,0 +1,44 @@ +/* + * 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.server.cluster; + +import java.io.Serializable; + + +public interface WorkQueue { + + Integer enqueInsert(String indexName, Serializable key); + + Integer enqueUpdate(String indexName, Serializable key); + + Integer enqueDelete(String indexName, Serializable key); + + Serializable dequeInsert(String indexName); + + Serializable dequeUpdate(String indexName); + + Serializable dequeDelete(String indexName); + + Status getStatus(Integer workId); + + interface Status { + + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/db/Dao.java b/sonar-server/src/main/java/org/sonar/server/db/Dao.java new file mode 100644 index 00000000000..44fd54dd41a --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/db/Dao.java @@ -0,0 +1,36 @@ +/* + * 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.server.db; + +import java.io.Serializable; + +public interface Dao, K extends Serializable> { + + public E getByKey(K key); + + public E update(E item); + + public E insert(E item); + + public void delete(E item); + + public void deleteByKey(K key); + +} diff --git a/sonar-server/src/main/java/org/sonar/server/db/Dto.java b/sonar-server/src/main/java/org/sonar/server/db/Dto.java new file mode 100644 index 00000000000..483a276f175 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/db/Dto.java @@ -0,0 +1,28 @@ +/* + * 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.server.db; + +import java.io.Serializable; + +public interface Dto { + + K getKey(); + +} diff --git a/sonar-server/src/main/java/org/sonar/server/search/Hit.java b/sonar-server/src/main/java/org/sonar/server/search/Hit.java new file mode 100644 index 00000000000..8f5c0960992 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/search/Hit.java @@ -0,0 +1,71 @@ +/* + * 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.server.search; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class Hit implements Comparable { + + private Map> fields; + + private Integer rank; + + public Hit(Integer rank){ + this.fields = new HashMap>(); + this.rank = rank; + } + + public Collection getFieldValues(String field){ + return this.fields.get(field); + } + + public Serializable getFieldValue(String field){ + if(this.hasField(field)){ + return fields.get(field).iterator().next(); + } else { + return null; + } + } + + public Hit addFieldValue(String field, Serializable value){ + if(!this.hasField(field)){ + this.fields.put(field, new ArrayList()); + } + return this; + } + + public boolean hasField(String field){ + return this.fields.containsKey(field) && + !this.fields.get(field).isEmpty(); + } + + public Integer getRank(){ + return this.rank; + } + + @Override + public int compareTo(Hit hit) { + return this.getRank().compareTo(hit.getRank()); + } +} 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 new file mode 100644 index 00000000000..a93d2db89e0 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/search/Index.java @@ -0,0 +1,50 @@ +/* + * 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.server.search; + +import org.picocontainer.Startable; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Date; +import java.util.Map; + +public interface Index extends Startable { + + Hit getByKey(K key); + + void insert(K key); + + void udpate(K key); + + void delete(K key); + + K dequeueInsert(); + + K dequeueUpdate(); + + K dequeueDelete(); + + Map normalize(K key); + + Date getLastSynchronization(); + + Collection synchronizeSince(Date date); +} -- 2.39.5