@Override public JmxServerConnectionWrapper createConnection(final InetAddress ipAddress, final Map<String, String> propertiesMap) throws JmxServerConnectionException { JmxConnectionConfig config = JmxConnectionConfigBuilder.buildFrom(ipAddress, propertiesMap).build(); return createConnection(config); }
public static JmxConnectionConfigBuilder buildFrom(InetAddress ipAddress, Map<String, String> properties) { final JmxConnectionConfigBuilder builder = new JmxConnectionConfigBuilder(); builder.withIpAddress(ipAddress); builder.withSunCacao(ParameterMap.getKeyedBoolean(properties, "sunCacao", false)); builder.withUsername(properties.get("username")); builder.withPassword(properties.get("password")); builder.withFactory(properties.getOrDefault("factory", "STANDARD")); // Legacy if (properties.get("url") == null) { String url = createLegacyUrl(ipAddress, properties); builder.withUrl(url); builder.withPort(properties.getOrDefault("port", "1099")); } else { builder.withUrl(properties.get("url")); } return builder; }
@Override public JmxDatacollectionConfig execute() throws TaskRunException { final JmxConnectionConfig connectionConfig = new JmxConnectionConfigBuilder() .withUrl(config.getConnection()) .withUsername(config.getUser()) .withPassword(config.getPassword()) .build(); try (JmxServerConnectionWrapper connector = new DefaultJmxConnector().createConnection(connectionConfig)) { final JmxDatacollectionConfiggenerator jmxConfigGenerator = new JmxDatacollectionConfiggenerator(new Slf4jLogAdapter(JmxDatacollectionConfiggenerator.class)); final JmxDatacollectionConfig generatedJmxConfigModel = jmxConfigGenerator.generateJmxConfigModel( connector.getMBeanServerConnection(), "anyservice", !config.isSkipDefaultVM(), config.isSkipNonNumber(), JmxHelper.loadInternalDictionary()); applyFilters(generatedJmxConfigModel); return generatedJmxConfigModel; } catch (IOException | MBeanServerQueryException | JMException | JmxServerConnectionException e) { if (e instanceof UnknownHostException || e.getCause() instanceof UnknownHostException) { throw new TaskRunException(String.format("Unknown host: %s", config.getConnection()), e); } if (e instanceof MalformedURLException || e.getCause() instanceof MalformedURLException) { throw new TaskRunException( String.format("Cannot create valid JMX Connection URL. Connection: '%s'", config.getConnection()), e); } throw new TaskRunException("Error while retrieving MBeans from server.", e); } }
public static JmxConnectionConfigBuilder buildFrom(String ipAddress, Map<String, String> properties) { InetAddress inetAddress = InetAddressUtils.getInetAddress(ipAddress); return buildFrom(inetAddress, properties); }
@Override public JmxDatacollectionConfig execute() throws JobManager.TaskRunException { final JmxConnectionConfig connectionConfig = new JmxConnectionConfigBuilder() .withUrl(config.getConnection()) .withUsername(config.getUser()) .withPassword(config.getPassword()) .build(); try (JmxServerConnectionWrapper connector = new DefaultJmxConnector().createConnection(connectionConfig)) { final JmxDatacollectionConfiggenerator jmxConfigGenerator = new JmxDatacollectionConfiggenerator(new Slf4jLogAdapter(JmxDatacollectionConfiggenerator.class)); final JmxDatacollectionConfig generatedJmxConfigModel = jmxConfigGenerator.generateJmxConfigModel( connector.getMBeanServerConnection(), "anyservice", !config.isSkipDefaultVM(), config.isSkipNonNumber(), JmxHelper.loadInternalDictionary()); applyFilters(generatedJmxConfigModel); return generatedJmxConfigModel; } catch (IOException | MBeanServerQueryException | JMException | JmxServerConnectionException e) { if (e instanceof UnknownHostException || e.getCause() instanceof UnknownHostException) { throw new JobManager.TaskRunException(String.format("Unknown host: %s", config.getConnection()), e); } if (e instanceof MalformedURLException || e.getCause() instanceof MalformedURLException) { throw new JobManager.TaskRunException( String.format("Cannot create valid JMX Connection URL. Connection: '%s'", config.getConnection()), e); } throw new JobManager.TaskRunException("Error while retrieving MBeans from server.", e); } }
public static JmxConnectionConfigBuilder buildFrom(String ipAddress, Map<String, String> properties) { InetAddress inetAddress = InetAddressUtils.getInetAddress(ipAddress); return buildFrom(inetAddress, properties); }
@Override public JmxServerConnectionWrapper createConnection(final InetAddress ipAddress, final Map<String, String> propertiesMap) throws JmxServerConnectionException { JmxConnectionConfig config = JmxConnectionConfigBuilder.buildFrom(ipAddress, propertiesMap).build(); return createConnection(config); }
public static JmxConnectionConfigBuilder buildFrom(InetAddress ipAddress, Map<String, String> properties) { final JmxConnectionConfigBuilder builder = new JmxConnectionConfigBuilder(); builder.withIpAddress(ipAddress); builder.withSunCacao(ParameterMap.getKeyedBoolean(properties, "sunCacao", false)); builder.withUsername(properties.get("username")); builder.withPassword(properties.get("password")); builder.withFactory(properties.getOrDefault("factory", "STANDARD")); // Legacy if (properties.get("url") == null) { String url = createLegacyUrl(ipAddress, properties); builder.withUrl(url); builder.withPort(properties.getOrDefault("port", "1099")); } else { builder.withUrl(properties.get("url")); } return builder; }
public static JmxServerConnectionWrapper getMBeanServerConnection(Map<String,String> propertiesMap, InetAddress address) throws IOException { final long timeout = DEFAULT_TIMEOUT; propertiesMap.putIfAbsent("factory", "STANDARD"); propertiesMap.putIfAbsent("port", "1099"); propertiesMap.putIfAbsent("protocol", "rmi"); propertiesMap.putIfAbsent("urlPath", "/jmxrmi"); propertiesMap.putIfAbsent("timeout", Long.toString(timeout)); final Callable<JmxServerConnectionWrapper> task = new Callable<JmxServerConnectionWrapper>() { @Override public JmxServerConnectionWrapper call() throws Exception { return new DefaultJmxConnector().createConnection(address, propertiesMap); } }; final Future<JmxServerConnectionWrapper> future = executor.submit(task); try { final JmxServerConnectionWrapper connectionWrapper = future.get(timeout, TimeUnit.MILLISECONDS); return connectionWrapper; } catch (InterruptedException | ExecutionException | TimeoutException e) { final String url = JmxConnectionConfigBuilder.buildFrom(address, propertiesMap).build().getUrl(); LOG.info("Exception connecting JMXConnectorFactory url {} , Error: {}", url, e.getMessage()); if (!future.isDone()) { future.cancel(true); LOG.info(" the task {}", future.isCancelled() ? "was cancelled" : "could not be cancelled"); } throw new ConnectException("Error connecting JMXConnectionFactory " + url); } } }
@Override public DetectRequest buildRequest(String location, InetAddress address, Integer port, Map<String, String> attributes) { // in case port is null, but url is provided, the port is extracted from the url if (port == null && attributes.containsKey("url")) { try { final JmxConnectionConfig config = JmxConnectionConfigBuilder.buildFrom(address, attributes).build(); port = new JMXServiceURL(config.getUrl()).getPort(); } catch (MalformedURLException e) { throw new IllegalArgumentException("url is not valid", e); } } return new DetectRequestImpl(address, port, getRuntimeAttributes(address, port)); }
public static JmxServerConnectionWrapper getMBeanServerConnection(Map<String,String> propertiesMap, InetAddress address) throws IOException { final long timeout = DEFAULT_TIMEOUT; propertiesMap.putIfAbsent("factory", "STANDARD"); propertiesMap.putIfAbsent("port", "1099"); propertiesMap.putIfAbsent("protocol", "rmi"); propertiesMap.putIfAbsent("urlPath", "/jmxrmi"); propertiesMap.putIfAbsent("timeout", Long.toString(timeout)); final Callable<JmxServerConnectionWrapper> task = new Callable<JmxServerConnectionWrapper>() { @Override public JmxServerConnectionWrapper call() throws Exception { return new DefaultJmxConnector().createConnection(address, propertiesMap); } }; final Future<JmxServerConnectionWrapper> future = executor.submit(task); try { final JmxServerConnectionWrapper connectionWrapper = future.get(timeout, TimeUnit.MILLISECONDS); return connectionWrapper; } catch (InterruptedException | ExecutionException | TimeoutException e) { final String url = JmxConnectionConfigBuilder.buildFrom(address, propertiesMap).build().getUrl(); LOG.info("Exception connecting JMXConnectorFactory url {} , Error: {}", url, e.getMessage()); if (!future.isDone()) { future.cancel(true); LOG.info(" the task {}", future.isCancelled() ? "was cancelled" : "could not be cancelled"); } throw new ConnectException("Error connecting JMXConnectionFactory " + url); } } }
public static MBeanServer getMBeanServer(JmxConfigDao jmxConfigDao, String address, Map<String, String> parameters) { Objects.requireNonNull(address); Objects.requireNonNull(parameters); if (jmxConfigDao != null && jmxConfigDao.getConfig() != null) { try { final JmxConnectionConfig config = JmxConnectionConfigBuilder.buildFrom(address, parameters).build(); final int port = new JMXServiceURL(config.getUrl()).getPort(); final MBeanServer mBeanServer = jmxConfigDao.getConfig().lookupMBeanServer(address, port); return mBeanServer; } catch (MalformedURLException e) { LOG.warn("Unexpected exception: {}", e.getMessage(), e); } } return null; // not found or exception }
public static MBeanServer getMBeanServer(JmxConfigDao jmxConfigDao, String address, Map<String, String> parameters) { Objects.requireNonNull(address); Objects.requireNonNull(parameters); if (jmxConfigDao != null && jmxConfigDao.getConfig() != null) { try { final JmxConnectionConfig config = JmxConnectionConfigBuilder.buildFrom(address, parameters).build(); final int port = new JMXServiceURL(config.getUrl()).getPort(); final MBeanServer mBeanServer = jmxConfigDao.getConfig().lookupMBeanServer(address, port); return mBeanServer; } catch (MalformedURLException e) { LOG.warn("Unexpected exception: {}", e.getMessage(), e); } } return null; // not found or exception }