Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call airflow deliver pipeline #308

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
Expand Down Expand Up @@ -103,23 +106,44 @@ private void callAirflowDeliverPipeline(String requestId) {
String pi = GetRequestPermissionsTask.labHeadEmailToLabName(piEmail);
String recipe = requestDataRecord.getStringVal("RequestName", user);

//2021-01-01T15:00:00Z - airflow format
DateFormat airflowFormat = new SimpleDateFormat( "yyyy-MM-ddTHH:mm:ssZ");
String exec_date = airflowFormat.format(new Date(System.currentTimeMillis() + 10000));
// create json body like:
// {"execution_date": "2022-05-19", "conf": {"project":"13097","pi":"abdelwao","recipe":"RNASeq-TruSeqPolyA"}}
String conf = "\"conf\":{\"project\":\""+requestId+"\",\"pi\":\""+pi+"\",\"recipe\":\""+recipe+"\"}";
String body ="{\"execution_date\":\""+exec_date+"\",\""+conf+"}";

Date execDate = new Date(System.currentTimeMillis() + 10000);
String body = formatDeliverPipelineJSON(requestId, pi, recipe, execDate);
log.info("Calling airflow pipeline with json body: " + body);
String cmd = "curl -X POST -d '" + body + "' 'http://igo-ln01:8080/api/v1/dags/deliver_pipeline/dagRuns' -H 'content-type: application/json' --user \"airflow-api:"+airflow_pass+"\"";
Runtime.getRuntime().exec(cmd);
String cmd = "curl -X POST -d '" + body + "' \"http://igo-ln01:8080/api/v1/dags/deliver_pipeline/dagRuns\" -H \"content-type:application/json\" --user \"airflow-api:"+airflow_pass+"\"";
System.out.println("CMD:" + cmd);
// instead of separating each command argument for processBuilder just use "sh"
ProcessBuilder builder = new ProcessBuilder("sh", "-c", cmd);
Process process = builder.start();
logResults(process, log);
} catch (IoError | NotFound | IOException ex) {
log.error(ex);
ex.printStackTrace();
}
}

public static void logResults(Process process, Log log) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line = "";
log.info("Airflow exec pipeline error results:");
while ((line = reader.readLine()) != null) {
log.info(line);
}
reader.close();
}

protected static String formatDeliverPipelineJSON(String requestId, String pi, String recipe, Date execDate) {
//2021-01-01T15:00:00Z - airflow format
DateFormat airflowFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
airflowFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String dateStr = airflowFormat.format(execDate);
dateStr = dateStr.replace(' ', 'T') + "Z";
// create json body like:
// {"execution_date": "2022-05-19", "conf": {"project":"13097","pi":"abdelwao","recipe":"RNASeq-TruSeqPolyA"}}
String conf = "\"conf\":{\"project\":\""+requestId+"\",\"pi\":\""+pi+"\",\"recipe\":\""+recipe+"\"}";
String body ="{\"execution_date\":\""+dateStr+"\","+conf+"}";
return body;
}

/**
* Returns request metadata given a request id.
* @param requestId
Expand All @@ -143,7 +167,7 @@ private RequestSampleList getRequestSampleListDetails(String requestId) {

/**
* Returns list of sample manifest instances given a request id.
* @param requestId
* @param sl
* @return
*/
private List<Map<String, Object>> getSampleManifestListByRequestId(RequestSampleList sl) {
Expand Down Expand Up @@ -185,7 +209,7 @@ private List<Map<String, Object>> getSampleManifestListByRequestId(RequestSample
/**
* Packages message for CMO MetaDB and publishes to MetaDB NATS server.
* @param projectId
* @param requestId
* @param requestDetails
* @param sampleManifestList
*/
private void publishIgoNewRequestToMetaDb(String projectId, RequestSampleList requestDetails, List<Map<String, Object>> sampleManifestList) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.mskcc.limsrest.controller;

import org.junit.jupiter.api.Test;

import java.util.Date;

import static org.junit.jupiter.api.Assertions.*;

class IgoNewRequestMetaDbPublisherTest {

@Test
void formatDeliverPipelineJSON() {
Date now = new Date();
String result = IgoNewRequestMetaDbPublisher.formatDeliverPipelineJSON("12345","Curie","WGS", now);
System.out.println(result);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.mskcc.domain.sample.BankedSample;
import org.mskcc.domain.sample.CmoSampleInfo;
import org.mskcc.limsrest.ConnectionLIMS;
import org.mskcc.limsrest.service.cmoinfo.CorrectedCmoSampleIdGenerator;

import java.rmi.RemoteException;
import java.util.*;
Expand Down

This file was deleted.

Loading