Merge "AAI id mapping in SOL002 Adapter"
[so.git] / adapters / etsi-sol002-adapter / src / main / java / org / onap / so / adapters / vevnfm / service / StartupService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SO
4  * ================================================================================
5  * Copyright (C) 2020 Samsung. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.vevnfm.service;
22
23 import java.util.Collections;
24 import java.util.List;
25 import org.onap.aai.domain.yang.EsrSystemInfo;
26 import org.onap.so.adapters.vevnfm.aai.AaiConnection;
27 import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
28 import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.retry.annotation.Backoff;
33 import org.springframework.retry.annotation.EnableRetry;
34 import org.springframework.retry.annotation.Recover;
35 import org.springframework.retry.annotation.Retryable;
36 import org.springframework.stereotype.Service;
37
38 @Service
39 @EnableRetry
40 public class StartupService {
41
42     private static final Logger logger = LoggerFactory.getLogger(StartupService.class);
43
44     private final String vnfmDefaultEndpoint;
45     private final AaiConnection aaiConnection;
46
47     @Autowired
48     public StartupService(final ConfigProperties configProperties, final AaiConnection aaiConnection) {
49         this.vnfmDefaultEndpoint = configProperties.getVnfmDefaultEndpoint();
50         this.aaiConnection = aaiConnection;
51     }
52
53     @Retryable(value = {Exception.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000, multiplier = 2))
54     public List<EsrSystemInfo> receiveVnfm() throws VeVnfmException {
55         return aaiConnection.receiveVnfm();
56     }
57
58     @Recover
59     public List<EsrSystemInfo> recoverReceiveVnfm(final Throwable t) {
60         logger.warn("Connection to AAI failed");
61         final EsrSystemInfo info = new EsrSystemInfo();
62         info.setServiceUrl(vnfmDefaultEndpoint);
63         logger.warn("This EsrSystemInfo is used by default: {}", info);
64         return Collections.singletonList(info);
65     }
66 }