/**
- * 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.
private String ownerDefinedType;
private String cloudZone;
-
+
private String complexName;
+ private String physicalLocationId;
+
private String cloudExtraInfo;
private String status;
this.cloudZone = cloudZone;
}
- public String getComplexName() {
- return complexName;
- }
-
- public void setComplexName(String complexName) {
- this.complexName = complexName;
- }
-
public String getCloudExtraInfo() {
return cloudExtraInfo;
}
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;
+ }
+
}
/**
- * 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.
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;
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);
+ }
+ }
}
@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;
--- /dev/null
+/**
+ * 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"));
+ }
+}
/**
- * 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.
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;
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);
}
}
+ 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();
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();
}
}
/**
- * 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.
assertEquals(vimRegisterInfo.getCloudZone(), cloudZone);
}
+ @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";
/**
- * 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.
vimRegisterInfo.setCloudType("openstack");
vimRegisterInfo.setCloudZone("default");
vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setPhysicalLocationId("complex");
vimRegisterInfo.setOwnerDefinedType("test");
vimRegisterInfo.setStatus("normal");
vimAuthInfos.add(vimAuthInfo);
vimRegisterInfo.setCloudType("openstack");
vimRegisterInfo.setCloudZone("default");
vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setPhysicalLocationId("complex");
vimRegisterInfo.setOwnerDefinedType("test");
vimRegisterInfo.setStatus("normal");
VimAuthInfo vimAuthInfo = new VimAuthInfo();
vimRegisterInfo.setCloudType("openstack");
vimRegisterInfo.setCloudZone("default");
vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setPhysicalLocationId("complex");
vimRegisterInfo.setOwnerDefinedType("test");
vimRegisterInfo.setStatus("normal");
vimAuthInfos.add(vimAuthInfo);