WSO2 API Manager Mysql database initialization - mysql

I'm trying to change the carbon H2 database (for this test) for a MariaDB system. Once my master-datasources.xml and my databases created and configured thanks to the provided scripts, I start the API Manager but it fails with the following error :
ERROR - Activator Cannot start User Manager Core bundle
June 1st 2018, 14:51:07.000 org.wso2.carbon.user.core.UserStoreException: Cannot initialize the realm.
Caused by: org.wso2.carbon.user.core.UserStoreException: nullType class java.lang.reflect.InvocationTargetException
June 1st 2018, 14:51:07.000 Caused by: org.wso2.carbon.user.core.UserStoreException: nullType class java.lang.reflect.InvocationTargetException
Caused by: org.wso2.carbon.user.core.UserStoreException: Error occurred while checking is existing domain : PRIMARY for tenant : -123
I tried to use MariaDB only for the carbon database, using the following datasource config:
<datasource>
<name>WSO2_CARBON_DB</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/WSO2CarbonDB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://wso2_mysql:3306/wso2_am_carbon;DB_CLOSE_ON_EXIT=FALSE</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>
user-mgt.xml is using the correct datasource name :
<Property name="dataSource">jdbc/WSO2CarbonDB</Property>
and my database has been initialized with the dbscripts/mysql5.7.sql script. User permissions have been set correctly.
Since after the failed start the database stays empty I guess there is a problem writing to it. So I tried to start the app with the -Dsetup parameter but no luck.
Thank you.

In the very first startup of the WSO2 server without the datasource changes, It will add an admin user to the default userstore. Therefore, if you have already created admin user within configured AD and that user has defined as admin user in IS configurations, IS use that user as the admin user.
Therefore, When you change the datasource of the primary userstore of WSO2 Server, you need to change the addAdmin property as true in user-mgt.xml file which can be found under /repository/conf directory.
<Configuration>
<AddAdmin>true</AddAdmin>
<AdminRole>admin</AdminRole>
<AdminUser>
<UserName>admin</UserName>
<Password>admin</Password>
</AdminUser>
-
-
</Configuration>
Please check after changing the above property.

Related

When Connecting WSO2 apim in docker to mysql in local machine getting error while using useSSL=true in url

When Connecting WSO2 apim in docker to mysql in local machine getting error while using ssl=true in url .
Datasource connection code in apim:
<datasource>
<name>WSO2_CARBON_DB</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/WSO2CarbonDB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://host.docker.internal:3306/carbon_db?serverTimezone=UTC&useSSL=true</url>
<username>userame</username>
<password>password</password>
<driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
<defaultAutoCommit>true</defaultAutoCommit>
</configuration>
</definition>
</datasource>
It works fine when useSSL=false. useSSL= true gives the following connection failure error:
wso2am_1 | [2019-05-06 07:37:25,095] ERROR - TransactionManager Failed to start new registry transaction.
wso2am_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
Mysql server is 8.0 and ssl variables are as:
Please try with requireSSL=true.

WSO2 API manager failing to create new api with MySql

I have a new install of wso2 api manager v1.10.0. When using the default master-datasources.xml that uses the h2 database it works fine. I can click on the 'Deploy Sample API' button and the CalculatorAPI sample gets created properly. However, when I change master-datasources.xml to use MySql then trying to create the sample Calculator API hangs (the UI hangs at "Please Wait"). The CalculatorAPI is created but is not Published and the lifecycle cannot be changed to Published. The only change I made was to master-datasources.xml.
MySql and wso2AM are installed locally on Ubuntu Linux.
The data source configs for MySql I am using are:
<datasource>
<name>WSO2_CARBON_DB</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/WSO2CarbonDB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/regdb</url>
<username>regadmin</username>
<password>regadmin</password>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<maxActive>80</maxActive>
<maxWait>60000</maxWait>
<minIdle>5</minIdle>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
<datasource>
<name>WSO2AM_DB</name>
<description>The datasource used for API Manager database</description>
<jndiConfig>
<name>jdbc/WSO2AM_DB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/WSO2AM_DB</url>
<username>regadmin</username>
<password>regadmin</password>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<maxActive>80</maxActive>
<maxWait>60000</maxWait>
<minIdle>5</minIdle>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
I ran the following commands in MySql to apply privileges:
GRANT ALL ON regdb.* TO regadmin#localhost IDENTIFIED BY "regadmin";
GRANT ALL ON WSO2AM_DB.* TO regadmin#localhost IDENTIFIED BY "regadmin";
FLUSH PRIVILEGES;
I started api manager with -Dsetup and it did create tables under both regdb and WSO2AM_DB.
The MySql jdbc driver is in repository/components/lib/mysql-connector-java-5.1.38.jar.
I checked all the logs and there are no errors. Any help will be appreciated.
I tried the same scenario using wso2 API manager 1.10 with MySQL but it works for me.
If you are still getting this error
Delete the API and disconnect your wifi or broadband connection for a while and try.
If you can see the API in CREATED mode. click on the API and go to lifecycle tab and change the status to PUBLISHED.

How to prevent database renewing its data in camunda

