/
catalogservice_zk.go
62 lines (50 loc) · 2.07 KB
/
catalogservice_zk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package manageserver
import (
"encoding/json"
"net/http"
"github.com/golang/glog"
"golang.org/x/net/context"
"github.com/cloudstax/firecamp/catalog/zookeeper"
"github.com/cloudstax/firecamp/manage"
)
func (s *ManageHTTPServer) createZkService(ctx context.Context, w http.ResponseWriter, r *http.Request, requuid string) (errmsg string, errcode int) {
// parse the request
req := &manage.CatalogCreateZooKeeperRequest{}
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
glog.Errorln("CatalogCreateZooKeeperRequest decode request error", err, "requuid", requuid)
return http.StatusText(http.StatusBadRequest), http.StatusBadRequest
}
err = s.checkRequest(req.Service, req.Resource)
if err != nil {
glog.Errorln("CatalogCreateZooKeeperRequest invalid request, local cluster", s.cluster,
"region", s.region, "requuid", requuid, req.Service, "error", err)
return err.Error(), http.StatusBadRequest
}
// create the service in the control plane and the container platform
crReq, jmxUser, jmxPasswd := zkcatalog.GenDefaultCreateServiceRequest(s.platform, s.region, s.azs, s.cluster,
req.Service.ServiceName, req.Options, req.Resource)
serviceUUID, err := s.createCommonService(ctx, crReq, requuid)
if err != nil {
glog.Errorln("createCommonService error", err, "requuid", requuid, req.Service)
return manage.ConvertToHTTPError(err)
}
glog.Infoln("created zookeeper service", serviceUUID, "requuid", requuid, req.Service)
// zookeeper does not require additional init work. set service initialized
errmsg, errcode = s.setServiceInitialized(ctx, req.Service.ServiceName, requuid)
if errcode != http.StatusOK {
return errmsg, errcode
}
resp := &manage.CatalogCreateZooKeeperResponse{
JmxRemoteUser: jmxUser,
JmxRemotePasswd: jmxPasswd,
}
b, err := json.Marshal(resp)
if err != nil {
glog.Errorln("Marshal CatalogCreateZooKeeperResponse error", err, "requuid", requuid, req.Service, req.Options)
return http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError
}
w.WriteHeader(http.StatusOK)
w.Write(b)
return "", http.StatusOK
}