2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl;
20 import java.util.concurrent.Executors;
21 import java.util.concurrent.ScheduledExecutorService;
22 import java.util.concurrent.ScheduledFuture;
23 import java.util.concurrent.TimeUnit;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.config.DcaeConfig;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 class DcaeProviderWorker implements AutoCloseable {
33 private static final Logger LOG = LoggerFactory.getLogger(DcaeProviderWorker.class);
35 private static final int MIN_HEARTBEAT_TIME_SECONDS = 30;
37 private final ScheduledExecutorService scheduler;
38 private final DcaeSenderImpl dcaepClient;
39 private final DcaeMessages dcaeMessages;
40 private final ScheduledFuture<?> taskReference;
42 public DcaeProviderWorker(DcaeConfig configuration, String entityName, DeviceManagerImpl deviceManager) {
45 LOG.info("Configuration: " + configuration);
46 int heartbeatSeconds = configuration.getTimerPeriodSeconds();
47 if (heartbeatSeconds < MIN_HEARTBEAT_TIME_SECONDS) {
48 heartbeatSeconds = MIN_HEARTBEAT_TIME_SECONDS;
49 LOG.info("Adjust heartbeat intervall to minimum of { } seconds.", heartbeatSeconds);
52 dcaepClient = new DcaeSenderImpl(configuration.getEventReveicerUrl(), configuration.getUserCredentials());
53 dcaeMessages = new DcaeMessages(dcaepClient, entityName, heartbeatSeconds, deviceManager);
56 LOG.info("Create Fault manager client Task");
57 this.scheduler = Executors.newSingleThreadScheduledExecutor();
58 Runnable task = new DcaeProviderTask(dcaeMessages);
60 LOG.info("Fault task created with " + heartbeatSeconds + " Seconds");
61 this.taskReference = this.scheduler.scheduleAtFixedRate(task, 0, heartbeatSeconds, TimeUnit.SECONDS);
62 LOG.info("Fault task scheduled");
65 public void sendProblemNotification(String mountPointName, ProblemNotificationXml notification) {
66 LOG.debug("Notification answer: {}", dcaeMessages.postNotification(mountPointName, notification));
71 this.taskReference.cancel(false);
73 this.scheduler.shutdown();
74 this.scheduler.awaitTermination(5, TimeUnit.SECONDS);
75 } catch (InterruptedException | SecurityException e) {
76 LOG.debug("Schedler shutdown interrupted with exception: ", e);
77 if (e instanceof InterruptedException) {
78 Thread.currentThread().interrupt();