use of com.exalttech.trex.ui.models.Port in project trex-stateless-gui by cisco-system-traffic-generator.
the class MainViewController method loadPortModel.
/**
* Build port detail table
*/
private void loadPortModel() {
PortModel model = portManager.getPortModel(getSelectedPortIndex());
portManager.updatedPorts(Arrays.asList(getSelectedPortIndex()));
Optional<Integer> optional = portManager.getOwnedPortIndexes().stream().filter(idx -> idx.equals(getSelectedPortIndex())).findFirst();
optional.ifPresent(val -> model.setIsOwned(true));
portView.loadModel(model);
}
use of com.exalttech.trex.ui.models.Port in project trex-stateless-gui by cisco-system-traffic-generator.
the class MainViewController method initialize.
@Override
public void initialize(URL url, ResourceBundle rb) {
portManager = PortsManager.getInstance();
portManager.setPortManagerHandler(this);
statsTableGenerator = new StatsTableGenerator();
leftArrow = new Image("/icons/arrow_left.png");
rightArrow = new Image("/icons/arrow_right.png");
initializeInlineComponent();
logsContainer.setDisable(false);
eventBus = TrexApp.injector.getInstance(EventBus.class);
portView.visibleProperty().bind(portViewVisibilityProperty);
statTableContainer.visibleProperty().bindBidirectional(systemInfoVisibilityProperty);
// Handle update port state event
AsyncResponseManager.getInstance().asyncEventObjectProperty().addListener((observable, oldValue, newVal) -> {
TrexEvent event = newVal;
int portId = event.getData().getAsJsonPrimitive("port_id").getAsInt();
PortModel portModel = portManager.getPortModel(portId);
switch(event.getType()) {
case PORT_RELEASED:
case PORT_ACQUIRED:
case PORT_ATTR_CHANGED:
case PORT_STARTED:
case PORT_STOPPED:
if (ConnectionManager.getInstance().isConnected()) {
Platform.runLater(() -> {
portManager.updatedPorts(Arrays.asList(portModel.getIndex()));
onPortListUpdated(true);
});
boolean isAllPortsStopped = true;
for (final Port port : portManager.getPortList()) {
if (port.getIndex() == port.getIndex()) {
continue;
}
final String portStatus = port.getStatus();
if (portStatus.equals("TX") || portStatus.equals("PAUSE")) {
isAllPortsStopped = false;
break;
}
}
}
break;
case SERVER_STOPPED:
resetApplication(true);
break;
}
});
}
use of com.exalttech.trex.ui.models.Port in project trex-stateless-gui by cisco-system-traffic-generator.
the class MainViewController method updateHeaderBtnStat.
/**
* Update header stream buttons state
*/
private void updateHeaderBtnStat() {
int portIndex = getSelectedPortIndex();
resetBtnState();
if (portIndex != -1) {
Port port = portManager.getPortList().get(portIndex);
PortState state = PortState.getPortStatus(port.getStatus());
// enable state btn btn according to owner
boolean isOwner = portManager.isCurrentUserOwner(portIndex);
switch(state) {
case STREAMS:
startStream.setDisable(!isOwner || !portManager.getPortModel(portIndex).isStreamLoaded());
break;
case TX:
pauseStream.setDisable(!isOwner);
stopStream.setDisable(!isOwner);
break;
case PAUSE:
startStream.setDisable(!isOwner);
pauseStream.setDisable(!isOwner);
stopStream.setDisable(!isOwner);
pauseStream.getStyleClass().add("pauseIconPressed");
break;
case IDLE:
AssignedProfile portProfile = assignedPortProfileMap.get(portIndex);
if (portProfile != null) {
startStream.setDisable(!(isOwner && portProfile.isProfileAssigned()));
}
break;
default:
break;
}
}
}
use of com.exalttech.trex.ui.models.Port in project trex-stateless-gui by cisco-system-traffic-generator.
the class MainViewController method updateContextMenuState.
/**
* Update right click menu enabling state
*/
private void updateContextMenuState() {
int portId = getSelectedPortIndex();
if (portId != -1) {
Port port = portManager.getPortList().get(portId);
// enable acquire option if port not owned
rightClickPortMenu.getItems().get(0).setDisable(!Util.isNullOrEmpty(port.getOwner()));
// enable release option if port owned by loggin-user
rightClickPortMenu.getItems().get(2).setDisable(!port.getOwner().equals(ConnectionManager.getInstance().getClientName()));
}
}
use of com.exalttech.trex.ui.models.Port in project trex-stateless-gui by cisco-system-traffic-generator.
the class ConnectionManager method sendPortStatusRequest.
/**
* Send request for port status
*
* @param portList
* @return
* @throws JsonProcessingException
* @throws UnsupportedEncodingException
* @throws IncorrectRPCMethodException
* @throws InvalidRPCResponseException
*/
public String sendPortStatusRequest(List<Port> portList) throws JsonProcessingException, UnsupportedEncodingException, IncorrectRPCMethodException, InvalidRPCResponseException {
List<String> addStreamCommandList = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
RPCRequest rpcRequest = new RPCRequest();
String jsonRequestString;
for (Port port : portList) {
rpcRequest.setId(Util.getRandomID(Constants.RPC_REQUEST_ID_LENGTH));
rpcRequest.setMethod(Constants.PORT_STATUS_METHOD);
rpcRequest.setParams(port.getPortParam());
jsonRequestString = mapper.writeValueAsString(rpcRequest);
jsonRequestString = Util.tuneJSONParams(jsonRequestString, port.getPortParam(), apiH);
addStreamCommandList.add(jsonRequestString);
}
String requestCommand = Util.toPrettyFormat(addStreamCommandList.toString());
LOG.info("Send port status request \n " + requestCommand);
byte[] serverResponse = getServerRPCResponse(addStreamCommandList.toString());
return handleResponse(serverResponse, false);
}
Aggregations