Get complex name and put it to cloud region 03/33703/1
authorLiZi <li.zi30@zte.com.cn>
Fri, 2 Mar 2018 02:08:47 +0000 (21:08 -0500)
committerLiZi <li.zi30@zte.com.cn>
Fri, 2 Mar 2018 02:09:03 +0000 (21:09 -0500)
Get complex name by query complex object and put it to cloud region when register VIM.

Change-Id: I1c5a2537b70de5ec8d3630dec6c8b79981445290
Issue-ID: AAI-829
Signed-off-by: LiZi <li.zi30@zte.com.cn>
esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Complex.java
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxy.java
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ICloudRegion.java
esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java
esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java

index 0a543bb..77f9b8b 100644 (file)
@@ -23,6 +23,10 @@ public class Complex implements Serializable {
     
     @SerializedName("physical-location-id")
     private String physicalLocationId;
+    
+    
+    @SerializedName("complex-name")
+    private String complexName;
 
     public String getPhysicalLocationId() {
         return physicalLocationId;
@@ -31,4 +35,12 @@ public class Complex implements Serializable {
     public void setPhysicalLocationId(String physicalLocationId) {
         this.physicalLocationId = physicalLocationId;
     }
+
+    public String getComplexName() {
+        return complexName;
+    }
+
+    public void setComplexName(String complexName) {
+        this.complexName = complexName;
+    }
 }
index a162cd0..623fa1c 100644 (file)
@@ -81,8 +81,17 @@ public class CloudRegionProxy {
             throw new ExtsysException("Query complexes from A&AI failed.", e);
         }
     }
-    
-    public void createCloudRegionRelationShip(String cloudOwner, String cloudRegionId, Relationship relationship) throws ExtsysException {
+
+    public String queryComplex(String physicalLocationId) throws ExtsysException {
+        try {
+            return adapterServiceproxy.queryComplex(transactionId, fromAppId, authorization, physicalLocationId);
+        } catch (Exception e) {
+            throw new ExtsysException("Query complexes from A&AI failed.", e);
+        }
+    }
+
+    public void createCloudRegionRelationShip(String cloudOwner, String cloudRegionId, Relationship relationship)
+            throws ExtsysException {
         ClientConfig config = new ClientConfig(new RelationshipProvider());
         ICloudRegion createRelationshipProxy =
                 ConsumerFactory.createConsumer(MsbConfig.getCloudInfrastructureAddr(), config, ICloudRegion.class);
index f2e47b6..b30cd82 100644 (file)
@@ -83,4 +83,12 @@ public interface ICloudRegion {
     public String queryComplexList(@HeaderParam("X-TransactionId") String transactionId,
             @HeaderParam("X-FromAppId") String fromApp, @HeaderParam("Authorization") String authorization)
             throws ExtsysException;
+
+    @GET
+    @Path("/complexes/complex/{physical_location_id}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public String queryComplex(@HeaderParam("X-TransactionId") String transactionId,
+            @HeaderParam("X-FromAppId") String fromApp, @HeaderParam("Authorization") String authorization,
+            @PathParam("physical_location_id") String physical_location_id) throws ExtsysException;
 }
index 7c3c8d7..3003159 100644 (file)
@@ -20,6 +20,7 @@ import java.util.List;
 import javax.ws.rs.core.Response;
 import org.onap.aai.esr.entity.aai.CloudRegionDetail;
 import org.onap.aai.esr.entity.aai.CloudRegionList;
+import org.onap.aai.esr.entity.aai.Complex;
 import org.onap.aai.esr.entity.aai.ComplexList;
 import org.onap.aai.esr.entity.aai.EsrSystemInfo;
 import org.onap.aai.esr.entity.aai.Relationship;
@@ -71,7 +72,8 @@ public class VimManagerWrapper {
         String cloudOwner = vimRegisterInfo.getCloudOwner();
         String cloudRegionId = vimRegisterInfo.getCloudRegionId();
         String physicalLocationId = vimRegisterInfo.getPhysicalLocationId();
-        //TODO query complex by complex id to get complex name. and put the name to vimRegisterInfo.complexName
+        String complexName = getComplexName(physicalLocationId);
+        cloudRegion.setComplexName(complexName);
         try {
             cloudRegionProxy.registerVim(cloudOwner, cloudRegionId, cloudRegion);
             result.setCloudOwner(cloudOwner);
@@ -242,19 +244,32 @@ public class VimManagerWrapper {
         }
         return cloudRegionDetail;
     }
+    
+    private String getComplexName(String physicalLocationId) {
+        Complex complex = new Complex();
+        try {
+            String complexStr = cloudRegionProxy.queryComplex(physicalLocationId);
+            LOG.info("The complexes query result is: " + complexStr);
+            complex = new Gson().fromJson(complexStr, Complex.class);
+            return complex.getComplexName();
+        } catch (ExtsysException e) {
+            LOG.error("Query complex by physical location Id failed !", e);
+            return null;
+        }
+    }
 
     public Response queryComplexes() {
         ComplexList complexList = new ComplexList();
         List<String> physicalLocationIdList = new ArrayList<>();
         try {
             String complexesString = cloudRegionProxy.qureyComplexes();
-            LOG.info("The complex query result is: " + complexesString);
+            LOG.info("The complexes query result is: " + complexesString);
             complexList = new Gson().fromJson(complexesString, ComplexList.class);
             for (int i=0; i<complexList.getComplex().size(); i++) {
                 physicalLocationIdList.add(complexList.getComplex().get(i).getPhysicalLocationId());
             }
         } catch (ExtsysException e) {
-            LOG.error("Query vim details by ID failed !", e);
+            LOG.error("Query complexes failed !", e);
         }
         return Response.ok(physicalLocationIdList).build();
     }
index 7387ddb..4c82147 100644 (file)
@@ -58,9 +58,11 @@ public class VimManagerWrapperTest {
         vimAuthInfo.setDefaultTenant("admin");
         vimAuthInfos.add(vimAuthInfo);
         vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
+        String complexStr = "{\"physical-location-id\": \"complex\", \"data-center-code\": \"test\", \"complex-name\": \"complex\"}";
         CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.class);
         Mockito.doNothing().when(mockCloudRegionProxy).registerVim(Mockito.anyString(), Mockito.anyString(),
                 (CloudRegionDetail) Mockito.anyObject());
+        Mockito.when(mockCloudRegionProxy.queryComplex(Mockito.anyString())).thenReturn(complexStr);
         VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
         Response response = vimManagerWrapper.registerVim(vimRegisterInfo);
         if (response != null) {