#!/bin/bash

#
# Constants:
#

WORKSPACE="${WORKSPACE:-}"
SUCCESS=0
FAILURE=1

CS_PASSWORD="onap123#@!"
SDC_USER="asdc_user"
SDC_PASSWORD="Aa1234%^!"

JETTY_BASE="/var/lib/jetty"

RELEASE=latest
LOCAL=false
RUNTESTS=false
BE_DEBUG_PORT="--publish 4000:4000"
FE_DEBUG_PORT="--publish 6000:6000"
ONBOARD_DEBUG_PORT="--publish 4001:4000"


# Java Options:
BE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=4000,server=y,suspend=n -Xmx1536m -Xms1536m"
FE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=6000,server=y,suspend=n -Xmx256m -Xms256m"
ONBOARD_BE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=4001,server=y,suspend=n -Xmx1g -Xms1g"
DCAE_BE_JAVA_OPTIONS="-XX:MaxPermSize=256m -Xmx1024m -Dconfig.home=config -Dlog.home=/var/lib/jetty/logs/ -Dlogging.config=config/dcae-be/logback-spring.xml"
DCAE_FE_JAVA_OPTIONS="-XX:MaxPermSize=256m -Xmx1024m -Dconfig.home=config -Dlog.home=/var/lib/jetty/logs/ -Dlogging.config=config/dcae-fe/logback-spring.xml"
SIM_JAVA_OPTIONS=" -Xmx128m -Xms128m -Xss1m"
API_TESTS_JAVA_OPTIONS="-Xmx512m -Xms512m"
UI_TESTS_JAVA_OPTIONS="-Xmx1024m -Xms1024m"
#Define this as variable, so it can be excluded in run commands on Docker for OSX, as /etc/localtime cant be mounted there.
LOCAL_TIME_MOUNT_CMD="--volume /etc/localtime:/etc/localtime:ro"
# If os is OSX, unset this, so /etc/localtime is not mounted, otherwise leave it be
if [[ "$OSTYPE" == "darwin"* ]]; then
  LOCAL_TIME_MOUNT_CMD=""
fi


#
# Functions:
#


function usage {
    echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -t|--runTests <Run-with-sanityDocker>] [ -sim|--simulator <Run-with-simulator>] [ -ta <run api tests with the supplied test suit>] [ -tu <run ui tests with the supplied test suit>] [ -ta <run api tests with the supplied test suit>] [ -tu <run ui tests with the supplied test suit>] [ -tad <run api tests with the default test suit>] [ -tu <run ui tests with the default test suit>] [ -dcae|--dcae <Run-with-DCAE>][ -h|--help ]"
    echo "start dockers built locally example: docker_run.sh -l"
    echo "start dockers built locally and simulator example: docker_run.sh -l -sim"
    echo "start dockers, pull from onap nexus according to release and simulator example: docker_run.sh -r 1.3-STAGING-latest -sim"
    echo "start dockers built locally and run api tests docker example: docker_run.sh -l -tad"
    echo "start dockers built locally and run only the catalog be example: docker_run.sh -l -d sdc-BE "
}
#


function cleanup {
    echo "Performing old dockers cleanup"

	if [ "$1" == "all" ] ; then
		docker_ids=`docker ps -a | egrep -v "onap/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit}|dcae" | awk '{print $1}'`
		for X in ${docker_ids}
		do
			docker rm -f ${X}
		done
	else
	    echo "performing $1 docker cleanup"
	    tmp=`docker ps -a -q --filter="name=$1"`
	    if [[ ! -z "$tmp" ]]; then
    		docker rm -f ${tmp}
        fi
	fi
}
#


function dir_perms {
    mkdir -p ${WORKSPACE}/data/logs/BE/SDC/SDC-BE
    mkdir -p ${WORKSPACE}/data/logs/FE/SDC/SDC-FE

    mkdir -p ${WORKSPACE}/data/logs/DCAE-BE/DCAE
    mkdir -p ${WORKSPACE}/data/logs/DCAE-FE/DCAE

    mkdir -p ${WORKSPACE}/data/logs/sdc-api-tests/ExtentReport
    mkdir -p ${WORKSPACE}/data/logs/ONBOARD/SDC/ONBOARD-BE
	mkdir -p ${WORKSPACE}/data/logs/sdc-api-tests/target
	mkdir -p ${WORKSPACE}/data/logs/sdc-ui-tests/ExtentReport
	mkdir -p ${WORKSPACE}/data/logs/sdc-ui-tests/target
	mkdir -p ${WORKSPACE}/data/logs/docker_logs
	mkdir -p ${WORKSPACE}/data/logs/WS
    chmod -R 777 ${WORKSPACE}/data/logs
}
#


