Removing jackson to mitigate cve-2017-4995
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / onap / direct / notification / L3NetworkManager.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
17
18 import com.nokia.cbam.lcm.v32.model.AffectedVirtualLink;
19 import io.reactivex.Observable;
20 import java.util.ArrayList;
21 import org.onap.aai.model.L3Network;
22 import org.onap.aai.model.Relationship;
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.slf4j.Logger;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.context.annotation.Conditional;
30 import org.springframework.stereotype.Component;
31
32 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
33 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
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;
36
37 /**
38  * Responsible for managing the {@link L3Network} in AAI
39  */
40 @Component
41 @Conditional(value = Conditions.UseForDirect.class)
42 class L3NetworkManager extends AbstractManager {
43     private static Logger logger = org.slf4j.LoggerFactory.getLogger(L3NetworkManager.class);
44
45     @Autowired
46     L3NetworkManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
47         super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
48     }
49
50     @Override
51     protected Logger getLogger() {
52         return logger;
53     }
54
55     void update(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink) {
56         L3Network l3Network = createOrGet(getNetwork(vnfId, affectedVirtualLink), new L3Network());
57         updateNetworkFields(vimId, vnfId, affectedVirtualLink, l3Network);
58     }
59
60     private Observable<L3Network> getNetwork(String vnfId, AffectedVirtualLink affectedVirtualLink) {
61         return aaiRestApiProvider.getNetworkApi().getNetworkL3NetworksL3Network(buildNetworkId(vnfId, affectedVirtualLink), null, null, null, null, null, null, null, null, null);
62     }
63
64     void delete(String vnfId, AffectedVirtualLink removedVl) {
65         L3Network l3Network = getNetwork(vnfId, removedVl).blockingFirst();
66         systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()));
67     }
68
69     private void updateNetworkFields(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink, L3Network network) {
70         network.setNetworkId(buildNetworkId(vnfId, affectedVirtualLink));
71         network.setNetworkName(extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "name"));
72         network.setNeutronNetworkId(affectedVirtualLink.getResource().getResourceId());
73         network.setIsBoundToVpn(false);
74         network.setIsExternalNetwork(false);
75         network.setIsProviderNetwork(false);
76         network.setIsSharedNetwork(false);
77         network.setOperationalStatus("active");
78         network.setOrchestrationStatus("active");
79         if (network.getRelationshipList() == null) {
80             network.setRelationshipList(new ArrayList<>());
81         }
82         addMissingRelation(network.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
83         addSingletonRelation(network.getRelationshipList(), getRegionLink(vimId));
84         addSingletonRelation(network.getRelationshipList(), getTenantLink(vimId, extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "tenantId")));
85         systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network));
86     }
87
88     private String buildNetworkId(String vnfId, AffectedVirtualLink affectedVirtualLink) {
89         return vnfId + SEPARATOR + affectedVirtualLink.getId();
90     }
91
92     private Relationship getRegionLink(String vimId) {
93         Relationship relationship = new Relationship();
94         relationship.setRelatedTo("cloud-region");
95         relationship.setRelationshipData(new ArrayList<>());
96         relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
97         relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
98         return relationship;
99     }
100
101     private Relationship getTenantLink(String vimId, String tenantId) {
102         Relationship relationship = new Relationship();
103         relationship.setRelatedTo("tenant");
104         relationship.setRelationshipData(new ArrayList<>());
105         relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
106         relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
107         relationship.getRelationshipData().add(buildRelationshipData("tenant.tenant-id", tenantId));
108         return relationship;
109     }
110 }