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.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.init;
19 import java.io.IOException;
20 import java.util.List;
22 import org.apache.http.client.ClientProtocolException;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmSubscriptionInfo;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmSubscriptionsMapper;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.boot.ApplicationArguments;
34 import org.springframework.boot.ApplicationRunner;
35 import org.springframework.core.annotation.Order;
36 import org.springframework.stereotype.Component;
40 public class CbamNofiticationSubscription implements ApplicationRunner {
41 private static final Logger logger = LoggerFactory.getLogger(CbamNofiticationSubscription.class);
44 AdaptorEnv adaptorEnv;
47 private CbamMgmrInf cbamMgmr;
50 private VnfmSubscriptionsMapper subscriptionsMapper;
53 public void run(ApplicationArguments args){
54 boolean subscribed = false;
55 List<VnfmSubscriptionInfo> allSubscripions = subscriptionsMapper.getAll();
56 if(allSubscripions != null && !allSubscripions.isEmpty())
58 for(VnfmSubscriptionInfo subscriptionInfo : allSubscripions)
61 Subscription subscription = cbamMgmr.getSubscription(subscriptionInfo.getId());
62 if(subscription != null)
65 logger.info("CBAM Notification has already been subscribed with id = " + subscriptionInfo.getId());
69 subscriptionsMapper.delete(subscriptionInfo.getId());
71 } catch (Exception e) {
72 logger.error("Query or delete subscription error.", e);
79 CBAMCreateSubscriptionRequest subscriptionRequest = new CBAMCreateSubscriptionRequest();
80 subscriptionRequest.setCallbackUrl(adaptorEnv.getDriverApiUriFront() + "/api/nokiavnfmdriver/v1/notifications");
82 CBAMCreateSubscriptionResponse createSubscription = cbamMgmr.createSubscription(subscriptionRequest);
83 if(createSubscription != null)
85 subscriptionsMapper.insert(createSubscription.getId());
86 logger.info("CBAM Notification is successfully subscribed with id = " + createSubscription.getId());
88 } catch (Exception e) {
89 logger.error("Subscribe notification error.", e);