jetty-metrics configuration - jetty

I am trying to use the metrics-jetty project from Coda Hale: http://metrics.codahale.com/manual/jetty/
The thing is, I really dont know how to configure jetty to use the classes.
I added the projects into my pom.xml, but when using a jetty.xml:
<Call name="addConnector">
<Arg>
<New class="com.yammer.metrics.jetty.InstrumentedSelectChannelConnector">
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="9090"/></Set>
<Set name="maxIdleTime">300000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">8443</Set>
<Set name="lowResourcesConnections">20000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
(Copied from the jetty-distribution), i am getting this error:
Caused by: java.lang.ClassNotFoundException: com.yammer.metrics.jetty.InstrumentedSelectChannelConnector
EDIT
Doing this directly in the jetty-maven-plugin has the same effect:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
<reload>manual</reload>
<connectors>
<connector
implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
</connector>
<connector
implementation="com.yammer.metrics.jetty.InstrumentedSelectChannelConnector">
</connector>
</connectors>
<webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>
<!-- <jettyXml>${project.basedir}/src/main/resources/jetty.xml</jettyXml> -->
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Thanks in advance
Björn

This seems like a pretty straight forward classpath issue. Where do you have the jars containing the instrumented connector?
In the distribution you need to have it in the server classpath, either under lib/ext or as a declared option on startup. In the plugin you need the artifact declared as a dependency of the plugin itself.

Related

how can I make jetty open chrome browser when jetty server starts?

