From 1d8aafe77787e3c86ec53075cd0eaf3536316aef Mon Sep 17 00:00:00 2001 From: LiZi Date: Thu, 1 Mar 2018 21:08:47 -0500 Subject: [PATCH] Get complex name and put it to cloud region 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 --- .../java/org/onap/aai/esr/entity/aai/Complex.java | 12 ++++++++++++ .../esr/externalservice/aai/CloudRegionProxy.java | 13 +++++++++++-- .../aai/esr/externalservice/aai/ICloudRegion.java | 8 ++++++++ .../org/onap/aai/esr/wrapper/VimManagerWrapper.java | 21 ++++++++++++++++++--- .../onap/aai/esr/wrapper/VimManagerWrapperTest.java | 2 ++ 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Complex.java b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Complex.java index 0a543bb..77f9b8b 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Complex.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Complex.java @@ -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; + } } diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxy.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxy.java index a162cd0..623fa1c 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxy.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxy.java @@ -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); diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ICloudRegion.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ICloudRegion.java index f2e47b6..b30cd82 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ICloudRegion.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ICloudRegion.java @@ -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; } diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java index 7c3c8d7..3003159 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java @@ -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 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