* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import lombok.Setter;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.dbcp2.BasicDataSourceFactory;
-import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockState;
import org.onap.policy.drools.core.lock.PolicyResourceLockManager;
* Name of the host on which this JVM is running.
*/
@Getter
- private final String hostName;
+ private final String pdpName;
/**
* UUID of this object.
* Constructs the object.
*/
public DistributedLockManager() {
- this.hostName = NetworkUtil.getHostname();
+ this.pdpName = PolicyEngineConstants.PDP_NAME;
this.resource2lock = getResource2lock();
}
"SELECT resourceId FROM pooling.locks WHERE host=? AND owner=? AND expirationTime > now()")) {
// @formatter:on
- stmt.setString(1, hostName);
+ stmt.setString(1, pdpName);
stmt.setString(2, uuidString);
try (ResultSet resultSet = stmt.executeQuery()) {
super(state, resourceId, ownerKey, holdSec, callback);
this.feature = feature;
- this.hostName = feature.hostName;
+ this.hostName = feature.pdpName;
this.uuidString = feature.uuidString;
}
+ "values (?, ?, ?, timestampadd(second, ?, now()))")) {
stmt.setString(1, getResourceId());
- stmt.setString(2, feature.hostName);
+ stmt.setString(2, feature.pdpName);
stmt.setString(3, feature.uuidString);
stmt.setInt(4, getHoldSec());
stmt.executeUpdate();
- this.hostName = feature.hostName;
+ this.hostName = feature.pdpName;
this.uuidString = feature.uuidString;
return true;
+ " AND ((host=? AND owner=?) OR expirationTime < now())")) {
stmt.setString(1, getResourceId());
- stmt.setString(2, feature.hostName);
+ stmt.setString(2, feature.pdpName);
stmt.setString(3, feature.uuidString);
stmt.setInt(4, getHoldSec());
return false;
}
- this.hostName = feature.hostName;
+ this.hostName = feature.pdpName;
this.uuidString = feature.uuidString;
return true;
assertEquals(5, getRecordCount());
// expire one record
- updateRecord(RESOURCE, feature.getHostName(), feature.getUuidString(), -1);
+ updateRecord(RESOURCE, feature.getPdpName(), feature.getUuidString(), -1);
// change host of another record
updateRecord(RESOURCE3, OTHER_HOST, feature.getUuidString(), HOLD_SEC);
// change uuid of another record
- updateRecord(RESOURCE5, feature.getHostName(), OTHER_OWNER, HOLD_SEC);
+ updateRecord(RESOURCE5, feature.getPdpName(), OTHER_OWNER, HOLD_SEC);
// run the checker
assertEquals(3, getRecordCount());
// expire one record
- updateRecord(RESOURCE, feature.getHostName(), feature.getUuidString(), -1);
+ updateRecord(RESOURCE, feature.getPdpName(), feature.getUuidString(), -1);
// arrange to free lock4 while the checker is running
freeLock.set(lock4);
+ " WHERE resourceId=? AND host=? AND owner=?")) {
stmt.setString(1, resourceId);
- stmt.setString(2, feature.getHostName());
+ stmt.setString(2, feature.getPdpName());
stmt.setString(3, uuidString);
try (ResultSet result = stmt.executeQuery()) {
* @throws SQLException if an error occurs accessing the DB
*/
private void insertRecord(String resourceId, String uuidString, int expireOffset) throws SQLException {
- this.insertRecord(resourceId, feature.getHostName(), uuidString, expireOffset);
+ this.insertRecord(resourceId, feature.getPdpName(), uuidString, expireOffset);
}
private void insertRecord(String resourceId, String hostName, String uuidString, int expireOffset)
import org.onap.policy.common.endpoints.listeners.ScoListener;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.utils.coder.StandardCoderObject;
-import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.drools.metrics.Metric;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.policies.DomainMaker;
protected TopicSinkClient client;
@Getter
- protected final String name = NetworkUtil.getHostname();
+ protected final String name = PolicyEngineConstants.PDP_NAME;
protected LifecycleState state = new LifecycleStateTerminated(this);
logger.info("The mandatory Policy Types are {}. Compliance is {}",
mandatoryPolicyTypes, isMandatoryPolicyTypesCompliant());
- stats.setPdpInstanceId(Metric.HOSTNAME);
+ stats.setPdpInstanceId(PolicyEngineConstants.PDP_NAME);
}
@GsonJsonIgnore
assertEquals(fsm.getGroup(), status.getStatistics().getPdpGroupName());
assertEquals(fsm.getSubGroup(), status.getStatistics().getPdpSubGroupName());
- assertEquals(NetworkUtil.getHostname(), status.getStatistics().getPdpInstanceId());
+ assertEquals(PolicyEngineConstants.PDP_NAME, status.getStatistics().getPdpInstanceId());
assertEquals(6, status.getStatistics().getPolicyDeploySuccessCount());
assertEquals(2, status.getStatistics().getPolicyDeployFailCount());
assertEquals(8, status.getStatistics().getPolicyDeployCount());
return serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
}
-}
\ No newline at end of file
+}
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
import org.onap.policy.common.utils.time.TestTimeMulti;
import org.onap.policy.drools.domain.models.controller.ControllerPolicy;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.system.PolicyControllerConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
protected PdpUpdate getPdpUpdate(List<ToscaPolicy> policiesToDeploy, List<ToscaPolicy> policiesToUndeploy) {
PdpUpdate update = new PdpUpdate();
- update.setName(NetworkUtil.getHostname());
+ update.setName(PolicyEngineConstants.PDP_NAME);
update.setPdpGroup("A");
update.setPdpSubgroup("a");
update.setPoliciesToBeDeployed(policiesToDeploy);
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpState;
getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_CONTROLLER_POLICY_NAME);
PdpUpdate update = new PdpUpdate();
- update.setName(NetworkUtil.getHostname());
+ update.setName(PolicyEngineConstants.PDP_NAME);
update.setPdpGroup("W");
update.setPdpSubgroup("w");
update.setPoliciesToBeDeployed(List.of(policyNativeController));
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
// TODO: extract repeated similar assertion blocks into their own helper methods
PdpUpdate update = new PdpUpdate();
- update.setName(NetworkUtil.getHostname());
+ update.setName(PolicyEngineConstants.PDP_NAME);
update.setPdpGroup("W");
update.setPdpSubgroup("w");
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
PdpUpdate update = new PdpUpdate();
- update.setName(NetworkUtil.getHostname());
+ update.setName(PolicyEngineConstants.PDP_NAME);
update.setPdpGroup("Z");
update.setPdpSubgroup("z");
assertNull(fsm.getSubGroup());
PdpUpdate update = new PdpUpdate();
- update.setName(NetworkUtil.getHostname());
+ update.setName(PolicyEngineConstants.PDP_NAME);
update.setPdpGroup("A");
update.setPdpSubgroup("a");
assertEquals("foo", status.getPdpType());
assertEquals(PdpState.TERMINATED, status.getState());
assertEquals(PdpHealthStatus.HEALTHY, status.getHealthy());
- assertEquals(NetworkUtil.getHostname(), status.getName());
+ assertEquals(PolicyEngineConstants.PDP_NAME, status.getName());
assertEquals(fsm.getName(), status.getName());
assertEquals(PdpMessageType.PDP_STATUS, status.getMessageName());
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
@Test
public void testUpdate() {
PdpUpdate update = new PdpUpdate();
- update.setName(NetworkUtil.getHostname());
+ update.setName(PolicyEngineConstants.PDP_NAME);
update.setPdpGroup("A");
update.setPdpSubgroup("a");
update.setPoliciesToBeDeployed(Collections.emptyList());
assertFalse(fsm.statusTask.isCancelled());
assertFalse(fsm.statusTask.isDone());
}
-}
\ No newline at end of file
+}
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.drools.system;
import lombok.Getter;
+import org.onap.policy.common.utils.network.NetworkUtil;
-public class PolicyEngineConstants {
+public final class PolicyEngineConstants {
/**
* Default Telemetry Server Port.
*/
public static final String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY";
+ /**
+ * Unique name of this drools-pdp JVM.
+ */
+ public static final String PDP_NAME = NetworkUtil.genUniqueName("drools");
+
/**
* Policy Engine Manager.
*/