Refine Container Startup 76/83776/3
authorInstrumental <jonathan.gathman@att.com>
Fri, 29 Mar 2019 20:42:37 +0000 (15:42 -0500)
committerInstrumental <jonathan.gathman@att.com>
Fri, 29 Mar 2019 21:53:00 +0000 (16:53 -0500)
Issue-ID: AAF-773
Change-Id: Ia198a11eceb9bfacafde26cde97d15949a3fe78c
Signed-off-by: Instrumental <jonathan.gathman@att.com>
20 files changed:
auth/auth-cass/cass_init/cmd.sh
auth/auth-cass/docker/Dockerfile.cass
auth/auth-cass/docker/dbuild.sh
auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java
auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java
auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java
auth/docker/Dockerfile.base
auth/docker/Dockerfile.client
auth/docker/Dockerfile.config
auth/docker/agent.sh
auth/docker/d.props.init
auth/docker/dbuild.sh
auth/helm/aaf/aaf.sh [new file with mode: 0644]
auth/helm/aaf/templates/aaf-fs.yaml
auth/helm/aaf/templates/aaf-locate.yaml
auth/helm/aaf/values.yaml
auth/sample/bin/pod_wait.sh
auth/sample/etc/org.osaaf.aaf.locate.props
docs/sections/configuration/AAF_4.1_config.rst
docs/sections/configuration/onboard.rst

index b26536d..b665012 100644 (file)
@@ -149,7 +149,7 @@ case "$1" in
 
     # Startup like normal
     echo "Cassandra Startup"
-    exec /usr/local/bin/docker-entrypoint.sh 
+    exec -c "/usr/local/bin/docker-entrypoint.sh"
   ;;
   wait)
     # Wait for initialization.  This can be called from Docker only as a check to make sure it is ready
index 52aa49c..0406411 100644 (file)
@@ -18,7 +18,7 @@
 #  ============LICENSE_END====================================================
 #
 # Use dbuild.sh input parameter to set registry
-FROM ${REGISTRY}cassandra:3.11
+FROM ${REGISTRY}/cassandra:3.11
 MAINTAINER AAF Team, AT&T 2018
 ENV VERSION=${AAF_VERSION}
 
index 2913b1a..17d359c 100644 (file)
@@ -29,10 +29,10 @@ DOCKER=${DOCKER:-docker}
 echo "$0: Building aaf_cass Container for aaf_cass:$VERSION"
 
 # default nexus repo only contains Amd64 images, use docker.io for multi-platform builds
-if [[ $1 && $1 == "docker.io" ]]; then
-    DOCKER_PULL_REGISTRY=''
-else 
-    DOCKER_PULL_REGISTRY='nexus3.onap.org:10001\/'
+if [ $# -gt 0 ]; then
+    if [ "$1" == "-r" ]; then
+      DOCKER_PULL_REGISTRY=$2
+    fi
 fi
 echo "$0: DOCKER_PULL_REGISTRY=${DOCKER_REGISTRY}"
 
index e2317a5..02d9351 100644 (file)
@@ -187,5 +187,4 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
         }
         return def;
     }
-
 }
index fe610e5..ee92540 100644 (file)
  *
  */
 package org.onap.aaf.auth.server;
+import java.io.File;
 import java.io.IOException;
+import java.net.Inet4Address;
+import java.net.UnknownHostException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -29,6 +32,7 @@ import org.onap.aaf.auth.org.OrganizationFactory;
 import org.onap.aaf.auth.rserv.RServlet;
 import org.onap.aaf.cadi.Access;
 import org.onap.aaf.cadi.Access.Level;
+import org.onap.aaf.cadi.config.Config;
 import org.onap.aaf.cadi.register.Registrant;
 import org.onap.aaf.cadi.register.Registrar;
 import org.onap.aaf.misc.env.Trans;
@@ -38,6 +42,7 @@ public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Tr
     private Registrar<ENV> registrar;
     private boolean do_register;
     protected AbsService<ENV,TRANS> service;
