summaryrefslogtreecommitdiffstats
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/files/README30
-rw-r--r--site-manager/src/main/files/siteManager20
-rw-r--r--site-manager/src/main/files/siteManager.properties24
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/Main.java313
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessService.java56
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessServiceImpl.java124
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/IllegalCommandLineArgumentException.java30
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/MissingPropertyException.java31
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/NoMatchingEntryFoundException.java31
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/PropertyFileProcessingException.java35
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/CommandLineHelper.java122
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/Constants.java54
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ErrorMessages.java78
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ExtraCommandLineArgument.java144
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/JmxOpProcessor.java72
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/PersistenceUnitPropertiesProvider.java111
-rw-r--r--site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/Printable.java28
17 files changed, 0 insertions, 1303 deletions
diff --git a/site-manager/src/main/files/README b/site-manager/src/main/files/README
deleted file mode 100644
index d5d2df6e..00000000
--- a/site-manager/src/main/files/README
+++ /dev/null
@@ -1,30 +0,0 @@
-Copyright 2018 AT&T Intellectual Property. All rights reserved.
-This file is licensed under the CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE
-Full license text at https://creativecommons.org/licenses/by/4.0/legalcode
-
-Before using 'siteManager', the file 'siteManager.properties' needs to be
-edited to configure the parameters used to access the database:
-
- javax.persistence.jdbc.driver - typically 'org.mariadb.jdbc.Driver'
- javax.persistence.jdbc.url - URL referring to the database,
- which typically has the form: 'jdbc:mariadb://<host>:<port>/<db>'
- ('<db>' is probably 'xacml' in this case)
- javax.persistence.jdbc.user - the user id for accessing the database
- javax.persistence.jdbc.password - password for accessing the database
-
-Once the properties file has been updated, the 'siteManager' script can be
-invoked as follows:
-
- siteManager show [ -s <site> | -r <resourceName> ] :
- display node information
- siteManager setAdminState { -s <site> | -r <resourceName> } <new-state> :
- update admin state on selected nodes
- siteManager lock { -s <site> | -r <resourceName> } :
- lock selected nodes
- siteManager unlock { -s <site> | -r <resourceName> } :
- unlock selected nodes
-
-Note that the 'siteManager' script assumes that the script,
-'site-manager-${project.version}.jar' file and 'siteManager.properties' file
-are all in the same directory. If the files are separated, the 'siteManager'
-script will need to be modified so it can locate the jar and properties files.
diff --git a/site-manager/src/main/files/siteManager b/site-manager/src/main/files/siteManager
deleted file mode 100644
index 2258b996..00000000
--- a/site-manager/src/main/files/siteManager
+++ /dev/null
@@ -1,20 +0,0 @@
-#! /bin/bash
-# Copyright 2018 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-dir="${0%/*}"
-CLASSPATH="${dir}/site-manager-${project.version}.jar" java \
- -DsiteManager.properties=${dir}/siteManager.properties \
- org.onap.policy.common.sitemanager.Main "$@" | \
- grep -v "^\[EL Info\]"
diff --git a/site-manager/src/main/files/siteManager.properties b/site-manager/src/main/files/siteManager.properties
deleted file mode 100644
index a2801181..00000000
--- a/site-manager/src/main/files/siteManager.properties
+++ /dev/null
@@ -1,24 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# site-manager
-# ================================================================================
-# Copyright (C) 2017 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-javax.persistence.jdbc.driver = org.mariadb.jdbc.Driver
-# javax.persistence.jdbc.url = jdbc:mariadb://<host>:3306/xacml
-# javax.persistence.jdbc.user = <userid>
-# javax.persistence.jdbc.password = <password>
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
deleted file mode 100644
index a415c229..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/Main.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2017-2018 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager;
-
-/*
- * Site Manager argument list:
- *
- * none - dump help information show - dump information about all nodes ([site, nodetype,
- * resourceName], adminState, opState, availStatus, standbyStatus) The first 3 determine the sort
- * order. setAdminState [ -s <site> | -r <resourceName> ] <new-state> lock [ -s <site> | -r
- * <resourceName> ] unlock [ -s <site> | -r <resourceName> ]
- */
-
-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;
-import org.onap.policy.common.sitemanager.data.service.DatabaseAccessServiceImpl;
-import org.onap.policy.common.sitemanager.exception.IllegalCommandLineArgumentException;
-import org.onap.policy.common.sitemanager.exception.MissingPropertyException;
-import org.onap.policy.common.sitemanager.exception.NoMatchingEntryFoundException;
-import org.onap.policy.common.sitemanager.exception.PropertyFileProcessingException;
-import org.onap.policy.common.sitemanager.utils.CommandLineHelper;
-import org.onap.policy.common.sitemanager.utils.PersistenceUnitPropertiesProvider;
-import org.onap.policy.common.sitemanager.utils.Printable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class contains the main entry point for Site Manager.
- */
-public class Main {
-
- private static final Logger logger = LoggerFactory.getLogger(Main.class.getName());
-
- // table mapping 'resourceName' to 'StateManagmentEntity'
- static Map<String, StateManagementEntity> stateManagementTable = new HashMap<>();
-
- // table mapping 'resourceName' to 'StateManagmentEntity'
- static Map<String, ResourceRegistrationEntity> resourceRegistrationTable = new HashMap<>();
-
- /**
- * Print out help information regarding command arguments.
- */
- private static String getHelpString() {
- return HELP_STRING;
- }
-
- /**
- * This is the main entry point.
- *
- * @param args these are command-line arguments to 'siteManager'
- */
- public static void main(final String[] args) {
- final Printable printable = new PrintableImpl();
- 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);
-
- if (commandLineHelper.isHelpArgumentSet()) {
- printable.println(getHelpString());
- System.exit(0);
- }
-
- if (!commandLineHelper.isValid()) {
- printable.println(getHelpString());
- System.exit(2);
- }
- process(commandLineHelper, printable);
- } catch (final IllegalCommandLineArgumentException illegalCommandLineArgumentException) {
- printable.println(illegalCommandLineArgumentException.getMessage());
- printable.println(getHelpString());
- System.exit(1);
- } catch (final PropertyFileProcessingException | MissingPropertyException exception) {
- System.exit(3);
- } catch (final NoMatchingEntryFoundException exception) {
- System.exit(4);
- }
- }
-
- private void process(final CommandLineHelper cmd, final Printable printable) {
- // fetch options, and remaining arguments
- final String sOption = cmd.getSite();
- final String rOption = cmd.getResourceName();
- final List<String> argList = cmd.getArgList();
-
- final String arg0 = argList.get(0);
-
- // read in properties used to access the database
- final String propertiesFileName = System.getProperty(SITE_MANAGER_PROPERTIES_PROPERTY_NAME);
- final Properties properties = PersistenceUnitPropertiesProvider.getProperties(propertiesFileName, printable);
-
- try (final DatabaseAccessService accessService =
- getDatabaseAccessService(OPERATIONAL_PERSISTENCE_UNIT, properties)) {
-
- final List<StateManagementEntity> stateManagementResultList =
- accessService.getStateManagementEntities(rOption, sOption);
- final List<ResourceRegistrationEntity> resourceRegistrationResultList =
- accessService.getResourceRegistrationEntities(rOption, sOption);
-
- // perform 'StateManagementEntity' query, and place matching entries
- // in 'stateManagementTable'
- for (final StateManagementEntity stateManagementEntity : stateManagementResultList) {
- stateManagementTable.put(stateManagementEntity.getResourceName(), stateManagementEntity);
- }
-
- // perform 'ResourceRegistrationQuery', and place matching entries
- // in 'resourceRegistrationTable' ONLY if there is also an associated
- // 'stateManagementTable' entry
- for (final ResourceRegistrationEntity resourceRegistrationEntity : resourceRegistrationResultList) {
- final String resourceName = resourceRegistrationEntity.getResourceName();
- if (stateManagementTable.get(resourceName) != null) {
- // only include entries that have a corresponding
- // state table entry -- silently ignore the rest
- resourceRegistrationTable.put(resourceName, resourceRegistrationEntity);
- }
- }
-
- if (resourceRegistrationTable.isEmpty()) {
- final String message = arg0 + NO_MATCHING_ENTRIES;
- printable.println(message);
- throw new NoMatchingEntryFoundException(message);
- }
-
- if (SET_ADMIN_STATE.getValue().equalsIgnoreCase(arg0)) {
- // update admin state on all of the nodes
- final String adminState = argList.get(1);
- // iterate over all matching 'ResourceRegistrationEntity' instances
- for (final ResourceRegistrationEntity r : resourceRegistrationTable.values()) {
- // we know the corresponding 'StateManagementEntity' exists --
- // 'ResourceRegistrationEntity' entries without a matching
- // 'StateManagementEntity' entry were not placed in the table
- final StateManagementEntity s = stateManagementTable.get(r.getResourceName());
-
- // update the admin state, and save the changes
- s.setAdminState(adminState);
- }
- accessService.persist(stateManagementTable.values());
-
- } else if (LOCK.getValue().equalsIgnoreCase(arg0) || UNLOCK.getValue().equalsIgnoreCase(arg0)) {
- // these use the JMX interface
- for (final ResourceRegistrationEntity r : resourceRegistrationTable.values()) {
- // lock or unlock the entity
- jmxOp(arg0, r, printable);
-
- // change should be reflected in 'adminState'
- accessService.refreshEntity(stateManagementTable.get(r.getResourceName()));
- }
- }
- } catch (final NoMatchingEntryFoundException exception) {
- throw exception;
- } catch (final Exception exception) {
- printable.println(exception.getMessage());
- }
-
- // display all entries
- display();
- }
-
- /**
- * 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 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) {
- return (first == null) ? -1 : 1;
- }
-
- if (first == null && second == null) {
- return 0;
- }
-
- return first.compareTo(second);
- }
-
- /**
- * Update an array of 'length' fields using an array of Strings, any of which may be 'null'.
- * This method is used to determine the field width of each column in a tabular dump.
- *
- * @param current this is an array of length 7, containing the current maximum lengths of each
- * column in the tabular dump
- * @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[] 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
- current[i] = newLength;
- }
- }
- }
-
- /**
- * Ordered display -- dump out all of the entries in log.
- */
- static void display() {
- 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) {
- break;
- }
- }
- return (rval);
- });
-
- final String[] labels = new String[] {"Site", "NodeType", "ResourceName", "AdminState", "OpState",
- "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[labels.length];
- updateLengths(lengths, labels);
-
- // Go through the 'resourceRegistrationTable', and generate the
- // associated table row. Maximum column widths are updated, and the
- // entry is inserted into tree, which has the effect of sorting the
- // entries.
- for (final ResourceRegistrationEntity r : resourceRegistrationTable.values()) {
- final StateManagementEntity s = stateManagementTable.get(r.getResourceName());
-
- // 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()};
-
- treeset.add(values);
- updateLengths(lengths, values);
- }
-
- // generate format string
- final StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 7; i += 1) {
- sb.append('%').append(i + 1).append("$-").append(lengths[i]).append("s ");
- }
- sb.setCharAt(sb.length() - 1, '\n');
- final String formatString = sb.toString();
-
- // display column headers
- logger.info(formatString, (Object[]) labels);
- logger.info(formatString, (Object[]) underlines);
-
- // display all of the rows
- for (final String[] values : treeset) {
- logger.info(formatString, (Object[]) values);
- }
- }
-
- DatabaseAccessService getDatabaseAccessService(final String persistenceUnitName, final Properties properties) {
- return new DatabaseAccessServiceImpl(persistenceUnitName, properties);
- }
-
- private static class PrintableImpl implements Printable {
-
- @Override
- public void println(final String value) {
- System.out.println(value);
- }
- }
-}
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
deleted file mode 100644
index 4b29359a..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessService.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.data.service;
-
-import java.util.Collection;
-import java.util.List;
-import org.onap.policy.common.im.jpa.ResourceRegistrationEntity;
-import org.onap.policy.common.im.jpa.StateManagementEntity;
-
-public interface DatabaseAccessService extends AutoCloseable {
-
- <T> List<T> execute(final Class<T> clazz, final String query, final String paramName, final String paramValue);
-
- <T> List<T> execute(final Class<T> clazz, final String query);
-
- /**
- * Get {@link StateManagementEntity} entities from database.
- *
- * @param resourceOption resource name (optional)
- * @param stateOption site name (optional)
- * @return list of {@link StateManagementEntity} entities found
- */
- List<StateManagementEntity> getStateManagementEntities(final String resourceOption, final String stateOption);
-
- /**
- * Get {@link ResourceRegistrationEntity} entities from database.
- *
- * @param resourceOption resource name (optional)
- * @param stateOption site name (optional)
- * @return list of {@link ResourceRegistrationEntity} entities found
- */
- List<ResourceRegistrationEntity> getResourceRegistrationEntities(final String resourceOption,
- final String stateOption);
-
- <T> void persist(final Collection<T> entities);
-
- <T> void refreshEntity(final T enity);
-}
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
deleted file mode 100644
index 769b164b..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/data/service/DatabaseAccessServiceImpl.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.data.service;
-
-import static org.onap.policy.common.sitemanager.utils.Constants.RESOURCE_NAME;
-import static org.onap.policy.common.sitemanager.utils.Constants.RESOURCE_REGISTRATION_QUERY;
-import static org.onap.policy.common.sitemanager.utils.Constants.SITE_NAME;
-import static org.onap.policy.common.sitemanager.utils.Constants.STATE_MANAGEMENT_QUERY;
-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;
-
-public class DatabaseAccessServiceImpl implements DatabaseAccessService {
-
- private final EntityManagerFactory entityManagerFactory;
- private EntityManager entityManager;
-
- public DatabaseAccessServiceImpl(final String persistenceUnitName, final Properties properties) {
- this.entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnitName, properties);
- this.entityManager = entityManagerFactory.createEntityManager();
- }
-
- public DatabaseAccessServiceImpl(final EntityManagerFactory entityManagerFactory) {
- this.entityManagerFactory = entityManagerFactory;
- this.entityManager = entityManagerFactory.createEntityManager();
- }
-
- @Override
- public <T> List<T> execute(final Class<T> clazz, final String query, final String paramName,
- final String paramValue) {
- final TypedQuery<T> typedQuery = entityManager.createQuery(query, clazz);
- typedQuery.setParameter(paramName, paramValue);
- return typedQuery.getResultList();
-
- }
-
- @Override
- public <T> List<T> execute(final Class<T> clazz, final String query) {
- final TypedQuery<T> typedQuery = entityManager.createQuery(query, clazz);
- return typedQuery.getResultList();
- }
-
- @Override
- 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, resourceOption);
- } else if (stateOption != null) {
- return execute(StateManagementEntity.class, STATE_MANAGEMENT_QUERY);
- }
- return execute(StateManagementEntity.class, STATE_MANAGEMENT_QUERY);
-
- }
-
- @Override
- 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, resourceOption);
- } else if (stateOption != null) {
- final String query = RESOURCE_REGISTRATION_QUERY + WHERE_R_SITE_NAME + SITE_NAME;
- return execute(ResourceRegistrationEntity.class, query, SITE_NAME, stateOption);
- }
- return execute(ResourceRegistrationEntity.class, RESOURCE_REGISTRATION_QUERY);
- }
-
- @Override
- public <T> void persist(final Collection<T> entities) {
- try (final EntityTransCloser et = new EntityTransCloser(entityManager.getTransaction())) {
- for (final T entity : entities) {
- entityManager.persist(entity);
- }
- entityManager.flush();
- et.commit();
- }
- }
-
- @Override
- public <T> void refreshEntity(final T enity) {
- entityManager.refresh(enity);
-
- }
-
- @Override
- public void close() {
- if (entityManager.isOpen()) {
- entityManager.close();
- }
- }
-
-}
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/IllegalCommandLineArgumentException.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/IllegalCommandLineArgumentException.java
deleted file mode 100644
index db374c38..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/IllegalCommandLineArgumentException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.exception;
-
-public class IllegalCommandLineArgumentException extends RuntimeException {
-
- private static final long serialVersionUID = 4229478147993769997L;
-
- public IllegalCommandLineArgumentException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/MissingPropertyException.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/MissingPropertyException.java
deleted file mode 100644
index b5c10883..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/MissingPropertyException.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.exception;
-
-public class MissingPropertyException extends RuntimeException {
-
- private static final long serialVersionUID = 1224494625143527218L;
-
- public MissingPropertyException(final String message) {
- super(message);
- }
-
-}
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/NoMatchingEntryFoundException.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/NoMatchingEntryFoundException.java
deleted file mode 100644
index f77cdce2..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/NoMatchingEntryFoundException.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.exception;
-
-public class NoMatchingEntryFoundException extends RuntimeException {
-
- private static final long serialVersionUID = -1118517375170348132L;
-
- public NoMatchingEntryFoundException(final String message) {
- super(message);
- }
-
-}
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/PropertyFileProcessingException.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/PropertyFileProcessingException.java
deleted file mode 100644
index 2c4bcb9f..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/exception/PropertyFileProcessingException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.exception;
-
-public class PropertyFileProcessingException extends RuntimeException {
-
- private static final long serialVersionUID = 6507640341242930149L;
-
- public PropertyFileProcessingException(final String message) {
- super(message);
- }
-
- public PropertyFileProcessingException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
-}
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
deleted file mode 100644
index cfc68785..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/CommandLineHelper.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.onap.policy.common.sitemanager.exception.IllegalCommandLineArgumentException;
-
-public class CommandLineHelper {
-
- private static final String HELP_QUESTION_MARK_ARGUMENT_NAME = "?";
-
- private static final String HELP_ARGUMENT_NAME = "h";
-
- private static final String RESOURCE_ARGUMENT_NAME = "r";
-
- private static final String SITE_ARGUMENT_NAME = "s";
-
- private final CommandLine commandLine;
-
- private static final CommandLineParser PARSER = new DefaultParser();
-
- private final Printable printable;
-
- public CommandLineHelper(final String[] args, final Printable printable) {
- this.commandLine = getCommandLine(getOptions(), args);
- this.printable = printable;
- }
-
- private Options getOptions() {
- final Options options = new Options();
- options.addOption(Option.builder(SITE_ARGUMENT_NAME).hasArg(true).desc("specify site").build());
- options.addOption(Option.builder(RESOURCE_ARGUMENT_NAME).hasArg(true).desc("specify resource name").build());
- options.addOption(Option.builder(HELP_ARGUMENT_NAME).hasArg(false).desc("display help").build());
- options.addOption(Option.builder(HELP_QUESTION_MARK_ARGUMENT_NAME).hasArg(false).desc("display help").build());
-
- return options;
- }
-
- public String getSite() {
- return commandLine.getOptionValue(SITE_ARGUMENT_NAME);
- }
-
- public String getResourceName() {
- return commandLine.getOptionValue(RESOURCE_ARGUMENT_NAME);
- }
-
- private CommandLine getCommandLine(final Options options, final String[] args) {
- try {
- return PARSER.parse(options, args);
- } catch (final ParseException | NullPointerException exception) {
- throw new IllegalCommandLineArgumentException(exception.getMessage(), exception);
- }
- }
-
- /**
- * 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);
- final String rOption = commandLine.getOptionValue(RESOURCE_ARGUMENT_NAME);
- final List<String> argList = commandLine.getArgList();
-
- // a number of commands require either the '-r' option or '-s' option
- final boolean optionLetterSpecified = (rOption != null || sOption != null);
-
- if (argList.isEmpty()) {
- printable.println(ErrorMessages.NO_COMMAND_SPECIFIED);
- return false;
- }
- // a number of commands require either the '-r' option or '-s' option
- final String arg0 = argList.get(0);
- final ExtraCommandLineArgument argument = ExtraCommandLineArgument.getExtraCommandLineArgument(arg0);
-
- if (!argument.isValid(argList, printable, optionLetterSpecified)) {
- return false;
- }
-
- if (sOption != null && rOption != null) {
- printable.println(arg0 + ErrorMessages.R_AND_S_OPTIONS_ARE_MUTUALLY_EXCLUSIVE);
- return false;
- }
-
- return true;
- }
-
- public boolean isHelpArgumentSet() {
- return commandLine.hasOption(HELP_ARGUMENT_NAME) || commandLine.hasOption(HELP_QUESTION_MARK_ARGUMENT_NAME);
- }
-
- public List<String> getArgList() {
- return commandLine.getArgList();
- }
-
-}
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/Constants.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/Constants.java
deleted file mode 100644
index 0f2d9a49..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/Constants.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.utils;
-
-public final class Constants {
-
- public static final String SITE_NAME = "site";
-
- public static final String WHERE_R_SITE_NAME = " WHERE r.site = :";
-
- public static final String WHERE_R_RESOURCE_NAME = " WHERE r.resourceName = :";
-
- public static final String RESOURCE_NAME = "resourceName";
-
- public static final String WHERE_S_RESOURCE_NAME = " WHERE s.resourceName = :";
-
- public static final String RESOURCE_REGISTRATION_QUERY = "SELECT r FROM ResourceRegistrationEntity r";
-
- public static final String STATE_MANAGEMENT_QUERY = "SELECT s FROM StateManagementEntity s";
-
- public static final String JDBC_PASSWORD_PROPERTY_NAME = "javax.persistence.jdbc.password";
-
- public static final String JDBC_USER_PROPERTY_NAME = "javax.persistence.jdbc.user";
-
- public static final String JDBC_URL_PROPERTY_NAME = "javax.persistence.jdbc.url";
-
- public static final String JDBC_DRIVER_PROPERTY_NAME = "javax.persistence.jdbc.driver";
-
- public static final String OPERATIONAL_PERSISTENCE_UNIT = "operationalPU";
-
- public static final String SITE_MANAGER_PROPERTIES_PROPERTY_NAME = "siteManager.properties";
-
- private Constants() {
- super();
- }
-}
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
deleted file mode 100644
index 54695c65..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ErrorMessages.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.utils;
-
-public class ErrorMessages {
-
- public static final String EXTRA_ARGUMENTS = "Extra arguments";
-
- public static final String EITHER_S_OR_R_OPTION_IS_NEEDED = "Either '-s' or '-r' option is needed";
-
- public static final String R_AND_S_OPTIONS_ARE_MUTUALLY_EXCLUSIVE = ": 'r' and 's' options are mutually exclusive";
-
- public static final String UNKNOWN_COMMAND = ": Unknown command";
-
- public static final String UNLOCK_EITHER_S_OR_R_OPTION_IS_NEEDED = "unlock: " + EITHER_S_OR_R_OPTION_IS_NEEDED;
-
- public static final String UNLOCK_EXTRA_ARGUMENTS = "unlock: " + EXTRA_ARGUMENTS;
-
- public static final String LOCK_EITHER_S_OR_R_OPTION_IS_NEEDED = "lock: " + EITHER_S_OR_R_OPTION_IS_NEEDED;
-
- public static final String LOCK_EXTRA_ARGUMENTS = "lock: " + EXTRA_ARGUMENTS;
-
- public static final String SET_ADMIN_STATE_EITHER_S_OR_R_OPTION_IS_NEEDED =
- "setAdminState: " + EITHER_S_OR_R_OPTION_IS_NEEDED;
-
- public static final String SET_ADMIN_STATE_EXTRA_ARGUMENTS = "setAdminState: " + EXTRA_ARGUMENTS;
-
- public static final String SET_ADMIN_STATE_MISSING_NEW_STATE_VALUE = "setAdminState: Missing <new-state> value";
-
- public static final String SHOW_EXTRA_ARGUMENTS = "show: " + EXTRA_ARGUMENTS;
-
- 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"
- + " siteManager lock { -s <site> | -r <resourceName> } :\n" + " lock selected nodes\n"
- + " siteManager unlock { -s <site> | -r <resourceName> } :\n" + " unlock selected nodes\n";
-
- public static final String SITE_MANAGER_PROPERY_FILE_MISSING_PROPERTY =
- "The following properties need to be specified:\n\n" + " javax.persistence.jdbc.driver -"
- + " typically 'org.mariadb.jdbc.Driver'\n"
- + " javax.persistence.jdbc.url - URL referring to the database,\n"
- + " which typically has the form:" + " 'jdbc:mariadb://<host>:<port>/<db>'\n"
- + " ('<db>' is probably 'xacml' in this case)\n"
- + " javax.persistence.jdbc.user - the user id for accessing the" + " database\n"
- + " javax.persistence.jdbc.password - password for accessing the" + " database\n";
-
- public static final String SITE_MANAGER_PROPERY_FILE_NOT_DEFINED_MESSAGE =
- "'siteManager' needs to be passed the system property\n"
- + "'siteManager.properties', which is the file name of a\n"
- + "properties file containing database access information\n\n";
-
- private ErrorMessages() {
- super();
- }
-
-}
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
deleted file mode 100644
index 55dfea7e..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/ExtraCommandLineArgument.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.utils;
-
-import java.util.List;
-
-public enum ExtraCommandLineArgument {
- SHOW("show") {
-
- @Override
- public boolean isValid(final List<String> argList, final Printable printable) {
- if (argList.size() != 1) {
- printable.println(ErrorMessages.SHOW_EXTRA_ARGUMENTS);
- return false;
- }
- return true;
- }
-
- @Override
- public boolean isValid(final List<String> argList, final Printable printable,
- final boolean optionLetterSpecified) {
- return isValid(argList, printable);
- }
- },
- SET_ADMIN_STATE("setAdminState") {
- @Override
- public boolean isValid(final List<String> argList, final Printable printable,
- final boolean optionLetterSpecified) {
- boolean isValid = true;
- switch (argList.size()) {
- case 1:
- printable.println(ErrorMessages.SET_ADMIN_STATE_MISSING_NEW_STATE_VALUE);
- isValid = false;
- break;
- case 2:
- isValid = true;
- break;
- default:
- printable.println(ErrorMessages.SET_ADMIN_STATE_EXTRA_ARGUMENTS);
- isValid = false;
- }
- if (!optionLetterSpecified) {
- printable.println(ErrorMessages.SET_ADMIN_STATE_EITHER_S_OR_R_OPTION_IS_NEEDED);
- return false;
- }
-
- return isValid;
- }
-
- },
- LOCK("lock") {
-
- @Override
- public boolean isValid(final List<String> argList, final Printable printable,
- final boolean optionLetterSpecified) {
- boolean isValid = true;
- if (argList.size() != 1) {
- printable.println(ErrorMessages.LOCK_EXTRA_ARGUMENTS);
- isValid = false;
- }
- if (!optionLetterSpecified) {
- printable.println(ErrorMessages.LOCK_EITHER_S_OR_R_OPTION_IS_NEEDED);
- isValid = false;
- }
- return isValid;
- }
- },
- UNLOCK("unlock") {
-
- @Override
- public boolean isValid(final List<String> argList, final Printable printable,
- final boolean optionLetterSpecified) {
- boolean isValid = true;
- if (argList.size() != 1) {
- printable.println(ErrorMessages.UNLOCK_EXTRA_ARGUMENTS);
- isValid = false;
- }
- if (!optionLetterSpecified) {
- printable.println(ErrorMessages.UNLOCK_EITHER_S_OR_R_OPTION_IS_NEEDED);
- isValid = false;
- }
- return isValid;
- }
- },
- INVALID("") {
- @Override
- public boolean isValid(final List<String> argList, final Printable printable,
- final boolean optionLetterSpecified) {
- printable.println(argList.get(0) + ErrorMessages.UNKNOWN_COMMAND);
- return false;
- }
- };
-
- private final String value;
-
- private ExtraCommandLineArgument(final String value) {
- this.value = value;
- }
-
- public String getValue() {
- 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)) {
- return argument;
- }
- }
- return ExtraCommandLineArgument.INVALID;
- }
-
- public boolean isValid(final List<String> argList, final Printable printable) {
- return isValid(argList, printable, false);
- }
-
- public abstract boolean isValid(final List<String> argList, final Printable printable,
- final boolean optionLetterSpecified);
-
-}
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
deleted file mode 100644
index 33a2238a..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/JmxOpProcessor.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.utils;
-
-import java.io.IOException;
-import javax.management.JMX;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.common.im.jmx.ComponentAdminMBean;
-import org.onap.policy.common.im.jpa.ResourceRegistrationEntity;
-
-public class JmxOpProcessor {
-
- private JmxOpProcessor() {
- super();
- }
-
- /**
- * 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 {@link ResourceRegistrationEntity} to lock or
- * unlock
- */
- public static void jmxOp(final String action, final ResourceRegistrationEntity resourceRegistrationEntity,
- final Printable printable) {
- final String resourceName = resourceRegistrationEntity.getResourceName();
- final String jmxUrl = resourceRegistrationEntity.getResourceUrl();
- if (jmxUrl == null) {
- printable.println(action + ": no resource URL for '" + resourceName + "'");
- return;
- }
-
- try (final JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(jmxUrl))) {
- final ComponentAdminMBean admin = JMX.newMXBeanProxy(connector.getMBeanServerConnection(),
- new ObjectName("ONAP_POLICY_COMP:name=" + resourceName), ComponentAdminMBean.class);
-
- if ("lock".equals(action)) {
- admin.lock();
- } else if ("unlock".equals(action)) {
- admin.unlock();
- } else {
- printable.println("Unknown action: " + action);
- }
- } catch (final IOException | MalformedObjectNameException | IntegrityMonitorException exception) {
- printable.println(action + " failed for '" + resourceName + "': " + exception);
- }
- }
-
-}
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
deleted file mode 100644
index ffc48694..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/PersistenceUnitPropertiesProvider.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.utils;
-
-import static org.onap.policy.common.sitemanager.utils.Constants.JDBC_DRIVER_PROPERTY_NAME;
-import static org.onap.policy.common.sitemanager.utils.Constants.JDBC_PASSWORD_PROPERTY_NAME;
-import static org.onap.policy.common.sitemanager.utils.Constants.JDBC_URL_PROPERTY_NAME;
-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;
-
-public class PersistenceUnitPropertiesProvider {
-
- private 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);
- printable.println(SITE_MANAGER_PROPERY_FILE_MISSING_PROPERTY);
- throw new PropertyFileProcessingException("Property file name is null :" + propertiesFileName);
- }
-
- final Path filePath = Paths.get(propertiesFileName);
- final Properties properties = getProperties(filePath, printable);
-
- // verify that we have all of the properties needed
- if (isNotValid(properties, JDBC_DRIVER_PROPERTY_NAME, JDBC_URL_PROPERTY_NAME, JDBC_USER_PROPERTY_NAME,
- JDBC_PASSWORD_PROPERTY_NAME)) {
- // one or more missing properties
- printable.println(SITE_MANAGER_PROPERY_FILE_MISSING_PROPERTY);
- throw new MissingPropertyException("missing mandatory attributes");
- }
- return properties;
- }
-
- private static Properties getProperties(final Path filePath, final Printable printable) {
- if (!filePath.toFile().exists()) {
- printable.println(SITE_MANAGER_PROPERY_FILE_NOT_DEFINED_MESSAGE);
- printable.println(SITE_MANAGER_PROPERY_FILE_MISSING_PROPERTY);
- throw new PropertyFileProcessingException("Property file not found");
- }
-
- try (final BufferedReader bufferedReader = Files.newBufferedReader(filePath);) {
- final Properties properties = new Properties();
- properties.load(bufferedReader);
- return properties;
- } catch (final IOException exception) {
- printable.println("Exception loading properties: " + exception);
- printable.println(ErrorMessages.SITE_MANAGER_PROPERY_FILE_NOT_DEFINED_MESSAGE);
- printable.println(ErrorMessages.SITE_MANAGER_PROPERY_FILE_MISSING_PROPERTY);
- 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;
- }
-}
diff --git a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/Printable.java b/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/Printable.java
deleted file mode 100644
index 757268a7..00000000
--- a/site-manager/src/main/java/org/onap/policy/common/sitemanager/utils/Printable.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * site-manager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.sitemanager.utils;
-
-@FunctionalInterface
-public interface Printable {
-
- void println(final String value);
-
-}