use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method delQuestion.
public boolean delQuestion(String containerName, String testrigName, String questionName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_DEL_QUESTION);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_TESTRIG_NAME, testrigName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_QUESTION_NAME, questionName);
JSONObject jObj = postData(webTarget, multiPart);
return jObj != null;
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return false;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method queueWork.
public boolean queueWork(WorkItem wItem) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_QUEUE_WORK);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_WORKITEM, BatfishObjectMapper.writeString(wItem));
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
JSONObject jObj = postData(webTarget, multiPart);
return jObj != null;
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return false;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method uploadQuestion.
public boolean uploadQuestion(String containerName, String testrigName, String qName, String qFileName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_UPLOAD_QUESTION);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_TESTRIG_NAME, testrigName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_QUESTION_NAME, qName);
addFileMultiPart(multiPart, CoordConsts.SVC_KEY_FILE, qFileName);
return postData(webTarget, multiPart) != null;
} catch (Exception e) {
if (e.getMessage().contains("FileNotFoundException")) {
_logger.errorf("File not found: %s (question file)\n", qFileName);
} else {
_logger.errorf("Exception when uploading question to %s using (%s, %s, %s): %s\n", _coordWorkMgr, testrigName, qName, qFileName, ExceptionUtils.getStackTrace(e));
}
return false;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method uploadTestrig.
public boolean uploadTestrig(String containerName, String testrigName, String zipfileName, boolean autoAnalyze) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_UPLOAD_TESTRIG);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_TESTRIG_NAME, testrigName);
addFileMultiPart(multiPart, CoordConsts.SVC_KEY_ZIPFILE, zipfileName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_AUTO_ANALYZE_TESTRIG, String.valueOf(autoAnalyze));
return postData(webTarget, multiPart) != null;
} catch (Exception e) {
if (e.getMessage().contains("FileNotFoundException")) {
_logger.errorf("File not found: %s\n", zipfileName);
} else {
_logger.errorf("Exception when uploading test rig to %s using (%s, %s, %s): %s\n", _coordWorkMgr, containerName, testrigName, zipfileName, ExceptionUtils.getStackTrace(e));
}
return false;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method listQuestions.
@Nullable
public String[] listQuestions(String containerName, String testrigName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_LIST_QUESTIONS);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_TESTRIG_NAME, testrigName);
JSONObject jObj = postData(webTarget, multiPart);
if (jObj == null) {
return null;
}
if (!jObj.has(CoordConsts.SVC_KEY_QUESTION_LIST)) {
_logger.errorf("question list key not found in: %s\n", jObj);
return null;
}
JSONObject questions = jObj.getJSONObject(CoordConsts.SVC_KEY_QUESTION_LIST);
// JSONObject has String keys, so the implicit cast is safe.
@SuppressWarnings("unchecked") String[] questionList = Iterators.toArray((Iterator<String>) questions.keys(), String.class);
return questionList;
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
Aggregations