Browse code

api/server/httputils: service unavailable for disable swarm

When swarm-mode is disabled, we need to return an error indicating this.
406 was chosen for the "Not Acceptable" verbiage, but this code has
specific semantics in relation to the `Accept` header, which aren't
applicable here.

We now use a 503 for this case. While it is not a perfect match, it does
make it clear that the particular "service" (read: API endpoint) is not
available. The body of the message provides the user with enough
information to take action on it by enabling swarm-mode and ensuring the
service is available.

Signed-off-by: Stephen J Day <stephen.day@docker.com>

Stephen J Day authored on 2016/11/17 12:09:42
Showing 3 changed files
... ...
@@ -62,7 +62,7 @@ func GetHTTPErrorStatusCode(err error) int {
62 62
 			{"wrong login/password", http.StatusUnauthorized},
63 63
 			{"unauthorized", http.StatusUnauthorized},
64 64
 			{"hasn't been activated", http.StatusForbidden},
65
-			{"this node", http.StatusNotAcceptable},
65
+			{"this node", http.StatusServiceUnavailable},
66 66
 		} {
67 67
 			if strings.Contains(errStr, status.keyword) {
68 68
 				statusCode = status.code
... ...
@@ -6731,14 +6731,14 @@ paths:
6731 6731
           description: "bad parameter"
6732 6732
           schema:
6733 6733
             $ref: "#/definitions/ErrorResponse"
6734
-        406:
6735
-          description: "node is already part of a swarm"
6736
-          schema:
6737
-            $ref: "#/definitions/ErrorResponse"
6738 6734
         500:
6739 6735
           description: "server error"
6740 6736
           schema:
6741 6737
             $ref: "#/definitions/ErrorResponse"
6738
+        503:
6739
+          description: "node is already part of a swarm"
6740
+          schema:
6741
+            $ref: "#/definitions/ErrorResponse"
6742 6742
       parameters:
6743 6743
         - name: "body"
6744 6744
           in: "body"
... ...
@@ -6773,14 +6773,14 @@ paths:
6773 6773
       responses:
6774 6774
         200:
6775 6775
           description: "no error"
6776
-        406:
6777
-          description: "node is not part of a swarm"
6778
-          schema:
6779
-            $ref: "#/definitions/ErrorResponse"
6780 6776
         500:
6781 6777
           description: "server error"
6782 6778
           schema:
6783 6779
             $ref: "#/definitions/ErrorResponse"
6780
+        503:
6781
+          description: "node is not part of a swarm"
6782
+          schema:
6783
+            $ref: "#/definitions/ErrorResponse"
6784 6784
       parameters:
6785 6785
         - name: "force"
6786 6786
           description: "Force leave swarm, even if this is the last manager or that it will break the cluster."
... ...
@@ -6800,14 +6800,14 @@ paths:
6800 6800
           description: "bad parameter"
6801 6801
           schema:
6802 6802
             $ref: "#/definitions/ErrorResponse"
6803
-        406:
6804
-          description: "node is not part of a swarm"
6805
-          schema:
6806
-            $ref: "#/definitions/ErrorResponse"
6807 6803
         500:
6808 6804
           description: "server error"
6809 6805
           schema:
6810 6806
             $ref: "#/definitions/ErrorResponse"
6807
+        503:
6808
+          description: "node is not part of a swarm"
6809
+          schema:
6810
+            $ref: "#/definitions/ErrorResponse"
6811 6811
       parameters:
6812 6812
         - name: "body"
6813 6813
           in: "body"
... ...
@@ -6877,10 +6877,6 @@ paths:
6877 6877
                 type: "string"
6878 6878
             example:
6879 6879
               ID: "ak7w3gjqoa3kuz8xcpnyy0pvl"
6880
-        406:
6881
-          description: "server error or node is not part of a swarm"
6882
-          schema:
6883
-            $ref: "#/definitions/ErrorResponse"
6884 6880
         409:
6885 6881
           description: "name conflicts with an existing service"
6886 6882
           schema:
... ...
@@ -6889,6 +6885,10 @@ paths:
6889 6889
           description: "server error"
6890 6890
           schema:
6891 6891
             $ref: "#/definitions/ErrorResponse"
6892
+        503:
6893
+          description: "server error or node is not part of a swarm"
6894
+          schema:
6895
+            $ref: "#/definitions/ErrorResponse"
6892 6896
       parameters:
6893 6897
         - name: "body"
6894 6898
           in: "body"
... ...
@@ -4821,7 +4821,7 @@ Initialize a new swarm. The body of the HTTP response includes the node ID.
4821 4821
 
4822 4822
 - **200** – no error
4823 4823
 - **400** – bad parameter
4824
-- **406** – node is already part of a swarm
4824
+- **503** – node is already part of a swarm
4825 4825
 
4826 4826
 JSON Parameters:
4827 4827
 
... ...
@@ -4890,7 +4890,7 @@ Join an existing swarm
4890 4890
 
4891 4891
 - **200** – no error
4892 4892
 - **400** – bad parameter
4893
-- **406** – node is already part of a swarm
4893
+- **503** – node is already part of a swarm
4894 4894
 
4895 4895
 JSON Parameters:
4896 4896
 
... ...
@@ -4928,7 +4928,7 @@ Leave a swarm
4928 4928
 **Status codes**:
4929 4929
 
4930 4930
 - **200** – no error
4931
-- **406** – node is not part of a swarm
4931
+- **503** – node is not part of a swarm
4932 4932
 
4933 4933
 ### Retrieve the swarm's unlock key
4934 4934
 
... ...
@@ -5024,7 +5024,7 @@ Update a swarm
5024 5024
 
5025 5025
 - **200** – no error
5026 5026
 - **400** – bad parameter
5027
-- **406** – node is not part of a swarm
5027
+- **503** – node is not part of a swarm
5028 5028
 
5029 5029
 JSON Parameters:
5030 5030
 
... ...
@@ -5268,8 +5268,8 @@ image](#create-an-image) section for more details.
5268 5268
 **Status codes**:
5269 5269
 
5270 5270
 - **201** – no error
5271
-- **406** – server error or node is not part of a swarm
5272 5271
 - **409** – name conflicts with an existing object
5272
+- **503** – server error or node is not part of a swarm
5273 5273
 
5274 5274
 **JSON Parameters**:
5275 5275
 
... ...
@@ -6049,8 +6049,8 @@ Create a secret
6049 6049
 **Status codes**:
6050 6050
 
6051 6051
 - **201** – no error
6052
-- **406** – server error or node is not part of a swarm
6053 6052
 - **409** – name conflicts with an existing object
6053
+- **503** – server error or node is not part of a swarm
6054 6054
 
6055 6055
 **JSON Parameters**:
6056 6056