use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method delEnvironment.
public boolean delEnvironment(String containerName, String testrigName, String envName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_DEL_ENVIRONMENT);
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_ENV_NAME, envName);
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 uploadEnvironment.
public boolean uploadEnvironment(String containerName, String testrigName, String baseEnvName, String envName, String zipfileName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_UPLOAD_ENV);
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_BASE_ENV_NAME, baseEnvName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_ENV_NAME, envName);
addFileMultiPart(multiPart, CoordConsts.SVC_KEY_ZIPFILE, zipfileName);
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 environment to %s using (%s, %s, %s): %s\n", _coordWorkMgr, testrigName, envName, zipfileName, ExceptionUtils.getStackTrace(e));
}
return false;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method checkApiKey.
@Nullable
public String checkApiKey() {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_CHECK_API_KEY);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
JSONObject jObj = postData(webTarget, multiPart);
if (jObj == null) {
return null;
}
return Boolean.toString(jObj.getBoolean(CoordConsts.SVC_KEY_API_KEY));
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method listAnalyses.
@Nullable
public JSONObject listAnalyses(String containerName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_LIST_ANALYSES);
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);
JSONObject jObj = postData(webTarget, multiPart);
if (jObj == null) {
return null;
}
if (!jObj.has(CoordConsts.SVC_KEY_ANALYSIS_LIST)) {
_logger.errorf("analysis list key not found in: %s\n", jObj);
return null;
}
return jObj.getJSONObject(CoordConsts.SVC_KEY_ANALYSIS_LIST);
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method getQuestionTemplates.
/**
* Gets the questions configured at the coordinator
*
* @return JSON Object containing question keys and question content as values null if there is
* any failure
*/
@Nullable
JSONObject getQuestionTemplates() {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_GET_QUESTION_TEMPLATES);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
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;
}
return jObj.getJSONObject(CoordConsts.SVC_KEY_QUESTION_LIST);
} catch (Exception e) {
_logger.errorf("Exception in getQuestionTemplates from %s\n", _coordWorkMgr);
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
Aggregations