2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.vevnfm.service;
23 import java.util.LinkedList;
24 import java.util.List;
25 import org.onap.aai.domain.yang.EsrSystemInfo;
26 import org.onap.so.adapters.vevnfm.aai.EsrId;
27 import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.scheduling.annotation.EnableScheduling;
32 import org.springframework.scheduling.annotation.Scheduled;
33 import org.springframework.stereotype.Service;
37 public class SubscriptionScheduler {
39 private static final Logger logger = LoggerFactory.getLogger(SubscriptionScheduler.class);
42 private SubscriberService subscriberService;
44 private List<EsrId> esrIds;
46 public void setInfos(final List<EsrSystemInfo> infos) {
47 esrIds = new LinkedList<>();
49 for (final EsrSystemInfo info : infos) {
50 final EsrId esrId = new EsrId();
56 List<EsrId> getEsrIds() {
60 @Scheduled(fixedRate = 5000, initialDelay = 2000)
61 void subscribeTask() throws VeVnfmException {
62 if (isEsrIdsValid()) {
63 for (final EsrId esrId : esrIds) {
64 singleSubscribe(esrId);
69 @Scheduled(fixedRate = 20000)
70 void checkSubscribeTask() throws VeVnfmException {
71 if (isEsrIdsValid()) {
72 for (final EsrId esrId : esrIds) {
73 singleCheckSubscription(esrId);
78 private boolean isEsrIdsValid() {
79 return esrIds != null && !esrIds.isEmpty();
82 private void singleSubscribe(final EsrId esrId) throws VeVnfmException {
83 if (esrId.getId() == null) {
84 logger.info("Single subscribe task");
85 esrId.setId(subscriberService.subscribe(esrId.getInfo()));
89 private void singleCheckSubscription(final EsrId esrId) throws VeVnfmException {
90 if (esrId.getId() != null) {
91 logger.info("Checking subscription: {}", esrId.getId());
92 if (!subscriberService.checkSubscription(esrId.getInfo(), esrId.getId())) {
93 logger.info("Subscription {} not available", esrId.getId());