Prevent Command Execution Failures using Dynamic Instance Naming

Payara

When creating instances, it can sometimes be a chore remembering what names are already in use or even coming up with a name to use in the first place!  The Dynamic Instance Naming feature, sometimes called auto-naming, introduces a new option to the create-instance & create-local-instance commands that, when enabled, will resolve any name conflicts or generate a name for you.

The Dynamic Instance Naming feature is activated by the new -a (or –autoname if you fancy being verbose) option on the command line, like so:

asadmin -a create-instance --node localhost-domain1 instance1

In the above example, if an instance named instance1 didn’t exist, you’d get your instance as normal. If an instance did exist with the same name (or another resource has that name – remember that things like deployment groups share the same name space!), what would happen is you’d get an instance named something along the lines of instance1-BemusedCatfish. Previously, you’d have just got an error!

Now, what would happen if you omitted the instance name altogether like so?

asadmin -a create-instance --node localhost-domain1

Payara Server will now auto-generate a name for you, that’s what would happen! The server will auto-generate a name similar to ConfusedCarp and create an instance using it. Those of you familiar with the Payara Platform will recognise that this is very similar to the names that Payara Micro instances generate for themselves!

Obviously, if you’d rather the commands fail when a conflict is found, or prompt you to enter a name, you can simply omit this new option: it’s all optional and off by default.

Setting Up Instances Via Scripts

Now while this may just sound like a silly gimmick feature, it does have some actual uses. The most obvious one is when setting up instances via scripts. Rather than having to specify the name of each instance before you start running commands, and then having those commands fail if a conflict is found, you can now use the auto-name option and combine it with the new, extra terse option to set the names of variables on the fly:

INSTANCE_NAME=”$(asadmin -T -a create-local-instance --node localhost-domain1)”
asadmin start-instance ${INSTANCE_NAME}

“Wait? Extra terse? What’s that?” I hear you cry: it’s another option we added, specifically for this situation. It’s enabled via the -T flag (in comparison to “normal” terseness being enabled via “-t”), and will make the output of the command simply the instance name, like so:

> asadmin -T -a create-local-instance --node localhost-domain1
> ObnoxiousShark

Auto-Naming in Docker Nodes

The auto-naming feature has also been brought into our tech-preview of Docker Nodes. The default image (payara/server-node) has been updated to now also auto-generate instance names if one isn’t provided. This doesn’t normally happen fi you’re creating instances using asadmin or the Admin Console – this only happens if you’re creating the containers directly using the Docker CLI or REST API. With this functionality now present, you could now run the following command repeatedly without changes from the Docker CLI to create your containers and instances , auto-generating names for the instances in each (assuming you’ve set up a Docker Node on the machine – that’s still required unfortunately!):

docker container create --network host --mount type=bind,source="/home/anon/passwordfile.txt",target="/opt/payara/passwords/passwordfile.txt",readonly -e PAYARA_DAS_HOST=payaraDas -e PAYARA_DAS_PORT=4848 -e PAYARA_NODE_NAME=docky1 payara/server-node:5.193

The name conflict resolution feature is also present in the Docker Nodes image, so if you ran the above command with an instance name provided it will resolve the conflicts as it would when creating “normal” instances.

docker container create --network host --mount type=bind,source="/home/anon/passwordfile.txt",target="/opt/payara/passwords/passwordfile.txt",readonly -e PAYARA_DAS_HOST=payaraDas -e PAYARA_DAS_PORT=4848 -e PAYARA_NODE_NAME=docky1 -e PAYARA_INSTANCE_NAME=insty1 payara/server-node:5.193

Get the Full Documentation 

Full documentation of the auto-name and extra terse features can be found here, and documentation of creating Docker Node instances directly from Docker can be found here.

Don’t have the Payara Platform yet? 

{{cta(‘b2e4c2b6-f33a-4ae4-9290-f1cf476f445a’)}}

As always, you can contact us via the usual methods: leave a comment, find us on Facebook & Twitter, or visit our GitHub or Forum.

Comments (0)

Post a comment

Your email address will not be published. Required fields are marked *

Payara needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at any time. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, please review our Legal & Privacy Policy.

Related Posts

payara qube logo 5 minutes
Payara

Payara Cloud Is Now part of Payara Qube family of Unified Platforms for Enterprise Java

Payara Cloud is becoming part of Payara Qube family of Java application deployment runtimes. This move reflects how the […]

Payara promotional graphic showing transition from Spring to Jakarta EE, including technology logos, a code icon and arrows leading from Spring to Jakarta EE. 6 minutes
Jakarta EE

From Spring Boot To Jakarta EE 11: How Payara Starter Eases The Transition

If you’ve been living in the Spring ecosystem, you’re used to fast project setup. Spring Initializr gives you a […]

Promotional graphic for a podcast episode titled “Why Open Source is the Future of Business Innovation - A conversation with Arun Gupta”. The podcast is hosted by Payara Community. The right side features a photo of the speaker, Arun Gupta, labeled as a “VP, Developer Experience at JetBrains”. The design uses dark blue and teal backgrounds with coral and fish illustrations. 2 minutes
Community

Payara Podcast – Why Open Source is the Future of Business Innovation – A Conversation with Arun Gupta

Open source is no longer a developer-only concern — it’s at the heart of how modern businesses innovate, build […]