Search in sources :

Example 1 with RPCResponse

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());
    }
}
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 RPCResponse

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();
}
Also used : RPCResponse(com.cisco.trex.stateless.model.RPCResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

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