CURL脚本用于Couchbase分析中的“Map From Data Services”功能。

huangapple go评论66阅读模式
英文:

CURL Script for "Map From Data Services" functionality in Couchabase analytics

问题

我正在尝试使用CURL创建一个脚本,将数据服务中存储桶范围内的所有集合映射到本地的分析服务(Couchbase)。

我在我的数据节点中创建了大约50个集合,现在我需要它们在我的分析节点中(本地,没有远程链接)。

如果有人已经完成了这个任务,请提供建议。

附注:不需要ChatGPT的答案,已经尝试过它们,但没有成功。

已经尝试过CBQ命令、CLI命令和CURL命令,但都没有成功。

希望能够通过以上任何一种方式实现相同的目标。

英文:

I am trying to create a script using CURL to map all collections present in a bucket.scope from data service to analytical service locally (Couchbase).

I have 50 odd collections created in my data node and now i need them in my analytics node (locally , no remote links).

suggest if any one has already done this.

P.S, No ChatGPT answers, tried them all not working.

Tried CBQ Commands, CLI commands, CURL commands. No Luck.

Hoping to acheive the same with any of the above.

答案1

得分: 1

I'm not sure if there is a way to do this with a single cURL command, but you could do this with a series of cURL commands orchestrated in a small bash script such as the example below:

#!/bin/bash

USERNAME=administrator
PASSWORD=password
COUCHBASE_HOST=http://127.0.0.1:8091
ANALYTICS_HOST=http://127.0.0.1:8095

BUCKET=$1
SCOPE=$2

if [ $# != 2 ]; then
  echo Usage: $0 <bucket> <scope>
  exit 1
fi

run_analytics () {
  echo Running "$*"
  curl -s -u $USERNAME:$PASSWORD $ANALYTICS_HOST/analytics/service -d statement="$*" | jq '.errors[].msg' 2>/dev/null
}

echo Mapping $BUCKET.$SCOPE in Analytics

run_analytics CREATE ANALYTICS SCOPE `$BUCKET`.`$SCOPE` IF NOT EXISTS
run_analytics DISCONNECT LINK `$BUCKET`.`$SCOPE`.Local

for collection in $(curl -s -u $USERNAME:$PASSWORD $COUCHBASE_HOST/pools/default/buckets/$BUCKET/scopes | jq -r ".scopes[] | select(.name == \"$SCOPE\") | .collections[].name"); do
  run_analytics ALTER COLLECTION `$BUCKET`.`$SCOPE`.`$collection` ENABLE ANALYTICS
done

run_analytics CONNECT LINK `$BUCKET`.`$SCOPE`.Local

Note that there's no error handling, handling of funky bucket characters that would require URL encoding, etc. but hopefully this helps...
英文:

I'm not sure if there is a way to do this with a single cURL command, but you could do this with series of cURL commands orchestrated in a small bash script such as the example below:

#!/bin/bash

USERNAME=administrator
PASSWORD=password
COUCHBASE_HOST=http://127.0.0.1:8091
ANALYTICS_HOST=http://127.0.0.1:8095

BUCKET=$1
SCOPE=$2

if [ $# != 2 ]; then
  echo Usage: $0 \&lt;bucket\&gt; \&lt;scope\&gt;
  exit 1
fi

run_analytics () {
  echo Running &quot;$*&quot;
  curl -s -u $USERNAME:$PASSWORD $ANALYTICS_HOST/analytics/service -d statement=&quot;$*&quot; | jq &#39;.errors[].msg&#39; 2&gt;/dev/null
}

echo Mapping $BUCKET.$SCOPE in Analytics

run_analytics CREATE ANALYTICS SCOPE \`$BUCKET\`.\`$SCOPE\` IF NOT EXISTS
run_analytics DISCONNECT LINK \`$BUCKET\`.\`$SCOPE\`.Local

for collection in $(curl -s -u $USERNAME:$PASSWORD $COUCHBASE_HOST/pools/default/buckets/$BUCKET/scopes | jq -r &quot;.scopes[] | select(.name == \&quot;$SCOPE\&quot;) | .collections[].name&quot;); do
  run_analytics ALTER COLLECTION \`$BUCKET\`.\`$SCOPE\`.\`$collection\` ENABLE ANALYTICS
done

run_analytics CONNECT LINK \`$BUCKET\`.\`$SCOPE\`.Local

Note that there's no error handling, handling of funky bucket characters that would require URL encoding, etc. but hopefully this helps...

huangapple
  • 本文由 发表于 2023年6月19日 15:40:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76504556.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定