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 c7e897efe50452d0d5ad2832eac3eef0e441c56e..0e0252152c19538adc7d40bd247820e530f17d24 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 f745f9568c60ac8879dbcd882fa5bad3b2413eef..12d4babb544a82c4970244c1cf25dec3f7a6c3c1 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 0000000000000000000000000000000000000000..8680bb6504725dda42d6422ecece17f81a623ea8 --- /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 0000000000000000000000000000000000000000..d231076203dcd201278070ec93ad35c219782fe1 --- /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 0000000000000000000000000000000000000000..96b583b5233303d306b524893b07c8bc44ca9f5c --- /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