Search in sources :

Example 1 with InvalidRPCResponseException

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();
    }
}
Also used : RPCError(com.exalttech.trex.remote.models.common.RPCError) IOException(java.io.IOException) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)

Example 2 with 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());
    }
}
Also used : SizeLimitExceededException(javax.naming.SizeLimitExceededException) Multiplier(com.exalttech.trex.remote.models.multiplier.Multiplier) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException) TrafficException(com.exalttech.trex.remote.exceptions.TrafficException)

Example 3 with InvalidRPCResponseException

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());
    }
}
Also used : SizeLimitExceededException(javax.naming.SizeLimitExceededException) Multiplier(com.exalttech.trex.remote.models.multiplier.Multiplier) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException) TrafficException(com.exalttech.trex.remote.exceptions.TrafficException)

Example 4 with InvalidRPCResponseException

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());
    }
}
Also used : SizeLimitExceededException(javax.naming.SizeLimitExceededException) PortAcquireException(com.exalttech.trex.remote.exceptions.PortAcquireException) RPCResponse(com.cisco.trex.stateless.model.RPCResponse) IOException(java.io.IOException) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)

Example 5 with InvalidRPCResponseException

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));
    }
}
Also used : AssignedProfile(com.exalttech.trex.ui.views.models.AssignedProfile) PortModel(com.exalttech.trex.ui.models.PortModel) IOException(java.io.IOException) StreamValidation(com.exalttech.trex.remote.models.validate.StreamValidation) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException) TrafficException(com.exalttech.trex.remote.exceptions.TrafficException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) PortAcquireException(com.exalttech.trex.remote.exceptions.PortAcquireException) IOException(java.io.IOException)

Aggregations

IncorrectRPCMethodException (com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException)5 InvalidRPCResponseException (com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)5 TrafficException (com.exalttech.trex.remote.exceptions.TrafficException)3 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SizeLimitExceededException (javax.naming.SizeLimitExceededException)3 PortAcquireException (com.exalttech.trex.remote.exceptions.PortAcquireException)2 Multiplier (com.exalttech.trex.remote.models.multiplier.Multiplier)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 RPCResponse (com.cisco.trex.stateless.model.RPCResponse)1 RPCError (com.exalttech.trex.remote.models.common.RPCError)1 StreamValidation (com.exalttech.trex.remote.models.validate.StreamValidation)1 PortModel (com.exalttech.trex.ui.models.PortModel)1 AssignedProfile (com.exalttech.trex.ui.views.models.AssignedProfile)1