Hi,
Most probably the vrouter object was created from the vrouter provisioning 
script that sets the type as an array.

We will fix UI to not set it as an array element, but to proceed you can modify 
the following lines in vrouter provisioning scripts and the delete/add the 
vrouter config objects.

159         # Configure router type
    160         if self._args.router_type:
    161             
vrouter_obj.set_virtual_router_type([self._args.router_type])
    162         else:
    163             vrouter_obj.set_virtual_router_type([])
    164         if vrouter_exists:
    165             self._vnc_lib.virtual_router_update(vrouter_obj)
    166         else:

Rahul
________________________________
From: Pedro Marques<mailto:[email protected]>
Sent: ‎30-‎10-‎2015 00:15
To: 温曙光<mailto:[email protected]>
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [opencontrail-dev] java api to manipulate VirtualRouter Object is 
broken on R2.20?

Looks like there are several distinct bugs:
  1. Web ui shouldn't be generating objects that don't conform to the schema.

  Fixing this bug should be a question of just changing the .js bellow. But the 
web-ui shouldn't be using manual
  encoding of types. It should generate a client library for javascript just 
like the ones that exists for python, golang and java. It is not the first time 
that the web-ui hand-crafted code creates issues...

  2. API server shouldn't accept objects that don't conform to the schema.
  I was under the impression that the api server was actually enforcing the 
string restrictions from the schema. It is odd that it accepts a list for what 
should be a simple type.

I'm assuming that a virtual-router can't be multiple types at once. So changing 
the schema doesn't look like the right approach here.

  Pedro.
温曙光<mailto:[email protected]>
October 29, 2015 at 6:53 AM
Dear all:

    I use java api to access contrail config, but java api can't deserialize 
VirtualRouter due to virtual_router_type's type doesn't match between database 
and vnc_cfg.xsd.

test code: -------------->

package test_vrouter;

import java.io.IOException;

import net.juniper.contrail.api.ApiConnector;
import net.juniper.contrail.api.ApiConnectorFactory;
import net.juniper.contrail.api.types.VirtualRouter;

public class Test {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        ApiConnector api = ApiConnectorFactory.build("10.10.7.208", 8082)
                .credentials("admin", "admin").tenantName("admin")
                .authServer("keystone", 
"http://10.10.7.208:5000/v2.0";<http://10.10.7.208:5000/v2.0>);

        VirtualRouter vr = (VirtualRouter)api.findById(VirtualRouter.class, 
"068f26d9-1704-4030-b1ed-6dee2a608d2d");
        vr.setDisplayName("ubuntu208-1");
        api.update(vr);
        System.out.println(vr.toString());
    }
}


exception stack: ------------>
Exception in thread "main" com.google.gson.JsonSyntaxException: 
java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 
1 column 179
    at 
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)
    at com.google.gson.Gson.fromJson(Gson.java:803)
    at com.google.gson.Gson.fromJson(Gson.java:768)
    at com.google.gson.Gson.fromJson(Gson.java:717)
    at com.google.gson.Gson.fromJson(Gson.java:689)
    at net.juniper.contrail.api.ApiSerializer.deserialize(ApiSerializer.java:52)
    at net.juniper.contrail.api.ApiBuilder.jsonToApiObject(ApiBuilder.java:66)
    at 
net.juniper.contrail.api.ApiConnectorImpl.findById(ApiConnectorImpl.java:500)
    at test_vrouter.Test.main(Test.java:17)
Caused by: java.lang.IllegalStateException: Expected a string but was 
BEGIN_ARRAY at line 1 column 179
    at com.google.gson.stream.JsonReader.nextString(JsonReader.java:821)
    at com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:358)
    at com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:346)
    at 
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
    at 
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
    ... 8 more


