/** * Returns the ATS agent addresses which contains its IP and port. * If a port is not passed, we will append the default one. * * @param atsAgents a list of agents * @return */ public static String[] getAtsAgentsIpAndPort( String[] atsAgents ) { if (atsAgents == null) { return null; } String[] fixedAtsAgents = new String[atsAgents.length]; for (int i = 0; i < atsAgents.length; i++) { fixedAtsAgents[i] = getAtsAgentIpAndPort(atsAgents[i]); } return fixedAtsAgents; }
private String getHostsList() { StringBuilder hostsLists = new StringBuilder(); for (String host : atsAgents) { if (host.startsWith(HostUtils.LOCAL_HOST_IPv4)) { host = host.replace(HostUtils.LOCAL_HOST_IPv4, HostUtils.getLocalHostIP()); } else if (host.startsWith(HostUtils.LOCAL_HOST_NAME)) { host = host.replace(HostUtils.LOCAL_HOST_NAME, HostUtils.getLocalHostIP()); } else if (host.startsWith(HostUtils.LOCAL_HOST_IPv6)) { host = host.replace(HostUtils.LOCAL_HOST_IPv6, HostUtils.getLocalHostIP()); } hostsLists.append( (hostsLists.length() > 0 ? ", " : "") + host); } return hostsLists.toString(); } }
/** * @param atsAgent * @return whether the agent is located on the local host */ public static boolean isLocalAtsAgent( String atsAgent ) { if (!StringUtils.isNullOrEmpty(atsAgent)) { String[] tokens = HostUtils.splitAddressHostAndPort(atsAgent); if (tokens.length > 0) { return HostUtils.isLocalHost(tokens[0]); } } return true; }
private IProcessTalker getOperationsImplementationFor( String atsAgent, String command ) { atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); if (HostUtils.isLocalAtsAgent(atsAgent)) { return new LocalProcessTalker(command); } else { return new RemoteProcessTalker(atsAgent, command); } } }
public void copyDirectoryTo( String fromDirName, String toMachine, String toDirName, boolean isRecursive, boolean failOnError ) { try { InternalFileSystemOperations toRemoteFSOperations = new InternalFileSystemOperations(toMachine); int port = toRemoteFSOperations.openFileTransferSocket(); remoteFileSystemOperations.sendDirectoryTo(fromDirName, toDirName, HostUtils.splitAddressHostAndPort(HostUtils.getAtsAgentIpAndPort(toMachine))[0], port, isRecursive, failOnError); toRemoteFSOperations.waitForFileTransferCompletion(port); } catch (Exception e) { String message = new StringBuilder().append("Unable to copy directory ") .append(fromDirName) .append(" from ") .append(this.atsAgent) .append(" to ") .append(toDirName) .append(" on ") .append(toMachine) .toString(); throw new FileSystemOperationException(message, e); } }
remoteAtsAgent = getAtsAgentIpAndPort(remoteAtsAgent); String[] atsAgentTokens = splitAddressHostAndPort(remoteAtsAgent); Socket socket = null; try { } else { if (tmpPublicAddress.isLoopbackAddress()) { List<InetAddress> ipList = getIpAddressesList(true); if (ipList.size() > 0) { tmpPublicAddress = ipList.get(0); List<InetAddress> ipList = getIpAddressesList(true); if (ipList.size() > 0) { localHostPublicAddress = ipList.get(0);
@Override public void copyDirectory( String fromDirName, String toDirName, boolean isRecursive, boolean failOnError ) { try { int port = remoteFileSystemOperations.openFileTransferSocket(); localFileSystemOperations.sendDirectoryTo(fromDirName, toDirName, HostUtils.splitAddressHostAndPort(atsAgent)[0], port, isRecursive, failOnError); remoteFileSystemOperations.waitForFileTransferCompletion(port); } catch (Exception e) { String message = new StringBuilder().append("Unable to copy directory ") .append(fromDirName) .append(" to ") .append(toDirName) .append(" on host ") .append(this.atsAgent) .toString(); throw new FileSystemOperationException(message, e); } }
public void setHost( String host ) { this.host = host; XmlUtils.setAttribute(applicationNode, AtsProjectConfiguration.NODE_APPLICATION_PROPERTY_HOST, this.host); this.isLocalHost = HostUtils.isLocalHost(host); }
&& stripIPv6InterfaceId(compressIPv6Address(host)).equalsIgnoreCase(stripIPv6InterfaceId(compressIPv6Address(hostAddress)))) { localHosts.add(host); return true;
private ActionQueue( Set<String> atsAgents, String name, int sequence ) { queuedActions = new ArrayList<ActionRequest>(); inQueueMode = false; if (atsAgents == null) { atsAgents = new HashSet<String>(); } // add default port in case none is not provided by the user String[] atsAgentsArray = HostUtils.getAtsAgentsIpAndPort(new ArrayList<String>(atsAgents).toArray(new String[atsAgents.size()])); this.atsAgents = new HashSet<String>(Arrays.asList(atsAgentsArray)); this.name = name; this.sequence = sequence; }
public void copyFileTo( String fromFile, String toMachine, String toFile, boolean failOnError ) { try { Integer copyFileStartPort = getCopyFilePortProperty(ActionLibraryConfigurator.getInstance() .getCopyFileStartPort()); Integer copyFileEndPort = getCopyFilePortProperty(ActionLibraryConfigurator.getInstance() .getCopyFileEndPort()); InternalFileSystemOperations toRemoteFSOperations = new InternalFileSystemOperations(toMachine); if (copyFileStartPort != null && copyFileStartPort > 0 && copyFileEndPort != null && copyFileEndPort > 0) { toRemoteFSOperations.setCopyFilePortRange(copyFileStartPort, copyFileEndPort); } int port = toRemoteFSOperations.openFileTransferSocket(); this.remoteFileSystemOperations.sendFileTo(fromFile, toFile, HostUtils.splitAddressHostAndPort(HostUtils.getAtsAgentIpAndPort(toMachine) /* append port */ )[0], port, failOnError); toRemoteFSOperations.waitForFileTransferCompletion(port); } catch (Exception e) { String message = new StringBuilder().append("Unable to copy file ") .append(fromFile) .append(" from ") .append(this.atsAgent) .append(" to file ") .append(toFile) .append(" on ") .append(toMachine) .toString(); throw new FileSystemOperationException(message, e); } }
private IFileSystemSnapshot getOperationsImplementationFor( String atsAgent, String name, SnapshotConfiguration configuration ) { atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); if (HostUtils.isLocalAtsAgent(atsAgent)) { return new LocalFileSystemSnapshot(name, configuration); } else { return new RemoteFileSystemSnapshot(atsAgent, name, configuration); } }
/** * Returns the ATS agent address which contains its IP and port. * If a port is not passed, we will append the default one. * * @param atsAgent the agent * @return */ public static String getAtsAgentIpAndPort( String atsAgent ) { if (atsAgent == null) { return null; } String[] tokens = splitAddressHostAndPort(atsAgent); if (tokens.length != 1 // port number detected || StringUtils.isNullOrEmpty(tokens[0])) { // null or empty IP, do not touch return atsAgent; } else { // IP/Hostname provided, but no PORT, so use the default one if (!atsAgent.startsWith("[") && tokens[0].split(":").length > 1) { // assume it is IPv6 return "[" + atsAgent + "]:" + AtsSystemProperties.getAgentDefaultPort(); } return atsAgent + ":" + AtsSystemProperties.getAgentDefaultPort(); } }
public MobileDriver( String deviceName, String platformVersion, String udid, String host, int port ) { this.deviceName = deviceName; this.platformVersion = platformVersion; this.port = port; this.udid = udid; if (host == null) { this.host = HostUtils.LOCAL_HOST_IPv4; } else { this.host = host; this.isWorkingRemotely = !HostUtils.isLocalHost(host); } this.isAndroidAgent = deviceName.toLowerCase().contains("android"); this.mobileDeviceUtils = new MobileDeviceUtils(this); }
/** * Constructor providing the ATS agents (used as loaders) to run the test steps from * @param atsAgents array of used ATS agents * loaders */ @PublicAtsApi public LoadClient( String[] atsAgents ) { if (atsAgents == null) { atsAgents = new String[0]; } // add default port in case none is not provided by the user atsAgents = HostUtils.getAtsAgentsIpAndPort(atsAgents); this.loaderAddresses = new HashSet<String>(Arrays.asList(atsAgents)); this.loaderDataConfig = new LoaderDataConfig(); }
protected AbstractAgentClient( String atsAgent, String component ) { this.log = Logger.getLogger(this.getClass()); if (LOCAL_JVM.equals(atsAgent)) { // we will work in the local JVM, so no running external instance of ATS Agent this.atsAgent = atsAgent; } else { // add default port in case none is not provided by the user this.atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); } this.component = component; } }
/** * Log all jars found in the classpath. * If a jar is found more than once, then we list these one after another */ public void logClassPath() { log.info("Classpath of JVM on " + HostUtils.getLocalHostIP() + ": \n" + getClassPathDescription()); }
HostUtils.splitAddressHostAndPort(atsAgent)[0], port, failOnError); remoteFileSystemOperations.waitForFileTransferCompletion(port);
this.host = XmlUtils.getMandatoryAttribute(applicationNode, AtsProjectConfiguration.NODE_APPLICATION_PROPERTY_HOST); this.isLocalHost = HostUtils.isLocalHost(host);
/** * Add Agent loader to the list of hosts where the test steps will be executed * @param agentLoader address of the remote ATS agent */ @PublicAtsApi public void addLoaderHost( String agentLoader ) { // add default port in case none is not provided by the user agentLoader = HostUtils.getAtsAgentIpAndPort(agentLoader); loaderAddresses.add(agentLoader); }