*
* @return String (resourceName)
*/
- public String getPdpdNowActive();
+ String getPdpdNowActive();
/**
* Returns the resourceName (PDP ID) for the Drools-PDP that is
*
* @return String (resourceName)
*/
- public String getPdpdLastActive();
+ String getPdpdLastActive();
/**
* Returns the resourceName associated with this instance of the feature.
*
* @return String (resourceName)
*/
- public String getResourceName();
+ String getResourceName();
}
* problem that has resolved).
* @throws AllSeemsWellException exception
*/
- public void allSeemsWell(@NotNull String key, @NotNull Boolean asw, @NotNull String msg)
+ void allSeemsWell(@NotNull String key, @NotNull Boolean asw, @NotNull String msg)
throws AllSeemsWellException;
/**
*
* @param stateChangeObserver observer
*/
- public void addObserver(Observer stateChangeObserver);
+ void addObserver(Observer stateChangeObserver);
/**
* Returns the X.731 Administrative State for this resource.
*
* @return String (locked, unlocked)
*/
- public String getAdminState();
+ String getAdminState();
/**
* Returns the X.731 Operational State for this resource.
*
* @return String (enabled, disabled)
*/
- public String getOpState();
+ String getOpState();
/**
* Returns the X.731 Availability Status for this resource.
*
* @return String (failed; dependency; dependency,failed)
*/
- public String getAvailStatus();
+ String getAvailStatus();
/**
* Returns the X.731 Standby Status for this resource.
*
* @return String (providingservice, hotstandby or coldstandby)
*/
- public String getStandbyStatus();
+ String getStandbyStatus();
/**
* Returns the X.731 Standby Status for the named resource
* @param resourceName the resource name
* @return String (providingservice, hotstandby or coldstandby)
*/
- public String getStandbyStatus(String resourceName);
+ String getStandbyStatus(String resourceName);
/**
* This method moves the X.731 Operational State for the named resource into a value of disabled
* @param resourceName resource name
* @throws Exception exception
*/
- public void disableFailed(String resourceName) throws Exception;
+ void disableFailed(String resourceName) throws Exception;
/**
* This method moves the X.731 Operational State for this resource into a value of disabled and
*
* @throws Exception exception
*/
- public void disableFailed() throws Exception;
+ void disableFailed() throws Exception;
/**
* This method moves the X.731 Standby Status for this resource from hotstandby to
*
* @throws Exception exception
*/
- public void promote() throws Exception;
+ void promote() throws Exception;
/**
* This method moves the X.731 Standby Status for this resource from providingservice to
*
* @throws Exception exception
*/
- public void demote() throws Exception;
+ void demote() throws Exception;
/**
* Returns the resourceName associated with this instance of the
*
* @return String (resourceName)
*/
- public String getResourceName();
+ String getResourceName();
/**
* This Lockable method will lock the StateManagement object Admin state.
* @return true if successful, false otherwise
*/
@Override
- public boolean lock();
+ boolean lock();
/**
* This Lockable method will unlock the StateManagement object Admin state.
* @return true if successfull, false otherwise
*/
@Override
- public boolean unlock();
+ boolean unlock();
/**
* This Lockable method indicates the Admin state StateManagement object.
* @return true if locked, false otherwise
*/
@Override
- public boolean isLocked();
+ boolean isLocked();
}
public interface DroolsPdp {
- public String getPdpId();
+ String getPdpId();
- public boolean isDesignated();
+ boolean isDesignated();
- public int getPriority();
+ int getPriority();
- public Date getUpdatedDate();
+ Date getUpdatedDate();
- public void setDesignated(boolean isDesignated);
+ void setDesignated(boolean isDesignated);
- public void setUpdatedDate(Date updatedDate);
+ void setUpdatedDate(Date updatedDate);
- public int comparePriority(DroolsPdp other);
+ int comparePriority(DroolsPdp other);
- public int comparePriority(DroolsPdp other,String previousSite);
+ int comparePriority(DroolsPdp other, String previousSite);
- public String getSite();
+ String getSite();
- public void setSite(String site);
+ void setSite(String site);
- public Date getDesignatedDate();
+ Date getDesignatedDate();
- public void setDesignatedDate(Date designatedDate);
+ void setDesignatedDate(Date designatedDate);
}
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//return a list of PDPs, NOT including this PDP
- public Collection<DroolsPdp> getDroolsPdps();
+ Collection<DroolsPdp> getDroolsPdps();
- public void update(DroolsPdp pdp);
+ void update(DroolsPdp pdp);
- //determines if the DroolsPdp parameter is considered "current" or expired
+ //determines if the DroolsPdp parameter is considered "current" or expired
//(has it been too long since the Pdp sent an update)
- public boolean isPdpCurrent(DroolsPdp pdp);
+ boolean isPdpCurrent(DroolsPdp pdp);
// Updates DESIGNATED boolean in PDP record.
- public void setDesignated(DroolsPdp pdp, boolean designated);
+ void setDesignated(DroolsPdp pdp, boolean designated);
// Marks droolspdpentity.DESIGNATED=false, so another PDP-D will go active.
- public void standDownPdp(String pdpId);
+ void standDownPdp(String pdpId);
// This is used in a JUnit test environment to manually
// insert a PDP
- public void insertPdp(DroolsPdp pdp);
+ void insertPdp(DroolsPdp pdp);
// This is used in a JUnit test environment to manually
// delete a PDP
- public void deletePdp(String pdpId);
+ void deletePdp(String pdpId);
// This is used in a JUnit test environment to manually
// clear the droolspdpentity table.
- public void deleteAllPdps();
+ void deleteAllPdps();
// This is used in a JUnit test environment to manually
// get a PDP
- public DroolsPdpEntity getPdp(String pdpId);
+ DroolsPdpEntity getPdp(String pdpId);
// Used by DroolsPdpsElectionHandler to determine if the currently designated
// PDP has failed.
- public boolean hasDesignatedPdpFailed(Collection<DroolsPdp> pdps);
+ boolean hasDesignatedPdpFailed(Collection<DroolsPdp> pdps);
}
*/
private static DroolsPdp myPdp;
- private DesignationWaiter designationWaiter;
- private Timer updateWorker;
- private Timer waitTimer;
private Date waitTimerLastRunDate;
- // The interval between checks of the DesignationWaiter to be sure it is running.
- private int pdpCheckInterval;
-
// The interval between runs of the DesignationWaiter
private int pdpUpdateInterval;
this.pdpsConnector = pdps;
DroolsPdpsElectionHandler.myPdp = myPdp;
this.isDesignated = false;
- pdpCheckInterval = 3000;
+
+ // The interval between checks of the DesignationWaiter to be sure it is running.
+ int pdpCheckInterval = 3000;
try {
pdpCheckInterval = Integer.parseInt(ActiveStandbyProperties.getProperty(
ActiveStandbyProperties.PDP_CHECK_INVERVAL));
} catch (Exception e) {
- logger.error("Could not get pdpCheckInterval property. Using default {}",pdpCheckInterval, e);
+ logger.error("Could not get pdpCheckInterval property. Using default {}", pdpCheckInterval, e);
}
pdpUpdateInterval = 2000;
try {
// Create the timer which will update the updateDate in DroolsPdpEntity table.
// This is the heartbeat
- updateWorker = Factory.getInstance().makeTimer();
+ Timer updateWorker = Factory.getInstance().makeTimer();
// Schedule the TimerUpdateClass to run at 100 ms and run at pdpCheckInterval ms thereafter
// NOTE: The first run of the TimerUpdateClass results in myPdp being added to the
updateWorker.scheduleAtFixedRate(new TimerUpdateClass(), 100, pdpCheckInterval);
// Create the timer which will run the election algorithm
- waitTimer = Factory.getInstance().makeTimer();
+ Timer waitTimer = Factory.getInstance().makeTimer();
// Schedule it to start in startMs ms
// (so it will run after the updateWorker and run at pdpUpdateInterval ms thereafter
long startMs = getDWaiterStartMs();
- designationWaiter = new DesignationWaiter();
+ DesignationWaiter designationWaiter = new DesignationWaiter();
waitTimer.scheduleAtFixedRate(designationWaiter, startMs, pdpUpdateInterval);
waitTimerLastRunDate = new Date(nowMs + startMs);
// get an instance of logger
private static final Logger logger = LoggerFactory.getLogger(PmStandbyStateChangeNotifier.class);
private Timer delayActivateTimer;
- private int pdpUpdateInterval;
private boolean isWaitingForActivation;
private long startTimeWaitingForActivationMs;
private long waitInterval;
*
*/
public PmStandbyStateChangeNotifier() {
- pdpUpdateInterval =
- Integer.parseInt(ActiveStandbyProperties.getProperty(ActiveStandbyProperties.PDP_UPDATE_INTERVAL));
+ int pdpUpdateInterval =
+ Integer.parseInt(ActiveStandbyProperties.getProperty(ActiveStandbyProperties.PDP_UPDATE_INTERVAL));
isWaitingForActivation = false;
startTimeWaitingForActivationMs = currentTime.getMillis();
// delay the activate so the DesignatedWaiter can run twice - give it an extra 2 seconds
@FunctionalInterface
public interface ThreadRunningChecker {
- public void checkThreadStatus();
+ void checkThreadStatus();
}
package org.onap.policy.drools.activestandby;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testAllSeemsWell: After insertion, PDP={} has DESIGNATED={}",
thisPdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == false);
+ assertFalse(droolsPdpEntity.isDesignated());
logger.debug("testAllSeemsWell: Instantiating stateManagement object");
StateManagement sm = new StateManagement(emfXacml, "dummy");
droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testAllSeemsWell: After sm.demote() invoked, DESIGNATED= {} "
+ "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == true);
+ assertTrue(droolsPdpEntity.isDesignated());
String standbyStatus = smf.getStandbyStatus(thisPdpId);
logger.debug("testAllSeemsWell: After demotion, PDP= {} "
+ "has standbyStatus= {}", thisPdpId, standbyStatus);
package org.onap.policy.drools.activestandby;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testColdStandby: After insertion, DESIGNATED= {} "
+ "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == true);
+ assertTrue(droolsPdpEntity.isDesignated());
/*
* When the Standby Status changes (from providingservice) to hotstandby
droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testColdStandby: After lock sm.lock() invoked, "
+ "DESIGNATED= {} for PDP={}", droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == false);
+ assertFalse(droolsPdpEntity.isDesignated());
logger.debug("\n\ntestColdStandby: Exiting\n\n");
}
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testHotStandby1: After insertion, PDP={} has DESIGNATED={}",
thisPdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == false);
+ assertFalse(droolsPdpEntity.isDesignated());
logger.debug("testHotStandby1: Instantiating stateManagement object");
StateManagement sm = new StateManagement(emfx, "dummy");
droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED= {} "
+ "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == true);
+ assertTrue(droolsPdpEntity.isDesignated());
String standbyStatus = smf.getStandbyStatus(thisPdpId);
logger.debug("testHotStandby1: After demotion, PDP= {} "
+ "has standbyStatus= {}", thisPdpId, standbyStatus);
DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
logger.info("testHotStandby2: After insertion, PDP= {}, which is "
+ "not current, has DESIGNATED= {}", activePdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == true);
+ assertTrue(droolsPdpEntity.isDesignated());
/*
* Promote the designated PDP.
droolsPdpEntity = conn.getPdp(thisPdpId);
logger.info("testHotStandby2: After insertion, PDP={} "
+ "has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == false);
+ assertFalse(droolsPdpEntity.isDesignated());
// Now we want to create a StateManagementFeature and initialize it. It will be
logger.info("testHotStandby2: After demoting PDP={}"
+ ", DESIGNATED= {}"
+ " for PDP= {}", activePdpId, droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == true);
+ assertTrue(droolsPdpEntity.isDesignated());
standbyStatus = sm2.getStandbyStatus(thisPdpId);
logger.info("testHotStandby2: After demoting PDP={}"
+ ", PDP={} has standbyStatus= {}",
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testLocking1: After insertion, PDP= {} has DESIGNATED= {}",
thisPdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == true);
+ assertTrue(droolsPdpEntity.isDesignated());
logger.debug("testLocking1: Instantiating stateManagement object");
StateManagement smDummy = new StateManagement(emfx, "dummy");
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testLocking2: After insertion, PDP= {} has DESIGNATED= {}",
thisPdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == true);
+ assertTrue(droolsPdpEntity.isDesignated());
logger.debug("testLocking2: Instantiating stateManagement object and promoting PDP={}", thisPdpId);
StateManagement smDummy = new StateManagement(emfx, "dummy");
droolsPdpEntity = conn.getPdp(standbyPdpId);
logger.debug("testLocking2: After insertion, PDP={} has DESIGNATED= {}",
standbyPdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == false);
+ assertFalse(droolsPdpEntity.isDesignated());
logger.debug("testLocking2: Demoting PDP= {}", standbyPdpId);
final StateManagement sm2 = new StateManagement(emfx, standbyPdpId);
}
logger.debug("testLocking2: Verifying designated status for PDP= {}", standbyPdpId);
- boolean standbyPdpDesignated = conn.getPdp(standbyPdpId).isDesignated();
- assertTrue(standbyPdpDesignated == false);
+ assertFalse(conn.getPdp(standbyPdpId).isDesignated());
logger.debug("\n\ntestLocking2: Exiting\n\n");
}
private static final String TEST_TOPIC = "test-topic";
private static final String TEST_SERVER = "http://test.com";
- /**
- * These are used for sending PDPD configuration notifications to a policy controller.
- */
- private static Properties controllerProps = null;
private static String message = null;
private static PdpdConfiguration pdpdNotification = null;
private static PolicyController policyController = null;
KieUtils.installArtifact(Paths.get(JUNIT_KMODULE_PATH).toFile(), Paths.get(JUNIT_KMODULE_POM_PATH).toFile(),
JUNIT_KJAR_DRL_PATH, Paths.get(JUNIT_KMODULE_DRL_PATH).toFile());
- controllerProps = new Properties();
+ // These properties are used for sending PDPD configuration notifications to a policy controller.
+ Properties controllerProps = new Properties();
controllerProps.put(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
controllerProps.put(DroolsPropertyConstants.RULES_GROUPID, TEST_GROUP_ID);
controllerProps.put(DroolsPropertyConstants.RULES_ARTIFACTID, TEST_ARTIFACT_ID);
controllerProps.put(DroolsPropertyConstants.RULES_VERSION, TEST_VERSION);
- policyController = PolicyEngineConstants.getManager().createPolicyController(TEST_CONTROLLER_NAME,
- controllerProps);
+ policyController =
+ PolicyEngineConstants.getManager().createPolicyController(TEST_CONTROLLER_NAME, controllerProps);
message = "{\"requestID\":\"38adde30-cc22-11e8-a8d5-f2801f1b9fd1\",\"entity\":\"controller\",\"controllers\":"
+ "[{\"name\":\"test-controller\",\"drools\":{\"groupId\":\"org.onap.policy.drools.test\","
*
* @return a report
*/
- public Reports healthCheck();
+ Reports healthCheck();
}
private static final String TEST_TOPIC_A = "org.onap.policy.test-topic-a";
private static final String TEST_TOPIC_B = "org.onap.policy.test-topic-b";
- /**
- * The mock PolicyController to be used for the junits.
- */
- private PolicyController controller;
-
/**
* The mock properties to be used for the junits.
*/
message = new String(Files.readAllBytes(Paths.get("src/test/resources/onset.json")));
props = mockFeatureProperties();
- controller = mock(PolicyController.class);
props.setProperty("dmaap.source.topics", TEST_TOPIC_A);
props.setProperty("dmaap.source.topics." + TEST_TOPIC_A + ".servers", "http://testing123.com/");
props.setProperty("noop.sink.topics", TEST_TOPIC_B);
+ // The mock PolicyController to be used for the junits.
+ PolicyController controller = mock(PolicyController.class);
+
List<TopicSource> topicSources = TopicEndpointManager.getManager().addTopicSources(props);
doReturn(topicSources).when(controller).getTopicSources();
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
/**
* Cancels the scheduled task.
*/
- public void cancel();
+ void cancel();
}
* @return {@code true} if the request was handled by the manager, {@code false} otherwise
* @throws PoolingFeatureException feature exception
*/
- public boolean apply(PoolingManagerImpl mgr) throws PoolingFeatureException;
+ boolean apply(PoolingManagerImpl mgr) throws PoolingFeatureException;
}
/**
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/**
* Gets the properties used to configure the manager.
- *
+ *
* @return pooling properties
*/
- public PoolingProperties getProperties();
+ PoolingProperties getProperties();
/**
* Gets the host id.
- *
+ *
* @return the host id
*/
- public String getHost();
+ String getHost();
/**
* Gets the name of the internal DMaaP topic used by this manager to communicate with
* its other hosts.
- *
+ *
* @return the name of the internal DMaaP topic
*/
- public String getTopic();
+ String getTopic();
/**
* Starts distributing requests according to the given bucket assignments.
- *
+ *
* @param assignments must <i>not</i> be {@code null}
*/
- public void startDistributing(BucketAssignments assignments);
+ void startDistributing(BucketAssignments assignments);
/**
* Gets the current bucket assignments.
- *
+ *
* @return the current bucket assignments, or {@code null} if no assignments have been
* made
*/
- public BucketAssignments getAssignments();
+ BucketAssignments getAssignments();
/**
* Publishes a message to the internal topic on the administrative channel.
- *
+ *
* @param msg message to be published
*/
- public void publishAdmin(Message msg);
+ void publishAdmin(Message msg);
/**
* Publishes a message to the internal topic on a particular channel.
- *
+ *
* @param channel channel on which the message should be published
* @param msg message to be published
*/
- public void publish(String channel, Message msg);
+ void publish(String channel, Message msg);
/**
* Handles a {@link Forward} event that was received from the internal topic.
- *
+ *
* @param event event
*/
- public void handle(Forward event);
+ void handle(Forward event);
/**
* Schedules a timer to fire after a delay.
- *
+ *
* @param delayMs delay, in milliseconds
* @param task task
* @return a new scheduled task
*/
- public CancellableScheduledTask schedule(long delayMs, StateTimerTask task);
+ CancellableScheduledTask schedule(long delayMs, StateTimerTask task);
/**
* Schedules a timer to fire repeatedly.
- *
+ *
* @param initialDelayMs initial delay, in milliseconds
* @param delayMs delay, in milliseconds
* @param task task
* @return a new scheduled task
*/
- public CancellableScheduledTask scheduleWithFixedDelay(long initialDelayMs, long delayMs, StateTimerTask task);
+ CancellableScheduledTask scheduleWithFixedDelay(long initialDelayMs, long delayMs, StateTimerTask task);
/**
* Transitions to the "start" state.
- *
+ *
* @return the new state
*/
- public State goStart();
+ State goStart();
/**
* Transitions to the "query" state.
- *
+ *
* @return the new state
*/
- public State goQuery();
+ State goQuery();
/**
* Transitions to the "active" state.
- *
+ *
* @return the new state
*/
- public State goActive();
+ State goActive();
/**
* Transitions to the "inactive" state.
- *
+ *
* @return the new state
*/
- public State goInactive();
+ State goInactive();
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/**
* Extracts an object contained within another object.
- *
+ *
* @param object object from which to extract the contained object
* @return the extracted value, or {@code null} if it cannot be extracted
*/
- public Object extract(Object object);
+ Object extract(Object object);
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/**
* Fires the timer.
- *
+ *
* @return the new state, or {@code null} if the state is unchanged
*/
- public State fire();
+ State fire();
}
@FunctionalInterface
private static interface VoidFunction {
- public void apply();
+ void apply();
}
}
*/
private Queue<ScheduledFuture<?>> futures;
- private Properties plainProps;
private PoolingProperties poolProps;
private ListeningController controller;
private ClassExtractors extractors;
/**
* Setup.
- *
+ *
* @throws Exception throws exception
*/
@Before
public void setUp() throws Exception {
- plainProps = new Properties();
+ Properties plainProps = new Properties();
poolProps = mock(PoolingProperties.class);
when(poolProps.getSource()).thenReturn(plainProps);
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
private static interface WithString {
- public String getStrValue();
+ String getStrValue();
}
/**
/**
* Verifies that fields are set as expected by {@link #makeValidMessage()}.
- *
+ *
* @param msg message whose fields are to be validated
*/
public void testValidFields(T msg) {
/**
* Function that updates a message.
- *
+ *
* @param <T> type of Message the function updates
*/
@FunctionalInterface
/**
* Updates a message.
- *
+ *
* @param msg message to be updated
*/
- public void update(T msg);
+ void update(T msg);
}
/**
* Function that updates a single field within a message.
- *
+ *
* @param <T> type of Message the function updates
*/
@FunctionalInterface
/**
* Updates a field within a message.
- *
+ *
* @param msg message to be updated
* @param newValue new field value
*/
- public void update(T msg, String newValue);
+ void update(T msg, String newValue);
}
}
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
public interface DroolsSession {
- public String getSessionName();
-
- public void setSessionName(String sessionName);
-
- public long getSessionId();
-
- public void setSessionId(long sessionId);
-
- public Date getCreatedDate();
-
- public void setCreatedDate(Date createdDate);
-
- public Date getUpdatedDate();
-
- public void setUpdatedDate(Date updatedDate);
+ String getSessionName();
+
+ void setSessionName(String sessionName);
+
+ long getSessionId();
+
+ void setSessionId(long sessionId);
+
+ Date getCreatedDate();
+
+ void setCreatedDate(Date createdDate);
+
+ Date getUpdatedDate();
+
+ void setUpdatedDate(Date updatedDate);
}
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* @param sessName session name
* @return a session, or {@code null} if it is not found
*/
- public DroolsSession get(String sessName);
+ DroolsSession get(String sessName);
/**
* Replaces a session, adding it if it does not exist.
* @param sess session to be replaced
*/
- public void replace(DroolsSession sess);
+ void replace(DroolsSession sess);
}
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
private static final Logger logger = LoggerFactory.getLogger(PersistenceFeatureTest.class);
- private EntityManagerFactory emf;
-
/**
* Opens the EMF, which generates the schema, as a side-effect.
*
propMap.put("javax.persistence.jdbc.driver", "org.h2.Driver");
propMap.put("javax.persistence.jdbc.url", "jdbc:h2:mem:JpaDroolsSessionConnectorTest");
- emf = Persistence.createEntityManagerFactory("schemaDroolsPU", propMap);
-
- emf.close();
+ Persistence.createEntityManagerFactory("schemaDroolsPU", propMap).close();
}
/**
private KieSessionConfiguration kiecfg;
private KieBase kiebase;
private KieStoreServices kiestore;
- private KieContainer kiecont;
private TransactionManager transmgr;
private UserTransaction usertrans;
private TransactionSynchronizationRegistry transreg;
kiecfg = mock(KieSessionConfiguration.class);
kiebase = mock(KieBase.class);
kiestore = mock(KieStoreServices.class);
- kiecont = mock(KieContainer.class);
transmgr = mock(TransactionManager.class);
usertrans = mock(UserTransaction.class);
transreg = mock(TransactionSynchronizationRegistry.class);
emfCount = 0;
jpaCount = 0;
propName = null;
-
+
feat = new PersistenceFeatureImpl();
props.putAll(stdprops);
when(kiesvc.getStoreServices()).thenReturn(kiestore);
when(kiesvc.newKieSessionConfiguration()).thenReturn(kiecfg);
+ KieContainer kiecont = mock(KieContainer.class);
when(polcont.getKieContainer()).thenReturn(kiecont);
when(polsess.getPolicyContainer()).thenReturn(polcont);
*
* @param controller policy controller
*/
- public void register(PolicyController controller);
+ void register(PolicyController controller);
/**
* unregisters a controller for monitoring test transactions.
*
* @param controller policy controller
*/
- public void unregister(PolicyController controller);
+ void unregister(PolicyController controller);
}
/**
* Start the thread or threads that do the 'KieSession' processing.
*/
- public void start();
+ void start();
/**
* Stop the thread or threads that do the 'KieSession' processing.
*/
- public void stop();
+ void stop();
/**
* This method is called to notify the running session that
* 'KieContainer.updateToVersion(...)' has been called (meaning the
* full name of this session has changed).
*/
- public default void updated() {
+ default void updated() {
}
}
* @param args standard 'main' arguments, which are currently ignored
* @param configDir the relative directory containing configuration files
*/
- public default void globalInit(String[] args, String configDir) {}
+ default void globalInit(String[] args, String configDir) {}
/**
* This method is used to create a 'KieSession' as part of a
* (this depends on the capabilities and state of the object implementing
* this interface)
*/
- public default KieSession activatePolicySession(PolicyContainer policyContainer, String name, String kieBaseName) {
+ default KieSession activatePolicySession(PolicyContainer policyContainer, String name, String kieBaseName) {
return null;
}
*
* @param policySession the new 'PolicySession' instance
*/
- public default void newPolicySession(PolicySession policySession) {}
+ default void newPolicySession(PolicySession policySession) {}
/**
* This method is called to select the 'ThreadModel' instance associated
* with a 'PolicySession' instance.
*/
- public default PolicySession.ThreadModel selectThreadModel(PolicySession session) {
+ default PolicySession.ThreadModel selectThreadModel(PolicySession session) {
return null;
}
* @return 'true' if this feature is handling the operation,
* and 'false' if not.
*/
- public default boolean insertDrools(PolicySession session, Object object) {
+ default boolean insertDrools(PolicySession session, Object object) {
return false;
}
* @param policySession the 'PolicySession' object that wrapped the
* 'KieSession'
*/
- public default void disposeKieSession(PolicySession policySession) {}
+ default void disposeKieSession(PolicySession policySession) {}
/**
* This method is called after 'KieSession.destroy()' is called.
* @param policySession the 'PolicySession' object that wrapped the
* 'KieSession'
*/
- public default void destroyKieSession(PolicySession policySession) {}
+ default void destroyKieSession(PolicySession policySession) {}
}
* ============LICENSE_START=======================================================
* policy-core
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
public interface PdpJmxMBean {
- public long getRulesFired();
-
- public long getUpdates();
+ long getRulesFired();
+
+ long getUpdates();
}
* {@code false} otherwise
* @return a new lock
*/
- public Lock createLock(String resourceId, String ownerKey, int holdSec, LockCallback callback,
- boolean waitForLock);
+ Lock createLock(String resourceId, String ownerKey, int holdSec, LockCallback callback,
+ boolean waitForLock);
}
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
*/
public class KieUtils {
- private static final Logger logger = LoggerFactory.getLogger(KieUtils.class);
-
private KieUtils() {
// Utility class
}
* @param modelHash the hash for the model
* @return true it owns it
*/
- boolean ownsCoder(Class<? extends Object> coderClass, int modelHash);
+ boolean ownsCoder(Class<?> coderClass, int modelHash);
/**
* fetches a class from the model.
* @throws IllegalArgumentException with invalid parameters
* @throws LinkageError Failure to link rules and models in Drools Libraries
*/
- public DroolsController build(Properties properties, List<? extends TopicSource> eventSources,
- List<? extends TopicSink> eventSinks) throws LinkageError;
+ DroolsController build(Properties properties, List<? extends TopicSource> eventSources,
+ List<? extends TopicSink> eventSinks) throws LinkageError;
/**
* Explicit construction of a Drools Controller.
* @throws IllegalArgumentException with invalid parameters
* @throws LinkageError Failure to link rules and models in Drools Libraries
*/
- public DroolsController build(String groupId, String artifactId, String version,
- List<TopicCoderFilterConfiguration> decoderConfigurations,
- List<TopicCoderFilterConfiguration> encoderConfigurations) throws LinkageError;
+ DroolsController build(String groupId, String artifactId, String version,
+ List<TopicCoderFilterConfiguration> decoderConfigurations,
+ List<TopicCoderFilterConfiguration> encoderConfigurations) throws LinkageError;
/**
* Releases the Drools Controller from operation.
*
* @param controller the Drools Controller to shut down
*/
- public void shutdown(DroolsController controller);
+ void shutdown(DroolsController controller);
/**
* Disables all Drools Controllers from operation.
*/
- public void shutdown();
+ void shutdown();
/**
* Destroys and releases resources for a Drools Controller.
*
* @param controller the Drools Controller to destroy
*/
- public void destroy(DroolsController controller);
+ void destroy(DroolsController controller);
/**
* Destroys all Drools Controllers.
*/
- public void destroy();
+ void destroy();
/**
* Gets the Drools Controller associated with the maven group and artifact id.
* @return the Drools Controller
* @throws IllegalArgumentException with invalid parameters
*/
- public DroolsController get(String groupId, String artifactId, String version);
+ DroolsController get(String groupId, String artifactId, String version);
/**
* returns the current inventory of Drools Controllers.
*
* @return a list of Drools Controllers
*/
- public List<DroolsController> inventory();
+ List<DroolsController> inventory();
}
@Override
- public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
+ public boolean ownsCoder(Class<?> coderClass, int modelHash) {
if (!isClass(coderClass.getName())) {
logger.error("{}{} cannot be retrieved. ", this, coderClass.getName());
return false;
}
@Override
- public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
+ public boolean ownsCoder(Class<?> coderClass, int modelHash) {
throw new IllegalStateException(makeInvokeMsg());
}
* @param eventProtocolParams parameter object for event protocol
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public void addDecoder(EventProtocolParams eventProtocolParams);
+ void addDecoder(EventProtocolParams eventProtocolParams);
/**
* removes all decoders associated with the controller id.
* @param topic the topic
* @throws IllegalArgumentException if invalid arguments have been provided
*/
- public void removeDecoders(String groupId, String artifactId, String topic);
+ void removeDecoders(String groupId, String artifactId, String topic);
/**
* Given a controller id and a topic, it gives back its filters.
* @return list of decoders
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic);
+ List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic);
/**
* gets all decoders associated with the group and artifact ids.
* @param artifactId of the controller
* @throws IllegalArgumentException if invalid arguments have been provided
*/
- public List<CoderFilters> getDecoderFilters(String groupId, String artifactId);
+ List<CoderFilters> getDecoderFilters(String groupId, String artifactId);
/**
* Given a controller id, a topic, and a classname, it gives back the classes that implements the decoding.
* @return list of decoders
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public CoderFilters getDecoderFilters(
- String groupId, String artifactId, String topic, String classname);
+ CoderFilters getDecoderFilters(
+ String groupId, String artifactId, String topic, String classname);
/**
* Given a controller id and a topic, it gives back the decoding configuration.
* @return decoding toolset
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic);
+ ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic);
/**
* Given a controller id and a topic, it gives back all the decoding configurations.
* @return decoding toolset
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId);
+ List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId);
/**
* Given a controller id and a topic, it gives back the classes that implements the encoding.
* @return list of decoders
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic);
+ List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic);
/**
* gets all encoders associated with the group and artifact ids.
* @return List of filters
* @throws IllegalArgumentException if invalid arguments have been provided
*/
- public List<CoderFilters> getEncoderFilters(String groupId, String artifactId);
+ List<CoderFilters> getEncoderFilters(String groupId, String artifactId);
/**
* get encoder based on coordinates and classname.
* @return CoderFilters decoders
* @throws IllegalArgumentException invalid arguments passed in
*/
- public CoderFilters getEncoderFilters(
- String groupId, String artifactId, String topic, String classname);
+ CoderFilters getEncoderFilters(
+ String groupId, String artifactId, String topic, String classname);
/**
* is there a decoder supported for the controller id and topic.
* @param topic protocol
* @return true if supported
*/
- public boolean isDecodingSupported(String groupId, String artifactId, String topic);
+ boolean isDecodingSupported(String groupId, String artifactId, String topic);
/**
* Adds a Encoder class to encode the protocol over this topic.
* @param eventProtocolParams parameter object for event protocol
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public void addEncoder(EventProtocolParams eventProtocolParams);
+ void addEncoder(EventProtocolParams eventProtocolParams);
/**
* is there an encoder supported for the controller id and topic.
* @param topic protocol
* @return true if supported
*/
- public boolean isEncodingSupported(String groupId, String artifactId, String topic);
+ boolean isEncodingSupported(String groupId, String artifactId, String topic);
/**
* get encoder based on topic and encoded class.
* @return list of filters
* @throws IllegalArgumentException invalid arguments passed in
*/
- public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass);
+ List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass);
/**
* gets the identifier of the creator of the encoder.
* @return a drools controller
* @throws IllegalArgumentException invalid arguments passed in
*/
- public DroolsController getDroolsController(String topic, Object encodedClass);
+ DroolsController getDroolsController(String topic, Object encodedClass);
/**
* gets the identifier of the creator of the encoder.
* @return list of drools controllers
* @throws IllegalArgumentException invalid arguments passed in
*/
- public List<DroolsController> getDroolsControllers(String topic, Object encodedClass);
+ List<DroolsController> getDroolsControllers(String topic, Object encodedClass);
/**
* decode topic's stringified event (json) to corresponding Event Object.
* @throws UnsupportedOperationException if the operation is not supported
* @throws IllegalStateException if the system is in an illegal state
*/
- public Object decode(String groupId, String artifactId, String topic, String json);
+ Object decode(String groupId, String artifactId, String topic, String json);
/**
* encodes topic's stringified event (json) to corresponding Event Object.
* @return encoded string
* @throws IllegalArgumentException invalid arguments passed in
*/
- public String encode(String groupId, String artifactId, String topic, Object event);
+ String encode(String groupId, String artifactId, String topic, Object event);
/**
* encodes topic's stringified event (json) to corresponding Event Object.
* @throws IllegalArgumentException invalid arguments passed in
* @throws UnsupportedOperationException operation cannot be performed
*/
- public String encode(String topic, Object event);
+ String encode(String topic, Object event);
/**
* encodes topic's stringified event (json) to corresponding Event Object.
* @throws IllegalArgumentException invalid arguments passed in
* @throws UnsupportedOperationException operation cannot be performed
*/
- public String encode(String topic, Object event, DroolsController droolsController);
+ String encode(String topic, Object event, DroolsController droolsController);
}
* {@code false} otherwise
* @return a new lock
*/
- public Lock createLock(String resourceId, String ownerKey, int holdSec, LockCallback callback,
- boolean waitForLock);
+ Lock createLock(String resourceId, String ownerKey, int holdSec, LockCallback callback,
+ boolean waitForLock);
/**
* Invoked when the host goes into the active state.
defaultConfig.put(
PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + TELEMETRY_SERVER_DEFAULT_NAME
+ PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
- "" + Integer.toString(TELEMETRY_SERVER_DEFAULT_PORT));
+ "" + TELEMETRY_SERVER_DEFAULT_PORT);
defaultConfig.put(
PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + TELEMETRY_SERVER_DEFAULT_NAME
+ PolicyEndPointProperties.PROPERTY_HTTP_REST_PACKAGES_SUFFIX,
@FunctionalInterface
private static interface PredicateWithEx<T> {
- public boolean test(T value) throws InterruptedException;
+ boolean test(T value) throws InterruptedException;
}
@Override
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.builder.ReleaseId;
public void testGsonToolset(JsonProtocolFilter protocolFilter) {
GsonProtocolCoderToolset gsonToolset = new GsonProtocolCoderToolset(
EventProtocolParams.builder().topic(JUNIT_PROTOCOL_CODER_TOPIC)
- .groupId(this.releaseId.getGroupId())
- .artifactId(this.releaseId.getArtifactId())
+ .groupId(releaseId.getGroupId())
+ .artifactId(releaseId.getArtifactId())
.eventClass(Triple.class.getName())
.protocolFilter(protocolFilter)
.customGsonCoder(null)
private void validateInitialization(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset) {
Assert.assertTrue(CONTROLLER_ID.equals(coderToolset.getControllerId()));
- Assert.assertTrue(this.releaseId.getGroupId().equals(coderToolset.getGroupId()));
- Assert.assertTrue(this.releaseId.getArtifactId().equals(coderToolset.getArtifactId()));
+ Assert.assertTrue(releaseId.getGroupId().equals(coderToolset.getGroupId()));
+ Assert.assertTrue(releaseId.getArtifactId().equals(coderToolset.getArtifactId()));
Assert.assertNull(coderToolset.getCustomCoder());
Assert.assertTrue(coderToolset.getCoders().size() == 1);