I'm following the example usage as described here https://helpx.adobe.com/coldfusion/using/docker-images-coldfusion.html to create datasources using my setupColdFusion.cfm. I can create datasources just fine but apparently the default datasoruces cfartgallery, cfbookclub, cfcodeexplorer and cfdocexamples are not yet created when the setupColdFusion.cfm is run. Thus, statements like:
in my setupColdFusion.cfm will result in errors like:
coldfusion.runtime.UndefinedElementException: Element cfartgallery is undefined in a Java object of type class coldfusion.server.ConfigMap.
What is the suggested way to delete unwanted datasources at setup?
My broader suggestion is that whenever you have something where you're not sure whether it's going to work or not, you wrap it in an exception handler and move on. So, you'd try your DB remove, and catch the failure (if it fails), and you'd be able to read the failure reason in the CFCATCH structure. If it's because the DB doesn't exist, you're all set and you can treat that as a normal outcome and keep going. If it's for some other reason, then you have to figure out how to respond to that other reason.
Dave Watts, Eidolon LLC
Thanks for the suggestion Dave. In this case I know its going to fail. I could add try/catch around these statements but knowing the datasources don't exist at the time the script is run I've simply removed them. The issue for me is at completion of the initialization of the Docker container those datasources will exist and I'd like to remove them in an automated fashion. I had the expectation the startup script would be able to complete the desired configuration when the Docker containers are first run. Was hoping someone with experience with these Docker images that had also run into this issue would have a work around other than manually deleting them later.
ecarey :"What is the suggested way to delete unwanted datasources at setup?"
Without code certainly!
Open the ColdFusion Administrator.
Go to the datasources page.
Click on the delete button of the datasource concerned.
And you're done in under 10 seconds. 🙂
I can confirm that
1) there is nothing wrong with the code you mentioned;
2) your code probably worked as expected;
3) you got the error because, when you ran the code, there was no cfartgallery datasource; it either had not been configured or had been deleted earlier.
I copied the same code and ran it as follows:
<cfscript> adminObj = createObject("component","CFIDE.adminapi.administrator"); adminObj.login("my_cfAdmin_password"); // Create datasource object datasource = createObject("component", "CFIDE.adminapi.datasource"); // delete datasource movedb datasource.deleteDatasource("movedb"); //writedump(datasource.getdatasources()) </cfscript>
The result is that it deleted the datasource movedb, as expected. The dump confirmed this.
When I ran the same code again, I got an error identical to yours:
@ecarey: What is the suggested way to delete unwanted datasources at setup?
I would first complete setup, then delete unwanted datasources afterwards.
Thanks for the suggestions BKBK. The Docker container has one initialization script available to me. It is specified via it's setupScript env var. That one script is run before the existance of the extra datasources thus I cannot delete them using it. I must do an additional step. Like you point out, its not that big a deal to do so from ui or script. It's just an unfortunate consequence of having the one setup script run before those datasources are created by the container. It would have been a more convenient implementation of the Docker container to run the setup script after their creation... so they could be deleted without having to come up with a workaround.