DATACOUCH-19 - adding logging for bucket creation.

This commit is contained in:
Michael Nitschinger
2013-07-29 13:37:27 +02:00
parent 3a72ca7f96
commit e0e8b63d93

View File

@@ -6,6 +6,8 @@ import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
@@ -18,6 +20,8 @@ import java.util.Arrays;
public class BucketCreator implements InitializingBean {
private final Logger logger = LoggerFactory.getLogger(BucketCreator.class);
private final String hostUri;
private final String adminUser;
private final String adminPass;
@@ -40,21 +44,29 @@ public class BucketCreator implements InitializingBean {
String fullUri = hostUri + "/default/buckets/default";
ResponseEntity<String> entity = null;
try {
template.getForEntity(fullUri, String.class);
entity = template.getForEntity(fullUri, String.class);
} catch (HttpClientErrorException ex) {
logger.info("Got execpetion while looking for bucket: " + ex.getMessage());
if (ex.getMessage().equals("404 Object Not Found")) {
logger.info("Creating default bucket with admin credentials.");
createBucket();
return;
} else {
throw new RuntimeException("Could not see if bucket is already created.", ex);
}
}
logger.info("Checking for bucket returned status code " + entity.getStatusCode());
}
private void createBucket() throws Exception {
ClusterManager bucketManager =
new ClusterManager(Arrays.asList(new URI(hostUri)), adminUser, adminPass);
bucketManager.createDefaultBucket(BucketType.COUCHBASE, 128, 0, true);
logger.info("Finished creating bucket, sleeping for warmup.");
Thread.sleep(5000);
bucketManager.shutdown();
}