Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
psuter committed Feb 26, 2016
1 parent 3290095 commit d75f187
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 6 deletions.
4 changes: 3 additions & 1 deletion common/scala/src/whisk/core/database/CouchDb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class CouchDb(host: String, port: Int, dbUsername: String, dbPassword: String) {

def getDb(name: String): CouchDatabase = {
if (name != null && name.nonEmpty)
client.database(name, false)
client.database(name, true) // Hack so that I don't have to create the DBs.
else null
}

def shutdown() : Unit = client.shutdown()
}
4 changes: 3 additions & 1 deletion common/scala/src/whisk/core/database/CouchDbStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.lightcouch.CouchDbException
import org.lightcouch.NoDocumentException
import org.lightcouch.Response

class CouchDBStore[RawDocument, DocumentAbstraction](
class CouchDbStore[RawDocument, DocumentAbstraction](
host: String,
port: Int,
dbUsername: String,
Expand Down Expand Up @@ -142,4 +142,6 @@ class CouchDBStore[RawDocument, DocumentAbstraction](
case _ => msg
}
}

def shutdown() : Unit = client.shutdown()
}
13 changes: 10 additions & 3 deletions common/scala/src/whisk/core/entity/WhiskStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ object WhiskAuthStore {

def datastore(config: WhiskConfig) = {
require(config != null && config.isValid, "config is undefined or not valid")
new CloudantStore[AuthRecord, WhiskAuth](config.dbUsername, config.dbPassword, config.dbAuths)
// new CloudantStore[AuthRecord, WhiskAuth](config.dbUsername, config.dbPassword, config.dbAuths)
import whisk.core.database.CouchDbStore
new CouchDbStore[AuthRecord, WhiskAuth]("172.17.0.2", 6984, "whisk_admin", "passw0rd", config.dbAuths)
}
}

Expand All @@ -87,7 +89,9 @@ object WhiskEntityStore {

def datastore(config: WhiskConfig) = {
require(config != null && config.isValid, "config is undefined or not valid")
new CloudantStore[EntityRecord, WhiskEntity](config.dbUsername, config.dbPassword, config.dbWhisk)
// new CloudantStore[EntityRecord, WhiskEntity](config.dbUsername, config.dbPassword, config.dbWhisk)
import whisk.core.database.CouchDbStore
new CouchDbStore[EntityRecord, WhiskEntity]("172.17.0.2", 6984, "whisk_admin", "passw0rd", config.dbWhisk)
}
}

Expand All @@ -99,7 +103,10 @@ object WhiskActivationStore {

def datastore(config: WhiskConfig) = {
require(config != null && config.isValid, "config is undefined or not valid")
new CloudantStore[ActivationRecord, WhiskActivation](config.dbUsername, config.dbPassword, config.dbActivations)

//new CloudantStore[ActivationRecord, WhiskActivation](config.dbUsername, config.dbPassword, config.dbActivations)
import whisk.core.database.CouchDbStore
new CouchDbStore[ActivationRecord, WhiskActivation]("172.17.0.2", 6984, "whisk_admin", "passw0rd", config.dbActivations)
}
}

Expand Down
15 changes: 15 additions & 0 deletions config/cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

curl -k -X POST \
-H 'Content-Type: application/json' \
-d '{
"_id": "_design/subjects",
"views": {
"uuids": {
"map": "function (doc) { emit([doc.uuid], {secret: doc.key}); }"
}
},
"language" : "javascript",
"indexes": {} }' \
https://whisk_admin:passw0rd@172.17.0.2:6984/subjects

2 changes: 1 addition & 1 deletion tests/src/whisk/core/database/test/DbUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ trait DbUtils extends TransactionCounter {
} else true
}
}, timeout)
assert(success.isSuccess, "wait aborted")
assert(success.isSuccess, "wait aborted after: " + timeout + ": " + success)
}

/**
Expand Down
47 changes: 47 additions & 0 deletions tools/couchdb/createAdmin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

COUCHDB_HOST="localhost"
COUCHDB_PORT="6984"
COUCHDB_USER="whisk_admin"

usage() {
echo "Usage: $0 -h HOST -p PORT -u USER -P PASS" 1>&2;
echo " HOST defaults to ${COUCHDB_HOST}" 1>&2;
echo " PORT defaults to ${COUCHDB_PORT}" 1>&2;
echo " USER defaults to ${COUCHDB_USER}" 1>&2;
echo " PASS is mandatory." 1>&2;
exit 1;
}

while getopts ":h:p:u:P:" opt; do
case "${opt}" in
h)
COUCHDB_HOST=${OPTARG}
;;
p)
COUCHDB_PORT=${OPTARG}
;;
u)
COUCHDB_USER=${OPTARG}
;;
P)
COUCHDB_PASS=${OPTARG}
;;
*)
usage
;;
esac
done

if [ -z "${COUCHDB_PASS}" ]; then
usage
fi

shift $((OPTIND-1))

CURL="curl -k"

# Attempt to register the user as admin. This generally only works on fresh installs.
# - an output of "" is a good sign.
# - an output of {"error": ...} is not a good sign.
${CURL} -X PUT https://${COUCHDB_HOST}:${COUCHDB_PORT}/_config/admins/${COUCHDB_USER} -d "\"${COUCHDB_PASS}\""

0 comments on commit d75f187

Please sign in to comment.