Newer
Older

Reid Givens
committed
import {HttpClient, HttpParams} 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) {
}

Reid Givens
committed
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
61
62
63
64
public getJobRecordCount(epoch: number, queue: string, pattern: string, status: string): Observable<number> {
return this.http.get<number>(this.configService.config.url + this.endPoint + 'byEpoch/' + epoch.toString() + '/byQueue/' + queue +
'/pages?pattern=' + encodeURI(pattern) + '&status=' + encodeURI(status), {observe: 'response'}).pipe(
map(response => {
return response.body;
}));
}
public getJobSpecRecordCount(epoch: number, queue: string, pattern: string, status: string): Observable<number> {
return this.http.get<number>(this.configService.config.url + this.endPoint + 'specs/byEpoch/' + epoch.toString() + '/byQueue/' + queue +
'/pages?pattern=' + encodeURI(pattern) + '&status=' + encodeURI(status), {observe: 'response'}).pipe(
map(response => {
return response.body;
}));
}
public getJobSpecPage(epoch: number, queue: string, pageId: number, pattern: string, status: string): Observable<Array<JobSpec>> {
let params = new HttpParams();
if (!!pattern) {
params = params.append('pattern', pattern);
}
if (!!status) {
params = params.append('status', status);
}
return this.http.get<Array<JobSpec>>(this.configService.config.url + this.endPoint + 'specs/byEpoch/' + epoch.toString() + '/byQueue/' + queue +
'/pages/' + pageId.toString() + '/', {params: params, observe: 'response'}).pipe(
map(response => {
return response.body;
}));
}
public getJobPage(epoch: number, queue: string, pageId: number, pattern: string, status: string): Observable<Array<Job>> {
let params = new HttpParams();
if (!!pattern) {
params = params.append('pattern', pattern);
}
if (!!status) {
params = params.append('status', status);
}
return this.http.get<Array<Job>>(this.configService.config.url + this.endPoint + 'byEpoch/' + epoch.toString() + '/byQueue/' + queue +
'/pages/' + pageId.toString() + '/', {params: params, observe: 'response'}).pipe(
map(response => {
return response.body;
}));
}
/*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;
}));

Reid Givens
committed
}*/
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;
}));
}

Reid Givens
committed
// unlike the above, this returns an object the same shape as the pages
public getJobSpecById(id: number): Observable<JobSpec> {
return this.http.get<JobSpec>(this.configService.config.url + this.endPoint + 'specs/byId/' + id, {observe: 'response'}).pipe(
map(response => {
return response.body;
}));
}

Reid Givens
committed
public jobSpecToJob(spec: JobSpec): Job {
const summary = new Job();

Reid Givens
committed
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;

Reid Givens
committed
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;

Reid Givens
committed
public getJobExecution(id: number): Observable<JobExecution> {
return this.http.get<JobExecution>(this.configService.config.url + this.endPoint + 'jobs/' + id, {observe: 'response'}).pipe(
map(response => {
return response.body;
}));

Reid Givens
committed
}
// unlike the above, this returns an object the same shape as the pages
public getJobById(id: number): Observable<Job> {
return this.http.get<Job>(this.configService.config.url + this.endPoint + 'byId/' + 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 submitJob(id: number, queue: string): Observable<any> {
return this.http.put(this.configService.config.url + this.endPoint + 'queues/' + queue + '/specs/' + id + '/submit', {}, {observe: "response"}).pipe(
map(response => {
return response;
}));
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;
}));
}

Reid Givens
committed
public updateJobStatus(id: number, status: string) {
return this.http.put(this.configService.config.url + this.endPoint + 'jobs/' + id + '/status?status=' + status, {}, {observe: "response"}).pipe(
map(response => {
return status;
}));
}
public performQA(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(

Reid Givens
committed
return this.http.put(this.configService.config.url + this.endPoint + 'jobs/' + id + '/ingest?status=' + status + '&queue=' + queue, {}, {observe: "response"}).pipe(
public deleteJobSpec(jobSpecId: number, queue: string): Observable<number> {
return this.http.delete<string>(this.configService.config.url + this.endPoint + 'queues/' + queue + '/specs/' + jobSpecId, {observe: "response"}).pipe(
map(response => {
return response.status;
}));
}