Skip to content

Commit

Permalink
feat(robot-extension): handle management of extension port in the GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucashimpens committed Feb 14, 2025
1 parent 4d84741 commit 77818ff
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ public AnswerList<RobotExecutor> readByVariousByCriteria(List<String> robot, Str
public Answer create(RobotExecutor object) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO robotexecutor (`robot`, `executor`, `isactive`, `rank`, `host`, `port`, `HostUser`, `HostPassword`, `deviceudid`, `devicename`, `deviceport`, `isdevicelockunlock`, `ExecutorProxyServiceHost`, `ExecutorProxyServicePort`, `ExecutorBrowserProxyHost`, `ExecutorBrowserProxyPort`, `executorproxytype`, `description`, `usrcreated`) ");
query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
query.append("INSERT INTO robotexecutor (`robot`, `executor`, `isactive`, `rank`, `host`, `port`, `HostUser`, `HostPassword`, `deviceudid`, `devicename`, `deviceport`, `isdevicelockunlock`, `ExecutorProxyServiceHost`, `ExecutorProxyServicePort`, `ExecutorBrowserProxyHost`, `ExecutorBrowserProxyPort`, `ExecutorExtensionPort`, `executorproxytype`, `description`, `usrcreated`) ");
query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

// Debug message on SQL.
if (LOG.isDebugEnabled()) {
Expand Down Expand Up @@ -309,6 +309,7 @@ public Answer create(RobotExecutor object) {
} else {
preStat.setNull(i++, Types.INTEGER);
}
preStat.setInt(i++, object.getExecutorExtensionPort());
preStat.setString(i++, object.getExecutorProxyType());
preStat.setString(i++, object.getDescription());
preStat.setString(i++, object.getUsrCreated());
Expand Down Expand Up @@ -367,7 +368,7 @@ public Answer delete(RobotExecutor object) {
@Override
public Answer update(String robot, String executor, RobotExecutor object) {
MessageEvent msg = null;
final String query = "UPDATE robotexecutor SET `robot` = ?, `executor` = ?, description = ?, isactive = ?, `rank` = ?, `host` = ?, `port` = ?, `HostUser` = ?, `HostPassword` = ?, `deviceudid` = ?, `devicename` = ?, `deviceport` = ?, `isdevicelockunlock` = ?, `ExecutorProxyServiceHost` = ?, `ExecutorProxyServicePort` = ?, `ExecutorBrowserProxyHost` = ?, `ExecutorBrowserProxyPort` = ?, `executorproxytype` = ?, "
final String query = "UPDATE robotexecutor SET `robot` = ?, `executor` = ?, description = ?, isactive = ?, `rank` = ?, `host` = ?, `port` = ?, `HostUser` = ?, `HostPassword` = ?, `deviceudid` = ?, `devicename` = ?, `deviceport` = ?, `isdevicelockunlock` = ?, `ExecutorProxyServiceHost` = ?, `ExecutorProxyServicePort` = ?, `ExecutorBrowserProxyHost` = ?, `ExecutorBrowserProxyPort` = ?, `ExecutorExtensionPort` = ?, `executorproxytype` = ?, "
+ "dateModif = NOW(), usrModif= ? WHERE `robot` = ? and `executor` = ?";

// Debug message on SQL.
Expand Down Expand Up @@ -409,6 +410,7 @@ public Answer update(String robot, String executor, RobotExecutor object) {
} else {
preStat.setNull(i++, Types.INTEGER);
}
preStat.setInt(i++, object.getExecutorExtensionPort());
preStat.setString(i++, object.getExecutorProxyType());
preStat.setString(i++, object.getUsrModif());
preStat.setString(i++, robot);
Expand Down Expand Up @@ -476,6 +478,7 @@ public RobotExecutor loadFromResultSet(ResultSet rs) throws SQLException {
Integer executorProxyServicePort = rs.getInt("rbe.ExecutorProxyServicePort");
String executorBrowserProxyHost = rs.getString("rbe.ExecutorBrowserProxyHost");
Integer executorBrowserProxyPort = rs.getInt("rbe.ExecutorBrowserProxyPort");
Integer executorExtensionPort = rs.getInt("rbe.ExecutorExtensionPort");
String executorProxyType = rs.getString("rbe.executorproxytype");
if(deviceport == 0) {
deviceport=null;
Expand All @@ -489,7 +492,7 @@ public RobotExecutor loadFromResultSet(ResultSet rs) throws SQLException {

//TODO remove when working in test with mockito and autowired
factoryRobotExecutor = new FactoryRobotExecutor();
return factoryRobotExecutor.create(id, robot, executor, isActive, rank, host, port, hostUser, hostPassword, executorExtensionProxyPort, deviceudid, devicename, deviceport, isDevicelockunlock, executorProxyServiceHost, executorProxyServicePort, executorBrowserProxyHost, executorBrowserProxyPort, executorProxyType, description, usrCreated, dateCreated, usrModif, dateModif);
return factoryRobotExecutor.create(id, robot, executor, isActive, rank, host, port, hostUser, hostPassword, executorExtensionProxyPort, deviceudid, devicename, deviceport, isDevicelockunlock, executorProxyServiceHost, executorProxyServicePort, executorBrowserProxyHost, executorBrowserProxyPort, executorExtensionPort, executorProxyType, description, usrCreated, dateCreated, usrModif, dateModif);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class RobotExecutor {
private Integer executorProxyServicePort;
private String executorBrowserProxyHost;
private Integer executorBrowserProxyPort;
private Integer executorExtensionPort;
private String UsrCreated;
private Timestamp DateCreated;
private String UsrModif;
Expand Down Expand Up @@ -247,6 +248,14 @@ public void setExecutorBrowserProxyPort(Integer executorBrowserProxyPort) {
this.executorBrowserProxyPort = executorBrowserProxyPort;
}

public Integer getExecutorExtensionPort() {
return executorExtensionPort;
}

public void setExecutorExtensionPort(Integer executorExtensionPort) {
this.executorExtensionPort = executorExtensionPort;
}

public String getExecutorProxyType() {
return executorProxyType;
}
Expand Down Expand Up @@ -377,6 +386,9 @@ public boolean equals(Object obj) {
if ((this.executorBrowserProxyPort == null) ? (other.executorBrowserProxyPort != null) : !this.executorBrowserProxyPort.equals(other.executorBrowserProxyPort)) {
return false;
}
if ((this.executorExtensionPort == null) ? (other.executorExtensionPort != null) : !this.executorExtensionPort.equals(other.executorExtensionPort)) {
return false;
}
return true;
}

Expand All @@ -403,6 +415,7 @@ public JSONObject toJson(boolean secured) {
result.put("executorProxyServicePort", this.getExecutorProxyServicePort());
result.put("executorBrowserProxyHost", this.getExecutorBrowserProxyHost());
result.put("executorBrowserProxyPort", this.getExecutorBrowserProxyPort());
result.put("executorExtensionPort", this.getExecutorExtensionPort());
result.put("executorProxyType", this.getExecutorProxyType());
result.put("executor", this.getExecutor());
result.put("host", this.getHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public interface IFactoryRobotExecutor {
* @param executorProxyServicePort
* @param executorBrowserProxyHost
* @param executorBrowserProxyPort
* @param executorExtensionPort
* @param deviceUdid
* @param UsrCreated
* @param executorProxyType
Expand All @@ -57,6 +58,6 @@ public interface IFactoryRobotExecutor {
*/
RobotExecutor create(Integer ID, String robot, String executor, boolean isActive,
Integer rank, String host, String port, String hostUser, String hostPassword, Integer executorExtensionProxyPort, String deviceUdid,
String deviceName, Integer devicePort, boolean isDeviceLockUnlock, String executorProxyServiceHost, Integer executorProxyServicePort, String executorBrowserProxyHost, Integer executorBrowserProxyPort, String executorProxyType,
String deviceName, Integer devicePort, boolean isDeviceLockUnlock, String executorProxyServiceHost, Integer executorProxyServicePort, String executorBrowserProxyHost, Integer executorBrowserProxyPort, Integer executorExtensionPort, String executorProxyType,
String description, String UsrCreated, Timestamp DateCreated, String UsrModif, Timestamp DateModif);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class FactoryRobotExecutor implements IFactoryRobotExecutor {

@Override
public RobotExecutor create(Integer ID, String robot, String executor, boolean isActive, Integer rank, String host, String port, String hostUser, String hostPassword,
Integer executorExtensionProxyPort, String deviceUdid, String deviceName, Integer devicePort, boolean isDeviceLockUnlock, String executorProxyServiceHost, Integer executorProxyServicePort, String executorBrowserProxyHost, Integer executorBrowserProxyPort, String executorProxyType, String description,
Integer executorExtensionProxyPort, String deviceUdid, String deviceName, Integer devicePort, boolean isDeviceLockUnlock, String executorProxyServiceHost, Integer executorProxyServicePort, String executorBrowserProxyHost, Integer executorBrowserProxyPort, Integer executorExtensionPort, String executorProxyType, String description,
String UsrCreated, Timestamp DateCreated, String UsrModif, Timestamp DateModif) {
RobotExecutor newRobot = new RobotExecutor();
newRobot.setID(ID);
Expand All @@ -53,6 +53,7 @@ public RobotExecutor create(Integer ID, String robot, String executor, boolean i
newRobot.setExecutorBrowserProxyHost(executorBrowserProxyHost);
newRobot.setExecutorProxyType(executorProxyType);
newRobot.setExecutorBrowserProxyPort(executorBrowserProxyPort);
newRobot.setExecutorExtensionPort(executorExtensionPort);
newRobot.setDescription(description);
newRobot.setUsrCreated(UsrCreated);
newRobot.setDateCreated(DateCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ public ArrayList<String> getSqlDocumentation() {
b.append(",('robotexecutor','executorBrowserProxyHost','','fa','میزبان پروکسی مرورگر', 'میزبانی که برای اتصال به سرویس پروکسی به مرورگر داده می شود. اگر خالی باشد، میزبان سرویس ربات پروکسی استفاده خواهد شد.',NULL)");
b.append(",('robotexecutor','executorBrowserProxyPort','','en','Browser Proxy Port','Port that will be used by the browser in order to connect to the proxy service. If 0, port will be determined randomly.',NULL)");
b.append(",('robotexecutor','executorBrowserProxyPort','','fa','درگاه پروکسی مرورگر','درگاهی که مرورگر برای اتصال به سرویس پروکسی از آن استفاده می کند. اگر 0 باشد، پورت به صورت تصادفی تعیین می شود.',NULL)");
b.append(",('robotexecutor','executorExtensionPort','','en','Extension Port', 'Port that will be used in order to connect to the Cerberus Robot Extension. If 0, port will be the node port.',NULL)");
b.append(",('robotexecutor','executorExtensionPort','','fr','Port de l\\'extension ', 'Port qui sera utilisé pour accéder à l\\'extension Cerberus. Si 0, le port sera celui du noeud.',NULL)");
b.append(",('robotexecutor','executorProxyType','','fr','Type de Proxy', 'Activer / Désactiver l\\'utilisation du proxy. L\\'utilisation du proxy permet de collecter des statistique et de controler le trafic réseau engendré par le navigateur.',NULL)");
b.append(",('robotexecutor','executorProxyType','','en','Proxy Type', 'Activate / Unactivate the usage of proxy service. Proxy service will allow to collect statistics and control the network traffic generated by the browser.',NULL)");
b.append(",('robotexecutor','executorProxyType','','fa','فعالسازی پروکسی', 'فعالسازی / غیرفعالسازی استفاده از پروکسی. سرویس پروکسی امکان جمع آوری آمار و کنترل ترافیک شبکه تولید شده توسط مرورگر را فراهم می کند.',NULL)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Session {
private String nodeHost;
private String nodePort;

private Integer executorExtensionPort; //Port where the cerberus robot extension is available on the node host
private Integer executorExtensionProxyPort; // if >0, we use the proxy on host:proxyPort in order to connect to sikuli API (host is the host of the robot - ie the proxy should run on the same server as the robot server).

private boolean started;
Expand Down Expand Up @@ -99,6 +100,14 @@ public void setExecutorExtensionProxyPort(Integer executorExtensionProxyPort) {
this.executorExtensionProxyPort = executorExtensionProxyPort;
}

public Integer getExecutorExtensionPort() {
return executorExtensionPort;
}

public void setExecutorExtensionPort(Integer executorExtensionPort) {
this.executorExtensionPort = executorExtensionPort;
}

public Integer getCerberus_selenium_highlightElement_default() {
return cerberus_selenium_highlightElement_default;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,11 @@ public void startServer(TestCaseExecution execution) throws CerberusException {
if (execution.getRobotExecutorObj() != null) {
LOG.debug("Session node proxy set : {}", execution.getRobotExecutorObj().getExecutorExtensionProxyPort());
session.setExecutorExtensionProxyPort(execution.getRobotExecutorObj().getExecutorExtensionProxyPort());
LOG.debug("Extension port set: {}", execution.getRobotExecutorObj().getExecutorExtensionPort());
session.setExecutorExtensionPort(execution.getRobotExecutorObj().getExecutorExtensionPort());
} else {
session.setExecutorExtensionProxyPort(0);
session.setExecutorExtensionPort(0);
}
session.setConsoleLogs(new JSONArray());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,18 @@ public void executeNextInQueue(boolean forceExecution) throws CerberusException
// Application require a robot so we can get the list of executors.
if (StringUtil.isEmptyOrNull(robot)) {
robotExelist = new ArrayList<>();
robotExelist.add(factoryRobotExecutor.create(0, "", "", true, 1, exe.getQueueRobotHost(), exe.getQueueRobotPort(), "", "", 0, "", "", null, false, "", 0, "", 0, "", "", "", null, "", null));
robotExelist.add(factoryRobotExecutor.create(0, "", "", true, 1, exe.getQueueRobotHost(), exe.getQueueRobotPort(), "", "", 0, "", "", null, false, "", 0, "", 0, 0,"", "", "", null, "", null));
} else {
robotExelist = robot_executor.get(robot);
if (robotExelist == null || robotExelist.size() < 1) {
if (robotExelist == null || robotExelist.isEmpty()) {
robotExelist = new ArrayList<>();
robotExelist.add(factoryRobotExecutor.create(0, "", "", true, 1, "", "", "", "", 0, "", "", null, false, "", 0, "", 0, "", "", "", null, "", null));
robotExelist.add(factoryRobotExecutor.create(0, "", "", true, 1, "", "", "", "", 0, "", "", null, false, "", 0, "", 0, 0, "", "", "", null, "", null));
}
}
} else {
// Application does not require a robot so we create a fake one with empty data.
robotExelist = new ArrayList<>();
robotExelist.add(factoryRobotExecutor.create(0, "", "", true, 1, "", "", "", "", 0, "", "", null, false, "", 0, "", 0, "", "", "", null, "", null));
robotExelist.add(factoryRobotExecutor.create(0, "", "", true, 1, "", "", "", "", 0, "", "", null, false, "", 0, "", 0, 0,"", "", "", null, "", null));
}

// Looping over every potential executor on the corresponding robot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class FilemanagementService implements IFilemanagementService {
public static final String FILEMANAGEMENT_UPLOADROBOTFILE = "upload";
public static final String FILEMANAGEMENT_GETROBOTFILE = "download";

private static final String SIKULI_FILEMANAGEMENT_PATH = "/extra/ExecuteFilemanagementAction";

private JSONObject generatePostParameters(String action, int nbFiles, String filename, String option, String contentBase64) throws JSONException, IOException, MalformedURLException, MimeTypeException {
JSONObject result = new JSONObject();

Expand Down Expand Up @@ -96,8 +98,7 @@ public AnswerItem<JSONObject> doFilemanagementAction(Session session, String act

StringBuilder response = new StringBuilder();
URL url;
String host = StringUtil.cleanHostURL(session.getNodeHost());
String urlToConnect = host + ":" + session.getNodePort() + "/extra/ExecuteFilemanagementAction";
String urlToConnect = generateSikuliUrlOnNode(session, SIKULI_FILEMANAGEMENT_PATH);
try {
/**
* Connect to ExecuteSikuliAction Servlet Through SeleniumServer
Expand Down Expand Up @@ -293,4 +294,9 @@ public AnswerItem<JSONObject> doFilemanagementActionGetRobotFile(Session session
return ans;
}

private String generateSikuliUrlOnNode(Session session, String path) {
int port = session.getExecutorExtensionPort() != 0 ? session.getExecutorExtensionPort() : Integer.parseInt(session.getNodePort());
return String.format("%s:%d%s", StringUtil.cleanHostURL("127.0.0.1"), port, path);
}

}
Loading

0 comments on commit 77818ff

Please sign in to comment.