aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-server/src/main/java
diff options
context:
space:
mode:
authorTschaen, Brendan <ctschaen@att.com>2018-11-26 22:42:22 -0500
committerTschaen, Brendan <ctschaen@att.com>2018-11-26 22:43:36 -0500
commit76d8bc46fdf9b36548dff46b9d1c91bf7c56f6ac (patch)
treec6fce094636967a40b80d5075464265758392069 /mdbc-server/src/main/java
parent73c29e3fd2cd218906744987e6ae683d77b092b9 (diff)
MySQL JUnit test
and code cleanup, renaming variable for clarity, updating stale interfaces Change-Id: I766267c442b7b037b41fe9f2f33092a1c01669ca Issue-ID: MUSIC-205 Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
Diffstat (limited to 'mdbc-server/src/main/java')
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/MdbcServerLogic.java4
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java39
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/MixinFactory.java8
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java5
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java13
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigest.java6
6 files changed, 34 insertions, 41 deletions
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/MdbcServerLogic.java b/mdbc-server/src/main/java/org/onap/music/mdbc/MdbcServerLogic.java
index 757b468..989b6e4 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/MdbcServerLogic.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/MdbcServerLogic.java
@@ -50,7 +50,6 @@ public class MdbcServerLogic extends JdbcMeta{
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MdbcServerLogic.class);
StateManager manager;
- String name;
//TODO: Delete this properties after debugging
private final Properties info;
@@ -58,8 +57,7 @@ public class MdbcServerLogic extends JdbcMeta{
public MdbcServerLogic(String Url, Properties info, NodeConfiguration config) throws SQLException, MDBCServiceException {
super(Url,info);
- this.name = config.nodeName;
- this.manager = new StateManager(Url,info,config.partition,"test"); //FIXME: db name should not be passed in ahead of time
+ this.manager = new StateManager(Url,info,config.partition,config.nodeName, "test"); //FIXME: db name should not be passed in ahead of time
this.info = info;
int concurrencyLevel = Integer.parseInt(
info.getProperty(ConnectionCacheSettings.CONCURRENCY_LEVEL.key(),
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java b/mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java
index 22ddee1..c13fe16 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java
@@ -62,23 +62,27 @@ public class StateManager {
*/
private TxCommitProgress transactionInfo;
private Map<String,MdbcConnection> mdbcConnections;
- private String sqlDatabase;
- private String url;
+ private String sqlDBName;
+ private String sqlDBUrl;
String musicmixin;
String cassandraUrl;
private Properties info;
+ /** Identifier for this server instance */
+ private String mdbcServerName;
+
@SuppressWarnings("unused")
private DatabasePartition ranges;
- public StateManager(String url, Properties info, DatabasePartition ranges, String sqlDatabase) throws MDBCServiceException {
- this.sqlDatabase = sqlDatabase;
+ public StateManager(String sqlDBUrl, Properties info, DatabasePartition ranges, String mdbcServerName, String sqlDBName) throws MDBCServiceException {
+ this.sqlDBName = sqlDBName;
this.ranges = ranges;
- this.url = url;
+ this.sqlDBUrl = sqlDBUrl;
this.info = info;
+ this.mdbcServerName = mdbcServerName;
this.transactionInfo = new TxCommitProgress();
- //\fixme this is not really used, delete!
+ //\fixme this might not be used, delete?
try {
info.load(this.getClass().getClassLoader().getResourceAsStream("music.properties"));
info.putAll(MDBCUtils.getMdbcProperties());
@@ -98,20 +102,13 @@ public class StateManager {
}
/**
- * Initialize the
+ * Initialize the connections to music, set up any necessary tables in music
* @param mixin
* @param cassandraUrl
* @throws MDBCServiceException
*/
protected void initMusic() throws MDBCServiceException {
- this.musicInterface = MixinFactory.createMusicInterface(musicmixin, cassandraUrl, info);
- this.musicInterface.createKeyspace();
- try {
- this.musicInterface.initializeMetricDataStructures();
- } catch (MDBCServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- throw(e);
- }
+ this.musicInterface = MixinFactory.createMusicInterface(musicmixin, mdbcServerName, info);
this.mdbcConnections = new HashMap<>();
}
@@ -125,9 +122,9 @@ public class StateManager {
return;
}
try {
- Connection sqlConnection = DriverManager.getConnection(this.url, this.info);
+ Connection sqlConnection = DriverManager.getConnection(this.sqlDBUrl, this.info);
StringBuilder sql = new StringBuilder("CREATE DATABASE IF NOT EXISTS ")
- .append(sqlDatabase)
+ .append(sqlDBName)
.append(";");
Statement stmt = sqlConnection.createStatement();
stmt.execute(sql.toString());
@@ -186,14 +183,14 @@ public class StateManager {
return;
}
try {
- sqlConnection = DriverManager.getConnection(this.url+"/"+this.sqlDatabase, this.info);
+ sqlConnection = DriverManager.getConnection(this.sqlDBUrl+"/"+this.sqlDBName, this.info);
} catch (SQLException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.QUERYERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
sqlConnection = null;
}
//Create MDBC connection
try {
- newConnection = new MdbcConnection(id, this.url+"/"+this.sqlDatabase, sqlConnection, info, this.musicInterface, transactionInfo,ranges);
+ newConnection = new MdbcConnection(id, this.sqlDBUrl+"/"+this.sqlDBName, sqlConnection, info, this.musicInterface, transactionInfo,ranges);
} catch (MDBCServiceException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
newConnection = null;
@@ -235,7 +232,7 @@ public class StateManager {
//Create connection to local SQL DB
try {
- sqlConnection = DriverManager.getConnection(this.url+"/"+this.sqlDatabase, this.info);
+ sqlConnection = DriverManager.getConnection(this.sqlDBUrl+"/"+this.sqlDBName, this.info);
} catch (SQLException e) {
logger.error("sql connection was not created correctly");
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.QUERYERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
@@ -243,7 +240,7 @@ public class StateManager {
}
//Create MDBC connection
try {
- newConnection = new MdbcConnection(id,this.url+"/"+this.sqlDatabase, sqlConnection, info, this.musicInterface, transactionInfo,ranges);
+ newConnection = new MdbcConnection(id,this.sqlDBUrl+"/"+this.sqlDBName, sqlConnection, info, this.musicInterface, transactionInfo,ranges);
} catch (MDBCServiceException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
newConnection = null;
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MixinFactory.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MixinFactory.java
index 0f05734..1edb38d 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MixinFactory.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MixinFactory.java
@@ -74,13 +74,11 @@ public class MixinFactory {
* Look for a class in CLASSPATH that implements the {@link MusicInterface} interface, and has the mixin name <i>name</i>.
* If one is found, construct and return it, using the other arguments for the constructor.
* @param name the name of the Mixin
- * @param msm the MusicSqlManager to use as an argument to the constructor
- * @param dbi the DBInterface to use as an argument to the constructor
- * @param url the URL to use as an argument to the constructor
+ * @param mdbcServerName the name of this mdbcServer instance
* @param info the Properties to use as an argument to the constructor
* @return the newly constructed MusicInterface, or null if one cannot be found.
*/
- public static MusicInterface createMusicInterface(String name, String url, Properties info) {
+ public static MusicInterface createMusicInterface(String name, String mdbcServerName, Properties info) {
for (Class<?> cl : Utils.getClassesImplementing(MusicInterface.class)) {
try {
Constructor<?> con = cl.getConstructor();
@@ -92,7 +90,7 @@ public class MixinFactory {
con = cl.getConstructor(String.class, Properties.class);
if (con != null) {
logger.info(EELFLoggerDelegate.applicationLogger,"Found match: "+miname);
- return (MusicInterface) con.newInstance(url, info);
+ return (MusicInterface) con.newInstance(mdbcServerName, info);
}
}
}
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
index 5b10a73..f4231d8 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
@@ -44,11 +44,6 @@ import org.onap.music.mdbc.tables.TxCommitProgress;
*/
public interface MusicInterface {
/**
- * This function is used to created all the required data structures, both local
- * \TODO Check if this function is required in the MUSIC interface or could be just created on the constructor
- */
- void initializeMetricDataStructures() throws MDBCServiceException;
- /**
* Get the name of this MusicInterface mixin object.
* @return the name
*/
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
index 258ea4f..8ffb6af 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
@@ -155,7 +155,7 @@ public class MusicMixin implements MusicInterface {
this.allReplicaIds = null;
}
- public MusicMixin(String url, Properties info) throws MDBCServiceException {
+ public MusicMixin(String mdbcServerName, Properties info) throws MDBCServiceException {
// Default values -- should be overridden in the Properties
// Default to using the host_ids of the various peers as the replica IDs (this is probably preferred)
this.musicAddress = info.getProperty(KEY_MUSIC_ADDRESS, DEFAULT_MUSIC_ADDRESS);
@@ -173,7 +173,8 @@ public class MusicMixin implements MusicInterface {
this.music_ns = info.getProperty(KEY_MUSIC_NAMESPACE,DEFAULT_MUSIC_NAMESPACE);
logger.info(EELFLoggerDelegate.applicationLogger,"MusicSqlManager: music_ns="+music_ns);
- createKeyspace();
+
+ initializeMetricTables();
}
/**
@@ -234,8 +235,12 @@ public class MusicMixin implements MusicInterface {
musicSession = null;
}
}
- @Override
- public void initializeMetricDataStructures() throws MDBCServiceException {
+
+ /**
+ * This function is used to created all the required data structures, both local
+ */
+ private void initializeMetricTables() throws MDBCServiceException {
+ createKeyspace();
try {
createMusicTxDigest();//\TODO If we start partitioning the data base, we would need to use the redotable number
createMusicRangeInformationTable();
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigest.java b/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigest.java
index 210cb9e..7057172 100644
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigest.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigest.java
@@ -95,9 +95,9 @@ public class MusicTxDigest {
/**
* Replay the digest for a given partition
- * @param mi
- * @param partitionId
- * @param dbi
+ * @param mi music interface
+ * @param partitionId the partition to be replayed
+ * @param dbi interface to the database that will replay the operations
* @throws MDBCServiceException
*/
public void replayDigestForPartition(MusicInterface mi, UUID partitionId, DBInterface dbi) throws MDBCServiceException {