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 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 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); } }
@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); } }