2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
18 import org.onap.aai.domain.yang.v11.L3InterfaceIpv4AddressList;
19 import org.onap.aai.domain.yang.v11.L3InterfaceIpv6AddressList;
20 import org.onap.aai.domain.yang.v11.LInterface;
21 import org.onap.aai.domain.yang.v11.RelationshipList;
22 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
27 import org.slf4j.Logger;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.context.annotation.Conditional;
30 import org.springframework.stereotype.Component;
32 import static java.lang.String.format;
33 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.CLOUD;
34 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
35 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
38 * Responsible for managing the {@link LInterface} in AAI
41 @Conditional(value = Conditions.UseForDirect.class)
42 class LInterfaceManager extends AbstractManager {
43 private static Logger logger = org.slf4j.LoggerFactory.getLogger(LInterfaceManager.class);
46 LInterfaceManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
47 super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
50 static String buildUrl(String vimId, ReportedAffectedCp affectedCp) {
51 String cloudOwner = getCloudOwner(vimId);
52 String regionName = getRegionName(vimId);
53 String tenantId = affectedCp.getTenantId();
54 String vServerId = affectedCp.getServerProviderId();
55 String cpId = affectedCp.getCpId();
56 return format("/cloud-regions/cloud-region/%s/%s/tenants/tenant/%s/vservers/vserver/%s/l-interfaces/l-interface/%s", cloudOwner, regionName, tenantId, vServerId, cpId);
60 protected Logger getLogger() {
64 void update(String vnfId, String vimId, ReportedAffectedCp affectedCp, boolean inMaintenance) {
65 LInterface lInterface = createOrGet(CLOUD, buildUrl(vimId, affectedCp), OBJECT_FACTORY.createLInterface());
66 updateFields(lInterface, affectedCp, vnfId, buildUrl(vimId, affectedCp), inMaintenance);
69 void delete(String vimId, ReportedAffectedCp removedCp) {
70 aaiRestApiProvider.delete(logger, AAIRestApiProvider.AAIService.CLOUD, buildUrl(vimId, removedCp));
73 private void updateFields(LInterface logicalInterface, ReportedAffectedCp affectedCp, String vnfId, String url, boolean inMaintenance) {
74 logicalInterface.setInMaint(inMaintenance);
75 logicalInterface.setIsIpUnnumbered(false);
76 logicalInterface.setIsPortMirrored(false);
77 logicalInterface.setInterfaceName(affectedCp.getName());
78 logicalInterface.setInterfaceId(affectedCp.getCpId());
79 logicalInterface.setInterfaceRole(affectedCp.getCpdId());
80 logicalInterface.setMacaddr(affectedCp.getMacAddress());
81 logicalInterface.setProvStatus("active");
82 if (affectedCp.getIpAddress() != null) {
83 if (affectedCp.getIpAddress().contains(":")) {
84 L3InterfaceIpv6AddressList ipv6Address = OBJECT_FACTORY.createL3InterfaceIpv6AddressList();
85 ipv6Address.setL3InterfaceIpv6Address(affectedCp.getIpAddress());
86 ipv6Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
87 logicalInterface.getL3InterfaceIpv6AddressList().add(ipv6Address);
89 L3InterfaceIpv4AddressList ipv4Address = OBJECT_FACTORY.createL3InterfaceIpv4AddressList();
90 ipv4Address.setL3InterfaceIpv4Address(affectedCp.getIpAddress());
91 ipv4Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
92 logicalInterface.getL3InterfaceIpv4AddressList().add(ipv4Address);
95 if (logicalInterface.getRelationshipList() == null) {
96 logicalInterface.setRelationshipList(new RelationshipList());
98 addSingletonRelation(logicalInterface.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
99 aaiRestApiProvider.put(logger, CLOUD, url, logicalInterface, Void.class);