Search in sources :

Example 26 with MultiPart

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;
    }
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) JSONObject(org.codehaus.jettison.json.JSONObject) WebTarget(javax.ws.rs.client.WebTarget) BatfishException(org.batfish.common.BatfishException) ProcessingException(javax.ws.rs.ProcessingException)

Example 27 with MultiPart

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;
    }
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) WebTarget(javax.ws.rs.client.WebTarget) BatfishException(org.batfish.common.BatfishException) ProcessingException(javax.ws.rs.ProcessingException)

Example 28 with MultiPart

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;
    }
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) JSONObject(org.codehaus.jettison.json.JSONObject) WebTarget(javax.ws.rs.client.WebTarget) BatfishException(org.batfish.common.BatfishException) ProcessingException(javax.ws.rs.ProcessingException)

Example 29 with MultiPart

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;
    }
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) JSONObject(org.codehaus.jettison.json.JSONObject) WorkStatus(org.batfish.datamodel.pojo.WorkStatus) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) BatfishException(org.batfish.common.BatfishException) ProcessingException(javax.ws.rs.ProcessingException) Nullable(javax.annotation.Nullable)

Example 30 with MultiPart

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;
    }
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) JSONObject(org.codehaus.jettison.json.JSONObject) WebTarget(javax.ws.rs.client.WebTarget) BatfishException(org.batfish.common.BatfishException) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

MultiPart (org.glassfish.jersey.media.multipart.MultiPart)63 WebTarget (javax.ws.rs.client.WebTarget)42 ProcessingException (javax.ws.rs.ProcessingException)28 BatfishException (org.batfish.common.BatfishException)28 JSONObject (org.codehaus.jettison.json.JSONObject)20 Test (org.junit.Test)16 Nullable (javax.annotation.Nullable)15 MediaType (javax.ws.rs.core.MediaType)15 BodyPart (org.glassfish.jersey.media.multipart.BodyPart)11 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)11 Response (javax.ws.rs.core.Response)10 FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)10 Client (javax.ws.rs.client.Client)7 StreamDataBodyPart (org.glassfish.jersey.media.multipart.file.StreamDataBodyPart)7 IOException (java.io.IOException)5 ParseException (java.text.ParseException)5 FileDataBodyPart (org.glassfish.jersey.media.multipart.file.FileDataBodyPart)5 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)3 File (java.io.File)3 Path (javax.ws.rs.Path)3