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 com.nokia.cbam.lcm.v32.model.AffectedVirtualLink;
19 import com.nokia.cbam.lcm.v32.model.OperationExecution;
20 import com.nokia.cbam.lcm.v32.model.VnfLifecycleChangeNotification;
21 import java.util.Collection;
22 import java.util.HashSet;
23 import java.util.Optional;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
29 import org.slf4j.Logger;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.context.annotation.Conditional;
32 import org.springframework.stereotype.Component;
34 import static com.google.common.collect.Iterables.filter;
35 import static com.google.common.collect.Iterables.tryFind;
36 import static com.nokia.cbam.lcm.v32.model.ChangeType.*;
37 import static com.nokia.cbam.lcm.v32.model.OperationStatus.STARTED;
38 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.LInterfaceManager.buildUrl;
39 import static org.slf4j.LoggerFactory.getLogger;
40 import static org.springframework.util.StringUtils.isEmpty;
43 * Responsible for providing information related to the VNFM from VF-C source
46 @Conditional(value = Conditions.UseForDirect.class)
47 public class AAINotificationProcessor implements INotificationSender {
48 private static Logger logger = getLogger(AAINotificationProcessor.class);
49 private final GenericVnfManager genericVnfManager;
50 private final L3NetworkManager l3NetworkManager;
51 private final LInterfaceManager lInterfaceManager;
52 private final VnfcManager vnfcManager;
53 private final VserverManager vserverManager;
56 AAINotificationProcessor(GenericVnfManager genericVnfManager, L3NetworkManager l3NetworkManager, LInterfaceManager lInterfaceManager, VnfcManager vnfcManager, VserverManager vserverManager) {
57 this.genericVnfManager = genericVnfManager;
58 this.l3NetworkManager = l3NetworkManager;
59 this.lInterfaceManager = lInterfaceManager;
60 this.vnfcManager = vnfcManager;
61 this.vserverManager = vserverManager;
65 public void processNotification(VnfLifecycleChangeNotification receivedNotification, OperationExecution operationExecution, Optional<ReportedAffectedConnectionPoints> affectedConnectionPoints, String vimId) {
66 boolean inMaintenance = STARTED.equals(receivedNotification.getStatus());
67 genericVnfManager.createOrUpdate(receivedNotification.getVnfInstanceId(), inMaintenance);
68 addOrUpdateVls(receivedNotification, vimId);
69 addOrUpdateVnfcs(receivedNotification, vimId, inMaintenance);
70 processCps(receivedNotification, affectedConnectionPoints, vimId, inMaintenance);
71 removeVnfcs(receivedNotification, vimId);
72 removeVls(receivedNotification);
73 logger.info("Notification processed successfully");
76 private void removeVls(VnfLifecycleChangeNotification receivedNotification) {
77 for (AffectedVirtualLink removedVl : filter(receivedNotification.getAffectedVirtualLinks(), affectedVirtualLink -> affectedVirtualLink.getChangeType().equals(REMOVED))) {
78 l3NetworkManager.delete(receivedNotification.getVnfInstanceId(), removedVl);
82 private void removeVnfcs(VnfLifecycleChangeNotification receivedNotification, String vimId) {
83 for (com.nokia.cbam.lcm.v32.model.AffectedVnfc removedVnfc : filter(receivedNotification.getAffectedVnfcs(), vnfc -> REMOVED.equals(vnfc.getChangeType()))) {
84 vnfcManager.delete(receivedNotification.getVnfInstanceId(), removedVnfc);
85 vserverManager.delete(vimId, removedVnfc);
89 private void processCps(VnfLifecycleChangeNotification receivedNotification, Optional<ReportedAffectedConnectionPoints> affectedConnectionPoints, String vimId, boolean inMaintenance) {
90 if (affectedConnectionPoints.isPresent()) {
91 for (ReportedAffectedCp removedCp : collectCpsToBeDeleted(vimId, affectedConnectionPoints.get())) {
92 lInterfaceManager.delete(vimId, removedCp);
94 //these can only be added or modified because if something is in the post CPS it can not be removed
95 //since it is present after the operation
96 for (ReportedAffectedCp affectedCp : affectedConnectionPoints.get().getPost()) {
97 if (!isEmpty(affectedCp.getServerProviderId())) {
98 lInterfaceManager.update(receivedNotification.getVnfInstanceId(), vimId, affectedCp, inMaintenance);
100 logger.warn("The changed {} connection point is not linked to any server", affectedCp.getCpId());
104 logger.warn("The changed connection points are not present in VNF with {} identifier", receivedNotification.getVnfInstanceId());
108 private void addOrUpdateVnfcs(VnfLifecycleChangeNotification receivedNotification, String vimId, boolean inMaintenance) {
109 for (com.nokia.cbam.lcm.v32.model.AffectedVnfc affectedVnfc : receivedNotification.getAffectedVnfcs()) {
110 if (affectedVnfc.getChangeType() == MODIFIED || affectedVnfc.getChangeType() == ADDED) {
111 vserverManager.update(vimId, receivedNotification.getVnfInstanceId(), affectedVnfc, receivedNotification.getAffectedVirtualStorages(), inMaintenance);
112 vnfcManager.update(vimId, VserverManager.getTenantId(affectedVnfc), receivedNotification.getVnfInstanceId(), affectedVnfc, inMaintenance);
117 private void addOrUpdateVls(VnfLifecycleChangeNotification receivedNotification, String vimId) {
118 for (AffectedVirtualLink affectedVirtualLink : receivedNotification.getAffectedVirtualLinks()) {
119 if ((affectedVirtualLink.getChangeType() == MODIFIED) || (affectedVirtualLink.getChangeType() == ADDED)) {
120 l3NetworkManager.update(vimId, receivedNotification.getVnfInstanceId(), affectedVirtualLink);
126 * The ports that are present in the pre, but not present in the post are
127 * removed regardless of the "removed" flag being present in the pre, because
128 * that only signals the remove intention, but does not actually mean that
129 * the resource have been removed
131 private Collection<ReportedAffectedCp> collectCpsToBeDeleted(String vimId, ReportedAffectedConnectionPoints cps) {
132 Set<ReportedAffectedCp> cpsToRemove = new HashSet<>();
133 for (ReportedAffectedCp cpBeforeOperation : cps.getPre()) {
134 if (!isEmpty(cpBeforeOperation.getServerProviderId())) {
135 String originalResource = buildUrl(vimId, cpBeforeOperation);
136 if (!tryFind(cps.getPost(), cpAfterOperation -> originalResource.equals(buildUrl(vimId, cpAfterOperation))).isPresent()) {
137 cpsToRemove.add(cpBeforeOperation);