Browse Source

Merge branch 'GRA-985/host_updates_logic' of https://github.com/gravitl/netmaker into GRA-985/host_delete_logic

Abhishek Kondur 2 years ago
parent
commit
83ea8778d6
4 changed files with 8 additions and 6 deletions
  1. 4 2
      controllers/hosts.go
  2. 2 2
      mq/dynsec_helper.go
  3. 1 1
      mq/handlers.go
  4. 1 1
      mq/mq.go

+ 4 - 2
controllers/hosts.go

@@ -109,10 +109,12 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
 		}
 		}
 	}
 	}
 	// publish host update through MQ
 	// publish host update through MQ
-	mq.HostUpdate(&models.HostUpdate{
+	if mq.HostUpdate(&models.HostUpdate{
 		Action: models.UpdateHost,
 		Action: models.UpdateHost,
 		Host:   *newHost,
 		Host:   *newHost,
-	})
+	}); err != nil {
+		logger.Log(0, r.Header.Get("user"), "failed to send host update: ", currHost.ID.String(), err.Error())
+	}
 	go func() {
 	go func() {
 		if err := mq.PublishPeerUpdate(); err != nil {
 		if err := mq.PublishPeerUpdate(); err != nil {
 			logger.Log(0, "fail to publish peer update: ", err.Error())
 			logger.Log(0, "fail to publish peer update: ", err.Error())

+ 2 - 2
mq/dynsec_helper.go

@@ -186,7 +186,7 @@ func fetchHostAcls(hostID string) []Acl {
 		},
 		},
 		{
 		{
 			AclType:  "publishClientSend",
 			AclType:  "publishClientSend",
-			Topic:    fmt.Sprintf("host/update/%s", hostID),
+			Topic:    fmt.Sprintf("host/serverupdate/%s", hostID),
 			Priority: -1,
 			Priority: -1,
 			Allow:    true,
 			Allow:    true,
 		},
 		},
@@ -373,7 +373,7 @@ func fetchServerAcls() []Acl {
 		},
 		},
 		{
 		{
 			AclType:  "publishClientReceive",
 			AclType:  "publishClientReceive",
-			Topic:    "host/update/#",
+			Topic:    "host/serverupdate/#",
 			Priority: -1,
 			Priority: -1,
 			Allow:    true,
 			Allow:    true,
 		},
 		},

+ 1 - 1
mq/handlers.go

@@ -141,7 +141,7 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
 			logger.Log(1, "error unmarshaling payload ", err.Error())
 			logger.Log(1, "error unmarshaling payload ", err.Error())
 			return
 			return
 		}
 		}
-		logger.Log(0, fmt.Sprintf("recieved host update: %+v\n", hostUpdate))
+		logger.Log(0, "recieved host update for host: ", id)
 		var sendPeerUpdate bool
 		var sendPeerUpdate bool
 		switch hostUpdate.Action {
 		switch hostUpdate.Action {
 		case models.UpdateHost:
 		case models.UpdateHost:

+ 1 - 1
mq/mq.go

@@ -83,7 +83,7 @@ func SetupMQTT() {
 			client.Disconnect(240)
 			client.Disconnect(240)
 			logger.Log(0, "node update subscription failed")
 			logger.Log(0, "node update subscription failed")
 		}
 		}
-		if token := client.Subscribe("host/update/#", 0, mqtt.MessageHandler(UpdateHost)); token.WaitTimeout(MQ_TIMEOUT*time.Second) && token.Error() != nil {
+		if token := client.Subscribe("host/serverupdate/#", 0, mqtt.MessageHandler(UpdateHost)); token.WaitTimeout(MQ_TIMEOUT*time.Second) && token.Error() != nil {
 			client.Disconnect(240)
 			client.Disconnect(240)
 			logger.Log(0, "host update subscription failed")
 			logger.Log(0, "host update subscription failed")
 		}
 		}