From 6652164b384221018bf605b1d5fb809425b26a8e Mon Sep 17 00:00:00 2001 From: jhh Date: Tue, 18 Oct 2022 12:08:45 -0500 Subject: Support optional cluster name in policy engine This allows also for correlation with running pod hostnames in the case of multiple drools pdp flavors coexist. Issue-ID: POLICY-4403 Signed-off-by: jhh Change-Id: I81affeeec622e6c0e9627651bf34c0775a796827 Signed-off-by: jhh --- .../onap/policy/drools/lifecycle/LifecycleFsm.java | 27 +++++++++++++++------- .../server/restful/RestLifecycleManager.java | 6 ++--- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'feature-lifecycle/src/main/java/org/onap') diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java index 611ac240..09dcab00 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java @@ -39,6 +39,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import lombok.AccessLevel; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -153,6 +154,8 @@ public class LifecycleFsm implements Startable { @Setter protected String pdpType; + protected volatile String pdpName; + @Getter protected Set mandatoryPolicyTypes = new HashSet<>(); @@ -186,12 +189,6 @@ public class LifecycleFsm implements Startable { logger.info("The mandatory Policy Types are {}. Compliance is {}", mandatoryPolicyTypes, isMandatoryPolicyTypesCompliant()); - - stats.setPdpInstanceId(PolicyEngineConstants.PDP_NAME); - } - - public String getName() { - return PolicyEngineConstants.PDP_NAME; } @GsonJsonIgnore @@ -204,6 +201,18 @@ public class LifecycleFsm implements Startable { return client != null && client.getSink().isAlive(); } + /** + * Returns the PDP Name. + */ + public String getPdpName() { + if (this.pdpName == null) { + this.pdpName = PolicyEngineConstants.getManager().getPdpName(); + this.stats.setPdpInstanceId(pdpName); + } + + return this.pdpName; + } + /** * Current state. */ @@ -231,6 +240,8 @@ public class LifecycleFsm implements Startable { @Override public synchronized boolean start() { + this.pdpName = PolicyEngineConstants.getManager().getPdpName(); + stats.setPdpInstanceId(pdpName); logger.info("lifecycle event: start engine"); return state.start(); } @@ -651,7 +662,7 @@ public class LifecycleFsm implements Startable { protected PdpStatus statusPayload(@NonNull PdpState state) { var status = new PdpStatus(); - status.setName(getName()); + status.setName(getPdpName()); status.setPdpGroup(group); status.setPdpSubgroup(subGroup); status.setState(state); @@ -711,7 +722,7 @@ public class LifecycleFsm implements Startable { } protected boolean isItMe(String name, String group, String subgroup) { - if (Objects.equals(name, getName())) { + if (Objects.equals(name, getPdpName())) { return true; } diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java index 494c708b..5a534639 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -155,7 +155,7 @@ public class RestLifecycleManager { change.setPdpGroup(LifecycleFeature.getFsm().getGroup()); change.setPdpSubgroup(LifecycleFeature.getFsm().getSubGroup()); change.setState(PdpState.valueOf(state)); - change.setName(LifecycleFeature.getFsm().getName()); + change.setName(LifecycleFeature.getFsm().getPdpName()); return Response.status(Response.Status.OK).entity(LifecycleFeature.getFsm().stateChange(change)).build(); } @@ -442,7 +442,7 @@ public class RestLifecycleManager { private PdpUpdate getPolicyUpdate() { var update = new PdpUpdate(); - update.setName(LifecycleFeature.getFsm().getName()); + update.setName(LifecycleFeature.getFsm().getPdpName()); update.setPdpGroup(LifecycleFeature.getFsm().getGroup()); update.setPdpSubgroup(LifecycleFeature.getFsm().getSubGroup()); return update; -- cgit 1.2.3-korg