Some bug fixes 24/3524/1
authoragrawalgaurav <gaurav.agrawal@huawei.com>
Thu, 28 May 2020 19:45:22 +0000 (01:15 +0530)
committeragrawalgaurav <gaurav.agrawal@huawei.com>
Thu, 28 May 2020 19:45:22 +0000 (01:15 +0530)
Change-Id: I04b1b14cbc6d94ae705acf65536981151710e3ae

mecm/mepm/applcm/broker/pkg/handlers/adapter/dbAdapter/dbAdapter.go
mecm/mepm/applcm/resources/deployment/applcm-broker-deployment.yaml
mecm/mepm/applcm/resources/deployment/db-deployment.yaml [deleted file]
mecm/mepm/applcm/resources/deployment/db-service.yaml [deleted file]
mecm/mepm/applcm/resources/deployment/postgres-db-pvc.yaml [moved from mecm/mepm/applcm/resources/deployment/my-db-persistentvolumeclaim.yaml with 63% similarity]
mecm/mepm/applcm/resources/deployment/postgres-k8s.yaml [new file with mode: 0644]
mecm/mepm/applcm/resources/test/docker-compose.yaml

index 135fd6b..23fb49e 100644 (file)
@@ -17,14 +17,20 @@ package dbAdapter
 
 import (
        "broker/pkg/handlers/model"
-       "os"
-
+       "fmt"
        "github.com/jinzhu/gorm"
+       _ "github.com/jinzhu/gorm/dialects/postgres"
        "github.com/sirupsen/logrus"
+       "os"
 )
 
