use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method syncTestrigsSyncNow.
public boolean syncTestrigsSyncNow(String pluginId, String containerName, boolean force) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_SYNC_TESTRIGS_SYNC_NOW);
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_VERSION, Version.getVersion());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_PLUGIN_ID, pluginId);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_FORCE, String.valueOf(force));
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 uploadCustomObject.
public boolean uploadCustomObject(String containerName, String testrigName, String objName, String objFileName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_PUT_OBJECT);
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_OBJECT_NAME, objName);
addFileMultiPart(multiPart, CoordConsts.SVC_KEY_FILE, objFileName);
return postData(webTarget, multiPart) != null;
} catch (Exception e) {
if (e.getMessage().contains("FileNotFoundException")) {
_logger.errorf("File not found: %s\n", objFileName);
} else {
_logger.errorf("Exception when uploading custom object to %s using (%s, %s, %s): %s\n", _coordWorkMgr, testrigName, objName, objFileName, ExceptionUtils.getStackTrace(e));
}
return false;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method delTestrig.
public boolean delTestrig(String containerName, String testrigName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_DEL_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);
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 listIncompleteWork.
@Nullable
public List<WorkStatus> listIncompleteWork(String containerName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_LIST_INCOMPLETE_WORK);
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_WORK_LIST)) {
_logger.errorf("work list key not found in: %s\n", jObj);
return null;
}
String result = jObj.getString(CoordConsts.SVC_KEY_WORK_LIST);
List<WorkStatus> workList = BatfishObjectMapper.mapper().readValue(result, new TypeReference<List<WorkStatus>>() {
});
return workList;
} 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 syncTestrigsUpdateSettings.
public boolean syncTestrigsUpdateSettings(String pluginId, String containerName, Map<String, String> settings) {
try {
String settingsStr = BatfishObjectMapper.writePrettyString(settings);
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_SYNC_TESTRIGS_UPDATE_SETTINGS);
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_VERSION, Version.getVersion());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_PLUGIN_ID, pluginId);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_SETTINGS, settingsStr);
JSONObject jObj = postData(webTarget, multiPart);
return jObj != null;
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return false;
}
}
Aggregations