I am using
- camunda-bpm-wildfly-7.4.0
- mysql-5.6.24-winx64
- wildfly-8.2.1.Final
I have integerated mysql with camunda wildfly.
My datasource code in the standalone.xml is as follows,
<datasource jta="true" jndi-name="java:jboss/datasources/ProcessEngine" pool-name="ProcessEngine" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:8888/camundabpm?DB_CLOSE_DELAY=-1;MVCC=TRUE;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>mysql</driver>
How do I prevent the database resetting on server restart? It removes all data and replaces it with new data on every server start. So I am unable to persist my data between server on and off.
Update:
I found out that hibernate was deleting the tables from the db So I changed the property from this
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
to
<property name="hibernate.hbm2ddl.auto" value="update" />
after having a look at How to make Hibernate not drop tables. But now the tasklist process instances are removed and only the tables created by my project remain and all other tables are refreshed with new data.
Can you check the value of the databaseSchemaUpdate poroperty? It should be contained in the standalone.xml of our WildFly (very down). Make sure it os not set to create-drop.
See https://docs.camunda.org/manual/7.4/reference/deployment-descriptors/tags/process-engine/#configuration-properties

arquillian, wildfly change datasource to mysql - error missing/unsatisfied dependencies

i have working arquillian tests that use default h2/mem data base. now i want to switch to my sql.
I first copied mysql-connector-java-5.1.33-bin.jar to standalone/deployments. The log confirmed proper deployment. I also tried to setup the mysql datasource via wildfly's admin console and it worked fine (i did connection test but didn't add the datasource).
I want to keep the datasource setup within project's test. So i added the data source to src/test/resources/test-ds.xml:
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<datasource jndi-name="java:jboss/datasources/moritzTimetrackerTestDSmysql"
pool-name="moritzTimetracker-test" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/moritztimetracker</connection-url>
<driver>mysql-connector-java-5.1.33-bin.jar</driver>
<security>
<user-name>user</user-name>
<password>pass</password>
</security>
</datasource>
The src/test/resources/META-INF/test-persistence.xml looks like this:
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/moritzTimetrackerTestDSmysql</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
But if i run the test i get exception:
org.jboss.arquillian.container.spi.client.container.DeploymentException: Cannot deploy: test.war
...
Caused by: java.lang.Exception: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.data-source.java:jboss/datasources/moritzTimetrackerTestDSmysql is missing [jboss.jdbc-driver.mysql-connector-java-5_1_33-bin_jar]"]}
The log says:
JBAS014775: New missing/unsatisfied dependencies:
service jboss.data-source.java:jboss/datasources/moritzTimetrackerTestDSmysql (missing) dependents: [service jboss.data-source.reference-factory.java:jboss/datasources/moritzTimetrackerTestDSmysql]
service jboss.data-source.reference-factory.java:jboss/datasources/moritzTimetrackerTestDSmysql (missing) dependents: [service jboss.naming.context.java.jboss.datasources.moritzTimetrackerTestDSmysql]
service jboss.jdbc-driver.mysql-connector-java-5_1_33-bin_jar (missing) dependents: [service jboss.data-source.java:jboss/datasources/moritzTimetrackerTestDSmysql]
service jboss.persistenceunit."test.war#primary".__FIRST_PHASE__ (missing) dependents: [service jboss.deployment.unit."test.war".POST_MODULE]
How to correctly setup mysql as data source?
Your setup seems correct (I mean data source and persistence xml).
But please check whether you are deploying test-ds.xml file along with your app in every test case. I mean:
#Deployment
public static Archive<?> createDeployment() {
return ShrinkWrap.create(WebArchive.class, "test.war")
.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource("test-ds.xml") /* CRUCIAL STEP */
...
}
In this way, your data source definition is deployed with every micro deployment of your EJBs.
Since it is very badly documented i viewed the standalone.xml after i created the data source via the admin web interface. Setting the mysql datasource this way works fine:
<datasource jndi-name="java:jboss/datasources/testDSmysql"
pool-name="test" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/db</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql-connector-java-5.1.33-bin.jar_com.mysql.jdbc.Driver_5_1</driver>
<security>
<user-name>user</user-name>
<password>pass</password>
</security>
</datasource>
See "drive-class" and "driver" - it is very different than stuff you read in documentation?!

The underlying provider failed to open , login failed for user IIS APPPOOL

i am not a sql server guy but i am working on a client's application and want to connect to the database through EF Code first
the Exception message that i have is
The underlying provider failed to open
The Exception details
Cannot open database [DatabaseName] requested by the login. the login failed
login failed for user 'IIS APPPOOL\ASP.NET v4.0"
My web config
<add name="TraininGoDB"
providerName="System.Data.SqlClient"
connectionString="Server=LOCALPCNAME\SQLEXPRESS;Database=[DATABASENAME];Integrated Security=True;"/>
The EF context and entities are defined in a separate project with the app config of the following
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
i am using SQL Server Express 2008
don't know the problem from the database configration or from the web config
The user under which the web application pool (associated to your web application) is running doesn't have permissions to access your database. You need to grant it permissions or run under another user who has permissions. So, to summarize: check under which user your application pool is running, then check that that user has access to your database.
If all of your Web.config files are correct, SQLSERVER has the appropriate permissions, etc., there's one more thing you can check. I once had this issue when a client had me configure the project so that Entity Framework would not automatically drop the databases (if, for example, the models changed), but I was still testing the project on localhost. I thus needed to create a new database, but I forgot to fix my context files. For example, my problem was:
public MasterContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
Database.SetInitializer<MasterContext>(null);
}
when it should have been (for the purpose of testing):
public MasterContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
Database.SetInitializer<MasterContext>(new DropCreateDatabaseIfModelChanges<MasterContext>());
}
Otherwise, I would receive the same error, that the underlying provider failed on open, with the inner exception being that the login failed for the user.