-// DB name
-const DbName = "applcmDB"
+var (
+       username = os.Getenv("POSTGRES_USER")
+       password = os.Getenv("POSTGRES_PASSWORD")
+       dbName = os.Getenv("POSTGRES_DATABASE")
+       dbHost = os.Getenv("DBHOST")
+
+)
 
 // Database adapter
 type DbAdapter struct {
@@ -40,19 +46,14 @@ func NewDbAdapter(logger *logrus.Logger) *DbAdapter {
 func (adapter *DbAdapter) CreateDatabase() {
        adapter.logger.Infof("creating Database...")
 
-       usrpswd := os.Getenv("MYSQL_USER") + ":" + os.Getenv("MYSQL_PASSWORD")
-       host := "@tcp(" + "dbhost" + ":3306)/"
+       dbUri := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s", dbHost, username, dbName, password) //Build connection string
 
-       db, err := gorm.Open("mysql", usrpswd+host)
+       conn, err := gorm.Open("postgres", dbUri)
        if err != nil {
-               adapter.logger.Fatalf("Database connect error", err.Error())
+               fmt.Print(err)
        }
 
-       db.Exec("CREATE DATABASE  " + DbName)
-       db.Exec("USE applcmDB")
-       gorm.DefaultCallback.Create().Remove("mysql:set_identity_insert")
-
-       adapter.logger.Infof("Migrating models...")
+       db := conn
        db.AutoMigrate(&model.AppPackageInfo{})
        db.AutoMigrate(&model.AppInstanceInfo{})
        adapter.db = db
index ce4d6b4..74bb34a 100644 (file)
@@ -50,13 +50,15 @@ spec:
           value: /go/release/logfile
         - name: LOGGER_LEVEL
           value: info
-        - name: MYSQL_DATABASE
-          value: db
-        - name: MYSQL_PASSWORD
+        - name: POSTGRES_DATABASE
+          value: mecmdb
+        - name: DBHOST
+          value: mecmdb
+        - name: POSTGRES_PASSWORD
           value: password
-        - name: MYSQL_ROOT_PASSWORD
+        - name: POSTGRES_ROOT_PASSWORD
           value: password
-        - name: MYSQL_USER
+        - name: POSTGRES_USER
           value: root
         - name: PACKAGE_ARTIFACT_PATH
           value: /Artifacts/Deployment/
diff --git a/mecm/mepm/applcm/resources/deployment/db-deployment.yaml b/mecm/mepm/applcm/resources/deployment/db-deployment.yaml
deleted file mode 100644 (file)
index 3d75520..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright 2020 Huawei Technologies Co., Ltd.
-#
-# Licensed 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
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License 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.
-
-# yamllint disable
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  annotations:
-    kompose.cmd: kompose convert
-    kompose.version: 1.21.0 (992df58d8)
-  creationTimestamp: null
-  labels:
-    io.kompose.service: db
-  name: db
-spec:
-  replicas: 1
-  selector:
-    matchLabels:
-      io.kompose.service: db
-  strategy:
-    type: Recreate
-  template:
-    metadata:
-      annotations:
-        kompose.cmd: kompose convert
-        kompose.version: 1.21.0 (992df58d8)
-      creationTimestamp: null
-      labels:
-        io.kompose.service: db
-    spec:
-      containers:
-      - env:
-        - name: MYSQL_DATABASE
-          value: db
-        - name: MYSQL_PASSWORD
-          value: password
-        - name: MYSQL_ROOT_PASSWORD
-          value: password
-        - name: MYSQL_USER
-          value: root
-        image: mysql/mysql-server
-        imagePullPolicy: ""
-        name: db
-        ports:
-        - containerPort: 3306
-        resources: {}
-        volumeMounts:
-        - mountPath: /var/lib/mysql
-          name: my-db
-      restartPolicy: Always
-      serviceAccountName: ""
-      volumes:
-      - name: my-db
-        hostPath:
-          path: /data
-          type: DirectoryOrCreate
-status: {}
-
-# yamllint enable
diff --git a/mecm/mepm/applcm/resources/deployment/db-service.yaml b/mecm/mepm/applcm/resources/deployment/db-service.yaml
deleted file mode 100644 (file)
index ee1adb2..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright 2020 Huawei Technologies Co., Ltd.
-#
-# Licensed 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
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License 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.
-
-# yamllint disable
-apiVersion: v1
-kind: Service
-metadata:
-  annotations:
-    kompose.cmd: kompose convert
-    kompose.version: 1.21.0 (992df58d8)
-  creationTimestamp: null
-  labels:
-    io.kompose.service: db
-  name: dbhost
-spec:
-  ports:
-  - name: "3306"
-    port: 3306
-    targetPort: 3306
-  selector:
-    io.kompose.service: db
-status:
-  loadBalancer: {}
-
-# yamllint enable
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# yamllint disable
+
+# persistent volume
+---
+kind: PersistentVolume
 apiVersion: v1
+metadata:
+  name: postgres-pv-volume
+  labels:
+    type: local
+    app: postgres
+spec:
+  storageClassName: manual
+  capacity:
+    storage: 5Gi
+  accessModes:
+    - ReadWriteMany
+  hostPath:
+    path: "/data"
+
+# pvc
+---
 kind: PersistentVolumeClaim
+apiVersion: v1
 metadata:
-  creationTimestamp: null
+  name: postgres-pv-claim
+  namespace: default
   labels:
-    io.kompose.service: my-db
-  name: my-db
+    app: postgres
 spec:
+  storageClassName: manual
   accessModes:
-  - ReadWriteOnce
+    - ReadWriteMany
   resources:
     requests:
-      storage: 100Mi
-status: {}
-
-# yamllint enable
+      storage: 5Gi
diff --git a/mecm/mepm/applcm/resources/deployment/postgres-k8s.yaml b/mecm/mepm/applcm/resources/deployment/postgres-k8s.yaml
new file mode 100644 (file)
index 0000000..82e2921
--- /dev/null
@@ -0,0 +1,69 @@
+# Copyright 2020 Huawei Technologies Co., Ltd.
+#
+# Licensed 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
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License 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.
+
+
+# postgres database
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: postgres-db
+  namespace: default
+  labels:
+    app: postgres-db
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: postgres-db
+  template:
+    metadata:
+      labels:
+        app: postgres-db
+    spec:
+      volumes:
+        - name: postgres-data
+          persistentVolumeClaim:
+            claimName: postgres-pv-claim
+      containers:
+        - name: postgres-db
+          image: postgres:9.6
+          imagePullPolicy: "IfNotPresent"
+          env:
+            - name: POSTGRES_DB
+              value: mecmdb
+            - name: POSTGRES_USER
+              value: root
+            - name: POSTGRES_PASSWORD
+              value: password
+          volumeMounts:
+            - mountPath: /var/lib/postgresql/data
+              name: postgres-data
+          ports:
+            - containerPort: 5432
+
+# postgres service
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: mecmdb
+  namespace: default
+spec:
+  selector:
+    app: postgres-db
+  ports:
+    - name: "5432"
+      port: 5432
+      targetPort: 5432
index 6e585ec..545f0e9 100644 (file)
@@ -9,21 +9,20 @@ volumes:
   my-db:
 
 services:
-  db:
+  mecmdb:
     network_mode: bridge
-    image: mysql:5.7
+    image: postgres:9.6
     environment:
-      MYSQL_DATABASE: 'db'
-      MYSQL_USER: 'root'
-      MYSQL_PASSWORD: 'password'
-      # Password for root access
-      MYSQL_ROOT_PASSWORD: 'password'
+      POSTGRES_DB: 'mecmdb'
+      POSTGRES_USER: 'root'
+      POSTGRES_PASSWORD: 'password'
+      POSTGRES_ROOT_PASSWORD: 'password'
     ports:
-      - '3306:3306'
+      - '5432:5432'
     expose:
-      - '3306'
+      - '5432'
     volumes:
-      - my-db:/var/lib/mysql
+      - my-db:/var/lib/postgresql/data
     logging:
       driver: "json-file"
       options:
@@ -34,18 +33,19 @@ services:
     network_mode: bridge
     image: ealtedge/applcm-broker:latest
     depends_on:
-      - db
+      - mecmdb
       - helm-plugin
     links:
-      - db:dbhost
+      - mecmdb:mecmdb
       - helm-plugin:helmplugin
     restart: always
     container_name: applcm-broker
     environment:
-      MYSQL_DATABASE: 'db'
-      MYSQL_USER: 'root'
-      MYSQL_PASSWORD: 'password'
-      MYSQL_ROOT_PASSWORD: 'password'
+      POSTGRES_DATABASE: 'mecmdb'
+      DBHOST: 'mecmdb'
+      POSTGRES_USER: 'root'
+      POSTGRES_PASSWORD: 'password'
+      POSTGRES_ROOT_PASSWORD: 'password'
       HELM_PLUGIN_PORT: '50051'
       KUBERNETES_PLUGIN_PORT: '50052'
       LOGFILE_PATH: "/go/release/logfile"