aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/music/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/music/main')
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java162
-rw-r--r--src/main/java/org/onap/music/main/MusicDigest.java79
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java846
-rw-r--r--src/main/java/org/onap/music/main/PropertiesLoader.java187
-rw-r--r--src/main/java/org/onap/music/main/ResultType.java42
-rw-r--r--src/main/java/org/onap/music/main/ReturnType.java75
6 files changed, 0 insertions, 1391 deletions
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
deleted file mode 100644
index 221e680b..00000000
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * 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.music.main;
-
-import java.util.List;
-import java.util.Map;
-
-import org.onap.music.datastore.Condition;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.exceptions.MusicLockingException;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.cassandra.CassaLockStore;
-import org.onap.music.lockingservice.cassandra.MusicLockState;
-import org.onap.music.service.MusicCoreService;
-import org.onap.music.service.impl.MusicCassaCore;
-
-import com.datastax.driver.core.ResultSet;
-
-public class MusicCore {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
- private static boolean unitTestRun=true;
-
- private static MusicCoreService musicCore = MusicUtil.getMusicCoreService();
- public static CassaLockStore mLockHandle;
-
-
- /**
- * Acquire lock
- * @param fullyQualifiedKey DO NOT RELY ON THIS KEY WORKING. INCLUDE THE KEY IN THE LOCKID.
- * @param lockId - the full lock id (key + lockRef)
- * @return
- * @throws MusicLockingException
- * @throws MusicQueryException
- * @throws MusicServiceException
- */
- public static ReturnType acquireLock(String fullyQualifiedKey, String lockId)
- throws MusicLockingException, MusicQueryException, MusicServiceException {
- return musicCore.acquireLock(fullyQualifiedKey, lockId);
- }
-
- public static ReturnType acquireLockWithLease(String key, String lockId, long leasePeriod)
- throws MusicLockingException, MusicQueryException, MusicServiceException {
- return musicCore.acquireLockWithLease(key, lockId, leasePeriod);
- }
-
- public static String createLockReference(String fullyQualifiedKey) {
- return musicCore.createLockReference(fullyQualifiedKey);
- }
-
- public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
- String consistency) throws MusicServiceException {
- return musicCore.createTable(keyspace, table, tableQueryObject, consistency);
- }
-
- public static ResultSet quorumGet(PreparedQueryObject query) {
- return musicCore.quorumGet(query);
- }
-
- public static String whoseTurnIsIt(String fullyQualifiedKey) {
- return musicCore.whoseTurnIsIt(fullyQualifiedKey);
- }
-
- public static void destroyLockRef(String lockId) {
- musicCore.destroyLockRef(lockId);
- }
-
- public static ReturnType eventualPut(PreparedQueryObject queryObject) {
- return musicCore.eventualPut(queryObject);
- }
-
- public static ReturnType eventualPut_nb(PreparedQueryObject queryObject,String keyspace,
- String tablename,String primaryKey) {
- return musicCore.eventualPut_nb(queryObject, keyspace, tablename, primaryKey);
- }
-
- public static ReturnType criticalPut(String keyspace, String table, String primaryKeyValue,
- PreparedQueryObject queryObject, String lockReference, Condition conditionInfo) {
- return musicCore.criticalPut(keyspace, table, primaryKeyValue, queryObject, lockReference, conditionInfo);
- }
-
- public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
- throws MusicServiceException {
- return musicCore.nonKeyRelatedPut(queryObject, consistency);
- }
-
- public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException{
- return musicCore.get(queryObject);
- }
-
- public static ResultSet criticalGet(String keyspace, String table, String primaryKeyValue,
- PreparedQueryObject queryObject, String lockReference) throws MusicServiceException {
- return musicCore.criticalGet(keyspace, table, primaryKeyValue, queryObject,lockReference);
- }
-
- public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException,
- MusicQueryException,MusicServiceException {
- return musicCore.atomicPut(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
- }
-
- public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException {
- return musicCore.atomicGet(keyspaceName, tableName, primaryKey, queryObject);
- }
-
- public static List<String> getLockQueue(String fullyQualifiedKey)
- throws MusicServiceException, MusicQueryException, MusicLockingException {
- return musicCore.getLockQueue(fullyQualifiedKey);
- }
-
- public static long getLockQueueSize(String fullyQualifiedKey)
- throws MusicServiceException, MusicQueryException, MusicLockingException {
- return musicCore.getLockQueueSize(fullyQualifiedKey);
- }
-
- public static void deleteLock(String lockName) throws MusicLockingException {
- musicCore.deleteLock(lockName);
- }
-
- public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName,
- String primaryKey, PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
- return musicCore.atomicPutWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
- }
-
- public static ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
- return musicCore.atomicGetWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject);
- }
-
- public static Map<String, Object> validateLock(String lockName) {
- return musicCore.validateLock(lockName);
- }
-
- public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) {
- return musicCore.releaseLock(lockId, voluntaryRelease);
- }
-
-
-} \ No newline at end of file
diff --git a/src/main/java/org/onap/music/main/MusicDigest.java b/src/main/java/org/onap/music/main/MusicDigest.java
deleted file mode 100644
index d05969e3..00000000
--- a/src/main/java/org/onap/music/main/MusicDigest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * 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.music.main;
-
-/**
- *
- *
- */
-public class MusicDigest {
- private String evPutStatus;
- private String vectorTs;
-
- /**
- * @param evPutStatus
- * @param vectorTs
- */
- public MusicDigest(String evPutStatus, String vectorTs) {
- this.evPutStatus = evPutStatus;
- this.vectorTs = vectorTs;
- }
-
- /**
- * @return
- */
- public String getEvPutStatus() {
- return evPutStatus;
- }
-
- /**
- * @param evPutStatus
- */
- public void setEvPutStatus(String evPutStatus) {
- this.evPutStatus = evPutStatus;
- }
-
- /**
- * @return
- */
- public String getVectorTs() {
- return vectorTs;
- }
-
- /**
- * @param vectorTs
- */
- public void setVectorTs(String vectorTs) {
- this.vectorTs = vectorTs;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return vectorTs + "|" + evPutStatus;
- }
-}
-
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
deleted file mode 100755
index b737377d..00000000
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ /dev/null
@@ -1,846 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * Modifications Copyright (c) 2018 IBM.
- * Modifications Copyright (c) 2019 Samsung.
- * ===================================================================
- * 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.music.main;
-
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Scanner;
-import java.util.StringTokenizer;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.service.MusicCoreService;
-import org.onap.music.service.impl.MusicCassaCore;
-
-import com.datastax.driver.core.ConsistencyLevel;
-import com.datastax.driver.core.DataType;
-import com.sun.jersey.core.util.Base64;
-
-/**
- * @author nelson24
- *
- * Properties This will take Properties and load them into MusicUtil.
- * This is a hack for now. Eventually it would bebest to do this in
- * another way.
- *
- */
-public class MusicUtil {
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
-
- public static final String ATOMIC = "atomic";
- public static final String EVENTUAL = "eventual";
- public static final String CRITICAL = "critical";
- public static final String EVENTUAL_NB = "eventual_nb";
- public static final String ALL = "all";
- public static final String QUORUM = "quorum";
- public static final String ONE = "one";
- public static final String ATOMICDELETELOCK = "atomic_delete_lock";
- public static final String DEFAULTKEYSPACENAME = "TBD";
- private static final String XLATESTVERSION = "X-latestVersion";
- private static final String XMINORVERSION = "X-minorVersion";
- private static final String XPATCHVERSION = "X-patchVersion";
- public static final String SELECT = "select";
- public static final String INSERT = "insert";
- public static final String UPDATE = "update";
- public static final String UPSERT = "upsert";
- public static final String USERID = "userId";
- public static final String PASSWORD = "password";
- public static final String CASSANDRA = "cassandra";
-
- public static final String AUTHORIZATION = "Authorization";
-
- private static final String LOCALHOST = "localhost";
- private static final String PROPERTIES_FILE = "/opt/app/music/etc/music.properties";
-
- private static int myId = 0;
- private static ArrayList<String> allIds = new ArrayList<>();
- private static String publicIp = "";
- private static ArrayList<String> allPublicIps = new ArrayList<>();
- private static String myZkHost = LOCALHOST;
- private static String myCassaHost = LOCALHOST;
- private static String defaultMusicIp = LOCALHOST;
- private static int cassandraPort = 9042;
- private static int notifytimeout = 30000;
- private static int notifyinterval = 5000;
- private static int cacheObjectMaxLife = -1;
- private static String lockUsing = MusicUtil.CASSANDRA;
- private static boolean isCadi = false;
-
- private static boolean debug = true;
- private static String version = "2.3.0";
- private static String musicRestIp = LOCALHOST;
- private static String musicPropertiesFilePath = PROPERTIES_FILE;
- private static long defaultLockLeasePeriod = 6000;
- private static final String[] propKeys = new String[] { "cassandra.host", "music.ip", "debug",
- "version", "music.rest.ip", "music.properties", "lock.lease.period", "id", "all.ids", "public.ip",
- "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url","admin.username","admin.password","aaf.admin.url",
- "music.namespace","admin.aaf.role","cassandra.port","lock.using"};
- private static final String[] cosistencyLevel = new String[] {
- "ALL","EACH_QUORUM","QUORUM","LOCAL_QUORUM","ONE","TWO","THREE","LOCAL_ONE","ANY","SERIAL","LOCAL_SERIAL"};
- private static final Map<String,ConsistencyLevel> consistencyName = new HashMap<>();
- static {
- consistencyName.put("ONE",ConsistencyLevel.ONE);
- consistencyName.put("TWO",ConsistencyLevel.TWO);
- consistencyName.put("THREE",ConsistencyLevel.THREE);
- consistencyName.put("SERIAL",ConsistencyLevel.SERIAL);
- consistencyName.put("ALL",ConsistencyLevel.ALL);
- consistencyName.put("EACH_QUORUM",ConsistencyLevel.EACH_QUORUM);
- consistencyName.put("QUORUM",ConsistencyLevel.QUORUM);
- consistencyName.put("LOCAL_QUORUM",ConsistencyLevel.LOCAL_QUORUM);
- consistencyName.put("LOCAL_ONE",ConsistencyLevel.LOCAL_ONE);
- consistencyName.put("LOCAL_SERIAL",ConsistencyLevel.LOCAL_SERIAL);
- }
-
- private static String cassName = "cassandra";
- private static String cassPwd;
- private static String aafEndpointUrl = null;
- public static ConcurrentMap<String, Long> zkNodeMap = new ConcurrentHashMap<>();
- private static String adminId = "username";
- private static String adminPass= "password";
- private static String aafAdminUrl= null;
- private static String musicNamespace= "com.att.music.api";
- private static String adminAafRole= "com.att.music.api.admin_api";
-
- public static final long MusicEternityEpochMillis = 1533081600000L; // Wednesday, August 1, 2018 12:00:00 AM
-
- public static final long MaxLockReferenceTimePart = 1000000000000L; // millis after eternity (eq sometime in 2050)
-
- public static final long MaxCriticalSectionDurationMillis = 1L * 24 * 60 * 60 * 1000; // 1 day
-
-
- public static String getLockUsing() {
- return lockUsing;
- }
-
-
- public static void setLockUsing(String lockUsing) {
- MusicUtil.lockUsing = lockUsing;
- }
-
- public static String getAafAdminUrl() {
- return aafAdminUrl;
- }
-
-
- public static void setAafAdminUrl(String aafAdminUrl) {
- MusicUtil.aafAdminUrl = aafAdminUrl;
- }
-
-
- public static String getMusicNamespace() {
- return musicNamespace;
- }
-
-
- public static void setMusicNamespace(String musicNamespace) {
- MusicUtil.musicNamespace = musicNamespace;
- }
-
-
- public static String getAdminAafRole() {
- return adminAafRole;
- }
-
-
- public static void setAdminAafRole(String adminAafRole) {
- MusicUtil.adminAafRole = adminAafRole;
- }
-
-
-
- public static String getAdminId() {
- return adminId;
- }
-
-
- public static void setAdminId(String adminId) {
- MusicUtil.adminId = adminId;
- }
-
-
- public static String getAdminPass() {
- return adminPass;
- }
-
- public static void setAdminPass(String adminPass) {
- MusicUtil.adminPass = adminPass;
- }
-
-
- private MusicUtil() {
- throw new IllegalStateException("Utility Class");
- }
- /**
- *
- * @return cassandra port
- */
- public static int getCassandraPort() {
- return cassandraPort;
- }
-
- /**
- * set cassandra port
- * @param cassandraPort
- */
- public static void setCassandraPort(int cassandraPort) {
- MusicUtil.cassandraPort = cassandraPort;
- }
- /**
- * @return the cassName
- */
- public static String getCassName() {
- return cassName;
- }
-
- /**
- * @return the cassPwd
- */
- public static String getCassPwd() {
- return cassPwd;
- }
-
- /**
- * @return the aafEndpointUrl
- */
- public static String getAafEndpointUrl() {
- return aafEndpointUrl;
- }
-
- /**
- *
- * @param aafEndpointUrl
- */
- public static void setAafEndpointUrl(String aafEndpointUrl) {
- MusicUtil.aafEndpointUrl = aafEndpointUrl;
- }
-
- /**
- *
- * @return
- */
- public static int getMyId() {
- return myId;
- }
-
- /**
- *
- * @param myId
- */
- public static void setMyId(int myId) {
- MusicUtil.myId = myId;
- }
-
- /**
- *
- * @return
- */
- public static List<String> getAllIds() {
- return allIds;
- }
-
- /**
- *
- * @param allIds
- */
- public static void setAllIds(List<String> allIds) {
- MusicUtil.allIds = (ArrayList<String>) allIds;
- }
-
- /**
- *
- * @return
- */
- public static String getPublicIp() {
- return publicIp;
- }
-
- /**
- *
- * @param publicIp
- */
- public static void setPublicIp(String publicIp) {
- MusicUtil.publicIp = publicIp;
- }
-
- /**
- *
- * @return
- */
- public static List<String> getAllPublicIps() {
- return allPublicIps;
- }
-
- /**
- *
- * @param allPublicIps
- */
- public static void setAllPublicIps(List<String> allPublicIps) {
- MusicUtil.allPublicIps = (ArrayList<String>) allPublicIps;
- }
-
- /**
- * Returns An array of property names that should be in the Properties
- * files.
- *
- * @return
- */
- public static String[] getPropkeys() {
- return propKeys;
- }
-
- /**
- * Get MusicRestIp - default = localhost property file value - music.rest.ip
- *
- * @return
- */
- public static String getMusicRestIp() {
- return musicRestIp;
- }
-
- /**
- * Set MusicRestIp
- *
- * @param musicRestIp
- */
- public static void setMusicRestIp(String musicRestIp) {
- MusicUtil.musicRestIp = musicRestIp;
- }
-
- /**
- * Get MusicPropertiesFilePath - Default = /opt/music/music.properties
- * property file value - music.properties
- *
- * @return
- */
- public static String getMusicPropertiesFilePath() {
- return musicPropertiesFilePath;
- }
-
- /**
- * Set MusicPropertiesFilePath
- *
- * @param musicPropertiesFilePath
- */
- public static void setMusicPropertiesFilePath(String musicPropertiesFilePath) {
- MusicUtil.musicPropertiesFilePath = musicPropertiesFilePath;
- }
-
- /**
- * Get DefaultLockLeasePeriod - Default = 6000 property file value -
- * lock.lease.period
- *
- * @return
- */
- public static long getDefaultLockLeasePeriod() {
- return defaultLockLeasePeriod;
- }
-
- /**
- * Set DefaultLockLeasePeriod
- *
- * @param defaultLockLeasePeriod
- */
- public static void setDefaultLockLeasePeriod(long defaultLockLeasePeriod) {
- MusicUtil.defaultLockLeasePeriod = defaultLockLeasePeriod;
- }
-
- /**
- * Set Debug
- *
- * @param debug
- */
- public static void setDebug(boolean debug) {
- MusicUtil.debug = debug;
- }
-
- /**
- * Is Debug - Default = true property file value - debug
- *
- * @return
- */
- public static boolean isDebug() {
- return debug;
- }
-
- /**
- * Set Version
- *
- * @param version
- */
- public static void setVersion(String version) {
- MusicUtil.version = version;
- }
-
- /**
- * Return the version property file value - version
- *
- * @return
- */
- public static String getVersion() {
- return version;
- }
-
- /**
- * Get MyCassHost - Cassandra Hostname - Default = localhost property file
- * value - cassandra.host
- *
- * @return
- */
- public static String getMyCassaHost() {
- return myCassaHost;
- }
-
- /**
- * Set MyCassHost - Cassandra Hostname
- *
- * @param myCassaHost
- */
- public static void setMyCassaHost(String myCassaHost) {
- MusicUtil.myCassaHost = myCassaHost;
- }
-
- /**
- * Get DefaultMusicIp - Default = localhost property file value - music.ip
- *
- * @return
- */
- public static String getDefaultMusicIp() {
- return defaultMusicIp;
- }
-
- /**
- * Set DefaultMusicIp
- *
- * @param defaultMusicIp
- */
- public static void setDefaultMusicIp(String defaultMusicIp) {
- MusicUtil.defaultMusicIp = defaultMusicIp;
- }
-
- /**
- *
- * @return
- */
- public static String getTestType() {
- String testType = "";
- try {
- Scanner fileScanner = new Scanner(new File(""));
- testType = fileScanner.next();// ignore the my id line
- @SuppressWarnings("unused")
- String batchSize = fileScanner.next();// ignore the my public ip
- // line
- fileScanner.close();
- } catch (FileNotFoundException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
- return testType;
-
- }
-
- /**
- *
- * @param time
- */
- public static void sleep(long time) {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- Thread.currentThread().interrupt();
- }
- }
-
- /**
- * Utility function to check if the query object is valid.
- *
- * @param withparams
- * @param queryObject
- * @return
- */
- public static boolean isValidQueryObject(boolean withparams, PreparedQueryObject queryObject) {
- if (withparams) {
- int noOfValues = queryObject.getValues().size();
- int noOfParams = 0;
- char[] temp = queryObject.getQuery().toCharArray();
- for (int i = 0; i < temp.length; i++) {
- if (temp[i] == '?')
- noOfParams++;
- }
- return (noOfValues == noOfParams);
- } else {
- return !queryObject.getQuery().isEmpty();
- }
-
- }
-
- public static void setCassName(String cassName) {
- MusicUtil.cassName = cassName;
- }
-
- public static void setCassPwd(String cassPwd) {
- MusicUtil.cassPwd = cassPwd;
- }
-
- @SuppressWarnings("unchecked")
- public static String convertToCQLDataType(DataType type, Object valueObj) throws Exception {
-
- String value = "";
- switch (type.getName()) {
- case UUID:
- value = valueObj + "";
- break;
- case TEXT:
- case VARCHAR:
- String valueString = valueObj + "";
- valueString = valueString.replace("'", "''");
- value = "'" + valueString + "'";
- break;
- case MAP: {
- Map<String, Object> otMap = (Map<String, Object>) valueObj;
- value = "{" + jsonMaptoSqlString(otMap, ",") + "}";
- break;
- }
- default:
- value = valueObj + "";
- break;
- }
- return value;
- }
-
- /**
- *
- * @param colType
- * @param valueObj
- * @return
- * @throws MusicTypeConversionException
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public static Object convertToActualDataType(DataType colType, Object valueObj) throws Exception {
- String valueObjString = valueObj + "";
- switch (colType.getName()) {
- case UUID:
- return UUID.fromString(valueObjString);
- case VARINT:
- return BigInteger.valueOf(Long.parseLong(valueObjString));
- case BIGINT:
- return Long.parseLong(valueObjString);
- case INT:
- return Integer.parseInt(valueObjString);
- case FLOAT:
- return Float.parseFloat(valueObjString);
- case DOUBLE:
- return Double.parseDouble(valueObjString);
- case BOOLEAN:
- return Boolean.parseBoolean(valueObjString);
- case MAP:
- return (Map<String, Object>) valueObj;
- case LIST:
- return (List<Object>)valueObj;
- case BLOB:
-
- default:
- return valueObjString;
- }
- }
-
- public static ByteBuffer convertToActualDataType(DataType colType, byte[] valueObj) {
- ByteBuffer buffer = ByteBuffer.wrap(valueObj);
- return buffer;
- }
-
- /**
- *
- * Utility function to parse json map into sql like string
- *
- * @param jMap
- * @param lineDelimiter
- * @return
- */
-
- public static String jsonMaptoSqlString(Map<String, Object> jMap, String lineDelimiter) throws Exception{
- StringBuilder sqlString = new StringBuilder();
- int counter = 0;
- for (Map.Entry<String, Object> entry : jMap.entrySet()) {
- Object ot = entry.getValue();
- String value = ot + "";
- if (ot instanceof String) {
- value = "'" + value.replace("'", "''") + "'";
- }
- sqlString.append("'" + entry.getKey() + "':" + value);
- if (counter != jMap.size() - 1)
- sqlString.append(lineDelimiter);
- counter = counter + 1;
- }
- return sqlString.toString();
- }
-
- @SuppressWarnings("unused")
- public static String buildVersion(String major, String minor, String patch) {
- if (minor != null) {
- major += "." + minor;
- if (patch != null) {
- major += "." + patch;
- }
- }
- return major;
- }
-
- /**
- * Currently this will build a header with X-latestVersion, X-minorVersion and X-pathcVersion
- * X-latestVerstion will be equal to the latest full version.
- * X-minorVersion - will be equal to the latest minor version.
- * X-pathVersion - will be equal to the latest patch version.
- * Future plans will change this.
- * @param response
- * @param major
- * @param minor
- * @param patch
- * @return
- */
- public static ResponseBuilder buildVersionResponse(String major, String minor, String patch) {
- ResponseBuilder response = Response.noContent();
- String versionIn = buildVersion(major,minor,patch);
- String version = MusicUtil.getVersion();
- String[] verArray = version.split("\\.",3);
- if ( minor != null ) {
- response.header(XMINORVERSION,minor);
- } else {
- response.header(XMINORVERSION,verArray[1]);
- }
- if ( patch != null ) {
- response.header(XPATCHVERSION,patch);
- } else {
- response.header(XPATCHVERSION,verArray[2]);
- }
- response.header(XLATESTVERSION,version);
- logger.info(EELFLoggerDelegate.applicationLogger,"Version In:" + versionIn);
- return response;
- }
-
-
- public static Map<String,String> extractBasicAuthentication(String authorization){
- Map<String,String> authValues = new HashMap<>();
- if(authorization == null) {
- authValues.put("ERROR", "Authorization cannot be null");
- return authValues;
- }
- authorization = authorization.replaceFirst("Basic", "");
- String decoded = Base64.base64Decode(authorization);
- StringTokenizer token = new StringTokenizer(decoded, ":");
- authValues.put(MusicUtil.USERID, token.nextToken());
- authValues.put(MusicUtil.PASSWORD,token.nextToken());
- return authValues;
-
- }
-
- public static boolean isValidConsistency(String consistency) {
- for (String string : cosistencyLevel) {
- if (string.equalsIgnoreCase(consistency))
- return true;
- }
- return false;
-
- }
-
- public static ConsistencyLevel getConsistencyLevel(String consistency) {
- return consistencyName.get(consistency.toUpperCase());
- }
-
- public static void loadProperties() throws Exception {
- Properties prop = new Properties();
- InputStream input = null;
- try {
- // load the properties file
- input = MusicUtil.class.getClassLoader().getResourceAsStream("music.properties");
- prop.load(input);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Unable to find properties file.");
- throw new Exception();
- } finally {
- if (input != null) {
- try {
- input.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- // get the property value and return it
- MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
- MusicUtil.setCassName(prop.getProperty("cassandra.user"));
- MusicUtil.setCassPwd(prop.getProperty("cassandra.password"));
- MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty("cassandra.port")));
- MusicUtil.setNotifyTimeOut(Integer.parseInt(prop.getProperty("notify.timeout")));
- MusicUtil.setNotifyInterval(Integer.parseInt(prop.getProperty("notify.interval")));
- MusicUtil.setCacheObjectMaxLife(Integer.parseInt(prop.getProperty("cacheobject.maxlife")));
- }
-
- public static void setNotifyInterval(int notifyinterval) {
- MusicUtil.notifyinterval = notifyinterval;
- }
- public static void setNotifyTimeOut(int notifytimeout) {
- MusicUtil.notifytimeout = notifytimeout;
- }
-
- public static int getNotifyInterval() {
- return MusicUtil.notifyinterval;
- }
-
- public static int getNotifyTimeout() {
- return MusicUtil.notifytimeout;
- }
-
- public static int getCacheObjectMaxLife() {
- return MusicUtil.cacheObjectMaxLife;
- }
-
- public static void setCacheObjectMaxLife(int cacheObjectMaxLife) {
- MusicUtil.cacheObjectMaxLife = cacheObjectMaxLife;
- }
-
- /**
- * Given the time of write for an update in a critical section, this method provides a transformed timestamp
- * that ensures that a previous lock holder who is still alive can never corrupt a later critical section.
- * The main idea is to us the lock reference to clearly demarcate the timestamps across critical sections.
- * @param the UUID lock reference associated with the write.
- * @param the long timeOfWrite which is the actual time at which the write took place
- * @throws MusicServiceException
- * @throws MusicQueryException
- */
- public static long v2sTimeStampInMicroseconds(long ordinal, long timeOfWrite) throws MusicServiceException, MusicQueryException {
- // TODO: use acquire time instead of music eternity epoch
- long ts = ordinal * MaxLockReferenceTimePart + (timeOfWrite - MusicEternityEpochMillis);
-
- return ts;
- }
-
- public static MusicCoreService getMusicCoreService() {
- if(getLockUsing().equals(MusicUtil.CASSANDRA))
- return MusicCassaCore.getInstance();
- else
- return MusicCassaCore.getInstance();
- }
-
- /**
- * @param lockName
- * @return
- */
- public static Map<String, Object> validateLock(String lockName) {
- Map<String, Object> resultMap = new HashMap<>();
- String[] locks = lockName.split("\\.");
- if(locks.length < 3) {
- resultMap.put("Error", "Invalid lock. Please make sure lock is of the type keyspaceName.tableName.primaryKey");
- return resultMap;
- }
- String keyspace= locks[0];
- if(keyspace.startsWith("$"))
- keyspace = keyspace.substring(1);
- resultMap.put("keyspace",keyspace);
- return resultMap;
- }
-
-
- public static void setIsCadi(boolean isCadi) {
- MusicUtil.isCadi = isCadi;
- }
-
- public static void writeBackToQuorum(PreparedQueryObject selectQuery, String primaryKeyName,
- PreparedQueryObject updateQuery, String keyspace, String table,
- Object cqlFormattedPrimaryKeyValue)
- throws Exception {
- try {
- ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(selectQuery);
- // write it back to a quorum
- Row row = results.one();
- ColumnDefinitions colInfo = row.getColumnDefinitions();
- int totalColumns = colInfo.size();
- int counter = 1;
- StringBuilder fieldValueString = new StringBuilder("");
- for (Definition definition : colInfo) {
- String colName = definition.getName();
- if (colName.equals(primaryKeyName))
- continue;
- DataType colType = definition.getType();
- Object valueObj = MusicDataStoreHandle.getDSHandle().getColValue(row, colName, colType);
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- fieldValueString.append(colName + " = ?");
- updateQuery.addValue(valueString);
- if (counter != (totalColumns - 1))
- fieldValueString.append(",");
- counter = counter + 1;
- }
- updateQuery.appendQueryString("UPDATE " + keyspace + "." + table + " SET "
- + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
- updateQuery.addValue(cqlFormattedPrimaryKeyValue);
-
- MusicDataStoreHandle.getDSHandle().executePut(updateQuery, "critical");
- } catch (MusicServiceException | MusicQueryException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery ,
- ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR);
- }
- }
-
- public static boolean getIsCadi() {
- return MusicUtil.isCadi;
- }
-
-
- /**
- * @return a random uuid
- */
- public static String generateUUID() {
- String uuid = UUID.randomUUID().toString();
- logger.info(EELFLoggerDelegate.applicationLogger,"New AID generated: "+uuid);
- return uuid;
- }
-
-}
-
diff --git a/src/main/java/org/onap/music/main/PropertiesLoader.java b/src/main/java/org/onap/music/main/PropertiesLoader.java
deleted file mode 100644
index db04ff4b..00000000
--- a/src/main/java/org/onap/music/main/PropertiesLoader.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * 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.music.main;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.PropertySource;
-import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
-import org.springframework.stereotype.Component;
-
-@PropertySource(value = {"file:/opt/app/music/etc/music.properties", "classpath:/project.properties"})
-@Component
-public class PropertiesLoader implements InitializingBean {
-
- @Value("${cassandra.host}")
- public String cassandraHost;
-
- @Value("${music.ip}")
- public String musicIp;
-
- @Value("${debug}")
- public String debug;
-
- @Value("${version}")
- public String version;
-
- @Value("${music.rest.ip}")
- public String musicRestIp;
-
- @Value("${music.properties}")
- public String musicProperties;
-
- @Value("${lock.lease.period}")
- public String lockLeasePeriod;
-
- @Value("${public.ip}")
- public String publicIp;
-
- @Value("${my.id}")
- public String myId;
-
- @Value("${all.ids}")
- public String allIds;
-
- @Value("${all.public.ips}")
- public String allPublicIps;
-
- @Value("${cassandra.user}")
- public String cassandraUser;
-
- @Value("${cassandra.password}")
- public String cassandraPassword;
-
- @Value("${aaf.endpoint.url}")
- public String aafEndpointUrl;
-
- @Value("${admin.username}")
- public String adminUsername;
-
- @Value("${admin.password}")
- public String adminPassword;
-
- @Value("${cassandra.port}")
- public String cassandraPort;
-
- @Value("${aaf.admin.url}")
- public String aafAdminUrl;
-
- @Value("${music.namespace}")
- public String musicNamespace;
-
- @Value("${admin.aaf.role}")
- public String adminAafRole;
-
- @Value("${notify.interval}")
- public String notifyInterval;
-
- @Value("${notify.timeout}")
- public String notifyTimeout;
-
- @Value("${cadi}")
- public String isCadi;
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesLoader.class);
-
- @Bean
- public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
- //return new PropertySourcesPlaceholderConfigurer();
- PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
- pspc.setIgnoreResourceNotFound(true);
- pspc.setIgnoreUnresolvablePlaceholders(true);
- return pspc;
- }
-
- public void loadProperties () {
- if(aafAdminUrl != null && !aafAdminUrl.equals("${aaf.admin.url}"))
- MusicUtil.setAafAdminUrl(aafAdminUrl);
- if(aafEndpointUrl != null && !aafEndpointUrl.equals("${aaf.endpoint.url}"))
- MusicUtil.setAafEndpointUrl(aafEndpointUrl);
- if(adminAafRole != null && !adminAafRole.equals("${admin.aaf.role}"))
- MusicUtil.setAdminAafRole(adminAafRole);
- //MusicUtil.setAdminId(adminId);
- if(adminPassword != null && !adminPassword.equals("${admin.password}"))
- MusicUtil.setAdminPass(adminPassword);
- if(adminUsername != null && !adminUsername.equals("${admin.username}"))
- MusicUtil.setAdminId(adminUsername);
- if(allIds != null && !allIds.equals("${all.ids}")) {
- String[] ids = allIds.split(":");
- MusicUtil.setAllIds(new ArrayList<String>(Arrays.asList(ids)));
- }
- if(allPublicIps != null && !allPublicIps.equals("${all.public.ips}")) {
- String[] ips = allPublicIps.split(":");
- if (ips.length == 1) {
- // Future use
- } else if (ips.length > 1) {
- MusicUtil.setAllPublicIps(
- new ArrayList<String>(Arrays.asList(ips)));
- }
- }
- if(cassandraPort != null && !cassandraPort.equals("${cassandra.port}"))
- MusicUtil.setCassandraPort(Integer.parseInt(cassandraPort));
- if(cassandraUser != null && !cassandraUser.equals("${cassandra.user}"))
- MusicUtil.setCassName(cassandraUser);
- if(cassandraPassword != null && !cassandraPassword.equals("${cassandra.password}"))
- MusicUtil.setCassPwd(cassandraPassword);
- if(debug != null && !debug.equals("${debug}"))
- MusicUtil.setDebug(Boolean.parseBoolean(debug));
- if(lockLeasePeriod != null && !lockLeasePeriod.equals("${lock.lease.period}"))
- MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(lockLeasePeriod));
- if(musicIp != null && !musicIp.equals("${music.ip}"))
- MusicUtil.setDefaultMusicIp(musicIp);
- if(musicNamespace != null && !musicNamespace.equals("${music.namespace}"))
- MusicUtil.setMusicNamespace(musicNamespace);
- if(musicProperties != null && !musicProperties.equals("${music.properties}"))
- MusicUtil.setMusicPropertiesFilePath(musicProperties);
- if(musicRestIp != null && !musicRestIp.equals("${music.rest.ip}"))
- MusicUtil.setMusicRestIp(musicRestIp);
- if(cassandraHost != null && !cassandraHost.equals("${cassandra.host}"))
- MusicUtil.setMyCassaHost(cassandraHost);
- logger.info("#### Cassandra Host: " + MusicUtil.getMyCassaHost());
- if(myId != null && !myId.equals("${my.id}"))
- MusicUtil.setMyId(Integer.parseInt(myId));
- if(notifyInterval != null && !notifyInterval.equals("${notify.interval}"))
- MusicUtil.setNotifyInterval(Integer.parseInt(notifyInterval));
- if(notifyTimeout != null && !notifyTimeout.equals("${notify.timeout}"))
- MusicUtil.setNotifyTimeOut(Integer.parseInt(notifyTimeout));
- if(allPublicIps != null && !allPublicIps.equals("${public.ip}"))
- MusicUtil.setPublicIp(allPublicIps);
- if(version != null && !version.equals("${version}"))
- MusicUtil.setVersion(version);
- if(isCadi != null && !isCadi.equals("${cadi}"))
- MusicUtil.setIsCadi(Boolean.parseBoolean(isCadi));
- }
-
-
- @Override
- public void afterPropertiesSet() throws Exception {
- // TODO Auto-generated method stub
-
- }
-
-}
diff --git a/src/main/java/org/onap/music/main/ResultType.java b/src/main/java/org/onap/music/main/ResultType.java
deleted file mode 100644
index f5ef2070..00000000
--- a/src/main/java/org/onap/music/main/ResultType.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * 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.music.main;
-
-public enum ResultType {
- SUCCESS("Success"), FAILURE("Failure"),
- SYNTAXERROR("SyntaxError"), EXCEPTION("Exception"),
- BODYMISSING("Incomplete Request body. Please correct your input request and retry.");
-
- private String result;
-
- ResultType(String result) {
- this.result = result;
- }
-
- public String getResult() {
- return result;
- }
-
-}
-
-
diff --git a/src/main/java/org/onap/music/main/ReturnType.java b/src/main/java/org/onap/music/main/ReturnType.java
deleted file mode 100644
index f02dabbf..00000000
--- a/src/main/java/org/onap/music/main/ReturnType.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * 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.music.main;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class ReturnType {
- private ResultType result;
- private String message;
-
- private String timingInfo;
-
- public ReturnType(ResultType result, String message) {
- super();
- this.result = result;
- this.message = message;
- }
-
- public String getTimingInfo() {
- return timingInfo;
- }
-
- public void setTimingInfo(String timingInfo) {
- this.timingInfo = timingInfo;
- }
-
- public ResultType getResult() {
- return result;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public String toJson() {
- return "{ \"result\":\"" + result.getResult() + "\", \"message\":\"" + message + "\"}";
- }
-
- public String toString() {
- return result + " | " + message;
- }
-
- public Map<String, Object> toMap() {
- Map<String, Object> newMap = new HashMap<>();
- newMap.put("result", result.getResult());
- newMap.put("message", message);
- return newMap;
- }
-
-}