From 474a41a781afb2666ae138eb5cb4cbced947a552 Mon Sep 17 00:00:00 2001 From: Xavier Perret <xa.perret@outlook.com> Date: Tue, 1 Nov 2022 13:21:51 +0100 Subject: [PATCH] bim --- README.md => lab1/README.md | 0 {app => lab1/app}/client.go | 0 {app => lab1/app}/client.yaml | 0 {app => lab1/app}/command-line/userinput.go | 0 {app => lab1/app}/go.mod | 0 {app => lab1/app}/go.sum | 0 .../manage-connection/manage-connection.go | 0 {app => lab1/app}/neighbor-0.yaml | 0 {app => lab1/app}/neighbor-1.yaml | 0 {app => lab1/app}/neighbor-2.yaml | 0 {app => lab1/app}/neighbor-3.yaml | 0 {app => lab1/app}/neighbor-4.yaml | 0 {app => lab1/app}/neighbor-5.yaml | 0 .../app}/object-storage/object-storage.go | 0 .../process-connection/process-connection.go | 13 +++---- {app => lab1/app}/sender/sender.go | 0 {app => lab1/app}/server.go | 0 {app => lab1/app}/test.go | 0 {app => lab1/app}/types/datastructures.go | 0 {app => lab1/app}/utilities/utilities.go | 34 ++++++++++++++++--- lab2/api-pod.yaml | 21 ++++++++++++ lab2/redis-deploy.yaml | 30 ++++++++++++++++ lab2/redis-pod.yaml | 20 +++++++++++ 23 files changed, 107 insertions(+), 11 deletions(-) rename README.md => lab1/README.md (100%) rename {app => lab1/app}/client.go (100%) rename {app => lab1/app}/client.yaml (100%) rename {app => lab1/app}/command-line/userinput.go (100%) rename {app => lab1/app}/go.mod (100%) rename {app => lab1/app}/go.sum (100%) rename {app => lab1/app}/manage-connection/manage-connection.go (100%) rename {app => lab1/app}/neighbor-0.yaml (100%) rename {app => lab1/app}/neighbor-1.yaml (100%) rename {app => lab1/app}/neighbor-2.yaml (100%) rename {app => lab1/app}/neighbor-3.yaml (100%) rename {app => lab1/app}/neighbor-4.yaml (100%) rename {app => lab1/app}/neighbor-5.yaml (100%) rename {app => lab1/app}/object-storage/object-storage.go (100%) rename {app => lab1/app}/process-connection/process-connection.go (97%) rename {app => lab1/app}/sender/sender.go (100%) rename {app => lab1/app}/server.go (100%) rename {app => lab1/app}/test.go (100%) rename {app => lab1/app}/types/datastructures.go (100%) rename {app => lab1/app}/utilities/utilities.go (78%) create mode 100644 lab2/api-pod.yaml create mode 100644 lab2/redis-deploy.yaml create mode 100644 lab2/redis-pod.yaml diff --git a/README.md b/lab1/README.md similarity index 100% rename from README.md rename to lab1/README.md diff --git a/app/client.go b/lab1/app/client.go similarity index 100% rename from app/client.go rename to lab1/app/client.go diff --git a/app/client.yaml b/lab1/app/client.yaml similarity index 100% rename from app/client.yaml rename to lab1/app/client.yaml diff --git a/app/command-line/userinput.go b/lab1/app/command-line/userinput.go similarity index 100% rename from app/command-line/userinput.go rename to lab1/app/command-line/userinput.go diff --git a/app/go.mod b/lab1/app/go.mod similarity index 100% rename from app/go.mod rename to lab1/app/go.mod diff --git a/app/go.sum b/lab1/app/go.sum similarity index 100% rename from app/go.sum rename to lab1/app/go.sum diff --git a/app/manage-connection/manage-connection.go b/lab1/app/manage-connection/manage-connection.go similarity index 100% rename from app/manage-connection/manage-connection.go rename to lab1/app/manage-connection/manage-connection.go diff --git a/app/neighbor-0.yaml b/lab1/app/neighbor-0.yaml similarity index 100% rename from app/neighbor-0.yaml rename to lab1/app/neighbor-0.yaml diff --git a/app/neighbor-1.yaml b/lab1/app/neighbor-1.yaml similarity index 100% rename from app/neighbor-1.yaml rename to lab1/app/neighbor-1.yaml diff --git a/app/neighbor-2.yaml b/lab1/app/neighbor-2.yaml similarity index 100% rename from app/neighbor-2.yaml rename to lab1/app/neighbor-2.yaml diff --git a/app/neighbor-3.yaml b/lab1/app/neighbor-3.yaml similarity index 100% rename from app/neighbor-3.yaml rename to lab1/app/neighbor-3.yaml diff --git a/app/neighbor-4.yaml b/lab1/app/neighbor-4.yaml similarity index 100% rename from app/neighbor-4.yaml rename to lab1/app/neighbor-4.yaml diff --git a/app/neighbor-5.yaml b/lab1/app/neighbor-5.yaml similarity index 100% rename from app/neighbor-5.yaml rename to lab1/app/neighbor-5.yaml diff --git a/app/object-storage/object-storage.go b/lab1/app/object-storage/object-storage.go similarity index 100% rename from app/object-storage/object-storage.go rename to lab1/app/object-storage/object-storage.go diff --git a/app/process-connection/process-connection.go b/lab1/app/process-connection/process-connection.go similarity index 97% rename from app/process-connection/process-connection.go rename to lab1/app/process-connection/process-connection.go index c7e897e..0e02521 100644 --- a/app/process-connection/process-connection.go +++ b/lab1/app/process-connection/process-connection.go @@ -96,7 +96,6 @@ func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config trans := utilities.TranslateMessageToTransaction(mess) utilities.PrintTransaction(trans) - // todo change this for cloud address := strings.Split(conn.RemoteAddr().String(), ":")[0] vote(serverListener, serverConfig, trans, address, objectStorage, amIRoot) } @@ -106,10 +105,11 @@ func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config // transactions which are the same as the one stored locally. This function relies on the broadcast by wave // with ACK distributed algorithm. However, some adjustments are needed to implement this function. func vote(server net.Listener, serverConfig Config, trans Transaction, parentAddress string, objectStorage Blob, amIRoot bool) AckTransaction { - var ack AckTransaction - ack.Id = "" - ack.TotalNodes = 0 - ack.AmountOfCorrectNode = 0 + ack := AckTransaction{ + Id: "", + TotalNodes: 0, + AmountOfCorrectNode: 0, + } var transactionToRate Transaction @@ -225,7 +225,8 @@ func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig } } - vote(serverListener, serverConfig, transToRate, "", objectStorage, amIRoot) + ack := vote(serverListener, serverConfig, transToRate, "", objectStorage, amIRoot) + utilities.PrintAckTransaction(ack) } func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serverConfig Config, amIRoot bool, mutex *sync.Mutex) { diff --git a/app/sender/sender.go b/lab1/app/sender/sender.go similarity index 100% rename from app/sender/sender.go rename to lab1/app/sender/sender.go diff --git a/app/server.go b/lab1/app/server.go similarity index 100% rename from app/server.go rename to lab1/app/server.go diff --git a/app/test.go b/lab1/app/test.go similarity index 100% rename from app/test.go rename to lab1/app/test.go diff --git a/app/types/datastructures.go b/lab1/app/types/datastructures.go similarity index 100% rename from app/types/datastructures.go rename to lab1/app/types/datastructures.go diff --git a/app/utilities/utilities.go b/lab1/app/utilities/utilities.go similarity index 78% rename from app/utilities/utilities.go rename to lab1/app/utilities/utilities.go index f745f95..12d4bab 100644 --- a/app/utilities/utilities.go +++ b/lab1/app/utilities/utilities.go @@ -98,14 +98,29 @@ func PrintConnection(connection net.Conn, connectionNumber int) { } func TranslateMessageToAckTransaction(mess Message) AckTransaction { - var newAck AckTransaction + var transactionId string + var amountOfCorrectNode int + var totalNodes int + var err error var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) - newAck.Id = body["id"].(string) - newAck.AmountOfCorrectNode = body["amountOfCorrectNode"].(int) - newAck.TotalNodes = body["totalNodes"].(int) + transactionId = body["id"].(string) + amountOfCorrectNode, err = strconv.Atoi(body["amountOfCorrectNode"].(string)) + if err != nil { + fmt.Println("Error while converting amountOfCorrectNode to int", err) + return AckTransaction{} + } + totalNodes, err = strconv.Atoi(body["totalNodes"].(string)) + if err != nil { + fmt.Println("Error while converting totalNodes to int", err) + return AckTransaction{} + } - return newAck + return AckTransaction{ + Id: transactionId, + AmountOfCorrectNode: amountOfCorrectNode, + TotalNodes: totalNodes, + } } func TranslateMessageToTransaction(mess Message) Transaction { @@ -131,3 +146,12 @@ func PrintTransactionDoneMessage() { fmt.Println("All transactions have been received") fmt.Println("***********************************") } + +func PrintAckTransaction(ack AckTransaction) { + fmt.Println("***********************************") + fmt.Println("Printing ack transaction") + fmt.Println("The id is ", ack.Id) + fmt.Println("The amount of correct node is ", ack.AmountOfCorrectNode) + fmt.Println("The total nodes is ", ack.TotalNodes) + fmt.Println("***********************************") +} diff --git a/lab2/api-pod.yaml b/lab2/api-pod.yaml new file mode 100644 index 0000000..8680bb6 --- /dev/null +++ b/lab2/api-pod.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Pod +metadata: + name: api + labels: + component: api + app: todo +spec: + containers: + - name: api + image: icclabcna/ccp2-k8s-todo-api + ports: + - containerPort: 8081 + resources: + limits: + cpu: 100m + env: + - name: REDIS_ENDPOINT + value: redis-svc + - name: REDIS_PWD + value: ccp2 \ No newline at end of file diff --git a/lab2/redis-deploy.yaml b/lab2/redis-deploy.yaml new file mode 100644 index 0000000..d231076 --- /dev/null +++ b/lab2/redis-deploy.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis-deploy + labels: + app: todo +spec: + replicas: 1 + selector: + matchLabels: + app: todo + template: + metadata: + name: redis + labels: + component: redis + app: todo + spec: + containers: + - name: redis + image: redis + ports: + - containerPort: 6379 + resources: + limits: + cpu: 100m + args: + - redis-server + - --requirepass ccp2 + - --appendonly yes \ No newline at end of file diff --git a/lab2/redis-pod.yaml b/lab2/redis-pod.yaml new file mode 100644 index 0000000..96b583b --- /dev/null +++ b/lab2/redis-pod.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Pod +metadata: + name: redis-pod + labels: + component: redis + app: todo +spec: + containers: + - name: redis-container + image: redis + ports: + - containerPort: 6379 + resources: + limits: + cpu: 100m + args: + - redis-server + - --requirepass ccp2 + - --appendonly yes -- GitLab