--- /dev/null
+LICENSES.txt
+
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the "Software License");
+you may not use this software except in compliance with the Software
+License. You may obtain a copy of the Software License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the Software License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the Software License for the specific language governing permissions
+and limitations under the Software License.
+
+
+
+Unless otherwise specified, all documentation contained herein is licensed
+under the Creative Commons License, Attribution 4.0 Intl. (the
+"Documentation License"); you may not use this documentation except in
+compliance with the Documentation License. You may obtain a copy of the
+Documentation License at
+
+https://creativecommons.org/licenses/by/4.0/
+
+Unless required by applicable law or agreed to in writing, documentation
+distributed under the Documentation License is distributed on an "AS IS"
+BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+implied. See the Documentation License for the specific language governing
+permissions and limitations under the Documentation License.
+
+
+
--- /dev/null
+# Database as a service repository
+
+This repository containes all the needed elements to deploy database as a service to kubernetes
+
+## Architecture
+
+Redis is the chosen database technology and the final product will deploy autonomous
+redis cluster. In R0 schedule, single, non-redundant, non-persistent redis server is
+deployed
+
+## Subsystem structure
+
+**docker** Contains dockerfiles to produce dbaas / testapplication container images
+**charts** Contais helm charts to deploy dbaas service / testapplication
+**testapplication** Contains dbaas test applications with various languages such as go, ..
+
+## Container image creation
+
+The images must be built at subsystem root level
+
+To produce dbaas service image:
+```
+docker build --file docker/Dockerfile.redis --tag redis-standalone .
+```
+
+To produce testapplication image:
+```
+docker build --file docker/Dockerfile.testapp --tag dbaas-test .
+```
+
+## Deployment
+
+### DBaaS service
+
+In R0, dbaas service is realized with single container running redis database.
+The database is configured to be non-persistent and non-redundant. The container
+exposes single port which is hardcoded to be 6379.
+
+After dbaas service is installed, environment variables **DBAAS_SERVICE_HOST**
+and **DBAAS_SERVICE_PORT** are exposed to application containers. SDL library
+will automatically use these environment variables.
+
+The service is installed via helm by using dbaas-service chart. Modify the
+values accordingly before installation (repository location, image name, ..)
+
+```
+helm install ./dbaas-service
+```
+
+### DBaaS test application
+
+Test application is installed via helm by using dbaas-test chart. Modify the
+values accordingly before installation (repository location, image name, ..)
+
+```
+helm install ./dbaas-test
+```
+
+## Testing
+
+Make sure that dbaas-service and dbaas-test application are deployed:
+```
+>>helm ls
+NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
+angry-greyhound 1 Thu Mar 21 11:36:23 2019 DEPLOYED dbaas-test-0.1.0 1.0 default
+loitering-toad 1 Thu Mar 21 11:35:21 2019 DEPLOYED dbaas-0.1.0 1.0 default
+```
+
+Check the deployed pods
+```
+>>kubectl get pods
+NAME READY STATUS RESTARTS AGE
+dbaas-test-app-7695dbb9ff-qn8c2 1/1 Running 0 5s
+redis-standalone-78978f4c6f-54b2s 1/1 Running 0 66s
+```
+
+Connect to the test application container:
+```
+kubectl exec -it dbaas-test-app-7695dbb9ff-qn8c2 -- /bin/bash
+```
+
+In test application container:
+```
+The environment variables for database backend should be set:
+
+>>printenv
+DBAAS_SERVICE_HOST=10.108.103.51
+DBAAS_SERVICE_PORT=6379
+
+
+Go test application using preliminary go SDL-API should be able to perform reads and writes:
+
+>>./testapp
+key1:data1
+key3:%!s(<nil>)
+key2:data2
+num1:1
+num2:2
+-------------
+mix2:2
+num1:1
+num2:2
+pair1:data1
+array1:adata1
+mix1:data1
+mix3:data3
+mix4:4
+arr1:
+key1:data1
+key2:data2
+pair2:data2
+array2:adata2
+
+
+Redis server can be pinged with redis-cli:
+
+>>redis-cli -h $DBAAS_SERVICE_HOST -p $DBAAS_SERVICE_PORT ping
+PONG
+```
+
+## License
+This project is licensed under the Apache License 2.0 - see the [LICENSE.md](LICENSE.md) file for details
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+apiVersion: v1
+appVersion: "1.0"
+description: DBaaS realized with standalone, non-persistent, non-redundant Redis
+name: dbaas
+version: 0.1.0
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+ name: {{ .Values.backend.name }}
+spec:
+ replicas: {{ .Values.backend.replicas }}
+ template:
+ metadata:
+ labels:
+ app: {{ .Values.backend.name }}
+ spec:
+ terminationGracePeriodSeconds: {{ .Values.backend.terminationGracePeriodSeconds }}
+ containers:
+ - image: {{ .Values.backend.image.name }}:{{ .Values.backend.image.tag }}
+ imagePullPolicy: {{ .Values.backend.image.imagePullPolicy }}
+ ports:
+ - containerPort: {{ .Values.backend.targetPort }}
+ name: {{ .Values.backend.name }}
+ restartPolicy: Always
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ .Chart.Name }}
+spec:
+ selector:
+ app: {{ .Values.backend.name }}
+ ports:
+ - port: {{ .Values.backend.port }}
+ targetPort: {{ .Values.backend.targetPort }}
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+backend:
+ terminationGracePeriodSeconds: 0
+ replicas: 1
+ name: "redis-standalone"
+ port: 6379
+ targetPort: 6379
+ image:
+ name: snapshot.docker.ranco-dev-tools.eastus.cloudapp.azure.com/redis-standalone
+ tag: latest
+ imagePullPolicy: IfNotPresent
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+apiVersion: v1
+appVersion: "1.0"
+description: Application for testing DBAAS connectivity
+name: dbaas-test
+version: 0.1.0
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+ name: {{ .Values.testapp.name }}
+spec:
+ replicas: {{ .Values.testapp.replicas }}
+ template:
+ metadata:
+ labels:
+ app: {{ .Values.testapp.name }}
+ spec:
+ terminationGracePeriodSeconds: {{ .Values.testapp.terminationGracePeriodSeconds }}
+ containers:
+ - image: {{ .Values.testapp.image.name }}:{{ .Values.testapp.image.tag }}
+ imagePullPolicy: {{ .Values.testapp.image.imagePullPolicy }}
+ name: {{ .Values.testapp.name }}
+ restartPolicy: Always
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+testapp:
+ terminationGracePeriodSeconds: 0
+ replicas: 1
+ name: "dbaas-test-app"
+ image:
+ name: snapshot.docker.ranco-dev-tools.eastus.cloudapp.azure.com/dbaas-test
+ tag: latest
+ imagePullPolicy: IfNotPresent
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+FROM ubuntu:latest
+
+# Install redis
+RUN apt-get update && \
+ apt install -y redis-server && \
+ apt-get clean
+
+# Create suitable configuration file
+RUN sed -i 's/^\(bind .*\)$/# \1/' /etc/redis/redis.conf && \
+ sed -i 's/^\(daemonize .*\)$/# \1/' /etc/redis/redis.conf && \
+ sed 's/^protected-mode yes/protected-mode no/' -i /etc/redis/redis.conf
+
+EXPOSE 6379
+
+CMD ["redis-server", "/etc/redis/redis.conf"]
+
--- /dev/null
+# Copyright (c) 2019 AT&T Intellectual Property.
+# Copyright (c) 2019 Nokia.
+#
+# 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.
+
+FROM ubuntu:latest
+
+# Install redis tools & golang & git
+RUN apt-get update && \
+ apt install -y redis-tools && \
+ apt install -y git && \
+ apt install -y wget && \
+ wget https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz && \
+ tar -xvf go1.11.4.linux-amd64.tar.gz && \
+ mv go /usr/local && \
+ apt-get clean
+
+# Copy sourcefiles
+COPY ./testapplication ./testapplication
+
+# Install go testapplication
+RUN export GOROOT=/usr/local/go && \
+ export GOPATH=$HOME/Projects/Proj1 && \
+ export PATH=$GOPATH/bin:$GOROOT/bin:$PATH && \
+ go get github.com/go-redis/redis && \
+ go build /testapplication/go/testapp.go
+
+# Keep the container alive
+ENTRYPOINT ["tail", "-f", "/dev/null"]
--- /dev/null
+// Copyright (c) 2019 AT&T Intellectual Property.
+// Copyright (c) 2019 Nokia.
+//
+// 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.
+
+package sdl
+
+import (
+ "github.com/go-redis/redis"
+ "os"
+ "reflect"
+)
+
+type SdlInstance struct {
+ nameSpace string
+ nsPrefix string
+ client *redis.Client
+}
+
+func Create(nameSpace string) *SdlInstance {
+ hostname := os.Getenv("DBAAS_SERVICE_HOST")
+ if hostname == "" {
+ hostname = "localhost"
+ }
+ port := os.Getenv("DBAAS_SERVICE_PORT")
+ if port == "" {
+ port = "6379"
+ }
+ redisAddress := hostname + ":" + port
+ client := redis.NewClient(&redis.Options{
+ Addr: redisAddress,
+ Password: "", // no password set
+ DB: 0, // use default DB
+ })
+
+ s := SdlInstance{
+ nameSpace: nameSpace,
+ nsPrefix: "{" + nameSpace + "},",
+ client: client,
+ }
+
+ return &s
+}
+
+func (s *SdlInstance) setNamespaceToKeys(pairs ...interface{}) []interface{} {
+ var retVal []interface{}
+ for i, v := range pairs {
+ if i%2 == 0 {
+ reflectType := reflect.TypeOf(v)
+ switch reflectType.Kind() {
+ case reflect.Slice:
+ x := reflect.ValueOf(v)
+ for i2 := 0; i2 < x.Len(); i2++ {
+ if i2%2 == 0 {
+ retVal = append(retVal, s.nsPrefix+x.Index(i2).Interface().(string))
+ } else {
+ retVal = append(retVal, x.Index(i2).Interface())
+ }
+ }
+ case reflect.Array:
+ x := reflect.ValueOf(v)
+ for i2 := 0; i2 < x.Len(); i2++ {
+ if i2%2 == 0 {
+ retVal = append(retVal, s.nsPrefix+x.Index(i2).Interface().(string))
+ } else {
+ retVal = append(retVal, x.Index(i2).Interface())
+ }
+ }
+ default:
+ retVal = append(retVal, s.nsPrefix+v.(string))
+ }
+ } else {
+ retVal = append(retVal, v)
+ }
+ }
+ return retVal
+}
+
+func (s *SdlInstance) Set(pairs ...interface{}) error {
+ keyAndData := s.setNamespaceToKeys(pairs...)
+ err := s.client.MSet(keyAndData...).Err()
+ return err
+}
+
+func (s *SdlInstance) Get(keys []string) (map[string]interface{}, error) {
+ var keysWithNs []string
+ for _, v := range keys {
+ keysWithNs = append(keysWithNs, s.nsPrefix+v)
+ }
+ val, err := s.client.MGet(keysWithNs...).Result()
+ m := make(map[string]interface{})
+ if err != nil {
+ return m, err
+ }
+ for i, v := range val {
+ m[keys[i]] = v
+ }
+ return m, err
+}
+
+func (s *SdlInstance) SetIf(key string, oldData, newData interface{}) {
+ panic("SetIf not implemented\n")
+}
+
+func (s *SdlInstance) SetIfiNotExists(key string, data interface{}) {
+ panic("SetIfiNotExists not implemented\n")
+}
+
+func (s *SdlInstance) Remove(keys ...string) {
+ panic("Remove not implemented\n")
+}
+
+func (s *SdlInstance) RemoveIf(key string, data interface{}) {
+ panic("RemoveIf not implemented\n")
+}
+
+func (s *SdlInstance) GetAll() []string {
+ panic("GetAll not implemented\n")
+}
+
+func (s *SdlInstance) RemoveAll() {
+ panic("RemoveAll not implemented\n")
+}
+
--- /dev/null
+// Copyright (c) 2019 AT&T Intellectual Property.
+// Copyright (c) 2019 Nokia.
+//
+// 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.
+
+package main
+
+import (
+ "fmt"
+ "./sdl"
+)
+
+func main() {
+ sdl1 := sdl.Create("test1")
+
+ var err error
+
+ err = sdl1.Set("key1", "data1", "key2", "data2")
+ if err != nil {
+ fmt.Printf("unable to write to DB\n")
+ }
+
+ err = sdl1.Set("num1", 1, "num2", 2)
+ if err != nil {
+ fmt.Printf("unable to write to DB\n")
+ }
+
+ d := make([]byte, 3)
+ d[0] = 1
+ d[1] = 2
+ d[2] = 3
+ err = sdl1.Set("arr1", d)
+ if err != nil {
+ fmt.Printf("unable to write to DB\n")
+ }
+
+ p := []string{"pair1", "data1", "pair2", "data2"}
+ err = sdl1.Set(p)
+ if err != nil {
+ fmt.Printf("unable to write to DB\n")
+ }
+
+ a := [4]string{"array1", "adata1", "array2", "adata2"}
+ err = sdl1.Set(a)
+ if err != nil {
+ fmt.Printf("unable to write to DB\n")
+ }
+
+ mix1 := []interface{}{"mix1", "data1", "mix2", 2}
+ err = sdl1.Set(mix1)
+ if err != nil {
+ fmt.Printf("unable to write to DB\n")
+ }
+
+ mix2 := [4]interface{}{"mix3", "data3", "mix4", 4}
+ err = sdl1.Set(mix2)
+ if err != nil {
+ fmt.Printf("unable to write to DB\n")
+ }
+
+ retDataMap, err := sdl1.Get([]string{"key1", "key3", "key2"})
+ if err != nil {
+ fmt.Printf("Unable to read from DB\n")
+ } else {
+ for i, v := range retDataMap {
+ fmt.Printf("%s:%s\n", i, v)
+ }
+ }
+
+ retDataMap2, err := sdl1.Get([]string{"num1", "num2"})
+ if err != nil {
+ fmt.Printf("Unable to read from DB\n")
+ } else {
+ for i, v := range retDataMap2 {
+ fmt.Printf("%s:%s\n", i, v)
+ }
+ }
+
+ fmt.Println("-------------")
+ allKeys := []string{"key1", "key2", "num1", "num2", "pair1", "pair2", "array1", "array2", "mix1", "mix2", "mix3", "mix4", "arr1"}
+ retDataMap3, err := sdl1.Get(allKeys)
+ if err != nil {
+ fmt.Printf("Unable to read from DB\n")
+ } else {
+ for i3, v3 := range retDataMap3 {
+ fmt.Printf("%s:%s\n", i3, v3)
+ }
+ }
+}