From 505a8d1871d7526ddb59c1c3819ad839131e59d3 Mon Sep 17 00:00:00 2001 From: Mayur Khachane Date: Mon, 25 Sep 2023 11:37:03 +0530 Subject: [PATCH] AV-186753: Added pagination support in vRO plugin. (#194) * AV-186753: Added pagination support in the plugin. * Updated fetchObjectLists action version. --- o11nplugin-vro-core/pom.xml | 6 +-- .../java/com/vmware/avi/vro/AviVroClient.java | 40 +++++++++++++++++-- o11nplugin-vro-package/pom.xml | 2 +- .../com/vmware/actions/CreateSegmentPool.xml | 4 +- .../com/vmware/actions/deleteObject.xml | 2 +- .../com/vmware/actions/fetchNetworkSubnet.xml | 4 +- .../com/vmware/actions/fetchObjectLists.xml | 4 +- .../com/vmware/actions/fetchObjectsNames.xml | 6 +-- .../com/vmware/actions/getDNSProvider.xml | 8 ++-- .../getExistingObjectsWithController.xml | 4 +- .../remoteAuthenticationConfiguration.xml | 4 +- .../com/vmware/actions/updatePool.xml | 4 +- o11nplugin-vro/pom.xml | 2 +- pom.xml | 2 +- version.txt | 4 +- 15 files changed, 65 insertions(+), 31 deletions(-) diff --git a/o11nplugin-vro-core/pom.xml b/o11nplugin-vro-core/pom.xml index 497fa130..67fcd67d 100644 --- a/o11nplugin-vro-core/pom.xml +++ b/o11nplugin-vro-core/pom.xml @@ -6,7 +6,7 @@ vro com.vmware.avi - 22.1.4.RELEASE + 22.1.4.1 4.0.0 @@ -23,7 +23,7 @@ com.vmware.avi.sdk avisdk - 22.1.4.RELEASE + 22.1.4..1 @@ -189,4 +189,4 @@ - \ No newline at end of file + diff --git a/o11nplugin-vro-core/src/main/java/com/vmware/avi/vro/AviVroClient.java b/o11nplugin-vro-core/src/main/java/com/vmware/avi/vro/AviVroClient.java index 6ba0dd32..49c75da5 100644 --- a/o11nplugin-vro-core/src/main/java/com/vmware/avi/vro/AviVroClient.java +++ b/o11nplugin-vro-core/src/main/java/com/vmware/avi/vro/AviVroClient.java @@ -718,13 +718,47 @@ private void clearQueue() { * @throws Exception */ @VsoMethod - public JSONArray get(String objectType, Map params, String tenant) throws Exception { + public JSONObject get(String objectType, Map params, String tenant) throws Exception { AviApi session = getSession(); if ((null != objectType) && (!objectType.isEmpty())) { HashMap userHeader = this.getTenantHeader(tenant); JSONObject data = session.get(objectType, params, userHeader); logger.info("Existing data of " + objectType + " : " + data); - return (JSONArray) data.get("results"); + return data; + } else { + logger.debug("ObjectType is empty"); + throw new AviApiException("Please provide objectType"); + } + } + + /*** + * Method for getting object data. + * + * @param objectType is the type of object. + * @param params is a map containing the key and values. + * @param tenant name of the Tenant + * @return the JSONArray of the response. + * @throws Exception + */ + @VsoMethod + public JSONArray getAllData(String objectType, Map params, String tenant) throws Exception { + AviApi session = getSession(); + if ((null != objectType) && (!objectType.isEmpty())) { + HashMap userHeader = this.getTenantHeader(tenant); + JSONObject data = session.get(objectType, params, userHeader); + logger.info("Existing data of " + objectType + " : " + data); + JSONArray results = new JSONArray(); + JSONArray response = (JSONArray) data.get("results"); + for (int i = 0; i < response.length(); i++) { + results.put(response.getJSONObject(i)); + } + if (data.has("next")) { + String pageNo = data.getString("next").split("=")[1]; + Map pageParams = new HashMap<>(); + pageParams.put("page", pageNo); + results.putAll(this.getAllData(objectType, pageParams, tenant)); + } + return results; } else { logger.debug("ObjectType is empty"); throw new AviApiException("Please provide objectType"); @@ -844,7 +878,7 @@ public AviRestResource getObjectByName(String objectType, String objectName) thr @VsoMethod public List getObject(String objectType, Map params, String tenant) throws Exception { - JSONArray array = this.get(objectType, params, tenant); + JSONArray array = this.getAllData(objectType, params, tenant); List objectList = new ArrayList(); // ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); diff --git a/o11nplugin-vro-package/pom.xml b/o11nplugin-vro-package/pom.xml index cc5a2491..069b5e13 100644 --- a/o11nplugin-vro-package/pom.xml +++ b/o11nplugin-vro-package/pom.xml @@ -9,7 +9,7 @@ vro com.vmware.avi - 22.1.4.RELEASE + 22.1.4.1 diff --git a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/CreateSegmentPool.xml b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/CreateSegmentPool.xml index ba255b57..5f48c530 100644 --- a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/CreateSegmentPool.xml +++ b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/CreateSegmentPool.xml @@ -1,7 +1,7 @@ @@ -25,7 +25,7 @@ nsxtCloudURL = nsxtCloudURL.split('#')[0] // Retrieve The Specified Segment var tenant = avivroClient.cred.tenant -var network_seg = avivroClient.get("network", null, tenant) +var network_seg = avivroClient.getAllData("network", null, tenant) // Parse the JSON Output network_seg = JSON.parse(network_seg) diff --git a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/deleteObject.xml b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/deleteObject.xml index 8183736c..ab3c55d8 100644 --- a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/deleteObject.xml +++ b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/deleteObject.xml @@ -70,7 +70,7 @@ function getUUIDOfObject(aviVroClientObj,objectType,name){ param.name=name; var resultArray=aviVroClientObj.get(objectType,param); resultArray=JSON.parse(resultArray); - var jsonObj=resultArray[0]; + var jsonObj=resultArray.results[0]; var msg =objectType+" "+name+" Deleted successfully."; msgArray.push(msg); return jsonObj; diff --git a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchNetworkSubnet.xml b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchNetworkSubnet.xml index d7a984a2..e7d65e1f 100644 --- a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchNetworkSubnet.xml +++ b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchNetworkSubnet.xml @@ -1,5 +1,5 @@ - + @@ -82,7 +82,7 @@ } function getObjectData(aviPlugin, objectType, params, tenantRef){ - var result = aviPlugin.get(objectType, params, tenantRef); + var result = aviPlugin.getAllData(objectType, params, tenantRef); var resultData = JSON.parse(result); return resultData; }]]> diff --git a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchObjectLists.xml b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchObjectLists.xml index d75f3fd4..ff642e6d 100644 --- a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchObjectLists.xml +++ b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchObjectLists.xml @@ -1,7 +1,7 @@ @@ -35,7 +35,7 @@ } var response = aviPlugin.get(objectType,params, clientTenant); var objectData = JSON.parse(response); - var object =objectData[0]; + var object = objectData.results[0]; if(object!=null){ if (field == "existingMembers"){ //var poolObject=objectData[0]; diff --git a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchObjectsNames.xml b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchObjectsNames.xml index 368d743f..84898ac1 100644 --- a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchObjectsNames.xml +++ b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/fetchObjectsNames.xml @@ -1,7 +1,7 @@ @@ -32,7 +32,7 @@ try{ if (aviPlugin != null){ if(cloudName == "" || cloudName == null){ var objectList = new Array(); - var response = aviPlugin.get(objectType,null, clientTenant); + var response = aviPlugin.getAllData(objectType,null, clientTenant); var objectData = JSON.parse(response); for each(index in objectData){ @@ -46,7 +46,7 @@ try{ cloudUuid = objectData.uuid; cloudRef.cloud_uuid = cloudUuid; var objectList = new Array(); - var response = aviPlugin.get(objectType,cloudRef, clientTenant); + var response = aviPlugin.getAllData(objectType,cloudRef, clientTenant); var objectData = JSON.parse(response); for each(index in objectData){ diff --git a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/getDNSProvider.xml b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/getDNSProvider.xml index 2832e608..c27259a5 100644 --- a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/getDNSProvider.xml +++ b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/getDNSProvider.xml @@ -1,7 +1,7 @@ @@ -27,9 +27,9 @@ } var param = new Object(); param.name=cloud; - var resultArray=aviVroClientObj.get("cloud",param, clientTenant); - resultArray=JSON.parse(resultArray); - var cloudObj=resultArray[0]; + var resultObject=aviVroClientObj.get("cloud",param, clientTenant); + resultObject=JSON.parse(resultObject); + var cloudObj = resultObject.results[0]; var dnsProvider=cloudObj.dns_provider_ref; var dnsProviderUUID = dnsProvider.substring(dnsProvider.indexOf("ipamdnsproviderprofile-")); var dnsProviderObj=aviVroClientObj.getObjectDataByUUID("ipamdnsproviderprofile",dnsProviderUUID); diff --git a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/getExistingObjectsWithController.xml b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/getExistingObjectsWithController.xml index 0e21b9da..728df0db 100644 --- a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/getExistingObjectsWithController.xml +++ b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/getExistingObjectsWithController.xml @@ -2,7 +2,7 @@ + version="0.0.4" allowed-operations="vfe"> + version="0.0.1" allowed-operations="vfe"> @@ -216,7 +216,7 @@ function tenanturl(str) { //System.log("str "+str) - var tenantObject = aviVroClient.get("tenant") + var tenantObject = aviVroClient.getAllData("tenant") tenantObject = JSON.parse(tenantObject) diff --git a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/updatePool.xml b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/updatePool.xml index 9234a721..f9718438 100644 --- a/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/updatePool.xml +++ b/o11nplugin-vro-package/src/main/resources/ScriptModule/com/vmware/actions/updatePool.xml @@ -1,7 +1,7 @@ @@ -31,7 +31,7 @@ param.name=poolname; var response = aviVroClientObj.get("pool",param, clientTenant); response = JSON.parse(response); - var jsonData=response[0]; + var jsonData = response.results[0]; jsonData.servers=[]; var updatedServers=[]; diff --git a/o11nplugin-vro/pom.xml b/o11nplugin-vro/pom.xml index c3a92555..62eaa4e9 100644 --- a/o11nplugin-vro/pom.xml +++ b/o11nplugin-vro/pom.xml @@ -10,7 +10,7 @@ vro com.vmware.avi - 22.1.4.RELEASE + 22.1.4.1 diff --git a/pom.xml b/pom.xml index d10ce909..0e0aaae9 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.vmware.avi vro pom - 22.1.4.RELEASE + 22.1.4.1 UTF-8 diff --git a/version.txt b/version.txt index 9f5ca634..e6e23096 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ -release_version=22.1.4 -eng_version=30.1.2 +release_version=22.1.4.1 +eng_version=30.2.1