Skip to content

Commit

Permalink
Merge pull request #5930 from confluentinc/26092024-2
Browse files Browse the repository at this point in the history
26092024 2 (#13)
  • Loading branch information
vdesabou authored Sep 27, 2024
2 parents 0ee38ba + 1a705e9 commit e8f167f
Show file tree
Hide file tree
Showing 12 changed files with 621 additions and 464 deletions.
2 changes: 1 addition & 1 deletion connect/connect-filestream-sink/filestream-sink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ playground topic produce -t filestream --nb-messages 5 << 'EOF'
"email": "faker.internet.exampleEmail()",
"phone": "faker.phone.imei()",
"website": "faker.internet.domainName()",
"city": "faker.address.city()",
"city": "faker.location.city()",
"company": "faker.company.name()"
}
]
Expand Down
2 changes: 1 addition & 1 deletion connect/connect-http-sink/http_no_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ playground topic produce -t http-messages --nb-messages 10 << 'EOF'
"email": "faker.internet.exampleEmail()",
"phone": "faker.phone.imei()",
"website": "faker.internet.domainName()",
"city": "faker.address.city()",
"city": "faker.location.city()",
"company": "faker.company.name()"
}
EOF
Expand Down
2 changes: 1 addition & 1 deletion connect/connect-http-sink/http_oauth2_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ playground topic produce -t http-messages --nb-messages 10 << 'EOF'
"email": "faker.internet.exampleEmail()",
"phone": "faker.phone.imei()",
"website": "faker.internet.domainName()",
"city": "faker.address.city()",
"city": "faker.location.city()",
"company": "faker.company.name()"
}
EOF
Expand Down
898 changes: 451 additions & 447 deletions scripts/cli/completions.bash

Large diffs are not rendered by default.

80 changes: 74 additions & 6 deletions scripts/cli/playground

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion scripts/cli/playground.json
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@
},
{
"name": "stop",
"description": "🛑 Stop connector (only available if CP > 7.5 )\n",
"description": "🛑 Stop connector (only available if CP > 7.5)\n",
"usage": "playground connector stop [OPTIONS]",
"options": [
{
Expand Down Expand Up @@ -2697,6 +2697,17 @@
],
"argument": "OFFSETS",
"description": "📍 Create connector with offsets (https://docs.confluent.io/cloud/current/connectors/offsets.html#create-connectors-with-offsets)\n\n⚠️ Only available for ccloud connectors, the connector should not really exists\n"
},
{
"names": [
"--initial-state"
],
"argument": [
"RUNNING",
"PAUSED",
"STOPPED"
],
"description": "🪵 Create connector with specific status (https://cwiki.apache.org/confluence/display/KAFKA/KIP-980%3A+Allow+creating+connectors+in+a+stopped+state)\n\nOnly available if CP > 7.7\n\n⚠️ not available for ccloud connectors\n\nAllowed values: RUNNING, PAUSED, STOPPED\n"
}
]
},
Expand Down
14 changes: 13 additions & 1 deletion scripts/cli/playground.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,7 @@ subcommands:
- name: stop
description: |
🛑 Stop connector (only available if CP > 7.5 )
🛑 Stop connector (only available if CP > 7.5)
usage: playground connector stop [OPTIONS]
options:
- names:
Expand Down Expand Up @@ -2833,6 +2833,18 @@ subcommands:
⚠️ Only available for ccloud connectors, the connector should not really exists
- names:
- --initial-state
argument: [RUNNING, PAUSED, STOPPED]
description: |
🪵 Create connector with specific status (https://cwiki.apache.org/confluence/display/KAFKA/KIP-980%3A+Allow+creating+connectors+in+a+stopped+state)
Only available if CP > 7.7
⚠️ not available for ccloud connectors
Allowed values: RUNNING, PAUSED, STOPPED
- name: update
description: |
🛠️ Update connector configuration by opening current connector config in text editor set with playground config editor <editor> (default is code). Once file is saved, the new configuration is updated.
Expand Down
2 changes: 1 addition & 1 deletion scripts/cli/predefined-schemas/json/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"email": "faker.internet.exampleEmail()",
"phone": "faker.phone.imei()",
"website": "faker.internet.domainName()",
"city": "faker.address.city()",
"city": "faker.location.city()",
"company": "faker.company.name()"
}
2 changes: 1 addition & 1 deletion scripts/cli/snippets/sink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ playground topic produce -t topic-json --nb-messages 5 << 'EOF'
"email": "faker.internet.exampleEmail()",
"phone": "faker.phone.imei()",
"website": "faker.internet.domainName()",
"city": "faker.address.city()",
"city": "faker.location.city()",
"company": "faker.company.name()"
}
]
Expand Down
18 changes: 16 additions & 2 deletions scripts/cli/src/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ commands:
"email": "faker.internet.exampleEmail()",
"phone": "faker.phone.imei()",
"website": "faker.internet.domainName()",
"city": "faker.address.city()",
"city": "faker.location.city()",
"company": "faker.company.name()"
}
EOF
Expand Down Expand Up @@ -3076,7 +3076,7 @@ commands:
- *connector