+       protected String hostname;
 
 
     public AbsServiceStarter(final AbsService<ENV,TRANS> service) {
@@ -52,6 +57,14 @@ public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Tr
         // for Debugging purposes without fear that real clients will start to call your debug instance
         do_register = !"TRUE".equalsIgnoreCase(access().getProperty("aaf_locate_no_register",null));
         _propertyAdjustment();
+        hostname = access().getProperty(Config.HOSTNAME, null);
+        if (hostname==null) {
+            try {
+                               hostname = Inet4Address.getLocalHost().getHostName();
+                       } catch (UnknownHostException e) {
+                               hostname= "cannotBeDetermined";
+                       }
+        }
     }
     
     public abstract void _start(RServlet<TRANS> rserv) throws Exception;
@@ -70,6 +83,8 @@ public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Tr
        ExecutorService es = Executors.newSingleThreadExecutor();
        Future<?> app = es.submit(this);
         final AbsServiceStarter<?,?> absSS = this;
+        // Docker/K8 may separately create startup Status in this dir for startup 
+        // sequencing.  If so, delete ON EXIT 
        Runtime.getRuntime().addShutdownHook(new Thread() {
              @Override
           public void run() {
@@ -120,7 +135,28 @@ public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Tr
             registrar=null;
         } 
         if (service!=null) {
-            service.destroy();
+            File status = new File("/opt/app/aaf/status/");
+            boolean deleted = false;
+               if(status.exists()) {
+                       int lastdot = service.app_name.lastIndexOf("aaf.");
+                       String fname;
+                       if(lastdot<0) {
+                               fname = service.app_name + '-' + hostname;
+                       } else {
+                               fname = service.app_name.substring(lastdot).replace('.', '-') 
+                                               + '-' + hostname;
+                       }
+                       status = new File(status, fname);
+                       if(status.exists()) {
+                               status.delete();
+                       }
+               }
+               if(deleted) {
+                       service.access.log(Level.INIT, "Deleted Status",status.getAbsolutePath());
+               } else {
+                       service.access.log(Level.INIT, "Status not deleted: ",status.getAbsolutePath());
+               }
+               service.destroy();
         }
     }
 }
index 1256c60..182956c 100644 (file)
@@ -21,7 +21,6 @@
 package org.onap.aaf.auth.server;
 
 import java.io.IOException;
-import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.util.Properties;
 
@@ -93,10 +92,6 @@ public class JettyServiceStarter<ENV extends RosettaEnv, TRANS extends Trans> ex
 
     @Override
     public void _start(RServlet<TRANS> rserv) throws Exception {
-        String hostname = access().getProperty(Config.HOSTNAME, null);
-        if (hostname==null) {
-            hostname = Inet4Address.getLocalHost().getHostName();
-        }
         final int port = Integer.parseInt(access().getProperty("port","0"));
         final String keystore = access().getProperty(Config.CADI_KEYSTORE, null);
         final int IDLE_TIMEOUT = Integer.parseInt(access().getProperty(Config.AAF_CONN_IDLE_TIMEOUT, Config.AAF_CONN_IDLE_TIMEOUT_DEF));
index ad8e271..35ade62 100644 (file)
@@ -18,7 +18,7 @@
 #  ============LICENSE_END====================================================
 #
 # Use dbuild.sh input parameter to set registry
-FROM ${REGISTRY}openjdk:8-jre-alpine
+FROM ${REGISTRY}/openjdk:8-jre-alpine
 MAINTAINER AAF Team, AT&T 2018
 
 LABEL description="aaf_base"
index 111c377..b62f7b4 100644 (file)
@@ -18,7 +18,6 @@
 #  ============LICENSE_END====================================================
 #
 FROM ${DOCKER_REPOSITORY}/onap/aaf/aaf_base:${AAF_VERSION}
-#FROM nexus3.onap.org:10001/onap/aaf/aaf-base-xenial:latest
 MAINTAINER AAF Team, AT&T 2018
 ENV VERSION=${AAF_VERSION}
 
index 7e442b2..27b2fff 100644 (file)
@@ -18,7 +18,6 @@
 #  ============LICENSE_END====================================================
 #
 FROM ${DOCKER_REPOSITORY}/onap/aaf/aaf_base:${AAF_VERSION}
-#FROM nexus3.onap.org:10001/onap/aaf/aaf-base-xenial:latest
 MAINTAINER AAF Team, AT&T 2018
 ENV VERSION=${AAF_VERSION}
 
index ce878f5..931249b 100644 (file)
@@ -159,10 +159,10 @@ case "$1" in
   aafcli) 
     shift
     reset_sso
