ConfigConverter { public AgentCoreEngineConfiguration convert() throws Exception { Configuration config = this.sourceConfig; config.validate(); GlobalConfiguration globalConfiguration = new GlobalConfiguration( config.getSubsystem().getEnabled(), config.getSubsystem().getImmutable(), config.getSubsystem().getInContainer(), config.getSubsystem().getAutoDiscoveryScanPeriodSecs(), config.getSubsystem().getTypeVersion(), 2); MetricsExporterConfiguration metricsExporter = new MetricsExporterConfiguration( config.getMetricsExporter().getEnabled(), config.getMetricsExporter().getHost(), config.getMetricsExporter().getPort(), config.getMetricsExporter().getConfigDir(), config.getMetricsExporter().getConfigFile(), MetricsExporterConfiguration.Mode.valueOf(config.getMetricsExporter().getProxy().getMode().name()), config.getMetricsExporter().getProxy().getDataDir(), config.getMetricsExporter().getProxy().getMetricLabelsExpression()); DiagnosticsConfiguration diagnostics = new DiagnosticsConfiguration( config.getDiagnostics().getEnabled(), config.getDiagnostics().getInterval(), config.getDiagnostics().getTimeUnits().toJavaTimeUnit()); StorageAdapterConfiguration storageAdapter = new StorageAdapterConfiguration( config.getStorageAdapter().getUsername(), config.getStorageAdapter().getPassword(), config.getStorageAdapter().getFeedId(), config.getStorageAdapter().getUrl(), config.getStorageAdapter().useSSL(), config.getStorageAdapter().getInventoryContext(), config.getStorageAdapter().getFeedcommContext(), config.getStorageAdapter().getHawkularContext(), null, null, config.getStorageAdapter().getSecurityRealmName(), config.getStorageAdapter().getConnectTimeoutSecs(), config.getStorageAdapter().getReadTimeoutSecs()); PlatformConfiguration platformConfiguration = new PlatformConfiguration( config.getPlatform().getEnabled(), config.getPlatform().getMemory().getEnabled(), config.getPlatform().getFileStores().getEnabled(), config.getPlatform().getProcessors().getEnabled(), config.getPlatform().getPowerSources().getEnabled(), config.getPlatform().getMachineId(), config.getPlatform().getContainerId()); ProtocolConfiguration<DMRNodeLocation> dmrConfiguration = buildDmrConfiguration(config); ProtocolConfiguration<JMXNodeLocation> jmxConfiguration = buildJmxConfiguration(config); AgentCoreEngineConfiguration agentConfig = new AgentCoreEngineConfiguration( globalConfiguration, metricsExporter, diagnostics, storageAdapter, platformConfiguration, dmrConfiguration, jmxConfiguration); return agentConfig; } ConfigConverter(Configuration config); AgentCoreEngineConfiguration convert();  }
@Test public void testManagedServerDefaultAllResourceTypeSets() throws Exception { Configuration config = loadTestConfigFile("/all-resource-type-sets.yaml"); AgentCoreEngineConfiguration agentConfig = new ConfigConverter(config).convert(); Assert.assertTrue(agentConfig.getGlobalConfiguration().isSubsystemEnabled()); Assert.assertEquals(2, agentConfig.getDmrConfiguration().getEndpoints().get("local-dmr-ms").getResourceTypeSets().size()); Assert.assertTrue(agentConfig.getDmrConfiguration().getEndpoints().get("local-dmr-ms").getResourceTypeSets() .contains(new Name("dmr type set 1"))); Assert.assertTrue(agentConfig.getDmrConfiguration().getEndpoints().get("local-dmr-ms").getResourceTypeSets() .contains(new Name("dmr type set 2"))); Assert.assertEquals(2, agentConfig.getDmrConfiguration().getEndpoints().get("remote-dmr-ms-1").getResourceTypeSets().size()); Assert.assertTrue(agentConfig.getDmrConfiguration().getEndpoints().get("remote-dmr-ms-1").getResourceTypeSets() .contains(new Name("dmr type set 1"))); Assert.assertTrue(agentConfig.getDmrConfiguration().getEndpoints().get("remote-dmr-ms-1").getResourceTypeSets() .contains(new Name("dmr type set 2"))); Assert.assertEquals(2, agentConfig.getDmrConfiguration().getEndpoints().get("remote-dmr-ms-2").getResourceTypeSets().size()); Assert.assertTrue(agentConfig.getDmrConfiguration().getEndpoints().get("remote-dmr-ms-2").getResourceTypeSets() .contains(new Name("dmr type set 1"))); Assert.assertTrue(agentConfig.getDmrConfiguration().getEndpoints().get("remote-dmr-ms-2").getResourceTypeSets() .contains(new Name("dmr type set 2"))); Assert.assertEquals(2, agentConfig.getJmxConfiguration().getEndpoints().get("local-jmx-ms").getResourceTypeSets().size()); Assert.assertTrue(agentConfig.getJmxConfiguration().getEndpoints().get("local-jmx-ms").getResourceTypeSets() .contains(new Name("jmx type set 1"))); Assert.assertTrue(agentConfig.getJmxConfiguration().getEndpoints().get("local-jmx-ms").getResourceTypeSets() .contains(new Name("jmx type set 2"))); Assert.assertEquals(2, agentConfig.getJmxConfiguration().getEndpoints().get("remote-jmx-ms-1").getResourceTypeSets().size()); Assert.assertTrue(agentConfig.getJmxConfiguration().getEndpoints().get("remote-jmx-ms-1").getResourceTypeSets() .contains(new Name("jmx type set 1"))); Assert.assertTrue(agentConfig.getJmxConfiguration().getEndpoints().get("remote-jmx-ms-1").getResourceTypeSets() .contains(new Name("jmx type set 2"))); Assert.assertEquals(2, agentConfig.getJmxConfiguration().getEndpoints().get("remote-jmx-ms-2").getResourceTypeSets().size()); Assert.assertTrue(agentConfig.getJmxConfiguration().getEndpoints().get("remote-jmx-ms-2").getResourceTypeSets() .contains(new Name("jmx type set 1"))); Assert.assertTrue(agentConfig.getJmxConfiguration().getEndpoints().get("remote-jmx-ms-2").getResourceTypeSets() .contains(new Name("jmx type set 2"))); }
@Test public void testEmpty() throws Exception { Configuration config = loadTestConfigFile("/empty.yaml"); AgentCoreEngineConfiguration agentConfig = new ConfigConverter(config).convert(); Assert.assertEquals("empty", agentConfig.getGlobalConfiguration().getTypeVersion()); }
@Test public void testRealConfig() throws Exception { Configuration config = loadTestConfigFile("/wildfly10/hawkular-javaagent-config.yaml"); AgentCoreEngineConfiguration agentConfig = new ConfigConverter(config).convert(); Assert.assertTrue(agentConfig.getGlobalConfiguration().isSubsystemEnabled()); }
@Test public void testRealConfigEAP6() throws Exception { Configuration config = loadTestConfigFile("/eap6/hawkular-javaagent-config.yaml"); AgentCoreEngineConfiguration agentConfig = new ConfigConverter(config).convert(); Assert.assertTrue(agentConfig.getGlobalConfiguration().isSubsystemEnabled()); }
@Test public void testRealConfigJMX() throws Exception { Configuration config = loadTestConfigFile("/real-config-jmx.yaml"); AgentCoreEngineConfiguration agentConfig = new ConfigConverter(config).convert(); Assert.assertTrue(agentConfig.getGlobalConfiguration().isSubsystemEnabled()); Assert.assertTrue(agentConfig.getDmrConfiguration().getEndpoints().isEmpty()); }
@Test public void testConvertConfig() throws Exception { Configuration config = loadTestConfigFile("/test-convert.yaml"); AgentCoreEngineConfiguration agentConfig = new ConfigConverter(config).convert(); Assert.assertTrue(agentConfig.getGlobalConfiguration().isSubsystemEnabled()); Assert.assertEquals(111, agentConfig.getGlobalConfiguration().getAutoDiscoveryScanPeriodSeconds()); Assert.assertEquals(true, agentConfig.getMetricsExporterConfiguration().isEnabled()); Assert.assertEquals("thehost", agentConfig.getMetricsExporterConfiguration().getHost()); Assert.assertEquals(12345, agentConfig.getMetricsExporterConfiguration().getPort()); Assert.assertEquals("exporter", agentConfig.getMetricsExporterConfiguration().getConfigDir()); Assert.assertEquals("config.yaml", agentConfig.getMetricsExporterConfiguration().getConfigFile()); Assert.assertEquals(Mode.slave, agentConfig.getMetricsExporterConfiguration().getProxyMode()); Assert.assertEquals("proxy/data/dir", agentConfig.getMetricsExporterConfiguration().getProxyDataDir()); Assert.assertEquals("http: Assert.assertEquals("the user", agentConfig.getStorageAdapter().getUsername()); Assert.assertEquals("the pass", agentConfig.getStorageAdapter().getPassword()); Assert.assertEquals("h-server", agentConfig.getStorageAdapter().getSecurityRealm()); Assert.assertNull(agentConfig.getStorageAdapter().getKeystorePath()); Assert.assertNull(agentConfig.getStorageAdapter().getKeystorePassword()); Assert.assertEquals("the feed", agentConfig.getStorageAdapter().getFeedId()); Assert.assertEquals(5, agentConfig.getDiagnostics().getInterval()); EndpointConfiguration localDmr = agentConfig.getDmrConfiguration().getEndpoints().get("Test Local DMR"); Assert.assertEquals(true, localDmr.isEnabled()); Assert.assertEquals(2, localDmr.getWaitForResources().size()); Assert.assertEquals("/subsystem=undertow", localDmr.getWaitForResources().get(0).getResource()); Assert.assertEquals("/", localDmr.getWaitForResources().get(1).getResource()); EndpointConfiguration localJmx = agentConfig.getJmxConfiguration().getEndpoints().get("Test Local JMX"); Assert.assertEquals(true, localJmx.isEnabled()); Assert.assertEquals(2, localJmx.getWaitForResources().size()); Assert.assertEquals("java.lang:type=Runtime", localJmx.getWaitForResources().get(0).getResource()); Assert.assertEquals("java.lang:type=Memory", localJmx.getWaitForResources().get(1).getResource()); EndpointConfiguration remoteDmr = agentConfig.getDmrConfiguration().getEndpoints().get("Test Remote DMR"); Assert.assertEquals(true, remoteDmr.isEnabled()); Assert.assertEquals(1, remoteDmr.getWaitForResources().size()); Assert.assertEquals("/subsystem=undertow", remoteDmr.getWaitForResources().get(0).getResource()); EndpointConfiguration remoteJmx = agentConfig.getJmxConfiguration().getEndpoints().get("Test Remote JMX"); Assert.assertEquals(true, remoteJmx.isEnabled()); Assert.assertEquals(1, remoteJmx.getWaitForResources().size()); Assert.assertEquals("java.lang:type=Runtime", remoteJmx.getWaitForResources().get(0).getResource()); EndpointConfiguration remoteDmr2 = agentConfig.getDmrConfiguration().getEndpoints().get("Test Remote DMR 2"); Assert.assertEquals(true, remoteDmr2.isEnabled()); Assert.assertEquals(0, remoteDmr2.getWaitForResources().size()); EndpointConfiguration remoteJmx2 = agentConfig.getJmxConfiguration().getEndpoints().get("Test Remote JMX 2"); Assert.assertEquals(true, remoteJmx2.isEnabled()); Assert.assertEquals(0, remoteJmx2.getWaitForResources().size()); }
@Test public void testTypeVersion() throws Exception { Configuration config = loadTestConfigFile("/all-resource-type-sets-with-type-version.yaml"); AgentCoreEngineConfiguration agentConfig = new ConfigConverter(config).convert(); Assert.assertNotNull(agentConfig.getDmrConfiguration() .getTypeSets() .getResourceTypeSets() .get(new Name("dmr type set 1")) .getTypeMap() .get(new Name("dmr type 1 EAPX"))); Assert.assertNotNull(agentConfig.getDmrConfiguration() .getTypeSets() .getResourceTypeSets() .get(new Name("dmr type set 1")) .getTypeMap() .get(new Name("dmr type 2 EAPX"))); }