use of com.exalttech.trex.remote.exceptions.InvalidRPCResponseException in project trex-stateless-gui by cisco-system-traffic-generator.
the class ConnectionManager method handleResponse.
private String handleResponse(byte[] serverResponse, boolean writeToLog) throws UnsupportedEncodingException, IncorrectRPCMethodException, InvalidRPCResponseException {
if (serverResponse != null) {
String rpcResponse = new String(serverResponse, "UTF-8");
LOG.trace("Received Server response \n" + Util.toPrettyFormat(rpcResponse));
if (writeToLog) {
logProperty.setValue("Received Server response " + Util.toPrettyFormat(rpcResponse));
}
if (rpcResponse.contains("\"error\"")) {
try {
rpcResponse = Util.removeFirstBrackets(rpcResponse);
RPCError rpcError = new ObjectMapper().readValue(rpcResponse, RPCError.class);
String err = rpcError.getError().getSpecificOrMessage();
LOG.error(err);
LogsController.getInstance().appendText(LogType.ERROR, err);
throw new IncorrectRPCMethodException(err + "\n " + Util.toPrettyFormat(rpcResponse));
} catch (IOException ex) {
LOG.warn("Error parsing response", ex);
}
}
return rpcResponse;
} else {
throw new InvalidRPCResponseException();
}
}
use of com.exalttech.trex.remote.exceptions.InvalidRPCResponseException in project trex-stateless-gui by cisco-system-traffic-generator.
the class RPCMethods method startTraffic.
/**
* @param portID
* @param force
* @param type
* @param multiplierValue
* @param duration
* @return multiplier value from the server
* @throws com.exalttech.trex.remote.exceptions.TrafficException
*/
public double startTraffic(int portID, boolean force, String type, double multiplierValue, double duration) throws TrafficException {
LogsController.getInstance().appendText(LogType.INFO, "Starting Traffic on Port " + portID);
String handler = (String) connectionHandler.get(portID);
Multiplier trafficMultiplier = new Multiplier(type, multiplierValue);
TrafficParams trafficParams = new TrafficParams(force, handler, trafficMultiplier, portID);
trafficParams.setDuration(duration);
try {
String updateTrafficResponse = serverConnectionManager.sendRPCRequest(Constants.START_TRAFFIC_METHOD, trafficParams);
LOG.trace("Start Traffic response:" + updateTrafficResponse);
return getMultiplierValue(updateTrafficResponse);
} catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException | SizeLimitExceededException ex) {
throw new TrafficException(ex.toString());
}
}
use of com.exalttech.trex.remote.exceptions.InvalidRPCResponseException in project trex-stateless-gui by cisco-system-traffic-generator.
the class RPCMethods method updateTraffic.
/**
* @param portID
* @param force
* @param type
* @param multiplierValue
* @return multiplier value from the server
* @throws com.exalttech.trex.remote.exceptions.TrafficException
*/
public double updateTraffic(int portID, boolean force, String type, double multiplierValue) throws TrafficException {
LOG.trace("Updating Traffic on port(s) [" + portID + "], setting to " + multiplierValue + " pps");
LogsController.getInstance().appendText(LogType.INFO, "Updating Traffic on port(s) [" + portID + "], setting to " + multiplierValue + " pps");
Multiplier trafficMultiplier = new Multiplier(type, multiplierValue);
String handler = (String) connectionHandler.get(portID);
TrafficParams trafficParams = new TrafficParams(force, handler, trafficMultiplier, portID);
try {
String updateTrafficResponse = serverConnectionManager.sendRPCRequest(Constants.UPDATE_TRAFFIC_METHOD, trafficParams);
return getMultiplierValue(updateTrafficResponse);
} catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException | SizeLimitExceededException ex) {
throw new TrafficException(ex.toString());
}
}
use of com.exalttech.trex.remote.exceptions.InvalidRPCResponseException 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 (InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException | IOException | SizeLimitExceededException ex) {
throw new PortAcquireException(ex.getMessage());
}
}
use of com.exalttech.trex.remote.exceptions.InvalidRPCResponseException in project trex-stateless-gui by cisco-system-traffic-generator.
the class MainViewController method assignProfile.
/**
* Assign profile to selected port
*
* @param profileName
*/
private void assignProfile(String profileName, double currentBandwidth, boolean assignPrevBandwidth, int portID) {
try {
// update selected profile
AssignedProfile assignedProf = assignedPortProfileMap.get(portID);
if (assignedProf == null) {
return;
}
assignedProf.setProfileName(profileName);
assignedProf.setAllStreamsWithLatency(allStreamWithLatency);
PortModel port = PortsManager.getInstance().getPortModel(portID);
String portState = port.getPortStatus();
StreamValidation streamValidationGraph = serverRPCMethods.assignTrafficProfile(portID, loadedProfiles);
portManager.getPortModel(portID).setStreamLoaded(true);
startStream.setDisable(false);
// update current multiplier data
assignedProf.setRate(streamValidationGraph.getResult().getRate());
multiplierView.assignNewProfile(assignedProf);
// update multiplier value according to previous bandwidth value
if (assignPrevBandwidth) {
multiplierView.setSliderValue(currentBandwidth);
}
updateMultiplierValues(assignedProf);
if (portState.equalsIgnoreCase("tx")) {
startTraffic(portID);
}
} catch (IOException | InvalidRPCResponseException | IncorrectRPCMethodException ex) {
startStream.setDisable(true);
portManager.getPortModel(portID).setStreamLoaded(false);
LOG.error("Failed to load Stream", ex);
} catch (Exception ex) {
java.util.logging.Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
portManager.updatedPorts(Arrays.asList(portID));
}
}
Aggregations