Jboss-cli: JBAS014653 ("Expected [OBJECT] but was LIST") when trying to add datasource - postgresql

I tried inserting a new XA-Datasource in Wildfly 8.1:
/opt/wildfly/bin/jboss-cli.sh --connect --controller=192.168.1.220:9990
[standalone#192.168.1.220:9990 /] xa-data-source add --name=myName --jndi-name=java:jboss/datasources/myDS --driver-name=postgresql --user-name=myUser --password=myPass --use-java-context=true --use-ccm=true --min-pool-size=10 --max-pool-size=100 --transaction-isolation=TRANSACTION_READ_COMMITTED --pool-prefill=true --allocation-retry=1 --prepared-statements-cache-size=32 --share-prepared-statements=true --xa-datasource-class=org.postgresql.xa.PGXADataSource --xa-datasource-properties=[{ServerName=192.168.1.220},{PortNumber=5432},{DatabaseName=postgres}] --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker --exception-sorter-properties=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter
But I received this error:
{"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => "JBAS014688: Wrong type for exception-sorter-properties. Expected [OBJECT] but was LIST"}}
In the Web interface the value for Exception Sorter is a simple string.
I tried many value types.

Use --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter instead of --exception-sorter-properties=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter.

Related

TypeORM migration gives Maximum call stack size exceeded error with Postgres

When I run a migration, I get the following error. I initially had this in one project - now I've created a new blank project and still get the error. Here is the ormconfig.ts:
import { DataSource } from 'typeorm';
const env = {
"DB_HOST":"localhost",
"DB_PORT":5432,
"DB_USERNAME":"postgres",
"DB_PASSWORD":"postgres",
"DB_DATABASE":"task-management",
}
export const connectionSource = new DataSource({
migrationsTableName: 'migrations',
type: 'postgres',
host: env.DB_HOST,
port: env.DB_PORT,
username: env.DB_USERNAME,
password: env.DB_PASSWORD,
database: env.DB_DATABASE,
logging: false,
synchronize: false,
name: 'default',
migrations: ['migrations/**/*{.ts,.js}'],
});
I run the migration with: typeorm-ts-node-esm migration:run -d migrations/ormconfig.ts
which gives the following error:
Error during migration run:
RangeError: Maximum call stack size exceeded
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:43
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:35)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:27:42
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:27:22)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:30:17
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:35)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:30:17
I assume there is some circular dependency causing an infinite loop in DirectoryExportedClassesLoader.ts, so I put a console.log(JSON.stringify(exported)) on line 26 of DirectoryExportedClassesLoader.ts, and I now get:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'DataSource'
| property 'driver' -> object with constructor 'PostgresDriver'
--- property 'connection' closes the circle
at JSON.stringify (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/typeormTest/src/util/DirectoryExportedClassesLoader.ts:29:25)
It seems DirectoryExportedClassLoader.js is guaranteed to get a Maximum call stack size exceeded error if there are circular dependencies, because it is self-recursive whenever it encounters an object property.
A little help please!
changing this entry from the DataSource config object fixed the issue.
migrations: []
This was one of those ones that just took a lot of trial and error to solve...

Cannot read property 'prototype' of undefined - nestjs with typeorm and mongoDB

I'm setting up a simple API using nestjs with typeorm and mongodb. However when I make a simple http request I get the following error
[Nest] 8852 - 09/28/2021, 6:06:03 PM [ExceptionsHandler] Cannot read property 'prototype' of undefined +4874934ms TypeError: Cannot read property 'prototype' of undefined at FindCursor.cursor.toArray (C:\Users\admin\Documents\projects\shoplist\api\node_modules\typeorm\entity-manager\MongoEntityManager.js:669:37) at MongoEntityManager.<anonymous> (C:\Users\admin\Documents\projects\shoplist\api\node_modules\typeorm\entity-manager\MongoEntityManager.js:60:54) at step (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:143:27) at Object.next (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:124:57) at fulfilled (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:114:62) at processTicksAndRejections (internal/process/task_queues.js:95:5)
offices.controller.ts
#Get('/list')
findAll() {
return this.officesService.findAll();
}
offices.service.ts
async findAll() {
try {
const offices = await this.officesRepository.find();
return { success: true, message: 'Office successfully retrieved!', data: offices }
} catch(e) {
throw new InternalServerErrorException({ success: false, error: e.message })
}
}
I honestly don't know why it gives me error 500 with that message. Any idea what's happening?
These errors seam like a mongodb version problem. If you are using mongodb > 3, Typeorm doesn't support yet. They have PR open at github --> https://github.com/typeorm/typeorm/issues/7907
It's issue of mongodb version with typeorm.
typeorm doesn't have support for >3 version yet.
Run this to resolve issue.
mongodb#3 #types/mongodb#3
Complete dependencies
npm install typeorm #nestjs/typeorm mongodb#3 #types/mongodb#3
Resolved same issue following this.

Error in connection with PostgreSQL 12 by creating a datasource

