# ===============LICENSE_START=======================================================
# Acumos Apache-2.0
# ===================================================================================
# Copyright (C) 2019 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=========================================================

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: <ACUMOS_NAMESPACE>
  name: mlwb-pipeline
  labels:
    app: mlwb-pipeline
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mlwb-pipeline
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mlwb-pipeline
        <ACUMOS_SERVICE_LABEL_KEY>: <MLWB_PIPELINE_SERVICE_LABEL>
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: <ACUMOS_SERVICE_LABEL_KEY>
                operator: NotIn
                values:
                - <MLWB_PIPELINE_SERVICE_LABEL>
            topologyKey: "kubernetes.io/node"
      imagePullSecrets:
      - name: acumos-registry
      containers:
      - name: mlwb-pipeline
        image: <MLWB_PIPELINE_SERVICE_IMAGE>
        env:
        - name: ACUMOS_NAMESPACE
          value: <ACUMOS_NAMESPACE>
        - name: CERT_KEY_PASSWORD
          value: <MLWB_NIFI_KEY_PASSWORD>
        - name: TRUSTSTORE_PASSWORD
          value: <MLWB_NIFI_TRUSTSTORE_PASSWORD>
        - name: KEYSTORE_PASSWORD
          value: <MLWB_NIFI_KEYSTORE_PASSWORD>
        - name: SPRING_APPLICATION_JSON
          value: '{
            "server": {
              "port": 9090
            },
            "dateformat": "yyyy-MM-dd-HH-mm-ss-SSS",
            "resultsetSize": 2000,
            "cmndatasvc": {
              "url": "http://<ACUMOS_CDS_HOST>:<ACUMOS_CDS_PORT>/ccds",
              "user": "<ACUMOS_CDS_USER>",
              "pwd": "<ACUMOS_CDS_PASSWORD>"
            },
            "projectservice": {
              "url": "http://mlwb-project-service:9088/mlWorkbench/v1/project"
            },
            "jwt" : {
              "secretkey": "<ACUMOS_JWT_KEY>"
            },
            "useexternalpipeline": <MLWB_NIFI_EXTERNAL_PIPELINE_SERVICE>,
            "maxtries": 5,
            "sleeptimems": 30000,
            "nifi": {
              "waittime": "120000",
              "createpod": <MLWB_NIFI_CREATE_USER_POD>,
              "adminusername" : "<MLWB_NIFI_REGISTRY_INITIAL_ADMIN>",
              "serviceurl": "http://nifi-service-{0}:8080",
              "registryurl": "http://nifi-registry-service:8080",
              "directregistryurl": "https://<MLWB_NIFI_REGISTRY_INITIAL_ADMIN>:8443",
              "registryname": "Acumos-NiFi-Registry",
              "namespace": "<ACUMOS_NAMESPACE>",
              "template": {
                "path": "/maven/templates/",
                "apacheconfigmap": "apache_configmap.yaml",
                "nificonfigmap": "nifi_configmap.yaml",
                "service": "service.yaml",
                "serviceadmin": "service_admin.yaml",
                "ingress": "ingress.yaml",
                "deployment": "deployment.yaml"
              }
            }
          }'
        command: ["/bin/sh", "-c"]
        args:
        - if [[ ! -d /maven/templates ]]; then
            mkdir /maven/templates;
          fi;
          cp /maven/temp/* /maven/templates/.;
          chmod 777 /maven/templates/*;
          cd /maven;
          java -Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom -jar pipeline-service-*jar;
        ports:
        - containerPort: 9090
        volumeMounts:
        - mountPath: /maven/logs
          name: logs
        - mountPath: /maven/conf
          name: nifi-certs-registry
        - mountPath: /maven/temp
          name: nifi-templates
      restartPolicy: Always
      volumes:
      - name: logs
        persistentVolumeClaim:
          claimName: <MLWB_PIPELINE_SERVICE_LABEL>
      - name: nifi-certs-registry
        secret:
          secretName: nifi-certs-registry
      - name: nifi-templates
        configMap:
          name: nifi-templates
