Github user dsmiley commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/304#discussion_r161076165
--- Diff: solr/core/src/java/org/apache/solr/cloud/CreateAliasCmd.java ---
@@ -45,13 +147,92 @@ public CreateAliasCmd(OverseerCollectionMessageHandler
ocmh) {
public void call(ClusterState state, ZkNodeProps message, NamedList
results)
throws Exception {
final String aliasName = message.getStr(NAME);
- final List<String> canonicalCollectionList =
parseCollectionsParameter(message.get("collections"));
- final String canonicalCollectionsString =
StrUtils.join(canonicalCollectionList, ',');
-
ZkStateReader zkStateReader = ocmh.zkStateReader;
- validateAllCollectionsExistAndNoDups(canonicalCollectionList,
zkStateReader);
+ ZkStateReader.AliasesManager holder = zkStateReader.aliasesHolder;
+ if (!anyRoutingParams(message)) {
+ final List<String> canonicalCollectionList =
parseCollectionsParameter(message.get("collections"));
+ final String canonicalCollectionsString =
StrUtils.join(canonicalCollectionList, ',');
+ validateAllCollectionsExistAndNoDups(canonicalCollectionList,
zkStateReader);
+ holder.applyModificationAndExportToZk(aliases ->
aliases.cloneWithCollectionAlias(aliasName, canonicalCollectionsString));
+ } else {
+ final String routedField = message.getStr(ROUTING_FIELD);
+ final String routingType = message.getStr(ROUTING_TYPE);
+ final String tz = message.getStr(TZ);
+ final String start = message.getStr(START);
+ final String increment = message.getStr(ROUTING_INCREMENT);
+ final String maxFutureMs = message.getStr(ROUTING_MAX_FUTURE);
+
+ try {
+ if (0 > Long.valueOf(maxFutureMs)) {
+ throw new NumberFormatException("Negative value not allowed
here");
+ }
+ } catch (NumberFormatException e) {
+ throw new SolrException(BAD_REQUEST, ROUTING_MAX_FUTURE + " must
be a valid long integer representing a number " +
+ "of milliseconds greater than or equal to zero");
+ }
- zkStateReader.aliasesHolder.applyModificationAndExportToZk(aliases ->
aliases.cloneWithCollectionAlias(aliasName, canonicalCollectionsString));
+ // Validate we got everything we need
+ if (routedField == null || routingType == null || start == null ||
increment == null) {
+ SolrException solrException = new SolrException(BAD_REQUEST, "If
any of " + CREATE_ROUTED_ALIAS_PARAMS +
+ " are supplied, then all of " + REQUIRED_ROUTING_PARAMS + "
must be present.");
+ log.error("Could not create routed alias",solrException);
+ throw solrException;
+ }
+
+ if (!"time".equals(routingType)) {
+ SolrException solrException = new SolrException(BAD_REQUEST, "Only
time based routing is supported at this time");
+ log.error("Could not create routed alias",solrException);
+ throw solrException;
+ }
+ // Check for invalid timezone
+ if(tz != null && !TimeZoneUtils.KNOWN_TIMEZONE_IDS.contains(tz)) {
+ SolrException solrException = new SolrException(BAD_REQUEST,
"Invalid timezone:" + tz);
+ log.error("Could not create routed alias",solrException);
+ throw solrException;
+
+ }
+ TimeZone zone;
+ if (tz != null) {
+ zone = TimeZoneUtils.getTimeZone(tz);
+ } else {
+ zone = TimeZoneUtils.getTimeZone("UTC");
+ }
+ DateTimeFormatter fmt =
DATE_TIME_FORMATTER.withZone(zone.toZoneId());
+
+ // check that the increment is valid date math
+ String checkIncrement = ISO_INSTANT.format(Instant.now()) +
increment;
+ DateMathParser.parseMath(new Date(), checkIncrement); // exception
if invalid increment
--- End diff --
Maybe I wasn't clear before. I mean create a new DateMathParser using the
constructor that accept the timezone (and we can supply ours; null is okay).
Then call the instance method `parseMath(str)` on it (not the static with
'now'). the arg should be the start metadata. The "now" will default to the
current instant in time which is what we want.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]