X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=esr-mgr%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fesr%2Fwrapper%2FVimManagerWrapper.java;h=30031599c095bba5e49292f0cfeea6fcafd746a1;hb=1d8aafe77787e3c86ec53075cd0eaf3536316aef;hp=bc7e872dfc8c120df9dbd7de4d24f1f1ea9c2c07;hpb=602b54865f4f47b491848b83417c5c0d05bfebe7;p=aai%2Fesr-server.git 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 bc7e872..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 @@ -1,5 +1,5 @@ /** - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2018 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,11 @@ 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; +import org.onap.aai.esr.entity.aai.RelationshipData; import org.onap.aai.esr.entity.rest.VimRegisterInfo; import org.onap.aai.esr.entity.rest.VimRegisterResponse; import org.onap.aai.esr.exception.ExceptionUtil; @@ -67,17 +71,15 @@ public class VimManagerWrapper { CloudRegionDetail cloudRegion = vimManagerUtil.vimRegisterInfo2CloudRegion(vimRegisterInfo); String cloudOwner = vimRegisterInfo.getCloudOwner(); String cloudRegionId = vimRegisterInfo.getCloudRegionId(); + String physicalLocationId = vimRegisterInfo.getPhysicalLocationId(); + String complexName = getComplexName(physicalLocationId); + cloudRegion.setComplexName(complexName); try { cloudRegionProxy.registerVim(cloudOwner, cloudRegionId, cloudRegion); result.setCloudOwner(cloudOwner); result.setCloudRegionId(cloudRegionId); - Tenant tenant = new Tenant(); - tenant.setDefaultTenant(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0).getDefaultTenant()); - try { - VimManagerProxy.updateVim(cloudOwner, cloudRegionId, tenant); - } catch (ExtsysException e) { - LOG.error("Update VIM by Multi-cloud failed !", e); - } + createRelationship(cloudOwner, cloudRegionId, physicalLocationId); + updateVimWithMultiCloud(cloudRegion, cloudOwner, cloudRegionId); return Response.ok(result).build(); } catch (ExtsysException error) { LOG.error("Register VIM failed !", error); @@ -85,6 +87,34 @@ public class VimManagerWrapper { } } + private void updateVimWithMultiCloud(CloudRegionDetail cloudRegion, String cloudOwner, String cloudRegionId) { + Tenant tenant = new Tenant(); + tenant.setDefaultTenant(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0).getDefaultTenant()); + try { + VimManagerProxy.updateVim(cloudOwner, cloudRegionId, tenant); + } catch (ExtsysException e) { + LOG.error("Update VIM by Multi-cloud failed !", e); + } + } + + private void createRelationship(String cloudOwner, String cloudRegionId, String physicalLocationId) { + Relationship relationship = new Relationship(); + RelationshipData relationshipData = new RelationshipData(); + List relationshipDatas = new ArrayList<>(); + String relatedLink = "/aai/v11/cloud-infrastructure/complexes/complex/" + physicalLocationId; + relationship.setRelatedTo("complex"); + relationship.setRelatedLink(relatedLink); + relationshipData.setRelationshipKey("complex.physical-location-id"); + relationshipData.setRelationshipValue(physicalLocationId); + relationshipDatas.add(relationshipData); + relationship.setRelationshipData(relationshipDatas); + try { + cloudRegionProxy.createCloudRegionRelationShip(cloudOwner, cloudRegionId, relationship); + } catch (ExtsysException e) { + LOG.error("Create relationship between cloudRegion and complex failed !", e); + } + } + public Response updateVim(String cloudOwner, String cloudRegionId, VimRegisterInfo vimRegisterInfo) { LOG.info("Start update VIM, input VIM info is: " + extsysUtil.objectToString(vimRegisterInfo)); VimRegisterResponse result = new VimRegisterResponse(); @@ -214,4 +244,33 @@ 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 complexes query result is: " + complexesString); + complexList = new Gson().fromJson(complexesString, ComplexList.class); + for (int i=0; i