Several issues with cluster management api

I have encountered lots of issues with node js api to manage a cluster.
1-I can’t create a bucket. ClusterManager.createBucket always return an error “Error”.
I tried with REST api using the node builtin http module and get an invalid authentication error.
Finally got it working using the node module “request” to make a REST api call, so probably something is not working with the latest node 6.6 and http module and since I saw the node sdk also use raw http module, the problem is probably there.
2-After I created the bucket with the REST api, the openbucket return “CouchbaseError: Data received on socket was not in the expected format”, if it is being called on the same process".
If I rerun the script with the bucket already there, I can open the bucket just fine.

I am running Node JS 6.6 on Windows with the 2.2.3 sdk and connected to a Couchbase 4.5.1 server on a mac through local networking.

In case anybody else have the same error, I managed to solve problem 2 by adding a delay between the creating of the bucket and the connection. Probably was still initializing the bucket.
Problem one still persist and the only solution is to use the REST api with request module.

1 Like

Could you post a code snippet of trying to create a bucket with the node API? Sounds like it could be a bug and worth creating a ticket for.

Same as the docs:
http://developer.couchbase.com/documentation/server/current/sdk/nodejs/managing-clusters.html
And this is my replacement using REST and the request module :

function CreateBucket(bucket_name, callback, opts) {


    if (opts == undefined) opts = defaultOpts;
    var cluster = new couchbase.Cluster(config.connstr);

    var cluster_man = cluster.manager(config.admin, config.admin_pwd)
    cluster_man.listBuckets(function (err, buckets) {
        if (err) {
            console.log("CreateBucket " + err);
            return;
        }
        for (var i = 0; i < buckets.length; i++) {
            if (buckets[i].name == bucket_name) {
                
                callback("CreateBucket " + bucket_name + " already exist.",true);
                return;
            }
        }

        //replacement for node sdk CreateBucket, because doesn't work for me....
        request.post(config.connstr + "/pools/default/buckets", {
            form: {
                "name": bucket_name,
                "authType": "sasl",
                "saslPassword": config.bucket_pwd,
                "bucketType": "couchbase",
                "ramQuotaMB": 200
            }
        },
            function (err, httpResponse, body) {
                if(!err){
                    callback(body,false);
                    
                    return;
                }
                console.log(' Server responded with:',err);

            }
        ).auth(config.admin, config.admin_pwd, false);


    });


}

@brett19 Could you have a look?

Regarding number 2, I also see this. Creating a bucket, then trying to open the bucket from the same process fails with the “not in the expected format” message. However, when rerunning the script with the bucket already created, I can open it without an error.

I am using the node.js SDK.

I initially tried adding a delay of 1 second between the two commands but it didn’t help. However, increasing this to 2 seconds does seem to fix this. I would guess that the bucket has not finished initialising or something after 1 second, although the cluseterManager.createBucket call returned before starting the delay. Is there an event or any other way to find out when the bucket is ready and can be opened rather than adding an arbitrary delay?

Thanks,
Giles