Skip to content

Commit

Permalink
More updates for #110. REST API updates (not yet visible) and import_…
Browse files Browse the repository at this point in the history
…json_documents.sh script.
  • Loading branch information
JoelProminic committed Feb 8, 2024
1 parent ef5b03b commit 5cb3d5d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
- { src: 'deploy_database.sh.j2', dest: '/opt/domino/scripts/deploy_database.sh', owner: '{{ service_user }}' }
- { src: 'deploy_html.sh.j2', dest: '/opt/domino/scripts/deploy_html.sh', owner: '{{ service_user }}' }
- { src: 'run_dxl_importer.sh.j2', dest: '/opt/domino/scripts/run_dxl_importer.sh', owner: '{{ service_user }}'}
- { src: 'import_json_documents.sh.j2', dest: '/opt/domino/scripts/import_json_documents.sh', owner: '{{ service_user }}'}

-
name: "Placing Configuration and scripts"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
# Import a JSON file containing documents into database(s) using Genesis.

USAGE="./import_json_documents.sh <json-file>"


set -e

if [ "$#" -lt 1 ]; then
echo "At least one JSON file required. USAGE:"
echo " $USAGE"
exit 1
fi

# Parameters
SOURCE_FILE=$1

# Genesis directories
GENESIS_DIR={{ domino_home_dir }}/JavaAddin/Genesis
JSON_TRIGGER_DIR=$GENESIS_DIR/json
JSON_RESPONSE_DIR=$GENESIS_DIR/jsonresponse

importJsonFile() {
# parameters
JSON_SOURCE_FILE=$1

# validate the file
if jq -reM '""' "$JSON_SOURCE_FILE" 2>&1; then
echo "No errors found in file '$JSON_SOURCE_FILE'";
else
echo "Invalid JSON: '$JSON_SOURCE_FILE'"
exit 1
fi

# Ensure directories exist
sudo mkdir -p "$JSON_TRIGGER_DIR"
sudo mkdir -p "$JSON_RESPONSE_DIR"
sudo chown {{ domino_user }}:{{ domino_group }} "$JSON_TRIGGER_DIR"
sudo chown {{ domino_user }}:{{ domino_group }} "$JSON_RESPONSE_DIR"

# extract the file name
JSON_BASE_NAME=`basename -s .json "$JSON_SOURCE_FILE"`
# build a unique target name and path
TIMESTAMP=`date +%Y%m%d%H%M%S`
JSON_TARGET_NAME="${TIMESTAMP}_${JSON_BASE_NAME}.json"
JSON_TARGET_FILE=$JSON_TRIGGER_DIR/$JSON_TARGET_NAME

# Start operation
sudo chown {{ domino_user }}:{{ domino_group }} "$JSON_SOURCE_FILE"
sudo cp "$JSON_SOURCE_FILE" "$JSON_TARGET_FILE"
echo "Starting import: $JSON_TARGET_FILE"

# Wait for operation to complete
ALLOWED_RETRIES=3
RETRIES=0
while [ -e $JSON_TARGET_FILE ]; # && "$RETRIES" -lt "$ALLOWED_RETRIES" ];
do
sleep 1;
RETRIES=$((RETRIES+1));
done
if [ "$RETRIES" -ge "$ALLOWED_RETRIES" ]; then
echo "Timeout on import attempt.";
exit 1;
fi

# check response
JSON_RESPONSE_FILE="$JSON_RESPONSE_DIR/$JSON_TARGET_NAME"
RESPONSE=$(cat "$JSON_RESPONSE_FILE" | tr -d '\n')
if [ "$RESPONSE" = "OK" ]; then
echo "Import successful."
else
echo "Deployment failed: '$RESPONSE'"
exit 1
fi
}

importJsonFile "$SOURCE_FILE"
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ restinterface:
- upload-html
- java-domino-gradle
- nsfodp
serverName: demo/DEMO
baseURL: https://127.0.0.1:{{ domino_vagrant_rest_api_port_forwards[0].guest }}
- import-domino-json
{% if domino_major_version == 12 and domino_patch_version == 1 %}
serverName: {{ settings.hostname }}/{{ domino_organization }}
{% else %}
serverName: {{ settings.hostname }}.{{ settings.domain }}/{{ domino_organization }}
{% endif %}
baseURL: https://domino.{{ settings.hostname }}.{{ settings.domain|lower }}
dominoVersion: {{ domino_major_version }}.{{ domino_minor_version }}.{{ domino_patch_version }}

0 comments on commit 5cb3d5d

Please sign in to comment.