/** * 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; }
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; } }
/** * 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); }
private void checkAgentVersion( String monitoredHost ) { String agentVersion = this.restHelpers.get(monitoredHost).getAgentVersion(); String atsVersion = AtsVersion.getAtsVersion(); if (!atsVersion.equals(agentVersion)) { log.warn("*** ATS WARNING *** You are using ATS version " + atsVersion + " with ATS agent version " + agentVersion + " located at '" + HostUtils.getAtsAgentIpAndPort(monitoredHost) + "'. This might cause incompatibility problems!"); } }
/** * Schedule monitoring the user activity on an ATS Agent(usually used as a performance test loader). * </br>No statistics collection will be triggered until the startMonitor method is called. * * @param atsAgent the ATS Agent which runs the monitored virtual users */ @PublicAtsApi public void scheduleUserActivityMonitoring( String atsAgent ) { atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); monitoredAgents.add(atsAgent); performSetup(atsAgent); scheduleUserActivity(atsAgent); }
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); } }
/** * Schedule monitoring a JVM application * <br><b>Note:</b> You must open the tested JVM application for JMX connections by adding the following * runtime properties: * "-Dcom.sun.management.jmxremote.port=[PORT NUMBER] -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" * * @param monitoredHost the host where the monitored application is * @param jvmPort the JMX port which is used for monitoring the JVM application * @param jvmReadingTypes what kind of data to collect. Use some of the SystemMonitor.MONITOR_JVM_* constants */ @PublicAtsApi public void scheduleJvmMonitoring( String monitoredHost, String jvmPort, String[] jvmReadingTypes ) { monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost); scheduleJvmMonitoring(monitoredHost, jvmPort, "", jvmReadingTypes); }
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); } } }
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); } }
/** * It works in the same way as the <b>scheduleProcessMonitoring</b> method works with an extra parameter specifying * a name of a parent process. * </br>When one or more processes have a parent process specified, the parent process will combine * the statistics of all of its children processes. * </br>This way it is possible to get a picture of the resource usage of a whole tested product * which is running more than one actual system processes * * @param monitoredHost the host where the monitored process lives * @param parentProcess the virtual parent process * @param processPattern the pattern to use in order to find the process among all system processes. * @param processAlias the process alias to use when logging into the database * @param processReadingTypes what kind of data to collect. Use some of the SystemMonitor.MONITOR_PROCESS_* constants */ @PublicAtsApi public void scheduleChildProcessMonitoring( String monitoredHost, String parentProcess, String processPattern, String processAlias, String[] processReadingTypes ) { monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost); performSetup(monitoredHost); scheduleParentProcessMonitoring(monitoredHost, parentProcess, processPattern, processAlias, null, processReadingTypes); }
/** * Constructor when working on a remote host * * @param atsAgent the address of the remote ATS agent which will run the operation * <p> * <b>Note:</b> If you want to specify port to IPv6 address, the supported format is: <i>[IP]:PORT</i> * </p> */ @PublicAtsApi public FileSystemOperations( @Validate( name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent ) { // validate input parameters atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); new Validator().validateMethodParameters(new Object[]{ atsAgent }); this.atsAgent = atsAgent; }
/** * Constructor when working on a remote host * * @param atsAgent the address of the remote ATS agent which will run the wanted operation * <p> * <b>Note:</b> If you want to specify port to IPv6 address, the supported format is: <i>[IP]:PORT</i> * </p> */ @PublicAtsApi public SystemOperations( @Validate( name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent ) { // validate input parameters atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); new Validator().validateMethodParameters(new Object[]{ atsAgent }); this.atsAgent = atsAgent; }
/** * Schedule monitoring on a system process. * </br>No statistics collection will be triggered until the startMonitor method is called. * * @param monitoredHost the host where the monitored process lives * @param processPattern the pattern to use in order to find the process among all system processes. * <br><b>Note: </b>We match the processes by finding the given processPattern in the start command of the process. * <br>This means that it is possible to match more than one process. In this case a number is appended to the processAlias. * <br>For example if the processPattern is "my_process" matching 2 processes will give "my_process" and "my_process [2]" * @param processAlias the process alias to use when logging into the database * @param processReadingTypes what kind of data to collect. Use some of the SystemMonitor.MONITOR_PROCESS_* constants */ @PublicAtsApi public void scheduleProcessMonitoring( String monitoredHost, String processPattern, String processAlias, String[] processReadingTypes ) { monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost); performSetup(monitoredHost); scheduleProcessMonitoring(monitoredHost, null, processPattern, processAlias, null, processReadingTypes); }
/** * Constructor when working on a remote host * * @param atsAgent the remote ATS agent * @param rootKey the root key, use one of the predefined HKEY_* values */ @PublicAtsApi public RegistryOperations( @Validate( name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent, @Validate( name = "rootKey", type = ValidationType.STRING_NOT_EMPTY) String rootKey ) { atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); new Validator().validateMethodParameters(new Object[]{ atsAgent, rootKey }); this.rootKey = rootKey; this.registryOperationsImpl = getOperationsImplementationFor(atsAgent); }
/** * Retrieves static info about a machine and stores this info into the * log DB * * @param atsAgent the address of the ATS Agent running on the machine of interest * @param dbMachineName the name of the machine as it appears in the DB * @throws Exception */ @PublicAtsApi public void updateMachineInfo( @Validate( name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent, @Validate( name = "dbMachineName", type = ValidationType.STRING_NOT_EMPTY) String dbMachineName ) throws Exception { // validate input parameters atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); new Validator().validateMethodParameters(new Object[]{ atsAgent, dbMachineName }); log.info("Retrieving info about " + dbMachineName + " from " + atsAgent); MachineDescriptionOperations mm = new MachineDescriptionOperations(atsAgent); String machineDescriptionString = mm.getDescription(); log.info("Saving retrieved info about " + dbMachineName + " into the Test Explorer database"); SQLServerDbWriteAccess dbAccess = new DbAccessFactory().getNewDbWriteAccessObject(); dbAccess.updateMachineInfo(dbMachineName, machineDescriptionString, true); log.info("Successfully updated the info about " + dbMachineName); } }
/** * Schedule a monitor and pass some custom parameters to it. * <br>No statistics collection will be triggered until the startMonitor method is called. * * @param monitoredHost the host to monitor * @param readingType what kind of data to collect. You call a custom monitor here or some of the SystemMonitor.MONITORTYPE_* constants * @param readingParameters the parameters this monitor knows how to work with */ @PublicAtsApi public void scheduleMonitoring( String monitoredHost, String readingType, Map<String, String> readingParameters ) { monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost); performSetup(monitoredHost); // create JsonMonitoringUtils.constructXYZ() values Object[] values = new Object[]{ null, readingType, readingParameters }; String errorMsg = performMonitoringOperation(monitoredHost, RestHelper.BASE_MONITORING_REST_SERVICE_URI, RestHelper.SCHEDULE_MONITORING_RELATIVE_URI, "There were errors while scheduling monitoring", values); if (!StringUtils.isNullOrEmpty(errorMsg)) { throw new MonitoringException(errorMsg); } }
/** * Constructor for running process on a remote host * * @param atsAgent the address of the remote ATS agent which will run the process * @param command the command to run * * <p> * <b>Note:</b> If you want to specify port to IPv6 address, the supported format is: <i>[IP]:PORT</i> * </p> */ @PublicAtsApi public ProcessExecutor( @Validate( name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent, @Validate( name = "command", type = ValidationType.STRING_NOT_EMPTY) String command ) { // validate input parameters atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); new Validator().validateMethodParameters(new Object[]{ atsAgent, command }); this.processExecutor = getOperationsImplementationFor(atsAgent, command); }
String[] systemReadingTypes ) { monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost); performSetup(monitoredHost);
/** * Constructor for running process on a remote host * * @param atsAgent the address of the remote ATS agent which will run the process * @param command the command to run * @param commandArguments command arguments * * <p> * <b>Note:</b> If you want to specify port to IPv6 address, the supported format is: <i>[IP]:PORT</i> * </p> */ @PublicAtsApi public ProcessExecutor( @Validate( name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent, @Validate( name = "command", type = ValidationType.STRING_NOT_EMPTY) String command, @Validate( name = "commandArguments", type = ValidationType.NONE) String[] commandArguments ) { // validate input parameters atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); new Validator().validateMethodParameters(new Object[]{ atsAgent, command, commandArguments }); this.processExecutor = getOperationsImplementationFor(atsAgent, command, commandArguments); }
/** * Killing external process(such not started by us) on a remote host. <br/> * The process is found by a token which is contained in the start command. * No regex supported. * * @param atsAgent the address of the remote ATS agent which will run the kill command * @param startCommandSnippet the token to search for in the process start command. * The minimum allowed length is 2 characters * @return the number of killed processes */ @PublicAtsApi public static int killExternalProcess( @Validate( name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent, @Validate( name = "startCommandSnippet", type = ValidationType.STRING_NOT_EMPTY) String startCommandSnippet ) { // validate input parameters atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent); new Validator().validateMethodParameters(new Object[]{ atsAgent, startCommandSnippet }); try { return new InternalProcessOperations(atsAgent).killExternalProcess(startCommandSnippet); } catch (AgentException e) { throw new ProcessExecutorException(e); } }