Active IQ Unified Manager Discussions

WFA - Checking DNS before launching a Datastore creation Workflow

POLICARD
5,740 Views

Hi All,

 

I have a workflow for creating a NFS Datastore and mounting it automatically in Vcenter.

A FQDN name is used for mounting the datastore. I want to test it before creating anything.

 

So I have created a MVEL function:

function ResolveDns(fqdn)
{
import java.net.*;
throws UnknownHostException
InetAddress add = InetAddress.getByName(fqdn);
 
String ipaddress = add.getHostAddress();
return ipaddress;
}

This function is working as expected because the workflow fails if the DNS entry doesn't exist.

 

But The error message is very ugly:

[Error: failed to access property: ResolveDns('e11dcdot1.pharma.aventis.com'): [Error: InetAddress.getByName(fqdn): e11dcdot1.pharma.aventis.com]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]]
[Near : {... e11dcdot1.pharma.aventis.com' ....}]
^
[Line: 1, Column: 0]

How to manage with exception and having a friendly message instead of this ?

I tried some try / catch, but I have a compilation error:

The faulty code:

function ResolveDns(fqdn)
{
throws  UnknownHostException
import java.net.*;
try {
	InetAddress add = InetAddress.getByName(fqdn);
}
catch(UnknownHostException e) {
	System.err.println("Cannot find host");
	System.exit(1);
	}

String ipaddress = add.getHostAddress();
return ipaddress;
}

 

The result:

Illegal expression: Failed to compile function definition by MVEL:function ResolveDns(fqdn)
{
throws  UnknownHostException
import java.net.*;
try {
InetAddress add = InetAddress.getByName(fqdn);
}
catch(UnknownHostException e) {
System.err.println("Cannot find host");
System.exit(1);...

Do you have any idea ... ? 🙂

 

Thanks by advance

1 ACCEPTED SOLUTION

francoisbnc
5,698 Views

You cannot use powershell in function.

 

Just create a command like below you can integrate in workflow you want. It throw Host not found if host is not in dns.

 

param (
[parameter(Mandatory=$true, HelpMessage="Host to verify")]
[string]$host

)
try
{
[Net.DNS]::GetHostEntry($host)
}
catch
{
throw "Host not found"
}

 

 

2015-12-15_10-05-20.png

 

 

 

François

View solution in original post

7 REPLIES 7

francoisbnc
5,728 Views

Why use MVEL function?, you can integrate directly catch in commands. Perhaps more simple for managing exceptions.

 

An example in PS

 

try
{
   [Net.DNS]::GetHostEntry("hosttotest")
}
catch
{
    throw "Host not found"
}

 

Regards,

François

POLICARD
5,700 Views

Hi François,

 

If even it was possible ... I love Powershell and I am discovering MVEL (due to WFA).

 

There is the message I have if I test any Powershell code in a WFA function :

wfa powershell error.png

francoisbnc
5,699 Views

You cannot use powershell in function.

 

Just create a command like below you can integrate in workflow you want. It throw Host not found if host is not in dns.

 

param (
[parameter(Mandatory=$true, HelpMessage="Host to verify")]
[string]$host

)
try
{
[Net.DNS]::GetHostEntry($host)
}
catch
{
throw "Host not found"
}

 

 

2015-12-15_10-05-20.png

 

 

 

François

POLICARD
5,687 Views

Hi Francois

 

I am using a name generated automatically. I was convinced I cannot use a variable in a step prior to the volume creation.

 

I have checked and it's working fine.

 

Many thanks for your help 🙂

sinhaa
5,690 Views

There are advantage of having MVEL functions over doing it in a Command Code.

 

  1. A workflow *preview* can do this function validation for me. A code in comamnd can't make this check until execution starts which may be too late. Big advantage.
  2. I can use it in building expressions for Workflow User-Inputs etc.

But the disadvantage is MVEL being an expression language, you can't use complex programming constructs in its function. 

 

There is NO try-catch in MVEL.

 

How to do what you want to do? 

I'm thinking but right now I don't know.

 

sinhaa

 

 

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

POLICARD
5,685 Views

Hi Sinhaa,

 

In fact I want to keep the MVEL function because it also allows me to find the appropriate IP to set on the LIF.

 

As you said, thanks MVEL code, the workflow is aborted before creating anything (volume, etc ...)

 

My goal is to have an uderstandable message when the workflow is failing. So the command before the volume creation is perfect for me. 

POLICARD
5,669 Views

At the end I have to remove the command that cannot really check the DNS entry and I keep the MVEL function with the ugly message...

 

The most important is the workflow is not running if the DNS entry doesn't exist.

 

Hope a future version of WFA will allow to create a specific error output depending on MVEL behavior... Or a way for adding some command for checking only with powershell code runable before the real execution (and only for checking).

Public