@@ -95,6 +95,7 @@ type networkInfo struct {
9595type HTTPService interface {
9696 common.ServiceAPI
9797 SendNCSnapShotPeriodically (int , chan bool )
98+ SetNodeOrchestrator (* cns.SetOrchestratorTypeRequest )
9899 SyncNodeStatus (string , string , string , json.RawMessage ) (int , string )
99100}
100101
@@ -2063,6 +2064,14 @@ func (service *HTTPRestService) SendNCSnapShotPeriodically(ncSnapshotIntervalInM
20632064 }
20642065}
20652066
2067+ // SetNodeOrchestrator :- Set node orchestrator after registering with mDNC
2068+ func (service * HTTPRestService ) SetNodeOrchestrator (r * cns.SetOrchestratorTypeRequest ) {
2069+ body , _ := json .Marshal (r )
2070+ req , _ := http .NewRequest (http .MethodPost , "" , bytes .NewBuffer (body ))
2071+ req .Header .Set ("Content-Type" , "application/json; charset=UTF-8" )
2072+ service .setOrchestratorType (httptest .NewRecorder (), req )
2073+ }
2074+
20662075// SyncNodeStatus :- Retrieve the latest node state from DNC & returns the first occurence of returnCode and error with respect to contextFromCNI
20672076func (service * HTTPRestService ) SyncNodeStatus (dncEP , infraVnet , nodeID string , contextFromCNI json.RawMessage ) (returnCode int , errStr string ) {
20682077 logger .Printf ("[Azure CNS] SyncNodeStatus" )
@@ -2096,8 +2105,8 @@ func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string,
20962105 }
20972106
20982107 var (
2099- ncsToBeAdded map [string ]cns.CreateNetworkContainerRequest
2100- ncsToBeDeleted map [string ]bool
2108+ ncsToBeAdded = make ( map [string ]cns.CreateNetworkContainerRequest )
2109+ ncsToBeDeleted = make ( map [string ]bool )
21012110 )
21022111
21032112 // determine new NCs and NCs to be deleted
@@ -2108,25 +2117,28 @@ func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string,
21082117
21092118 for _ , nc := range nodeInfoResponse .NetworkContainers {
21102119 ncid := cns .SwiftPrefix + nc .NetworkContainerid
2120+ delete (ncsToBeDeleted , ncid )
21112121 if _ , exists := service .state .ContainerStatus [ncid ]; ! exists {
21122122 ncsToBeAdded [ncid ] = nc
2113- } else {
2114- delete (ncsToBeDeleted , ncid )
21152123 }
21162124 }
21172125 service .lock .Unlock ()
21182126
21192127 // check if the version is valid and save it to service state
21202128 for _ , nc := range ncsToBeAdded {
21212129 response , err = nmagentclient .GetNetworkContainerVersion (nc .NetworkContainerid ,
2122- fmt .Sprintf (nodeInfoResponse .GetNCVersionURLFmt , nc .PrimaryInterfaceIdentifier , nc .NetworkContainerid , nc .AuthorizationToken ))
2130+ fmt .Sprintf (nodeInfoResponse .GetNCVersionURLFmt ,
2131+ nmagentclient .WireserverIP ,
2132+ nc .PrimaryInterfaceIdentifier ,
2133+ nc .NetworkContainerid ,
2134+ nc .AuthorizationToken ))
21232135 if err == nil {
21242136 if response .StatusCode == http .StatusOK {
21252137 var versionResponse nmagentclient.NetworkContainerResponse
2126- if err = json . NewDecoder (response .Body ). Decode ( & versionResponse ); err != nil {
2127- response . Body . Close ( )
2128-
2129- tmpErrStr = fmt .Sprintf ("[Azure-CNS] Failed to decode GetNCVersion response for NC %s with error: %+v " , nc .NetworkContainerid , err )
2138+ rBytes , _ := ioutil . ReadAll (response .Body )
2139+ json . Unmarshal ( rBytes , & versionResponse )
2140+ if versionResponse . ResponseCode == "" {
2141+ tmpErrStr = fmt .Sprintf ("[Azure-CNS] Failed to unmarshal GetNCVersion response %s for NC %s " , rBytes , nc .NetworkContainerid )
21302142 if errStr == "" && bytes .Compare (nc .OrchestratorContext , contextFromCNI ) == 0 {
21312143 returnCode = UnexpectedError
21322144 errStr = tmpErrStr
@@ -2144,7 +2156,7 @@ func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string,
21442156 req .Header .Set ("Content-Type" , "application/json; charset=UTF-8" )
21452157 service .createOrUpdateNetworkContainer (httptest .NewRecorder (), req )
21462158 } else {
2147- tmpErrStr = fmt .Sprintf ("[Azure-CNS] Network container %s v%d had not propagated to respective NMA" , nc .NetworkContainerid , v1 )
2159+ tmpErrStr = fmt .Sprintf ("[Azure-CNS] Network container %s v%d had not propagated to respective NMA w/ v%d " , nc .NetworkContainerid , v1 , v2 )
21482160 if errStr == "" && bytes .Compare (nc .OrchestratorContext , contextFromCNI ) == 0 {
21492161 returnCode = NetworkContainerPendingStatePropagation
21502162 errStr = tmpErrStr
0 commit comments