I would like to open my chrome browser when jetty server starts. For that I have added ant plugin to plugins of my profile (where I also have jetty plugin which works fine):
<profiles>
<profile>
<id>DEV</id> <!-- to be used for building GUI for local Tomcat -->
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.22.v20191022</version>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
<webAppConfig>
<contextPath>/dev</contextPath>
</webAppConfig>
<configuration>
<webApp>${basedir}\target</webApp>
</configuration>
<connectors>
<connector
implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>${ojdbc8.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>Run URL in system browser.</id>
<phase>install</phase>
<configuration>
<target>
<exec executable="start" vmlauncher="false">
<arg line="http://localhost:8080/dev/"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I start the server like this: mvn jetty:run-war -P dev. The browser doesn't start. when I try the url http://localhost:8080/dev/ manually, it works. any idea how to start the browser automatically?

Still reproducible: No artifacts found to be deployed in this server. Ignoring Carbon Application

This issue has been reported several times and one popular resolution provided was to set server roles. However in my case server roles were already set. Car file also has the Artifacts, still I am getting this error.
I am following this tutorial here: https://docs.wso2.com/display/ESB500/Sending+a+Simple+Message
Here is my Project:
https://drive.google.com/file/d/1cmtCjqxMX1VYnGc7LuUjA8m9YG4NYKVO/view?usp=sharing
How can I fix this?
Edit:
SampleServicesCompositeApplication pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.SampleServices</groupId>
<artifactId>SampleServicesCompositeApplication</artifactId>
<version>1.0.0</version>
<packaging>carbon/application</packaging>
<name>SampleServicesCompositeApplication</name>
<description>SampleServicesCompositeApplication</description>
<properties>
<com.example.SampleServices.endpoint_._QueryDoctorEP>capp/EnterpriseServiceBus</com.example.SampleServices.endpoint_._QueryDoctorEP>
<com.example.SampleServices.api_._HealthcareAPI>capp/EnterpriseServiceBus</com.example.SampleServices.api_._HealthcareAPI>
<artifact.types>jaggery/app=zip,synapse/priority-executor=xml,synapse/inbound-endpoint=xml,service/rule=aar,synapse/message-store=xml,event/stream=json,service/meta=xml,datasource/datasource=xml,synapse/proxy-service=xml,bpel/workflow=zip,synapse/sequence=xml,synapse/endpointTemplate=xml,carbon/application=car,wso2/gadget=dar,synapse/api=xml,synapse/event-source=xml,synapse/message-processors=xml,event/receiver=xml,lib/dataservice/validator=jar,synapse/template=xml,synapse/endpoint=xml,lib/carbon/ui=jar,lib/synapse/mediator=jar,event/publisher=xml,synapse/local-entry=xml,synapse/task=xml,webapp/jaxws=war,registry/resource=zip,synapse/configuration=xml,service/axis2=aar,synapse/lib=zip,synapse/sequenceTemplate=xml,event/execution-plan=siddhiql,service/dataservice=dbs,web/application=war,lib/library/bundle=jar</artifact.types>
</properties>
<dependencies>
<dependency>
<groupId>com.example.SampleServices.api</groupId>
<artifactId>HealthcareAPI</artifactId>
<version>1.0.0</version>
<type>xml</type>
</dependency>
<dependency>
<groupId>com.example.SampleServices.endpoint</groupId>
<artifactId>QueryDoctorEP</artifactId>
<version>1.0.0</version>
<type>xml</type>
</dependency>
</dependencies>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</repository>
<repository>
<id>wso2-maven2-repository-1</id>
<url>http://dist.wso2.org/maven2</url>
</repository>
<repository>
<id>wso2-nexus-repository-1</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</pluginRepository>
<pluginRepository>
<id>wso2-maven2-repository-1</id>
<url>http://dist.wso2.org/maven2</url>
</pluginRepository>
<pluginRepository>
<id>wso2-nexus-repository-1</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<buildcommands />
<projectnatures>
<projectnature>org.wso2.developerstudio.eclipse.distribution.project.nature</projectnature>
</projectnatures>
</configuration>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>maven-car-plugin</artifactId>
<version>2.1.1</version>
<extensions>true</extensions>
<executions>
<execution>
<id>car</id>
<phase>package</phase>
<goals>
<goal>car</goal>
</goals>
</execution>
</executions>
<configuration />
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>maven-car-deploy-plugin</artifactId>
<version>1.1.1</version>
<extensions>true</extensions>
<configuration>
<carbonServers>
<CarbonServer>
<trustStorePath>${basedir}/src/main/resources/security/wso2carbon.jks</trustStorePath>
<trustStorePassword>wso2carbon</trustStorePassword>
<trustStoreType>JKS</trustStoreType>
<serverUrl>https://localhost:9443</serverUrl>
<userName>admin</userName>
<password>admin</password>
<operation>deploy</operation>
</CarbonServer>
</carbonServers>
</configuration>
</plugin>
</plugins>
</build>
</project>
As per our conversation, you have been deploying the artifacts in Api manager product instead of Enterprise Integrator product, hence the far file was not deployed.
Please choose the proper product for your deployment.

How to exclude some classes in jacoco:structure

I want to exclude some class files since those files do not want to get considered when calculating code coverage.
My scenario is I'm getting .exec file and class files from Jenkins for multiple projects and trying to create one aggregated report. So I'm using jacoco:merge to create the merged exec file and I'm generating the report using jacoco:report. I want to exclude some classes here. But I can't use <excludes> inside jacoco:structure.
My code attached here.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>wso2</groupId>
<artifactId>code-coverage-report</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<directory>${project.basedir}/target</directory>
</build>
<profiles>
<profile>
<id>with-tests</id>
<activation>
<property>
<name>!maven.test.skip</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-jacoco-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<includeTypes>jar</includeTypes>
<includeArtifactIds>org.jacoco.ant</includeArtifactIds>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<!-- Ant plugin - Merge Jacoco Reports -->
<!-- Logging and distribution modules are not checked since not relevant -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:jacoco="antlib:org.jacoco.ant">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${project.build.directory}"/>
</taskdef>
<jacoco:merge destfile="merged.exec">
<fileset dir="jacoco/exec/" includes="*.exec"/>
</jacoco:merge>
<jacoco:report>
<executiondata>
<file file="merged.exec"/>
</executiondata>
<structure name="Final Coverage Report">
<classfiles>
<fileset dir="jacoco/class/classes/"/>
</classfiles>
<excludes>
**/org/xxx/carbon/dataservices/ui/stub/admin/*,
**/org/xxx/carbon/rest/api/stub/types/aaa/*,
**/org/xxx/carbon/endpoint/stub/types/aaa/*,
</excludes>
</structure>
<html destdir="jacoco/tmp_report"/>
<xml destfile="jacoco/tmp_report/coverage-report.xml"/>
<csv destfile="jacoco/tmp_report/coverage-report.csv"/>
</jacoco:report>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<jacoco.version>0.7.9</jacoco.version>
</properties>
</project>
But it gives the following exception. when I try to run it.
An Ant BuildException has occured: structure doesn't support the nested "excludes" element.
See documentation:
Task report
Element structure
Note that the classfiles and sourcefiles elements accept any Ant resource collection. Therefore also filtering the class file set is possible and allows to narrow the scope of the report, for example:
<classfiles>
<fileset dir="classes">
<include name="org/jacoco/examples/important/**/*.class"/>
</fileset>
</classfiles>
Hence
<classfiles>
<fileset dir="jacoco/class/classes/">
<exclude name="org/xxx/carbon/dataservices/ui/stub/admin/**/*.class"/>
<exclude name="org/xxx/carbon/rest/api/stub/types/aaa/**/*.class"/>
<exclude name="org/xxx/carbon/endpoint/stub/types/aaa/**/*.class"/>
</fileset>
</classfiles>

WSO2 BAM 2.4.1 port offset error

I am running BAM 2.4.1 in windows.
set in carbon.xml.
<Ports>
<!-- Ports offset. This entry will set the value of the ports defined below to
the define value + Offset.
e.g. Offset=2 and HTTPS port=9443 will set the effective HTTPS port to 9445
-->
<Offset>200</Offset>
bam-datasources.xml
datasources-configuration xmlns:svns="http://org.wso2.securevault/configuration">
<providers>
<provider>org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader</provider>
</providers>
<datasources>
<datasource>
<name>WSO2BAM_DATASOURCE</name>
<description>The datasource used for analyzer data</description>
<definition type="RDBMS">
<configuration>
<url>jdbc:h2:repository/database/samples/BAM_STATS_DB;AUTO_SERVER=TRUE</url>
<username>wso2carbon</username>
<password>wso2carbon</password>
<driverClassName>org.h2.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
<datasource>
<name>WSO2BAM_CASSANDRA_DATASOURCE</name>
<description>The datasource used for Cassandra data</description>
<definition type="RDBMS">
<configuration>
<url>jdbc:cassandra://localhost:9160/EVENT_KS</url>
<username>admin</username>
<password>admin</password>
</configuration>
</definition>
</datasource>
<datasource>
<name>WSO2BAM_UTIL_DATASOURCE</name>
<description>The datasource used for BAM utilities, such as message store etc..</description>
<definition type="RDBMS">
<configuration>
<url>jdbc:cassandra://localhost:9160/BAM_UTIL_KS</url>
<username>admin</username>
<password>admin</password>
<dataSourceProps>
<property name="externalCassandra">false</property>
</dataSourceProps>
</configuration>
</definition>
</datasource>
<!-- The URL configs are loaded from hector-config.xml -->
<datasource>
<name>WSO2BAM_HIVE_INCREMENTAL_DATASOURCE</name>
<definition type="RDBMS">
<configuration>
<username>admin</username>
<password>admin</password>
<dataSourceProps>
<property name="replicationFactor">1</property>
<property name="strategyClass">org.apache.cassandra.locator.SimpleStrategy</property>
<property name="readConsistencyLevel">QUORUM</property>
<property name="writeConsistencyLevel">QUORUM</property>
<property name="keyspaceName">HIVE_INCREMENTAL_KS</property>
</dataSourceProps>
</configuration>
</definition>
</datasource>
</datasources>
</datasources-configuration>
no problem with start.
But after press "Cassandra Keyspaces" in "Main" of management console I get errors
in console
The following error details are available. Please refer logs for more details.
org.wso2.carbon.cassandra.mgt.ui.CassandraAdminClientException: Error retrieving keyspace names !
at org.wso2.carbon.cassandra.mgt.ui.CassandraKeyspaceAdminClient.listKeyspacesOfCurrentUSer(CassandraKeyspaceAdminClient.java:122)
at org.apache.jsp.cassandramgt.cassandra_005fkeyspaces_jsp._jspService(org.apache.jsp.cassandramgt.cassandra_005fkeyspaces_jsp:107)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492) ......
and error in server log
[2014-07-24 18:09:43,190] WARN {me.prettyprint.cassandra.connection.CassandraHo
stRetryService} - Downed localhost(127.0.0.1):9160 host still appears to be dow
n: Unable to open transport to localhost(127.0.0.1):9160 , java.net.ConnectExcep
tion: Connection refused: connect
note, what port 9160 is not correct.
https://wso2.org/jira/browse/BAM-1476
reported as Fixed [ 1 ] but....
What is wrong?
Change 9160 value in the WSO2BAM_CASSANDRA_DATASOURCE section to 9160+portOffset. Also change /conf/etc/hector-config.xml with the same value.

