summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java
blob: 6e37cd1eac90a91a1360e447ffed6e665f97da90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright 2016-2017, Nokia Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;

import io.reactivex.Observable;
import java.util.ArrayList;
import org.onap.aai.model.L3InterfaceIpv4AddressList;
import org.onap.aai.model.L3InterfaceIpv6AddressList;
import org.onap.aai.model.LInterface;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProviderForSo;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static java.lang.String.format;

import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;

/**
 * Responsible for managing the {@link LInterface} in AAI
 */
@Component
class LInterfaceManager extends AbstractManager {
    private static Logger logger = org.slf4j.LoggerFactory.getLogger(LInterfaceManager.class);

    @Autowired
    LInterfaceManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProviderForSo cbamRestApiProvider) {
        super(aaiRestApiProvider, cbamRestApiProvider);
    }

    static String buildUrl(String vimId, ReportedAffectedCp affectedCp) {
        String cloudOwner = getCloudOwner(vimId);
        String regionName = getRegionName(vimId);
        String tenantId = affectedCp.getTenantId();
        String vServerId = affectedCp.getServerProviderId();
        String cpId = affectedCp.getCpId();
        return format("/cloud-regions/cloud-region/%s/%s/tenants/tenant/%s/vservers/vserver/%s/l-interfaces/l-interface/%s", cloudOwner, regionName, tenantId, vServerId, cpId);
    }

    @Override
    protected Logger getLogger() {
        return logger;
    }

    void update(String vnfId, String vimId, ReportedAffectedCp affectedCp, boolean inMaintenance) {
        LInterface lInterface = createOrGet(getLinterface(vimId, affectedCp), new LInterface());
        updateFields(vimId, lInterface, affectedCp, vnfId, inMaintenance);
    }

    void delete(String vimId, ReportedAffectedCp removedCp) {
        LInterface linterface = getLinterface(vimId, removedCp).blockingFirst();
        String cloudOwner = getCloudOwner(vimId);
        String regionName = getRegionName(vimId);
        String tenantId = removedCp.getTenantId();
        String vServerId = removedCp.getServerProviderId();
        String cpId = removedCp.getCpId();
        aaiRestApiProvider.getCloudInfrastructureApi().deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, linterface.getResourceVersion());
    }

    private Observable<LInterface> getLinterface(String vimId, ReportedAffectedCp cp) {
        String cloudOwner = getCloudOwner(vimId);
        String regionName = getRegionName(vimId);
        String tenantId = cp.getTenantId();
        String vServerId = cp.getServerProviderId();
        String cpId = cp.getCpId();
        return aaiRestApiProvider.getCloudInfrastructureApi().getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, null, null, null, null, null, null, null, null, null, null, null, null);
    }

    private void updateFields(String vimId, LInterface logicalInterface, ReportedAffectedCp affectedCp, String vnfId, boolean inMaintenance) {
        logicalInterface.setInMaint(inMaintenance);
        logicalInterface.setIsIpUnnumbered(false);
        logicalInterface.setIsPortMirrored(false);
        logicalInterface.setInterfaceName(affectedCp.getName());
        logicalInterface.setInterfaceId(affectedCp.getCpId());
        logicalInterface.setInterfaceRole(affectedCp.getCpdId());
        logicalInterface.setMacaddr(affectedCp.getMacAddress());
        logicalInterface.setProvStatus("active");
        logicalInterface.setL3InterfaceIpv6AddressList(new ArrayList<>());
        logicalInterface.setL3InterfaceIpv4AddressList(new ArrayList<>());
        if (affectedCp.getIpAddress() != null) {
            if (affectedCp.getIpAddress().contains(":")) {
                L3InterfaceIpv6AddressList ipv6Address = new L3InterfaceIpv6AddressList();
                ipv6Address.setL3InterfaceIpv6Address(affectedCp.getIpAddress());
                ipv6Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
                logicalInterface.getL3InterfaceIpv6AddressList().add(ipv6Address);
            } else {
                L3InterfaceIpv4AddressList ipv4Address = new L3InterfaceIpv4AddressList();
                ipv4Address.setL3InterfaceIpv4Address(affectedCp.getIpAddress());
                ipv4Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
                logicalInterface.getL3InterfaceIpv4AddressList().add(ipv4Address);
            }
        }
        if (logicalInterface.getRelationshipList() == null) {
            logicalInterface.setRelationshipList(new ArrayList<>());
        }
        addSingletonRelation(logicalInterface.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
        String cloudOwner = getCloudOwner(vimId);
        String regionName = getRegionName(vimId);
        String tenantId = affectedCp.getTenantId();
        String vServerId = affectedCp.getServerProviderId();
        String cpId = affectedCp.getCpId();
        aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface).blockingFirst();
    }
}