function docker_logs {
    docker logs $1 > ${WORKSPACE}/data/logs/docker_logs/$1_docker.log
}
#


#
# Readiness Prob
#

function ready_probe {
    docker exec $1 /var/lib/ready-probe.sh > /dev/null 2>&1
    rc=$?
    if [[ ${rc} == 0 ]]; then
        echo DOCKER $1 start finished in $2 seconds
        return ${SUCCESS}
    fi
    return ${FAILURE}
}
#


function probe_docker {
    MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
    echo MATCH is -- ${MATCH}

    if [ -n "$MATCH" ] ; then
        echo DOCKER start finished in $2 seconds
        return ${SUCCESS}
    fi
    return ${FAILURE}
}
#


function probe_es {
    health_Check_http_code=$(curl --noproxy "*" -o /dev/null -w '%{http_code}' http://${IP}:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
    if [[ "$health_Check_http_code" -eq 200 ]] ; then
        echo DOCKER start finished in $1 seconds
        return ${SUCCESS}
    fi
    return ${FAILURE}
}
#


function probe_sim {
    if lsof -Pi :8285 -sTCP:LISTEN -t >/dev/null ; then
        echo "Already running"
        return ${SUCCESS}
    else
        echo "Not running"
        return ${FAILURE}
    fi
}
#


function probe_dcae_be {
    health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}' http://${IP}:8082/dcae/conf/composition)
    if [[ "${health_check_http_code}" -eq 200 ]] ; then
        echo DOCKER start finished in $1 seconds
        return ${SUCCESS}
    fi
    return ${FAILURE}
}
#

function probe_dcae_fe {
    health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}' http://${IP}:8183/dcaed/healthCheck)
    if [[ "${health_check_http_code}" -eq 200 ]] ; then
        echo DOCKER start finished in $1 seconds
        return ${SUCCESS}
    fi
    return ${FAILURE}
}
#


# Not applicable for current release. Return Success in any case
function probe_dcae_tools {
   health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}'  http://${IP}:8082/dcae/getResourcesByMonitoringTemplateCategory)
    if [[ "${health_check_http_code}" -eq 200 ]] ; then
        echo DOCKER start finished in $1 seconds
        return ${SUCCESS}
    fi
    return ${SUCCESS}
}
#

# check simulator status
function probe_sim {
    if lsof -Pi :8285 -sTCP:LISTEN -t >/dev/null ; then
        echo "running"
        sim_stat=true
    else
        echo "not running"
        sim_stat=false
    fi
}
#


function monitor_docker {
    DOCKER_NAME=$1
    echo "Monitor ${DOCKER_NAME} Docker"
    sleep 5
    TIME_OUT=900
    INTERVAL=20
    TIME=0

    while [ "$TIME" -lt "$TIME_OUT" ]; do

        case ${DOCKER_NAME} in

            sdc-cs)
                ready_probe ${DOCKER_NAME} ${TIME} ;
                status=$? ;
            ;;
            sdc-es)
                probe_es ${TIME} ;
                status=$? ;
            ;;
            sdc-BE)
       		    ready_probe ${DOCKER_NAME} ${TIME} ;
                status=$? ;
            ;;
            sdc-FE)
                ready_probe ${DOCKER_NAME} ${TIME} ;
                status=$? ;
            ;;
            sdc-onboard-BE)
                ready_probe ${DOCKER_NAME} ${TIME} ;
                status=$? ;
            ;;
            dcae-be)
                probe_dcae_be ${TIME} ;
                status=$? ;
            ;;
            dcae-fe)
                probe_dcae_fe ${TIME} ;
                status=$? ;
            ;;
            dcae-tools)
                probe_dcae_tools ;
                status=$? ;
            ;;
            *<style>.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */</style><div class="highlight"><pre><span></span><span class="c">&lt;!--</span>
<span class="c">  ============LICENSE_START=======================================================</span>
<span class="c">   Copyright (C) 2018 Ericsson. All rights reserved.</span>
<span class="c">  ================================================================================</span>
<span class="c">  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c">  you may not use this file except in compliance with the License.</span>
<span class="c">  You may obtain a copy of the License at</span>

<span class="c">       http://www.apache.org/licenses/LICENSE-2.0</span>

