how to configurate r2dbc with yaml? - project-reactor

I am configuring r2db-mysql application with yaml ,
but its run error when i try to connect mysql
here is my yaml config
spring:
r2dbc:
url: r2dbc:mysql://localhost:3306/schema?useUnicode=true&characterEncoding=utf-8&txcAppName=account&useSSL=true
username: root
password: root
here is error stack
Caused by: java.lang.IllegalStateException: Unable to create a ConnectionFactory for 'ConnectionFactoryOptions{options={database=schema, host=localhost, driver=mysql, useUnicode=true, characterEncoding=utf-8, password=REDACTED, port=3306, txcAppName=account, useSSL=true, user=ifx}}'. Available drivers: [ pool ]
at io.r2dbc.spi.ConnectionFactories.get(ConnectionFactories.java:145)
at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryBuilder.build(ConnectionFactoryBuilder.java:125)
at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations.createConnectionFactory(ConnectionFactoryConfigurations.java:56)
at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations$Pool.connectionFactory(ConnectionFactoryConfigurations.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 84 common frames omitted
Due to the failure configuration experience with yaml, i try to according to [offical article] (https://github.com/mirromutth/r2dbc-mysql) to configurate in spring with java bean ,and its success
here is code sample
#Bean
public ConnectionFactory initConnectionFactory(#Autowired R2dbcProperties r2dbcProperties){
ConnectionFactory pooledConnectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
.option(DRIVER,"mysql")
// .option(PROTOCOL,"mysql") // driver identifier, PROTOCOL is delegated as DRIVER by the pool.
.option(HOST,"xxxx")
.option(PORT,3306)
.option(USER,"root")
.option(PASSWORD,"root")
.option(DATABASE,"schema")
.build());
return pooledConnectionFactory;
}

Related

Prometheus: Hadoop Monitoring using JMX Exporter

I am very new to Prometheus and monitoring and working on getting JMX-Exporter setup for my Windows-based Hadoop installation for small POC.
I tried putting in following line in "hadoop_installation\bin\hdfs.cmd\"
set HADOOP_OPTS=%HADOOP_OPTS% "-javaagent:C:\path\to\jmx_prometheus_javaagent-0.11.0.jar=1985:C:\path\to\conf\hadoop.yml"
following is my hadoop.yml
rules:
- pattern: Hadoop<service=ResourceManager, name=MetricsSystem, sub=Stats><>NumAllSources
name: sources
labels:
app_id: "hadoop_rm"
Now when I run start-all.cmd
It gives me errors,
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.NumberFormatException: For input string: "C"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at io.prometheus.jmx.shaded.io.prometheus.jmx.JavaAgent.premain(JavaAgent.java:42)
... 6 more
FATAL ERROR in native method: processing of -javaagent failed
I am not sure whether I am on the right track for this?
Is there any other way except readymade FSImage exporter?

ElasticSearch health check failed every time when spring boot start up

I am working with Elastic Search 5.5.0 on Spring boot 1.5.8.RELEASE using the Java Transport Client library.
The Elastic Search was deployed with docker in a container. It works well. The queries from my java application works well too.
The problem is that the Elasticsearch Health check failed almost every time when Spring boot started from my local machine as the following exception says. I didn't call any health check explicitly in my application.
How can I remove the health check every time on start up or are there any way of passing the health check?
Thanks.
20180201 09:04:12.499 [restartedMain] INFO c.k.a.Application - Log info On
20180201 09:04:12.499 [restartedMain] WARN c.k.a.Application - Log warn On
20180201 09:04:12.499 [restartedMain] ERROR c.k.a.Application - Log error On
20180201 09:04:15.628 [RMI TCP Connection(9)-10.10.20.187] WARN o.s.b.a.h.ElasticsearchHealthIndicator - Health check failed
org.elasticsearch.ElasticsearchTimeoutException: java.util.concurrent.TimeoutException: Timeout waiting for task.
at org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:71)
at org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:58)
at org.springframework.boot.actuate.health.ElasticsearchHealthIndicator.doHealthCheck(ElasticsearchHealthIndicator.java:52)
at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:43)
at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:68)
at org.springframework.boot.actuate.endpoint.HealthEndpoint.invoke(HealthEndpoint.java:85)
at org.springframework.boot.actuate.endpoint.HealthEndpoint.invoke(HealthEndpoint.java:35)
at org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean.getData(DataEndpointMBean.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor178.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1252)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1246)
at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:1085)
at org.springframework.jmx.export.SpringModelMBean.invoke(SpringModelMBean.java:90)
at javax.management.modelmbean.RequiredModelMBean.getAttribute(RequiredModelMBean.java:1562)
at org.springframework.jmx.export.SpringModelMBean.getAttribute(SpringModelMBean.java:109)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:647)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:678)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1445)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:639)
at sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.TimeoutException: Timeout waiting for task.
at org.elasticsearch.common.util.concurrent.BaseFuture$Sync.get(BaseFuture.java:232)
at org.elasticsearch.common.util.concurrent.BaseFuture.get(BaseFuture.java:67)
at org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:69)
... 47 common frames omitted
You can disable the Elasticsearch health check by adding the following line to your application.xml file
management.health.elasticsearch.enabled: false
When I went deep into the same issue happening in my sprint boot app too, I found that elasticsearch health check use org.elasticsearch.client.RestClient but I was using org.elasticsearch.client.RestHighLevelClient and had created Bean for the same.
In case you want to keep the recurring elasticsearch's healthcheck,
Create a Bean for RestClient using the right host and port.
Or add following entry in app config yml/xml to remove healthcheck itself:
management.health.elasticsearch.enabled: false
disable the health indicator auto configuration
#SpringBootApplication(exclude = {
ElasticSearchRestHealthIndicatorAutoConfiguration.class
})
public class YourApplication
Disable elastic search health check. Mention this property in your yml/xml file
management.health.elasticsearch.enabled=false

