You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2019/05/13 16:48:49 UTC

[sling-whiteboard] branch master updated: Improved logging, attempt to determine if the bundles are installed correctly, fixing issue if the releases folder contained a file

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 3887419  Improved logging, attempt to determine if the bundles are installed correctly, fixing issue if the releases folder contained a file
3887419 is described below

commit 3887419706e32f7f57d3c9af79fa632c1f6089c6
Author: Dan Klco <dk...@apache.org>
AuthorDate: Mon May 13 12:48:38 2019 -0400

    Improved logging, attempt to determine if the bundles are installed correctly, fixing issue if the releases folder contained a file
---
 release-validator/init.sh |   2 +-
 release-validator/run.sh  | 106 ++++++++++++++++++++++++++++++++++++----------
 2 files changed, 85 insertions(+), 23 deletions(-)

diff --git a/release-validator/init.sh b/release-validator/init.sh
index 239e9d9..b3c88a8 100644
--- a/release-validator/init.sh
+++ b/release-validator/init.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 echo "Installing dependencies..."
-yum install -y wget openssl git
+yum install -y wget openssl git jq
 
 echo "Installing Apache Maven..."
 mkdir mvn
diff --git a/release-validator/run.sh b/release-validator/run.sh
index a18b5ce..4e13907 100644
--- a/release-validator/run.sh
+++ b/release-validator/run.sh
@@ -1,25 +1,42 @@
 #!/bin/bash
 
+prints() {
+  if [ "$2" == "info" ]; then
+    COLOR="96m";
+  elif [ "$2" == "success" ]; then
+    COLOR="92m";
+  elif [ "$2" == "error" ]; then
+    COLOR="91m";
+  else 
+    COLOR="0m";
+  fi
+  STARTCOLOR="\e[$COLOR";
+  ENDCOLOR="\e[0m";
+  printf "\n\n$STARTCOLOR%b$ENDCOLOR" "$1\n";
+}
+
 mkdir tmp
 
-echo "Loading PGP Keys..."
+prints "Starting Validation for Apache Sling Release #$RELEASE_ID" "info"
+
+prints "Loading PGP Keys..." "info"
 curl https://people.apache.org/keys/group/sling.asc --output sling.asc || exit 1
 gpg --import sling.asc || exit 1
 
-echo "Validating release..."
-CHECK_RESULT=$(/bin/bash check_staged_release.sh ${RELEASE_ID} tmp)
+prints "Validating release signatures..." "info"
+CHECK_RESULT=$(/bin/bash check_staged_release.sh $RELEASE_ID tmp)
 printf "\n$CHECK_RESULT\n"
 if [[ "$CHECK_RESULT" == *"BAD"* ]]; then
+  prints "Loading PGP Keys..." "error"
   echo "Check(s) Failed!"
   exit 1
 elif [[ "$CHECK_RESULT" = *"no files found"* ]]; then
-  echo "Staging repository ${RELEASE_ID} not found!"
+  prints "Staging repository ${RELEASE_ID} not found!" "error"
   exit 1
 else
-  echo "Check successful!"
+  prints "Release signatures check successful!" "success"
 fi
 
-echo "Updating .m2/settings.xml..."
 mkdir ~/.m2
 cat > ~/.m2/settings.xml <<EOF
 <settings>
@@ -28,7 +45,7 @@ cat > ~/.m2/settings.xml <<EOF
      <id>staging</id>
      <repositories>
        <repository>
-         <id>my-repo2</id>
+         <id>staging-repo</id>
          <name>your custom repo</name>
          <url>https://repository.apache.org/content/repositories/orgapachesling-$RELEASE_ID</url>
        </repository>
@@ -44,7 +61,10 @@ EOF
 HAS_BUNDLE=false
 for RELEASE_FOLDER in tmp/${RELEASE_ID}/org/apache/sling/*
 do
-  echo "Running build for $RELEASE_FOLDER"
+  if [[ -f $RELEASE_FOLDER ]]; then
+    continue
+  fi
+  prints "Running build for $RELEASE_FOLDER" "info"
   
   echo "Resolving Maven Variables..."
   MVN_PACKAGING=$(mvn/bin/mvn -q -Dexec.executable=echo  -Dexec.args='${project.packaging}' --non-recursive  exec:exec -f $RELEASE_FOLDER/**/*.pom)
@@ -56,13 +76,14 @@ do
   else
     REPO="sling-${MVN_ARTIFACT_ID//\./-}"
   fi
+  printf "Resolved Variables:\n\tArtifact ID: $MVN_ARTIFACT_ID\n\tPackaging: $MVN_PACKAGING\n\tRepo Slug: $REPO\n\tVersion: $MVN_VERSION\n"
 
-  echo "Checking out code from https://github.com/apache/$REPO.git..."
+  prints "Checking out code from https://github.com/apache/$REPO.git..." "info"
   git clone https://github.com/apache/$REPO.git || exit 1
   cd $REPO
   git checkout $MVN_ARTIFACT_ID-$MVN_VERSION || exit 1
 
-  echo "Building project..."
+  prints "Building $MVN_ARTIFACT_ID..." "info"
   ../mvn/bin/mvn clean install || exit 1
   
   if [ "$MVN_PACKAGING" == "bundle" ]
@@ -73,10 +94,11 @@ do
   cd ..  
 done
 
+prints "Build(s) Successful!" "success"
 
 if [ "$HAS_BUNDLE" = true ];
 then