- name: stop
help: 🛑 Stop connector (only available if CP > 7.5 )
help: 🛑 Stop connector (only available if CP > 7.5)
flags:
- *verbose
- *connector
Expand Down Expand Up @@ -3299,6 +3299,20 @@ commands:
⚠️ Only available for ccloud connectors, the connector should not really exists
- long: --initial-state
arg: initial-state
allowed:
- RUNNING
- PAUSED
- STOPPED
required: false
help: |-
🪵 Create connector with specific status (https://cwiki.apache.org/confluence/display/KAFKA/KIP-980%3A+Allow+creating+connectors+in+a+stopped+state)
Only available if CP > 7.7
⚠️ not available for ccloud connectors
examples: |
playground connector create-or-update -c filestream-sink << EOF
{
Expand Down
47 changes: 45 additions & 2 deletions scripts/cli/src/commands/connector/create-or-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ skip_automatic_connector_config=${args[--skip-automatic-connector-config]}
verbose="${args[--verbose]}"
no_clipboard="${args[--no-clipboard]}"
offsets=${args[--offsets]}
initial_state=${args[--initial-state]}

connector_type=$(playground state get run.connector_type)

Expand All @@ -26,6 +27,21 @@ then
fi
fi

if [[ -n "$initial_state" ]]
then
tag=$(docker ps --format '{{.Image}}' | egrep 'confluentinc/cp-.*-connect-base:' | awk -F':' '{print $2}')
if [ $? != 0 ] || [ "$tag" == "" ]
then
logerror "❌ could not find current CP version from docker ps"
exit 1
fi

if ! version_gt $tag "7.6.99"; then
logerror "❌ --initial-state is available since CP 7.7 only"
exit 1
fi
fi

environment=$(playground state get run.environment_before_switch)
if [ "$environment" = "" ]
then
Expand Down Expand Up @@ -55,6 +71,7 @@ fi
json_file=$tmp_dir/connector.json
new_json_file=$tmp_dir/connector_new.json
connector_with_offsets_file=$tmp_dir/connector_with_offsets.json
connector_with_initial_state_file=$tmp_dir/connector_with_initial_state.json
json_validate_file=$tmp_dir/json_validate_file

echo "$json_content" > $json_file
Expand Down Expand Up @@ -213,6 +230,12 @@ then
exit 1
fi

if [[ -n "$initial_state" ]]
then
logerror "❌ --initial-state is set but not supported with $connector_type connector"
exit 1
fi

get_ccloud_connect
if [[ -n "$offsets" ]]
then
Expand All @@ -235,15 +258,35 @@ else
logerror "❌ --offsets is set but not supported with $connector_type connector"
exit 1
fi
if [[ -n "$initial_state" ]] && [ $is_create == 0 ]
then
logerror "❌ --initial-state is set but $connector_type connector $connector already exists"
exit 1
fi
get_connect_url_and_security
if [[ -n "$skip_automatic_connector_config" ]]
then
log "🤖 --skip-automatic-connector-config is set"
else
add_connector_config_based_on_environment "$environment" "$json_content"
fi
echo "$json_content" > $new_json_file
handle_onprem_connect_rest_api "curl $security -s -X PUT -H \"Content-Type: application/json\" --data @$new_json_file $connect_url/connectors/$connector/config"

if [[ -n "$initial_state" ]]
then
log "🪵 creating $connector_type connector $connector with --initial-state: $initial_state"
# add mandatory name field
new_json_content=$(echo $json_content | jq -c ". + {\"name\": \"$connector\"}")

sed -e "s|:CONNECTOR_NAME:|$connector|g" \
-e "s|:CONNECTOR_CONFIG:|$new_json_content|g" \
-e "s|:CONNECTOR_INITIAL_STATE:|$initial_state|g" \
$root_folder/scripts/cli/src/create-connector-post-template-initial-state.json > ${connector_with_initial_state_file}

handle_onprem_connect_rest_api "curl $security -s -X POST -H \"Content-Type: application/json\" --data @$connector_with_initial_state_file $connect_url/connectors"
else
echo "$json_content" > $new_json_file
handle_onprem_connect_rest_api "curl $security -s -X PUT -H \"Content-Type: application/json\" --data @$new_json_file $connect_url/connectors/$connector/config"
fi
fi

if [[ -n "$level" ]]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": ":CONNECTOR_NAME:",
"config": :CONNECTOR_CONFIG:,
"initial_state": ":CONNECTOR_INITIAL_STATE:"
}

0 comments on commit e8f167f

Please sign in to comment.