├── .gitignore ├── .mvn ├── extensions.xml ├── srcdeps.yaml └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .travis.maven.settings.xml ├── .travis.yml ├── LICENSE ├── README.adoc ├── docker-dist ├── Dockerfile ├── README.adoc ├── build.sh ├── example-env-file ├── hawkular-javaagent-example.yaml ├── pom.xml └── src │ └── main │ └── resources │ └── run_hawkular_javaagent.sh ├── eap6-support └── hawkular-javaagent-wildfly-feature-pack-eap6 │ ├── assembly.xml │ ├── feature-pack-build.xml │ ├── pom.xml │ └── src │ └── main │ └── resources │ ├── bin │ └── standalone-hawkular-javaagent-javaopts.conf │ └── featurepack │ └── content │ └── standalone │ └── configuration │ └── hawkular-javaagent-config.yaml ├── hawkular-agent-command-cli ├── README.adoc ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── hawkular │ │ └── agent │ │ └── commandcli │ │ └── CommandCli.java │ └── resources │ ├── logging-debug.properties │ └── logging.properties ├── hawkular-agent-core ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── hawkular │ │ └── agent │ │ └── monitor │ │ ├── api │ │ ├── HawkularAgentContext.java │ │ ├── HawkularAgentContextImpl.java │ │ ├── InventoryEvent.java │ │ ├── InventoryListener.java │ │ ├── InventoryStorage.java │ │ ├── NotificationPayloadBuilder.java │ │ └── NotificationStorage.java │ │ ├── cmd │ │ ├── AbstractAgnosticResourcePathCommand.java │ │ ├── AbstractDMRResourcePathCommand.java │ │ ├── AbstractJMXResourcePathCommand.java │ │ ├── AbstractRemoveModelNodeCommand.java │ │ ├── AbstractResourceCommand.java │ │ ├── AddDatasourceCommand.java │ │ ├── AddJdbcDriverCommand.java │ │ ├── Command.java │ │ ├── CommandContext.java │ │ ├── DeployApplicationCommand.java │ │ ├── DisableApplicationCommand.java │ │ ├── EchoCommand.java │ │ ├── EnableApplicationCommand.java │ │ ├── ExecuteAgnosticOperationCommand.java │ │ ├── ExecuteDMROperationCommand.java │ │ ├── ExecuteJMXOperationCommand.java │ │ ├── ExportJdrCommand.java │ │ ├── FeedCommProcessor.java │ │ ├── GenericErrorResponseCommand.java │ │ ├── InvalidCommandRequestException.java │ │ ├── RemoveDatasourceCommand.java │ │ ├── RemoveJdbcDriverCommand.java │ │ ├── RestartApplicationCommand.java │ │ ├── StatisticsControlCommand.java │ │ ├── UndeployApplicationCommand.java │ │ ├── UpdateDatasourceCommand.java │ │ └── WebSocketClientBuilder.java │ │ ├── config │ │ └── AgentCoreEngineConfiguration.java │ │ ├── diagnostics │ │ ├── Diagnostics.java │ │ ├── DiagnosticsImpl.java │ │ ├── JBossLoggingReporter.java │ │ └── ProtocolDiagnostics.java │ │ ├── inventory │ │ ├── AttributeLocation.java │ │ ├── AttributeLocationProvider.java │ │ ├── ConnectionData.java │ │ ├── ID.java │ │ ├── IDObject.java │ │ ├── Instance.java │ │ ├── Interval.java │ │ ├── InventoryIdUtil.java │ │ ├── MeasurementInstance.java │ │ ├── MeasurementType.java │ │ ├── MetricType.java │ │ ├── MonitoredEndpoint.java │ │ ├── Name.java │ │ ├── NameSet.java │ │ ├── NamedObject.java │ │ ├── NodeLocation.java │ │ ├── NodeLocationProvider.java │ │ ├── Operation.java │ │ ├── OperationParam.java │ │ ├── Resource.java │ │ ├── ResourceConfigurationPropertyInstance.java │ │ ├── ResourceConfigurationPropertyType.java │ │ ├── ResourceManager.java │ │ ├── ResourceType.java │ │ ├── ResourceTypeManager.java │ │ ├── SupportedMetricType.java │ │ ├── TypeSet.java │ │ └── TypeSets.java │ │ ├── log │ │ ├── AgentLoggers.java │ │ └── MsgLogger.java │ │ ├── prometheus │ │ ├── JmxCollector.java │ │ ├── JmxScraper.java │ │ └── WebServer.java │ │ ├── protocol │ │ ├── Discovery.java │ │ ├── Driver.java │ │ ├── EndpointService.java │ │ ├── LocationResolver.java │ │ ├── ProtocolException.java │ │ ├── ProtocolService.java │ │ ├── ProtocolServices.java │ │ ├── Session.java │ │ ├── dmr │ │ │ ├── DMRDriver.java │ │ │ ├── DMREndpointService.java │ │ │ ├── DMRLocationResolver.java │ │ │ ├── DMRNodeLocation.java │ │ │ ├── DMRSession.java │ │ │ ├── ModelControllerClientFactory.java │ │ │ └── StatisticsControl.java │ │ ├── jmx │ │ │ ├── JMXDriver.java │ │ │ ├── JMXEndpointService.java │ │ │ ├── JMXLocationResolver.java │ │ │ ├── JMXNodeLocation.java │ │ │ ├── JMXSession.java │ │ │ ├── JolokiaClientFactory.java │ │ │ ├── JolokiaJMXDriver.java │ │ │ └── MBeanServerConnectionJMXDriver.java │ │ └── platform │ │ │ ├── Constants.java │ │ │ ├── OshiPlatformCache.java │ │ │ └── PlatformMBeanGenerator.java │ │ ├── service │ │ ├── AgentCoreEngine.java │ │ ├── ServiceStatus.java │ │ └── Version.java │ │ ├── storage │ │ ├── AsyncInventoryStorage.java │ │ ├── HawkularStorageAdapter.java │ │ ├── HttpClientBuilder.java │ │ ├── InventoryStorageProxy.java │ │ ├── NotificationDispatcher.java │ │ ├── NotificationPayloadBuilderImpl.java │ │ └── StorageAdapter.java │ │ └── util │ │ ├── BaseHttpClientGenerator.java │ │ ├── Consumer.java │ │ ├── ThreadFactoryGenerator.java │ │ ├── Util.java │ │ └── WildflyCompatibilityUtils.java │ └── test │ └── java │ └── org │ └── hawkular │ └── agent │ └── monitor │ ├── inventory │ ├── InventoryIdUtilTest.java │ ├── NamedObjectTest.java │ ├── ResourceManagerTest.java │ └── ResourceTypeManagerTest.java │ ├── protocol │ ├── LocationResolverTest.java │ ├── dmr │ │ ├── DMREndpointServiceTest.java │ │ └── DMRLocationResolverTest.java │ ├── jmx │ │ └── JMXLocationResolverTest.java │ └── platform │ │ ├── OshiPlatformCacheTest.java │ │ └── PlatformMBeanGeneratorTest.java │ ├── service │ └── ServiceStatusTest.java │ ├── storage │ └── AsyncInventoryStorageTest.java │ └── util │ └── UtilTest.java ├── hawkular-agent-itest-util ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── hawkular │ └── agent │ └── itest │ └── util │ └── ITestHelper.java ├── hawkular-dmr-client ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── hawkular │ │ ├── dmr │ │ └── api │ │ │ ├── DmrApiException.java │ │ │ ├── DmrApiLoggers.java │ │ │ ├── DmrNodePath.java │ │ │ ├── DmrUtils.java │ │ │ ├── MsgLogger.java │ │ │ ├── OperationBuilder.java │ │ │ ├── OperationFailureException.java │ │ │ ├── SubsystemDatasourceConstants.java │ │ │ └── SubsystemLoggingConstants.java │ │ └── dmrclient │ │ ├── Address.java │ │ ├── CoreJBossASClient.java │ │ ├── DatasourceJBossASClient.java │ │ ├── DeploymentJBossASClient.java │ │ ├── FailureException.java │ │ ├── InfinispanJBossASClient.java │ │ ├── JBossASClient.java │ │ ├── LoggingJBossASClient.java │ │ ├── MessagingJBossASClient.java │ │ ├── SecurityDomainJBossASClient.java │ │ ├── SocketBindingJBossASClient.java │ │ ├── TransactionsJBossASClient.java │ │ ├── VaultJBossASClient.java │ │ ├── WebJBossASClient.java │ │ └── modules │ │ ├── AddModuleRequest.java │ │ └── Modules.java │ └── test │ ├── java │ └── org │ │ └── hawkular │ │ └── dmrclient │ │ ├── AddressTest.java │ │ ├── OperationBuilderTest.java │ │ └── modules │ │ └── ModulesTest.java │ └── resources │ └── org │ └── hawkular │ └── dmrclient │ └── modules │ ├── complicated.xml │ ├── minimal.xml │ └── usual.xml ├── hawkular-javaagent-itest-parent ├── hawkular-javaagent-all-itests │ ├── hawkular-javaagent-cmdgw-itest │ │ ├── pom.xml │ │ ├── server-provisioning.xml │ │ └── src │ │ │ └── test │ │ │ ├── java │ │ │ └── org │ │ │ │ └── hawkular │ │ │ │ └── agent │ │ │ │ └── ws │ │ │ │ └── test │ │ │ │ ├── AbstractCommandITest.java │ │ │ │ ├── DatasourceCommandITest.java │ │ │ │ ├── ExecuteOperationCommandITest.java │ │ │ │ ├── ExportJdrCommandITest.java │ │ │ │ ├── ImmutableITest.java │ │ │ │ ├── JdbcDriverCommandITest.java │ │ │ │ ├── StandaloneDeployApplicationITest.java │ │ │ │ ├── StandaloneWildFlyITest.java │ │ │ │ └── StatisticsControlCommandITest.java │ │ │ └── resources │ │ │ ├── hawkular-javaagent-itest-config.yaml │ │ │ ├── logging.properties │ │ │ └── org │ │ │ └── hawkular │ │ │ └── agent │ │ │ └── ws │ │ │ └── test │ │ │ ├── DatasourceCommandITest.testH2Ds-after-add.node.txt │ │ │ ├── DatasourceCommandITest.testH2Ds-after-update.node.txt │ │ │ ├── DatasourceCommandITest.testXaDs-after-add.node.txt │ │ │ ├── DatasourceCommandITest.testXaDs-after-update.node.txt │ │ │ └── JdbcDriverCommandITest.driver-after-add.node.txt │ ├── hawkular-javaagent-domain-itest │ │ ├── pom.xml │ │ ├── server-provisioning-hawkular.xml │ │ ├── server-provisioning-plain-wildfly.xml │ │ └── src │ │ │ └── test │ │ │ ├── java │ │ │ └── org │ │ │ │ └── hawkular │ │ │ │ └── agent │ │ │ │ └── test │ │ │ │ ├── AbstractDomainITestSuite.java │ │ │ │ ├── ControlDomainServersITest.java │ │ │ │ ├── DomainDeployApplicationITest.java │ │ │ │ └── DomainResourcesITest.java │ │ │ └── resources │ │ │ ├── hawkular-javaagent-itest-config.yaml │ │ │ └── logging.properties │ └── pom.xml ├── hawkular-javaagent-helloworld-war │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── hawkular │ │ │ └── agent │ │ │ └── helloworld │ │ │ ├── HelloWorldServlet.java │ │ │ ├── SimpleMXBean.java │ │ │ └── SimpleMXBeanImpl.java │ │ └── webapp │ │ ├── WEB-INF │ │ ├── beans.xml │ │ ├── jboss-web.xml │ │ └── web.xml │ │ └── index.html ├── hawkular-javaagent-itest-feature-pack │ ├── assembly.xml │ ├── feature-pack-build.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── xsl │ │ ├── configuration │ │ └── standalone │ │ │ └── hawkular-javaagent-itest-subsystems.xsl │ │ └── subsystem-templates │ │ ├── hawkular-javaagent-itest-infinispan.xsl │ │ ├── hawkular-javaagent-itest-logging.xsl │ │ └── hawkular-javaagent-itest-messaging-activemq.xsl ├── hawkular-javaagent-itest-util │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── hawkular │ │ └── javaagent │ │ └── itest │ │ └── util │ │ ├── AbstractITest.java │ │ └── WildFlyClientConfig.java └── pom.xml ├── hawkular-javaagent-wildfly-dist ├── assembly.xml ├── pom.xml └── server-provisioning-plain-wildfly.xml ├── hawkular-javaagent-wildfly-feature-pack ├── assembly.xml ├── feature-pack-build.xml ├── pom.xml └── src │ └── main │ └── resources │ └── featurepack │ └── content │ ├── bin │ ├── domain.conf │ ├── standalone.conf │ └── start-with-hawkular.sh │ ├── domain │ └── configuration │ │ └── host-hawkular.xml │ └── standalone │ └── configuration │ ├── hawkular-javaagent-config-metrics-only.yaml │ └── hawkular-javaagent-config.yaml ├── hawkular-javaagent ├── AGENT-CONFIG.adoc ├── README.adoc ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── hawkular │ │ └── agent │ │ └── javaagent │ │ ├── InventoryReport.java │ │ ├── JavaAgent.java │ │ ├── JavaAgentEngine.java │ │ ├── JavaAgentMXBean.java │ │ ├── Util.java │ │ ├── cmd │ │ └── EchoCommand.java │ │ ├── config │ │ ├── AbstractExpression.java │ │ ├── AbstractStringifiedProperty.java │ │ ├── BooleanExpression.java │ │ ├── ConfigConverter.java │ │ ├── ConfigManager.java │ │ ├── Configuration.java │ │ ├── DMRMetric.java │ │ ├── DMRMetricSet.java │ │ ├── DMRNotification.java │ │ ├── DMROperation.java │ │ ├── DMROperationParam.java │ │ ├── DMRResourceConfig.java │ │ ├── DMRResourceType.java │ │ ├── DMRResourceTypeSet.java │ │ ├── Diagnostics.java │ │ ├── IntegerExpression.java │ │ ├── JMXMetric.java │ │ ├── JMXMetricSet.java │ │ ├── JMXOperation.java │ │ ├── JMXOperationParam.java │ │ ├── JMXResourceConfig.java │ │ ├── JMXResourceType.java │ │ ├── JMXResourceTypeSet.java │ │ ├── LocalDMR.java │ │ ├── LocalJMX.java │ │ ├── ManagedServers.java │ │ ├── MetricTypeJsonProperty.java │ │ ├── MetricUnitJsonProperty.java │ │ ├── MetricsExporter.java │ │ ├── MetricsExporterProxy.java │ │ ├── Platform.java │ │ ├── RemoteDMR.java │ │ ├── RemoteJMX.java │ │ ├── SecurityRealm.java │ │ ├── StorageAdapter.java │ │ ├── StringExpression.java │ │ ├── StringPropertyReplacer.java │ │ ├── Subsystem.java │ │ ├── TimeUnits.java │ │ ├── Validatable.java │ │ └── WaitFor.java │ │ └── log │ │ ├── JavaAgentLoggers.java │ │ └── MsgLogger.java │ └── test │ ├── java │ └── org │ │ └── hawkular │ │ └── agent │ │ └── javaagent │ │ ├── GenerateFeedIdTest.java │ │ └── config │ │ ├── ConfigConverterTest.java │ │ ├── ConfigCopyTest.java │ │ ├── ConfigExpressionTest.java │ │ ├── ConfigManagerTest.java │ │ ├── StringPropertyReplacerTest.java │ │ └── UtilTest.java │ └── resources │ ├── all-resource-type-sets-with-type-version.yaml │ ├── all-resource-type-sets.yaml │ ├── bad-notif.yaml │ ├── empty.yaml │ ├── real-config-jmx.yaml │ ├── simple.yaml │ ├── test-config.yaml │ ├── test-convert.yaml │ ├── test-overlay-all-resource-types-1.yaml │ ├── test-overlay-all-resource-types-2.yaml │ ├── test-overlay1.yaml │ └── test-overlay2.yaml ├── mvnw ├── mvnw.cmd └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Mobile Tools for Java (J2ME) 2 | .mtj.tmp/ 3 | 4 | # virtual machine crash logs 5 | hs_err_pid* 6 | 7 | # maven target directories 8 | target/ 9 | pom.xml.releaseBackup 10 | release.properties 11 | pom.xml.versionsBackup 12 | 13 | # IDE files 14 | .project 15 | .classpath 16 | .settings 17 | .idea 18 | *.ipr 19 | *.iml 20 | *.iws 21 | nb-configuration.xml 22 | 23 | # KDE 24 | .directory 25 | 26 | # MacOS DS_Store 27 | .DS_Store 28 | 29 | # Swap files 30 | *.swp 31 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 24 | 25 | 26 | org.srcdeps.mvn 27 | srcdeps-maven-local-repository 28 | 2.1.0 29 | 30 | 31 | org.srcdeps.mvn 32 | srcdeps-maven-enforcer 33 | 2.1.0 34 | 35 | -------------------------------------------------------------------------------- /.mvn/srcdeps.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # `.mvn/srcdeps.yaml` - the srcdeps configuration file 19 | # 20 | # The full srcdeps.yaml reference can be found under https://github.com/srcdeps/srcdeps-core/tree/master/doc/srcdeps.yaml 21 | # 22 | # Note that the options set here can be overriden on the command line, 23 | # see https://github.com/srcdeps/srcdeps-maven/blob/master/README.adoc#override-mvnsrcdepsyaml-options-on-the-command-line 24 | 25 | 26 | configModelVersion: 1.1 27 | 28 | repositories: 29 | 30 | org.hawkular: 31 | selectors: 32 | - org.hawkular 33 | urls: 34 | - git:https://github.com/hawkular/hawkular-parent-pom.git 35 | buildArguments: 36 | - -Dcheckstyle.skip=true 37 | - -Dlicense.skip=true 38 | - -Drevapi.skip=true 39 | 40 | org.hawkular.alerts: 41 | selectors: 42 | - org.hawkular.alerts 43 | urls: 44 | - git:https://github.com/hawkular/hawkular-alerts.git 45 | buildArguments: 46 | - -Dcheckstyle.skip=true 47 | - -Dlicense.skip=true 48 | - -Drevapi.skip=true 49 | 50 | org.hawkular.commons: 51 | selectors: 52 | - org.hawkular.commons 53 | urls: 54 | - git:https://github.com/hawkular/hawkular-commons.git 55 | buildArguments: 56 | - -Dcheckstyle.skip=true 57 | - -Dlicense.skip=true 58 | - -Drevapi.skip=true 59 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkular/hawkular-agent/a7a88fc7e4f12302e4c4306d1c91e11f81c8b811/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Hawkular Java Agent 2 | 3 | [link=https://travis-ci.org/hawkular/hawkular-agent] 4 | image::https://travis-ci.org/hawkular/hawkular-agent.svg?branch=master[Build Status] 5 | 6 | [TIP, caption='Synopsis'] 7 | ==== 8 | Hawkular Java Agent can be used to manage WildFly or EAP applications servers as well as any Java application exposing JMX data. 9 | ==== 10 | 11 | == Installation 12 | 13 | The agent runs as a JVM Java Agent. See link:hawkular-javaagent/README.adoc[]. 14 | 15 | == Configuration 16 | 17 | The agent is configured with a yaml file. For an example, see link:hawkular-javaagent-wildfly-feature-pack/src/main/resources/featurepack/content/standalone/configuration/hawkular-javaagent-config.yaml[] 18 | 19 | == Running 20 | 21 | You attach the Hawkular Java Agent to your own application, so running your application runs the Hawkular Java Agent with it. 22 | 23 | If you want to test the Hawkular Java Agent, you can run it standalone and just point it to a remote Java application to manage (you do this by addinga remote-dmr or remote-jmx managed server definition to its configuration file). You can run it like this: 24 | 25 | ``` 26 | java -Dhawkular.rest.user=jdoe -Dhawkular.rest.password=password -Dhawkular.rest.url=http://localhost:8080 -jar hawkular-javaagent/target/hawkular-javaagent-*-shaded.jar config=hawkular-javaagent-wildfly-feature-pack/src/main/resources/featurepack/content/standalone/configuration/hawkular-javaagent-config.yaml 27 | ``` 28 | -------------------------------------------------------------------------------- /docker-dist/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | FROM jboss/wildfly:11.0.0.Final 19 | 20 | MAINTAINER Hawkular project 21 | 22 | # ADD test-simple.war /opt/jboss/wildfly/standalone/deployments/ 23 | COPY target/hawkular $JBOSS_HOME/ 24 | COPY src/main/resources/run_hawkular_javaagent.sh /opt/hawkular/bin/run_hawkular_agent.sh 25 | 26 | ENV HAWKULAR_URL=http://hawkular:8080 \ 27 | HAWKULAR_USER=jdoe \ 28 | HAWKULAR_PASSWORD=password \ 29 | HAWKULAR_AGENT_IMMUTABLE=true \ 30 | HAWKULAR_AGENT_METRICS_PORT=9779 \ 31 | HAWKULAR_AGENT_MODE=standalone 32 | 33 | EXPOSE 8080 9090 9779 34 | 35 | USER root 36 | 37 | 38 | RUN yum install --quiet -y openssl && \ 39 | rm -rf /var/cache/yum && \ 40 | chown -RH jboss:0 $JBOSS_HOME $JAVA_HOME/jre/lib/security/cacerts /opt/hawkular && \ 41 | chmod -R ug+rw $JBOSS_HOME $JAVA_HOME/jre/lib/security/cacerts /opt/hawkular && \ 42 | chmod -R a+rw /opt/hawkular/ && \ 43 | chmod -R a+x $JBOSS_HOME 44 | 45 | USER jboss 46 | CMD /opt/hawkular/bin/run_hawkular_agent.sh 47 | -------------------------------------------------------------------------------- /docker-dist/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 4 | # and other contributors as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | 20 | docker > /dev/null 2>&1 || { echo "docker is required, but is not found. Make sure it is accessible."; exit 1; } 21 | TAG="${1:-latest}" 22 | IMAGE="${2:-hawkular/wildfly-hawkular-javaagent}" 23 | 24 | pushd "$( dirname "${BASH_SOURCE[0]}" )" 25 | 26 | echo "Building Docker image for Wildfly + Hawkular javaagent: $IMAGE:$TAG." 27 | docker build -t $IMAGE:$TAG . -f Dockerfile 28 | 29 | popd 30 | -------------------------------------------------------------------------------- /docker-dist/example-env-file: -------------------------------------------------------------------------------- 1 | HAWKULAR_URL=http://hawkular.example.com:8080 2 | HAWKULAR_USER=jdoe 3 | HAWKULAR_PASSWORD=password 4 | -------------------------------------------------------------------------------- /docker-dist/hawkular-javaagent-example.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | apiVersion: apps/v1beta1 19 | kind: Deployment 20 | metadata: 21 | name: hawkular-javaagent-example 22 | spec: 23 | replicas: 1 24 | selector: 25 | matchLabels: 26 | app: hawkular-javaagent-example 27 | template: 28 | metadata: 29 | labels: 30 | app: hawkular-javaagent-example 31 | spec: 32 | containers: 33 | - name: hawkular-javaagent-example 34 | image: hawkular/wildfly-hawkular-javaagent:latest 35 | ports: 36 | - containerPort: 8080 37 | env: 38 | - name: HAWKULAR_URL 39 | valueFrom: 40 | secretKeyRef: 41 | name: hawkular-javaagent-example 42 | key: HAWKULAR_URL 43 | - name: HAWKULAR_USER 44 | valueFrom: 45 | secretKeyRef: 46 | name: hawkular-javaagent-example 47 | key: HAWKULAR_USER 48 | - name: HAWKULAR_PASSWORD 49 | valueFrom: 50 | secretKeyRef: 51 | name: hawkular-javaagent-example 52 | key: HAWKULAR_PASSWORD 53 | volumeMounts: 54 | - name: secrets 55 | mountPath: /client-secrets 56 | readOnly: true 57 | volumes: 58 | - name: secrets 59 | secret: 60 | secretName: hawkular-javaagent-example-ca 61 | optional: true 62 | items: 63 | - key: hawkular-services-ca.crt 64 | path: hawkular-services-public.pem 65 | -------------------------------------------------------------------------------- /docker-dist/src/main/resources/run_hawkular_javaagent.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 4 | # and other contributors as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | PUBLIC_KEY="/client-secrets/hawkular-services-public.pem" 20 | 21 | import_hawkular_services_public_key() { 22 | local PUBLIC_KEY_DER="/tmp/hawkular-services-public.cert" 23 | if [[ -f ${PUBLIC_KEY} ]] && [[ -s ${PUBLIC_KEY} ]]; then 24 | openssl x509 -inform pem -in ${PUBLIC_KEY} -out ${PUBLIC_KEY_DER} 25 | keytool -import -keystore ${JAVA_HOME}/jre/lib/security/cacerts -storepass changeit \ 26 | -file ${PUBLIC_KEY_DER} -noprompt 27 | rm -f ${PUBLIC_KEY_DER} 28 | fi 29 | } 30 | 31 | run_hawkular_agent() { 32 | local START_WITH_HAWKULAR_PARAMS="-s ${HAWKULAR_URL}" 33 | if [[ "${HAWKULAR_AGENT_MODE}" == "domain" ]]; then 34 | START_WITH_HAWKULAR_PARAMS="$START_WITH_HAWKULAR_PARAMS -d" 35 | fi 36 | ${JBOSS_HOME}/bin/start-with-hawkular.sh ${START_WITH_HAWKULAR_PARAMS} "$@" 37 | } 38 | 39 | main() { 40 | HAWKULAR_AGENT_MODE=`echo ${HAWKULAR_AGENT_MODE} | tr '[:upper:]' '[:lower:]'` 41 | if [[ "${HAWKULAR_AGENT_MODE}" != "standalone" ]] && [[ "${HAWKULAR_AGENT_MODE}" != "domain" ]]; then 42 | echo 'HAWKULAR_AGENT_MODE must be set to "standalone" or "domain", found:' ${HAWKULAR_AGENT_MODE} 43 | exit 44 | fi 45 | import_hawkular_services_public_key 46 | run_hawkular_agent "$@" 47 | } 48 | 49 | main "$@" 50 | -------------------------------------------------------------------------------- /eap6-support/hawkular-javaagent-wildfly-feature-pack-eap6/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 23 | 24 | hawkular-javaagent-wildfly-feature-pack-eap6 25 | 26 | zip 27 | 28 | false 29 | 30 | 31 | target/hawkular-javaagent-wildfly-feature-pack-eap6-${project.version} 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /eap6-support/hawkular-javaagent-wildfly-feature-pack-eap6/feature-pack-build.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /eap6-support/hawkular-javaagent-wildfly-feature-pack-eap6/src/main/resources/bin/standalone-hawkular-javaagent-javaopts.conf: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Hawkular Java Agent: 19 | # Explicitly tell the VM to use the JBoss Log Manager via -Djava.util.logging.manager system property. 20 | # Use the -javaagent VM option to load the Hawkular Java Agent with its config file. 21 | JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager -javaagent:$JBOSS_HOME/bin/hawkular-javaagent.jar=config=$JBOSS_HOME/standalone/configuration/hawkular-javaagent-config.yaml,delay=10" 22 | -------------------------------------------------------------------------------- /eap6-support/hawkular-javaagent-wildfly-feature-pack-eap6/src/main/resources/featurepack/content/standalone/configuration/hawkular-javaagent-config.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: "${hawkular.agent.enabled:true}" 21 | immutable: "${hawkular.agent.immutable:false}" 22 | in-container: "${hawkular.agent.in-container:false}" 23 | auto-discovery-scan-period-secs: ${hawkular.agent.auto-discovery-scan-period-secs:600} 24 | type-version: EAP6 25 | 26 | metrics-exporter: 27 | enabled: true 28 | host: ${hawkular.agent.metrics.host:127.0.0.1} 29 | port: ${hawkular.agent.metrics.port:9779} 30 | config-dir: ${jboss.server.config.dir} 31 | config-file: EAP6 32 | 33 | diagnostics: 34 | enabled: true 35 | interval: 1 36 | time-units: minutes 37 | 38 | storage-adapter: 39 | feed-id: "${hawkular.rest.feedId:autogenerate}" 40 | url: "${hawkular.rest.url:http://hawkular-server:8080}" 41 | username: "${env.HAWKULAR_USER,hawkular.rest.username}" 42 | password: "${env.HAWKULAR_PASSWORD,hawkular.rest.password}" 43 | 44 | # MANAGED SERVERS 45 | 46 | managed-servers: 47 | local-dmr: 48 | name: Local DMR 49 | enabled: true 50 | wait-for: 51 | - name: / 52 | metric-labels: 53 | feed_id: "%FeedId" 54 | 55 | local-jmx: 56 | name: Local JMX 57 | enabled: true 58 | wait-for: 59 | - name: java.lang:type=Runtime 60 | metric-labels: 61 | feed_id: "%FeedId" 62 | 63 | platform: 64 | enabled: true 65 | #machine-id: my-machine-id-here 66 | -------------------------------------------------------------------------------- /hawkular-agent-command-cli/README.adoc: -------------------------------------------------------------------------------- 1 | == SUMMARY 2 | 3 | This command CLI utility allows you to send commands to the Hawkular Server over the https://github.com/hawkular/hawkular-commons/tree/master/hawkular-command-gateway/hawkular-command-gateway-api[Hawkular Command Gateway] websocket, 4 | which in turn can forward the command to the agent. 5 | 6 | It can be run on the command line like this: 7 | 8 | ``` 9 | java -jar hawkular-agent-command-cli-*.jar 10 | ``` 11 | 12 | where options include things such as your credentials, the command you want to send along with its parameters, 13 | as well as optional binary data. 14 | 15 | An example command to deploy a WAR to a specific WildFly instance in inventory: 16 | 17 | ``` 18 | java -jar hawkular-agent-command-cli-*.jar \ 19 | --server-url http://myhost:8080 \ 20 | --username myuser \ 21 | --password myPassword \ 22 | --command DeployApplicationRequest \ 23 | '-PresourcePath=/t;hawkular/f;c15f9426-734e-4ee6-82d3-7b0d82c41a6d/r;Local~~' 24 | -PdestinationFileName=hello-world.war 25 | --binary-data-file=/home/me/files/hello-world.war 26 | ``` 27 | 28 | Notice you can pass parameters to your command using the `-Pname=value` arguments. You can specify 0, 1, or more `-P` options. 29 | 30 | You can also pass map parameters in your command using the `-Mname:key=value` arguments. You can also specify 0, 1, or more `-M` options. For example, suppose your command requires that you pass two maps - one called "values" and one called "options". Further suppose you want to pass a "values" map having entries of "color=blue" and "sound=beep" and the "options" map having a single entry of "debug=true". You can send those maps parameters like this: 31 | 32 | 33 | ``` 34 | -Mvalues:color=blue -Mvalues:sound=beep -Moptions:debug=true 35 | ``` 36 | 37 | Refer to the https://github.com/hawkular/hawkular-commons/tree/master/hawkular-command-gateway/hawkular-command-gateway-api/src/main/resources/schema[Command Gateway JSON schemas] to know what commands can be passed (the command name is the name of the schema) 38 | and what parameters those commands support. 39 | -------------------------------------------------------------------------------- /hawkular-agent-command-cli/src/main/resources/logging-debug.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | handlers=java.util.logging.ConsoleHandler 19 | 20 | java.util.logging.ConsoleHandler.level=FINE 21 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 22 | java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tb %1$td %1$tT.%1$tQ %2$s]%6$s%n 23 | 24 | .level=INFO 25 | org.hawkular.agent.level=FINE 26 | -------------------------------------------------------------------------------- /hawkular-agent-command-cli/src/main/resources/logging.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | handlers=java.util.logging.ConsoleHandler 19 | 20 | java.util.logging.ConsoleHandler.level=FINE 21 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 22 | java.util.logging.SimpleFormatter.format=%4$s: %5$s%6$s%n 23 | 24 | .level=INFO 25 | org.hawkular.agent.level=INFO 26 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/api/HawkularAgentContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.api; 18 | 19 | public interface HawkularAgentContext { 20 | InventoryStorage getInventoryStorage(); 21 | } 22 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/api/HawkularAgentContextImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.api; 18 | 19 | public class HawkularAgentContextImpl implements HawkularAgentContext { 20 | 21 | private final InventoryStorage inventoryStorage; 22 | 23 | public HawkularAgentContextImpl(InventoryStorage inventoryStorage) { 24 | this.inventoryStorage = inventoryStorage; 25 | 26 | } 27 | 28 | @Override 29 | public InventoryStorage getInventoryStorage() { 30 | return inventoryStorage; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/api/InventoryListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.api; 18 | 19 | import org.hawkular.agent.monitor.protocol.Session; 20 | 21 | /** 22 | * A listener for changes in the inventory of resources maintained by the present agent. 23 | * 24 | * @author Peter Palaga 25 | */ 26 | public interface InventoryListener { 27 | /** 28 | * Notifies this listener that some resources were added, modified or removed to the monitored endpoint. 29 | * 30 | * @param event the {@link InventoryEvent} 31 | */ 32 | > void receivedEvent(InventoryEvent event); 33 | } 34 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/api/InventoryStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.api; 18 | 19 | public interface InventoryStorage extends InventoryListener { 20 | } -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/api/NotificationPayloadBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.api; 18 | 19 | import org.hawkular.client.api.Notification; 20 | import org.hawkular.client.api.NotificationType; 21 | 22 | /** 23 | * When the notification data is all added call {@link #toPayload()} 24 | * to get the payload message that can be used to send to the storage backend via the storage adapter. 25 | */ 26 | public interface NotificationPayloadBuilder { 27 | 28 | /** 29 | * Add the NotificationType for the notification. 30 | * 31 | * @param notificationType Not Null 32 | */ 33 | void addNotificationType(NotificationType notificationType); 34 | 35 | /** 36 | * Add a property supported for the given notification type. 37 | * 38 | * @param name property name 39 | * @param value the string value 40 | */ 41 | void addProperty(String key, String value); 42 | 43 | /** 44 | * @return the payload in a format suitable for the storage adapter. 45 | */ 46 | Notification toPayload(); 47 | } 48 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/api/NotificationStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.api; 18 | 19 | public interface NotificationStorage { 20 | /** 21 | * @return a builder object suitable for wrapping metric data in a proper payload 22 | * message format to be sent to the storage backend. 23 | */ 24 | NotificationPayloadBuilder createNotificationPayloadBuilder(); 25 | 26 | /** 27 | * Sends the notification found in the given builder. 28 | * This is an asynchronous call. But if a waitMillis is provided, it indicates the caller is willing 29 | * to wait up to that amount of milliseconds for the send to complete before returning. 30 | * 31 | * @param payloadBuilder contains the notification to send 32 | * @param waitMillis the amount of milliseconds to wait for the send to complete before returning (0==no wait) 33 | */ 34 | void store(NotificationPayloadBuilder payloadBuilder, long waitMillis); 35 | } -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | import org.hawkular.bus.common.BasicMessage; 20 | import org.hawkular.bus.common.BasicMessageWithExtraData; 21 | import org.hawkular.bus.common.BinaryData; 22 | 23 | public interface Command { 24 | 25 | /** 26 | * Performs the command for the server. A non-null return value will be sent back to the server. 27 | * 28 | * @param envelope the request that describes what needs to be executed eventually with attached {@link BinaryData} 29 | * @param binaryData if not null, this contains extra binary data that came across with the command request 30 | * @param context contains data that can help commands do their job 31 | * @return the results of the command that need to be sent back to the server; if null, nothing will be sent back. 32 | * @throws Exception if failed to execute the command 33 | */ 34 | BasicMessageWithExtraData execute(BasicMessageWithExtraData envelope, CommandContext context) 35 | throws Exception; 36 | } 37 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/CommandContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import org.hawkular.agent.monitor.config.AgentCoreEngineConfiguration; 23 | import org.hawkular.agent.monitor.service.AgentCoreEngine; 24 | import org.hawkular.bus.common.BasicMessage; 25 | import org.hawkular.bus.common.BasicMessageWithExtraData; 26 | 27 | public class CommandContext { 28 | 29 | /** 30 | * This listener is called after the command's response has been sent. 31 | */ 32 | public interface ResponseSentListener { 33 | void onSend(BasicMessageWithExtraData response, Exception sendError); 34 | } 35 | 36 | private final FeedCommProcessor feedComm; 37 | private final AgentCoreEngine agentCoreEngine; 38 | private final List sentListeners; 39 | 40 | public CommandContext( 41 | FeedCommProcessor feedCommProcessor, 42 | AgentCoreEngine agentCoreEngine) { 43 | this.feedComm = feedCommProcessor; 44 | this.agentCoreEngine = agentCoreEngine; 45 | this.sentListeners = new ArrayList<>(0); 46 | } 47 | 48 | /** 49 | * @return the object that can be used to send data back to the server 50 | */ 51 | public FeedCommProcessor getFeedCommProcessor() { 52 | return feedComm; 53 | } 54 | 55 | public AgentCoreEngineConfiguration getAgentCoreEngineConfiguration() { 56 | return agentCoreEngine.getConfiguration(); 57 | } 58 | 59 | public AgentCoreEngine getAgentCoreEngine() { 60 | return agentCoreEngine; 61 | } 62 | 63 | public void addResponseSentListener(ResponseSentListener listener) { 64 | this.sentListeners.add(listener); 65 | } 66 | 67 | List getResponseSentListeners() { 68 | return this.sentListeners; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/EchoCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | import org.hawkular.bus.common.BasicMessageWithExtraData; 20 | import org.hawkular.cmdgw.api.EchoRequest; 21 | import org.hawkular.cmdgw.api.EchoResponse; 22 | 23 | public class EchoCommand implements Command { 24 | public static final Class REQUEST_CLASS = EchoRequest.class; 25 | 26 | @Override 27 | public BasicMessageWithExtraData execute(BasicMessageWithExtraData envelope, 28 | CommandContext context) { 29 | String reply = String.format("Hawkular Agent Echo: [%s]", envelope.getBasicMessage().getEchoMessage()); 30 | 31 | // return the response 32 | EchoResponse echoResponse = new EchoResponse(); 33 | echoResponse.setReply(reply); 34 | return new BasicMessageWithExtraData<>(echoResponse, envelope.getBinaryData()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/ExecuteAgnosticOperationCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | import org.hawkular.bus.common.BasicMessageWithExtraData; 20 | import org.hawkular.cmdgw.api.ExecuteOperationRequest; 21 | import org.hawkular.cmdgw.api.ExecuteOperationResponse; 22 | 23 | /** 24 | * Execute an operation on a resource which can be either a DMR or JMX resource. 25 | */ 26 | public class ExecuteAgnosticOperationCommand extends 27 | AbstractAgnosticResourcePathCommand { 28 | public static final Class REQUEST_CLASS = ExecuteOperationRequest.class; 29 | 30 | public ExecuteAgnosticOperationCommand() { 31 | super("Execute Operation", "Any Resource"); 32 | } 33 | 34 | @Override 35 | protected ExecuteOperationResponse createResponse() { 36 | return new ExecuteOperationResponse(); 37 | } 38 | 39 | @Override 40 | protected AbstractDMRResourcePathCommand getDMRCommand() { 41 | return new ExecuteDMROperationCommand(); 42 | } 43 | 44 | @Override 45 | protected AbstractJMXResourcePathCommand getJMXCommand() { 46 | return new ExecuteJMXOperationCommand(); 47 | } 48 | 49 | @Override 50 | protected String getOperationName(BasicMessageWithExtraData envelope) { 51 | return envelope.getBasicMessage().getOperationName(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/GenericErrorResponseCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | import org.hawkular.agent.monitor.log.AgentLoggers; 20 | import org.hawkular.agent.monitor.log.MsgLogger; 21 | import org.hawkular.bus.common.BasicMessage; 22 | import org.hawkular.bus.common.BasicMessageWithExtraData; 23 | import org.hawkular.cmdgw.api.GenericErrorResponse; 24 | 25 | /** 26 | * The server is responding to our agent with some generic error message, probably due to some error condition that 27 | * caused the server not be able to service one of our requests. 28 | */ 29 | public class GenericErrorResponseCommand implements Command { 30 | private static final MsgLogger log = AgentLoggers.getLogger(GenericErrorResponseCommand.class); 31 | public static final Class REQUEST_CLASS = GenericErrorResponse.class; 32 | 33 | @Override 34 | public BasicMessageWithExtraData execute(BasicMessageWithExtraData envelope, 35 | CommandContext context) throws Exception { 36 | GenericErrorResponse errorResponse = envelope.getBasicMessage(); 37 | String errorMessage = errorResponse.getErrorMessage(); 38 | String stackTrace = errorResponse.getStackTrace(); 39 | 40 | log.warnReceivedGenericErrorResponse(errorMessage, stackTrace); 41 | 42 | return null; // nothing to send back 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/InvalidCommandRequestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | /** 20 | * An exception that commands can throw if they receive an invalid request. 21 | * 22 | * @author Peter Palaga 23 | */ 24 | public class InvalidCommandRequestException extends Exception { 25 | 26 | private static final long serialVersionUID = -3482329012488512371L; 27 | 28 | public InvalidCommandRequestException() { 29 | super(); 30 | } 31 | 32 | public InvalidCommandRequestException(String message) { 33 | super(message); 34 | } 35 | 36 | public InvalidCommandRequestException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public InvalidCommandRequestException(String message, Throwable cause, boolean enableSuppression, 41 | boolean writableStackTrace) { 42 | super(message, cause, enableSuppression, writableStackTrace); 43 | } 44 | 45 | public InvalidCommandRequestException(Throwable cause) { 46 | super(cause); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/RemoveDatasourceCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | import org.hawkular.agent.monitor.config.AgentCoreEngineConfiguration.AbstractEndpointConfiguration; 20 | import org.hawkular.agent.monitor.inventory.MonitoredEndpoint; 21 | import org.hawkular.bus.common.BasicMessageWithExtraData; 22 | import org.hawkular.cmdgw.api.RemoveDatasourceRequest; 23 | import org.hawkular.cmdgw.api.RemoveDatasourceResponse; 24 | import org.hawkular.dmrclient.DatasourceJBossASClient; 25 | 26 | /** 27 | * @author Peter Palaga 28 | */ 29 | public class RemoveDatasourceCommand 30 | extends AbstractRemoveModelNodeCommand { 31 | 32 | private static final String DATASOURCE_ENTITY_TYPE = "Datasource"; 33 | public static final Class REQUEST_CLASS = RemoveDatasourceRequest.class; 34 | 35 | public RemoveDatasourceCommand() { 36 | super(DATASOURCE_ENTITY_TYPE); 37 | } 38 | 39 | @Override 40 | protected RemoveDatasourceResponse createResponse() { 41 | return new RemoveDatasourceResponse(); 42 | } 43 | 44 | @Override 45 | protected void validate(String modelNodePath, BasicMessageWithExtraData envelope) { 46 | DatasourceJBossASClient.checkDatasourcePath(modelNodePath); 47 | } 48 | 49 | @Override 50 | protected void validate(BasicMessageWithExtraData envelope, 51 | MonitoredEndpoint endpoint) { 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/RemoveJdbcDriverCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | import org.hawkular.agent.monitor.config.AgentCoreEngineConfiguration.AbstractEndpointConfiguration; 20 | import org.hawkular.agent.monitor.inventory.MonitoredEndpoint; 21 | import org.hawkular.bus.common.BasicMessageWithExtraData; 22 | import org.hawkular.cmdgw.api.RemoveJdbcDriverRequest; 23 | import org.hawkular.cmdgw.api.RemoveJdbcDriverResponse; 24 | import org.hawkular.dmrclient.DatasourceJBossASClient; 25 | 26 | /** 27 | * @author Peter Palaga 28 | */ 29 | public class RemoveJdbcDriverCommand 30 | extends AbstractRemoveModelNodeCommand { 31 | 32 | private static final String JDBC_DRIVER_ENTITY_TYPE = "JDBC Driver"; 33 | public static final Class REQUEST_CLASS = RemoveJdbcDriverRequest.class; 34 | 35 | public RemoveJdbcDriverCommand() { 36 | super(JDBC_DRIVER_ENTITY_TYPE); 37 | } 38 | 39 | @Override 40 | protected RemoveJdbcDriverResponse createResponse() { 41 | return new RemoveJdbcDriverResponse(); 42 | } 43 | 44 | @Override 45 | protected void validate(String modelNodePath, BasicMessageWithExtraData envelope) { 46 | DatasourceJBossASClient.checkJdbcDriverPath(modelNodePath); 47 | } 48 | 49 | @Override 50 | protected void validate(BasicMessageWithExtraData envelope, 51 | MonitoredEndpoint endpoint) { 52 | assertLocalDMRServer(endpoint); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/cmd/WebSocketClientBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.cmd; 18 | 19 | import javax.net.ssl.SSLContext; 20 | import javax.net.ssl.X509TrustManager; 21 | 22 | import org.hawkular.agent.monitor.config.AgentCoreEngineConfiguration.StorageAdapterConfiguration; 23 | import org.hawkular.agent.monitor.util.BaseHttpClientGenerator; 24 | 25 | public class WebSocketClientBuilder extends BaseHttpClientGenerator { 26 | 27 | public WebSocketClientBuilder(StorageAdapterConfiguration storageAdapter, SSLContext sslContext, 28 | X509TrustManager x509TrustManager) { 29 | super(new BaseHttpClientGenerator.Configuration.Builder() 30 | .username(storageAdapter.getUsername()) 31 | .password(storageAdapter.getPassword()) 32 | .useSsl(storageAdapter.isUseSSL()) 33 | .sslContext(sslContext) 34 | .x509TrustManager(x509TrustManager) 35 | .keystorePath(storageAdapter.getKeystorePath()) 36 | .keystorePassword(storageAdapter.getKeystorePassword()) 37 | .connectTimeout(storageAdapter.getConnectTimeoutSeconds()) 38 | .readTimeout(0) 39 | .build()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/diagnostics/Diagnostics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.diagnostics; 18 | 19 | import com.codahale.metrics.Meter; 20 | import com.codahale.metrics.MetricRegistry; 21 | import com.codahale.metrics.Timer; 22 | 23 | /** 24 | * Provides diagnostic metrics for the scheduler itself. 25 | */ 26 | public interface Diagnostics { 27 | /** 28 | * @return the registry of all metrics 29 | */ 30 | MetricRegistry getMetricRegistry(); 31 | 32 | /** 33 | * @return the DMR sampling an discovery related diagnostics 34 | */ 35 | ProtocolDiagnostics getDMRDiagnostics(); 36 | 37 | /** 38 | * @return the JMX sampling an discovery related diagnostics 39 | */ 40 | ProtocolDiagnostics getJMXDiagnostics(); 41 | 42 | /** 43 | * @return the platform sampling an discovery related diagnostics 44 | */ 45 | ProtocolDiagnostics getPlatformDiagnostics(); 46 | 47 | /** 48 | * @return tracks how many errors occurred while trying to store data to Hawkular storage 49 | */ 50 | Meter getStorageErrorRate(); 51 | 52 | /** 53 | * @return tracks the number of resources that have been stored/synced in inventory over time 54 | */ 55 | Meter getInventoryRate(); 56 | 57 | /** 58 | * @return time it takes to execute inventory storage requests 59 | */ 60 | Timer getInventoryStorageRequestTimer(); 61 | } 62 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/diagnostics/ProtocolDiagnostics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.diagnostics; 18 | 19 | import com.codahale.metrics.Meter; 20 | import com.codahale.metrics.Timer; 21 | 22 | /** 23 | * Diagnostic metrics for tracking request times and request error rates. 24 | * 25 | * @author Peter Palaga 26 | */ 27 | public final class ProtocolDiagnostics { 28 | private final Meter errorRate; 29 | private final Timer requestTimer; 30 | private final Timer fullDiscoveryScanTimer; 31 | 32 | public ProtocolDiagnostics(Timer requestTimer, Meter errorRate, Timer fullDiscoveryScanTimer) { 33 | super(); 34 | this.requestTimer = requestTimer; 35 | this.errorRate = errorRate; 36 | this.fullDiscoveryScanTimer = fullDiscoveryScanTimer; 37 | } 38 | 39 | /** 40 | * @return tracks the failure rate when performing protocol requests (such as fetching DMR attributes). 41 | */ 42 | public Meter getErrorRate() { 43 | return errorRate; 44 | } 45 | 46 | /** 47 | * @return tracks the time protocol requests take 48 | */ 49 | public Timer getRequestTimer() { 50 | return requestTimer; 51 | } 52 | 53 | /** 54 | * @return tracks the time it takes to perform a full discovery scan 55 | */ 56 | public Timer getFullDiscoveryScanTimer() { 57 | return fullDiscoveryScanTimer; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/AttributeLocationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | /** 20 | * This abstract class simply is here as a common way for subclasses to be provided 21 | * an attribute location. Extending subclasses become {@link NamedObject}s as well. 22 | * 23 | * @author Peter Palaga 24 | */ 25 | public abstract class AttributeLocationProvider extends NamedObject { 26 | private final AttributeLocation attributeLocation; 27 | 28 | public AttributeLocationProvider(ID id, Name name, AttributeLocation attributeLocation) { 29 | super(id, name); 30 | if (attributeLocation == null) { 31 | throw new IllegalArgumentException( 32 | "Cannot create a new [" + getClass().getName() + "] with a null attributeLocation"); 33 | } 34 | this.attributeLocation = attributeLocation; 35 | } 36 | 37 | public AttributeLocation getAttributeLocation() { 38 | return attributeLocation; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/ID.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | /** 20 | * Can be used to identify object instances. 21 | */ 22 | public class ID implements Comparable { 23 | 24 | public static final ID NULL_ID = new ID(null); 25 | 26 | private final String id; 27 | 28 | public ID(String id) { 29 | this.id = id != null && id.endsWith("/") ? id.substring(0, id.length() - 1) + '~' : id; 30 | } 31 | 32 | /** 33 | * @return the actual ID string, or null if this object represents a null ID. 34 | */ 35 | public String getIDString() { 36 | return this.id; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object obj) { 41 | if (this == obj) { 42 | return true; 43 | } 44 | 45 | if (obj == null) { 46 | return false; 47 | } 48 | 49 | if (!(obj instanceof ID)) { 50 | return false; 51 | } 52 | String thisIDString = this.id; 53 | String thatIDString = ((ID) obj).id; 54 | if (thisIDString == null) { 55 | return thatIDString == null; 56 | } 57 | return thisIDString.equals(thatIDString); 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | String i = getIDString(); 63 | return (i != null) ? i.hashCode() : 0; 64 | } 65 | 66 | /** 67 | * @return the same string that is returned by {@link #getIDString()}. 68 | */ 69 | @Override 70 | public String toString() { 71 | return getIDString(); 72 | } 73 | 74 | @Override 75 | public int compareTo(ID other) { 76 | return this.id.compareTo(other.id); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/MetricType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.inventory.api.model.MetricUnit; 22 | 23 | /** 24 | * Metadata for a type of metric. 25 | * 26 | * @param the type of the protocol specific location typically a subclass of {@link NodeLocation} 27 | */ 28 | public final class MetricType extends MeasurementType { 29 | 30 | private final MetricUnit metricUnits; 31 | 32 | public MetricType( 33 | ID id, 34 | Name name, 35 | AttributeLocation location, 36 | MetricUnit metricUnits, 37 | SupportedMetricType metricType, 38 | String metricFamily, 39 | Map metricLabels, 40 | String metricExpression) { 41 | super(id, name, metricType, location, metricFamily, metricLabels, metricExpression); 42 | this.metricUnits = metricUnits; 43 | } 44 | 45 | public MetricUnit getMetricUnits() { 46 | return metricUnits; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/Name.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | /** 20 | * @author John Mazzitelli 21 | */ 22 | public class Name implements Comparable { 23 | private final String name; 24 | 25 | public Name(String name) { 26 | this.name = name; 27 | } 28 | 29 | public String getNameString() { 30 | return this.name; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object obj) { 35 | if (this == obj) { 36 | return true; 37 | } 38 | 39 | if (obj == null) { 40 | return false; 41 | } 42 | 43 | if (!(obj instanceof Name)) { 44 | return false; 45 | } 46 | String thisName = this.name; 47 | String thatName = ((Name) obj).name; 48 | if (thisName == null) { 49 | return thatName == null; 50 | } 51 | return thisName.equals(thatName); 52 | } 53 | 54 | @Override 55 | public int hashCode() { 56 | String n = getNameString(); 57 | return (n != null) ? n.hashCode() : 0; 58 | } 59 | 60 | /** 61 | * @return the same as {@link #getNameString()} 62 | */ 63 | @Override 64 | public String toString() { 65 | return getNameString(); 66 | } 67 | 68 | @Override 69 | public int compareTo(Name other) { 70 | return this.name.compareTo(other.name); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/NameSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | import java.util.Collections; 20 | import java.util.HashSet; 21 | import java.util.Set; 22 | 23 | /** 24 | * A generic named, disableable collection of other names. 25 | */ 26 | public class NameSet { 27 | 28 | public static class NameSetBuilder { 29 | private boolean enabled = true; 30 | private Name name; 31 | private Set nameSet = new HashSet<>(); 32 | 33 | private NameSetBuilder() { 34 | super(); 35 | } 36 | 37 | public NameSet build() { 38 | return new NameSet(name, enabled, Collections.unmodifiableSet(nameSet)); 39 | } 40 | 41 | public NameSetBuilder enabled(boolean enabled) { 42 | this.enabled = enabled; 43 | return this; 44 | } 45 | 46 | public NameSetBuilder nameOfSet(Name setName) { 47 | this.name = setName; 48 | return this; 49 | } 50 | 51 | public NameSetBuilder name(Name name) { 52 | this.nameSet.add(name); 53 | return this; 54 | } 55 | } 56 | 57 | public static NameSetBuilder builder() { 58 | return new NameSetBuilder(); 59 | } 60 | 61 | private final Name name; 62 | private final boolean enabled; 63 | private final Set nameSet; 64 | 65 | private NameSet(Name name, boolean enabled, Set nameSet) { 66 | this.name = name; 67 | this.enabled = enabled; 68 | this.nameSet = nameSet; 69 | } 70 | 71 | public Name getName() { 72 | return name; 73 | } 74 | 75 | public Set getNameSet() { 76 | return nameSet; 77 | } 78 | 79 | public boolean isEnabled() { 80 | return enabled; 81 | } 82 | 83 | public boolean isDisabledOrEmpty() { 84 | return !isEnabled() || nameSet == null || nameSet.isEmpty(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/NamedObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | /** 20 | * An object that has an associated name as well as an ID. 21 | * 22 | * @author John Mazzitelli 23 | */ 24 | public abstract class NamedObject extends IDObject { 25 | private final Name name; 26 | 27 | /** 28 | * Creates a named object. 29 | * 30 | * @param id the id of the object; if null, name will be used as its ID 31 | * @param name the name of the object; must not be null - typically this is determined 32 | * from the agent configuration as defined in the standalone.xml configuration. 33 | */ 34 | public NamedObject(ID id, Name name) { 35 | super((id != null && !id.equals(ID.NULL_ID)) ? id : (name != null) ? new ID(name.getNameString()) : null); 36 | 37 | if (name == null) { 38 | throw new IllegalArgumentException("name cannot be null"); 39 | } 40 | if (name.getNameString() == null) { 41 | throw new IllegalArgumentException("name string cannot be null"); 42 | } 43 | this.name = name; 44 | } 45 | 46 | public Name getName() { 47 | return this.name; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/NodeLocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | import org.hawkular.agent.monitor.protocol.Driver; 20 | 21 | /** 22 | * Just a marker interface for protocol specific node locations. A node location should entail some protocol specific 23 | * object (call it a "path") that can be used to retrieve one or mode nodes using a protocol specific {@link Driver}. 24 | *