I'm getting an exception while connecting to PostgreSQL 12 by creating a data source via wildfly admin console.
It works fine on my another machine which has PostgreSQL 9.5. and it seems to work fine when I connect without data-source.
try (Connection conn = DriverManager.getConnection(
"jdbc:postgresql://127.0.0.1:5432/registrar", "postgres", "postgres")) {
if (conn != null) {
System.out.println("Connected to the database!");
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("Select * FROM public.user LIMIT 10");
while(rs.next())
System.out.println(rs.getString(2));
} else {
System.out.println("Failed to make connection!");
}
But when I create a data-source like this:
and this the exception that I get when I try to test the connection from UI.
Request
{
"address" => [
("subsystem" => "datasources"),
("data-source" => "RegistrarDS")
],
"operation" => "test-connection-in-pool"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid",
"rolled-back" => true,
"response-headers" => {"process-state" => "reload-required"}
}
Has anything changed in PostgreSQL 12? What could be the issue?
Could be an issue with the datasource-class defined in your driver as described here on issues.redhat.com
If a datasource-class is defined then it takes precedence to create the datasource and as such it can only use connection-properties.
Since there is not a single connection-url property for all drivers, you have to use connection-properties if you are defining the datasource-class.
Another thing you could try is to set "Connection Properties" instead of "Connection URL" and make sure you are using the correct/latest driver jar file.
Also check your Postgresql logs for further info on the exception..
-> https://www.postgresql.org/about/news/2000/

Phoenix Repo.insert out of controller

I'm making a task that get an json in an api and insert in MongoDb. I'm using phoenix and Mongodb_Ecto.
I have a model Group and this code in a controller works like a charm:
HTTPoison.start
group = %Group{ param1: "value", param2: "value" } |> Repo.insert!
But,in a task I don't have the Repo defmodule. I tried to make this:
HTTPoison.start
group = %Group{ param1: "value", param2: "value"} |> MyApp.Repo.insert!
Using MyApp.Repo instead of only Repo.
I'm receiving this error:
** (exit) exited in: :gen_server.call(MyApp.Repo.Pool, {:checkout, #Reference<0.0.1.11>, true}, 5000)
** (EXIT) no process
:erlang.send(MyApp.Repo.Pool, {:"$gen_cast", {:cancel_waiting, #Reference<0.0.1.11>}}, [:noconnect])
(stdlib) gen_server.erl:416: :gen_server.do_send/2
(stdlib) gen_server.erl:232: :gen_server.do_cast/2
src/poolboy.erl:58: :poolboy.checkout/3
(stdlib) timer.erl:197: :timer.tc/3
lib/mongo/pool/poolboy.ex:33: Mongo.Pool.Poolboy.run/2
lib/mongo/pool.ex:142: Mongo.Pool.run_with_log/5
lib/mongo.ex:220: Mongo.insert_one/4
lib/mongo_ecto/connection.ex:124: Mongo.Ecto.Connection.catch_constraint_errors/1
lib/mongo_ecto.ex:522: Mongo.Ecto.insert/6
lib/ecto/repo/model.ex:253: Ecto.Repo.Model.apply/4
lib/ecto/repo/model.ex:83: anonymous fn/10 in Ecto.Repo.Model.do_insert/4
lib/ecto/repo/model.ex:14: Ecto.Repo.Model.insert!/4
How can I access Repo.insert in the correct way to save my data in mongoDb?
Thanks for this.
Your application (and therefore your database pool) is not started automatically in a Mix task. You can start it manually by adding the following:
:application.ensure_all_started(:my_app)
If :httpoison is listed in your Mixfile's :applications, you don't need to do HTTPoison.start anymore as the above line will ensure :httpoison is started before :my_app.

Puppet PostgresQL management

I am trying to provision an EC2 instance using puppet. In the process I have downloaded the puppetlabs-postgresql module from puppetlabs. Since I'm fairly new to puppet, i do not want to manage my database by creating classes in my site.pp file located in /etc/puppet/manifests/site.pp. Rather I want to have a module call database in /etc/puppet/modules/database.
What I have done so far is create an init.pp file in /etc/puppet/modules/database. Below is the content of my init.pp file :
class database {
# resources
postgresql::globals{'globals':
version => '9.3',
manage_package_repo => true,
encoding => 'UTF8',
locale => 'it_IT.utf8',
}
postgresql::server{'server':
ensure => 'present',
listen_addresses => '*',
manage_firewall => true,
}
postgresql::server::contrib{'contrib':
package_ensure => 'present',
}
}
And then in my /etc/puppet/manifests/site.pp file i have included the database class as below :
node default {
include localusers
include database
}
However i keep getting an error :
Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type postgresql::globals at /etc/puppet.manifests/init.pp:12
Please what is the correct way to make use of the postgresql classes and resources in my own module and create a database in the module as well ?
You're on the right track, but there are a few issues with how you're using the postgresql module. The reason you're getting the Invalid resource type error is that you're trying to use postgresql::globals as a defined type when it's actually a class. You have the same issue with the other two classes you're using. Try this...
class database {
# set global defaults before creating server
class { 'postgresql::globals':
version => '9.3',
manage_package_repo => true,
encoding => 'UTF8',
locale => 'it_IT.utf8',
}->
class { 'postgresql::server':
listen_addresses => '*',
manage_firewall => true,
}
# install the postgresql contrib package
class { 'postgresql::server::contrib':
package_ensure => 'present',
}
# create database with user and default permissions
postgresql::server::db { 'my_awesome_db':
user => 'my_db_user',
password => 'puppetRocks',
}
}
In the reference section of the module documentation, there's a breakdown of the classes and resources (a.k.a. defined types). The postgresql::server::db type that I used is the simplest way to create a database, user, and permissions all at once. There are separate types available for each of those to provide more fine-grained control.