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 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;
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.vnfm.LifecycleManager.getCloudOwner;
34 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
37 * Responsible for managing the {@link L3Network} in AAI
40 @Conditional(value = Conditions.UseForDirect.class)
41 class L3NetworkManager extends AbstractManager {
42 private static Logger logger = org.slf4j.LoggerFactory.getLogger(L3NetworkManager.class);
45 L3NetworkManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
46 super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
50 protected Logger getLogger() {
54 void update(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink) {
55 L3Network l3Network = createOrGet(getNetwork(vnfId, affectedVirtualLink), new L3Network());
56 updateNetworkFields(vimId, vnfId, affectedVirtualLink, l3Network);
59 private Observable<L3Network> getNetwork(String vnfId, AffectedVirtualLink affectedVirtualLink) {
60 return aaiRestApiProvider.getNetworkApi().getNetworkL3NetworksL3Network(buildNetworkId(vnfId, affectedVirtualLink), null, null, null, null, null, null, null, null, null);
63 void delete(String vnfId, AffectedVirtualLink removedVl) {
64 L3Network l3Network = getNetwork(vnfId, removedVl).blockingFirst();
65 aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()).blockingFirst();
68 private void updateNetworkFields(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink, L3Network network) {
69 network.setNetworkId(buildNetworkId(vnfId, affectedVirtualLink));
70 network.setNetworkName(extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "name"));
71 network.setNeutronNetworkId(affectedVirtualLink.getResource().getResourceId());
72 network.setIsBoundToVpn(false);
73 network.setIsExternalNetwork(false);
74 network.setIsProviderNetwork(false);
75 network.setIsSharedNetwork(false);
76 network.setOperationalStatus("active");
77 network.setOrchestrationStatus("active");
78 if (network.getRelationshipList() == null) {
79 network.setRelationshipList(new ArrayList<>());
81 addMissingRelation(network.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
82 addSingletonRelation(network.getRelationshipList(), getRegionLink(vimId));
83 addSingletonRelation(network.getRelationshipList(), getTenantLink(vimId, extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "tenantId")));
84 aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network).blockingFirst();
87 private String buildNetworkId(String vnfId, AffectedVirtualLink affectedVirtualLink) {
88 return vnfId + SEPARATOR + affectedVirtualLink.getId();
91 private Relationship getRegionLink(String vimId) {
92 Relationship relationship = new Relationship();
93 relationship.setRelatedTo("cloud-region");
94 relationship.setRelationshipData(new ArrayList<>());
95 relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
96 relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
100 private Relationship getTenantLink(String vimId, String tenantId) {
101 Relationship relationship = new Relationship();
102 relationship.setRelatedTo("tenant");
103 relationship.setRelationshipData(new ArrayList<>());
104 relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
105 relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
106 relationship.getRelationshipData().add(buildRelationshipData("tenant.tenant-id", tenantId));