25 | * Note that platform specific paths 26 | *

    27 | *
  • can be either relative to some other base path or absolute 28 | *
  • can contain wildcards so that they can be used to retrieve a set of matching nodes. 29 | *
30 | * @author Peter Palaga 31 | */ 32 | public interface NodeLocation { 33 | } 34 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/OperationParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | /** 20 | * Immutable object that describes a single operation parameter. 21 | * 22 | * @author hrupp 23 | */ 24 | public class OperationParam { 25 | 26 | private final String name; 27 | private final String type; 28 | private final String description; 29 | private final String defaultValue; 30 | private final Boolean required; 31 | 32 | public OperationParam(String name, String type, String description, String defaultValue, Boolean required) { 33 | this.name = name; 34 | this.type = type; 35 | this.description = description; 36 | this.defaultValue = defaultValue; 37 | this.required = required; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public String getType() { 45 | return type; 46 | } 47 | 48 | public String getDescription() { 49 | return description; 50 | } 51 | 52 | public String getDefaultValue() { 53 | return defaultValue; 54 | } 55 | 56 | public Boolean isRequired() { 57 | return required; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | StringBuilder str = new StringBuilder("OperationParam: "); 63 | str.append("name=[").append(this.name); 64 | str.append("], type=[").append(this.type); 65 | str.append("], description=[").append(this.description); 66 | str.append("], defaultValue=[").append(this.defaultValue); 67 | str.append("], required=[").append(this.required); 68 | str.append("]"); 69 | return str.toString(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/ResourceConfigurationPropertyInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | /** 20 | * @author John Mazzitelli 21 | * 22 | * @param the type of the protocol specific location, typically a subclass of {@link NodeLocation} 23 | */ 24 | public final class ResourceConfigurationPropertyInstance extends Instance> { 25 | 26 | private final String value; 27 | 28 | public ResourceConfigurationPropertyInstance(ID id, Name name, AttributeLocation attributeLocation, 29 | ResourceConfigurationPropertyType type, String value) { 30 | super(id, name, attributeLocation, type); 31 | this.value = value; 32 | } 33 | 34 | // copy-constructor 35 | public ResourceConfigurationPropertyInstance(ResourceConfigurationPropertyInstance original, boolean disown) { 36 | super(original, disown); 37 | this.value = original.value; 38 | } 39 | 40 | public String getValue() { 41 | return value; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return String.format("%s[value=%s]", super.toString(), getValue()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/ResourceConfigurationPropertyType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | /** 20 | * @author John Mazzitelli 21 | * 22 | * @param the type of the protocol specific location, typically a subclass of {@link NodeLocation} 23 | */ 24 | public final class ResourceConfigurationPropertyType extends AttributeLocationProvider { 25 | 26 | public ResourceConfigurationPropertyType(ID id, Name name, AttributeLocation attributeLocation) { 27 | super(id, name, attributeLocation); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/inventory/SupportedMetricType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.hawkular.agent.monitor.inventory; 19 | 20 | /** 21 | * These are the different types of metrics supported by the metric storage system (Prometheus). 22 | */ 23 | public enum SupportedMetricType { 24 | COUNTER, GAUGE, SUMMARY, HISTOGRAM; 25 | } 26 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/log/AgentLoggers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.log; 18 | 19 | import org.jboss.logging.Logger; 20 | 21 | /** 22 | * @author Peter Palaga 23 | */ 24 | public final class AgentLoggers { 25 | 26 | public static MsgLogger getLogger(Class clazz) { 27 | return Logger.getMessageLogger(MsgLogger.class, clazz.getName()); 28 | } 29 | 30 | private AgentLoggers() { 31 | super(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/prometheus/WebServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.prometheus; 18 | 19 | import java.io.File; 20 | import java.net.InetSocketAddress; 21 | 22 | import io.prometheus.client.CollectorRegistry; 23 | import io.prometheus.client.exporter.HTTPServer; 24 | import io.prometheus.client.hotspot.DefaultExports; 25 | 26 | public class WebServer { 27 | 28 | private HTTPServer server; 29 | private JmxCollector jmxCollector; 30 | 31 | public synchronized void start(String[] args) throws Exception { 32 | if (server != null) { 33 | return; 34 | } 35 | 36 | if (args.length < 2) { 37 | throw new Exception("Usage: WebServer <[hostname:]port> "); 38 | } 39 | String[] hostnamePort = args[0].split(":"); 40 | int port; 41 | InetSocketAddress socket; 42 | 43 | if (hostnamePort.length == 2) { 44 | port = Integer.parseInt(hostnamePort[1]); 45 | socket = new InetSocketAddress(hostnamePort[0], port); 46 | } else { 47 | port = Integer.parseInt(hostnamePort[0]); 48 | socket = new InetSocketAddress(port); 49 | } 50 | 51 | jmxCollector = new JmxCollector(new File(args[1])); 52 | jmxCollector.register(); 53 | 54 | DefaultExports.initialize(); 55 | server = new HTTPServer(socket, CollectorRegistry.defaultRegistry, true); // true == daemon 56 | } 57 | 58 | public synchronized void stop() { 59 | if (server == null) { 60 | return; 61 | } 62 | 63 | try { 64 | CollectorRegistry.defaultRegistry.unregister(jmxCollector); 65 | server.stop(); 66 | } finally { 67 | server = null; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/protocol/ProtocolException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.protocol; 18 | 19 | /** 20 | * Thrown on any problems related to the protocol specific access to resources. 21 | * 22 | * @author Peter Palaga 23 | */ 24 | public class ProtocolException extends Exception { 25 | private static final long serialVersionUID = 1L; 26 | 27 | public ProtocolException() { 28 | } 29 | 30 | public ProtocolException(String message) { 31 | super(message); 32 | } 33 | 34 | public ProtocolException(Throwable cause) { 35 | super(cause); 36 | } 37 | 38 | public ProtocolException(String message, Throwable cause) { 39 | super(message, cause); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/protocol/dmr/DMRSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.protocol.dmr; 18 | 19 | import java.io.IOException; 20 | 21 | import org.hawkular.agent.monitor.inventory.MonitoredEndpoint; 22 | import org.hawkular.agent.monitor.inventory.ResourceTypeManager; 23 | import org.hawkular.agent.monitor.protocol.Driver; 24 | import org.hawkular.agent.monitor.protocol.LocationResolver; 25 | import org.hawkular.agent.monitor.protocol.Session; 26 | import org.jboss.as.controller.client.ModelControllerClient; 27 | 28 | /** 29 | * @author Peter Palaga 30 | * @see Session 31 | */ 32 | public class DMRSession extends Session { 33 | 34 | private final ModelControllerClient client; 35 | 36 | public DMRSession(String feedId, 37 | MonitoredEndpoint endpoint, 38 | ResourceTypeManager resourceTypeManager, 39 | Driver driver, 40 | LocationResolver locationResolver, 41 | ModelControllerClient client) { 42 | super(feedId, endpoint, resourceTypeManager, driver, locationResolver); 43 | this.client = client; 44 | } 45 | 46 | /** @see java.io.Closeable#close() */ 47 | @Override 48 | public void close() throws IOException { 49 | if (client != null) { 50 | client.close(); 51 | } 52 | } 53 | 54 | /** 55 | * Returns a native client. Note that the returned client is valid only within the scope of this {@link DMRSession} 56 | * because it gets closed in {@link #close()}. 57 | * 58 | * @return a native client 59 | */ 60 | public ModelControllerClient getClient() { 61 | return client; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/protocol/jmx/JMXDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.protocol.jmx; 18 | 19 | import javax.management.ObjectName; 20 | 21 | import org.hawkular.agent.monitor.diagnostics.ProtocolDiagnostics; 22 | import org.hawkular.agent.monitor.protocol.Driver; 23 | 24 | /** 25 | * Abstract JMX driver that both local and remote JMX drivers extend. 26 | * 27 | * @see Driver 28 | */ 29 | public abstract class JMXDriver implements Driver { 30 | 31 | private final ProtocolDiagnostics diagnostics; 32 | 33 | public JMXDriver(ProtocolDiagnostics diagnostics) { 34 | this.diagnostics = diagnostics; 35 | } 36 | 37 | public abstract Object executeOperation(ObjectName objName, String opName, Object[] args, Class[] signature) 38 | throws Exception; 39 | 40 | protected ProtocolDiagnostics getDiagnostics() { 41 | return diagnostics; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/protocol/jmx/JMXSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.protocol.jmx; 18 | 19 | import java.io.IOException; 20 | 21 | import org.hawkular.agent.monitor.inventory.MonitoredEndpoint; 22 | import org.hawkular.agent.monitor.inventory.ResourceTypeManager; 23 | import org.hawkular.agent.monitor.protocol.Driver; 24 | import org.hawkular.agent.monitor.protocol.LocationResolver; 25 | import org.hawkular.agent.monitor.protocol.Session; 26 | 27 | /** 28 | * A session for any JMX endpoint (local or remote) 29 | * @see Session 30 | */ 31 | public class JMXSession 32 | extends Session { 33 | 34 | public JMXSession(String feedId, 35 | MonitoredEndpoint endpoint, 36 | ResourceTypeManager resourceTypeManager, 37 | Driver driver, 38 | LocationResolver locationResolver) { 39 | super(feedId, endpoint, resourceTypeManager, driver, locationResolver); 40 | } 41 | 42 | @Override 43 | public void close() throws IOException { 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/service/ServiceStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.service; 18 | 19 | /** 20 | * @author Peter Palaga 21 | */ 22 | public enum ServiceStatus { 23 | INITIAL, STARTING, RUNNING, STOPPING, STOPPED; 24 | 25 | public void assertInitialOrStopped(Class cl, String action) throws IllegalStateException { 26 | if (this != INITIAL && this != STOPPED) { 27 | throw new IllegalStateException("[" + cl.getName() + "] must be in state [" + INITIAL + "] or [" 28 | + STOPPED + "] rather than [" + this + "] to perform [" + action + "]"); 29 | } 30 | } 31 | 32 | public void assertRunning(Class cl, String action) throws IllegalStateException { 33 | if (this != RUNNING) { 34 | throw new IllegalStateException("[" + cl.getName() + "] must be in state [" + RUNNING + "] rather than [" 35 | + this + "] to perform [" + action + "]"); 36 | } 37 | } 38 | 39 | /** 40 | * @return true if the service is stopped or will be stopped soon. Initial mode is considered stopped. 41 | */ 42 | public boolean isStoppingOrStopped() { 43 | return this == STOPPING || this == STOPPED || this == INITIAL; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/storage/InventoryStorageProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.storage; 18 | 19 | import org.hawkular.agent.monitor.api.InventoryEvent; 20 | import org.hawkular.agent.monitor.api.InventoryStorage; 21 | import org.hawkular.agent.monitor.protocol.Session; 22 | 23 | /** 24 | * A proxy that delegates to a {@link StorageAdapter}. 25 | */ 26 | public class InventoryStorageProxy implements InventoryStorage { 27 | 28 | private StorageAdapter storageAdapter; 29 | 30 | public InventoryStorageProxy() { 31 | } 32 | 33 | public void setStorageAdapter(StorageAdapter storageAdapter) { 34 | this.storageAdapter = storageAdapter; 35 | } 36 | 37 | @Override 38 | public > void receivedEvent(InventoryEvent event) { 39 | if (storageAdapter == null) { 40 | throw new IllegalStateException("Storage infrastructure is not ready yet"); 41 | } 42 | storageAdapter.receivedEvent(event); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/storage/NotificationPayloadBuilderImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.storage; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.hawkular.agent.monitor.api.NotificationPayloadBuilder; 23 | import org.hawkular.client.api.Notification; 24 | import org.hawkular.client.api.NotificationType; 25 | 26 | public class NotificationPayloadBuilderImpl implements NotificationPayloadBuilder { 27 | 28 | private NotificationType notificationType; 29 | private Map properties = new HashMap<>(); 30 | 31 | @Override 32 | public void addNotificationType(NotificationType notificationType) { 33 | this.notificationType = notificationType; 34 | 35 | } 36 | 37 | @Override 38 | public void addProperty(String name, String value) { 39 | properties.put(name, value); 40 | } 41 | 42 | @Override 43 | public Notification toPayload() { 44 | return new Notification(notificationType, properties); 45 | } 46 | } -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/storage/StorageAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.storage; 18 | 19 | import org.hawkular.agent.monitor.api.InventoryStorage; 20 | import org.hawkular.agent.monitor.api.NotificationStorage; 21 | import org.hawkular.agent.monitor.config.AgentCoreEngineConfiguration; 22 | import org.hawkular.agent.monitor.diagnostics.Diagnostics; 23 | 24 | public interface StorageAdapter extends InventoryStorage, NotificationStorage { 25 | 26 | /** 27 | * Initializes the storage adapter. 28 | * 29 | * @param feedId identifies the feed that is storing data 30 | * @param config the configuration of the storage adapter 31 | * @param diag the object used to track internal diagnostic data for the storage adapter 32 | * @param httpClientBuilder used to communicate with the storage server 33 | */ 34 | void initialize( 35 | String feedId, 36 | AgentCoreEngineConfiguration.StorageAdapterConfiguration config, 37 | Diagnostics diag, 38 | HttpClientBuilder httpClientBuilder); 39 | 40 | /** 41 | * Clean up and stop whatever the storage adapter is doing. 42 | */ 43 | void shutdown(); 44 | 45 | /** 46 | * @return the storage adapter's configuration settings 47 | */ 48 | AgentCoreEngineConfiguration.StorageAdapterConfiguration getStorageAdapterConfiguration(); 49 | } 50 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/util/Consumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.util; 18 | 19 | public interface Consumer { 20 | void accept(T result); 21 | void report(Throwable e); 22 | } -------------------------------------------------------------------------------- /hawkular-agent-core/src/main/java/org/hawkular/agent/monitor/util/ThreadFactoryGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.util; 18 | 19 | import java.lang.Thread.UncaughtExceptionHandler; 20 | import java.util.concurrent.ThreadFactory; 21 | 22 | import org.jboss.threads.JBossThreadFactory; 23 | 24 | /** 25 | * @author John Mazzitelli 26 | */ 27 | public class ThreadFactoryGenerator { 28 | public static final ThreadFactory generateFactory(boolean daemon, String threadGroupName) { 29 | String namePattern = "%G-%t"; 30 | UncaughtExceptionHandler uncaughtExceptionHandler = null; 31 | Integer initialPriority = null; 32 | Long stackSize = null; 33 | return new JBossThreadFactory( 34 | new ThreadGroup(threadGroupName), 35 | daemon, 36 | initialPriority, 37 | namePattern, 38 | uncaughtExceptionHandler, 39 | stackSize, 40 | null); // this last param is ignored according to docs. 41 | // see: https://github.com/jbossas/jboss-threads/blob/2.2/src/main/java/org/jboss/threads/JBossThreadFactory.java#L90 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/test/java/org/hawkular/agent/monitor/inventory/InventoryIdUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.inventory; 18 | 19 | import java.util.Collections; 20 | 21 | import org.hawkular.agent.monitor.config.AgentCoreEngineConfiguration.EndpointConfiguration; 22 | import org.hawkular.agent.monitor.inventory.InventoryIdUtil.ResourceIdParts; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | public class InventoryIdUtilTest { 27 | 28 | @Test 29 | public void testParsingResourceId() { 30 | ID id; 31 | ResourceIdParts parts; 32 | 33 | EndpointConfiguration endpointConfig = new EndpointConfiguration("testmanagedserver", true, 34 | Collections.emptyList(), null, null, null, null, null); 35 | MonitoredEndpoint me = MonitoredEndpoint. of(endpointConfig, 36 | null); 37 | 38 | id = InventoryIdUtil.generateResourceId("fid", me, "/test/id/path"); 39 | Assert.assertEquals("fid~testmanagedserver~/test/id/path", id.toString()); 40 | parts = InventoryIdUtil.parseResourceId(id.getIDString()); 41 | Assert.assertEquals("fid", parts.getFeedId()); 42 | Assert.assertEquals("testmanagedserver", parts.getManagedServerName()); 43 | Assert.assertEquals("/test/id/path", parts.getIdPart()); 44 | 45 | // test that you can have ~ in the last part of the ID 46 | id = InventoryIdUtil.generateResourceId("fid", me, "~/~test/~id/~path"); 47 | Assert.assertEquals("fid~testmanagedserver~~/~test/~id/~path", id.toString()); 48 | parts = InventoryIdUtil.parseResourceId(id.getIDString()); 49 | Assert.assertEquals("fid", parts.getFeedId()); 50 | Assert.assertEquals("testmanagedserver", parts.getManagedServerName()); 51 | Assert.assertEquals("~/~test/~id/~path", parts.getIdPart()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hawkular-agent-core/src/test/java/org/hawkular/agent/monitor/protocol/dmr/DMREndpointServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.monitor.protocol.dmr; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import java.util.UUID; 22 | 23 | import org.junit.Test; 24 | 25 | 26 | /** 27 | * @author Peter Palaga 28 | * 29 | */ 30 | public class DMREndpointServiceTest { 31 | @Test 32 | public void testServerId() { 33 | 34 | String id = DMREndpointService.getServerIdentifier("one", "two", "three", null); 35 | assertEquals("one.two.three", id); 36 | 37 | id = DMREndpointService.getServerIdentifier(null, "two", "three", null); 38 | assertEquals("two.three", id); 39 | 40 | id = DMREndpointService.getServerIdentifier(null, null, "three", null); 41 | assertEquals("three", id); 42 | 43 | id = DMREndpointService.getServerIdentifier(null, null, null, null); 44 | assertEquals("", id); 45 | 46 | id = DMREndpointService.getServerIdentifier("", "two", "three", null); 47 | assertEquals("two.three", id); 48 | 49 | id = DMREndpointService.getServerIdentifier("", "", "three", null); 50 | assertEquals("three", id); 51 | 52 | id = DMREndpointService.getServerIdentifier("", "", "", null); 53 | assertEquals("", id); 54 | 55 | // if server name and node name are the same, only one is added to the full ID 56 | id = DMREndpointService.getServerIdentifier("one", "two", "two", null); 57 | assertEquals("one.two", id); 58 | 59 | id = DMREndpointService.getServerIdentifier("", "two", "two", null); 60 | assertEquals("two", id); 61 | 62 | id = DMREndpointService.getServerIdentifier(null, "two", "two", null); 63 | assertEquals("two", id); 64 | 65 | String uuid = UUID.randomUUID().toString(); 66 | id = DMREndpointService.getServerIdentifier("a", "b", "c", uuid); 67 | assertEquals(uuid, id); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmr/api/DmrApiException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmr.api; 18 | 19 | /** 20 | * @author Peter Palaga 21 | */ 22 | public class DmrApiException extends RuntimeException { 23 | private static final long serialVersionUID = 1047518822601238146L; 24 | 25 | public DmrApiException(String message) { 26 | super(message); 27 | } 28 | 29 | public DmrApiException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | public DmrApiException(Throwable cause) { 34 | super(cause); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmr/api/DmrApiLoggers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmr.api; 18 | 19 | import org.jboss.logging.Logger; 20 | 21 | /** 22 | * @author Peter Palaga 23 | */ 24 | public final class DmrApiLoggers { 25 | 26 | public static MsgLogger getLogger(Class clazz) { 27 | return Logger.getMessageLogger(MsgLogger.class, clazz.getName()); 28 | } 29 | 30 | private DmrApiLoggers() { 31 | super(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmr/api/DmrUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmr.api; 18 | 19 | import java.util.StringTokenizer; 20 | 21 | import org.jboss.dmr.ModelNode; 22 | 23 | /** 24 | * @author Peter Palaga 25 | */ 26 | public class DmrUtils { 27 | public static String toJavaStringLiteral(ModelNode node) { 28 | String in = node.toString(); 29 | StringBuilder result = new StringBuilder(in.length() + in.length()/16); 30 | StringTokenizer st = new StringTokenizer(in, "\n\r"); 31 | boolean first = true; 32 | while (st.hasMoreTokens()) { 33 | String line = st.nextToken(); 34 | /* no newline character at the end of the last line */ 35 | String newLine = st.hasMoreTokens() ? "\\n" : ""; 36 | line = "\"" + line.replace("\"", "\\\"") + newLine + "\" //"; 37 | if (first) { 38 | first = false; 39 | } else { 40 | line = "+ " + line; 41 | } 42 | result.append(line); 43 | } 44 | return result.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmr/api/MsgLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmr.api; 18 | 19 | import org.jboss.logging.BasicLogger; 20 | import org.jboss.logging.Logger; 21 | import org.jboss.logging.annotations.MessageLogger; 22 | import org.jboss.logging.annotations.ValidIdRange; 23 | 24 | @MessageLogger(projectCode = "HAWKDMRCLIENT") 25 | @ValidIdRange(min = 10000, max = 19999) 26 | public interface MsgLogger extends BasicLogger { 27 | MsgLogger LOG = Logger.getMessageLogger(MsgLogger.class, "org.hawkular.dmr"); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmr/api/OperationFailureException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmr.api; 18 | 19 | /** 20 | * @author Peter Palaga 21 | */ 22 | public class OperationFailureException extends DmrApiException { 23 | private static final long serialVersionUID = -8120364704766408172L; 24 | 25 | public OperationFailureException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | 29 | public OperationFailureException(String message) { 30 | super(message); 31 | } 32 | 33 | public OperationFailureException(Throwable cause) { 34 | super(cause); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmr/api/SubsystemDatasourceConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmr.api; 18 | 19 | /** 20 | * Constants specific to datasources subsystem. 21 | * 22 | * @author Peter Palaga 23 | */ 24 | public interface SubsystemDatasourceConstants { 25 | public interface DatasourceNodeCommonConstants { 26 | String DRIVER_NAME = "driver-name"; 27 | String JNDI_NAME = "jndi-name"; 28 | String NAME = "name"; 29 | String PASSWORD = "password"; 30 | String USER_NAME = "user-name"; 31 | String STATISTICS_ENABLED = "statistics-enabled"; 32 | } 33 | 34 | public interface DatasourceNodeConstants extends DatasourceNodeCommonConstants { 35 | String CONNECTION_URL = "connection-url"; 36 | String DRIVER_CLASS = "driver-class"; 37 | } 38 | 39 | public interface XaDatasourceNodeConstants extends DatasourceNodeCommonConstants { 40 | String SECURITY_DOMAIN = "security-domain"; 41 | String XA_DATASOURCE_CLASS = "xa-datasource-class"; 42 | } 43 | 44 | public interface JdbcDriverNodeConstants { 45 | String DRIVER_NAME = "driver-name"; 46 | String DRIVER_CLASS_NAME = "driver-class-name"; 47 | String DRIVER_MODULE_NAME = "driver-module-name"; 48 | String DRIVER_MAJOR_VERSION = "driver-major-version"; 49 | String DRIVER_MINOR_VERSION = "driver-minor-version"; 50 | String DRIVER_XA_DATASOURCE_CLASS_NAME = "driver-xa-datasource-class-name"; 51 | String JDBC_COMPLIANT = "jdbc-compliant"; 52 | } 53 | 54 | String CONNECTION_PROPERTIES = "connection-properties"; 55 | String DATASOURCE = "data-source"; 56 | String DATASOURCES = "datasources"; 57 | 58 | String JDBC_DRIVER = "jdbc-driver"; 59 | String XA_DATASOURCE = "xa-data-source"; 60 | 61 | String XA_DATASOURCE_PROPERTIES = "xa-datasource-properties"; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmr/api/SubsystemLoggingConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmr.api; 18 | 19 | /** 20 | * Constants specific to logging subsystem. 21 | * 22 | * @author Peter Palaga 23 | */ 24 | public interface SubsystemLoggingConstants { 25 | String LOGGING = "logging"; 26 | String LOGGER = "logger"; 27 | interface LoggerNodeConstants { 28 | String CATEGORY = "category"; 29 | String LEVEL = "level"; 30 | String USE_PARENT_HANDLERS = "use-parent-handlers"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmrclient/FailureException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmrclient; 18 | 19 | import org.jboss.dmr.ModelNode; 20 | 21 | /** 22 | * Indicates a failed client request. 23 | * 24 | * @author John Mazzitelli 25 | */ 26 | public class FailureException extends RuntimeException { 27 | private static final long serialVersionUID = 1L; 28 | 29 | private static final String GENERIC_ERROR = "Failed request"; 30 | 31 | public FailureException(ModelNode failureNode) { 32 | super(buildErrorMessage(GENERIC_ERROR, failureNode)); 33 | } 34 | 35 | public FailureException(ModelNode failureNode, String errMsg) { 36 | super(buildErrorMessage(errMsg, failureNode)); 37 | } 38 | 39 | public FailureException(ModelNode failureNode, Throwable cause) { 40 | super(buildErrorMessage(GENERIC_ERROR, failureNode), cause); 41 | } 42 | 43 | public FailureException(ModelNode failureNode, String errMsg, Throwable cause) { 44 | super(buildErrorMessage(errMsg, failureNode), cause); 45 | } 46 | 47 | public FailureException(String errMsg, Throwable cause) { 48 | super((errMsg != null) ? errMsg : GENERIC_ERROR, cause); 49 | } 50 | 51 | public FailureException(String errMsg) { 52 | super((errMsg != null) ? errMsg : GENERIC_ERROR); 53 | } 54 | 55 | public FailureException(Throwable cause) { 56 | super(GENERIC_ERROR, cause); 57 | } 58 | 59 | public FailureException() { 60 | super(GENERIC_ERROR); 61 | } 62 | 63 | private static String buildErrorMessage(String errMsg, ModelNode failureNode) { 64 | if (errMsg == null) { 65 | errMsg = GENERIC_ERROR; 66 | } 67 | 68 | String description = JBossASClient.getFailureDescription(failureNode); 69 | if (description != null) { 70 | errMsg += ": " + description; 71 | } 72 | 73 | return errMsg; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/main/java/org/hawkular/dmrclient/TransactionsJBossASClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.dmrclient; 18 | 19 | import org.jboss.as.controller.client.ModelControllerClient; 20 | import org.jboss.dmr.ModelNode; 21 | 22 | /** 23 | * Provides management of the transactions subsystem. 24 | * 25 | * @author John Mazzitelli 26 | */ 27 | public class TransactionsJBossASClient extends JBossASClient { 28 | 29 | public static final String TRANSACTIONS = "transactions"; 30 | 31 | public TransactionsJBossASClient(ModelControllerClient client) { 32 | super(client); 33 | } 34 | 35 | /** 36 | * Sets the default transaction timeout. 37 | * @param timeoutSecs the new default transaction timeout, in seconds. 38 | * @throws Exception any error 39 | */ 40 | public void setDefaultTransactionTimeout(int timeoutSecs) throws Exception { 41 | final Address address = Address.root().add(SUBSYSTEM, TRANSACTIONS); 42 | final ModelNode req = createWriteAttributeRequest("default-timeout", String.valueOf(timeoutSecs), address); 43 | final ModelNode response = execute(req); 44 | 45 | if (!isSuccess(response)) { 46 | throw new FailureException(response); 47 | } 48 | return; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/test/resources/org/hawkular/dmrclient/modules/complicated.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/test/resources/org/hawkular/dmrclient/modules/minimal.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /hawkular-dmr-client/src/test/resources/org/hawkular/dmrclient/modules/usual.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/hawkular-javaagent-cmdgw-itest/server-provisioning.xml: -------------------------------------------------------------------------------- 1 | 19 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/hawkular-javaagent-cmdgw-itest/src/test/java/org/hawkular/agent/ws/test/ExportJdrCommandITest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.ws.test; 18 | 19 | import org.hawkular.cmdgw.ws.test.TestWebSocketClient; 20 | import org.hawkular.inventory.api.model.Resource; 21 | import org.jboss.as.controller.client.ModelControllerClient; 22 | import org.testng.annotations.Test; 23 | 24 | /** 25 | * @author Juraci Paixão Kröhling 26 | */ 27 | public class ExportJdrCommandITest extends AbstractCommandITest { 28 | public static final String GROUP = "ExportJdrCommandITest"; 29 | 30 | @Test(groups = { GROUP }, dependsOnGroups = { StandaloneDeployApplicationITest.GROUP }) 31 | public void exportJdrCommand() throws Throwable { 32 | waitForHawkularServerToBeReady(); 33 | 34 | Resource wfResource = getHawkularWildFlyServerResource(); 35 | 36 | try (ModelControllerClient ignored = newHawkularModelControllerClient()) { 37 | String req = "ExportJdrRequest={\"authentication\":" + authentication + ", " 38 | + "\"feedId\":\"" + wfResource.getFeedId() + "\"," 39 | + "\"resourceId\":\"" + wfResource.getId() + "\"" 40 | + "}"; 41 | String responsePattern = "\\QExportJdrResponse={\\E.*"; 42 | try (TestWebSocketClient testClient = TestWebSocketClient.builder() 43 | .url(baseGwUri + "/ui/ws") 44 | .readTimeout(240)//seconds 45 | .expectWelcome(req) 46 | .expectGenericSuccess(wfResource.getFeedId()) 47 | .expectBinary(responsePattern, new TestWebSocketClient.ZipWithOneEntryMatcher(), TestWebSocketClient.Answer.CLOSE) 48 | .expectClose() 49 | .build()) { 50 | /* 240 seconds, as JDR takes long to execute */ 51 | testClient.validate(240_000); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/hawkular-javaagent-cmdgw-itest/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | handlers=java.util.logging.ConsoleHandler 19 | java.util.logging.ConsoleHandler.level=DEBUG 20 | 21 | .level=DEBUG 22 | org.hawkular.cmdgw.ws.test.TestWebSocketClient.level = DEBUG 23 | org.hawkular.cmdgw.ws.test.AbstractCommandITest.level = DEBUG 24 | org.hawkular.cmdgw.ws.test.StandaloneDeployApplicationITest.level = DEBUG 25 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/hawkular-javaagent-cmdgw-itest/src/test/resources/org/hawkular/agent/ws/test/JdbcDriverCommandITest.driver-after-add.node.txt: -------------------------------------------------------------------------------- 1 | { 2 | "deployment-name" => undefined, 3 | "driver-class-name" => "com.mysql.jdbc.Driver", 4 | "driver-datasource-class-name" => undefined, 5 | "driver-major-version" => 5, 6 | "driver-minor-version" => 1, 7 | "driver-module-name" => "com.mysql", 8 | "driver-name" => "mysql", 9 | "driver-xa-datasource-class-name" => "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource", 10 | "jdbc-compliant" => true, 11 | "module-slot" => undefined, 12 | "profile" => undefined, 13 | "xa-datasource-class" => undefined 14 | } -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/hawkular-javaagent-domain-itest/server-provisioning-hawkular.xml: -------------------------------------------------------------------------------- 1 | 19 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/hawkular-javaagent-domain-itest/server-provisioning-plain-wildfly.xml: -------------------------------------------------------------------------------- 1 | 19 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/hawkular-javaagent-domain-itest/src/test/java/org/hawkular/agent/test/AbstractDomainITestSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.test; 18 | 19 | import org.hawkular.javaagent.itest.util.AbstractITest; 20 | import org.testng.annotations.AfterSuite; 21 | import org.testng.annotations.BeforeSuite; 22 | import org.testng.annotations.Test; 23 | 24 | @Test(suiteName = AbstractDomainITestSuite.SUITE) 25 | public class AbstractDomainITestSuite extends AbstractITest { 26 | public static final String SUITE = "domain"; 27 | 28 | @BeforeSuite 29 | public void beforeSuiteWaitForHawkularServerToBeReady() throws Throwable { 30 | System.out.println("STARTING JAVAAGENT DOMAIN ITESTS"); 31 | } 32 | 33 | @AfterSuite(alwaysRun = true) 34 | public void afterDomainITestSuite() throws Throwable { 35 | System.out.println("FINISHED JAVAAGENT DOMAIN ITESTS"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/hawkular-javaagent-domain-itest/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | handlers=java.util.logging.ConsoleHandler 19 | java.util.logging.ConsoleHandler.level=FINEST 20 | 21 | .level=INFO 22 | org.hawkular.cmdgw.ws.test.TestWebSocketClient.level = FINEST 23 | org.hawkular.cmdgw.ws.test.AbstractCommandITest.level = FINEST 24 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-all-itests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.hawkular.agent 25 | hawkular-javaagent-itest-parent 26 | 2.0.0.Alpha1-SNAPSHOT 27 | 28 | 29 | hawkular-javaagent-all-itests 30 | pom 31 | 32 | Hawkular Agent: Parent of All Integration Tests 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | hawkular-javaagent-cmdgw-itest 42 | hawkular-javaagent-domain-itest 43 | 44 | 45 | 46 | 47 | itest.debug 48 | 49 | 50 | itest.debug 51 | 52 | 53 | 54 | -Xrunjdwp:transport=dt_socket,address=5007,server=y,suspend=y 55 | -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n 56 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-helloworld-war/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.hawkular.agent 25 | hawkular-javaagent-itest-parent 26 | 2.0.0.Alpha1-SNAPSHOT 27 | 28 | 29 | hawkular-javaagent-helloworld-war 30 | war 31 | 32 | Hawkular Agent: Hello World WAR 33 | A simple web application for testing purposes 34 | 35 | 36 | 37 | 38 | javax.enterprise 39 | cdi-api 40 | provided 41 | 42 | 43 | 44 | org.jboss.spec.javax.servlet 45 | jboss-servlet-api_3.1_spec 46 | provided 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.apache.maven.plugins 55 | maven-checkstyle-plugin 56 | 57 | **/SimpleMXBeanImpl.java 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-helloworld-war/src/main/java/org/hawkular/agent/helloworld/HelloWorldServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.hawkular.agent.helloworld; 19 | 20 | import java.io.IOException; 21 | import java.io.PrintWriter; 22 | 23 | import javax.inject.Inject; 24 | import javax.servlet.ServletConfig; 25 | import javax.servlet.ServletException; 26 | import javax.servlet.annotation.WebServlet; 27 | import javax.servlet.http.HttpServlet; 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | 31 | @WebServlet(value = "/HelloWorld", loadOnStartup = 1) 32 | public class HelloWorldServlet extends HttpServlet { 33 | private static final long serialVersionUID = 1L; 34 | 35 | @Inject 36 | private SimpleMXBeanImpl mbean; 37 | 38 | @Override 39 | public void init(ServletConfig config) throws ServletException { 40 | super.init(config); 41 | mbean.setTestInteger(0); 42 | log("Test MBean has been registered: " + SimpleMXBeanImpl.OBJECT_NAME); 43 | } 44 | 45 | @Override 46 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 47 | Integer num = Integer.valueOf(mbean.getTestInteger().intValue() + 1); 48 | mbean.setTestInteger(num); 49 | resp.setContentType("text/html"); 50 | PrintWriter writer = resp.getWriter(); 51 | writer.println("helloworld

"); 52 | writer.println(mbean.getTestString()); 53 | writer.println(" #"); 54 | writer.println(num); 55 | writer.println("

"); 56 | writer.close(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-helloworld-war/src/main/java/org/hawkular/agent/helloworld/SimpleMXBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.hawkular.agent.helloworld; 19 | 20 | import javax.management.MXBean; 21 | 22 | @MXBean 23 | public interface SimpleMXBean { 24 | 25 | // JMX Attributes 26 | 27 | String getTestString(); 28 | 29 | int getTestIntegerPrimitive(); 30 | Integer getTestInteger(); 31 | void setTestInteger(Integer i); 32 | 33 | boolean getTestBooleanPrimitive(); 34 | Boolean getTestBoolean(); 35 | 36 | long getTestLongPrimitive(); 37 | Long getTestLong(); 38 | 39 | double getTestDoublePrimitive(); 40 | Double getTestDouble(); 41 | 42 | float getTestFloatPrimitive(); 43 | Float getTestFloat(); 44 | 45 | short getTestShortPrimitive(); 46 | Short getTestShort(); 47 | 48 | char getTestCharPrimitive(); 49 | Character getTestChar(); 50 | 51 | byte getTestBytePrimitive(); 52 | Byte getTestByte(); 53 | 54 | // JMX Operations 55 | 56 | void testOperationNoParams(); 57 | String testOperationPrimitive(String s, int i, boolean b, long l, double d, float f, short h, char c, byte y); 58 | String testOperation(String s, Integer i, Boolean b, Long l, Double d, Float f, Short h, Character c, Byte y); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-helloworld-war/src/main/webapp/WEB-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 26 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-helloworld-war/src/main/webapp/WEB-INF/jboss-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | /hawkular/helloworld 24 | 25 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-helloworld-war/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 22 | 23 | 24 | index.html 25 | 26 | 27 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-helloworld-war/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-itest-feature-pack/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 23 | ${project.artifactId} 24 | 25 | zip 26 | 27 | false 28 | 29 | 30 | target/${project.artifactId}-${project.version} 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-itest-feature-pack/feature-pack-build.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-itest-feature-pack/src/main/xsl/configuration/standalone/hawkular-javaagent-itest-subsystems.xsl: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | hawkular-javaagent-itest-messaging-activemq.xml 27 | 28 | 29 | 30 | 31 | hawkular-javaagent-itest-logging.xml 32 | 33 | 34 | 35 | 36 | 37 | hawkular-javaagent-itest-infinispan.xml 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-itest-feature-pack/src/main/xsl/subsystem-templates/hawkular-javaagent-itest-infinispan.xsl: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-itest-feature-pack/src/main/xsl/subsystem-templates/hawkular-javaagent-itest-logging.xsl: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-itest-feature-pack/src/main/xsl/subsystem-templates/hawkular-javaagent-itest-messaging-activemq.xsl: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/hawkular-javaagent-itest-util/src/main/java/org/hawkular/javaagent/itest/util/WildFlyClientConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.hawkular.javaagent.itest.util; 19 | 20 | /** 21 | * Returns information about a plain wildfly that has been setup for the tests. 22 | */ 23 | public class WildFlyClientConfig { 24 | private final String wfHost; 25 | private final int wfManagementPort; 26 | 27 | public WildFlyClientConfig() { 28 | wfHost = System.getProperty("plain-wildfly.bind.address"); 29 | wfManagementPort = Integer.parseInt(System.getProperty("plain-wildfly.management.http.port")); 30 | if (wfHost == null) { 31 | throw new RuntimeException("Plain WildFly Server system properties are not set"); 32 | } 33 | } 34 | 35 | public String getHost() { 36 | return wfHost; 37 | } 38 | 39 | public int getManagementPort() { 40 | return wfManagementPort; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hawkular-javaagent-itest-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.hawkular.agent 25 | hawkular-wildfly-agent-parent 26 | 2.0.0.Alpha1-SNAPSHOT 27 | 28 | 29 | hawkular-javaagent-itest-parent 30 | pom 31 | 32 | Hawkular Agent: Javaagent Integration Tests Parent 33 | 34 | 35 | hawkular-javaagent-helloworld-war 36 | hawkular-javaagent-itest-feature-pack 37 | hawkular-javaagent-itest-util 38 | hawkular-javaagent-all-itests 39 | 40 | 41 | -------------------------------------------------------------------------------- /hawkular-javaagent-wildfly-dist/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 23 | 24 | dist 25 | 26 | zip 27 | 28 | false 29 | 30 | 31 | target 32 | 33 | 34 | ${project.build.finalName}/** 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /hawkular-javaagent-wildfly-dist/server-provisioning-plain-wildfly.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /hawkular-javaagent-wildfly-feature-pack/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 23 | 24 | hawkular-javaagent-wildfly-feature-pack 25 | 26 | zip 27 | 28 | false 29 | 30 | 31 | target/hawkular-javaagent-wildfly-feature-pack-${project.version} 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /hawkular-javaagent-wildfly-feature-pack/feature-pack-build.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /hawkular-javaagent-wildfly-feature-pack/src/main/resources/featurepack/content/standalone/configuration/hawkular-javaagent-config-metrics-only.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: "${hawkular.agent.enabled:true}" 21 | 22 | metrics-exporter: 23 | enabled: true 24 | host: ${hawkular.agent.metrics.host,jboss.bind.address:127.0.0.1} 25 | port: ${hawkular.agent.metrics.port:9779} 26 | config-dir: ${jboss.server.config.dir} 27 | config-file: WF10 28 | proxy: 29 | mode: slave 30 | data-dir: ${jboss.server.data.dir}/hawkular-metrics-exporter 31 | 32 | storage-adapter: 33 | feed-id: "${hawkular.rest.feedId:autogenerate}" 34 | url: "${hawkular.rest.url:http://hawkular-server:8080}" 35 | username: "${env.HAWKULAR_USER,hawkular.rest.username}" 36 | password: "${env.HAWKULAR_PASSWORD,hawkular.rest.password}" 37 | 38 | platform: 39 | enabled: true 40 | #machine-id: my-machine-id-here 41 | -------------------------------------------------------------------------------- /hawkular-javaagent-wildfly-feature-pack/src/main/resources/featurepack/content/standalone/configuration/hawkular-javaagent-config.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: "${hawkular.agent.enabled:true}" 21 | immutable: "${hawkular.agent.immutable:false}" 22 | in-container: "${hawkular.agent.in-container:false}" 23 | auto-discovery-scan-period-secs: ${hawkular.agent.auto-discovery-scan-period-secs:600} 24 | type-version: WF10 25 | 26 | metrics-exporter: 27 | enabled: true 28 | host: ${hawkular.agent.metrics.host,jboss.bind.address:127.0.0.1} 29 | port: ${hawkular.agent.metrics.port:9779} 30 | config-dir: ${jboss.server.config.dir} 31 | config-file: WF10 32 | proxy: 33 | mode: disabled 34 | data-dir: ${jboss.server.data.dir}/hawkular-metrics-exporter 35 | 36 | diagnostics: 37 | enabled: true 38 | interval: 1 39 | time-units: minutes 40 | 41 | storage-adapter: 42 | feed-id: "${hawkular.rest.feedId:autogenerate}" 43 | url: "${hawkular.rest.url:http://hawkular-server:8080}" 44 | username: "${env.HAWKULAR_USER,hawkular.rest.username}" 45 | password: "${env.HAWKULAR_PASSWORD,hawkular.rest.password}" 46 | 47 | # MANAGED SERVERS 48 | 49 | managed-servers: 50 | local-dmr: 51 | name: Local DMR 52 | enabled: true 53 | wait-for: 54 | - name: / 55 | metric-labels: 56 | feed_id: "%FeedId" 57 | 58 | local-jmx: 59 | name: Local JMX 60 | enabled: true 61 | wait-for: 62 | - name: java.lang:type=Runtime 63 | metric-labels: 64 | feed_id: "%FeedId" 65 | 66 | remote-dmr: 67 | - name: Remote DMR 68 | enabled: false 69 | host: 127.0.0.1 70 | port: 9990 71 | username: adminUser 72 | password: adminPass 73 | wait-for: 74 | - name: / 75 | metric-labels: 76 | feed_id: "%FeedId" 77 | 78 | platform: 79 | enabled: true 80 | #machine-id: my-machine-id-here 81 | -------------------------------------------------------------------------------- /hawkular-javaagent/README.adoc: -------------------------------------------------------------------------------- 1 | = Hawkular Java Agent 2 | 3 | This provides a Java Agent that can be installed in any VM via the -javaagent command line argument. 4 | 5 | == Running in your application 6 | 7 | To attach the Hawkular Java Agent to your running application's VM, pass the following option to your Java application's command line: 8 | 9 | ``` 10 | -javaagent:hawkular-javaagent-shaded-*.jar=config=hawkular-javaagent-config.yaml,delay=10" 11 | ``` 12 | 13 | Of course, make sure the path names point to the correct Hawkular Java Agent jar and its configuration file. The `delay` option tells the agent to delay its start up the given number of seconds. This is useful to give your main application time to start up before the agent starts monitoring it. 14 | 15 | == Running in WildFly or EAP 16 | 17 | It is recommended you copy the Hawkular Java Agent jar to the WildFly/EAP `bin/` directory and its configuration file to the `standalone/configuration` directory, but their locations really do not matter so long as you refer to their proper file paths in the `-javaagent` command line argument (e.g. `-javaagent:=config=,delay=10`). 18 | 19 | Due to the way the logging implementations are loaded, you must change your WildFly/EAP server configuration slightly: 20 | 21 | `standalone.conf`: 22 | 23 | ``` 24 | # Hawkular Java Agent: Add "org.jboss.logmanager" to the JBoss Modules system packages 25 | if [ "x$JBOSS_MODULES_SYSTEM_PKGS" = "x" ]; then 26 | JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,org.jboss.logmanager" 27 | fi 28 | 29 | # Hawkular Java Agent: 30 | # Explicitly tell the VM to use the JBoss Log Manager via -Djava.util.logging.manager system property. 31 | # Use the -javaagent VM option to load the Hawkular Java Agent with its config file. 32 | JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager -javaagent:$JBOSS_HOME/bin/hawkular-javaagent-*.jar=config=$JBOSS_HOME/standalone/configuration/hawkular-javaagent-config.yaml,delay=10" 33 | ``` 34 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/JavaAgentMXBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent; 18 | 19 | import javax.management.MXBean; 20 | 21 | @MXBean 22 | public interface JavaAgentMXBean { 23 | 24 | // JMX Attributes 25 | 26 | String getVersion(); 27 | 28 | boolean getImmutable(); 29 | 30 | boolean getInContainer(); 31 | 32 | String getMetricsEndpoints(); 33 | 34 | // JMX Operations 35 | void start(); 36 | 37 | void stop(); 38 | 39 | String status(); 40 | 41 | String fullDiscoveryScan(); 42 | 43 | String inventoryReport(); 44 | } 45 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent; 18 | 19 | import java.lang.reflect.Array; 20 | import java.lang.reflect.Constructor; 21 | 22 | public final class Util { 23 | 24 | /** 25 | * Performs a deep copy of the given array by calling a copy constructor to build clones of each array element. 26 | */ 27 | @SuppressWarnings("unchecked") 28 | public static T[] cloneArray(T[] original) { 29 | if (original == null) { 30 | return null; 31 | } 32 | 33 | try { 34 | Class clazz = original.getClass().getComponentType(); 35 | T[] copy = (T[]) Array.newInstance(clazz, original.length); 36 | if (copy.length != 0) { 37 | Constructor copyConstructor = (Constructor) clazz.getConstructor(clazz); 38 | int i = 0; 39 | for (T t : original) { 40 | copy[i++] = copyConstructor.newInstance(t); 41 | } 42 | } 43 | return copy; 44 | } catch (Exception e) { 45 | throw new RuntimeException("Cannot copy array. Does its type have a copy-constructor? " + original, e); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/cmd/EchoCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.cmd; 18 | 19 | import org.hawkular.agent.monitor.cmd.Command; 20 | import org.hawkular.agent.monitor.cmd.CommandContext; 21 | import org.hawkular.bus.common.BasicMessageWithExtraData; 22 | import org.hawkular.cmdgw.api.EchoRequest; 23 | import org.hawkular.cmdgw.api.EchoResponse; 24 | 25 | /** 26 | * A dummy command placeholder. 27 | */ 28 | public class EchoCommand 29 | implements Command { 30 | 31 | public static final Class REQUEST_CLASS = EchoRequest.class; 32 | 33 | public EchoCommand() { 34 | } 35 | 36 | 37 | @Override 38 | public BasicMessageWithExtraData execute( 39 | BasicMessageWithExtraData envelope, 40 | CommandContext context) 41 | throws Exception { 42 | 43 | // we can cast this because we know our command implementation is only ever installed in a JavaAgentEngine 44 | // JavaAgentEngine javaAgent = (JavaAgentEngine) context.getAgentCoreEngine(); 45 | // Configuration javaAgentConfig = javaAgent.getConfigurationManager().getConfiguration(); 46 | 47 | EchoResponse echoResp = new EchoResponse(); 48 | echoResp.setReply("ECHO:" + envelope.getBasicMessage().getEchoMessage()); 49 | return new BasicMessageWithExtraData(echoResp, null); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/AbstractExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.hawkular.agent.javaagent.config; 19 | 20 | /** 21 | * If a YAML property supports expressions (that is, can have ${x} tokens in its value), the 22 | * property type is going to be a subclass of this. 23 | */ 24 | public abstract class AbstractExpression extends AbstractStringifiedProperty { 25 | 26 | public AbstractExpression() { 27 | super(); 28 | } 29 | 30 | public AbstractExpression(T defaultVal) { 31 | super(defaultVal); 32 | } 33 | 34 | public AbstractExpression(String expr) { 35 | super(expr); 36 | } 37 | 38 | public AbstractExpression(AbstractExpression original) { 39 | super(original); 40 | } 41 | 42 | @Override 43 | public T get() { 44 | String valueAsString = StringPropertyReplacer.replaceProperties(super.getValueAsString()); 45 | return deserialize(valueAsString); 46 | } 47 | 48 | @Override 49 | protected String serialize(T value) { 50 | return value != null ? value.toString() : ""; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/BooleanExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | /** 20 | * The type of any YAML property that is a boolean 21 | * but whose YAML representation can include ${x} expressions. 22 | */ 23 | public class BooleanExpression extends AbstractExpression { 24 | public BooleanExpression() { 25 | super(); 26 | } 27 | 28 | public BooleanExpression(Boolean initialValue) { 29 | super(initialValue); 30 | } 31 | 32 | public BooleanExpression(String expression) { 33 | super(expression); 34 | } 35 | 36 | // copy-constructor 37 | public BooleanExpression(BooleanExpression original) { 38 | super(original); 39 | } 40 | 41 | @Override 42 | protected Boolean deserialize(String valueAsString) { 43 | // make sure the value is either true or false - anything else is an error 44 | if (valueAsString == null) { 45 | throw new IllegalArgumentException("Boolean expression was null"); 46 | } else if (valueAsString.equalsIgnoreCase("true")) { 47 | return Boolean.TRUE; 48 | } else if (valueAsString.equalsIgnoreCase("false")) { 49 | return Boolean.FALSE; 50 | } else { 51 | throw new IllegalArgumentException("Boolean expression was neither true nor false: " + valueAsString); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/Diagnostics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 20 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | @JsonAutoDetect( // 24 | fieldVisibility = Visibility.NONE, // 25 | getterVisibility = Visibility.NONE, // 26 | setterVisibility = Visibility.NONE, // 27 | isGetterVisibility = Visibility.NONE) 28 | public class Diagnostics implements Validatable { 29 | 30 | @JsonProperty 31 | private Boolean enabled = Boolean.TRUE; 32 | 33 | @JsonProperty 34 | private Integer interval = 5; 35 | 36 | @JsonProperty("time-units") 37 | private TimeUnits timeUnits = TimeUnits.minutes; 38 | 39 | public Diagnostics() { 40 | } 41 | 42 | public Diagnostics(Diagnostics original) { 43 | this.enabled = original.enabled; 44 | this.interval = original.interval; 45 | this.timeUnits = original.timeUnits; 46 | } 47 | 48 | @Override 49 | public void validate() throws Exception { 50 | if (interval == null || interval.intValue() < 0) { 51 | throw new Exception("diagnostics interval must be greater than or equal to 0"); 52 | } 53 | } 54 | 55 | public Boolean getEnabled() { 56 | return enabled; 57 | } 58 | 59 | public void setEnabled(Boolean enabled) { 60 | this.enabled = enabled; 61 | } 62 | 63 | public Integer getInterval() { 64 | return interval; 65 | } 66 | 67 | public void setInterval(Integer interval) { 68 | this.interval = interval; 69 | } 70 | 71 | public TimeUnits getTimeUnits() { 72 | return timeUnits; 73 | } 74 | 75 | public void setTimeUnits(TimeUnits timeUnits) { 76 | this.timeUnits = timeUnits; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/IntegerExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | /** 20 | * The type of any YAML property that is an integer 21 | * but whose YAML representation can include ${x} expressions. 22 | */ 23 | public class IntegerExpression extends AbstractExpression { 24 | public IntegerExpression() { 25 | super(); 26 | } 27 | 28 | public IntegerExpression(Integer initialValue) { 29 | super(initialValue); 30 | } 31 | 32 | public IntegerExpression(String expression) { 33 | super(expression); 34 | } 35 | 36 | // copy-constructor 37 | public IntegerExpression(IntegerExpression original) { 38 | super(original); 39 | } 40 | 41 | @Override 42 | protected Integer deserialize(String valueAsString) { 43 | try { 44 | return Integer.valueOf(valueAsString); 45 | } catch (Exception e) { 46 | throw new IllegalArgumentException("Integer expression could not be evaluated to a valid number", e); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/MetricTypeJsonProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | import java.util.Locale; 20 | 21 | import org.hawkular.agent.monitor.inventory.SupportedMetricType; 22 | 23 | public class MetricTypeJsonProperty extends AbstractStringifiedProperty { 24 | public MetricTypeJsonProperty() { 25 | super(); 26 | } 27 | 28 | public MetricTypeJsonProperty(SupportedMetricType initialValue) { 29 | super(initialValue); 30 | } 31 | 32 | public MetricTypeJsonProperty(String valueAsString) { 33 | super(valueAsString); 34 | } 35 | 36 | public MetricTypeJsonProperty(MetricTypeJsonProperty original) { 37 | super(original); 38 | } 39 | 40 | @Override 41 | protected SupportedMetricType deserialize(String valueAsString) { 42 | if (valueAsString != null) { 43 | return SupportedMetricType.valueOf(valueAsString.toUpperCase(Locale.ENGLISH)); 44 | } else { 45 | throw new IllegalArgumentException("Metric type is not specified"); 46 | } 47 | } 48 | 49 | @Override 50 | protected String serialize(SupportedMetricType value) { 51 | if (value != null) { 52 | return value.name().toLowerCase(); 53 | } else { 54 | throw new IllegalArgumentException("Metric type is not specified"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/MetricUnitJsonProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | import java.util.Locale; 20 | 21 | import org.hawkular.inventory.api.model.MetricUnit; 22 | 23 | public class MetricUnitJsonProperty extends AbstractStringifiedProperty { 24 | public MetricUnitJsonProperty() { 25 | super(); 26 | } 27 | 28 | public MetricUnitJsonProperty(MetricUnit initialValue) { 29 | super(initialValue); 30 | } 31 | 32 | public MetricUnitJsonProperty(String valueAsString) { 33 | super(valueAsString); 34 | } 35 | 36 | public MetricUnitJsonProperty(MetricUnitJsonProperty original) { 37 | super(original); 38 | } 39 | 40 | @Override 41 | protected MetricUnit deserialize(String valueAsString) { 42 | if (valueAsString != null) { 43 | return MetricUnit.valueOf(valueAsString.toUpperCase(Locale.ENGLISH)); 44 | } else { 45 | throw new IllegalArgumentException("Measurement units not specified"); 46 | } 47 | } 48 | 49 | @Override 50 | protected String serialize(MetricUnit value) { 51 | if (value != null) { 52 | return value.name().toLowerCase(); 53 | } else { 54 | throw new IllegalArgumentException("Metric type is not specified"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/StringExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | import org.hawkular.agent.javaagent.config.StringExpression.StringValue; 20 | 21 | /** 22 | * The type of any YAML property that is a string 23 | * but whose YAML representation can include ${x} expressions. 24 | */ 25 | public class StringExpression extends AbstractExpression { 26 | public StringExpression() { 27 | super(); 28 | } 29 | 30 | public StringExpression(StringValue initialValue) { 31 | super(initialValue); 32 | } 33 | 34 | public StringExpression(String expression) { 35 | super(expression); 36 | } 37 | 38 | // copy-constructor 39 | public StringExpression(StringExpression original) { 40 | super(original); 41 | } 42 | 43 | @Override 44 | protected StringValue deserialize(String valueAsString) { 45 | return new StringValue(valueAsString); 46 | } 47 | 48 | // we need a type to distinguish from String so our constructor signatures don't clash 49 | public static class StringValue { 50 | private final String value; 51 | 52 | public StringValue(String value) { 53 | this.value = value; 54 | } 55 | 56 | public String toString() { 57 | return this.value; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/TimeUnits.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | import java.util.concurrent.TimeUnit; 20 | 21 | public enum TimeUnits { 22 | milliseconds, seconds, minutes; 23 | 24 | public java.util.concurrent.TimeUnit toJavaTimeUnit() { 25 | switch (this) { 26 | case milliseconds: 27 | return TimeUnit.MILLISECONDS; 28 | case seconds: 29 | return TimeUnit.SECONDS; 30 | case minutes: 31 | return TimeUnit.MINUTES; 32 | default: 33 | throw new IllegalStateException("Invalid enum - cannot convert: " + this); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/Validatable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | /** 20 | * Objects that can have their state checked for correctness implement this interface. 21 | */ 22 | public interface Validatable { 23 | /** 24 | * Checks the state of the object to ensure it is valid. 25 | * 26 | * @throws Exception if the state of the object is not valid 27 | */ 28 | void validate() throws Exception; 29 | } 30 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/config/WaitFor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 20 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | @JsonAutoDetect( // 24 | fieldVisibility = Visibility.NONE, // 25 | getterVisibility = Visibility.NONE, // 26 | setterVisibility = Visibility.NONE, // 27 | isGetterVisibility = Visibility.NONE) 28 | public class WaitFor implements Validatable { 29 | 30 | @JsonProperty(required = true) 31 | private String name; 32 | 33 | public WaitFor() { 34 | } 35 | 36 | public WaitFor(WaitFor original) { 37 | this.name = original.name; 38 | } 39 | 40 | @Override 41 | public void validate() throws Exception { 42 | if (name == null || name.trim().isEmpty()) { 43 | throw new Exception("wait-for name must be specified"); 44 | } 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/log/JavaAgentLoggers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.log; 18 | 19 | import org.jboss.logging.Logger; 20 | 21 | public final class JavaAgentLoggers { 22 | public static MsgLogger getLogger(Class clazz) { 23 | return Logger.getMessageLogger(MsgLogger.class, clazz.getName()); 24 | } 25 | 26 | private JavaAgentLoggers() { 27 | super(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/main/java/org/hawkular/agent/javaagent/log/MsgLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.log; 18 | 19 | import org.jboss.logging.BasicLogger; 20 | import org.jboss.logging.Logger; 21 | import org.jboss.logging.Logger.Level; 22 | import org.jboss.logging.annotations.Cause; 23 | import org.jboss.logging.annotations.LogMessage; 24 | import org.jboss.logging.annotations.Message; 25 | import org.jboss.logging.annotations.MessageLogger; 26 | import org.jboss.logging.annotations.ValidIdRange; 27 | 28 | @MessageLogger(projectCode = "HAWKJAVAAGENT") 29 | @ValidIdRange(min = 10000, max = 19999) 30 | public interface MsgLogger extends BasicLogger { 31 | MsgLogger LOG = Logger.getMessageLogger(MsgLogger.class, "org.hawkular.agent.javaagent"); 32 | 33 | @LogMessage(level = Level.INFO) 34 | @Message(id = 10000, value = "Loaded configuration file [%s]") 35 | void infoLoadedConfigurationFile(String filepath); 36 | 37 | @LogMessage(level = Level.ERROR) 38 | @Message(id = 10001, value = "Error in security realm [%s]") 39 | void errorBuildingSecurityRealm(String securityRealmName, @Cause Throwable cause); 40 | } 41 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/test/java/org/hawkular/agent/javaagent/config/UtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.agent.javaagent.config; 18 | 19 | import org.hawkular.agent.javaagent.Util; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | public class UtilTest { 24 | 25 | public static class ClassWithCopyConstructor { 26 | private int number = 0; 27 | private String string = ""; 28 | 29 | public ClassWithCopyConstructor(int n, String s) { 30 | this.number = n; 31 | this.string = s; 32 | } 33 | 34 | public ClassWithCopyConstructor(ClassWithCopyConstructor original) { 35 | this.number = original.number; 36 | this.string = original.string; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "" + number + ":" + string; 42 | } 43 | } 44 | 45 | @Test 46 | public void testCloneArray() throws Exception { 47 | Assert.assertNull(Util.cloneArray(null)); 48 | Assert.assertEquals(0, Util.cloneArray(new ClassWithCopyConstructor[0]).length); 49 | 50 | ClassWithCopyConstructor[] arr = new ClassWithCopyConstructor[3]; 51 | arr[0] = new ClassWithCopyConstructor(1, "one"); 52 | arr[1] = new ClassWithCopyConstructor(2, "two"); 53 | arr[2] = new ClassWithCopyConstructor(3, "three"); 54 | ClassWithCopyConstructor[] dup = Util.cloneArray(arr); 55 | Assert.assertEquals(arr.length, dup.length); 56 | Assert.assertNotSame(arr, dup); 57 | for (int i = 0; i < arr.length; i++) { 58 | Assert.assertEquals(arr[i].toString(), dup[i].toString()); 59 | Assert.assertNotSame(arr[i], dup[i]); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /hawkular-javaagent/src/test/resources/all-resource-type-sets.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: true 21 | 22 | storage-adapter: 23 | url: http://127.0.0.1:8080 24 | username: jdoe 25 | password: password 26 | 27 | resource-type-set-dmr: 28 | - name: dmr type set 1 29 | resource-type-dmr: 30 | - name: dmr type 1 31 | path: /dmr-type=1 32 | - name: dmr type 2 33 | path: /dmr-type=2 34 | - name: dmr type set 2 35 | resource-type-dmr: 36 | - name: dmr type 3 37 | path: /dmr-type=3 38 | - name: dmr type 4 39 | path: /dmr-type=4 40 | - name: dmr type set X DISABLED 41 | enabled: false 42 | resource-type-dmr: 43 | - name: dmr type X 44 | path: /dmr-type=X 45 | 46 | resource-type-set-jmx: 47 | - name: jmx type set 1 48 | resource-type-jmx: 49 | - name: jmx type 1 50 | object-name: domain:type=one 51 | resource-name-template: name1 52 | - name: jmx type 2 53 | object-name: domain:type=two 54 | resource-name-template: name2 55 | - name: jmx type set 2 56 | resource-type-jmx: 57 | - name: jmx type 3 58 | object-name: domain:type=three 59 | resource-name-template: name3 60 | - name: jmx type 4 61 | object-name: domain:type=four 62 | resource-name-template: name4 63 | - name: jmx type set X DISABLED 64 | enabled: false 65 | resource-type-jmx: 66 | - name: jmx type X 67 | object-name: domain:type=X 68 | resource-name-template: nameX 69 | 70 | # No resource type set names are provided in managed server definitions. 71 | # The default is to include all of them if none are specified. 72 | managed-servers: 73 | local-dmr: 74 | name: local-dmr-ms 75 | 76 | remote-dmr: 77 | - name: remote-dmr-ms-1 78 | host: host1 79 | port: 1111 80 | - name: remote-dmr-ms-2 81 | host: host2 82 | port: 2222 83 | 84 | local-jmx: 85 | name: local-jmx-ms 86 | 87 | remote-jmx: 88 | - name: remote-jmx-ms-1 89 | url: http://host1 90 | - name: remote-jmx-ms-2 91 | url: http://host2 92 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/test/resources/bad-notif.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: true 21 | 22 | storage-adapter: 23 | url: http://127.0.0.1:8080 24 | username: jdoe 25 | password: password 26 | 27 | resource-type-set-dmr: 28 | - name: resource type set 29 | resource-type-dmr: 30 | - name: first resource type 31 | notification-dmr: 32 | - name: resource-added 33 | - name: not-valid 34 | 35 | managed-servers: 36 | local-dmr: 37 | name: Test 38 | resource-type-sets: 39 | - resource type set -------------------------------------------------------------------------------- /hawkular-javaagent/src/test/resources/empty.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # This is an empty but valid configuration file. 19 | 20 | subsystem: 21 | type-version: empty -------------------------------------------------------------------------------- /hawkular-javaagent/src/test/resources/test-overlay-all-resource-types-1.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: true 21 | 22 | # DMR 23 | 24 | metric-set-dmr: 25 | - name: new metric set dmr 26 | metric-dmr: 27 | - name: new metric dmr 28 | attribute: attrib 29 | metric-family: new_metric_dmr 30 | 31 | resource-type-set-dmr: 32 | - name: new resource type set dmr 33 | resource-type-dmr: 34 | - name: new resource type dmr 35 | path: /new=new 36 | resource-name-template: new dmr 37 | metric-sets: 38 | - new metric set dmr 39 | 40 | - name: new not enabled set dmr 41 | enabled: false 42 | resource-type-dmr: 43 | - name: new not enabled dmr 44 | path: / 45 | resource-name-template: not enabled 46 | 47 | # JMX 48 | 49 | metric-set-jmx: 50 | - name: new metric set jmx 51 | metric-jmx: 52 | - name: new metric jmx 53 | attribute: attrib 54 | metric-family: new_metric_jmx 55 | 56 | resource-type-set-jmx: 57 | - name: new resource type set jmx 58 | resource-type-jmx: 59 | - name: new resource type jmx 60 | object-name: domain:metric=new 61 | resource-name-template: new jmx 62 | metric-sets: 63 | - new metric set jmx 64 | 65 | - name: new not enabled set jmx 66 | enabled: false 67 | resource-type-jmx: 68 | - name: new not enabled jmx 69 | object-name: domain:metric=notenabled 70 | resource-name-template: not enabled 71 | 72 | # MANAGED SERVERS 73 | 74 | managed-servers: 75 | local-dmr: 76 | name: Test Local DMR 77 | enabled: true 78 | 79 | local-jmx: 80 | name: Test Local JMX 81 | enabled: true 82 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/test/resources/test-overlay-all-resource-types-2.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: true 21 | 22 | # DMR 23 | 24 | metric-set-dmr: 25 | - name: original metric set dmr 26 | metric-dmr: 27 | - name: original metric dmr 28 | attribute: attrib 29 | metric-family: original_metric_dmr 30 | 31 | resource-type-set-dmr: 32 | - name: original resource type set dmr 33 | resource-type-dmr: 34 | - name: original resource type dmr 35 | path: /orig=orig 36 | resource-name-template: original dmr 37 | metric-sets: 38 | - original metric set dmr 39 | 40 | - name: original not enabled set dmr 41 | enabled: false 42 | resource-type-dmr: 43 | - name: original not enabled dmr 44 | path: / 45 | resource-name-template: not enabled 46 | 47 | # JMX 48 | 49 | metric-set-jmx: 50 | - name: original metric set jmx 51 | metric-jmx: 52 | - name: original metric jmx 53 | attribute: attrib 54 | metric-family: original_metric_jmx 55 | 56 | resource-type-set-jmx: 57 | - name: original resource type set jmx 58 | resource-type-jmx: 59 | - name: original resource type jmx 60 | object-name: domain:metric=orig 61 | resource-name-template: original jmx 62 | metric-sets: 63 | - original metric set jmx 64 | 65 | - name: original not enabled set jmx 66 | enabled: false 67 | resource-type-jmx: 68 | - name: original not enabled jmx 69 | object-name: domain:metric=notenabled 70 | resource-name-template: not enabled 71 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/test/resources/test-overlay1.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: true 21 | 22 | # DMR 23 | 24 | metric-set-dmr: 25 | - name: original metric set dmr 26 | metric-dmr: 27 | - name: original metric dmr 28 | attribute: attrib 29 | metric-family: original_metric_dmr 30 | 31 | resource-type-set-dmr: 32 | - name: original resource type set dmr 33 | resource-type-dmr: 34 | - name: original resource type dmr 35 | path: /orig=orig 36 | resource-name-template: original dmr 37 | metric-sets: 38 | - original metric set dmr 39 | 40 | # JMX 41 | 42 | metric-set-jmx: 43 | - name: original metric set jmx 44 | metric-jmx: 45 | - name: original metric jmx 46 | attribute: attrib 47 | metric-family: original_metric_jmx 48 | 49 | resource-type-set-jmx: 50 | - name: original resource type set jmx 51 | resource-type-jmx: 52 | - name: original resource type jmx 53 | object-name: domain:metric=orig 54 | resource-name-template: original jmx 55 | metric-sets: 56 | - original metric set jmx 57 | 58 | # MANAGED SERVERS 59 | 60 | managed-servers: 61 | local-dmr: 62 | name: Test Local DMR 63 | enabled: true 64 | resource-type-sets: 65 | - original metric set dmr 66 | 67 | local-jmx: 68 | name: Test Local JMX 69 | enabled: true 70 | resource-type-sets: 71 | - original metric set jmx 72 | -------------------------------------------------------------------------------- /hawkular-javaagent/src/test/resources/test-overlay2.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | --- 19 | subsystem: 20 | enabled: true 21 | 22 | # DMR 23 | 24 | metric-set-dmr: 25 | - name: new metric set dmr 26 | metric-dmr: 27 | - name: new metric dmr 28 | attribute: attrib 29 | metric-family: new_metric_dmr 30 | 31 | resource-type-set-dmr: 32 | - name: new resource type set dmr 33 | resource-type-dmr: 34 | - name: new resource type dmr 35 | path: /new=new 36 | resource-name-template: original dmr 37 | metric-sets: 38 | - new metric set dmr 39 | 40 | # JMX 41 | 42 | metric-set-jmx: 43 | - name: new metric set jmx 44 | metric-jmx: 45 | - name: new metric jmx 46 | attribute: attrib 47 | metric-family: new_metric_jmx 48 | 49 | resource-type-set-jmx: 50 | - name: new resource type set jmx 51 | resource-type-jmx: 52 | - name: new resource type jmx 53 | object-name: domain:metric=new 54 | resource-name-template: original jmx 55 | metric-sets: 56 | - new metric set jmx 57 | 58 | # MANAGED SERVERS 59 | 60 | managed-servers: 61 | local-dmr: 62 | name: Test Local DMR 63 | enabled: true 64 | resource-type-sets: 65 | - new metric set dmr 66 | 67 | local-jmx: 68 | name: Test Local JMX 69 | enabled: true 70 | resource-type-sets: 71 | - new metric set jmx 72 | --------------------------------------------------------------------------------