<span class="c">  Unless required by applicable law or agreed to in writing, software</span>
<span class="c">  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c">  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c">  See the License for the specific language governing permissions and</span>
<span class="c">  limitations under the License.</span>

<span class="c">  SPDX-License-Identifier: Apache-2.0</span>
<span class="c">  ============LICENSE_END=========================================================</span>
<span class="c">--&gt;</span>
<span class="nt">&lt;project</span> <span class="na">xmlns=</span><span class="s">&quot;http://maven.apache.org/POM/4.0.0&quot;</span> <span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span class="na">xsi:schemaLocation=</span><span class="s">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span><span class="nt">&gt;</span>
    <span class="nt">&lt;modelVersion&gt;</span>4.0.0<span class="nt">&lt;/modelVersion&gt;</span>
    <span class="nt">&lt;parent&gt;</span>
        <span class="nt">&lt;groupId&gt;</span>org.onap.policy.apex-pdp.examples<span class="nt">&lt;/groupId&gt;</span>
        <span class="nt">&lt;artifactId&gt;</span>examples<span class="nt">&lt;/artifactId&gt;</span>
        <span class="nt">&lt;version&gt;</span>2.4.1-SNAPSHOT<span class="nt">&lt;/version&gt;</span>
    <span class="nt">&lt;/parent&gt;</span>

    <span class="nt">&lt;artifactId&gt;</span>examples-periodic<span class="nt">&lt;/artifactId&gt;</span>
    <span class="nt">&lt;name&gt;</span><span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">artifactId</span><span class="cp">}</span><span class="nt">&lt;/name&gt;</span>
    <span class="nt">&lt;description&gt;</span>APEX periodic event example<span class="nt">&lt;/description&gt;</span>

    <span class="nt">&lt;properties&gt;</span>
        <span class="nt">&lt;policymodel.name&gt;</span>PeriodicPolicyModel<span class="nt">&lt;/policymodel.name&gt;</span>
        <span class="nt">&lt;apex</span><span class="err">-domains-periodic-dir</span><span class="nt">&gt;</span><span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">basedir</span><span class="cp">}</span>/src<span class="nt">&lt;/apex-domains-periodic-dir&gt;</span>
    <span class="nt">&lt;/properties&gt;</span>

    <span class="nt">&lt;dependencies&gt;</span>
        <span class="nt">&lt;dependency&gt;</span>
            <span class="nt">&lt;groupId&gt;</span>org.onap.policy.apex-pdp.auth<span class="nt">&lt;/groupId&gt;</span>
            <span class="nt">&lt;artifactId&gt;</span>cli-editor<span class="nt">&lt;/artifactId&gt;</span>
            <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
        <span class="nt">&lt;/dependency&gt;</span>
    <span class="nt">&lt;/dependencies&gt;</span>

    <span class="nt">&lt;build&gt;</span>
        <span class="nt">&lt;plugins&gt;</span>
            <span class="c">&lt;!-- Generate the APEX Policy JSON from the APEX CLI command --&gt;</span>
            <span class="nt">&lt;plugin&gt;</span>
                <span class="nt">&lt;groupId&gt;</span>org.codehaus.mojo<span class="nt">&lt;/groupId&gt;</span>
                <span class="nt">&lt;artifactId&gt;</span>exec-maven-plugin<span class="nt">&lt;/artifactId&gt;</span>
                <span class="nt">&lt;executions&gt;</span>
                    <span class="nt">&lt;execution&gt;</span>
                        <span class="nt">&lt;id&gt;</span>generate-policy<span class="nt">&lt;/id&gt;</span>
                        <span class="nt">&lt;phase&gt;</span>compile<span class="nt">&lt;/phase&gt;</span>
                        <span class="nt">&lt;goals&gt;</span>
                            <span class="nt">&lt;goal&gt;</span>java<span class="nt">&lt;/goal&gt;</span>
                        <span class="nt">&lt;/goals&gt;</span>
                        <span class="nt">&lt;configuration&gt;</span>
                            <span class="nt">&lt;mainClass&gt;</span>org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain<span class="nt">&lt;/mainClass&gt;</span>
                            <span class="nt">&lt;classpathScope&gt;</span>compile<span class="nt">&lt;/classpathScope&gt;</span>
                            <span class="nt">&lt;arguments&gt;</span>
                                <span class="nt">&lt;argument&gt;</span>--command-file=<span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">basedir</span><span class="cp">}</span>/src/main/resources/policy/<span class="cp">${</span><span class="n">policymodel</span><span class="o">.</span><span class="n">name</span><span class="cp">}</span>.apex<span class="nt">&lt;/argument&gt;</span>
                                <span class="nt">&lt;argument&gt;</span>--output-model-file=<span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">build</span><span class="o">.</span><span class="n">directory</span><span class="cp">}</span>/classes/<span class="cp">${</span><span class="n">policymodel</span><span class="o">.</span><span class="n">name</span><span class="cp">}</span>.json<span class="nt">&lt;/argument&gt;</span>
                                <span class="nt">&lt;argument&gt;</span>--log-file=<span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">build</span><span class="o">.</span><span class="n">directory</span><span class="cp">}</span>/<span class="cp">${</span><span class="n">policymodel</span><span class="o">.</span><span class="n">name</span><span class="cp">}</span>_policygeneration.log<span class="nt">&lt;/argument&gt;</span>
                                <span class="nt">&lt;argument&gt;</span>--working-dir=<span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">basedir</span><span class="cp">}</span><span class="nt">&lt;/argument&gt;</span>
                            <span class="nt">&lt;/arguments&gt;</span>
                        <span class="nt">&lt;/configuration&gt;</span>
                    <span class="nt">&lt;/execution&gt;</span>
                <span class="nt">&lt;/executions&gt;</span>
            <span class="nt">&lt;/plugin&gt;</span>
        <span class="nt">&lt;/plugins&gt;</span>
    <span class="nt">&lt;/build&gt;</span>

    <span class="nt">&lt;profiles&gt;</span>
        <span class="nt">&lt;profile&gt;</span>
            <span class="nt">&lt;id&gt;</span>apexSite<span class="nt">&lt;/id&gt;</span>
            <span class="nt">&lt;activation&gt;</span>
                <span class="nt">&lt;property&gt;</span>
                    <span class="nt">&lt;name&gt;</span>apexSite<span class="nt">&lt;/name&gt;</span>
                <span class="nt">&lt;/property&gt;</span>
            <span class="nt">&lt;/activation&gt;</span>
            <span class="nt">&lt;properties&gt;</span>
                <span class="nt">&lt;adsite</span><span class="err">-examples-periodic-dir</span><span class="nt">&gt;</span><span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">basedir</span><span class="cp">}</span>/src<span class="nt">&lt;/adsite-examples-periodic-dir&gt;</span>
            <span class="nt">&lt;/properties&gt;</span>
            <span class="nt">&lt;distributionManagement&gt;</span>
                <span class="nt">&lt;site&gt;</span>
                    <span class="nt">&lt;id&gt;</span><span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">artifactId</span><span class="cp">}</span>-site<span class="nt">&lt;/id&gt;</span>
                    <span class="nt">&lt;url&gt;</span><span class="cp">${</span><span class="n">apex</span><span class="o">.</span><span class="n">adsite</span><span class="o">.</span><span class="n">prefix</span><span class="cp">}</span>/modules/<span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">artifactId</span><span class="cp">}</span>/<span class="cp">${</span><span class="n">project</span><span class="o">.</span><span class="n">artifactId</span><span class="cp">}</span>/<span class="nt">&lt;/url&gt;</span>
                <span class="nt">&lt;/site&gt;</span>
            <span class="nt">&lt;/distributionManagement&gt;</span>
        <span class="nt">&lt;/profile&gt;</span>
    <span class="nt">&lt;/profiles&gt;</span>
