2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
23 import static org.slf4j.LoggerFactory.getLogger;
25 import org.onap.aai.domain.yang.EsrSystemInfo;
26 import org.onap.aai.domain.yang.EsrSystemInfoList;
27 import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider;
28 import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException;
29 import org.slf4j.Logger;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32 import org.springframework.web.util.UriComponentsBuilder;
35 * Provides URLs for REST calls to a VNFM.
38 public class VnfmUrlProvider {
40 private static Logger logger = getLogger(VnfmUrlProvider.class);
41 private final AaiServiceProvider aaiServiceProvider;
44 public VnfmUrlProvider(final AaiServiceProvider aaiServiceProvider) {
45 this.aaiServiceProvider = aaiServiceProvider;
49 * Get the URL for a generic VNF in AAI.
51 * @param vnfId The identifier of the VNF
52 * @return the URL of the VNF
54 public String getOperationUrl(final String vnfmId, final String operationId) {
55 final String url = UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("/vnf_lcm_op_occs/")
56 .pathSegment(operationId).build().toString();
57 logger.debug("getOperationUrl:" + url);
62 private URI getBaseUri(final String vnfmId) {
63 final EsrSystemInfoList vnfmEsrSystemInfoList = aaiServiceProvider.invokeGetVnfmEsrSystemInfoList(vnfmId);
65 if (vnfmEsrSystemInfoList != null) {
66 for (final EsrSystemInfo esrSystemInfo : vnfmEsrSystemInfoList.getEsrSystemInfo()) {
67 return UriComponentsBuilder.fromHttpUrl(esrSystemInfo.getServiceUrl()).build().toUri();
71 throw new VnfmNotFoundException("VNFM, or Service URL for VNFM, not found for VNFM " + vnfmId);