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 io.reactivex.Observable;
19 import java.util.ArrayList;
20 import org.onap.aai.model.L3InterfaceIpv4AddressList;
21 import org.onap.aai.model.L3InterfaceIpv6AddressList;
22 import org.onap.aai.model.LInterface;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
28 import org.slf4j.Logger;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.Conditional;
31 import org.springframework.stereotype.Component;
33 import static java.lang.String.format;
35 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
36 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
37 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
40 * Responsible for managing the {@link LInterface} in AAI
43 @Conditional(value = Conditions.UseForDirect.class)
44 class LInterfaceManager extends AbstractManager {
45 private static Logger logger = org.slf4j.LoggerFactory.getLogger(LInterfaceManager.class);
48 LInterfaceManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
49 super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
52 static String buildUrl(String vimId, ReportedAffectedCp affectedCp) {
53 String cloudOwner = getCloudOwner(vimId);
54 String regionName = getRegionName(vimId);
55 String tenantId = affectedCp.getTenantId();
56 String vServerId = affectedCp.getServerProviderId();
57 String cpId = affectedCp.getCpId();
58 return format("/cloud-regions/cloud-region/%s/%s/tenants/tenant/%s/vservers/vserver/%s/l-interfaces/l-interface/%s", cloudOwner, regionName, tenantId, vServerId, cpId);
62 protected Logger getLogger() {
66 void update(String vnfId, String vimId, ReportedAffectedCp affectedCp, boolean inMaintenance) {
67 LInterface lInterface = createOrGet(getLinterface(vimId, affectedCp), new LInterface());
68 updateFields(vimId, lInterface, affectedCp, vnfId, inMaintenance);
71 void delete(String vimId, ReportedAffectedCp removedCp) {
72 LInterface linterface = getLinterface(vimId, removedCp).blockingFirst();
73 String cloudOwner = getCloudOwner(vimId);
74 String regionName = getRegionName(vimId);
75 String tenantId = removedCp.getTenantId();
76 String vServerId = removedCp.getServerProviderId();
77 String cpId = removedCp.getCpId();
78 aaiRestApiProvider.getCloudInfrastructureApi().deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, linterface.getResourceVersion());
81 private Observable<LInterface> getLinterface(String vimId, ReportedAffectedCp cp) {
82 String cloudOwner = getCloudOwner(vimId);
83 String regionName = getRegionName(vimId);
84 String tenantId = cp.getTenantId();
85 String vServerId = cp.getServerProviderId();
86 String cpId = cp.getCpId();
87 return aaiRestApiProvider.getCloudInfrastructureApi().getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, null, null, null, null, null, null, null, null, null, null, null, null);
90 private void updateFields(String vimId, LInterface logicalInterface, ReportedAffectedCp affectedCp, String vnfId, boolean inMaintenance) {
91 logicalInterface.setInMaint(inMaintenance);
92 logicalInterface.setIsIpUnnumbered(false);
93 logicalInterface.setIsPortMirrored(false);
94 logicalInterface.setInterfaceName(affectedCp.getName());
95 logicalInterface.setInterfaceId(affectedCp.getCpId());
96 logicalInterface.setInterfaceRole(affectedCp.getCpdId());
97 logicalInterface.setMacaddr(affectedCp.getMacAddress());
98 logicalInterface.setProvStatus("active");
99 if (affectedCp.getIpAddress() != null) {
100 if (affectedCp.getIpAddress().contains(":")) {
101 L3InterfaceIpv6AddressList ipv6Address = new L3InterfaceIpv6AddressList();
102 ipv6Address.setL3InterfaceIpv6Address(affectedCp.getIpAddress());
103 ipv6Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
104 if (logicalInterface.getL3InterfaceIpv6AddressList() == null) {
105 logicalInterface.setL3InterfaceIpv6AddressList(new ArrayList<>());
107 logicalInterface.getL3InterfaceIpv6AddressList().add(ipv6Address);
109 L3InterfaceIpv4AddressList ipv4Address = new L3InterfaceIpv4AddressList();
110 ipv4Address.setL3InterfaceIpv4Address(affectedCp.getIpAddress());
111 ipv4Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
112 if (logicalInterface.getL3InterfaceIpv4AddressList() == null) {
113 logicalInterface.setL3InterfaceIpv4AddressList(new ArrayList<>());
115 logicalInterface.getL3InterfaceIpv4AddressList().add(ipv4Address);
118 if (logicalInterface.getRelationshipList() == null) {
119 logicalInterface.setRelationshipList(new ArrayList<>());
121 addSingletonRelation(logicalInterface.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
122 String cloudOwner = getCloudOwner(vimId);
123 String regionName = getRegionName(vimId);
124 String tenantId = affectedCp.getTenantId();
125 String vServerId = affectedCp.getServerProviderId();
126 String cpId = affectedCp.getCpId();
127 systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface));