use the hint to add collection to session

This commit is contained in:
Noble Paul 2017-05-24 18:35:54 +09:30
parent cfe5cffddd
commit 66a6cffd66
2 changed files with 22 additions and 14 deletions

View File

@ -165,13 +165,7 @@ public class Policy implements MapWriter {
.collect(Collectors.toList());
for (String c : collections) {
String p = dataProvider.getPolicy(c);
if (p != null) {
List<Clause> perCollPolicy = policies.get(p);
if (perCollPolicy == null)
throw new RuntimeException(StrUtils.formatString("Policy for collection {0} is {1} . It does not exist", c, p));
}
expandedClauses.addAll(mergePolicies(c, policies.getOrDefault(p, emptyList()), clusterPolicy));
addClausesForCollection(dataProvider, c);
}
Collections.sort(expandedClauses);
@ -183,6 +177,16 @@ public class Policy implements MapWriter {
applyRules();
}
private void addClausesForCollection(ClusterDataProvider dataProvider, String c) {
String p = dataProvider.getPolicy(c);
if (p != null) {
List<Clause> perCollPolicy = policies.get(p);
if (perCollPolicy == null)
throw new RuntimeException(StrUtils.formatString("Policy for collection {0} is {1} . It does not exist", c, p));
}
expandedClauses.addAll(mergePolicies(c, policies.getOrDefault(p, emptyList()), clusterPolicy));
}
Session copy() {
return new Session(nodes, dataProvider, getMatrixCopy(), expandedClauses, paramsOfInterest);
}
@ -343,6 +347,16 @@ public class Policy implements MapWriter {
public SolrRequest getOperation() {
if (!isInitialized) {
String coll = (String) hints.get(Hint.COLL);
if(coll != null){
// if this is not a known collection from the existing clusterstate,
// then add it
if(session.matrix.stream().noneMatch(row -> row.replicaInfo.containsKey(coll))){
session.matrix.get(0).replicaInfo.put(coll, new HashMap<>());
session.addClausesForCollection(session.dataProvider, coll);
Collections.sort(session.expandedClauses);
}
}
session.applyRules();
originalViolations.addAll(session.getViolations());
this.operation = init();

View File

@ -54,13 +54,7 @@ public class PolicyHelper {
@Override
public Map<String, Map<String, List<Policy.ReplicaInfo>>> getReplicaInfo(String node, Collection<String> keys) {
Map<String, Map<String, List<Policy.ReplicaInfo>>> replicaInfo = delegate.getReplicaInfo(node, keys);
for (String s : optionalPolicyMapping.keySet()) {
if (!replicaInfo.containsKey(s)) {
replicaInfo.put(s, new HashMap<>());
}
}
return replicaInfo;
return delegate.getReplicaInfo(node, keys);
}
@Override