From b8bfef3a009922db72c1a618211ce03c07683e58 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Thu, 12 Aug 2021 23:05:15 +0100 Subject: Implement simple onboarding cassandra upgrade Introduces a folder to hold cql scripts to upgrade the onboarding cassandra. The files will be copied to the docker and executed in alphabetical order. The suggested pattern for the file names is YYYYMMDD-changeName.cql. Change-Id: Ia32a63ec5ab4417cf0df8bb5536c7f041e2327c9 Issue-ID: SDC-3669 Signed-off-by: andre.schmid --- integration-tests/pom.xml | 2 +- openecomp-be/.gitignore | 1 + openecomp-be/dist/pom.xml | 1 - .../artifacts/Dockerfile | 4 +-- .../artifacts/startup.sh | 42 ++++++++++++++-------- .../dist/sdc-onboard-db-init-docker/pom.xml | 31 ++++++++++++++-- openecomp-be/pom.xml | 1 + .../tools/install/database/alter_tables.cql | 1 - .../20191103-dox.package_details.cql | 1 + 9 files changed, 62 insertions(+), 22 deletions(-) delete mode 100644 openecomp-be/tools/install/database/alter_tables.cql create mode 100644 openecomp-be/tools/install/database/upgrade-scripts/20191103-dox.package_details.cql diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 5a80dcd26c..1656e28bce 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -544,7 +544,7 @@ limitations under the License. - Initializing onboard schemas + Onboarding init was successful custom diff --git a/openecomp-be/.gitignore b/openecomp-be/.gitignore index 2c9567e1a0..ab9a3f3ccc 100644 --- a/openecomp-be/.gitignore +++ b/openecomp-be/.gitignore @@ -11,3 +11,4 @@ package *.iml *.ipr *.iws +/dist/sdc-onboard-db-init-docker/artifacts/upgrade-scripts/ diff --git a/openecomp-be/dist/pom.xml b/openecomp-be/dist/pom.xml index 706f013743..83208a0a4a 100644 --- a/openecomp-be/dist/pom.xml +++ b/openecomp-be/dist/pom.xml @@ -3,7 +3,6 @@ 4.0.0 openecomp-sdc-docker-dist - org.openecomp.sdc openecomp-sdc-docker-dist pom diff --git a/openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/Dockerfile b/openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/Dockerfile index 8408d2f51c..05034e1565 100644 --- a/openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/Dockerfile +++ b/openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/Dockerfile @@ -32,8 +32,8 @@ USER sdc COPY --chown=sdc:sdc init_keyspaces.cql /home/sdc/ COPY --chown=sdc:sdc init_schemas.cql /home/sdc/ -COPY --chown=sdc:sdc alter_tables.cql /home/sdc/ -COPY --chown=sdc:sdc startup.sh /home/sdc/ +COPY --chown=sdc:sdc upgrade-scripts /home/sdc/upgrade-scripts +COPY --chown=sdc:sdc startup.sh /home/sdc/ RUN chmod 770 /home/sdc/startup.sh diff --git a/openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/startup.sh b/openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/startup.sh index 92bf869ccc..3856e10f89 100644 --- a/openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/startup.sh +++ b/openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/startup.sh @@ -1,38 +1,50 @@ #!/bin/sh - -cd /home/sdc +SDC_HOME="/home/sdc" +cd $SDC_HOME || { echo "$(date) Failed to access directory $SDC_HOME"; exit 1; } CS_PORT="" CS_HOST=127.0.0.1 -if [ ! -z "${CS_HOST_IP}" ]; then +if [ -n "${CS_HOST_IP}" ]; then CS_HOST=$CS_HOST_IP fi -if [ ! -z "${CS_HOST_PORT}" ]; then +if [ -n "${CS_HOST_PORT}" ]; then CS_PORT=$CS_HOST_PORT fi -echo "[Info] Going to initialize sdc onboard cassandra: user=$SDC_USER; host=$CS_HOST; port=$CS_PORT" +echo "$(date) [Info] Going to initialize sdc onboard cassandra: user=$SDC_USER; host=$CS_HOST; port=$CS_PORT" -echo "[Info] Initializing onboard keyspaces" -date; -cqlsh -u $SDC_USER -p $SDC_PASSWORD -f init_keyspaces.cql $CS_HOST $CS_PORT +echo "$(date) [Info] Initializing onboard keyspaces" +cqlsh -u "$SDC_USER" -p "$SDC_PASSWORD" -f init_keyspaces.cql "$CS_HOST" "$CS_PORT" rc=$? -date; if [ $rc != 0 ]; then - echo "[Error] Failed to initialize onboard keyspaces"; + echo "$(date) [Error] Failed to initialize onboard keyspaces"; exit $rc; fi +echo "$(date) [Info] Finished initializing onboard keyspaces" -echo "[Info] Initializing onboard schemas" -date; -cqlsh -u $SDC_USER -p $SDC_PASSWORD -f init_schemas.cql $CS_HOST $CS_PORT +echo "$(date) [Info] Initializing onboard schemas" +cqlsh -u "$SDC_USER" -p "$SDC_PASSWORD" -f init_schemas.cql "$CS_HOST" "$CS_PORT" rc=$? -date; if [ $rc != 0 ]; then - echo "[Error] Failed to initialize onboard schemas"; + echo "$(date) [Error] Failed to initialize onboard schemas"; exit $rc; fi +echo "$(date) [Info] Finished initializing onboard schemas" + +echo "$(date) [Info] Upgrading onboard schemas" +for entry in "$SDC_HOME/upgrade-scripts"/* +do + echo "$(date) Running upgrade file '$entry'" + cqlsh -u "$SDC_USER" -p "$SDC_PASSWORD" -f "$entry" "$CS_HOST" "$CS_PORT" + rc=$? + if [ $rc != 0 ]; then + echo "$(date) [Warn] Upgrade failed for file '$entry'. It is possible that the upgrade was previously applied."; + fi + echo "$(date) Successfully ran upgrade file '$entry'" +done + +echo "$(date) [Info] Onboarding init was successful" \ No newline at end of file diff --git a/openecomp-be/dist/sdc-onboard-db-init-docker/pom.xml b/openecomp-be/dist/sdc-onboard-db-init-docker/pom.xml index e4ea7a7859..7ceb47082e 100644 --- a/openecomp-be/dist/sdc-onboard-db-init-docker/pom.xml +++ b/openecomp-be/dist/sdc-onboard-db-init-docker/pom.xml @@ -3,7 +3,6 @@ 4.0.0 openecomp-sdc-docker-db-init - org.openecomp.sdc openecomp-sdc-docker-db-init pom @@ -26,6 +25,34 @@ + + org.apache.maven.plugins + maven-clean-plugin + + + clean-docker-artifacts + clean + + clean + + + + + + artifacts + + false + + init_keyspaces.cql + init_schemas.cql + upgrade-scripts/** + + + + + + + maven-resources-plugin 3.0.2 @@ -46,7 +73,7 @@ init_keyspaces.cql init_schemas.cql - alter_tables.cql + upgrade-scripts/** diff --git a/openecomp-be/pom.xml b/openecomp-be/pom.xml index c942349891..ace220474e 100644 --- a/openecomp-be/pom.xml +++ b/openecomp-be/pom.xml @@ -87,6 +87,7 @@ /tools/swagger-ui /tools/zusammen-tools /backend + /dist diff --git a/openecomp-be/tools/install/database/alter_tables.cql b/openecomp-be/tools/install/database/alter_tables.cql deleted file mode 100644 index 9363a036f9..0000000000 --- a/openecomp-be/tools/install/database/alter_tables.cql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE dox.package_details ADD RESOURCE_TYPE text; diff --git a/openecomp-be/tools/install/database/upgrade-scripts/20191103-dox.package_details.cql b/openecomp-be/tools/install/database/upgrade-scripts/20191103-dox.package_details.cql new file mode 100644 index 0000000000..1326dc7f80 --- /dev/null +++ b/openecomp-be/tools/install/database/upgrade-scripts/20191103-dox.package_details.cql @@ -0,0 +1 @@ +ALTER TABLE dox.package_details ADD RESOURCE_TYPE text; \ No newline at end of file -- cgit 1.2.3-korg