@@ -17,7 +17,7 @@ type ResponseError struct {
1717 Message string `json:"message"`
1818}
1919type JoinResponseData struct {
20- JoinInstance bool `json:"join_instance "`
20+ JoinInstance bool `json:"joinInstanceResponse "`
2121}
2222type JoinResponse struct {
2323 Errors []* ResponseError `json:"errors,omitempty"`
@@ -44,14 +44,21 @@ type BuiltInTopologyService struct {
4444 serviceHost string
4545}
4646
47+ type EditReplicasetResponse struct {
48+ Response bool `json:"editReplicasetResponse"`
49+ }
50+
4751var (
4852 topologyIsDown = errors .New ("topology service is down" )
4953 alreadyJoined = errors .New ("already joined" )
5054 alreadyBootstrapped = errors .New ("already bootstrapped" )
5155)
5256
5357var join_mutation = `mutation do_join_server($uri: String!, $instance_uuid: String!, $replicaset_uuid: String!, $roles: [String!]) {
54- join_instance: join_server(uri: $uri, instance_uuid: $instance_uuid, replicaset_uuid: $replicaset_uuid, roles: $roles, timeout: 10)
58+ joinInstanceResponse: join_server(uri: $uri, instance_uuid: $instance_uuid, replicaset_uuid: $replicaset_uuid, roles: $roles, timeout: 10)
59+ }`
60+ var edit_rs_mutation = `mutation editReplicaset($uuid: String!, $weight: Float) {
61+ editReplicasetResponse: edit_replicaset(uuid: $uuid, weight: $weight)
5562}`
5663
5764func (s * BuiltInTopologyService ) Join (pod * corev1.Pod ) error {
@@ -113,12 +120,30 @@ func (s *BuiltInTopologyService) Expel(pod *corev1.Pod) error {
113120 }
114121
115122 if resp .Data .ExpelInstance == false && (resp .Errors == nil || len (resp .Errors ) == 0 ) {
116- return errors .New ("Shit happened" )
123+ return errors .New ("something really bad happened" )
117124 }
118125
119126 return nil
120127}
121128
129+ func (s * BuiltInTopologyService ) SetWeight (replicasetUUID string ) error {
130+ client := graphql .NewClient (s .serviceHost , graphql .WithHTTPClient (& http.Client {Timeout : time .Duration (time .Second * 5 )}))
131+ req := graphql .NewRequest (edit_rs_mutation )
132+
133+ req .Var ("uuid" , replicasetUUID )
134+ req .Var ("weight" , 1 )
135+
136+ resp := & EditReplicasetResponse {}
137+ if err := client .Run (context .TODO (), req , resp ); err != nil {
138+ return err
139+ }
140+ if resp .Response == true {
141+ return nil
142+ }
143+
144+ return errors .New ("something really bad happened" )
145+ }
146+
122147func (s * BuiltInTopologyService ) BootstrapVshard () error {
123148 req := fmt .Sprint ("mutation bootstrap {bootstrapVshardResponse: bootstrap_vshard}" )
124149 j := fmt .Sprintf ("{\" query\" : \" %s\" }" , req )
0 commit comments