Newer
Older
import {HttpClient, HttpParams, HttpHeaders} from "@angular/common/http";
import {ConfigurationService} from "../env/configuration.service";
import {Observable, of} from "rxjs";
import {map, switchMap, concatMap} from "rxjs/operators";
import {Job, JobExecution, JobSpec} from "../model/job";
import {FiltersService} from "./filters.service";
import {CustomHttpParamEncoder} from "../custom-http-param-encoder";
import { Tile } from '../model/tile';
@Injectable({
providedIn: 'root'
})
export class JobsService {
endPoint: string = '/services/job/';
constructor(
private http: HttpClient,
private configService: ConfigurationService,
private filtersService: FiltersService) {

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

Reid Givens
committed
'/pages?pattern=' + encodeURIComponent(pattern) + '&status=' + encodeURI(status), {observe: 'response'}).pipe(

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

Reid Givens
committed
'/pages?pattern=' + encodeURIComponent(pattern) + '&status=' + encodeURI(status), {observe: 'response'}).pipe(

Reid Givens
committed
map(response => {
return response.body;
}));
}
public getJobSpecPage(epoch: number, queue: string, pageId: number, pattern: string, status: string): Observable<Array<JobSpec>> {
let params = new HttpParams({encoder: new CustomHttpParamEncoder()});

Reid Givens
committed
if (!!pattern) {
params = params.append('pattern', pattern);

Reid Givens
committed
}
if (!!status) {
params = params.append('status', status);
}
const sortName = this.filtersService.getCurrentSetting('JOBSPEC_SORT');
const sortDir = this.filtersService.getCurrentSetting('SORT_DIRECTION');
params = params.append('columnNames', sortName);
params = params.append('directions', sortDir);

Reid Givens
committed
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({encoder: new CustomHttpParamEncoder()});

Reid Givens
committed
if (!!pattern) {
params = params.append('pattern', pattern);

Reid Givens
committed
}
if (!!status) {
params = params.append('status', status);
}
const sortName = this.filtersService.getCurrentSetting('JOB_SORT');
const sortDir = this.filtersService.getCurrentSetting('SORT_DIRECTION');
params = params.append('columnNames', sortName);
params = params.append('directions', sortDir);

Reid Givens
committed
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 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<string> {
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;
}));
}
// Returns a JSON encoded string of plane information
public getPlanes(id: number): Observable<string> {
return this.http.get<string>(this.configService.config.url + this.endPoint + 'jobs/' + id + '/planes', {observe: 'response'}).pipe(
map(response => {
return response.body;
}));
// Returns a JSON encoded string of plane information
public getTiles(id: number): Observable<Tile[]> {
return this.http.get<Tile[]>(this.configService.config.url + this.endPoint + 'jobs/' + id + '/calibrationTiles', {observe: 'response'}).pipe(
map(response => {
return response.body;
})
);
// Writes a string of plane names
public writePlanes(id: number, planes: string): Observable<any> {
return this.http.put(this.configService.config.url + this.endPoint + 'jobs/' + id + '/writePlanes', {planes}, {observe: 'response'}).pipe(
map(response => {
return response.status;
}));

Daniel Nemergut
committed
// Returns a response containing the execution's pipeline directory to append to the weblog URL as a string
public getWeblogLink(id: number): Observable<any> {
return this.http.get(this.configService.config.url + this.endPoint + 'jobs/' + id + '/webloglink', {observe: 'response', responseType: 'text'}).pipe(

Daniel Nemergut
committed
map(response => {
return response;
}));
}
public performQA(id: number, status: string, queue: string, selectedTiles?: number[]) {
const ingestUrl = this.configService.config.url + this.endPoint + 'jobs/' + id + '/ingest?status=' + status + '&queue=' + queue;
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(ingestUrl, {}, {observe: "response"}).pipe(
switchMap(response => {
if (selectedTiles) {
const tileUrl = this.configService.config.url + this.endPoint + 'jobs/' + id + '/calAutoPimsTiles';
return this.http.post<Tile[]>(tileUrl, selectedTiles, {observe: "response"}).pipe(map(response => response.body))
} else {
return of(response.body);
}
})
);
}));
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;
}));
}