Search in sources :

Example 1 with PortAcquireException

use of com.exalttech.trex.remote.exceptions.PortAcquireException 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 2 with PortAcquireException

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

the class RPCMethods method acquireAllServerPorts.

/**
     *
     * @param portList
     * @param force
     */
public void acquireAllServerPorts(List<Port> portList, Boolean force) {
    try {
        connectionHandler.clear();
        for (Port port : portList) {
            String handler = this.acquireServerPort(port.getIndex(), force);
            connectionHandler.put(port.getIndex(), handler);
        }
    } catch (PortAcquireException ex) {
        LOG.error("------" + ex.getMessage());
    }
}
Also used : PortAcquireException(com.exalttech.trex.remote.exceptions.PortAcquireException) Port(com.exalttech.trex.ui.models.Port)

Aggregations

PortAcquireException (com.exalttech.trex.remote.exceptions.PortAcquireException)2 RPCResponse (com.cisco.trex.stateless.model.RPCResponse)1 IncorrectRPCMethodException (com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException)1 InvalidRPCResponseException (com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)1 Port (com.exalttech.trex.ui.models.Port)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1