MCPcopy
hub / github.com/uber/aresdb / AddJob

Method AddJob

controller/mutators/etcd/job_mutator.go:148–186  ·  view source on GitHub ↗

AddJob adds a new job

(namespace string, job models.JobConfig)

Source from the content-addressed store, hash-verified

146
147// AddJob adds a new job
148func (j *jobMutatorImpl) AddJob(namespace string, job models.JobConfig) error {
149 err := common.Validate(&job, nil)
150 if err != nil {
151 return err
152 }
153
154 jobListProto, jobListVersion, err := readEntityList(j.etcdStore, utils.JobListKey(namespace))
155 if err != nil {
156 return err
157 }
158
159 jobProto := pb.EntityConfig{
160 Name: job.Name,
161 Tomstoned: false,
162 }
163 jobVersion := kv.UninitializedVersion
164 jobProto.Config, err = json.Marshal(job)
165 if err != nil {
166 return err
167 }
168
169 jobListProto, incarnation, exist := addEntity(jobListProto, jobProto.Name)
170 if exist {
171 return common.ErrJobConfigAlreadyExist
172 }
173
174 if incarnation > 0 {
175 jobProto, jobVersion, err = j.readJob(namespace, job.Name)
176 if err != nil {
177 return err
178 }
179 jobProto.Tomstoned = false
180 }
181
182 return kvstore.NewTransaction().
183 AddKeyValue(utils.JobListKey(namespace), jobListVersion, &jobListProto).
184 AddKeyValue(utils.JobKey(namespace, job.Name), jobVersion, &jobProto).
185 WriteTo(j.etcdStore)
186}
187
188// GetHash returns hash that will be different if any job changed
189func (j *jobMutatorImpl) GetHash(namespace string) (string, error) {

Callers 1

UpdateJobMethod · 0.95

Calls 9

readJobMethod · 0.95
ValidateFunction · 0.92
JobListKeyFunction · 0.92
NewTransactionFunction · 0.92
JobKeyFunction · 0.92
readEntityListFunction · 0.85
addEntityFunction · 0.85
WriteToMethod · 0.80
AddKeyValueMethod · 0.80

Tested by

no test coverage detected