cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

49
Views
1
Helpful
7
Replies
Highlighted
Cisco Employee

Enum(0) in id-allocator's service reference throws error

 

Hello Team,

 

The interface-type in our YANG model is of type enumeration as given below:

 

leaf interface-type {

       type enumeration {

        enum Port-channel;

        enum GigabitEthernet;

        enum TenGigabitEthernet;

        }

      }

 

Interface-type is part of the service key along with device, interface-index and vlan-id.

 

We use id-allocator in this service. Therefore, the owner service of the allocation is represented as shown in below:

admin@ncs# show id-allocator pool pool-ASR903-PRE1-Port-channel-1
id-allocator pool pool-ASR903-PRE1-Port-channel-1
available 5 4000
allocation 3 owner "/ncs:services/siteswitch_multipoint_bridging:siteswitch_multipoint_bridging{ASR903-PRE1 Enum(0) 1 400}"
allocation 4 owner "/ncs:services/siteswitch_multipoint_bridging:siteswitch_multipoint_bridging{ASR903-PRE1 Enum(0) 1 300}"

 

Problem is that, when ncs is restarted we have been noticing below errors in ncs-java-vm.log.

 

<ERROR> 02-Feb-2016::02:12:35.501 IdAllocator$Redeployer Thread-17: - error in re-deploy: /ncs:services/siteswitch_multipoint_bridging:siteswitch_multipoint_bridging{ASR903-PRE1 Enum(0) 1 700}

com.tailf.maapi.MaapiException: /ncs:services/siteswitch_multipoint_bridging:siteswitch_multipoint_bridging{ASR903-PRE1 Port-channel 1 700}: Bad key "ASR903-PRE1 Enum(0) 1 700" ("Enum(0)" is an invalid value.) at: /services/siteswitch_multipoint_bridging

at com.tailf.maapi.MaapiException.mk(MaapiException.java:61)

at com.tailf.maapi.Maapi.exists(Maapi.java:2017)

at com.tailf.maapi.Maapi.exists(Maapi.java:2040)

at com.cisco.nso.idallocator.IdAllocator$Redeployer.run(IdAllocator.java:1300)

at java.lang.Thread.run(Thread.java:745)

 

Furthermore, customer wants to see the actual value, i.e. Port-channel not the Enum(0) in id-allocator.

 

 

How can we overcome this problem?

 

 

Regards,

 

-Fatih

 

 

 

 

Everyone's tags (3)
7 REPLIES 7
Cisco Employee

Re: Enum(0) in id-allocator's service reference throws error

 

Hi!

 

 

First thing to try is to remove "--exclude-enums" from ncsc's flags. This will generate the enum values (int and string) in the namespace object, given those you can convert values between its integer and the string representations.

 

 

Br,

 

Fredrik

 

Cisco Employee

Re: Enum(0) in id-allocator's service reference throws error

 

Hi Fredrik,

 

 

Thanks for the ncsc flag suggestion, I will check that.

 

More spefically, we use the following two for translation between enum and string value in different places in the code:

 

 

1)

interfac_typeTemp = p.getValue().toString();
interfac_typeTemp = interfac_typeTemp.replace("Enum(0)", "Port-channel");
interfac_typeTemp = interfac_typeTemp.replace("Enum(1)", "GigabitEthernet");
interfac_typeTemp = interfac_typeTemp.replace("Enum(2)", "TenGigabitEthernet");

 

 

2)

  String poolName = "pool-" + navdevice + "-" + interfacetype + "-" + interfacename;
String enumValue = "";
if (interfacetype.equals("Port-channel"))
enumValue = "Enum(0)";
if (interfacetype.equals("TenGigabitEthernet"))
enumValue = "Enum(2)";
if (interfacetype.equals("GigabitEthernet"))
enumValue = "Enum(1)";
 

String resourcePath = "/id-allocator/pool[name='" + poolName + "']" + "/allocation[owner='"
+ serviceContainerInstance.getKeyPath().replace(interfacetype, enumValue) + "']" + "/id";

 

 

 

Jan also suggested not to use p.getValue().

 

Do you have an example what we can use in the Java for the proper translation?

 

 

Regards,

 

-Fatih

 

Cisco Employee

Re: Enum(0) in id-allocator's service reference throws error

 

Hi Fatih,

 

 

You could also use string as type with a regular expression instead of Enum:

 

 

Something like:

 

typedef interface-type {
type string {
pattern 'Port-channel|GigabitEthernet|TenGigabitEthernet';

}
}

 

You will loose the tab completion but validation will work.

 

 

Roque

 

Cisco Employee

Re: Enum(0) in id-allocator's service reference throws error

 

Hi Fatih,

 

 

What version of the id-allocator are you using?

 

 

BR,

Johan

 

Cisco Employee

Re: Enum(0) in id-allocator's service reference throws error

 

Hi Fatih,

 

 

Looks like you have a few  good options already, but  I will throw in another for you.

 

 

Within your java, you can resolve an enum based on the ordinal value, assuming you know the location of the enum in the model. This is a bit more complicated, but I guess the advantage is if you add another interface type to your enum there is no need to revisit the java to add extra replaces/if statements.

 

//Path to enum in model

ConfPath confPath = new ConfPath(service.leaf("interface-type").getKeyPath());

//Get the value

     ConfEnumeration confEnum = (ConfEnumeration) service.leaf("interface-type").value();

//Resolve

     String enumValue = ConfEnumeration.getLabelByEnum(confPath, confEnum);

 

I added these prints to a test service, results below:

 

System.out.println(confPath.toString());
     System.out.println(confEnum.toString());
     System.out.println(enumValue);

/ncs:services/lspcallbacktester:lspcallbacktester{demo123}/interface-type
Enum(2)
TenGigabitEthernet

 

Hope this helps.

Cheers,

Dan.

 

Cisco Employee

Re: Enum(0) in id-allocator's service reference throws error

 

Hi Johan,

 

 

admin@ncs> show packages package id-allocator

packages package id-allocator

package-version 1.0

description     "Resource allocator for ids"

ncs-min-version [ 3.0 ]

directory       ./state/packages-in-use/1/id-allocator

required-package resource-manager

component "Reactive fastmap id  allocation"

  application java-class-name com.cisco.nso.idallocator.IdAllocator

  application start-phase phase2

oper-status up

[ok][2016-02-02 14:35:24]

admin@ncs>

 

 

Regards,

 

-Fatih

 

Cisco Employee

Re: Enum(0) in id-allocator's service reference throws error

 

Daniel,

 

Thanks for jumping into the discussion; this is how you should do it. The .toString() function should basically never be used on enumerations. Use .getLabelByEnum() instead.

 

ConfPath confPath = new ConfPath(service.leaf("interface-type").getKeyPath());

ConfEnumeration confEnum = (ConfEnumeration) service.leaf("interface-type").value();

String enumValue = ConfEnumeration.getLabelByEnum(confPath, confEnum);

 

The earlier suggestions to do it like this is outright dangerous! Promise me to never do this:

 

interfac_typeTemp = p.getValue().toString();

interfac_typeTemp = interfac_typeTemp.replace("Enum(0)", "Port-channel");

 

The other proposed solution kind of works, but has issues. Not the right answer:

 

typedef interface-type {

type string {

pattern 'Port-channel|GigabitEthernet|TenGigabitEthernet';

 

Best Regards,

 

/jan

 

Content for Community-Ad
FusionCharts will render here