Implement simple onboarding cassandra upgrade 63/123263/4
authorandre.schmid <andre.schmid@est.tech>
Thu, 12 Aug 2021 22:05:15 +0000 (23:05 +0100)
committerMichael Morris <michael.morris@est.tech>
Fri, 13 Aug 2021 16:14:07 +0000 (16:14 +0000)
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 <andre.schmid@est.tech>
integration-tests/pom.xml
openecomp-be/.gitignore
openecomp-be/dist/pom.xml
openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/Dockerfile
openecomp-be/dist/sdc-onboard-db-init-docker/artifacts/startup.sh
openecomp-be/dist/sdc-onboard-db-init-docker/pom.xml
openecomp-be/pom.xml
openecomp-be/tools/install/database/alter_tables.cql [deleted file]
openecomp-be/tools/install/database/upgrade-scripts/20191103-dox.package_details.cql [new file with mode: 0644]

index 5a80dcd..1656e28 100644 (file)
@@ -544,7 +544,7 @@ limitations under the License.
                                 </volumes>
                                 <wait>
                                     <time>30000</time>
-                                    <log>Initializing onboard schemas</log>
+                                    <log>Onboarding init was successful</log>
                                 </wait>
                                 <network>
                                     <mode>custom</mode>
index 2c9567e..ab9a3f3 100644 (file)
@@ -11,3 +11,4 @@ package
 *.iml
 *.ipr
 *.iws
+/dist/sdc-onboard-db-init-docker/artifacts/upgrade-scripts/
index 706f013..83208a0 100644 (file)
@@ -3,7 +3,6 @@
     <modelVersion>4.0.0</modelVersion>
 
     <name>openecomp-sdc-docker-dist</name>
-    <groupId>org.openecomp.sdc</groupId>
     <artifactId>openecomp-sdc-docker-dist</artifactId>
     <packaging>pom</packaging>
 
index 8408d2f..05034e1 100644 (file)
@@ -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
 
index 92bf869..3856e10 100644 (file)
@@ -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
index e4ea7a7..7ceb470 100644 (file)
@@ -3,7 +3,6 @@
     <modelVersion>4.0.0</modelVersion>
 
     <name>openecomp-sdc-docker-db-init</name>
-    <groupId>org.openecomp.sdc</groupId>
     <artifactId>openecomp-sdc-docker-db-init</artifactId>
     <packaging>pom</packaging>
 
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-clean-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>clean-docker-artifacts</id>
+                        <phase>clean</phase>
+                        <goals>
+                            <goal>clean</goal>
+                        </goals>
+                        <configuration>
+                            <filesets>
+                                <fileset>
+                                    <directory>
+                                        artifacts
+                                    </directory>
+                                    <followSymlinks>false</followSymlinks>
+                                    <includes>
+                                        <include>init_keyspaces.cql</include>
+                                        <include>init_schemas.cql</include>
+                                        <include>upgrade-scripts/**</include>
+                                    </includes>
+                                </fileset>
+                            </filesets>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <artifactId>maven-resources-plugin</artifactId>
                 <version>3.0.2</version>
@@ -46,7 +73,7 @@
                                     <includes>
                                         <include>init_keyspaces.cql</include>
                                         <include>init_schemas.cql</include>
-                                        <include>alter_tables.cql</include>
+                                        <include>upgrade-scripts/**</include>
                                     </includes>
                                 </resource>
                             </resources>
index c942349..ace2204 100644 (file)
@@ -87,6 +87,7 @@
     <module>/tools/swagger-ui</module>
     <module>/tools/zusammen-tools</module>
     <module>/backend</module>
+    <module>/dist</module>
   </modules>
 
   <profiles>
diff --git a/openecomp-be/tools/install/database/alter_tables.cql b/openecomp-be/tools/install/database/alter_tables.cql
deleted file mode 100644 (file)
index 9363a03..0000000
+++ /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 (file)
index 0000000..1326dc7
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE dox.package_details ADD RESOURCE_TYPE text;
\ No newline at end of file