aboutsummaryrefslogtreecommitdiffstats
path: root/site-manager/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'site-manager/src/main')
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/Main.java46
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessService.java17
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessServiceImpl.java26
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/CommandLineHelper.java6
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ErrorMessages.java2
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ExtraCommandLineArgument.java6
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/JmxOpProcessor.java5
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/PersistenceUnitPropertiesProvider.java41
8 files changed, 101 insertions, 48 deletions
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/Main.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/Main.java
index 780e14f0..a415c229 100644
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/Main.java
+++ b/site-manager/src/main/java/org/onap/policy/common/sitemanager/Main.java
@@ -32,15 +32,19 @@ package org.onap.policy.common.sitemanager;
import static org.onap.policy.common.sitemanager.utils.Constants.OPERATIONAL_PERSISTENCE_UNIT;
import static org.onap.policy.common.sitemanager.utils.Constants.SITE_MANAGER_PROPERTIES_PROPERTY_NAME;
import static org.onap.policy.common.sitemanager.utils.ErrorMessages.HELP_STRING;
+import static org.onap.policy.common.sitemanager.utils.ErrorMessages.NO_MATCHING_ENTRIES;
import static org.onap.policy.common.sitemanager.utils.ExtraCommandLineArgument.LOCK;
import static org.onap.policy.common.sitemanager.utils.ExtraCommandLineArgument.SET_ADMIN_STATE;
import static org.onap.policy.common.sitemanager.utils.ExtraCommandLineArgument.UNLOCK;
import static org.onap.policy.common.sitemanager.utils.JmxOpProcessor.jmxOp;
+
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.TreeSet;
+
import org.onap.policy.common.im.jpa.ResourceRegistrationEntity;
import org.onap.policy.common.im.jpa.StateManagementEntity;
import org.onap.policy.common.sitemanager.data.service.DatabaseAccessService;
@@ -76,7 +80,7 @@ public class Main {
}
/**
- * This is the main entry point
+ * This is the main entry point.
*
* @param args these are command-line arguments to 'siteManager'
*/
@@ -85,6 +89,12 @@ public class Main {
new Main().process(args, printable);
}
+ /**
+ * Process command-line arguments.
+ *
+ * @param args args these are command-line arguments to 'siteManager'
+ * @param printable {@link Printable} callback to print statement
+ */
public void process(final String[] args, final Printable printable) {
try {
final CommandLineHelper commandLineHelper = new CommandLineHelper(args, printable);
@@ -149,7 +159,7 @@ public class Main {
}
if (resourceRegistrationTable.isEmpty()) {
- final String message = arg0 + ": No matching entries";
+ final String message = arg0 + NO_MATCHING_ENTRIES;
printable.println(message);
throw new NoMatchingEntryFoundException(message);
}
@@ -179,6 +189,8 @@ public class Main {
accessService.refreshEntity(stateManagementTable.get(r.getResourceName()));
}
}
+ } catch (final NoMatchingEntryFoundException exception) {
+ throw exception;
} catch (final Exception exception) {
printable.println(exception.getMessage());
}
@@ -188,11 +200,13 @@ public class Main {
}
/**
- * Compare two strings, either of which may be null
+ * Compare two strings, either of which may be null.
*
* @param first the first string
* @param second the second string
- * @return a negative value if s1<s2, 0 if they are equal, and positive if s1>s2
+ *
+ * @return a negative value if s1 is less then s2, 0 if they are equal, and positive if s1 is
+ * greater then s2
*/
private static int stringCompare(final String first, final String second) {
if (first == null ^ second == null) {
@@ -212,11 +226,12 @@ public class Main {
*
* @param current this is an array of length 7, containing the current maximum lengths of each
* column in the tabular dump
- * @param s this is an array of length 7, containing the current String entry for each column
+ * @param values this is an array of length 7, containing the current String entry for each
+ * column
*/
- private static void updateLengths(final int[] current, final String[] s) {
- for (int i = 0; i < 7; i += 1) {
- final String str = s[i];
+ private static void updateLengths(final int[] current, final String[] values) {
+ for (int i = 0; i < 7; i++) {
+ final String str = values[i];
final int newLength = (str == null ? 4 : str.length());
if (current[i] < newLength) {
// this column needs to be expanded
@@ -226,28 +241,29 @@ public class Main {
}
/**
- * Ordered display -- dump out all of the entries, in
+ * Ordered display -- dump out all of the entries in log.
*/
static void display() {
- final TreeSet<String[]> treeset = new TreeSet<>((final String[] r1, final String[] r2) -> {
+ final Set<String[]> treeset = new TreeSet<>((final String[] r1, final String[] r2) -> {
int rval = 0;
// the first 3 columns are 'Site', 'NodeType', and 'ResourceName',
// and are used to sort the entries
for (int i = 0; i < 3; i += 1) {
- if ((rval = stringCompare(r1[i], r2[i])) != 0)
+ if ((rval = stringCompare(r1[i], r2[i])) != 0) {
break;
+ }
}
return (rval);
});
final String[] labels = new String[] {"Site", "NodeType", "ResourceName", "AdminState", "OpState",
- "AvailStatus", "StandbyStatus"};
+ "AvailStatus", "StandbyStatus"};
final String[] underlines = new String[] {"----", "--------", "------------", "----------", "-------",
- "-----------", "-------------"};
+ "-----------", "-------------"};
// each column needs to be at least wide enough to fit the column label
- final int[] lengths = new int[7];
+ final int[] lengths = new int[labels.length];
updateLengths(lengths, labels);
// Go through the 'resourceRegistrationTable', and generate the
@@ -259,7 +275,7 @@ public class Main {
// these are the entries to be displayed for this row
final String[] values = new String[] {r.getSite(), r.getNodeType(), r.getResourceName(), s.getAdminState(),
- s.getOpState(), s.getAvailStatus(), s.getStandbyStatus()};
+ s.getOpState(), s.getAvailStatus(), s.getStandbyStatus()};
treeset.add(values);
updateLengths(lengths, values);
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessService.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessService.java
index 513ba174..4b29359a 100644
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessService.java
+++ b/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessService.java
@@ -32,22 +32,23 @@ public interface DatabaseAccessService extends AutoCloseable {
<T> List<T> execute(final Class<T> clazz, final String query);
/**
- * Get {@link StateManagementEntity} entities from database
+ * Get {@link StateManagementEntity} entities from database.
*
- * @param rOption resource name (optional)
- * @param sOption site name (optional)
+ * @param resourceOption resource name (optional)
+ * @param stateOption site name (optional)
* @return list of {@link StateManagementEntity} entities found
*/
- List<StateManagementEntity> getStateManagementEntities(final String rOption, final String sOption);
+ List<StateManagementEntity> getStateManagementEntities(final String resourceOption, final String stateOption);
/**
- * Get {@link ResourceRegistrationEntity} entities from database
+ * Get {@link ResourceRegistrationEntity} entities from database.
*
- * @param rOption resource name (optional)
- * @param sOption site name (optional)
+ * @param resourceOption resource name (optional)
+ * @param stateOption site name (optional)
* @return list of {@link ResourceRegistrationEntity} entities found
*/
- List<ResourceRegistrationEntity> getResourceRegistrationEntities(final String rOption, final String sOption);
+ List<ResourceRegistrationEntity> getResourceRegistrationEntities(final String resourceOption,
+ final String stateOption);
<T> void persist(final Collection<T> entities);
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessServiceImpl.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessServiceImpl.java
index ee98fc29..769b164b 100644
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessServiceImpl.java
+++ b/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessServiceImpl.java
@@ -27,13 +27,16 @@ import static org.onap.policy.common.sitemanager.utils.Constants.STATE_MANAGEMEN
import static org.onap.policy.common.sitemanager.utils.Constants.WHERE_R_RESOURCE_NAME;
import static org.onap.policy.common.sitemanager.utils.Constants.WHERE_R_SITE_NAME;
import static org.onap.policy.common.sitemanager.utils.Constants.WHERE_S_RESOURCE_NAME;
+
import java.util.Collection;
import java.util.List;
import java.util.Properties;
+
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
+
import org.onap.policy.common.im.jpa.ResourceRegistrationEntity;
import org.onap.policy.common.im.jpa.StateManagementEntity;
import org.onap.policy.common.utils.jpa.EntityTransCloser;
@@ -47,7 +50,7 @@ public class DatabaseAccessServiceImpl implements DatabaseAccessService {
this.entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnitName, properties);
this.entityManager = entityManagerFactory.createEntityManager();
}
-
+
public DatabaseAccessServiceImpl(final EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
this.entityManager = entityManagerFactory.createEntityManager();
@@ -69,11 +72,12 @@ public class DatabaseAccessServiceImpl implements DatabaseAccessService {
}
@Override
- public List<StateManagementEntity> getStateManagementEntities(final String rOption, final String sOption) {
- if (rOption != null) {
+ public List<StateManagementEntity> getStateManagementEntities(final String resourceOption,
+ final String stateOption) {
+ if (resourceOption != null) {
final String query = STATE_MANAGEMENT_QUERY + WHERE_S_RESOURCE_NAME + RESOURCE_NAME;
- return execute(StateManagementEntity.class, query, RESOURCE_NAME, rOption);
- } else if (sOption != null) {
+ return execute(StateManagementEntity.class, query, RESOURCE_NAME, resourceOption);
+ } else if (stateOption != null) {
return execute(StateManagementEntity.class, STATE_MANAGEMENT_QUERY);
}
return execute(StateManagementEntity.class, STATE_MANAGEMENT_QUERY);
@@ -81,14 +85,14 @@ public class DatabaseAccessServiceImpl implements DatabaseAccessService {
}
@Override
- public List<ResourceRegistrationEntity> getResourceRegistrationEntities(final String rOption,
- final String sOption) {
- if (rOption != null) {
+ public List<ResourceRegistrationEntity> getResourceRegistrationEntities(final String resourceOption,
+ final String stateOption) {
+ if (resourceOption != null) {
final String query = RESOURCE_REGISTRATION_QUERY + WHERE_R_RESOURCE_NAME + RESOURCE_NAME;
- return execute(ResourceRegistrationEntity.class, query, RESOURCE_NAME, rOption);
- } else if (sOption != null) {
+ return execute(ResourceRegistrationEntity.class, query, RESOURCE_NAME, resourceOption);
+ } else if (stateOption != null) {
final String query = RESOURCE_REGISTRATION_QUERY + WHERE_R_SITE_NAME + SITE_NAME;
- return execute(ResourceRegistrationEntity.class, query, SITE_NAME, sOption);
+ return execute(ResourceRegistrationEntity.class, query, SITE_NAME, stateOption);
}
return execute(ResourceRegistrationEntity.class, RESOURCE_REGISTRATION_QUERY);
}
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/CommandLineHelper.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/CommandLineHelper.java
index 58db7bc8..cfc68785 100644
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/CommandLineHelper.java
+++ b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/CommandLineHelper.java
@@ -21,6 +21,7 @@
package org.onap.policy.common.sitemanager.utils;
import java.util.List;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
@@ -76,6 +77,11 @@ public class CommandLineHelper {
}
}
+ /**
+ * validate given command line arguments.
+ *
+ * @return true if valid
+ */
public boolean isValid() {
// fetch options, and remaining arguments
final String sOption = commandLine.getOptionValue(SITE_ARGUMENT_NAME);
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ErrorMessages.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ErrorMessages.java
index 81145462..54695c65 100644
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ErrorMessages.java
+++ b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ErrorMessages.java
@@ -49,6 +49,8 @@ public class ErrorMessages {
public static final String NO_COMMAND_SPECIFIED = "No command specified";
+ public static final String NO_MATCHING_ENTRIES = ": No matching entries";
+
public static final String HELP_STRING = "Usage:\n" + " siteManager show [ -s <site> | -r <resourceName> ] :\n"
+ " display node information\n" + " siteManager setAdminState { -s <site> | -r <resourceName> }"
+ " <new-state> :\n" + " update admin state on selected nodes\n"
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ExtraCommandLineArgument.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ExtraCommandLineArgument.java
index a28deece..55dfea7e 100644
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ExtraCommandLineArgument.java
+++ b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ExtraCommandLineArgument.java
@@ -119,6 +119,12 @@ public enum ExtraCommandLineArgument {
return value;
}
+ /**
+ * Get {@link ExtraCommandLineArgument} for given command line argument.
+ *
+ * @param value the input command line argument
+ * @return {@link ExtraCommandLineArgument}
+ */
public static ExtraCommandLineArgument getExtraCommandLineArgument(final String value) {
for (final ExtraCommandLineArgument argument : ExtraCommandLineArgument.values()) {
if (argument.getValue().equals(value)) {
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/JmxOpProcessor.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/JmxOpProcessor.java
index 2e354d3b..33a2238a 100644
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/JmxOpProcessor.java
+++ b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/JmxOpProcessor.java
@@ -38,10 +38,11 @@ public class JmxOpProcessor {
}
/**
- * Process a 'lock' or 'unlock' operation on a single 'ResourceRegistrationEntity'
+ * Process a 'lock' or 'unlock' operation on a single {@link ResourceRegistrationEntity}.
*
* @param action this is the string "lock" or "unlock"
- * @param resourceRegistrationEntity this is the ResourceRegistrationEntity to lock or unlock
+ * @param resourceRegistrationEntity this is the {@link ResourceRegistrationEntity} to lock or
+ * unlock
*/
public static void jmxOp(final String action, final ResourceRegistrationEntity resourceRegistrationEntity,
final Printable printable) {
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/PersistenceUnitPropertiesProvider.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/PersistenceUnitPropertiesProvider.java
index 5d7abe7d..ffc48694 100644
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/PersistenceUnitPropertiesProvider.java
+++ b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/PersistenceUnitPropertiesProvider.java
@@ -26,12 +26,14 @@ import static org.onap.policy.common.sitemanager.utils.Constants.JDBC_URL_PROPER
import static org.onap.policy.common.sitemanager.utils.Constants.JDBC_USER_PROPERTY_NAME;
import static org.onap.policy.common.sitemanager.utils.ErrorMessages.SITE_MANAGER_PROPERY_FILE_MISSING_PROPERTY;
import static org.onap.policy.common.sitemanager.utils.ErrorMessages.SITE_MANAGER_PROPERY_FILE_NOT_DEFINED_MESSAGE;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
+
import org.onap.policy.common.sitemanager.exception.MissingPropertyException;
import org.onap.policy.common.sitemanager.exception.PropertyFileProcessingException;
@@ -41,6 +43,21 @@ public class PersistenceUnitPropertiesProvider {
super();
}
+ /**
+ * Parser and validate properties in give property file. <br>
+ * valid and mandatory property name
+ *
+ * <ul>
+ * <li>javax.persistence.jdbc.driver</li>
+ * <li>javax.persistence.jdbc.url</li>
+ * <li>javax.persistence.jdbc.user</li>
+ * <li>javax.persistence.jdbc.password</li>
+ * </ul>
+ *
+ * @param propertiesFileName the properties filename
+ * @param printable {@link Printable}
+ * @return {@link Properties}
+ */
public static Properties getProperties(final String propertiesFileName, final Printable printable) {
if (propertiesFileName == null) {
printable.println(SITE_MANAGER_PROPERY_FILE_NOT_DEFINED_MESSAGE);
@@ -61,18 +78,6 @@ public class PersistenceUnitPropertiesProvider {
return properties;
}
- private static boolean isNotValid(final Properties properties, final String... values) {
- if (values == null || values.length == 0) {
- return true;
- }
- for (final String val : values) {
- if (properties.get(val) == null) {
- return true;
- }
- }
- return false;
- }
-
private static Properties getProperties(final Path filePath, final Printable printable) {
if (!filePath.toFile().exists()) {
printable.println(SITE_MANAGER_PROPERY_FILE_NOT_DEFINED_MESSAGE);
@@ -91,4 +96,16 @@ public class PersistenceUnitPropertiesProvider {
throw new PropertyFileProcessingException("Exception loading properties: ", exception);
}
}
+
+ private static boolean isNotValid(final Properties properties, final String... values) {
+ if (values == null || values.length == 0) {
+ return true;
+ }
+ for (final String val : values) {
+ if (properties.get(val) == null) {
+ return true;
+ }
+ }
+ return false;
+ }
}