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>
@SerializedName("physical-location-id")
private String physicalLocationId;
+
+
+ @SerializedName("complex-name")
+ private String complexName;
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;
+ }
}
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);
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;
}
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;
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);
}
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();
}
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) {