-    if [ -f aaf-auth-cmd-$VERSION*-full.jar ]; then
-      java -Dcadi_prop_files="$HOME/.aaf/sso.props" -jar aaf-auth-cmd-$VERSION*-full.jar $@
+    if [ -f aaf-cadi-aaf-$VERSION-full.jar ]; then
+      java -Dcadi_prop_files="$HOME/.aaf/sso.props" -jar aaf-cadi-aaf-$VERSION-full.jar $@
     else 
-      echo "For local use, you need to have 'aaf-auth-cmd-$VERSION*-full.jar' (or newer)"
+      echo "For local use, you need to have 'aaf-cadi-aaf-$VERSION-full.jar' (or newer)"
     fi
     ;;
   local) 
@@ -185,10 +185,10 @@ case "$1" in
     reset_sso
     sso aaf_id "$DEPLOY_FQI"
     sso aaf_password "$DEPLOY_PASSWORD"
-    if [ -f aaf-auth-cmd-$VERSION*-full.jar ]; then
-      java -Dcadi_prop_files="$HOME/.aaf/sso.props" -cp aaf-auth-cmd-$VERSION*-full.jar org.onap.aaf.cadi.configure.Agent $CMD 
+    if [ -f aaf-cadi-aaf-$VERSION-full.jar ]; then
+      java -Dcadi_prop_files="$HOME/.aaf/sso.props" -cp aaf-cadi-aaf-$VERSION-full.jar org.onap.aaf.cadi.configure.Agent $CMD 
     else 
-      echo "For local use, you need to have 'aaf-cadi-aaf-$VERSION*-full.jar' (or newer)"
+      echo "For local use, you need to have 'aaf-cadi-aaf-$VERSION-full.jar' (or newer)"
     fi
     ;;
   *)
index 54a3926..b9eb016 100644 (file)
@@ -20,6 +20,8 @@
 # Variables for building Docker entities
 ORG=onap
 PROJECT=aaf
+# Note: Override can happen on dbuild.sh Commandline, -r <registry>
+DOCKER_PULL_REGISTRY=nexus3.onap.org:10001
 DOCKER_REPOSITORY=nexus3.onap.org:10003
 VERSION=2.1.11-SNAPSHOT
 CONF_ROOT_DIR=/opt/app/osaaf
index cdd97fc..b2a5d51 100755 (executable)
 # Docker Building Script.  Reads all the components generated by install, on per-version basis
 #
 
-DOCKER_PULL_REGISTRY='nexus3.onap.org:10001\/'
+# Pull in Variables from d.props
+if [ ! -e ./d.props ]; then
+    cp d.props.init d.props
+fi
+
+. ./d.props
+
 AAF_COMPONENTS=ALL
 
 # process input. originally, an optional positional parameter is used to designate a component.
@@ -45,13 +51,6 @@ fi
 
 echo "$0: AAF_COMPONENTS=$AAF_COMPONENTS DOCKER_PULL_REGISTRY=$DOCKER_PULL_REGISTRY"
 
-# Pull in Variables from d.props
-if [ ! -e ./d.props ]; then
-    cp d.props.init d.props
-fi
-
-. ./d.props
-
 DOCKER=${DOCKER:=docker}
 
 echo "Building Containers for aaf components, version $VERSION"
