[SO] Release so 1.13.0 image
[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.retry.annotation.Backoff;
32 import org.springframework.retry.annotation.EnableRetry;
33 import org.springframework.retry.annotation.Recover;
34 import org.springframework.retry.annotation.Retryable;
35 import org.springframework.stereotype.Service;
36
37 @Service
38 @EnableRetry
39 public class StartupService {
40
41     private static final Logger logger = LoggerFactory.getLogger(StartupService.class);
42
43     private final String vnfmDefaultEndpoint;
44     private final AaiConnection aaiConnection;
45
46     public StartupService(final ConfigProperties configProperties, final AaiConnection aaiConnection) {
47         this.vnfmDefaultEndpoint = configProperties.getVnfmDefaultEndpoint();
48         this.aaiConnection = aaiConnection;
49     }
50
51     @Retryable(value = {Exception.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000, multiplier = 2))
52     public List<EsrSystemInfo> receiveVnfm() throws VeVnfmException {
53         return aaiConnection.receiveVnfm();
54     }
55
56     @Recover
57     public List<EsrSystemInfo> recoverReceiveVnfm(final Throwable t) {
58         logger.warn("Connection to AAI failed");
59         final EsrSystemInfo info = new EsrSystemInfo();
60         info.setServiceUrl(vnfmDefaultEndpoint);
61         logger.warn("This EsrSystemInfo is used by default: {}", info);
62         return Collections.singletonList(info);
63     }
64 }