Grails - switching data sources based on User - database

We are developing a Grails web application, where different users (customers) need to be pointed at different databases containing only their organization's data. Unfortunately, the separated databases are a requirement, and we are being asked to be able to have only 1 web application for everybody.
However, Grails expects only a single datasource pool connecting to one database.
We want to be able switch database connections, per session, based on the user that is logged in, where the different connections are read in from properties files during the BootStrap init().
So far, we have been unable to find a solution that does not seem to have race conditions, there is no plugin we can find, and it doesn't seem to be a popular issue.
Our most promising was creating a custom dynamic data source, set up in Bootstrap to define a map of organization->dataSource, and utilizing a closure defined in Bootstrap to find the appropriate dataSource before GORM behavior, but this seems to cause race condition when there is latency.
Does anyone have an idea how this switching can legitimately be performed?
Thanks

Considering Grails is built upon Spring your best bet is to develop your own resolvable datasource.
Dynamic datasource routing
Example of datasource routing

It's not clear in your question if you're deploying your application once, and trying to configure the DataSource used by User, or if you just want to configure by deployment.
If it's just per deployment, Grails allow you to externalize the configuration. You can set this to use a file in the classpath or in a static location.

Related

Create multiple databases dynamically in Microsoft Azure

I am a newbie in Microsoft Azure platform. I want to create multiple databases dynamically (We are developing multi-tenant model. So, Each organization should have their own database. Whenever an organization is registered with our system, we need to create a new database dynamically). Please provide some insights on this.
By using Azure Resource Manager Templates you can reliably deploy the whole infrastructure required by each organisation. So if they need a webserver, database and middleware servers, you can define the whole thing in a template and reliably deploy that for every client.
(from the above link)
You can deploy, manage, and monitor all of the resources for your solution as a group, rather than handling these resources individually.
You can repeatedly deploy your solution throughout the development lifecycle and have confidence your resources are deployed in a consistent state.
You can use declarative templates to define your deployment.
You can define the dependencies between resources so they are deployed in the correct order.
You can apply access control to all services in your resource group because Role-Based Access Control (RBAC) is natively integrated into the management platform.
You can apply tags to resources to logically organize all of the resources in your subscription.
You can clarify billing for your organization by viewing the rolled-up costs for the entire group or for a group of resources sharing the same tag.
The link above has a lot of resources for learning how to use templates as well as the syntax and usage.
There are a large number of templates at the Azure ARM Template Github page and even some pre-existing templates to get you started deploying SQL Server to Azure (there's also mysql and postgress if you prefer)
Plus many others that you can work through to get accustomed to how they work.
you can use the AZURE SQL Database REST API to do so, its as simple as sending a PUT Request to a URL https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/microsoft.sql/servers/{server-name}/databases/{database-name}?api-version={api-version}
Check out these links for more details
https://msdn.microsoft.com/en-us/library/azure/mt163571.aspx
https://msdn.microsoft.com/en-us/library/azure/mt163685.aspx

Administer DotNetNuke Users From Desktop Application?

There is the UserController class that lets us access and save user data.
I think UserController was meant to be used from within the context of a DNN website application, since it somehow already knows the connection string and other DNN settings.
So I take it that DNN Controller classes can't be used outside the context of a DNN website application, thus I can't add/revoke roles, reset password, and other administrative actions from a desktop application, correct?
If it's possible, please let me know. Thank you.
That's not possible out of the box but some reference can be available here which does somewhat similar things: http://iweb.codeplex.com/
Most of what you are asking for are pretty simple DB operation. You could use Entity Framework to map tables into classes in your .Net App and then issue Update commands. However, these will be executed outside of DNN and may not impact a currently logged on user unless you clear the cache of DNN or restart app.
You could write custom WebAPI methods to do so as Hammond suggested above. You need to ensure that these methods are secure though and only Admin / Host can execute them.

Using Multiple Databases With iOS App

I have an iOS app that currently stores and pulls its data in/from SharePoint lists via a web service. I want to have the option in settings for the app to also use another database or cloud database i.e. parse.com
I don't want to have to put if statements all throughout my code to test whether the app is set up to use either of the repositories.
What's the best way in an iOS app to architect it to use multiple repositories/databases to store and retrieve the data used in the app?
Build a data manager class that handles the logic. I would go so far as to create one for each service you are attaching to. They can all inherit from a single base class and share the local cache code (which I am assuming is Core Data based on your tags). Then on launch you can instantiate the one you want to use.
I would NOT use a Singleton as suggested. Better to use Dependency Injection and be able to tear down and build up a new data manager if you switch between services while your application is running. Using a singleton would be a poor design decision.
If you localize all of your network code into a single class (something I was speaking about last year as a Network Controller) you can then easily switch between services by keeping your interfaces the same.

How does writing to a database work when a web app uses multiple databases like Sitecore has

In Sitecore you basically have three databases. The Core, Master and Web database.
Simply put the Core database holds all Sitecore settings. The Master database is the authoring database. So it contains all versions of any content.
Then in Sitecore you can "publish" the contents and it will publish the latest version of each content to the Web database.
So suppose I have a website with a news page. And a user is able to edit a news item from the web site (so not through the CMS). How would the database then get updated when it's set up like this?
It would probably update the Web database, but then when I go into the CMS I don't see the latest changes, since the CMS reads from the Master database, right?
So does that mean that it should write twice? Once to the Web database and once to the Master database?
Can anyone tell me how this works in Sitecore or the like?
The reason I'd like to know this is becasue I'm thinking of creating a similar database setup. And I'm just not sure how to solve this issue.
When you have items that needs to be updated by the website visitor, you need to use the SitecoreService SOAP webservice or create your own custom webservice that runs on the Master-instance and triggers a publish after updating.
Well, Sitecore has a publishing step. When the user publishes in Sitecore, it updates the Web database at that point. If you want to build a similar system, I would simply store all versions of an item in the Master database and only when the user chooses to publish, copy the latest version to the Web database.
If your site
- generates a lot of comments
- generates the comments continuously
- uses multiple content delivery servers
- requires CMS users to manage them
I would not store the comments as content items.
The reason is HTML cache and publishing behavior.
On high volume site you'd most certainly use html caching to achieve best possible performance. If a publish is required to show comments, you'd need frequent publish actions and thus html caches are cleared often.
You don't wan't that :-)
Modeling after the DMS implementation is the safest (not cheapest and Datatables isn't something I recommend these days), storing stuff in a separate database, possibly using queuing to prevent an overload if things get busy..

Scaling AppEngine applications

I've been thinking lately about the pros and cons of using AppEngine.
My concern would be, when we create application for GAE, the front-end code (the UI stuff) is served from the same application instance in the GAE cloud as with the Datastore codes.
The question would be when my applications grows:
For GAE:
Do I need to create multiple instance of my application?
If so, what do I need to manually update all instances?
For Appscale:
Do I also need to create multiple instance of my application?
If so, what do I need to manually update all instances?
GAE starts new frontend instances automatically, you even can't create or update frontend instances. You just need to configure min/max latency, min/max idle instances in Application Settings. See docs for performance settings
Btw, there are also Backend Instances that can be Resident and started manually from Admin Console. But it's useful only when you need something very specific
You seem to have missed the whole point of AppEngine, which is that Google takes care of scaling your app for you automatically. You seem to be confusing 'instance' with 'version' - you have control over which version of your app is serving, but Google dynamically creates and kills instances of that app depending on load. That's the main benefit of using AppEngine in the first place.

Resources