2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. 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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pdpx.main.comm;
26 import org.onap.policy.common.utils.network.NetworkUtil;
27 import org.onap.policy.models.pdp.concepts.PdpStateChange;
28 import org.onap.policy.models.pdp.concepts.PdpStatus;
29 import org.onap.policy.models.pdp.concepts.PdpUpdate;
30 import org.onap.policy.models.pdp.enums.PdpHealthStatus;
31 import org.onap.policy.models.pdp.enums.PdpState;
32 import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
33 import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 public class XacmlPdpMessage {
40 // The logger for this class
41 private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpMessage.class);
42 private String pdpGroup;
43 private String pdpSubGroup;
44 private PdpState pdpState;
45 private String pdpName = NetworkUtil.getHostname();
48 * Method used to format the initial registration status message.
50 * @param state of the PDP
51 * @return status message of the PDP
53 public PdpStatus formatInitialStatusMessage(PdpState state) {
54 PdpStatus status = new PdpStatus();
55 status.setName(pdpName);
57 if (XacmlPdpActivator.getCurrent().isAlive()) {
58 status.setHealthy(PdpHealthStatus.HEALTHY);
60 status.setHealthy(PdpHealthStatus.NOT_HEALTHY);
63 status.setPdpType("xacml");
64 status.setState(state);
65 status.setSupportedPolicyTypes(XacmlPdpApplicationManager.getToscaPolicyTypeIdents());
67 LOGGER.debug("formatStatusMessage state {} status{}", state, status);
74 * Method used to format the PdpStatus message for heartbeat and PDP Updates.
76 * @return status message of the PDP
78 public PdpStatus formatPdpStatusMessage() {
79 PdpStatus status = new PdpStatus();
80 status.setName(pdpName);
82 if (XacmlPdpActivator.getCurrent().isAlive()) {
83 status.setHealthy(PdpHealthStatus.HEALTHY);
85 status.setHealthy(PdpHealthStatus.NOT_HEALTHY);
88 status.setPdpType("xacml");
89 status.setState(pdpState);
90 status.setPdpGroup(pdpGroup);
91 status.setPdpSubgroup(pdpSubGroup);
92 status.setSupportedPolicyTypes(XacmlPdpApplicationManager.getToscaPolicyTypeIdents());
93 status.setPolicies(XacmlPdpApplicationManager.getToscaPolicyIdentifiers());
99 * Method used to update PDP status attributes from PdpStateChange.
101 public void updateInternalStatus(PdpStateChange message) {
102 pdpGroup = message.getPdpGroup();
103 pdpSubGroup = message.getPdpSubgroup();
104 pdpState = message.getState();
108 * Method used to update PDP status attributes from PdpUpdate.
110 public void updateInternalStatus(PdpUpdate message) {
111 pdpGroup = message.getPdpGroup();
112 pdpSubGroup = message.getPdpSubgroup();