Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {Injectable} from '@angular/core';
import {HttpClient, HttpResponse} from "@angular/common/http";
import {ConfigurationService} from "../env/configuration.service";
import {Observable} from "rxjs";
import {map, switchMap} from "rxjs/operators";
import {Job, JobExecution, JobSpec} from "../model/job";
@Injectable({
providedIn: 'root'
})
export class JobsService {
endPoint: string = '/services/job/';
constructor(private http: HttpClient, private configService: ConfigurationService) {
}
public getJobs(queue: string, id: string, pattern: string, status: string): Observable<Array<Job>> {
return this.http.get<Array<Job>>(this.configService.config.url + this.endPoint + 'optimized/queues/' + queue, {observe: 'response'}).pipe(
map((response: HttpResponse<Array<Job>>) => {
let reply = response.body;
if (id && id.length > 0) {
reply = reply.filter(job => job.job_id.toString() === id);
} else {
if (pattern && pattern.length > 0) {
reply = reply.filter(job => job.job_name.match(pattern.replace("+", "\\+")));
}
if (status && status.length > 0 && status !== 'ALL') {
reply = reply.filter(job => job.job_status == status);
}
}
return reply;
}));
}
public getJobSpecs(queue: string, id: string, pattern: string, status: string): Observable<Array<Job>> {
return this.http.get<Array<Job>>(this.configService.config.url + this.endPoint + 'optimized/queues/' + queue, {observe: 'response'}).pipe(
map((response: HttpResponse<Array<Job>>) => {
let reply = response.body;
if (id && id.length > 0) {
reply = reply.filter(job => job.jobspec_id.toString() === id);
} else {
if (pattern && pattern.length > 0) {
reply = reply.filter(job => job.jobspec_name.match(pattern.replace("+", "\\+")));
}
if (status && status.length > 0 && status !== 'ALL') {
reply = reply.filter(job => job.job_status == status);
}
}
return reply;
}));
}
public getJobSpec(id: number): Observable<JobSpec> {
return this.http.get<JobSpec>(this.configService.config.url + this.endPoint + 'specs/' + id, {observe: 'response'}).pipe(
map(response => {
return response.body;
}));
}
public jobSpecToJob (spec: JobSpec): Job {
const summary = new Job();
summary.jobspec_id = spec.id;
summary.jobspec_name = spec.name;
summary.jobspec_creation_date = spec.creationDate;
summary.jobspec_status = spec.status;
summary.jobspec_creation_date_formatted = new Date(spec.creationDate).toLocaleString("en-US");
summary.jobspec_sdm_id = spec.sdmId;
for (let i = 0; i < spec.executions.length; i++) {
const exec = spec.executions[i];
summary.job_id = exec.id;
summary.job_name = exec.name;
summary.job_starttime = Math.round(new Date(exec.startDate).getTime()/1000);
summary.job_endtime = Math.round(new Date(exec.endDate).getTime()/1000);
summary.job_status = exec.status;
summary.job_arch_status = exec.archiveStatus;
summary.job_starttime_formatted = exec.startDate;
summary.job_endtime_formatted = exec.endDate;
}
return summary;
};
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
public getJob(id: number): Observable<any> {
return this.http.get<JobExecution>(this.configService.config.url + this.endPoint + 'jobs/' + id, {observe: 'response'}).pipe(
map(response => {
return response.body;
}));
}
public createJob(id: number, queue: string, version: number): Observable<any> {
let command = {productId: id, inputProductVersions: [version]};
return this.http.post(this.configService.config.url + this.endPoint + 'createJob?id=' + id + '&queue=' + queue, command, {observe: "response"}).pipe(
map(response => {
return response.status;
}));
}
public updateNotes(id: number, notes: string): Observable<any> {
return this.http.put(this.configService.config.url + this.endPoint + 'jobs/' + id + '/notes', {notes: notes}, {observe: "response"}).pipe(
map(response => {
return notes;
}));
}
public updateJobStatus(id: number, status: string, queue: string) {
return this.http.put(this.configService.config.url + this.endPoint + '/jobs/' + id + '/status?status=' + status + '&queue=' + queue, {}, {observe: "response"}).pipe(
switchMap(response => {
return this.http.put(this.configService.config.url + this.endPoint + '/jobs/' + id + '/images?status=' + status + '&queue=' + queue, {}, {observe: "response"}).pipe(
map(response => {
return status;
}));
}));
}
}