AddJob adds a new job
(namespace string, job models.JobConfig)
| 146 | |
| 147 | // AddJob adds a new job |
| 148 | func (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 |
| 189 | func (j *jobMutatorImpl) GetHash(namespace string) (string, error) { |
no test coverage detected