GetAllAPIs returns all task APIs, for each API returning the most recently submitted job and all running jobs
(virtualServices []istioclientnetworking.VirtualService, k8sJobs []kbatch.Job, pods []kcore.Pod)
| 132 | |
| 133 | // GetAllAPIs returns all task APIs, for each API returning the most recently submitted job and all running jobs |
| 134 | func GetAllAPIs(virtualServices []istioclientnetworking.VirtualService, k8sJobs []kbatch.Job, pods []kcore.Pod) ([]schema.APIResponse, error) { |
| 135 | taskAPIsMap := map[string]*schema.APIResponse{} |
| 136 | |
| 137 | jobIDToK8sJobMap := map[string]*kbatch.Job{} |
| 138 | for i, kJob := range k8sJobs { |
| 139 | jobIDToK8sJobMap[kJob.Labels["jobID"]] = &k8sJobs[i] |
| 140 | } |
| 141 | |
| 142 | jobIDToPodsMap := map[string][]kcore.Pod{} |
| 143 | for _, pod := range pods { |
| 144 | if pod.Labels["jobID"] != "" { |
| 145 | jobIDToPodsMap[pod.Labels["jobID"]] = append(jobIDToPodsMap[pod.Labels["jobID"]], pod) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | for i := range virtualServices { |
| 150 | apiName := virtualServices[i].Labels["apiName"] |
| 151 | |
| 152 | metadata, err := spec.MetadataFromVirtualService(&virtualServices[i]) |
| 153 | if err != nil { |
| 154 | return nil, errors.Wrap(err, fmt.Sprintf("api %s", apiName)) |
| 155 | } |
| 156 | |
| 157 | jobStates, err := job.GetMostRecentlySubmittedJobStates(metadata.Name, 1, userconfig.TaskAPIKind) |
| 158 | |
| 159 | jobStatuses := []status.TaskJobStatus{} |
| 160 | if len(jobStates) > 0 { |
| 161 | jobStatus, err := getJobStatusFromJobState(jobStates[0], jobIDToK8sJobMap[jobStates[0].ID], jobIDToPodsMap[jobStates[0].ID]) |
| 162 | if err != nil { |
| 163 | return nil, err |
| 164 | } |
| 165 | |
| 166 | jobStatuses = append(jobStatuses, *jobStatus) |
| 167 | } |
| 168 | |
| 169 | taskAPIsMap[metadata.Name] = &schema.APIResponse{ |
| 170 | Metadata: metadata, |
| 171 | TaskJobStatuses: jobStatuses, |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | inProgressJobKeys, err := job.ListAllInProgressJobKeys(userconfig.TaskAPIKind) |
| 176 | if err != nil { |
| 177 | return nil, err |
| 178 | } |
| 179 | |
| 180 | for _, jobKey := range inProgressJobKeys { |
| 181 | alreadyAdded := false |
| 182 | for _, jobStatus := range taskAPIsMap[jobKey.APIName].TaskJobStatuses { |
| 183 | if jobStatus.ID == jobKey.ID { |
| 184 | alreadyAdded = true |
| 185 | break |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | if alreadyAdded { |
| 190 | continue |
| 191 | } |
no test coverage detected