<span class="nt">&lt;/project&gt;</span>
</pre></div>
</code></pre></td></tr></table>
</div> <!-- class=content -->
<div id="lfcollabprojects-footer">
  <div class="gray-diagonal">
    <div class="footer-inner">
      <p>
        &copy; 2017 <a href="https://www.onap.org/">ONAP</a> a Linux Foundation
        Collaborative Project. All Rights Reserved.
      </p>
      <p>
        Linux Foundation is a registered trademark of The Linux Foundation.
        Linux is a registered
        <a
          href="http://www.linuxfoundation.org/programs/legal/trademark"
          title="Linux Mark Institute"
          >trademark</a
        >
        of Linus Torvalds.
      </p>
      <p>
        Please see our
        <a href="http://www.linuxfoundation.org/privacy">privacy policy</a> and
        <a href="http://www.linuxfoundation.org/terms">terms of use</a>
      </p>
    </div>
  </div>
</div>
</div> <!-- id=cgit -->
</body>
</html>
_stat=$?
        if [ sim_stat=1 ]; then
            docker run \
                --detach \
                --name sdc-sim \
                --env FE_URL="${FE_URL}" \
                --env JAVA_OPTIONS="${SIM_JAVA_OPTIONS}" \
                --env ENVNAME="${DEP_ENV}" \
                ${LOCAL_TIME_MOUNT_CMD} \
                --volume ${WORKSPACE}/data/logs/WS/:/var/lib/jetty/logs \
                --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments \
                --publish 8285:8080 \
                --publish 8286:8443 ${PREFIX}/sdc-simulator:${RELEASE}
            echo "please wait while SDC-WEB-SIMULATOR is starting....."
            monitor_docker sdc-sim
        fi
    fi
}
#