-  echo "Installing bundle..."
+  prints "Bundles found, starting Apache Sling Starter..." "info"
   
   mkdir run
   
@@ -96,47 +118,87 @@ then
   
   echo "Waiting for Sling to fully start..."
 
-  while true; do
+  STARTED=false
+  ATTEMPT=0
+  while [ $ATTEMPT -lt 5 ]; do
     sleep 30
     RESP=$(curl -s http://localhost:8080/starter/index.html)
     if [[ "$RESP" == *"Do not remove this comment, used for Starter integration tests"* ]]; then
-      echo "Sling Starter started!"
+      prints "Sling Starter started!" "success"
+      let STARTED=true
       break
     else
       echo "Not yet started..."
     fi
+    let ATTEMPT=ATTEMPT+1 
   done
   
-  echo "Installing bundles..."
+  if [[ $STARTED = false ]]; then
+    prints "Sling failed to start!" "error"
+    exit 1
+  fi
+  
+  BUNDLE_SUCCESS=true
+  prints "Installing bundles..." "info"
   for RELEASE_FOLDER in tmp/${RELEASE_ID}/org/apache/sling/*
   do
   
     MVN_PACKAGING=$(mvn/bin/mvn -q -Dexec.executable=echo  -Dexec.args='${project.packaging}' --non-recursive  exec:exec -f $RELEASE_FOLDER/**/*.pom)
-    if [[ "$MVN_PACKAGING" = "bundle" ]] ; then
-      echo "Installing bundle ${RELEASE_FOLDER}..."
+    if [[ "$MVN_PACKAGING" = "bundle" ]]; then
     
       MVN_VERSION=$(mvn/bin/mvn -q -Dexec.executable=echo  -Dexec.args='${project.version}' --non-recursive  exec:exec -f $RELEASE_FOLDER/**/*.pom)
       MVN_ARTIFACT_ID=$(mvn/bin/mvn -q -Dexec.executable=echo  -Dexec.args='${project.artifactId}' --non-recursive  exec:exec -f $RELEASE_FOLDER/**/*.pom)
       REPO="sling-${MVN_ARTIFACT_ID//\./-}"
-  
-      curl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@"$REPO/target/$MVN_ARTIFACT_ID-$MVN_VERSION.jar" http://127.0.0.1:8080/system/console/bundles || exit 1
+      
+      echo "Installing / starting bundle $REPO/target/$MVN_ARTIFACT_ID-$MVN_VERSION.jar..."
+      curl -u admin:admin -F action=install -F bundlestart=true -F refreshPackages=true -F bundlestartlevel=20 -F bundlefile=@"$REPO/target/$MVN_ARTIFACT_ID-$MVN_VERSION.jar" http://127.0.0.1:8080/system/console/bundles || exit 1
+      
+      STATE=""
+      ATTEMPT=0
+      while [ $ATTEMPT -lt 12 ]; do
+        sleep 10
+        BUNDLE_RESPONSE=$(curl -s -u admin:admin http://127.0.0.1:8080/system/console/bundles/$MVN_ARTIFACT_ID.json)
+        let STATE=$(echo $BUNDLE_RESPONSE | jq -r '.data[0].state')
+        IMPORTS_IN_ERROR=$(echo $BUNDLE_RESPONSE | jq -r '.data[0].props[] | select(.key == "Imported Packages").value[] | select( contains("ERROR") )')
+        if [[ "$STATE" == "Active" ]]; then
+          prints "Bundle $MVN_ARTIFACT_ID started successfully!" "success"
+          break
+        else
+          echo "Bundle is currently in state $STATE, waiting to see if it starts..."
+        fi
+        let ATTEMPT=ATTEMPT+1
+      done
+      
+      if [[ "$STATE" != "Active" ]]; then
+        prints "Failed to start $MVN_ARTIFACT_ID, current state: $STATE"
+        printf "Imports in error state:\n$IMPORTS_IN_ERROR\n\n"
+        BUNDLE_SUCCESS=false
+      fi
     else
       echo "Ignoring non-bundle ${RELEASE_FOLDER}..."
     fi
   done
   
-  echo "Release ${RELEASE_ID} verified successfully!"
+  if [[ $BUNDLE_SUCCESS == true ]]; then
+    prints "Release ${RELEASE_ID} verified successfully!" "success"
+  else 
+    prints "Some bundles failed to start" "error"
+  fi
   
   if [[ "$KEEP_RUNNING" == "true" ]]; then
     TIMEOUT="${RUN_TIMEOUT:=10m}"
   	echo "Leaving Sling Starter running for $TIMEOUT for testing..."
+    
+    CONTAINER_ID=$(cat /etc/hostname)
   	
-  	printf "Run the following command to see the URL to connect to the Sling Starter under the PORT parameter:\n"
-  	printf "\tdocker ps\n"
+  	echo "Run the following command to see the URL to connect to the Sling Starter:"
+  	printf "\tdocker port $CONTAINER_ID\n"
+  	echo "If you are satisfied, the container can be stopped with:"
+  	printf "\tdocker stop $CONTAINER_ID\n"
 
     sleep $TIMEOUT
   fi
 else
   echo "Packaging is $MVN_PACKAGING, not bundle"
-  echo "Release ${RELEASE_ID} verified successfully!"
+  prints "Release $RELEASE_ID verified successfully!" "success"
 fi
\ No newline at end of file