why when I create a new class in a new package in Swarm it does not work?

I use Swarm 2017.3.X and 2017.5.0. When I add a new class in a new package I get NoClassDefFoundError caused by java.lang.ClassNotFoundException on runtime. Why?
org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError
...
Caused by: java.lang.NoClassDefFoundError: com/example/myapp/newpackage/NewClass
at com.example.myapp.MyBean.getSomething(MyBean.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)
... 45 more
Caused by: java.lang.ClassNotFoundException: com.example.myapp.newpackage.NewClass from [Module "deployment.198f19d8-46c4-4bf5-96fd-101dc0f57abd.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
... 57 more
Swarm finds all the Java classes in com.example.myapp (where Main.java is) but not the classes in com.example.myapp.newpackage (where NewClass.java is).
In Swarm you have to add each package in Main class:
deployment.addPackage(Main.class.getPackage());
deployment.addPackage(NewClass.class.getPackage()); //new
deployment.addAllDependencies();
Then it works!

NullPointerException in Embedded Jetty when using JMX

I get a NullPointerException every now and then in my Embedded Jetty application:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jetty.jmx.ObjectMBean.getAttribute(ObjectMBean.java:349)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:647)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:678)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1445)
...
Caused by: java.lang.NullPointerException
at org.eclipse.jetty.server.handler.ContextHandler.isShutdown(ContextHandler.java:682)
... 28 more
I have set up JMX like this:
Server server = new Server();
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mbContainer = new MBeanContainer(mBeanServer);
server.addBean(mbContainer);
This happens randomly (not always) at server startup and only if I have my Prometheous JMX Exporter running on the same machine, most likely connecting to the JMX server at a phase when Jetty is not quite ready to handle the connection.
Any ideas how to fix this?
The JMX exporter should be gracefully handling the error, so you shouldn't have to worry on the JMX side.
Looking at the jetty code, that's just a synchronised accessor so I don't see how you can get an NPE out of it. Presumably the object is null, so this is likely worth filing a bug against jetty.

Cannot start jenkins after changed keystore password

I changed my keystore password today to a more secure one and I cannot restart jenkins. The log has the following error:
SEVERE: Container startup failed
java.io.IOException: Failed to start a listener: winstone.HttpsConnectorFactory
at winstone.Launcher.spawnListener(Launcher.java:207)
at winstone.Launcher.<init>(Launcher.java:149)
at winstone.Launcher.main(Launcher.java:352)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at Main._main(Main.java:246)
at Main.main(Main.java:91)
Caused by: winstone.WinstoneException: Error getting the SSL context object
at winstone.HttpsConnectorFactory.getSSLContext(HttpsConnectorFactory.java:241)
at winstone.HttpsConnectorFactory.createConnector(HttpsConnectorFactory.java:131)
at winstone.HttpsConnectorFactory.start(HttpsConnectorFactory.java:116)
at winstone.Launcher.spawnListener(Launcher.java:205)
... 8 more
Caused by: java.security.UnrecoverableKeyException: Cannot recover key
at sun.security.provider.KeyProtector.recover(KeyProtector.java:328)
at sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:146)
at sun.security.provider.JavaKeyStore$JKS.engineGetKey(JavaKeyStore.java:56)
at sun.security.provider.KeyStoreDelegator.engineGetKey(KeyStoreDelegator.java:96)
at sun.security.provider.JavaKeyStore$DualFormatJKS.engineGetKey(JavaKeyStore.java:70)
at java.security.KeyStore.getKey(KeyStore.java:1023)
at sun.security.ssl.SunX509KeyManagerImpl.<init>(SunX509KeyManagerImpl.java:133)
at sun.security.ssl.KeyManagerFactoryImpl$SunX509.engineInit(KeyManagerFactoryImpl.java:70)
at javax.net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:256)
at winstone.HttpsConnectorFactory.getSSLContext(HttpsConnectorFactory.java:210)
I am assuming the password was stored somewhere and now they don't jive...
Turns out something got screwed up with keystore when I used a 3d party utility to combine a couple of certificates and change the password. I cleaned all that up and all is fine again.

Resources