Bug 1013886

Summary: Read server config from file
Product: [Community] PressGang CCMS Reporter: Matthew Casperson <mcaspers>
Component: Web-UIAssignee: Matthew Casperson <mcaspers>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 1.1CC: cbredesen, lnewson
Target Milestone: ---   
Target Release: 1.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-12-03 22:16:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Matthew Casperson 2013-10-01 02:00:03 UTC
Hard coded REST servers make the UI hard to deploy outside of RedHat, means it has to be compiled twice to be deployed on dev servers, and also impact things like testing. The server config should be:

1. Read from a config file deployed alongside the UI
2. Use a setting specified by a user
3. Fallback to using the same URL that hosts the UI

Comment 1 Matthew Casperson 2013-11-18 22:15:41 UTC
These server details can be loaded from a JSON file on the server at /pressgang-ccms-config/servers.json. The following is an example of the format of this file.

 [
  {
     "serverId": 1,
     "serverName": "My Server",
     "serverGroup": "Default Servers",
     "restUrl": "http://myserver.com/pressgang-ccms",
     "reportUrl": "http://mybirtserver.com",
     "monitoringUrl": "http://myserver.com/pressgang-ccms/monitoring",
     "readOnly": false
  }
 ]

If the server does not respond with a valid JSON file, the last valid JSON file saved to local storage will be used.

If there is no valid JSON file in local storage, the default locations for the server will be used.

Comment 2 Matthew Casperson 2013-11-18 23:56:24 UTC
This system requires a project to server up static content. https://github.com/pressgang-ccms/PressGangCCMSConfig is an example of this.

Comment 3 Matthew Casperson 2013-11-19 00:09:47 UTC
Fixed in 201311191000

This can be verified on the dev server.

Comment 4 Matthew Casperson 2013-11-19 00:21:55 UTC
You can also copy the file welcome-content/pressgang-ccms-config/servers.json assuming you don't have a ROOT.war file, and you have not disabled the welcome content.

Comment 5 Lee Newson 2013-11-24 23:39:30 UTC
Verified that the UI will now read from a servers.json file located at /pressgang-ccms-config/servers.json. If the servers.json file doesn't exist then it will use the default settings which point the rest server to the same host as the UI. It also groups the servers together properly so that the fail over will occur.

However if the servers.json contains no valid servers (ie the restServer value is missing) then the ListBox is populated with no values, when it probably should revert to the default.

Another problem is that the UI will save invalid configs to local storage as well (this happens as soon as the servers.json is returned), so if I had a valid version previously then did a minor update that was invalid, it wouldn't revert to the last valid settings and instead would fall through to the default settings.

Comment 6 Matthew Casperson 2013-11-25 03:53:37 UTC
I have added some validation checking to make sure that every server defined in the servers.json file has all the required fields, and that at least one server is defined. If that is not the case the settings are not saved into local storage and the server details are loaded from any previously saved settings, or use the default.

Comment 7 Matthew Casperson 2013-11-25 04:56:40 UTC
Note that my initial implementation was flawed. Getting the server details is now an inherently asynchronous operation because the details may be sourced from an external file.

This means that every call to ServerDetails.getSavedServer() has been changed from a synchronous call that returned the server details to an asynchronous callback.

This has no practical effect since once the server details are loaded for the first time, the "asynchronous" callback actually operates as a synchronous call (i.e. it calls the callback immediately). And the server details are first loaded when the app is opened and before any part of the UI is displayed.

I'm making a note of it here because of the number of calls to ServerDetails.getSavedServer() that had to be changed.

Comment 8 Lee Newson 2013-11-26 03:53:16 UTC
Using an invalid JSON config file appears to completely kill the UI now. All that happens is that an error about being unable to parse the file is logged and then you get a plain white screen.

The above is caused by the default settings not executing the callback.

When using multiple servers the list that is populated is always the same server now. This is caused my the populate method getting all the servers and then for each one of them only getting the "saved" server.

Other than the above issue I've verified the following:

- Invalid JSON will fall-back to local storage and then back to the defaults (except the defaults don't call the callback).
- If a required property is missing from a server definition, the entire servers.json is rejected and it will fall-back.
- If no servers are defined then it will fall-back.

Comment 9 Lee Newson 2013-11-26 04:00:08 UTC
Changing servers also doesn't work with the new implementation.

Comment 10 Lee Newson 2013-11-26 04:16:29 UTC
Ignore the above statement as upon looking into it more, the servers are changed however the AlertBox doesn't block the page from reloading so you don't see the warning message when switching between two different server groups.

Comment 11 Lee Newson 2013-11-26 04:54:20 UTC
The above instances should now be fixed and is currently live on the dev server.