aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-21 13:19:31 -0400
committerJim Hahn <jrh3@att.com>2019-06-21 17:19:09 -0400
commitd6aa3faba917b45e01f5001fe3a768feddedc798 (patch)
tree077a51a89320f558f08b2d0512f6cf63450ae90d /integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
parentc9392e1a126de54ae8a0e1f3316729e878115300 (diff)
Fix sonar issues in integrity monitor
Used Eclipse Refactor->Extract Method to reduce cyclomatic complexity. Flattened nested FpManager class into IntegrityMonitor class. Changed some strings to StringBuilder, where lots of concatenation was being done. Simplified some things by eliminating some try/catch blocks where an exception can't actually (except may an out-of-memory exception). Also addressed some sonar issues in the tests (e.g., use "<>" where appropriate). Eliminated some assertException methods, replacing them with assertj methods. Did not attempt to increase junit coverage. Change-Id: I311acaffcd87f0cbbf382c06c7fa26177007abd5 Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java')
-rw-r--r--integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java55
1 files changed, 27 insertions, 28 deletions
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
index 35b33be8..c5f9d7bc 100644
--- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Integrity Monitor
* ================================================================================
- * 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.
@@ -83,19 +83,19 @@ public class StateManagement extends Observable {
/*
* Guarantees single-threadedness of all actions. Only one action can execute at a time. That
* avoids race conditions between actions being called from different places.
- *
+ *
* Some actions can take significant time to complete and, if another conflicting action is
* called during its execution, it could put the system in an inconsistent state. This very
* thing happened when demote was called and the active/standby algorithm, seeing the state
* attempted to promote the PDP-D.
- *
+ *
*/
private static final Object SYNCLOCK = new Object();
private static final Object FLUSHLOCK = new Object();
/**
* StateManagement constructor.
- *
+ *
* @param entityManagerFactory the entity manager factory
* @param resourceName the resource name
* @throws StateManagementException if an error occurs
@@ -189,7 +189,7 @@ public class StateManagement extends Observable {
/**
* lock() changes the administrative state to locked.
- *
+ *
* @throws StateManagementException if an error occurs
*/
public void lock() throws StateManagementException {
@@ -232,7 +232,7 @@ public class StateManagement extends Observable {
/**
* unlock() changes the administrative state to unlocked.
- *
+ *
* @throws StateManagementException if an error occurs
*/
public void unlock() throws StateManagementException {
@@ -276,7 +276,7 @@ public class StateManagement extends Observable {
/**
* enableNotFailed() removes the "failed" availability status and changes the operational state
* to enabled if no dependency is also failed.
- *
+ *
* @throws StateManagementException if an error occurs
*/
public void enableNotFailed() throws StateManagementException {
@@ -323,7 +323,7 @@ public class StateManagement extends Observable {
/**
* disableFailed() changes the operational state to disabled and adds availability status of
* "failed".
- *
+ *
* @throws StateManagementException if an error occurs
*/
public void disableFailed() throws StateManagementException {
@@ -369,7 +369,7 @@ public class StateManagement extends Observable {
/**
* This version of disableFailed is to be used to manipulate the state of a remote resource in
* the event that remote resource has failed but its state is still showing that it is viable.
- *
+ *
* @throws StateManagementException if an error occurs
*/
public void disableFailed(final String otherResourceName) throws StateManagementException {
@@ -421,7 +421,7 @@ public class StateManagement extends Observable {
/**
* disableDependency() changes operational state to disabled and adds availability status of
* "dependency".
- *
+ *
* @throws StateManagementException if an error occurs
*/
public void disableDependency() throws StateManagementException {
@@ -467,7 +467,7 @@ public class StateManagement extends Observable {
/**
* enableNoDependency() removes the availability status of "dependency " and will change the
* operational state to enabled if not otherwise failed.
- *
+ *
* @throws StateManagementException if an error occurs
*/
public void enableNoDependency() throws StateManagementException {
@@ -512,11 +512,10 @@ public class StateManagement extends Observable {
/**
* promote() changes the standby status to providingservice if not otherwise failed.
- *
- * @throws StandbyStatusException if the status fails to change
- * @throws StateManagementException if an error occurs when promoting the status
+ *
+ * @throws IntegrityMonitorException if the status fails to change
*/
- public void promote() throws StandbyStatusException, StateManagementException {
+ public void promote() throws IntegrityMonitorException {
synchronized (SYNCLOCK) {
if (logger.isDebugEnabled()) {
logger.debug("\nStateManagement: SYNCLOCK promote() operation for resourceName = {}\n",
@@ -564,15 +563,15 @@ public class StateManagement extends Observable {
/**
* demote() changes standbystatus to hotstandby or, if failed, coldstandby.
- *
+ *
* @throws StateManagementException if an error occurs
*/
public void demote() throws StateManagementException {
synchronized (SYNCLOCK) {
if (logger.isDebugEnabled()) {
- logger.debug("\nStateManagement: SYNCLOCK demote() operation for resourceName = {}\n",
+ logger.debug("\nStateManagement: SYNCLOCK demote() operation for resourceName = {}\n",
this.resourceName);
- logger.debug("StateManagement: demote() operation started, resourceName = {}",
+ logger.debug("StateManagement: demote() operation started, resourceName = {}",
this.resourceName);
}
final EntityManager em = emf.createEntityManager();
@@ -611,7 +610,7 @@ public class StateManagement extends Observable {
* the remote resource has failed is such a way that it cannot update its own states. In
* particular this is observed by PDP-D DroolsPdpsElectionHandler when it is trying to determine
* which PDP-D should be designated as the lead.
- *
+ *
* @param otherResourceName the resouce name
* @throws StateManagementException if an error occurs
*/
@@ -660,7 +659,7 @@ public class StateManagement extends Observable {
/**
* Get the administration state.
- *
+ *
* @return the administration state
*/
public String getAdminState() {
@@ -696,7 +695,7 @@ public class StateManagement extends Observable {
/**
* Get the operational state.
- *
+ *
* @return the operational state
*/
public String getOpState() {
@@ -732,7 +731,7 @@ public class StateManagement extends Observable {
/**
* Get the availability status.
- *
+ *
* @return the availability status
*/
public String getAvailStatus() {
@@ -768,7 +767,7 @@ public class StateManagement extends Observable {
/**
* Get the standy status.
- *
+ *
* @return the standby status
*/
public String getStandbyStatus() {
@@ -804,7 +803,7 @@ public class StateManagement extends Observable {
/**
* Get the standbystatus of a particular resource.
- *
+ *
* @param otherResourceName the resource
* @return the standby status
*/
@@ -855,7 +854,7 @@ public class StateManagement extends Observable {
/**
* Find a StateManagementEntity.
- *
+ *
* @param em the entity manager
* @param otherResourceName the resource name
* @return the StateManagementEntity
@@ -944,7 +943,7 @@ public class StateManagement extends Observable {
/**
* Create an instance.
- *
+ *
* @param em the entity manager
*/
public MyTransaction(final EntityManager em) {