Grails on STS: How to run >1 grails app simultaneously - eclipse

The workspace consists of 2 projects. One is the main, user-facing, grails app, which runs on port 8080. The other is an admin app, also grails, by which all kinds of stuff for the main app is configured (and I'd like to get to run, simultaneous to the main app, on 8081).
I do not know how to get the two to run simultaneously (and have failed to find the answer via google). I want to do this, so that I could change stuff for the main app in the admin app, and test those changes in the main app, without constantly shutting down one in order to start the other.
I have tried setting the config.groovy parameter, for my local environment, to
grails.serverURL = "http://localhost:8081/admin-app"
(whereas the main app specifies grails.serverURL = "http://localhost:8080/main-app")
I have tried adding " -Dserver.port=8081" as a program argument in the run configuration for the admin app, but this does not do the trick.
My humblest thanks to the eclipse/STS guru who has the answer to this problem.

You should not add the server.port as a program argument. It needs to be a vm argument.
VM arguments are added on the arguments tab:
So, should be added on the bottom, not the top.

Related

Cannot view data from GCP Datastore (Firestore) in browser when using emulator

I am using Google's Datastore (which is Firestore's support for the GCP) and the emulator to handle storage locally. Everything works fine as far as storing data. But there does not appear to be any way of actually viewing the data in the browser. I have a feeling that this is not yet implemented because the emulator is still in beta. Has anyone been able to view data in their browser? It should be stressed that this is the emulator provided by the Google Cloud Platform SDK and not the one that Firebase uses for its products. The emulator is started with:
gcloud beta emulators datastore start
As of January 2022
Debugging
Setting up Firebase Datastore Emulator (FDE)
The Firebase Datastore Emulator (FDE) emulates the Google Datastore in App Engine. This is meant to run on Java 8 platforms. When correctly setup, any Datastore operations are done locally and stored to a file called local_db.bin.
The documentation for using the Firebase Datastore Emulator can be found at:
https://cloud.google.com/datastore/docs/tools/datastore-emulator
It should be noted that this documentaton contains errors and is missing some important settings. To use Firebase Datastore Emulator, install the emulator by running the following command from a terminal:
gcloud components install cloud-datastore-emulator
Start the emulator in a terminal:
gcloud beta emulators datastore start --data-dir=fbdatastore --host-port=localhost:8100
The official documentation does not indicate to use the --host-port flag. If you leave this flag out, a random port will be selected. But experience has shown that letting the port be randomly selected can result in exceptions generated by the client library used to access the local datastore - even when the port is correctly set in the environment variables.
The --data-dir flag indicates the directory where the local database file is stored. Here, it is specified as fbdatastore but you can use any folder located anywhere. You should make sure that the folder already exists before you start the emulator. In the example shown here, no path is included. This means that when you start the emulator, the directory specified by --data-dir should be in the same folder where you are launching the emulator.
The emulator will only create the local_db.bin file when you initially write data to it. If you don't write any data, it will not be created. Even it isn't created, the client APIs will still work correctly when reading from it, typically returning null values for any entities that you attempt to access. No exception will be thrown if the database file does not exist.
If the --data-dir is set to fbdatastore as used here, the local_db.bin file will be created under:
fbdatastore/WEB-INF/appengine-generated/local_db.bin
After the emulator has started, you can verify that it is running but opening a browser window and navigating to the url:
http://localhost:8100
This will only display the text "ok".
Before you can start debugging the app, several environment variables need to be set. You need to open a new terminal window and execute the following commands to set several variables:
export DATASTORE_DATASET=[project-id]
export DATASTORE_EMULATOR_HOST=localhost:8100
export DATASTORE_EMULATOR_HOST_PATH=localhost:8100/datastore
export DATASTORE_HOST=http://localhost:8100
export DATASTORE_PROJECT_ID=[project-id]
export DATASTORE_USE_PROJECT_ID_AS_APP_ID=true
The client libraries for the Datastore expect the app id to be used. But it was found that using only the app id didn't work. The environment variable DATASTORE_USE_PROJECT_ID_AS_APP_ID needs to be set as well. This is not specified in the documentation.
It should be noted that the official docs show the following:
export DATASTORE_DATASET=my-project-id
export DATASTORE_EMULATOR_HOST=::1:8432
export DATASTORE_EMULATOR_HOST_PATH=::1:8432/datastore
export DATASTORE_HOST=http://::1:8432
export DATASTORE_PROJECT_ID=my-project-id
For MacOS, this is wrong. The variables with values set to ::1 is wrong. Using this will cause exceptions and probably prevent the emulator from even loading. The ::1 needs to be replaced with localhost, as shown above.
You can just copy the 6 lines shown above and paste them into a terminal and hit Enter. But it is easier to just place these into a bash file and execute it. These need to be set before the local development server is started. The following bash file will set the environment variables and then start the development server:
export DATASTORE_DATASET=[project-id]
export DATASTORE_EMULATOR_HOST=localhost:8100
export DATASTORE_EMULATOR_HOST_PATH=localhost:8100/datastore
export DATASTORE_HOST=http://localhost:8100
export DATASTORE_PROJECT_ID=[project-id]
export DATASTORE_USE_PROJECT_ID_AS_APP_ID=true
java_dev_appserver.sh --address=0.0.0.0 --port=8080 --disable_update_check --jvm_flag=-Xdebug --jvm_flag=-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 build/exploded-website
Replace [project-id] with the project id shown in your Googel Cloud Platform console (don't include the square brackets).
The address parameter for java_dev_appserver.sh is set here to 8000. You will need to set this in your IDE. Also, the port for java_dev_appserver.sh is set to 8080. You can set this to whatever works on your system and doesn't conflict with any existing ports used elsewhere. The last parameter for java_dev_appserver.sh is the location of your war files, which is the compiled app. Here, it is located at build/web-site. Replace this with the location of your own build files.
To view the datastore locally in your browser, navigate to:
http://localhost:8080/_ah/admin/datastore
Details on the command parameters used to start the emulator can be found at:
https://cloud.google.com/sdk/gcloud/reference/beta/emulators/datastore/start
As far as I can understand what you want to do is to add data in the Datastore emulator running on your console and be able to see this data in the UI right?
Vieweing the data in the UI actually incurs in expenses for you because Datastore have to query the data to be able to display it on the UI.
I can still recommend you to create a Feature Request if you want to be able to see the entries form the Datastore emulator for free in the UI

Why do Selenium tests behave different on different machines?

I couldn't find much information on Google regarding this topic. Below, I have provided three results from the same Selenium tests. Why am I getting different results when running the tests from different places?
INFO:
So our architecture: Bitbucket, Bamboo Stage 1 (Build, Deploy to QA), Bamboo Stage 2 (start Amazon EC2 instance "Test", run tests from Test against recently deployed QA)
Using Chrome Webdriver.
For all three of the variations I am using the same QA URL that our application is deployed on.
I am running all tests Parallelizable per fixture
The EC2 instance is running Windows Server 2012 R2 with the Chrome browser installed
I have made sure that the test solution has been properly deployed to the EC2 "test" instance. It is indeed the exact same solution and builds correctly.
First, Local:
Second, from EC2 Via SSM Script that invokes the tests:
Note that the PowerShell script calls the nunit3-console.exe just like it would be utilized in my third example using the command line.
Lastly, RDP in on EC2 and run tests from the command line:
This has me perplexed... Any reasons why Selenium is running different on different machines?
This really should be a comment, but I can't comment yet so...
I don't know enough about the application you are testing to say for sure, but this seems like something I've seen testing the application I'm working on.
I have seen two issues. First, Selenium is checking for the element before it's created. Sometimes it works and sometimes it fails, it just depends on how quickly the page loads when the test runs. There's no rhyme or reason to it. Second, the app I'm testing is pretty dumb. When you touch a field, enter data and move on to the next, it, effectively, posts all editable fields back to the database and refreshes all the fields. So, Selenium enters the value, moves to the next field and pops either a stale element error or can't find element error depending on when in the post/refresh cycle it attempts to interact with the element.
The solution I have found is moderately ugly, I tried the wait until, but because it's the same element name, it's already visible and is grabbed immediately which returns a stale element. As a result, the only thing that I have found is that by using explicit waits between calls, I can get it to run correctly consistently. Below is an example of what I have to do with the app I'm testing. (I am aware that I can condense the code, I am working within the style manual for my company)
Thread.Sleep(2000);
By nBaseLocator = By.XPath("//*[#id='attr_seq_1240']");
IWebElement baseRate = driver.FindElement(nBaseLocator);
baseRate.SendKeys(Keys.Home + xBaseRate + Keys.Tab);
If this doesn't help, please tell us more about the app and how it's functioning so we can help you find a solution.
#Florent B. Thank you!
EDIT: This ended up not working...
The tests are still running different when called remotely with a powershell script. But, the tests are running locally on both the ec2 instance and my machine correctly.
So the headless command switch allowed me to replicate my failed tests locally.
Next I found out that a headless chrome browser is used during the tests when running via script on an EC2 instance... That is automatic, so the tests where indeed running and the errors where valid.
Finally, I figured out that the screen size is indeed the culprit as it was stuck to a size of 600/400 (600/400?)
So after many tries, the only usable screen size option for Windows, C# and ChromeDriver 2.32 is to set your webDriver options when you initiate you driver:
ChromeOptions chromeOpt = new ChromeOptions();
chromeOpt.AddArguments("--headless");
chromeOpt.AddArgument("--window-size=1920,1080");
chromeOpt.AddArguments("--disable-gpu");
webDriver = new ChromeDriver(chromeOpt);
FINISH EDIT:
Just to update
Screen size is large enough.
Still attempting to solve the issue. Anyone else ran into this?
AWS SSM Command -> Powershell -> Run Selenium Tests with Start-Process -> Any test that requires an element fails because ElementNotFound or ElementNotVisible exceptions.
Using POM for tests. FindsBy filter in c# is not finding elements.
Running tests locally on EC2 run fine from cmd, powershell and Powershell ISE.
The tests do not work correctly when executing with the AWS SSM Command. Cannot find any resources to fix problem.

Docker with shared X11 socket: Why can it "start" Firefox outside of the container?

I have the following scenario:
I set up a Docker container with access to the X11 socket, essentially I did this: https://stackoverflow.com/a/25334301
Then I installed Firefox within the container and started it using the "firefox" command in bash.
What I noticed: If Firefox was already running on my host machine when I started it in the container, it essentially "escaped" the container as it just opened a new window of the host instance of Firefox. It therefore had access to everything on the host machine and the container became useless.
This also works vice versa: If Firefox is not running on the host and I start an instance in the container, it is really running inside the container. If I then start Firefox on the host, the new instance is also running inside the container.
However, I couldn't reproduce this behavior with gvim instead of Firefox.
I am well aware of the security problems inherent with X11 socket sharing, but I cannot explain the scenario I described above. Why can a container start a "process"---or rather a window---outside of its restricted environment? And how is it even possible that my host system starts a process within a container only because the same program is already running inside a container?
(Please note that I didn't know how to call such a graphical instance of a program other than "process", although it's probably not a real process in this case...)
System: Ubuntu GNOME 14.10, Docker 1.5, ubuntu:latest Docker image.
UPDATE: This doesn't happen if I start Firefox using the -new-instance flag, so it seems to be more of a Firefox problem than a X11 socket problem.
UPDATE 2: Seems that this happens in other scenarios as well, for example using ssh with X-forwarding:
https://unix.stackexchange.com/questions/104476/why-starting-firefox-from-command-line-in-vm-starts-the-firefox-in-the-host-ma
and
https://superuser.com/questions/462055/launching-firefox-on-remote-server-causes-local-firefox-to-open-the-page-instead
Now the question is, how the hell does Firefox do this? What kind of X11 sorcery do they use to find out if Firefox is already running?
Because you forward the x11 socket into the container, any graphical program, whether inside the container or outside the container, will be talking to the same Xorg server. This is the same as when using ssh with X-forwarding.
Now let's say that one firefox instance is already started and communicating with that xserver. If we are the second firefox process starting up, we might find that first process by navigating the window tree from the root. We might be able to identify a window belonging to firefox through some properties that it sets on it's windows. Once we found a window belonging to firefox, we might send a message to the process owning that window, asking it to add a new tab.
Perhaps if we find such a process and ask it to open a new tab, we just die off as our job is done.
Of course, we could always just look at the source and find out that indeed firefox does basically this. In particular they:
find an existing window
and then notify it
But they don't notify it with a client message. They do it by changing a window property. Presumably the process that creates the window also subscribes to property change notifications. In case you're curious the full path through the code is:
from parsing the command line, StartRemoteClient
which creats a client (note that they do this over d-bus/wayland also) and then calls SendCommandLine()
which is a virtual function, so find it's override XRemoteClient
and in there you see where it calls the previous two functions linked to FindBestWindow() and then DoSendCommandLine().

Install4j: Howto copy and modify a launcher at runtime

In my installer i need a number of launchers, to install them as services, based on the user input. Those Launchers are all the same except for an index in their name.
I dont want to create all those launchers manually because that would be impossible to maintain.
Is there a way to copy and modify launchers at installer runtime and then install them as a service?
There is no reason to duplicate a service launcher at runtime. You can use an "Install service" action to install several services with different service names. To do that select "Other service executable" in the "Service" property of that action, then you can select and executable and a (variable) service name as well as variable arguments.
I have a Usecase too, where i want to have this Possibility of Renaming the Launcher an Runtime.
Assume you want to have a Testinfrastructure, where you want not only to test one Instance of your Programm, but several. And you want to use the Launchers from Install4J to start your Application.
Assume you have 5 Services that need to be started to provide the desired Functionality. Now think of having 10 Instances for 10 Customers, you want to test. Further you want to test it not on 10 different Machines, Docker, VM's, or what ever but on one single Machine.
This isn't possible, since you can't rename the Services at Runtime.
Wolfgang, i understand your Problem. Mine is similar.
I played a bit around with the Launcher.exe.
Perhaps there's a Solution for your Case.
Assuming your desired Launchernames are all off the same Length, like:
- Launcher_01.exe
- Launcher_02.exe
- Launcher_03.exe
- Launcher_04.exe
- Launcher_05.exe
You can then generate a Launcher once, with the Name "Launcher_xy.exe".
It's now possible to open up your favorite Hex-Editor an search for "Launcher_xy", rename it to "Launcher_01" and save the Data back to the exe-File. But be aware of not changing the Length of the Name. It won't work, if you'll change the Length.
So if you've changed the Name and afterwards execute
Launcher_xy.exe -install non-interactive
you will get a new Service called "Launcher_01.exe" under Windows-Services.

A service cannot spawn a new program unless it's running under Local System Account

First of all, I'm not sure if this is generic to services in general, but the problem I'm having is pretty specific, it has got to do with the SageTV service component.
Since there isn't much help over at the SageTV forums regarding this specific subject, I thought maybe this was a generic issue with services and therefore worth asking here at Stackoverflow.
Here goes:
I'm running the SageTV windows service with a plugin activated which is supposed to execute external programs. When running under the Local System Account (with the "Interact with the desktop option" enabled), this works fine. For testing purposes I'm using notepad.exe as the program to execute.
Then I created a new user (let's call it mediabrowser) and changed the SageTV service so it would run as that user. When I do that, the SageTV plugin no longer executes notepad. It just does nothing, I don't get any errors or anything, it's just that nothing happens when notepad should be getting executed.
The mediabrowser user has administrative priviliges. The option to interact with the desktop is only available for the Local System Account, and I believe that normal users are always allowed to interact with the desktop anyways.
Is this a general issue with services? If so, what permissions might my mediabrowser user need in order for this to work? I'm pretty sure this is because of permission differences between my mediabrowser user and the Local System Account.
Thanks in advance ...
Uhhh OK. Now I feel like an idiot. I just launched the tast manager on the machine and I can see that there are tons of notepad.exe processes under the mediabrowser user so I guess that notepad IS being executed correctly. It's just not being shown on the desktop.
So I guess this just works :-)