#
# Main
#

# Handle command line arguments
while [ $# -gt 0 ]; do
    case $1 in

	# -r | --release - The specific docker version to pull and deploy
    -r | --release )
          shift 1 ;
          RELEASE=$1;
          shift 1;;

	# -e | --environment - The environment name you want to deploy
    -e | --environment )
          shift 1;
          DEP_ENV=$1;
          shift 1 ;;

	# -p | --port - The port from which to connect to the docker nexus
    -p | --port )
          shift 1 ;
          PORT=$1;
          shift 1 ;;

	# -l | --local - Use this for deploying your local dockers without pulling them first
    -l | --local )
          LOCAL=true;
          shift 1;;

	# -ta - Use this for running the APIs sanity docker after all other dockers have been deployed
    -ta  )
          shift 1 ;
          API_SUITE=$1;
          RUN_API_TESTS=true;
          shift 1 ;;

	# -tu - Use this for running the UI sanity docker after all other dockers have been deployed
    -tu  )
          shift 1 ;
	      UI_SUITE=$1;
          RUN_UI_TESTS=true;
          shift 1 ;;

    # -tad - Use this for running the DEFAULT suite of tests in APIs sanity docker after all other dockers have been deployed
    -tad | -t )
          API_SUITE="onapApiSanity";
          RUN_API_TESTS=true;
          shift 1 ;;

	# -tud - Use this for running the DEFAULT suite of tests in UI sanity docker after all other dockers have been deployed
    -tud   )
          UI_SUITE="onapUiSanity";
          RUN_UI_TESTS=true;
          shift 1 ;;

    # -d | --docker - The init specified docker
    -d | --docker )
          shift 1 ;
          DOCKER=$1;
          shift 1 ;;
    # -sim | --simulator run the simulator
    -sim | --simulator )
         RUN_SIMULATOR=true;
         shift 1 ;;
    # -sim | --simulator run the simulator
    -u | --fe_url )
         shift 1 ;
         FE_URL=$1;
         shift 1 ;;
    # -dcae | --dcae - Use this to deploy DCAE upon SDC
    -dcae | --dcae )
         shift 1 ;
         DCAE_ENABLE='True';;

	# -h | --help - Display the help message with all the available run options
    -h | --help )
          usage;
          exit  ${SUCCESS};;

         * )
          usage;
          exit  ${FAILURE};;
    esac
done


#Prefix those with WORKSPACE so it can be set to something other then /opt
[ -f ${WORKSPACE}/opt/config/env_name.txt ] && DEP_ENV=$(cat ${WORKSPACE}/opt/config/env_name.txt) || echo ${DEP_ENV}
[ -f ${WORKSPACE}/opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat ${WORKSPACE}/opt/config/nexus_username.txt)    || NEXUS_USERNAME=release
[ -f ${WORKSPACE}/opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat ${WORKSPACE}/opt/config/nexus_password.txt)      || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
[ -f ${WORKSPACE}/opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat ${WORKSPACE}/opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=nexus3.onap.org:${PORT}
[ -f ${WORKSPACE}/opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO


export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
#If OSX, then use this to get IP
if [[ "$OSTYPE" == "darwin"* ]]; then
    export IP=$(ipconfig getifaddr en0)
fi
export PREFIX=${NEXUS_DOCKER_REPO}'/onap'

if [ ${LOCAL} = true ]; then
	PREFIX='onap'
fi

echo ""

if [ -z "${DOCKER}" ]; then
    cleanup all
	dir_perms
	sdc-es
	sdc-init-es
	sdc-cs
	sdc-cs-init
#	sdc-kbn
	sdc-cs-onboard-init
	sdc-onboard-BE
	sdc-BE
	sdc-BE-init
	sdc-FE
	dcae-be
	dcae-tools
	dcae-fe
	healthCheck
    sdc-sim
	sdc-api-tests
	sdc-ui-tests
else
	cleanup ${DOCKER}
	dir_perms
	${DOCKER}
    healthCheck
fi