the cause is Gson can't deserialize VirtualRouter from it's json 
representation:  ---------->
{"virtual-router": {"fq_name": ["default-global-system-config", "ubuntu208"], 
"uuid": "068f26d9-1704-4030-b1ed-6dee2a608d2d", "parent_uuid": 
"a15a4fed-d841-4bd0-bcb2-1de6e2d0cd69", "virtual_router_type": [], 
"parent_href": 
"http://10.10.7.208:8082/global-system-config/a15a4fed-d841-4bd0-bcb2-1de6e2d0cd69";<http://10.10.7.208:8082/global-system-config/a15a4fed-d841-4bd0-bcb2-1de6e2d0cd69>,
 "parent_type": "global-system-config", "href": 
"http://10.10.7.208:8082/virtual-router/068f26d9-1704-4030-b1ed-6dee2a608d2d";<http://10.10.7.208:8082/virtual-router/068f26d9-1704-4030-b1ed-6dee2a608d2d>,
 "virtual_machine_refs": [{"to": 
["default-domain__pro210__si_20fc5dda-9975-4dd1-aab5-215f60586533__1"], "href": 
"http://10.10.7.208:8082/virtual-machine/4605bc4d-78e5-4ab8-9696-06a5f7ee91ca";<http://10.10.7.208:8082/virtual-machine/4605bc4d-78e5-4ab8-9696-06a5f7ee91ca>,
 "attr": null, "uuid": "4605bc4d-78e5-4ab8-9696-06a5f7ee91ca"}, {"to": 
["default-domain", "pro23", 
"default-domain__pro23__nfcloud_si_vrouter_1b95ab01-25bf-484f-b6bf-38169e63e383__1"],
 "href": 
"http://10.10.7.208:8082/virtual-machine/6c04d5df-6d1b-49f4-b4e3-56fa2bd8f7fb";<http://10.10.7.208:8082/virtual-machine/6c04d5df-6d1b-49f4-b4e3-56fa2bd8f7fb>,
 "attr": null, "uuid": "6c04d5df-6d1b-49f4-b4e3-56fa2bd8f7fb"}], "id_perms": 
{"enable": true, "uuid": {"uuid_mslong": 472639199733104688, "uuid_lslong": 
12821024583874284845}, "created": "2015-09-17T08:30:46.870214", "description": 
null, "creator": null, "user_visible": true, "last_modified": 
"2015-10-29T09:19:21.466210", "permissions": {"owner": "admin", "owner_access": 
7, "other_access": 7, "group": "KeystoneServiceAdmin", "group_access": 7}}, 
"display_name": "ubuntu208-1", "virtual_router_ip_address": "10.10.7.208", 
"name": "ubuntu208"}}

the virtual_router_type is a empty array [], but it's declared as String in 
vnc_cfg.xsd:---------->
 966 <xsd:simpleType name="VirtualRouterType">
 967     <xsd:restriction base="xsd:string">
 968         <xsd:enumeration value="embedded"/>
 969         <xsd:enumeration value="tor-agent"/>
 970         <xsd:enumeration value="tor-service-node"/>
 971     </xsd:restriction>
 972 </xsd:simpleType>
 973
 974 <xsd:element name="virtual-router-type" type="VirtualRouterType"/>
 975 <!--#IFMAP-SEMANTICS-IDL
 976      Property('virtual-router-type', 'virtual-router') -->

and the generated java source decares virtual_router_type as String:  
---------->
 14 public class VirtualRouter extends ApiObjectBase {
 15     private String virtual_router_type;

I change it to private List<String> virtual_router_type or just remove it from 
Virtualrouter, the test code can succeed.

I digest into source code, and found that the virtual_router_type is stored in 
cassandra as a list, and vnc_cfg_api_server doesn't touch it
And I find out that it's writed to from 
./contrail-web-controller/webroot/config/physicaldevices/virtualrouters/ui/js/virtualrouters_config.js:
 ---------->
        postObject["virtual-router"] = {};
        postObject["virtual-router"]["fq_name"] = 
["default-global-system-config", name];
        postObject["virtual-router"]["parent_type"] = "global-system-config";
        postObject["virtual-router"]["name"] = name;
        postObject["virtual-router"]["virtual_router_ip_address"] = ipAddress;
        if(type != 'hypervisor' && type != '' && type != 'empty') {
            postObject["virtual-router"]["virtual_router_type"] = [type];
        } else {
            postObject["virtual-router"]["virtual_router_type"] = [];
        }
        if(mode === 'edit') {
            postObject["virtual-router"]["uuid"] = gblSelRow.uuid;
        }
        doAjaxCall(url, methodType, JSON.stringify(postObject), 
'successHandlerForVirtualRouters', 'failureHandlerForCreateVirtualRouters', 
null, null);


Any body can fix it, or give some advise about how to fix it
I prefer to change vnc_cfg.xsd's VirtualRouterType to an string array type, but 
I can't find a way to rewrite the xsd.






_______________________________________________
Dev mailing list
[email protected]<mailto:[email protected]>
http://lists.opencontrail.org/mailman/listinfo/dev_lists.opencontrail.org

_______________________________________________
Dev mailing list
[email protected]
http://lists.opencontrail.org/mailman/listinfo/dev_lists.opencontrail.org

Reply via email to