Permalink
Browse files

NCBC-49: Allow boostrapping to be compatible with /pools/default

Change-Id: Id3a986bef6e29fa8fa541f99f229a4aeb03856c1
Reviewed-on: http://review.couchbase.org/16517
Tested-by: Matt Ingenthron <matt@couchbase.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information...
1 parent 1ef6f9e commit 058a128425f54c91f329dfc57c82c6d95c779757 @johnzablocki johnzablocki committed with John C. Zablocki May 30, 2012
Showing with 30 additions and 2 deletions.
  1. +30 −2 src/Couchbase/ConfigHelper.cs
@@ -65,7 +65,7 @@ private static BootstrapInfo GetPoolsConfigUri(WebClient client, Uri clusterUrl)
/// <returns></returns>
public static ClusterConfig ResolveBucket(WebClient client, Uri bootstrapUri, string name)
{
- var bootstrapConfig = ConfigHelper.GetPoolsConfigUri(client, bootstrapUri);
+ var bootstrapConfig = ConfigHelper.GetPoolsConfigUri(client, cleanBootstrapUri(bootstrapUri));
var basePoolsConfigUri = new UriBuilder(bootstrapUri.Scheme, bootstrapUri.Host, bootstrapUri.Port).Uri;
var info = ConfigHelper.GetClusterInfo(client, new Uri(basePoolsConfigUri, bootstrapConfig.Uri));
@@ -82,6 +82,34 @@ public static ClusterConfig ResolveBucket(WebClient client, Uri bootstrapUri, st
return retval;
}
+
+ private static Uri cleanBootstrapUri(Uri bootstrapUri)
+ {
+ var lastSegment = bootstrapUri.Segments[bootstrapUri.Segments.Length - 1];
+
+ if (lastSegment == "/" && log.IsErrorEnabled) log.ErrorFormat("Invalid pool uri. No path specified: {0}", bootstrapUri.AbsoluteUri);
+
+ if (lastSegment.StartsWith("default", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if (log.IsWarnEnabled) log.WarnFormat("Client should bootstrap off of /pools, not {0}.", bootstrapUri.PathAndQuery);
+
+ //Previously the client expected to boostrap off of /pools/default,
+ //when it should be bootstrapping off of /pools. This code
+ //hides the change by forcing /default to /pools, though after
+ //a grace period a future release will not clean the Uri
+ var cleanedBootstrapUri = new UriBuilder
+ {
+ Scheme = bootstrapUri.Scheme,
+ Host = bootstrapUri.Host,
+ Port = bootstrapUri.Port,
+ Path = bootstrapUri.PathAndQuery.Replace(lastSegment, "")
+ }.Uri;
+
+ return cleanedBootstrapUri;
+ }
+
+ return bootstrapUri;
+ }
}
}
@@ -90,7 +118,7 @@ public static ClusterConfig ResolveBucket(WebClient client, Uri bootstrapUri, st
*
* @author Couchbase <info@couchbase.com>
* @copyright 2012 Couchbase, Inc.
- * @copyright 2010 Attila Kiskó, enyim.com
+ * @copyright 2010 Attila Kiskó, enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

0 comments on commit 058a128

Please sign in to comment.