Connecting Rundeck with MySql Database - mysql

I am trying to connect RunDeck with MySQL server but seeing below errors:-
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:524)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:470)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applyIndexes(AbstractSchemaMigrator.java:327)
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:84)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:203)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:110)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:176)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:478)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:422)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:711)
at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:276)
at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:39)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:23)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52)
at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24)
at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:201)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1201)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:648)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1201)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:931)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:808)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:564)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:395)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:206)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1267)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1181)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1075)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:225)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:703)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at grails.boot.GrailsApp.run(GrailsApp.groovy:84)
at grails.boot.GrailsApp.run(GrailsApp.groovy:393)
at grails.boot.GrailsApp.run(GrailsApp.groovy:380)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at rundeckapp.Application.main(Application.groovy:27)
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.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: INDEX command denied to user 'rundeck'#'10.0.0.8' for table 'base_report'
Here is my rundeck-config.properties file
#loglevel.default is the default log level for jobs: ERROR,WARN,INFO,VERBOSE,DEBUG
loglevel.default=INFO
rdeck.base=/var/lib/rundeck
#rss.enabled if set to true enables RSS feeds that are public (non-authenticated)
rss.enabled=false
# change hostname here
grails.serverURL=http://10.0.0.8:4440
dataSource.dbCreate = update
dataSource.url = jdbc:mysql://my-dev.************.us-east-1.rds.amazonaws.com:3306/rundeck?autoReconnect=true&useSSL=false
dataSource.username = rundeck
dataSource.password = ***************
dataSource.driverClassName=com.mysql.jdbc.Driver
rundeck.log4j.config.file = /etc/rundeck/log4j.properties
I have copied JDBC driver as well to /var/lib/rundeck/libext
[rundeck#mysever]$ pwd && ls -ld mysql-connector-java-5.1.46
/var/lib/rundeck/libext
drwxr-xr-x 3 rundeck rundeck 4096 Feb 26 13:28 mysql-connector-java-5.1.46
I have followed instructions here:
http://rundeck.org/2.10.6/administration/setting-up-an-rdb-datasource.html#setup-mysql
Even though I can see table structure in my RDS but there is no entry in any of the table
mysql> show tables;
+----------------------------+
| Tables_in_rundeck |
+----------------------------+
| auth_token |
| base_report |
| execution |
| job_file_record |
| log_file_storage_request |
| node_filter |
| notification |
| orchestrator |
| plugin_meta |
| project |
| rdoption |
| rdoption_values |
| rduser |
| referenced_execution |
| report_filter |
| scheduled_execution |
| scheduled_execution_filter |
| storage |
| workflow |
| workflow_step |
| workflow_workflow_step |
+----------------------------+

INDEX command denied to user 'rundeck'#'10.0.0.8' for table 'base_report'
You have a permissions issue that is causing the Schema Migration to fail. You should have run:
GRANT ALL ON rundeck.* to rundeck;
You can check the current permissions with:
SHOW GRANTS FOR rundeck;

Related

Hikari CP SSL Exception closing inbound before receiving peer's close_notify

Since switching from Tomcat CP (spring boot 1 default) to Hikari (spring boot 2 default) we've started seeing many instances of:
EXCEPTION STACK TRACE:
** BEGIN NESTED EXCEPTION **
javax.net.ssl.SSLException
MESSAGE: closing inbound before receiving peer's close_notify
STACKTRACE:
javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:645)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:624)
at com.mysql.cj.protocol.a.NativeProtocol.quit(NativeProtocol.java:1312)
at com.mysql.cj.NativeSession.quit(NativeSession.java:182)
at com.mysql.cj.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:1750)
at com.mysql.cj.jdbc.ConnectionImpl.close(ConnectionImpl.java:720)
at com.zaxxer.hikari.pool.PoolBase.quietlyCloseConnection(PoolBase.java:135)
at com.zaxxer.hikari.pool.HikariPool.lambda$closeConnection$1(HikariPool.java:441)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Environment
Spring Boot 2.1.1.RELEASE
Java 11
mysql-connector-java 8.0.13
HikariCP 3.2.0
Database:
RDS Aurora MySql 5.7.12 (default param group)
Configuration (Spring Boot)
Settings:
spring.datasource.hikari.transactionIsolation=TRANSACTION_REPEATABLE_READ
spring.datasource.hikari.minimumIdle=10
spring.datasource.hikari.idleTimeout=300000
spring.datasource.hikari.maximumPoolSize=20
spring.datasource.hikari.connectionTimeout=5000
spring.datasource.hikari.maxLifetime=900000
spring.datasource.hikari.validationTimeout=1000
Is there a setting which I'm missing, perhaps my idle times should be set much lower?
We have not (yet) experienced any obvious bad side effects of this, i.e. the application appears to continue running without issue, but this stacktrace appears frequently (perhaps every 4 seconds.
Database Settings
If I connect to mysql via the cli and run show variables; and grep for timeout related values, I see:
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 60 |
| wait_timeout | 28800 |

Unable to run Cygnus with MySQL agent

I am trying to setup and understand Cygnus. But I am facing issue during installation.
I followed below given steps.
Install Cygnus using Docker (docker run -d -p 5050:5050 -p 8081:8081
fiware/cygnus-common)
Executed version command (curl http://172.17.0.2:8081/v1/version) which gave following response
{"success":"true","version":"1.8.0_SNAPSHOT.39b2aa4789c61fa92fe6edc905410f1ddeb33490"}
Login into Cygnus container using command docker exec -it
/bin/bash
Created new file named “agent_mysql.conf” in
“/opt/apache-flume/conf/” folder.
Configuration details given below
.
cygnus-ngsi.sources = http-source
cygnus-ngsi.sinks = mysql-sink
cygnus-ngsi.channels = mysql-channel
cygnus-ngsi.sources.http-source.channels = mysql-channel
cygnus-ngsi.sources.http-source.type = org.apache.flume.source.http.HTTPSource
cygnus-ngsi.sources.http-source.port = 5050
cygnus-ngsi.sources.http-source.handler = com.telefonica.iot.cygnus.handlers.NGSIRestHandler
cygnus-ngsi.sources.http-source.handler.notification_target = /notify
cygnus-ngsi.sources.http-source.handler.default_service = def_serv
cygnus-ngsi.sources.http-source.handler.default_service_path = def_servpath
cygnus-ngsi.sources.http-source.handler.events_ttl = 2
cygnus-ngsi.sources.http-source.interceptors = ts gi
cygnus-ngsi.sources.http-source.interceptors.ts.type = timestamp
cygnus-ngsi.sources.http-source.interceptors.gi.type = com.telefonica.iot.cygnus.interceptors.NGSIGroupingInterceptor$Builder
cygnus-ngsi.sources.http-source.interceptors.gi.grouping_rules_conf_file = /Applications/apache-flume-1.4.0-bin/conf/grouping_rules.conf
# =============================================
# mysql-channel configuration
# channel type (must not be changed)
cygnus-ngsi.channels.mysql-channel.type = memory
# capacity of the channel
cygnus-ngsi.channels.mysql-channel.capacity = 1000
# amount of bytes that can be sent per transaction
cygnus-ngsi.channels.mysql-channel.transactionCapacity = 100
# channel name from where to read notification events
cygnus-ngsi.sinks.mysql-sink.channel = mysql-channel
# sink class, must not be changed
cygnus-ngsi.sinks.mysql-sink.type = com.telefonica.iot.cygnus.sinks.NGSIMySQLSink
#com.telefonica.iot.cygnus.sinks.OrionMySQLSink
# the FQDN/IP address where the MySQL server runs
cygnus-ngsi.sinks.mysql-sink.mysql_host = localhost
# the port where the MySQL server listes for incomming connections
cygnus-ngsi.sinks.mysql-sink.mysql_port = 3306
# a valid user in the MySQL server
cygnus-ngsi.sinks.mysql-sink.mysql_username = root
# password for the user above
cygnus-ngsi.sinks.mysql-sink.mysql_password = <myPassword>
# how the attributes are stored, either per row either per column (row, column)
cygnus-ngsi.sinks.mysql-sink.attr_persistence = row
Changed "cygnus-entrypoint.sh" file in / (root) folder and added following command by removing existing one.
${FLUME_HOME}/bin/cygnus-flume-ng agent --conf ${CYGNUS_CONF_PATH} -f ${CYGNUS_CONF_PATH}/agent_mysql.conf -n cygnus-ngsi -p ${CYGNUS_API_PORT} -Dflume.root.logger=${CYGNUS_LOG_LEVEL},${CYGNUS_LOG_APPENDER} -Dfile.encoding=UTF-8
Exited Docker container and came back to Ubuntu.
Stop and restart Docker container.
And I am getting following errors in logs
Please check and let me know what am I doing wrong? Appreciate your help.
LOGS
n$AgentConfiguration[1016] : Processing:mysql-sink
time=2018-04-30T14:24:00.807Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=validateConfiguration | msg=org.apache.flume.conf.FlumeConfiguration[140] : Post-validation flume configuration contains configuration for agents: [cygnus-ngsi]
time=2018-04-30T14:24:00.808Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadChannels | msg=org.apache.flume.node.AbstractConfigurationProvider[150] : Creating channels
time=2018-04-30T14:24:00.816Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=create | msg=org.apache.flume.channel.DefaultChannelFactory[40] : Creating instance of channel mysql-channel type memory
time=2018-04-30T14:24:00.825Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadChannels | msg=org.apache.flume.node.AbstractConfigurationProvider[205] : Created channel mysql-channel
time=2018-04-30T14:24:00.832Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=create | msg=org.apache.flume.source.DefaultSourceFactory[39] : Creating instance of source http-source, type org.apache.flume.source.http.HTTPSource
time=2018-04-30T14:24:00.836Z | lvl=ERROR | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=configure | msg=org.apache.flume.source.http.HTTPSource[113] : Error while configuring HTTPSource. Exception follows.
java.lang.ClassNotFoundException: com.telefonica.iot.cygnus.handlers.NGSIRestHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.flume.source.http.HTTPSource.configure(HTTPSource.java:102)
at org.apache.flume.conf.Configurables.configure(Configurables.java:41)
at org.apache.flume.node.AbstractConfigurationProvider.loadSources(AbstractConfigurationProvider.java:331)
at org.apache.flume.node.AbstractConfigurationProvider.getConfiguration(AbstractConfigurationProvider.java:102)
at org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable.run(PollingPropertiesFileConfigurationProvider.java:140)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
time=2018-04-30T14:24:00.840Z | lvl=ERROR | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadSources | msg=org.apache.flume.node.AbstractConfigurationProvider[366] : Source http-source has been removed due to an error during configuration
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.telefonica.iot.cygnus.handlers.NGSIRestHandler
at com.google.common.base.Throwables.propagate(Throwables.java:156)
at org.apache.flume.source.http.HTTPSource.configure(HTTPSource.java:114)
at org.apache.flume.conf.Configurables.configure(Configurables.java:41)
at org.apache.flume.node.AbstractConfigurationProvider.loadSources(AbstractConfigurationProvider.java:331)
at org.apache.flume.node.AbstractConfigurationProvider.getConfiguration(AbstractConfigurationProvider.java:102)
at org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable.run(PollingPropertiesFileConfigurationProvider.java:140)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.telefonica.iot.cygnus.handlers.NGSIRestHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.flume.source.http.HTTPSource.configure(HTTPSource.java:102)
... 11 more
time=2018-04-30T14:24:00.841Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=create | msg=org.apache.flume.sink.DefaultSinkFactory[40] : Creating instance of sink: mysql-sink, type: com.telefonica.iot.cygnus.sinks.NGSIMySQLSink
time=2018-04-30T14:24:00.842Z | lvl=ERROR | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=run | msg=org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable[142] : Failed to load configuration data. Exception follows.
org.apache.flume.FlumeException: Unable to load sink type: com.telefonica.iot.cygnus.sinks.NGSIMySQLSink, class: com.telefonica.iot.cygnus.sinks.NGSIMySQLSink
at org.apache.flume.sink.DefaultSinkFactory.getClass(DefaultSinkFactory.java:69)
at org.apache.flume.sink.DefaultSinkFactory.create(DefaultSinkFactory.java:41)
at org.apache.flume.node.AbstractConfigurationProvider.loadSinks(AbstractConfigurationProvider.java:415)
at org.apache.flume.node.AbstractConfigurationProvider.getConfiguration(AbstractConfigurationProvider.java:103)
at org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable.run(PollingPropertiesFileConfigurationProvider.java:140)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.telefonica.iot.cygnus.sinks.NGSIMySQLSink
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.flume.sink.DefaultSinkFactory.getClass(DefaultSinkFactory.java:67)
... 11 more
The simplest case is installing cygnus connecting MYSQL this way, using the "root" user to connect to cygnus.
docker run -d --name cygnus_container_name --link mysql_showcases \
-p 8081:8081 -p 5050:5050 \
-e CYGNUS_MYSQL_HOST=mysql_host -e CYGNUS_MYSQL_PORT=3306 \
-e CYGNUS_MYSQL_USER=root -e CYGNUS_MYSQL_PASS=root_password \
fiware/cygnus-ngsi
If you decide not to use root user to connect mysql, you'll need to change your user and password and create the database manually and granting the permissions to your user, since cygnus won't be able to create a database with a different user.
Finally I am able to run Cygnus with MySQL agent. I am using Ubuntu. (Linux ubuntucustomfiware 4.4.0-119-generic #143-Ubuntu SMP Mon Apr 2 16:08:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux)
I followed below steps.
Used MySQL installed in main Ubuntu instance instead of Docker container.
Modified /etc/mysql/mysql.conf.d/mysqld.cnf and changed
from
bind-address = 127.0.0.1
to
bind-address = *
Login into DB and grant all privileges to root user, so that it can connect from any host.
mysql -u root -p
GRANT ALL PRIVILEGES ON . TO 'root'#'%' IDENTIFIED BY 'MyPassword';
FLUSH PRIVILEGES;
exit;
Restart MySQL server
service mysql restart
Run Cygnus-ngsi
docker run -d --name cygnus -p 8081:8081 -p 5050:5050 -e
CYGNUS_MYSQL_HOST=PublicIPOfMySQLServer -e CYGNUS_MYSQL_PORT=3306 -e
CYGNUS_MYSQL_USER=root -e CYGNUS_MYSQL_PASS=MyPassword -e
CYGNUS_LOG_LEVEL='DEBUG' fiware/cygnus-ngsi
Modified Agent file and keep only mysql-sink. After below changes, stop/start cygnus docker container.
docker exec -it cygnus /bin/bash
vi /opt/apache-flume/conf/agent.conf
cygnus-ngsi.sinks = mysql-sink
cygnus-ngsi.channels = mysql-channel
exit;
docker stop cygnus
docker start cygnus
Now publish MQTT data to modify my entity and it inserted 4 rows (one row for each attribute) into MySQL DB
mosquitto_pub -h PublicIPOfMySQLServer -u UserName -P Password -t
/swm-reader-service1/reader-device-id1/attrs -m '{"tn": "9888", "pn":
"878787", "ri": "888888", "tdt":"Monday, May 10, 2018 03:16 AM"}'
Thanks for all your support.
Regards,
Krishan

Why am i getting these random timeout errors on mysql database being accessed directly

I have a Tomcat and Mysql installed on the same machine, its not been recently updated so we are using Tomcat 7.0.31 and MySql 5.0.95 on Linux.
When a user makes a purchase, its processed by Paypal and then they contact our server and we create the license and store it in the database, but unfortunately it doesn't always work giving errors such as:
The last packet successfully received from the server was 44,533,707
milliseconds ago. The last packet sent successfully to the server was
44,533,707 milliseconds ago. is longer than the server configured
value of 'wait_timeout'. You should consider either expiring and/or
testing connection validity before use in your application, increasing
the server configured values for client timeouts, or using the
Connector/J connection property 'autoReconnect=true' to avoid this
problem.
But I dont think MySql is down since I have never ever had a problem connecting to it, the errors occur randomly about 5% of the time.
Mysql contains two db instances and in my web.xml file I have
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/jaikoz</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>DB Connection2</description>
<res-ref-name>jdbc/songkong</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and in context.xml (I have changed username and password) I have
<Context path="/store" privileged="true">
<Resource name="jdbc/jaikoz" auth="Container" type="javax.sql.DataSource"
maxActive="-1" maxIdle="-1" maxWait="10000"
username="usrnm" password="pwd" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/jaikoz?autoReconnect=true"/>
<Resource name="jdbc/songkong" auth="Container" type="javax.sql.DataSource"
maxActive="-1" maxIdle="-1" maxWait="10000"
username="usernm" password="pwd" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/songkong?autoReconnect=true"/>
</Context>
Also this configuration is from my Store web application, I also a have a jaikoz and a songkong web application both of these define one of the connections. I had to introduce 'store' since payment provider required a single url to send all successful payments (be it from songkong or jaikoz)
I wonder if having two database connections is breaking things or having two applications define the same connection is breaking things since I don't think i had such a problem when I only the jaikoz application.
The errors say I could use AutorReconnect=true, but I am already doing that.
Ran Show Process List as suggested and got the following:
mysql> show processlist
-> ;
+--------+------+-----------------+----------+---------+-------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+------+-----------------+----------+---------+-------+-------+------------------+
| 127681 | paul | localhost:40360 | jaikoz | Sleep | 5 | | NULL |
| 127682 | paul | localhost:40361 | jaikoz | Sleep | 7 | | NULL |
| 127683 | paul | localhost:40362 | jaikoz | Sleep | 11 | | NULL |
| 127684 | paul | localhost:40363 | jaikoz | Sleep | 2 | | NULL |
| 127685 | paul | localhost:40364 | jaikoz | Sleep | 17 | | NULL |
| 127754 | paul | localhost:40664 | jaikoz | Sleep | 20 | | NULL |
| 127755 | paul | localhost:40665 | jaikoz | Sleep | 8 | | NULL |
| 127756 | paul | localhost:40666 | jaikoz | Sleep | 25 | | NULL |
| 128444 | paul | localhost:41250 | jaikoz | Sleep | 14 | | NULL |
| 128445 | paul | localhost:41251 | jaikoz | Sleep | 10 | | NULL |
| 134807 | paul | localhost:56829 | jaikoz | Sleep | 226 | | NULL |
| 134849 | paul | localhost:38795 | songkong | Sleep | 475 | | NULL |
| 143552 | paul | localhost:35811 | jaikoz | Sleep | 19338 | | NULL |
| 145211 | paul | localhost | jaikoz | Query | 0 | NULL | show processlist |
+--------+------+-----------------+----------+---------+-------+-------+------------------+
14 rows in set (0.00 sec)
Maybe shoud not be so many Jaikoz processes ?
How do i resolve this ?
Edited
Speaking to someone else since it is only connections from the Store web application that is failing and that only does anything when a purchase is made which is currently only a few times a day it sounds like the connection is being timed out by MySql itself without telling the jdbc pool, so when try to use the connection via the pool we get the error.
I added testWhileIdle="true" to my context.xml and removed the autoreconnect=true hoping this will remove connections from pool before mysql just gives up on them.
Unfortunately still failing sporadically but now giving a slightly different error message
JDBC begin transaction failed
Turn off connection pooling.
Turn off auto-reconnect
Be sure your code catches transaction errors, and replays them if necessary -- especially in the case of deadlocks.
Those tend to be issues relating to integrity of financial transactions.
If those do not clear up the problem, then provide
Queries per second
SHOW VARIABLES LIKE '%timeout';`
Sample of the transaction (SQL, please, not Java)
SHOW CREATE TABLE
As for the PROCESSLIST...
I see one connection (possibly pooled) that performed some SQL 5 seconds ago.
I see one connection (possibly pooled) that has not done anything for 19338 seconds ago (over 5 hours).
I would guess that you have not needed more than 12 simultaneous connections in the past 5 hours.
The list looks "normal".
The key thing was that I needed to provide a validationQuery in order for the validation done by testForIdle to work, since then had no problems.
<Context path="/store" privileged="true">
<Resource name="jdbc/myapp" auth="Container" type="javax.sql.DataSource"
maxActive="10" maxIdle="10"
testWhileIdle="true" validationQuery="select 1" validationQueryTimeout="5"
username="usrnm" password="pwd"
driverClassName="com.mysql.jdbc.Driver" testOnBorrow="true"
url="jdbc:mysql://localhost:3306/myapp"/>
</Context>

grails NullPointerException saving bi-directional one-to-many relationship model

I have the following two simple models creating a bidirectional one-to-many relationship in a Grails 2.4.3 application:
class Player {
String firstName
String lastName
String position
static belongsTo = [team: Team]
}
class Team {
String name
List players = new ArrayList()
static hasMany = [players: Player]
static mapping= {
players cascade:"all-delete-orphan"
}
}
I would like to be able to save and update teams and their associated players via nested JSON, like so:
{
name : "team A",
players : [
{
firstName : "john",
lastName :"doe",
position : "center"
}
]
}
My TeamController save action looks like this:
def save() {
def team = new Team(request.JSON)
team.save()
respond team
}
When I make a request with that JSON, I get an error:
curl -X POST -d '{name:"team a",players:[{firstName:"john",lastName:"doe",position:"center"}]}' http://localhost:8080/team-test/team/save.json --header "Content-Type:application/json"
Produces this output in console:
| Error 2014-11-14 10:32:26,111 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [POST] /team-test/team/save.json
Stacktrace follows:
Message: null
Line | Method
->> 8 | save in team.test.TeamController$$EOvbjH0K
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Because that's a rather vague message, I put a try/catch around the team.save() call in the TeamController and print out the stack trace:
def save() {
def team = new Team(request.JSON)
try {
team.save()
}
catch(Exception e)
{
e.printStackTrace()
}
respond team
}
Error java.lang.NullPointerException
| Error at org.hibernate.engine.spi.BatchFetchQueue.removeBatchLoadableEntityKey(BatchFetchQueue.java:163)
| Error at org.hibernate.engine.internal.StatefulPersistenceContext.addEntity(StatefulPersistenceContext.java:388)
| Error at org.hibernate.engine.internal.StatefulPersistenceContext.addEntity(StatefulPersistenceContext.java:461)
| Error at org.hibernate.action.internal.AbstractEntityInsertAction.makeEntityManaged(AbstractEntityInsertAction.java:143)
| Error at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:201)
| Error at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:179)
| Error at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:214)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
| Error at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:684)
| Error at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:676)
| Error at org.hibernate.engine.spi.CascadingActions$5.cascade(CascadingActions.java:235)
| Error at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:350)
| Error at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:293)
| Error at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
| Error at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:379)
| Error at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:319)
| Error at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:296)
| Error at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
| Error at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:118)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:460)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:294)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
| Error at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:684)
| Error at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:676)
| Error at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:671)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.SavePersistentMethod$1.doInHibernate(SavePersistentMethod.java:58)
| Error at org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:179)
| Error at org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:123)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.SavePersistentMethod.performSave(SavePersistentMethod.java:56)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod.doInvokeInternal(AbstractSavePersistentMethod.java:215)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod.invoke(AbstractDynamicPersistentMethod.java:68)
| Error at org.codehaus.groovy.grails.orm.hibernate.HibernateGormInstanceApi.save(HibernateGormInstanceApi.groovy:156)
| Error at team.test.Team$$EOvbjH0K.save(Team.groovy)
| Error at team.test.Team$$DOvbjH0K.save(Unknown Source)
| Error at team.test.Team.save(Team.groovy)
| Error at team.test.Team$save.call(Unknown Source)
| Error at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
| Error at team.test.TeamController$$EOvbkj0y.save(TeamController.groovy:9)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error at java.lang.reflect.Method.invoke(Method.java:606)
| Error at org.springsource.loaded.ri.ReloadedTypeInvoker$2.invoke(ReloadedTypeInvoker.java:122)
| Error at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1299)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper.invoke(MixedGrailsControllerHelper.java:154)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleAction(AbstractGrailsControllerHelper.java:375)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.executeAction(AbstractGrailsControllerHelper.java:252)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:205)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:126)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:72)
| Error at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
| Error at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:347)
| Error at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
| Error at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
| Error at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
| Error at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
| Error at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
| Error at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
| Error at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
| Error at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
| Error at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
| Error at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
| Error at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
| Error at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
| Error at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:178)
| Error at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:144)
| Error at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:135)
| Error at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:216)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
| Error at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
| Error at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
| Error at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
| Error at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
| Error at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
| Error at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
| Error at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
| Error at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
| Error at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
| Error at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
| Error at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
| Error at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
| Error at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
| Error at java.lang.Thread.run(Thread.java:745)
For further investigation, I put some logging in the controller action to see what's going on within the object:
def save() {
JSON.use('deep')
def team = new Team(request.JSON)
println "errors? " + team.getErrors()
println "team: " + team.toString()
println ((team as JSON).toString())
respond team
}
which produces the following output:
errors? grails.validation.ValidationErrors: 0 errors
team: team.test.Team : (unsaved)
{
"class":"team.test.Team",
"id":null,
"name":"team a",
"players":[
{
"class":"team.test.Player",
"id":null,
"firstName":"john",
"lastName":"doe",
"position":"center",
"team":null
}
]
}
Is there something wrong with my JSON? Why do I get this error? Is it because the team reference is null in the player object? Why is the team reference null in the player object?
Out of curiosity, I removed the belongsTo property from the Player class, and things work as expected...
{"class":"team.test.Team","id":2,"name":"team a","players":[{"class":"team.test.Player","id":2}]}
Why does it not work in the bidirectional case? What are the different implications of bidirectional and unidirectional in terms of table relationships, data binding, etc? I understand the different cascade strategies when using belongsTo or not in a one-to-many relationship, but both should cascade saves I thought.
I know I'm asking many questions. I need help making this work but would also like to understand what is happening in principle. Help is much appreciated.
edit:
per #th3morg's suggestion I attempted manually building out the Team and Player models and associating them via Team.addToPlayers().
def save() {
JSON.use('deep')
def teamData = request.JSON
def team = new Team()
team.name = teamData.name
teamData.players.each { playerData ->
def player = new Player(playerData)
team.addToPlayers(player)
}
team.save()
println ((team as JSON).toString())
respond team
}
produces:
{"class":"team.test.Team","id":3,"name":"team a","players":[{"class":"team.test.Player","id":3,"firstName":"john","lastName":"doe","position":"center","team":{"_ref":"../..","class":"team.test.Team"}}]}
This appears to work, but it is verbose and fragile. Is there no way to achieve the same result through automatic binding or through some other conventional magic?
I think in your case, the reason is straightforward - you need to explicitly call team.addToPlayers(player) before you save. I'm guessing that instantiating a team with the JSON constructor is equivalent to the Map constructor, which is basically equivalent to doing the following:
def team = new Team()
team.players = [new Player(), new Player()]
team.save()
i.e. setting the players properly directly, rather than calling addToPlayers.
If you run this in a test app, you will get exactly the same exception as you received in your version. This is because (as you've recognized), each Player does not have a back-reference to the Team set (which is what team.addToPlayers()) does. This (strangely) still saves the player object because the Hibernate session flushes when the controller finishes, saving any unsaved instances.
I'd be surprised if removing belongsTo property from the Player class actually fixes the issue - did it actually persist the TeamPlayers relationship? Or did it just look like it worked because you were responding with a JSON object where you had effectively manually set the players property?
I realize this is over a year old now, but the reason why I'm commenting is to leave a note for others : there is a (possibly related) known Grails bug which throws the same exception with multiple cascading relationships (e.g. A -> hasMany -> B hasMany -> C) where a child/grandchild has a beforeInsert() or beforeUpdate() method. This may be fixed in Grails 3.x but looks like it will not be fixed in 2.x. - see here and here.
You may be able to fix this with a beforeSave() function within your Team domain where you iterate over the players and save each player. This should avoid hibernate trying to save the transient player objects and also prevent you from having to code it yourself in the controller, which is a bit odd feeling.
Also, using GSON, you might be able to avoid any of the addTo associations hibernate would want.
https://github.com/robfletcher/grails-gson#readme

exception in running on windows7 64 bit

When i run sonar using StartSonar.bat i am getting exception like
as i read in http://obscuredclarity.blogspot.in/2012/05/install-sonar-on-windows-as-windows.html and i refered so many documentation regarding this but i did not find the solution for this. And the exception traced is,
jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
jvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
jvm 1 |
jvm 1 | 2013-05-06 13:10:25.267:INFO::Logging to org.sonar.application.Filter
edLogger#fee4648 via org.sonar.application.FilteredLogger
jvm 1 | 2013-05-06 13:10:25.301:INFO::jetty-6.1.25
jvm 1 | 2013-05-06 13:10:25.462:INFO::NO JSP Support for /, did not find org.
apache.jasper.servlet.JspServlet
jvm 1 | 2013-05-06 13:10:26.451:WARN::Failed startup of context org.mortbay.j
etty.webapp.WebAppContext#70c26b16{/,file:/C:/Program%20Files/sonar-3.5.1/war/so
nar-server}
jvm 1 | org.sonar.api.utils.SonarException: Unable to start database
jvm 1 | at org.sonar.server.database.EmbeddedDatabase.start(EmbeddedData
base.java:86)
jvm 1 | at org.sonar.server.database.EmbeddedDatabaseFactory.start(Embed
dedDatabaseFactory.java:41)
jvm 1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
jvm 1 | at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
jvm 1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Sourc
e)
jvm 1 | at java.lang.reflect.Method.invoke(Unknown Source)
jvm 1 | at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invok
eMethod(ReflectionLifecycleStrategy.java:110)
jvm 1 | at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start
(ReflectionLifecycleStrategy.java:89)
jvm 1 | at org.picocontainer.injectors.AbstractInjectionFactory$Lifecycl
eAdapter.start(AbstractInjectionFactory.java:84)
jvm 1 | at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBe
havior.java:169)
jvm 1 | at org.picocontainer.behaviors.Stored$RealComponentLifecycle.sta
rt(Stored.java:132)
jvm 1 | at org.picocontainer.behaviors.Stored.start(Stored.java:110)
jvm 1 | at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapte
r(DefaultPicoContainer.java:1009)
jvm 1 | at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultP
icoContainer.java:1002)
jvm 1 | at org.picocontainer.DefaultPicoContainer.start(DefaultPicoConta
iner.java:760)
jvm 1 | at org.sonar.api.platform.ComponentContainer.startComponents(Com
ponentContainer.java:72)
jvm 1 | at org.sonar.server.platform.Platform.startDatabaseConnectors(Pl
atform.java:198)
jvm 1 | at org.sonar.server.platform.Platform.init(Platform.java:138)
jvm 1 | at org.sonar.server.platform.PlatformLifecycleListener.contextIn
itialized(PlatformLifecycleListener.java:33)
jvm 1 | at org.mortbay.jetty.handler.ContextHandler.startContext(Context
Handler.java:548)
jvm 1 | at org.mortbay.jetty.servlet.Context.startContext(Context.java:1
36)
jvm 1 | at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppCon
text.java:1272)
jvm 1 | at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandl
er.java:517)
jvm 1 | at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.
java:489)
jvm 1 | at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCyc
le.java:50)
jvm 1 | at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapp
er.java:130)
jvm 1 | at org.mortbay.jetty.Server.doStart(Server.java:224)
jvm 1 | at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCyc
le.java:50)
jvm 1 | at org.sonar.application.JettyEmbedder.start(JettyEmbedder.java:
74)
jvm 1 | at org.sonar.application.StartServer.main(StartServer.java:49)
jvm 1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
jvm 1 | at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
jvm 1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Sourc
e)`
jvm 1 | at java.lang.reflect.Method.invoke(Unknown Source)
jvm 1 | at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimple
App.java:240)
jvm 1 | at java.lang.Thread.run(Unknown Source)
jvm 1 | 2013-05-06 13:10:26.473:INFO::Started SelectChannelConnector#0.0.0.0:
9000
may i know where i am going wrong
You have some configuration issue related to the database that you want to use for Sonar. Check your configuration in the "conf/sonar.properties" file to make sure that the DB connection properties are correctly set.