GetAPIByName returns a single task API and its most recently submitted job along with all running task jobs
(deployedResource *operator.DeployedResource)
| 211 | |
| 212 | // GetAPIByName returns a single task API and its most recently submitted job along with all running task jobs |
| 213 | func GetAPIByName(deployedResource *operator.DeployedResource) ([]schema.APIResponse, error) { |
| 214 | metadata, err := spec.MetadataFromVirtualService(deployedResource.VirtualService) |
| 215 | if err != nil { |
| 216 | return nil, err |
| 217 | } |
| 218 | |
| 219 | api, err := operator.DownloadAPISpec(deployedResource.Name, metadata.APIID) |
| 220 | if err != nil { |
| 221 | return nil, err |
| 222 | } |
| 223 | |
| 224 | k8sJobs, err := config.K8s.ListJobsByLabel("apiName", deployedResource.Name) |
| 225 | if err != nil { |
| 226 | return nil, err |
| 227 | } |
| 228 | |
| 229 | jobIDToK8sJobMap := map[string]*kbatch.Job{} |
| 230 | for i, kJob := range k8sJobs { |
| 231 | jobIDToK8sJobMap[kJob.Labels["jobID"]] = &k8sJobs[i] |
| 232 | } |
| 233 | |
| 234 | endpoint, err := operator.APIEndpoint(api) |
| 235 | if err != nil { |
| 236 | return nil, err |
| 237 | } |
| 238 | |
| 239 | pods, err := config.K8s.ListPodsByLabel("apiName", deployedResource.Name) |
| 240 | if err != nil { |
| 241 | return nil, err |
| 242 | } |
| 243 | |
| 244 | jobIDToPodsMap := map[string][]kcore.Pod{} |
| 245 | for _, pod := range pods { |
| 246 | jobIDToPodsMap[pod.Labels["jobID"]] = append(jobIDToPodsMap[pod.Labels["jobID"]], pod) |
| 247 | } |
| 248 | |
| 249 | inProgressJobKeys, err := job.ListAllInProgressJobKeysByAPI(userconfig.TaskAPIKind, deployedResource.Name) |
| 250 | if err != nil { |
| 251 | return nil, err |
| 252 | } |
| 253 | |
| 254 | jobStatuses := []status.TaskJobStatus{} |
| 255 | jobIDSet := strset.New() |
| 256 | for _, jobKey := range inProgressJobKeys { |
| 257 | jobStatus, err := getJobStatusFromK8sJob(jobKey, jobIDToK8sJobMap[jobKey.ID], jobIDToPodsMap[jobKey.ID]) |
| 258 | if err != nil { |
| 259 | return nil, err |
| 260 | } |
| 261 | |
| 262 | jobStatuses = append(jobStatuses, *jobStatus) |
| 263 | jobIDSet.Add(jobKey.ID) |
| 264 | } |
| 265 | |
| 266 | if len(jobStatuses) < 10 { |
| 267 | jobStates, err := job.GetMostRecentlySubmittedJobStates(deployedResource.Name, 10+len(jobStatuses), userconfig.TaskAPIKind) |
| 268 | if err != nil { |
| 269 | return nil, err |
| 270 | } |
no test coverage detected