apiVersion: apps/v1
# ===============LICENSE_START=======================================================
# Acumos Apache-2.0
# ===================================================================================
# Copyright (C) 2017-2018 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
# ===================================================================================
# This Acumos software file is distributed by AT&T and Tech Mahindra
# under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============LICENSE_END=========================================================

# What this is: kubernetes template for Acumos portal-be deployment
# How to use:

kind: Deployment
metadata:
  namespace: <ACUMOS_NAMESPACE>
  name: portal-be
  labels:
    app: portal-be
spec:
  replicas: 1
  selector:
    matchLabels:
      app: portal-be
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: portal-be
        <ACUMOS_SERVICE_LABEL_KEY>: <ACUMOS_PORTAL_SERVICE_LABEL>
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: <ACUMOS_SERVICE_LABEL_KEY>
                operator: NotIn
                values:
                - <ACUMOS_PORTAL_SERVICE_LABEL>
            topologyKey: "kubernetes.io/node"
      imagePullSecrets:
      - name: acumos-registry
      containers:
      - name: portal-be
        image: <PORTAL_BE_IMAGE>
        command: ["/bin/sh", "-c"]
        args:
        - set -x;
          cd maven;
          java $JAVA_OPTS -Dhttp.proxyHost=$ACUMOS_HTTP_PROXY_HOST -Dhttp.proxyPort=$ACUMOS_HTTP_PROXY_PORT -Dhttp.nonProxyHosts=$ACUMOS_HTTP_NON_PROXY_HOSTS -Dhttps.proxyHost=$ACUMOS_HTTP_PROXY_HOST -Dhttps.proxyPort=$ACUMOS_HTTP_PROXY_PORT -Dhttps.nonProxyHosts=$ACUMOS_HTTP_NON_PROXY_HOSTS -Djava.security.egd=file:/dev/./urandom -jar *.jar
        env:
        - name: ACUMOS_HTTP_NON_PROXY_HOSTS
          value: "<ACUMOS_HTTP_NON_PROXY_HOSTS>|docker-dind-service|cds-service|deployment-client-service|onboarding-service|msg-service|sv-scanning-service|lpe-service|lum-service"
        - name: ACUMOS_HTTP_PROXY_HOST
          value: "<ACUMOS_HTTP_PROXY_HOST>"
        - name: ACUMOS_HTTP_PROXY_PORT
          value: "<ACUMOS_HTTP_PROXY_PORT>"
        - name: JAVA_OPTS
          value: "-Xms512m -Xmx1024m"
        - name: SPRING_APPLICATION_JSON
          value: '{
            "logging": {
              "level": {
                "root": "INFO"
              }
            },
            "server": {
              "port": 8083,
              "contextPath": "/"
            },
            "proxy": {
              "host": "<ACUMOS_HTTP_PROXY>",
              "port": "<ACUMOS_HTTP_PROXY_PORT>",
              "protocol": "<ACUMOS_HTTP_PROXY_PROTOCOL>"
            },
            "docker": {
              "host": "<ACUMOS_DOCKER_API_HOST>",
              "port": "<ACUMOS_DOCKER_API_PORT>",
              "registry": {
                "url": "http://<ACUMOS_DOCKER_REGISTRY_HOST>:<ACUMOS_DOCKER_MODEL_PORT>/",
                "username": "<ACUMOS_DOCKER_REGISTRY_USER>",
                "password": "<ACUMOS_DOCKER_REGISTRY_PASSWORD>",
                "email": "<ACUMOS_ADMIN_EMAIL>"
              },
              "imagetag": {
                "prefix": "<ACUMOS_DOCKER_REGISTRY_HOST>:<ACUMOS_DOCKER_MODEL_PORT><ACUMOS_DOCKER_IMAGETAG_PREFIX>"
              }
            },
            "nexus": {
              "url": "http://<ACUMOS_NEXUS_HOST>:<ACUMOS_NEXUS_API_PORT>/<ACUMOS_NEXUS_MAVEN_REPO_PATH>/<ACUMOS_NEXUS_MAVEN_REPO>/",
              "proxy": "",
              "password": "<ACUMOS_NEXUS_RW_USER_PASSWORD>",
              "username": "<ACUMOS_NEXUS_RW_USER>",
              "groupId": "<ACUMOS_NEXUS_GROUP>"
            },
            "cdms": {
              "client": {
                "url": "http://<ACUMOS_CDS_HOST>:<ACUMOS_CDS_PORT>/ccds",
                "username": "<ACUMOS_CDS_USER>",
                "password": "<ACUMOS_CDS_PASSWORD>"
              }
            },
            "qanda": {
              "url": "https://stackoverflow.com/questions/tagged/acumos"
            },
            "concurrency" : {
              "async" : {
                "core-pool-size" : 10,
                "max-pool-size" : 50,
                "queue-capacity" : 10000
              }
            },
            "elk" : {
              "url" : "http://<ACUMOS_ELK_DOMAIN>:30960/elkclient"
            },
            "k8_deploy" : {
              "url" : "http://deployment-client-service:8337"
            },
            "lum": {
              "url": "http://lum-service:8080"
            },
            "license_profile": {
              "url": "https://<ACUMOS_DOMAIN>/license-profile-editor/index.html"
            },
            "microservice": {
              "url": "http://msg-service:8336/microservice-generation/v2/generateMicroservice"
            },
            "doc": {
              "url": "https://wiki.acumos.org"
            },
            "onboarding": {
              "push": {
                "model": {
                  "url": "http://onboarding-service:8090/onboarding-app/v2/models",
                  "dcae_url": "http://onboarding-service:8090/onboarding-app/v2/dcae_models"
                },
                "advancedmodel": {
                  "url": "http://onboarding-service:8090/onboarding-app/v2/advancedModel"
                }
              },
              "cliPushUrl": "https://<ACUMOS_ORIGIN><ACUMOS_ONBOARDING_CLIPUSHAPI>",
              "cliAuthUrl": "https://<ACUMOS_ORIGIN><ACUMOS_ONBOARDING_CLIAUTHAPI>",
              "tokenmode": "<ACUMOS_ONBOARDING_TOKENMODE>"
            },
            "model": {
              "storage": {
                "folder": {
                  "name": "/acumosWebOnboarding"
                }
              }
            },
            "portal": {
              "feature": {
                "publishSelfRequestEnabled": "<ACUMOS_PORTAL_PUBLISH_SELF_REQUEST_ENABLED>",
                "enablePublication": "<ACUMOS_PORTAL_ENABLE_PUBLICATION>",
                "validateModel": "false",
                "email_service": "<ACUMOS_EMAIL_SERVICE>",
                "cas_enabled": "<ACUMOS_CAS_ENABLE>",
                "download_bufferSize": 8,
                "signup_enabled": "true",
                "verifyAccount": "<ACUMOS_VERIFY_ACCOUNT>",
                "verifyToken": {
                  "exp_time": <ACUMOS_TOKEN_EXP_TIME>
                },
                "loginExpire" : {
                  "duration" : "8Y"
                },
                "sv": {
                  "enabled": "<ACUMOS_ENABLE_SECURITY_VERIFICATION>",
                  "api": "http://sv-scanning-service:9082"
                },
                "menu": "[
                  {\"name\": \" ML Learning Path\",
                   \"url\": \"\",
                   \"imagePath\": \"/images/sidebar-icons/ML_learning_path_selected.png\" }]",
                "cloud_enabled": "[
                  { \"cloudEnabled\": \"true\", \"cloudName\": \"azure\",
                    \"cloudDisplayText\": \"Microsoft Azure\",
                    \"imageUrl\": \"/images/deploy-cloud/microsoft_azure.png\" },
                  { \"cloudEnabled\": \"false\", \"cloudName\": \"gcp\",
                    \"cloudDisplayText\": \"Google Cloud Platform\",
                    \"imageUrl\": \"/images/deploy-cloud/google_cloud_platform.png\" },
                  { \"cloudEnabled\": \"true\",  \"cloudName\": \"deploylocal\",
                    \"cloudDisplayText\": \"Deploy To Local\",
                    \"imageUrl\": \"/images/deploy-cloud/deploy_to_local.png\" },
                  { \"cloudEnabled\": \"false\", \"cloudName\": \"whitebox\",
                    \"cloudDisplayText\": \"Deploy To White Box\",
                    \"imageUrl\": \"/images/deploy-cloud/deploy_to_whitebox.png\" }]",
                "ds": {
                  "menu": "{
                    \"workbenchActive\": true,
                    \"acucomposeActive\": true,
                    \"blocks\": []}"
                }
              },
              "ui": {
                "server": {
                  "address": "https://<ACUMOS_ORIGIN>"
                }
              },
              "submitValidation": {
                "api": "http://validation-client-service:9603/status/v1.0/tasks"
              },
              "dashboard": {
                "url": "http://<ACUMOS_ELK_DOMAIN>:<ACUMOS_ELK_KIBANA_PORT>"
              },
              "mailjet": {
                "api": {
                  "key": "<ACUMOS_MAILJET_API_KEY>"
                },
                "secret": {
                  "key": "<ACUMOS_MAILJET_SECRET_KEY>"
                },
                "address": {
                  "from": "<ACUMOS_MAILJET_ADMIN_EMAIL>"
                }
              }
            },
            "spring": {
              "mail": {
                "host": "<ACUMOS_SPRING_MAIL_SERVICE_DOMAIN>",
                "port": <ACUMOS_SPRING_MAIL_SERVICE_PORT>,
                "username": "<ACUMOS_SPRING_MAIL_USERNAME>",
                "password": "<ACUMOS_SPRING_MAIL_PASSWORD>",
                "debug": "true",
                "smtp": {
                  "starttls": {
                    "enable": "<ACUMOS_SPRING_MAIL_STARTTLS>"
                  },
                  "auth": "<ACUMOS_SPRING_MAIL_AUTH>"
                },
                "transport": {
                  "protocol": "<ACUMOS_SPRING_MAIL_PROTOCOL>"
                },
                "template": {
                  "folder": {
                    "path": "/fmtemplates/"
                  }
                }
              },
              "servlet": {
                "multipart": {
                  "max-file-size": "1024MB",
                  "max-request-size": "1024MB"
                }
              }
            },
            "client": {
              "ssl": {
                "key-store": "/app/certs/<ACUMOS_KEYSTORE_P12>",
                "key-store-password": "<ACUMOS_KEYSTORE_PASSWORD>",
                "key-store-type": "PKCS12",
                "key-password": "<ACUMOS_CERT_KEY_PASSWORD>",
                "trust-store": "/app/certs/<ACUMOS_TRUSTSTORE>",
                "trust-store-password": "<ACUMOS_TRUSTSTORE_PASSWORD>"
              }
            },
            "gateway": {
              "url": "https://<ACUMOS_FEDERATION_DOMAIN>:<ACUMOS_FEDERATION_LOCAL_PORT>"
            },
            "dcae": {
              "model": {
                "name": {
                  "prefix": "ONAP"
                }
              }
            },
            "jwt": {
              "auth": {
                "secret": {
                  "key": "<ACUMOS_JWT_KEY>"
                },
                "timeout": "80000000"
              }
            },
            "cas": {
              "service": {
                "validate": {
                  "url": "https://identity.linuxfoundation.org/cas/serviceValidate"
                }
              }
            },
            "logging": {
              "level":  {
                "org":   {
                  "acumos": {
                    "securityverification": "INFO",
                    "portal": "INFO"
                  }
                }
              }
            },
            "document": {
              "size": "<ACUMOS_PORTAL_DOCUMENT_MAX_SIZE>"
            },
            "jupyter": {
              "url": "https://<ACUMOS_ORIGIN>/hub/"
            },
            "kubernetes": {
               "doc": {
                  "url": "https://docs.acumos.org/"
               }
            },
            "image": {
              "size": "<ACUMOS_PORTAL_IMAGE_MAX_SIZE>"
            }
          }'
        ports:
        - containerPort: 8083
        volumeMounts:
        - mountPath: /maven/logs
          name: logs
        - mountPath: /app/certs
          name: certs-volume
      restartPolicy: Always
      volumes:
      - name: logs
        persistentVolumeClaim:
          claimName: <ACUMOS_PORTAL_SERVICE_LABEL>
      - name: certs-volume
        configMap:
          name: acumos-certs