diff --git a/auth/helm/aaf/aaf.sh b/auth/helm/aaf/aaf.sh
new file mode 100644 (file)
index 0000000..5bb8351
--- /dev/null
@@ -0,0 +1,84 @@
+. ../../docker/d.props
+IMAGE=onap/aaf/aaf_agent:$VERSION
+
+kubectl -n onap run -it --rm aaf-agent-$USER --image=$IMAGE --overrides='
+{
+    "spec": {
+        "containers": [
+            {
+                "name": "aaf-agent-'$USER'",
+               "image": "'$IMAGE'",
+                "imagePullPolicy": "IfNotPresent",
+               "command": [
+                   "bash", 
+                  "-c",
+                   "/opt/app/aaf_config/bin/agent.sh && cd /opt/app/osaaf/local && exec bash"
+                 ],
+                "env": [
+                   {
+                     "name": "aaf_locator_container",
+                     "value": "helm"
+                  },{
+                     "name": "aaf_locator_fqdn",
+                     "value": "'$HOSTNAME'"
+                  },{
+                     "name": "aaf_locator_url",
+                     "value": "https://aaf-locate:8095"
+                  },{
+                     "name": "aaf_locator_public_hostname",
+                     "value": "'$HOSTNAME'"
+                  },{
+                     "name": "AAF_ENV",
+                     "value": "'$AAF_ENV'"
+                  },{
+                     "name": "LATITUDE",
+                     "value": "'$LATITUDE'"
+                  },{
+                     "name": "LONGITUDE",
+                     "value": "'$LONGITUDE'"
+                  },{
+                     "name": "CASSANDRA_CLUSTER",
+                     "value": "'$CASSANDRA_CLUSTER'"
+                  },{
+                     "name": "CASSANDRA_USER",
+                     "value": "'$CASSANDRA_USER'"
+                  },{
+                     "name": "CASSANDRA_PASSWORD",
+                     "value": "'$CASSANDRA_PASSWORD'"
+                  },{
+                     "name": "CASSANDRA_PORT",
+                     "value": "'$CASSANDRA_PORT'"
+                  }
+                ],
+                "stdin": true,
+                "stdinOnce": true,
+                "tty": true,
+                "volumeMounts": [
+                    {
+                        "mountPath": "/opt/app/osaaf",
+                        "name": "aaf-config-vol"
+                    },
+                    {
+                        "mountPath": "/opt/app/aaf/status",
+                        "name": "aaf-status-vol"
+                    }
+                ]
+            }
+        ],
+      "volumes": [
+            {
+                "name": "aaf-config-vol",
+                "persistentVolumeClaim": {
+                    "claimName": "aaf-config-pvc"
+                }
+            },
+            {
+                "name": "aaf-status-vol",
+                "persistentVolumeClaim": {
+                    "claimName": "aaf-status-pvc"
+                }
+            }
+        ]
+   }
+}
+' --restart=Never  -- bash 
index 999b8d1..d53e920 100644 (file)
@@ -41,7 +41,7 @@ metadata:
   labels:
     app: aaf-fs
 spec:
-  replicas: 0
+  replicas: {{ .Values.replicas.fs }}
   selector:
     matchLabels:
       app: aaf-fs
index 1e05dcb..b09c80b 100644 (file)
@@ -41,7 +41,7 @@ metadata:
   labels:
     app: aaf-locate
 spec:
-  replicas: 0
+  replicas: {{ .Values.replicas.locate }}
   selector:
     matchLabels:
       app: aaf-locate
index 417e9fb..7556f25 100644 (file)
@@ -30,11 +30,11 @@ global:
 
 replicas:
   cass: 1
-  service: 0
-  locator: 0
-  oauth: 0
-  cm: 0
-  gui: 0
+  service: 1
+  locator: 1
+  oauth: 1
+  cm: 1
+  gui: 1
   hello: 0
 
 ingress:
@@ -56,7 +56,7 @@ persistence:
     mountSubPath: "config"
     storageClass: "manual"
   status:
-    volumeReclaimPolicy: Retain
+    volumeReclaimPolicy: Delete
     accessMode: ReadWriteOnce
     size: 10M
     mountSubPath: "status"
