2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023-2024 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.acm.runtime.supervision;
23 import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
24 import org.onap.policy.clamp.models.acm.concepts.Participant;
25 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
26 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
27 import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.stereotype.Component;
33 * This class is used to scan the automation compositions in the database and check if they are in the correct state.
36 public class SupervisionPartecipantScanner {
37 private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionPartecipantScanner.class);
39 private final long maxWaitMs;
41 private final ParticipantProvider participantProvider;
44 * Constructor for instantiating SupervisionPartecipantScanner.
46 * @param participantProvider the Participant Provider
47 * @param acRuntimeParameterGroup the parameters for the automation composition runtime
49 public SupervisionPartecipantScanner(final ParticipantProvider participantProvider,
50 final AcRuntimeParameterGroup acRuntimeParameterGroup) {
51 this.participantProvider = participantProvider;
52 this.maxWaitMs = acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs();
59 LOGGER.debug("Scanning participans in the database . . .");
61 for (var participant : participantProvider.getParticipants()) {
62 scanParticipantStatus(participant);
65 LOGGER.debug("Participans scan complete . . .");
68 private void scanParticipantStatus(Participant participant) {
69 var id = participant.getParticipantId();
70 if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) {
71 LOGGER.debug("report Participant is still OFF_LINE {}", id);
74 var now = TimestampHelper.nowEpochMilli();
75 var lastMsg = TimestampHelper.toEpochMilli(participant.getLastMsg());
76 if ((now - lastMsg) > maxWaitMs) {
77 LOGGER.debug("report Participant OFF_LINE {}", id);
78 participant.setParticipantState(ParticipantState.OFF_LINE);
79 participantProvider.saveParticipant(participant);