Active IQ Unified Manager Discussions
Active IQ Unified Manager Discussions
Hello All,
I am trying to write a Function to get the volume name Prefix pattern from the Storage controller name.
the Storage controller name could be :
cgtestx123.iceage.com or
mfdevx234.sid.iceage.com or
The volume Prefix that we are expecting is :
if the Storage is cgtestx123.abc.com volume name prefix should be => test123v[3 digit number]
if the Storage is mfdevx234.abc.com volume name prefix should be => dev234v[3 digit number]
So, if i would have to explain it, i can say that i need to take from 3rd character till character "x" and the numeric's before the domain name ".sid..... or .iceage...."
The function i am trying to write is not helping:
def getVolumeprefix (storagecontroller)
{
java.util.regex.Pattern RESOLVE_PATTERN = java.util.regex.Pattern.compile("(^.*?)(\\d+)(.\.*?)");
java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);
String number = matcher.group(2);
String site = storagecontroller.substring(2,5);
String volname = site + number + "v";
return volname;
}
can someone please help me in fixing this pattern function.
,Sheel
Solved! See The Solution
Hi Sheel,
The java.util.regex.Pattern.compile does not handle dot('\.') well. The dot needs to be given as \p{Punct}
I have modified the function and this works fine in my environment:
def getVolumeprefix (storagecontroller)
{
java.util.regex.Pattern RESOLVE_PATTERN = java.util.regex.Pattern.compile("^..(.+)x(\\d+)(\\p{Punct}.+)");
java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);
if (matcher.matches())
{
String number = matcher.group(2);
String site = matcher.group(1);
String volname = site + number + "v";
return volname;
}
throwException('Input not in correct format')
}
Hope this helps.
-Dhruv
Hi Sheel,
The java.util.regex.Pattern.compile does not handle dot('\.') well. The dot needs to be given as \p{Punct}
I have modified the function and this works fine in my environment:
def getVolumeprefix (storagecontroller)
{
java.util.regex.Pattern RESOLVE_PATTERN = java.util.regex.Pattern.compile("^..(.+)x(\\d+)(\\p{Punct}.+)");
java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);
if (matcher.matches())
{
String number = matcher.group(2);
String site = matcher.group(1);
String volname = site + number + "v";
return volname;
}
throwException('Input not in correct format')
}
Hope this helps.
-Dhruv
Thanks Dhruv,
it worked for me, i just added an elese condition as well, if i am selecting a vFiler, which generally does not have a domain name added to it:
def getVolumeprefix (storagecontroller)
{
java.util.regex.Pattern RESOLVE_PATTERN = java.util.regex.Pattern.compile("^..(.+)x(\\d+)(\\p{Punct}.+)");
java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);
if (matcher.matches())
{
String number = matcher.group(2);
String site = matcher.group(1);
String volname = site + number + "v";
return volname;
} else {
String part = storagecontroller.substring(2,storagecontroller.length());
String site = part.substring(0, part.length()-4);
String code = part.substring(part.length()-3, part.length());
String volname = site + code + "v";
return volname;
}
}
Dont have any knowledge about java. so i have to do copy and paste 🙂
Thats Great.
In case you want the function to work for both storage controllers and vfilers, the following will do. It will even throw an exception if the input format is not as expected.
def getVolumeprefix (storagecontroller)
{
java.util.regex.Pattern RESOLVE_PATTERN = java.util.regex.Pattern.compile("^..(.+)x(\\d{3}).*");
java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);
if (matcher.matches())
{
String number = matcher.group(2);
String site = matcher.group(1);
String volname = site + number + "v";
return volname;
}
throwException('Input not in correct format')
}