Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type Route struct {
type SetOrchestratorTypeRequest struct {
OrchestratorType string
DncPartitionKey string
NodeID string
}

// CreateNetworkContainerResponse specifies response of creating a network container.
Expand Down
51 changes: 31 additions & 20 deletions cns/restserver/restserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type httpRestServiceState struct {
Location string
NetworkType string
OrchestratorType string
NodeID string
Initialized bool
ContainerIDByOrchestratorContext map[string]string // OrchestratorContext is key and value is NetworkContainerID.
ContainerStatus map[string]containerstatus // NetworkContainerID is key.
Expand Down Expand Up @@ -978,9 +979,12 @@ func (service *HTTPRestService) restoreState() error {
func (service *HTTPRestService) setOrchestratorType(w http.ResponseWriter, r *http.Request) {
log.Printf("[Azure CNS] setOrchestratorType")

var req cns.SetOrchestratorTypeRequest
returnMessage := ""
returnCode := 0
var (
req cns.SetOrchestratorTypeRequest
returnMessage string
returnCode int
nodeID string
)

err := service.Listener.Decode(w, r, &req)
if err != nil {
Expand All @@ -990,24 +994,31 @@ func (service *HTTPRestService) setOrchestratorType(w http.ResponseWriter, r *ht
service.lock.Lock()

service.dncPartitionKey = req.DncPartitionKey
nodeID = service.state.NodeID

switch req.OrchestratorType {
case cns.ServiceFabric:
fallthrough
case cns.Kubernetes:
fallthrough
case cns.WebApps:
fallthrough
case cns.Batch:
fallthrough
case cns.DBforPostgreSQL:
fallthrough
case cns.AzureFirstParty:
service.state.OrchestratorType = req.OrchestratorType
service.saveState()
default:
returnMessage = fmt.Sprintf("Invalid Orchestrator type %v", req.OrchestratorType)
returnCode = UnsupportedOrchestratorType
if nodeID == "" || nodeID == req.NodeID {
switch req.OrchestratorType {
case cns.ServiceFabric:
fallthrough
case cns.Kubernetes:
fallthrough
case cns.WebApps:
fallthrough
case cns.Batch:
fallthrough
case cns.DBforPostgreSQL:
fallthrough
case cns.AzureFirstParty:
service.state.OrchestratorType = req.OrchestratorType
service.state.NodeID = req.NodeID
service.saveState()
default:
returnMessage = fmt.Sprintf("Invalid Orchestrator type %v", req.OrchestratorType)
returnCode = UnsupportedOrchestratorType
}
} else {
returnMessage = fmt.Sprintf("Invalid request since this node has already been registered as %s", nodeID)
returnCode = InvalidRequest
}

service.lock.Unlock()
Expand Down