summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Zi <li.zi30@zte.com.cn>2018-03-02 01:05:28 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-02 01:05:28 +0000
commitd48f437e18ae68c70547b21902d5ad87243aac35 (patch)
tree0b89ca1539f768f7e8a9b35f6c8e4645d0fe9f8e
parent23becdf6c11b619a92cebc9fbf64ce3835a7334a (diff)
parent06fe3f5d62f9b986ebb8babf6fb140baed44769f (diff)
Merge "Create relationship while register VIM."
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/VimRegisterInfo.java30
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxy.java15
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ICloudRegion.java2
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/RelationshipProvider.java54
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java2
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java47
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/entity/rest/VimRegisterInfoTest.java10
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.java3
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java2
9 files changed, 140 insertions, 25 deletions
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/VimRegisterInfo.java b/esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/VimRegisterInfo.java
index 0850354..3d6a305 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/VimRegisterInfo.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/VimRegisterInfo.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2016-2017 ZTE Corporation.
+ * Copyright 2016-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.
@@ -31,9 +31,11 @@ public class VimRegisterInfo {
private String ownerDefinedType;
private String cloudZone;
-
+
private String complexName;
+ private String physicalLocationId;
+
private String cloudExtraInfo;
private String status;
@@ -88,14 +90,6 @@ public class VimRegisterInfo {
this.cloudZone = cloudZone;
}
- public String getComplexName() {
- return complexName;
- }
-
- public void setComplexName(String complexName) {
- this.complexName = complexName;
- }
-
public String getCloudExtraInfo() {
return cloudExtraInfo;
}
@@ -120,4 +114,20 @@ public class VimRegisterInfo {
this.status = status;
}
+ public String getPhysicalLocationId() {
+ return physicalLocationId;
+ }
+
+ 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 bcfedb3..a162cd0 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
@@ -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.
@@ -18,6 +18,7 @@ package org.onap.aai.esr.externalservice.aai;
import org.glassfish.jersey.client.ClientConfig;
import org.onap.aai.esr.common.MsbConfig;
import org.onap.aai.esr.entity.aai.CloudRegionDetail;
+import org.onap.aai.esr.entity.aai.Relationship;
import org.onap.aai.esr.exception.ExtsysException;
import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
@@ -80,4 +81,16 @@ public class CloudRegionProxy {
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);
+ try {
+ createRelationshipProxy.createCloudRegionRelationship(transactionId, fromAppId, authorization, cloudOwner,
+ cloudRegionId, relationship);
+ } catch (Exception e) {
+ throw new ExtsysException("PUT cloud region to A&AI failed.", e);
+ }
+ }
}
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 e5f6531..f2e47b6 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
@@ -71,7 +71,7 @@ public interface ICloudRegion {
@Path("/cloud-regions/cloud-region/{cloud_owner}/{cloud_region_id}/relationship-list/relationship")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public void putRelationship(@HeaderParam("X-TransactionId") String transactionId,
+ public void createCloudRegionRelationship(@HeaderParam("X-TransactionId") String transactionId,
@HeaderParam("X-FromAppId") String fromApp, @HeaderParam("Authorization") String authorization,
@PathParam("cloud_owner") String cloud_owner, @PathParam("cloud_region_id") String cloud_region_id,
Relationship relationship) throws ExtsysException;
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/RelationshipProvider.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/RelationshipProvider.java
new file mode 100644
index 0000000..248cb3f
--- /dev/null
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/RelationshipProvider.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.aai.esr.externalservice.aai;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import org.onap.aai.esr.entity.aai.Relationship;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.google.gson.Gson;
+
+public class RelationshipProvider implements MessageBodyWriter<Relationship> {
+
+ private static final Logger logger = LoggerFactory.getLogger(EmsRegisterProvider.class);
+
+ @Override
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return Relationship.class.isAssignableFrom(type);
+ }
+
+ @Override
+ public long getSize(Relationship t, Class<?> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(Relationship t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
+ throws IOException, WebApplicationException {
+ String json = new Gson().toJson(t, Relationship.class);
+ logger.info("the param to register EMS input is:" + json);
+ entityStream.write(json.getBytes("UTF-8"));
+ }
+}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java b/esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java
index b37e319..bbcc5fe 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.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.
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 7545b01..7c3c8d7 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
@@ -22,6 +22,8 @@ import org.onap.aai.esr.entity.aai.CloudRegionDetail;
import org.onap.aai.esr.entity.aai.CloudRegionList;
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;
@@ -68,17 +70,14 @@ public class VimManagerWrapper {
CloudRegionDetail cloudRegion = vimManagerUtil.vimRegisterInfo2CloudRegion(vimRegisterInfo);
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
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);
@@ -86,6 +85,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<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();
@@ -218,17 +245,17 @@ public class VimManagerWrapper {
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);
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);
}
- return Response.ok(complexId).build();
+ return Response.ok(physicalLocationIdList).build();
}
}
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/entity/rest/VimRegisterInfoTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/entity/rest/VimRegisterInfoTest.java
index 74761f9..121d702 100644
--- a/esr-mgr/src/test/java/org/onap/aai/esr/entity/rest/VimRegisterInfoTest.java
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/entity/rest/VimRegisterInfoTest.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.
@@ -70,6 +70,14 @@ public class VimRegisterInfoTest {
}
@Test
+ public void getterAndSetter4physicalLocationId() {
+ final String physicalLocationId = "test";
+ VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
+ vimRegisterInfo.setPhysicalLocationId(physicalLocationId);
+ assertEquals(vimRegisterInfo.getPhysicalLocationId(), physicalLocationId);
+ }
+
+ @Test
public void getterAndSetter4complexName() {
final String complexName = "test";
VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.java
index 9426753..160de58 100644
--- a/esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.java
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/util/VimManagerUtilTest.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.
@@ -47,6 +47,7 @@ public class VimManagerUtilTest {
vimRegisterInfo.setCloudType("openstack");
vimRegisterInfo.setCloudZone("default");
vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setPhysicalLocationId("complex");
vimRegisterInfo.setOwnerDefinedType("test");
vimRegisterInfo.setStatus("normal");
vimAuthInfos.add(vimAuthInfo);
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java
index e1df1bb..7387ddb 100644
--- a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java
@@ -45,6 +45,7 @@ public class VimManagerWrapperTest {
vimRegisterInfo.setCloudType("openstack");
vimRegisterInfo.setCloudZone("default");
vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setPhysicalLocationId("complex");
vimRegisterInfo.setOwnerDefinedType("test");
vimRegisterInfo.setStatus("normal");
VimAuthInfo vimAuthInfo = new VimAuthInfo();
@@ -132,6 +133,7 @@ public class VimManagerWrapperTest {
vimRegisterInfo.setCloudType("openstack");
vimRegisterInfo.setCloudZone("default");
vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setPhysicalLocationId("complex");
vimRegisterInfo.setOwnerDefinedType("test");
vimRegisterInfo.setStatus("normal");
vimAuthInfos.add(vimAuthInfo);