Replicating from cb_lite to cb_server through sync_gateway

I am developing for a new application and trying to replicate the changes from cb_lite to cb_server through sync_gateway, but _replicate endpoint is unsuccessful. I have my cb_server at http://172.20.21.11:8091

This is my sync_gateway config file:

{
   "interface":":4984",
   "adminInterface":"0.0.0.0:4985",
   "log":["REST"],
   "databases":{
      "sync_gateway":{
         "server":"http://172.20.21.11:8091",
         "sync":`function(doc) {channel(doc.channels);}`
      }
   }
}

successfully running sync_gateway at http://172.20.21.10:4984

I am also using couchbase_lite_local for this POC Demo, so after downloading the .jar file, I can kick off the REST api by running java -jar couchbase-lite-local.jar, so I have cb_lite running at http://172.20.21.10:5984

I have then created a few documents through cb_lite API, so I can retrieve them by going to http://172.20.21.10:5984/sync_gateway/_all_docs

{
    "offset": 0,
    "total_rows": 2,
    "rows": [
        {
            "id": "126ae767-a78d-449e-8fb6-1e5449c34f3e",
            "value": {
                "rev": "1-f14eb3706bfafd3762f007defc5367f0",
                "_conflicts": []
            },
            "key": "126ae767-a78d-449e-8fb6-1e5449c34f3e"
        },
        {
            "id": "d6a72266-c2c7-4df3-8904-b323457a7068",
            "value": {
                "rev": "1-952026746a3efd5ae6cb2ce92116ba14",
                "_conflicts": []
            },
            "key": "d6a72266-c2c7-4df3-8904-b323457a7068"
        }
    ]
}

Now I like to _replicate these documents to the cb_server, so I am running a POST request to http://172.20.21.10:5984/_replicate with the following body:

{
   "create_target" : true,
   "source" : "http://172.20.21.10:4984/sync_gateway/",
   "target" : "sync_gateway"
}

The data doesn’t get synced to cb_server. Here is the log I see in cb_lite after request:

Nov 05, 2014 2:10:15 AM com.couchbase.lite.util.SystemLogger w
WARNING: Listener: authHeader is null
Nov 05, 2014 2:10:15 AM com.couchbase.lite.util.SystemLogger w
WARNING: Listener: Unauthorized -- requestCredentials not given or do not match allowed credentials
Nov 05, 2014 2:10:15 AM com.couchbase.lite.util.SystemLogger e
SEVERE: RemoteRequest: Got error status: 404 for org.apache.http.client.methods.HttpGet@6a290e04.  Reason: Not Found
Nov 05, 2014 2:10:15 AM com.couchbase.lite.util.SystemLogger w
WARNING: Sync: Puller@7c5a1774[http://172.20.21.10:4984/sync_gateway/]: starting ChangeTracker with since=null
Nov 05, 2014 2:10:15 AM com.couchbase.lite.util.SystemLogger w
WARNING: Sync: Puller@7c5a1774[http://172.20.21.10:4984/sync_gateway/]: started ChangeTracker com.couchbase.lite.replicator.ChangeTracker@47a2449b
Nov 05, 2014 2:10:15 AM com.couchbase.lite.util.SystemLogger w
WARNING: Sync: Puller@7c5a1774[http://172.20.21.10:4984/sync_gateway/]: Received invalid doc ID from _changes: {seq=1, id=_user/GUEST, changes=[]}
Nov 05, 2014 2:10:15 AM com.couchbase.lite.util.SystemLogger w
WARNING: ChangeTracker: com.couchbase.lite.replicator.ChangeTracker@47a2449b: Change tracker calling stop (OneShot)
Nov 05, 2014 2:10:15 AM com.couchbase.lite.util.SystemLogger w
WARNING: Sync: Puller@7c5a1774[http://172.20.21.10:4984/sync_gateway/]: ChangeTracker com.couchbase.lite.replicator.ChangeTracker@47a2449b stopped

Any guru out there knows what’s missing from this workflow? I am stuck pushing the changes from cb_lite to the cb_server and vice verse.

Anyone has any input on this? Am I missing an obvious step here?

I don’t immediately spot anything, but I’m not great at knowing what an expected log would look like. One thing missing here is the versions you’re using. Since it seems to be in the Couchbase Lite app, maybe @sweetiewill or @traun can advise if it’s normal to see the warning about null and auth header.

I have even revised the config.json to enable GUEST.

{
   "interface":":4984",
   "adminInterface":"0.0.0.0:4985",
   "log": ["CRUD+", "REST+", "Changes+", "Attach+"],
   "databases":{
      "sync_gateway":{
         "server":"http://172.20.21.11:8091",
         "users": {
             "GUEST": {"disabled": false, "admin_channels": ["*"]}
         },
         "sync":`function(doc) {channel(doc.channels);}`
      }
   }
} 

Here is a sample document I have created through cb_lite api:

{
   "channels": "user",
   "owner": "johns",

   "username": "johns",
   "name": "John S.",
   "email": "hello@hello.com"
}

but I am still unable to sync the docs from cb_lite to cb_server and back.

Hey @aminjam,

Curious if you added a change listener within your application ?

No, I just wanted to get a basic _replicate endpoint working first from cb_lite to cb_server through sync_gateway.

Are you still getting that error? By default the listener expects some basic auth credentials on every request, and if they don’t match what it expects, it will reject the request.

In the phonegap plugin, it first creates a Credentials object with randomly generated username/password:

and then later, when the Javascript code asks for the URL of the coucbhase lite listener, it will return those same credentials:

so that the Javascript code can pass them when it makes requests to the couchbase lite rest api.

Thanks @traun and @sweetiewill for the help. I really wanted to get the POC demo working for https://github.com/aminjam/hipops/tree/master/devops/scenarios/hipops-CBServerSyncGateway-dev so that I can connect CB_Server, CB_SyncGateway and CB_Lite all together in a single orchestration config. Since I couldn’t connect the CB_Lite, I made the configuration work with the Todo-Lite PhoneGap instead. That being said, I would like to collaborate with the team and expand docker orchestration tooling with hipops. Any input?