use of com.cisco.trex.stateless.model.RPCResponse in project trex-stateless-gui by cisco-system-traffic-generator.
the class RPCMethods method acquireServerPort.
/**
*
* @param portID the port ID
* @param force if force is set to true then the port will be acquired even
* though it is owned by other
* @return connectionHandler in case of success
* @throws PortAcquireException
*/
public String acquireServerPort(int portID, boolean force) throws PortAcquireException {
LOG.trace("Acquiring port [" + portID + "]");
LogsController.getInstance().appendText(LogType.INFO, "Acquiring port [" + portID + "]");
AcquireParams acquireParams = new AcquireParams();
acquireParams.setPortId(portID);
acquireParams.setForce(force);
acquireParams.setUser(serverConnectionManager.getClientName());
acquireParams.setSessionId(Util.getRandomID());
ObjectMapper mapper = new ObjectMapper();
try {
String response = serverConnectionManager.sendRPCRequest(Constants.ACQUIRE_METHOD, acquireParams);
response = Util.removeFirstBrackets(response);
RPCResponse rpcResult = mapper.readValue(response, RPCResponse.class);
String handler = mapper.readValue(rpcResult.getResult(), String.class);
connectionHandler.put(portID, handler);
serverConnectionManager.propagatePortHandler(portID, handler);
return handler;
} catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException ex) {
throw new PortAcquireException(ex.getMessage());
} catch (IOException ex) {
throw new PortAcquireException(ex.getMessage());
}
}
use of com.cisco.trex.stateless.model.RPCResponse in project trex-stateless-gui by cisco-system-traffic-generator.
the class RPCCommands method sendRequest.
// Should be removed from here, it is needed only for old architecture
private static String sendRequest(final String command, final Map<String, Object> parameters) throws IOException {
String stringParameters = "";
if (parameters != null) {
final String jsonParameters = new ObjectMapper().writeValueAsString(parameters);
stringParameters = jsonParameters.substring(1, jsonParameters.length() - 1);
}
final String jsonRPCResult = ConnectionManager.getInstance().sendRequest(command, stringParameters);
final RPCResponse[] rpcResult = new ObjectMapper().readValue(jsonRPCResult, RPCResponse[].class);
return rpcResult[0].getResult();
}
Aggregations