Commit 2739c611 authored by Yann Garcia's avatar Yann Garcia
Browse files

Add script to switch between MEC Sandbox and AdvantEDGE plateforms

parent 89759a79
Loading
Loading
Loading
Loading
+16 −20
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ DESC="AdvantEDGE platform"
TIMEOUT=7
IS_RUNNING=`kubectl get pods --all-namespaces | grep "meep-virt-engine" | awk '{print $2}'`
start_advantedge() {
    if [ -z $IS_RUNNING ] ; then
    if [ -z "$IS_RUNNING" ] ; then
      meepctl deploy dep
      sleep $TIMEOUT
      meepctl deploy core
@@ -14,7 +14,7 @@ start_advantedge() {
}

stop_advantedge() {
    if [ -n $IS_RUNNING ]; then
    if [ -n "$IS_RUNNING" ]; then
      meepctl delete core
      sleep $TIMEOUT
      meepctl delete dep
@@ -30,10 +30,9 @@ case "$1" in
start)
  echo "Starting $DESC"
  start_advantedge

  ;;
stop)
  echo "Stoping $DESC"
  echo "Stopping $DESC"
  stop_advantedge

  ;;
@@ -42,13 +41,10 @@ restart)
  stop_advantedge
  sleep $TIMEOUT
  start_advantedge

  ;;

status)
  kubectl get pods --all-namespaces
  ;;
  
*)
  echo "Usage: $0 {start|stop|restart|status}" >&2
  exit 1

scripts/switch.sh

0 → 100755
+122 −0
Original line number Diff line number Diff line
#!/bin/sh -e

set -vx

DESC="AdvantEDGE platform"
PLTF="Unknown"
TIMEOUT=7
IS_RUNNING=`kubectl get pods --all-namespaces | grep "meep-virt-engine" | awk '{print $2}'`
ADV_PATH=~/AdvantEDGE

start_advantedge() {
    if [ -z "$IS_RUNNING" ] ; then
        meepctl deploy dep
        sleep $TIMEOUT
        meepctl deploy core
        sleep $TIMEOUT
        kubectl get pods --all-namespaces
    fi
}

stop_avdantedge() {
    if [ -n "$IS_RUNNING" ]; then
        meepctl delete core
        sleep $TIMEOUT
        meepctl delete dep
        sleep $TIMEOUT
        kubectl get pods --all-namespaces
        sleep $TIMEOUT
        #helm delete --no-hooks meep-prometheus
    fi
}

switch_to_advantedge_pltf() {
    check_pltf_mode
    if [ "$PLTF" = "AdvantEDGE" ]; then
        start_advantedge
        return
    fi
    stop_avdantedge

    rm -fr charts/grafana/dashboards/mec-sandbox.json config/api/ config/permissions.yaml
    cp .meepctl-repocfg_adv.yaml .meepctl-repocfg.yaml
    git checkout --force config/objstore-thanos-archive.yaml config/objstore-thanos.yaml config/secrets.yaml examples/demo4-ue/src/demo-server/entrypoint.sh
    start_advantedge
}

switch_to_sandbox_pltf() {
    check_backup
    if [ "$PLTF" = "Sandbox" ]; then
        start_advantedge
        return
    fi
    stop_avdantedge
    cd ../mec-sandbox
    ./build.sh
    ./deploy.sh
    cd -
    start_advantedge
}

check_pltf_mode() {
    if [ -f charts/grafana/dashboards/mec-sandbox.json ]; then
        # Sandbox mode
        PLTF="Sandbox"
    else
        FT=`grep "frontend: false" .meepctl-repocfg.yaml`
        if [ -n "$FT" ]; then
            # AdvantEDGE mode
            PLTF="AdvantEDGE"
        fi
        unset FT
    fi
}

check_backup() {
    check_pltf_mode
    if [ "$PLTF" = "AdvantEDGE" ]; then
        if [ -f .meepctl-repocfg_adv.yaml ]; then
            echo "$0: AdvantEDGE backup already done"
        else
            echo "$0: AdvantEDGE backup created"
            cp .meepctl-repocfg.yaml .meepctl-repocfg_adv.yaml
        fi
    else
        if [ "$PLTF" = "Sandbox" ]; then
            if [ -f .meepctl-repocfg_adv.yaml ]; then
                echo "$0: AdvantEDGE backup already done"
            else
                echo "$0: Wrong configuration. Please, set up AdvantEDGE plateform"
                exit -1
            fi
        else
            echo "$0: Unknown configuration. Please, set up AdvantEDGE plateform"
            exit -1
        fi
    fi
}

check_backup

case "$1" in
AdvantEDGE)
  echo "Switching to AdvantEDGE"
  switch_to_advantedge_pltf
  ;;
Sandbox)
  echo "Switching to Sandbox"
  switch_to_sandbox_pltf
  ;;
status)
  check_pltf_mode
  echo "Plateform: $PLTF"
  kubectl get pods -n default
  ;;
*)
  echo "Usage: $0 Switch between AdvantEDGE plateform and MEC Sandbox plateform" >&2
  echo "       $0 {AdvantEDGE|Sandbox|status}" >&2
  exit 1
  ;;
esac

exit 0