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 org.onap.aai.domain.yang.v11.L3Network;
20 import org.onap.aai.domain.yang.v11.Relationship;
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.slf4j.Logger;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.context.annotation.Conditional;
29 import org.springframework.stereotype.Component;
31 import static java.lang.String.format;
32 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
33 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
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 L3Network} in AAI
41 @Conditional(value = Conditions.UseForDirect.class)
42 class L3NetworkManager extends AbstractManager {
43 private static final String NETWORK_URL = "/l3-networks/l3-network/%s";
44 private static Logger logger = org.slf4j.LoggerFactory.getLogger(L3NetworkManager.class);
47 L3NetworkManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
48 super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
52 protected Logger getLogger() {
56 void update(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink) {
57 L3Network l3Network = createOrGet(NETWORK, format(NETWORK_URL, buildNetworkId(vnfId, affectedVirtualLink)), OBJECT_FACTORY.createL3Network());
58 updateNetworkFields(vimId, vnfId, affectedVirtualLink, l3Network);
61 void delete(String vnfId, AffectedVirtualLink removedVl) {
62 aaiRestApiProvider.delete(logger, NETWORK, format(NETWORK_URL, buildNetworkId(vnfId, removedVl)));
65 private void updateNetworkFields(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink, L3Network network) {
66 network.setNetworkId(buildNetworkId(vnfId, affectedVirtualLink));
67 network.setNetworkName(extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "name"));
68 network.setNeutronNetworkId(affectedVirtualLink.getResource().getResourceId());
69 network.setIsBoundToVpn(false);
70 network.setIsExternalNetwork(false);
71 network.setIsProviderNetwork(false);
72 network.setIsSharedNetwork(false);
73 network.setOperationalStatus("active");
74 network.setOrchestrationStatus("active");
75 if (network.getRelationshipList() == null) {
76 network.setRelationshipList(new RelationshipList());
78 addMissingRelation(network.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
79 addSingletonRelation(network.getRelationshipList(), getRegionLink(vimId));
80 addSingletonRelation(network.getRelationshipList(), getTenantLink(vimId, extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "tenantId")));
81 aaiRestApiProvider.put(logger, NETWORK, format(NETWORK_URL, network.getNetworkId()), network, Void.class);
84 private String buildNetworkId(String vnfId, AffectedVirtualLink affectedVirtualLink) {
85 return vnfId + SEPARATOR + affectedVirtualLink.getId();
88 private Relationship getRegionLink(String vimId) {
89 Relationship relationship = new Relationship();
90 relationship.setRelatedTo("cloud-region");
91 relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
92 relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
96 private Relationship getTenantLink(String vimId, String tenantId) {
97 Relationship relationship = new Relationship();
98 relationship.setRelatedTo("tenant");
99 relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
100 relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
101 relationship.getRelationshipData().add(buildRelationshipData("tenant.tenant-id", tenantId));