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;
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);
}
}
+ 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<RelationshipData> 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();
}
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> complexId = new ArrayList<>();
+ 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++) {
- complexId.add(complexList.getComplex().get(i).getPhysicalLocationId());
+ 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(complexId).build();
+ return Response.ok(physicalLocationIdList).build();
}
}