index 07ff981..3d6a1b9 100644 (file)
@@ -29,17 +29,17 @@ shift
 
 function status {
   if [ -d "$DIR" ]; then
-     echo "$@" > $DIR/$APP
+     echo "$@" > $DIR/$APP-$HOSTNAME
   fi
 }
 
 
 function check {
   if [ -d "$DIR" ]; then
-    if [ -e "$DIR/$OTHER" ]; then
-      echo "$(cat $DIR/$OTHER)"
-    else 
+    if [ -z "$(ls $DIR/$OTHER* 2> /dev/null)" ]; then
       echo "$DIR/$OTHER does not exist"
+    else 
+      echo "$(cat $DIR/$OTHER*)"
     fi
   else 
     echo "$DIR does not exist"
@@ -51,13 +51,13 @@ function wait {
   while [ $n -lt 40  ]; do 
      rv="$(check)"
      echo "$rv"
-     if [ "$rv" = "ready" ]; then
-       echo "$OTHER is $rv"
-       n=10000
-     else 
+     if [ -z "$(echo $rv | grep "ready")" ]; then
        (( ++n )) 
        echo "Sleep 10 (iteration $n)"
        sleep 10
+     else 
+       echo "$OTHER is $rv"
+       n=10000
      fi
   done
 }
@@ -67,15 +67,15 @@ function start {
   while [ $n -lt 40  ]; do 
      rv="$(check)"
      echo "$OTHER is $rv"
-     if [ "$rv" = "ready" ]; then
+     if [ -z "$(echo $rv | grep "ready")" ]; then
+       (( ++n )) 
+       echo "Sleep 10 (iteration $n)"
+       sleep 10
+     else 
        # This is critical.  Until status is literally "ready" in the status directory, no processes will start
        status ready
        echo "Starting $@"
        n=10000
-     else 
-       (( ++n )) 
-       echo "Sleep 10 (iteration $n)"
-       sleep 10
      fi
   done
 }
@@ -89,6 +89,10 @@ case "$OTHER" in
     status "ready"
     echo "Done"
     ;;
+  stop) 
+    echo "Removing $DIR/$APP-$HOSTNAME"
+    rm $DIR/$APP-$HOSTNAME
+    ;;
   wait)
     OTHER="$1"
     shift    
@@ -102,4 +106,4 @@ case "$OTHER" in
   ;;
 esac  
 
-eval  "$@"
+eval "$@"
index 0979833..a132abd 100644 (file)
@@ -22,7 +22,7 @@
 ## AAF Locator Properties
 ##
 cadi_prop_files=/opt/app/osaaf/local/org.osaaf.aaf.props:/opt/app/osaaf/etc/org.osaaf.aaf.log4j.props:/opt/app/osaaf/etc/org.osaaf.aaf.orgs.props:/opt/app/osaaf/local/org.osaaf.aaf.cassandra.props
-aaf_locator_entries=locator
+aaf_locator_entries=locate
 port=8095
 aaf_locator_public_port.helm=30081
 #aaf_locator_public_port.oom=
index ff9816a..453ee23 100644 (file)
@@ -48,11 +48,11 @@ Prerequisites
 
         * (You can also get the ONAP TEST Root CA there)
 
-    * the latest aaf-auth-cmd-<VERSION>-full.jar from `ONAP Nexus`_.
+    * the latest aaf-cadi-aaf-<VERSION>-full.jar from `ONAP Nexus`_.
     * you can still use the same "agent.sh" script below
 
 .. _AAF FileServer: http://aaf-onap-test.osaaf.org/-
-.. _ONAP Nexus: https://nexus.onap.org/#nexus-search;quick~aaf-auth-cmd
+.. _ONAP Nexus: https://nexus.onap.org/#nexus-search;gav~~aaf-cadi-aaf~~~
 
 -----------------------
 Obtain the Agent Script
index 6f80e6e..4a1fa73 100644 (file)
@@ -8,6 +8,7 @@ In running AAF
 cd /opt/app/osaaf/data
 vi identities.dat
 insert like the following
+
   ngi|ONAP NGI Application|NGI|ONAP Application|||a|aaf_admin
 
 Save (:wq)