CreateDatabase defines create database admin API.
(rw http.ResponseWriter, r *http.Request)
| 65 | |
| 66 | // CreateDatabase defines create database admin API. |
| 67 | func (a *adminAPI) CreateDatabase(rw http.ResponseWriter, r *http.Request) { |
| 68 | nodeCntStr := r.FormValue("node") |
| 69 | nodeCnt, err := strconv.Atoi(nodeCntStr) |
| 70 | |
| 71 | var dbID string |
| 72 | |
| 73 | defer func() { |
| 74 | log.WithFields(log.Fields{ |
| 75 | "nodeCnt": nodeCnt, |
| 76 | "db": dbID, |
| 77 | }).WithError(err).Debug("create database") |
| 78 | }() |
| 79 | |
| 80 | if err != nil || nodeCnt <= 0 || nodeCnt >= math.MaxUint16 { |
| 81 | sendResponse(http.StatusBadRequest, false, "Invalid node count supplied", nil, rw) |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | if dbID, err = config.GetConfig().StorageInstance.Create(nodeCnt); err != nil { |
| 86 | sendResponse(http.StatusInternalServerError, false, err, nil, rw) |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | sendResponse(http.StatusCreated, true, nil, map[string]interface{}{ |
| 91 | "database": dbID, |
| 92 | }, rw) |
| 93 | } |
| 94 | |
| 95 | // DropDatabase defines drop database admin API. |
| 96 | func (a *adminAPI) DropDatabase(rw http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected