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.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;
 
  38  * Responsible for managing the {@link L3Network} in AAI
 
  41 @Conditional(value = Conditions.UseForDirect.class)
 
  42 class L3NetworkManager extends AbstractManager {
 
  43     private static Logger logger = org.slf4j.LoggerFactory.getLogger(L3NetworkManager.class);
 
  46     L3NetworkManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
 
  47         super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
 
  51     protected Logger getLogger() {
 
  55     void update(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink) {
 
  56         L3Network l3Network = createOrGet(getNetwork(vnfId, affectedVirtualLink), new L3Network());
 
  57         updateNetworkFields(vimId, vnfId, affectedVirtualLink, l3Network);
 
  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);
 
  64     void delete(String vnfId, AffectedVirtualLink removedVl) {
 
  65         L3Network l3Network = getNetwork(vnfId, removedVl).blockingFirst();
 
  66         systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()));
 
  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<>());
 
  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));
 
  88     private String buildNetworkId(String vnfId, AffectedVirtualLink affectedVirtualLink) {
 
  89         return vnfId + SEPARATOR + affectedVirtualLink.getId();
 
  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)));
 
 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));