Search in sources :

Example 1 with IncorrectRPCMethodException

use of com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException 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);
        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);
    } 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) 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)

Example 2 with IncorrectRPCMethodException

use of com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException 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 ex) {
        throw new TrafficException(ex.toString());
    }
}
Also used : 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 IncorrectRPCMethodException

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

Example 4 with IncorrectRPCMethodException

use of com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException 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 ex) {
        throw new TrafficException(ex.toString());
    }
}
Also used : 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 5 with IncorrectRPCMethodException

use of com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException in project trex-stateless-gui by cisco-system-traffic-generator.

the class ConnectionManager method handleResponse.

private String handleResponse(byte[] serverResponse, boolean writeToLog, boolean logTrace) throws UnsupportedEncodingException, IncorrectRPCMethodException, InvalidRPCResponseException {
    if (serverResponse != null) {
        String rpcResponse = new String(serverResponse, "UTF-8");
        if (logTrace) {
            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);
                LOG.error(rpcError.getError().getSpecificErr());
                LogsController.getInstance().appendText(LogType.ERROR, rpcError.getError().getSpecificErr());
                throw new IncorrectRPCMethodException(rpcError.getError().getSpecificErr() + "\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)

Aggregations

IncorrectRPCMethodException (com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException)5 InvalidRPCResponseException (com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 TrafficException (com.exalttech.trex.remote.exceptions.TrafficException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 IOException (java.io.IOException)3 PortAcquireException (com.exalttech.trex.remote.exceptions.PortAcquireException)2 Multiplier (com.exalttech.trex.remote.models.multiplier.Multiplier)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 AssignedProfile (com.exalttech.trex.ui.views.models.AssignedProfile)1