Disable unit tests in a submodule using system property

In my scenario I want to disable running unit tests for some modules during multi-module build, e.g.
mvn -Dmaven.test.skip.module1=true -Dmaven.test.skip.module2=true install
In module1 I can define a profile:
<profile>
<id>disable-unit-tests</id>
<activation>
<property>
<name>maven.test.skip.module1</name>
<value>true</value>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
but when I try to generalize it and put to parent POM:
<profile>
<id>disable-unit-tests</id>
<activation>
<property>
<name>maven.test.skip.${project.artifactId}</name>
<value>true</value>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
it is not activated with above mentioned command.
What I am doing wrong? Is there any solution?
Profile activation via properties cannot depend on properties, because properties are resolved later in the building of the default model.
In your case, the profile would be actived if the property 'maven.test.skip.${project.artifactId}' would be set.
Take a look at the following description: http://maven.apache.org/ref/3.1.1/maven-model-builder/
You need either to explicitly define your profile in all your submodules or use another plugin (either a self made) or gmaven/antrun to set a property depending on the presence of another one.
Update
Example for the gmaven solution:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.1.8</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>createSkipProperty</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
if (properties["maven.test.skip.${project.artifactId}"])
project.properties.setProperty("skip.this.module", "true")
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skip.this.module}</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This sets a skip.this.module property on the presence of maven.test.skip.${project.artifactId}. Advantage of this solution is, that you only need to define it once in your parent.