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.vnfm;
18 import com.google.common.io.BaseEncoding;
19 import com.nokia.cbam.catalog.v1.api.DefaultApi;
20 import com.nokia.cbam.lcm.v32.ApiClient;
21 import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
22 import com.nokia.cbam.lcm.v32.api.VnfsApi;
23 import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider;
25 import org.onap.vnfmdriver.model.VnfmInfo;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.beans.factory.annotation.Value;
28 import org.springframework.stereotype.Component;
30 import java.io.ByteArrayInputStream;
33 * Responsible for providing client to access CBAM REST API
36 public class CbamRestApiProvider {
37 public static final String NOKIA_LCN_API_VERSION = "3.2";
38 public static final String NOKIA_LCM_API_VERSION = "3.2";
39 private final DriverProperties driverProperties;
40 private final CbamTokenProvider tokenProvider;
41 private final VnfmInfoProvider vnfmInfoProvider;
43 @Value("${trustedCertificates}")
44 private String trustedCertificates;
45 @Value("${skipCertificateVerification}")
46 private boolean skipCertificateVerification;
49 public CbamRestApiProvider(DriverProperties driverProperties, CbamTokenProvider cbamTokenProvider, VnfmInfoProvider vnfmInfoProvider) {
50 this.driverProperties = driverProperties;
51 this.tokenProvider = cbamTokenProvider;
52 this.vnfmInfoProvider = vnfmInfoProvider;
56 * @param vnfmId the identifier of the VNFM
57 * @return API to access CBAM LCM API
59 public VnfsApi getCbamLcmApi(String vnfmId) {
60 return new VnfsApi(getLcmApiClient(vnfmId));
64 * @param vnfmId the identifier of the VNFM
65 * @return API to access the operation executions
67 public OperationExecutionsApi getCbamOperationExecutionApi(String vnfmId) {
68 return new OperationExecutionsApi(getLcmApiClient(vnfmId));
72 * @param vnfmId the identifier of the VNFM
73 * @return API to access CBAM LCN subscription API
75 public SubscriptionsApi getCbamLcnApi(String vnfmId) {
76 com.nokia.cbam.lcn.v32.ApiClient apiClient = new com.nokia.cbam.lcn.v32.ApiClient();
77 if (!skipCertificateVerification) {
78 apiClient.setSslCaCert(new ByteArrayInputStream(BaseEncoding.base64().decode(trustedCertificates)));
80 apiClient.setVerifyingSsl(false);
82 apiClient.setBasePath(driverProperties.getCbamLcnUrl());
83 apiClient.setAccessToken(tokenProvider.getToken(vnfmId));
84 return new SubscriptionsApi(apiClient);
88 * @param vnfmId the identifier of the VNFM
89 * @return API to access CBAM catalog API
91 public DefaultApi getCbamCatalogApi(String vnfmId) {
92 com.nokia.cbam.catalog.v1.ApiClient apiClient = new com.nokia.cbam.catalog.v1.ApiClient();
93 if (!skipCertificateVerification) {
94 apiClient.setSslCaCert(new ByteArrayInputStream(BaseEncoding.base64().decode(trustedCertificates)));
96 apiClient.setVerifyingSsl(false);
98 apiClient.setBasePath(driverProperties.getCbamCatalogUrl());
99 apiClient.setAccessToken(tokenProvider.getToken(vnfmId));
100 return new DefaultApi(apiClient);
103 private ApiClient getLcmApiClient(String vnfmId) {
104 VnfmInfo vnfmInfo = vnfmInfoProvider.getVnfmInfo(vnfmId);
105 ApiClient apiClient = new ApiClient();
106 if (!skipCertificateVerification) {
107 apiClient.setSslCaCert(new ByteArrayInputStream(BaseEncoding.base64().decode(trustedCertificates)));
109 apiClient.setVerifyingSsl(false);
111 apiClient.setAccessToken(tokenProvider.getToken(vnfmId));
112 apiClient.setBasePath(vnfmInfo.getUrl());