import org.sonar.server.authentication.ws.AuthenticationWs;
import org.sonar.server.charts.ChartFactory;
import org.sonar.server.cluster.LocalNonBlockingWorkQueue;
+import org.sonar.server.cluster.LocalQueueWorker;
import org.sonar.server.component.DefaultComponentFinder;
import org.sonar.server.component.DefaultRubyComponentService;
import org.sonar.server.component.ws.ComponentsWs;
import org.sonar.server.qualityprofile.QProfiles;
import org.sonar.server.qualityprofile.RegisterQualityProfiles;
import org.sonar.server.qualityprofile.RuleActivationContextFactory;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
+import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
import org.sonar.server.qualityprofile.persistence.ActiveRuleDao;
import org.sonar.server.qualityprofile.ws.ProfilesWs;
import org.sonar.server.qualityprofile.ws.QProfileRecreateBuiltInAction;
import org.sonar.server.rule.ws.RulesWs;
import org.sonar.server.rule2.RegisterRules;
import org.sonar.server.rule2.RuleService;
+import org.sonar.server.rule2.index.RuleIndex;
+import org.sonar.server.rule2.index.RuleNormalizer;
import org.sonar.server.rule2.persistence.RuleDao;
import org.sonar.server.rule2.ws.RulesWebService;
import org.sonar.server.rule2.ws.SearchAction;
ThreadLocalDatabaseSessionFactory.class,
new DatabaseSessionProvider(),
ServerMetadataPersister.class,
- ESNode.class,
HttpDownloader.class,
UriReader.class,
- ServerIdGenerator.class
+ ServerIdGenerator.class,
+
+ // Elasticsearch
+ ESNode.class,
+ RuleNormalizer.class,
+ ActiveRuleNormalizer.class,
+ RuleIndex.class,
+ ActiveRuleIndex.class,
+ LocalQueueWorker.class
);
- components.addAll(IndexUtils.getIndexClasses());
return components;
}
--- /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.server.qualityprofile;
+
+import org.sonar.core.qualityprofile.db.ActiveRuleKey;
+
+import java.util.Map;
+
+public interface ActiveRule {
+
+ ActiveRuleKey key();
+
+ String severity();
+
+ Boolean override();
+
+ String inherit();
+
+ Map<String, String> params();
+}
*/
package org.sonar.server.qualityprofile;
-
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class ActiveRuleDocument {
public static final String FIELD_ID = "id";
import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
import org.sonar.server.es.ESIndex;
import org.sonar.server.es.SearchQuery;
-import org.sonar.server.rule.RuleDocument;
import org.sonar.server.rule.RuleRegistry;
import java.io.IOException;
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class ESActiveRule {
public static final String TYPE_ACTIVE_RULE = "active_rule";
import static com.google.common.collect.Lists.newArrayList;
/**
- * @since 4.2
+ * @deprecated to be dropped in 4.4
*/
+@Deprecated
public class ProfileRuleQuery {
public static final String SORT_BY_CREATION_DATE = "SORT_BY_CREATION_DATE";
import org.sonar.api.rules.*;
import org.sonar.core.preview.PreviewCache;
import org.sonar.jpa.dao.RulesDao;
+import org.sonar.api.rules.ActiveRule;
import java.util.*;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class ProfilesBackup {
private static final String KEY = "key";
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.List;
+import org.sonar.api.rules.ActiveRule;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class ProfilesManager extends BaseDao {
private RulesDao rulesDao;
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class QProfileActiveRuleOperations implements ServerComponent {
private final MyBatis myBatis;
import static com.google.common.collect.Lists.newArrayList;
/**
- * Used through ruby code <pre>Internal.profile_backup</pre>
+ * @deprecated to be dropped in 4.4
*/
+@Deprecated
public class QProfileBackup implements ServerComponent {
private final DatabaseSessionFactory sessionFactory;
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class QProfileLookup implements ServerComponent {
private final MyBatis myBatis;
import java.util.List;
import java.util.Map;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class QProfileOperations implements ServerComponent {
public static final String PROFILE_PROPERTY_PREFIX = "sonar.profile.";
import java.util.List;
import java.util.Map;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class QProfileRule {
public static final String INHERITED = "INHERITED";
import static org.sonar.server.rule.RuleRegistry.INDEX_RULES;
import static org.sonar.server.rule.RuleRegistry.TYPE_RULE;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class QProfileRuleLookup implements ServerExtension {
private static final int PAGE_SIZE = 100;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class QProfileRuleParam {
private RuleParam param;
import java.util.Map;
/**
- * Used through ruby code <pre>Internal.quality_profiles</pre>
+ * @deprecated to be dropped in 4.4
*/
+@Deprecated
public class QProfiles implements ServerComponent {
private static final String LANGUAGE_PARAM = "language";
package org.sonar.server.qualityprofile.index;
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
-import org.sonar.server.rule2.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRule;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.sonar.api.rules.ActiveRule;
import org.sonar.core.cluster.WorkQueue;
-import org.sonar.core.profiling.Profiling;
import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
import org.sonar.server.rule2.index.RuleNormalizer;
public class ActiveRuleIndex extends NestedIndex<ActiveRule, ActiveRuleDto, ActiveRuleKey> {
-
- public ActiveRuleIndex(ActiveRuleNormalizer normalizer, WorkQueue workQueue, Profiling profiling, BaseIndex<?,?,?> index) {
- super(new ActiveRuleIndexDefinition(), normalizer, workQueue, profiling, index);
+ public ActiveRuleIndex(ActiveRuleNormalizer normalizer, WorkQueue workQueue, BaseIndex<?, ?, ?> index) {
+ super(new ActiveRuleIndexDefinition(), normalizer, workQueue, index);
}
@Override
return null;
}
-}
\ No newline at end of file
+}
--- /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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.qualityprofile.index;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.qualityprofile.persistence;
+
+import javax.annotation.ParametersAreNonnullByDefault;
import java.io.IOException;
import java.util.Collection;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class ESRuleTags {
public static final String TYPE_TAG = "tag";
import static com.google.common.collect.Lists.newArrayList;
/**
- * Register rules at server startup
- *
- * @since 4.2
+ * @deprecated to be dropped in 4.4
*/
+@Deprecated
public class RegisterRules implements Startable {
private static final Logger LOG = LoggerFactory.getLogger(RegisterRules.class);
import java.util.Collections;
import java.util.Date;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class Rule {
public static final String MANUAL_REPOSITORY_KEY = "manual";
package org.sonar.server.rule;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public final class RuleDocument {
public static final String FIELD_ID = "id";
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class RuleDocumentParser {
private RuleDocumentParser() {
import java.util.Date;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class RuleNote {
private final String data;
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class RuleOperations implements ServerComponent {
private final MyBatis myBatis;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class RuleParam {
private final String key;
import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery;
import static org.sonar.api.rules.Rule.STATUS_REMOVED;
+
/**
- * Fill search index with rules
- *
- * @since 4.1
+ * @deprecated to be dropped in 4.4
*/
+@Deprecated
public class RuleRegistry {
private static final Logger LOG = LoggerFactory.getLogger(RuleRegistry.class);
*/
package org.sonar.server.rule;
-
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class RuleTagDocument {
public static final String FIELD_VALUE = "value";
import java.util.Collection;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class RuleTagLookup implements ServerComponent {
private final ESRuleTags esRuleTags;
import java.util.Set;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class RuleTagOperations implements ServerExtension {
private final RuleTagDao ruleTagDao;
import java.util.Collection;
/**
- * Used through ruby code <pre>Internal.rule_tags</pre>
+ * @deprecated to be dropped in 4.4
*/
+@Deprecated
public class RuleTags implements ServerExtension {
private final RuleTagLookup ruleTagLookup;
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
public class Rules implements ServerExtension {
private final RuleDao ruleDao;
+++ /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.server.rule2;
-
-import org.sonar.core.qualityprofile.db.ActiveRuleKey;
-
-import java.util.Map;
-
-public interface ActiveRule {
-
- public ActiveRuleKey key();
-
- public Boolean override();
-
- public String severity();
-
- public String inherit();
-
- public Map<String, String> params();
-}
import org.sonar.api.utils.TimeProfiler;
import org.sonar.check.Cardinality;
import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
+import org.sonar.server.db.DbClient;
import org.sonar.server.qualityprofile.ProfilesManager;
-import org.sonar.server.qualityprofile.persistence.ActiveRuleDao;
import org.sonar.server.rule.RuleDefinitionsLoader;
-import org.sonar.server.rule2.persistence.RuleDao;
import javax.annotation.Nullable;
import java.util.ArrayList;
private final RuleDefinitionsLoader defLoader;
private final ProfilesManager profilesManager;
- private final MyBatis myBatis;
- private final RuleDao ruleDao;
- private final ActiveRuleDao activeRuleDao;
+ private final DbClient dbClient;
private final CharacteristicDao characteristicDao;
public RegisterRules(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
- MyBatis myBatis, RuleDao ruleDao, ActiveRuleDao activeRuleDao,
+ DbClient dbClient,
CharacteristicDao characteristicDao) {
- this(defLoader, profilesManager, myBatis, ruleDao, activeRuleDao, characteristicDao, System2.INSTANCE);
+ this(defLoader, profilesManager, dbClient, characteristicDao, System2.INSTANCE);
}
@VisibleForTesting
RegisterRules(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
- MyBatis myBatis, RuleDao ruleDao, ActiveRuleDao activeRuleDao,
+ DbClient dbClient,
CharacteristicDao characteristicDao, System2 system) {
this.defLoader = defLoader;
this.profilesManager = profilesManager;
- this.myBatis = myBatis;
- this.ruleDao = ruleDao;
- this.activeRuleDao = activeRuleDao;
+ this.dbClient = dbClient;
this.characteristicDao = characteristicDao;
}
@Override
public void start() {
TimeProfiler profiler = new TimeProfiler().start("Register rules");
- DbSession session = myBatis.openSession(false);
+ DbSession session = dbClient.openSession(false);
try {
-
- Map<RuleKey, RuleDto> allRules = getRulesByKey(session);
+ Map<RuleKey, RuleDto> allRules = loadRules(session);
RulesDefinition.Context context = defLoader.load();
for (RulesDefinition.ExtendedRepository repoDef : getRepositories(context)) {
RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());
- RuleDto rule = allRules.containsKey(ruleKey) ?
- allRules.remove(ruleKey) :
- this.createRuleDto(ruleDef, session);
+ RuleDto rule = allRules.containsKey(ruleKey) ? allRules.remove(ruleKey) : createRuleDto(ruleDef, session);
boolean executeUpdate = false;
if (mergeRule(ruleDef, rule)) {
executeUpdate = true;
}
- if(rule.getSubCharacteristicId() != null) {
+ if (rule.getSubCharacteristicId() != null) {
CharacteristicDto characteristicDto = characteristicDao.selectById(rule.getSubCharacteristicId(), session);
if (characteristicDto != null && mergeDebtDefinitions(ruleDef, rule, characteristicDto)) {
executeUpdate = true;
}
if (executeUpdate) {
- ruleDao.update(rule, session);
+ dbClient.ruleDao().update(rule, session);
}
mergeParams(ruleDef, rule, session);
-
}
+ session.commit();
}
List<RuleDto> activeRules = processRemainingDbRules(allRules.values(), session);
removeActiveRulesOnStillExistingRepositories(activeRules, context);
-
session.commit();
} finally {
// nothing
}
- private Map<RuleKey, RuleDto> getRulesByKey(DbSession session) {
+ private Map<RuleKey, RuleDto> loadRules(DbSession session) {
Map<RuleKey, RuleDto> rules = new HashMap<RuleKey, RuleDto>();
- for (RuleDto rule : ruleDao.findByNonManual(session)) {
+ for (RuleDto rule : dbClient.ruleDao().findByNonManual(session)) {
rules.put(rule.getKey(), rule);
}
return rules;
.setStatus(ruleDef.status().name())
.setSystemTags(ruleDef.tags());
- return ruleDao.insert(ruleDto, session);
+ return dbClient.ruleDao().insert(ruleDto, session);
}
private boolean mergeRule(RulesDefinition.Rule def, RuleDto dto) {
}
private void mergeParams(RulesDefinition.Rule ruleDef, RuleDto rule, DbSession session) {
- List<RuleParamDto> paramDtos = ruleDao.findRuleParamsByRuleKey(rule.getKey(), session);
+ List<RuleParamDto> paramDtos = dbClient.ruleDao().findRuleParamsByRuleKey(rule.getKey(), session);
List<String> existingParamDtoNames = new ArrayList<String>();
for (RuleParamDto paramDto : paramDtos) {
if (paramDef == null) {
//TODO cascade on the activeRule upon RuleDeletion
//activeRuleDao.removeRuleParam(paramDto, sqlSession);
- ruleDao.removeRuleParam(rule, paramDto, session);
+ dbClient.ruleDao().removeRuleParam(rule, paramDto, session);
} else {
// TODO validate that existing active rules still match constraints
// TODO store param name
if (mergeParam(paramDto, paramDef)) {
- ruleDao.updateRuleParam(rule, paramDto, session);
+ dbClient.ruleDao().updateRuleParam(rule, paramDto, session);
}
existingParamDtoNames.add(paramDto.getName());
}
.setDescription(param.description())
.setDefaultValue(param.defaultValue())
.setType(param.type().toString());
- ruleDao.addRuleParam(rule, paramDto, session);
+ dbClient.ruleDao().addRuleParam(rule, paramDto, session);
}
}
}
boolean toBeRemoved = true;
// Update custom rules from template
if (ruleDto.getParentId() != null) {
- RuleDto parent = ruleDao.getParent(ruleDto, session);
+ RuleDto parent = dbClient.ruleDao().getParent(ruleDto, session);
if (parent != null && !Rule.STATUS_REMOVED.equals(parent.getStatus())) {
ruleDto.setLanguage(parent.getLanguage());
ruleDto.setStatus(parent.getStatus());
ruleDto.setDefaultRemediationCoefficient(parent.getDefaultRemediationCoefficient());
ruleDto.setDefaultRemediationOffset(parent.getDefaultRemediationOffset());
ruleDto.setEffortToFixDescription(parent.getEffortToFixDescription());
- ruleDao.update(ruleDto, session);
+ dbClient.ruleDao().update(ruleDto, session);
toBeRemoved = false;
}
}
ruleDto.setTags(Collections.EMPTY_SET);
}
- ruleDao.update(ruleDto, session);
+ dbClient.ruleDao().update(ruleDto, session);
removedRules.add(ruleDto);
if (removedRules.size() % 100 == 0) {
session.commit();
for (RuleDto rule : removedRules) {
// SONAR-4642 Remove active rules only when repository still exists
if (repositoryKeys.contains(rule.getRepositoryKey())) {
+ // TODO
profilesManager.removeActivatedRules(rule.getId());
}
}
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.server.rule2.Rule;
import org.sonar.server.rule2.RuleParam;
-import org.sonar.server.rule2.index.RuleNormalizer;
import org.sonar.server.rule2.index.RuleNormalizer.RuleField;
+import org.sonar.server.search.IndexUtils;
import javax.annotation.CheckForNull;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Override
@CheckForNull
public Date createdAt() {
- SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
- try {
- return sdf.parse((String) fields.get(RuleField.CREATED_AT.key()));
- } catch (ParseException e) {
- throw new IllegalStateException("Cannot parse date", e);
- }
+ return IndexUtils.parseDateTime((String) fields.get(RuleField.CREATED_AT.key()));
}
@Override
@CheckForNull
public Date updatedAt() {
- SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
- try {
- return sdf.parse((String) fields.get(RuleField.UPDATED_AT.key()));
- } catch (ParseException e) {
- throw new IllegalStateException("Cannot parse date", e);
- }
+ return IndexUtils.parseDateTime((String) fields.get(RuleField.UPDATED_AT.key()));
}
@Override
*/
package org.sonar.server.rule2.index;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.core.cluster.WorkQueue;
-import org.sonar.core.profiling.Profiling;
import org.sonar.core.rule.RuleDto;
import org.sonar.server.es.ESNode;
import org.sonar.server.rule2.Rule;
RuleNormalizer.RuleField.INTERNAL_KEY.key(),
RuleNormalizer.RuleField.UPDATED_AT.key());
- public RuleIndex(RuleNormalizer normalizer, WorkQueue workQueue,
- Profiling profiling, ESNode node) {
- super(new RuleIndexDefinition(), normalizer, workQueue, profiling, node);
+ public RuleIndex(RuleNormalizer normalizer, WorkQueue workQueue, ESNode node) {
+ super(new RuleIndexDefinition(), normalizer, workQueue, node);
}
protected String getKeyValue(RuleKey key) {
}
public RuleResult search(RuleQuery query, QueryOptions options) {
-
SearchRequestBuilder esSearch = this.buildRequest(query, options);
FilterBuilder fb = this.getFilter(query, options);
QueryBuilder qb = this.getQuery(query, options);
public Rule toDoc(GetResponse response) {
- if (response == null) {
- throw new IllegalStateException("Cannot construct Rule with null response!!!");
- }
+ Preconditions.checkArgument(response != null, "Cannot construct Rule with null response!!!");
return new RuleDoc(response.getSource());
}
public Set<String> terms(String... fields) {
- Set<String> tags = new HashSet<String>();
+ Set<String> tags = new HashSet<String>();
SearchRequestBuilder request = this.getClient()
.prepareSearch(this.getIndexName())
.global(true)
.size(Integer.MAX_VALUE));
- SearchResponse esResponse = request.get();
+ SearchResponse esResponse = request.get();
TermsFacet termFacet = esResponse
.getFacets().facet("tags");
import org.sonar.api.rule.RuleKey;
import org.sonar.check.Cardinality;
import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
import org.sonar.server.db.DbClient;
import org.elasticsearch.search.SearchHit;
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
import org.sonar.server.qualityprofile.index.ActiveRuleDoc;
-import org.sonar.server.rule2.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.rule2.Rule;
import org.sonar.server.search.Result;
--- /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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.rule2.index;
+
+import javax.annotation.ParametersAreNonnullByDefault;
import com.google.common.collect.Lists;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
-import org.sonar.api.ServerComponent;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.DbSession;
import java.util.List;
import java.util.Map;
-public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> implements ServerComponent {
+public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> {
public RuleDao() {
super(new RuleIndexDefinition(), RuleMapper.class);
Preconditions.checkNotNull(rule.getId(), "Rule id must be set");
Preconditions.checkNotNull(paramDto.getId(), "Param is not yet persisted must be set");
paramDto.setRuleId(rule.getId());
- System.out.println("paramDto = " + paramDto);
session.enqueue(new EmbeddedIndexAction<RuleKey>(this.getIndexType(), IndexAction.Method.UPDATE, paramDto, rule.getKey()));
mapper(session).updateParameter(paramDto);
return paramDto;
--- /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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.rule2.persistence;
+
+import javax.annotation.ParametersAreNonnullByDefault;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.server.rule2.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.rule2.Rule;
import org.sonar.server.rule2.RuleParam;
import org.sonar.server.rule2.RuleService;
import org.slf4j.LoggerFactory;
import org.sonar.core.cluster.WorkQueue;
import org.sonar.core.db.Dto;
-import org.sonar.core.profiling.Profiling;
import org.sonar.server.es.ESNode;
import java.io.IOException;
private static final Logger LOG = LoggerFactory.getLogger(BaseIndex.class);
- private final Profiling profiling;
private final ESNode node;
protected BaseNormalizer<E, K> normalizer;
protected final IndexDefinition indexDefinition;
- public BaseIndex(IndexDefinition indexDefinition, BaseNormalizer<E, K> normalizer, WorkQueue workQueue,
- Profiling profiling, ESNode node) {
+ public BaseIndex(IndexDefinition indexDefinition, BaseNormalizer<E, K> normalizer,
+ WorkQueue workQueue, ESNode node) {
this.normalizer = normalizer;
- this.profiling = profiling;
this.node = node;
this.indexDefinition = indexDefinition;
}
public void start() {
/* Setup the index if necessary */
- this.initializeIndex();
+ initializeIndex();
}
@Override
/* Cluster And ES Stats/Client methods */
protected void initializeIndex() {
-
String index = this.getIndexName();
IndicesExistsResponse indexExistsResponse = getClient().admin().indices()
}
-
protected BoolFilterBuilder addMultiFieldTermFilter(Collection<String> values, BoolFilterBuilder filter, String... fields) {
if (values != null && !values.isEmpty()) {
BoolFilterBuilder valuesFilter = FilterBuilders.boolFilter();
for (String value : values) {
Collection<FilterBuilder> filterBuilders = new ArrayList<FilterBuilder>();
- for(String field:fields) {
+ for (String field : fields) {
filterBuilders.add(FilterBuilders.termFilter(field, value));
}
valuesFilter.should(FilterBuilders.orFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()])));
}
-
protected BoolFilterBuilder addTermFilter(String field, Collection<String> values, BoolFilterBuilder filter) {
if (values != null && !values.isEmpty()) {
BoolFilterBuilder valuesFilter = FilterBuilders.boolFilter();
import org.elasticsearch.index.query.FilterBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.picocontainer.Startable;
+import org.sonar.api.ServerComponent;
import org.sonar.core.db.Dto;
import javax.annotation.CheckForNull;
import java.io.Serializable;
-public interface Index<D, E extends Dto<K>, K extends Serializable> extends Startable {
+public interface Index<D, E extends Dto<K>, K extends Serializable> extends Startable, ServerComponent {
@CheckForNull
D getByKey(K item);
SearchResponse search(SearchRequestBuilder request,
- FilterBuilder filter, QueryBuilder query);
+ FilterBuilder filter, QueryBuilder query);
String getIndexType();
+++ /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.server.search;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.core.cluster.WorkQueue;
-import org.sonar.core.db.Dao;
-
-import java.io.Serializable;
-
-public class IndexSynchronizer<K extends Serializable> {
-
- private static final Logger LOG = LoggerFactory.getLogger(IndexSynchronizer.class);
-
- private final Index index;
- private final Dao<?,K> dao;
- private final WorkQueue workQueue;
-
- public IndexSynchronizer(Index index, Dao<?,K> dao, WorkQueue workQueue) {
- this.index = index;
- this.dao = dao;
- this.workQueue = workQueue;
- }
-
- public IndexSynchronizer<K> start() {
-
-// LOG.info("Starting synchronization thread for ", index.getClass().getSimpleName());
-//
-// Long since = index.getLastSynchronization();
-// index.setLastSynchronization(System.currentTimeMillis());
-//
-// for (K key : dao.keysOfRowsUpdatedAfter(since)) {
-// if (LOG.isTraceEnabled()) {
-// LOG.trace("Adding {} to workQueue for {}", key, index.getClass().getSimpleName());
-// }
-// workQueue.enqueue(new KeyIndexAction<K>(index.getIndexName(), IndexAction.Method.INSERT, key));
-// }
-
- return this;
- }
-}
*/
package org.sonar.server.search;
-import com.google.common.collect.ImmutableList;
-import org.sonar.server.cluster.LocalQueueWorker;
-import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
-import org.sonar.server.rule2.index.RuleIndex;
-import org.sonar.server.rule2.index.RuleNormalizer;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
-import java.util.List;
-
-public final class IndexUtils {
+public class IndexUtils {
+ private IndexUtils() {
+ // only static stuff
+ }
- @SuppressWarnings("unchecked")
- public static List<Class> getIndexClasses() {
- return ImmutableList.<Class>of(
- RuleNormalizer.class,
- ActiveRuleNormalizer.class,
- RuleIndex.class,
- ActiveRuleIndex.class,
- LocalQueueWorker.class
- );
+ public static Date parseDateTime(String s) {
+ DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+ try {
+ return sdf.parse(s);
+ } catch (ParseException e) {
+ throw new IllegalArgumentException("Cannot parse ES date: " + s, e);
+ }
}
}
import org.slf4j.LoggerFactory;
import org.sonar.core.cluster.WorkQueue;
import org.sonar.core.db.Dto;
-import org.sonar.core.profiling.Profiling;
import java.io.Serializable;
private static final Logger LOG = LoggerFactory.getLogger(NestedIndex.class);
- protected BaseIndex<?,?,?> parentIndex;
+ protected BaseIndex<?, ?, ?> parentIndex;
public NestedIndex(IndexDefinition indexDefinition, BaseNormalizer<E, K> normalizer, WorkQueue workQueue,
- Profiling profiling, BaseIndex<?,?,?> index) {
- super(indexDefinition, normalizer, workQueue, profiling, index.getNode());
+ BaseIndex<?, ?, ?> index) {
+ super(indexDefinition, normalizer, workQueue, index.getNode());
this.parentIndex = index;
}
protected abstract String getIndexField();
- protected String getKeyValue(K key){
+ protected String getKeyValue(K key) {
return this.getParentKeyValue(key);
}
protected void initializeIndex() {
- ;
}
@Override
public D getByKey(K key) {
- return toDoc( getClient().prepareGet(this.getIndexName(), this.indexDefinition.getIndexType(), this.getKeyValue(key))
+ return toDoc(getClient().prepareGet(this.getIndexName(), this.indexDefinition.getIndexType(), this.getKeyValue(key))
.get());
}
public abstract class Result<K> {
- private Collection<K> hits;
- private Map<String, Collection<FacetValue>> facets;
- private int total;
- private int offset;
- private long time;
+ private final Collection<K> hits;
+ private final Map<String, Collection<FacetValue>> facets;
+ private final long total;
+ private final long timeInMillis;
public Result(SearchResponse response) {
+ this.hits = new ArrayList<K>();
+ this.total = (int) response.getHits().totalHits();
+ this.timeInMillis = response.getTookInMillis();
- hits = new ArrayList<K>();
-
- if (response != null) {
- this.total = (int) response.getHits().totalHits();
- this.time = response.getTookInMillis();
-
-
- for (SearchHit hit : response.getHits()) {
- this.hits.add(getSearchResult(hit));
- }
-
+ for (SearchHit hit : response.getHits()) {
+ this.hits.add(getSearchResult(hit));
+ }
- if (response.getFacets() != null &&
- !response.getFacets().facets().isEmpty()) {
- this.facets = new HashMap<String, Collection<FacetValue>>();
- for (Facet facet : response.getFacets().facets()) {
- TermsFacet termFacet = (TermsFacet) facet;
- List<FacetValue> facetValues = new ArrayList<FacetValue>();
- for (TermsFacet.Entry facetValue : termFacet.getEntries()) {
- facetValues.add(new FacetValue<Integer>(facetValue.getTerm().string(),
- facetValue.getCount()));
- }
- this.facets.put(facet.getName(), facetValues);
+ if (response.getFacets() != null &&
+ !response.getFacets().facets().isEmpty()) {
+ this.facets = new HashMap<String, Collection<FacetValue>>();
+ for (Facet facet : response.getFacets().facets()) {
+ TermsFacet termFacet = (TermsFacet) facet;
+ List<FacetValue> facetValues = new ArrayList<FacetValue>();
+ for (TermsFacet.Entry facetValue : termFacet.getEntries()) {
+ facetValues.add(new FacetValue<Integer>(facetValue.getTerm().string(),
+ facetValue.getCount()));
}
- } else {
- this.facets = Collections.emptyMap();
+ this.facets.put(facet.getName(), facetValues);
}
+ } else {
+ this.facets = Collections.emptyMap();
}
}
return hits;
}
- public int getTotal() {
+ public long getTotal() {
return total;
}
- public int getOffset() {
- return offset;
- }
-
- public long getTime() {
- return time;
+ public long getTimeInMillis() {
+ return timeInMillis;
}
public Map<String, Collection<FacetValue>> getFacets() {
--- /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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.search.action;
+
+import javax.annotation.ParametersAreNonnullByDefault;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
-import org.sonar.core.cluster.WorkQueue;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.qualityprofile.db.QualityProfileDao;
-import org.sonar.core.rule.RuleDto;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagDto;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
+import org.sonar.server.db.DbClient;
import org.sonar.server.qualityprofile.ProfilesManager;
import org.sonar.server.qualityprofile.persistence.ActiveRuleDao;
-import org.sonar.server.rule.ESRuleTags;
import org.sonar.server.rule.RuleDefinitionsLoader;
-import org.sonar.server.rule.RuleRegistry;
import org.sonar.server.rule.RuleRepositories;
import org.sonar.server.rule2.persistence.RuleDao;
-import java.util.Collection;
import java.util.Date;
import static org.fest.assertions.Assertions.assertThat;
"effort_to_fix_description"};
RegisterRules task;
-
- @Mock
- ProfilesManager profilesManager;
-
- @Mock
- RuleRegistry ruleRegistry;
-
- @Mock
- ESRuleTags esRuleTags;
-
- @Captor
- ArgumentCaptor<Collection<RuleDto>> rulesCaptor;
-
- @Captor
- ArgumentCaptor<Collection<RuleTagDto>> ruleTagsCaptor;
-
+ ProfilesManager profilesManager = mock(ProfilesManager.class);
MyBatis myBatis;
RuleDao ruleDao;
- RuleTagDao ruleTagDao;
ActiveRuleDao activeRuleDao;
CharacteristicDao characteristicDao;
System2 system;
- WorkQueue queue;
Date date = DateUtils.parseDateTime("2014-03-17T19:10:03+0100");
-
- private DbSession session;
+ DbSession session;
+ DbClient dbClient;
@Before
public void before() {
when(system.now()).thenReturn(date.getTime());
myBatis = getMyBatis();
ruleDao = new RuleDao();
- ruleTagDao = new RuleTagDao(myBatis);
activeRuleDao = new ActiveRuleDao(new QualityProfileDao(myBatis), ruleDao);
+ dbClient = new DbClient(getDatabase(), getMyBatis(), ruleDao, activeRuleDao, new QualityProfileDao(getMyBatis()));
characteristicDao = new CharacteristicDao(myBatis);
- task = new RegisterRules(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RulesDefinition[]{new FakeRepository()}),
- profilesManager, myBatis, ruleDao, activeRuleDao, characteristicDao, system);
+ task = new RegisterRules(new RuleDefinitionsLoader(mock(RuleRepositories.class),
+ new RulesDefinition[]{new FakeRepository()}),
+ profilesManager, dbClient, characteristicDao, system
+ );
session = myBatis.openSession(false);
}
@Test
public void test_high_number_of_rules() {
task = new RegisterRules(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RulesDefinition[]{new BigRepository()}),
- profilesManager, myBatis, ruleDao, activeRuleDao, characteristicDao);
+ profilesManager, dbClient, characteristicDao);
setupData("shared");
task.start();
public void insert_extended_repositories() {
task = new RegisterRules(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RulesDefinition[]{
new FindbugsRepository(), new FbContribRepository()}),
- profilesManager, myBatis, ruleDao, activeRuleDao, characteristicDao
+ profilesManager, dbClient, characteristicDao
);