aboutsummaryrefslogtreecommitdiffstats
path: root/music-rest/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'music-rest/src/main/java')
-rwxr-xr-xmusic-rest/src/main/java/org/onap/music/MusicApplication.java5
-rw-r--r--music-rest/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java30
-rw-r--r--music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java31
3 files changed, 57 insertions, 9 deletions
diff --git a/music-rest/src/main/java/org/onap/music/MusicApplication.java b/music-rest/src/main/java/org/onap/music/MusicApplication.java
index 22c9e7bf..0fe354d9 100755
--- a/music-rest/src/main/java/org/onap/music/MusicApplication.java
+++ b/music-rest/src/main/java/org/onap/music/MusicApplication.java
@@ -33,6 +33,7 @@ import org.onap.music.authentication.CadiAuthFilter;
import org.onap.music.authentication.MusicAuthorizationFilter;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.MusicLoggingServletFilter;
+import org.onap.music.lockingservice.cassandra.LockCleanUpDaemon;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.PropertiesLoader;
import org.springframework.beans.factory.annotation.Autowired;
@@ -66,6 +67,10 @@ public class MusicApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
new MusicApplication().configure(new SpringApplicationBuilder(MusicApplication.class)).run(args);
+
+ LockCleanUpDaemon daemon = new LockCleanUpDaemon();
+ daemon.setDaemon(true);
+ daemon.start();
}
@Override
diff --git a/music-rest/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java b/music-rest/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
index ebaa3a1f..2c69c435 100644
--- a/music-rest/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
+++ b/music-rest/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
@@ -142,11 +142,20 @@ public class MusicConditional {
return new ReturnType(ResultType.FAILURE, e.getMessage());
}
if (results.all().isEmpty()) {
- MusicDataStoreHandle.getDSHandle().executePut(queryBank.get(MusicUtil.INSERT), "critical");
- return new ReturnType(ResultType.SUCCESS, "insert");
+ PreparedQueryObject qObject = queryBank.get(MusicUtil.INSERT);
+ qObject.setOperation(MusicUtil.INSERT);
+ logger.info(EELFLoggerDelegate.debugLogger,"### Conditional Insert");
+ MusicCore.criticalPut(keyspace, tableName, primaryKey, qObject, lockId, null);
+ //MusicDataStoreHandle.getDSHandle().executePut(queryBank.get(MusicUtil.INSERT), "critical");
+ return new ReturnType(ResultType.SUCCESS, MusicUtil.INSERT);
+
} else {
- MusicDataStoreHandle.getDSHandle().executePut(queryBank.get(MusicUtil.UPDATE), "critical");
- return new ReturnType(ResultType.SUCCESS, "update");
+ PreparedQueryObject qObject = queryBank.get(MusicUtil.UPDATE);
+ qObject.setOperation(MusicUtil.UPDATE);
+ logger.info(EELFLoggerDelegate.debugLogger,"### Condition Update");
+ MusicCore.criticalPut(keyspace, tableName, primaryKey, qObject, lockId, null);
+ //MusicDataStoreHandle.getDSHandle().executePut(queryBank.get(MusicUtil.UPDATE), "critical");
+ return new ReturnType(ResultType.SUCCESS, MusicUtil.UPDATE);
}
} else {
return new ReturnType(ResultType.FAILURE,
@@ -214,13 +223,15 @@ public class MusicConditional {
JSONObject json = new JSONObject(updatedValues);
PreparedQueryObject update = new PreparedQueryObject();
String vector_ts = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- update.appendQueryString("UPDATE " + dataObj.getKeyspace() + "." + dataObj.getTableName() + " SET " + dataObj.getCascadeColumnName() + "['" + dataObj.getPlanId()
+ update.appendQueryString("UPDATE " + dataObj.getKeyspace() + "." + dataObj.getTableName() + " SET "
+ + dataObj.getCascadeColumnName() + "['" + dataObj.getPlanId()
+ "'] = ?, vector_ts = ? WHERE " + dataObj.getPrimaryKey() + " = ?");
update.addValue(MusicUtil.convertToActualDataType(DataType.text(), json.toString()));
update.addValue(MusicUtil.convertToActualDataType(DataType.text(), vector_ts));
update.addValue(MusicUtil.convertToActualDataType(DataType.text(), dataObj.getPrimaryKeyValue()));
try {
- MusicDataStoreHandle.getDSHandle().executePut(update, "critical");
+ update.setOperation(MusicUtil.UPDATE);
+ MusicCore.criticalPut(dataObj.keyspace, dataObj.tableName, dataObj.primaryKeyValue, update, dataObj.lockId, null);
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.applicationLogger, ex);
return new ReturnType(ResultType.FAILURE, ex.getMessage());
@@ -228,9 +239,10 @@ public class MusicConditional {
}else {
return new ReturnType(ResultType.FAILURE,"Cannot find data related to key: "+dataObj.getPrimaryKey());
}
- MusicDataStoreHandle.getDSHandle().executePut(dataObj.getQueryBank().get(MusicUtil.UPSERT), "critical");
+ PreparedQueryObject qObject = dataObj.getQueryBank().get(MusicUtil.UPSERT);
+ qObject.setOperation(MusicUtil.INSERT);
+ MusicCore.criticalPut(dataObj.keyspace, dataObj.tableName, dataObj.primaryKeyValue, qObject, dataObj.lockId, null);
return new ReturnType(ResultType.SUCCESS, "update success");
-
} else {
return new ReturnType(ResultType.FAILURE,
"Cannot perform operation since you are the not the lock holder");
@@ -322,7 +334,7 @@ public class MusicConditional {
counter = counter + 1;
}
queryObject.appendQueryString("INSERT INTO " + keySpaceName + "." + tableName + " "
- + fieldsString + " VALUES " + valueString);
+ + fieldsString + " VALUES " + valueString + ";");
return queryObject;
}
diff --git a/music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java b/music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java
index 6fbc76a7..9c69b9e2 100644
--- a/music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java
+++ b/music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java
@@ -22,6 +22,7 @@
package org.onap.music.main;
+import java.util.HashSet;
import java.util.Properties;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
@@ -77,7 +78,19 @@ public class PropertiesLoader implements InitializingBean {
@Value("${retry.count}")
public String rertryCount;
+
+ @Value("${lock.daemon.sleeptime.ms}")
+ public String lockDaemonSleeptimems;
+ @Value("${keyspaces.for.lock.cleanup}")
+ public String keyspacesForLockCleanup;
+
+ @Value("${create.lock.wait.period.ms}")
+ private long createLockWaitPeriod;
+
+ @Value("${create.lock.wait.increment.ms}")
+ private int createLockWaitIncrement;
+
@Value("${transId.header.prefix}")
private String transIdPrefix;
@@ -172,6 +185,16 @@ public class PropertiesLoader implements InitializingBean {
if (isKeyspaceActive != null && !isKeyspaceActive.equals("${keyspace.active}")) {
MusicUtil.setKeyspaceActive(Boolean.parseBoolean(isKeyspaceActive));
}
+ if (lockDaemonSleeptimems != null && !lockDaemonSleeptimems.equals("${lock.daemon.sleeptime.ms}")) {
+ MusicUtil.setLockDaemonSleepTimeMs(Long.parseLong(lockDaemonSleeptimems));
+ }
+ if (keyspacesForLockCleanup !=null && !keyspacesForLockCleanup.equals("${keyspaces.for.lock.cleanup}")) {
+ HashSet<String> keyspaces = new HashSet<>();
+ for (String keyspace: keyspacesForLockCleanup.split(",")) {
+ keyspaces.add(keyspace);
+ }
+ MusicUtil.setKeyspacesToCleanLocks(keyspaces);
+ }
if(transIdPrefix!=null) {
MusicUtil.setTransIdPrefix(transIdPrefix);
}
@@ -203,6 +226,14 @@ public class PropertiesLoader implements InitializingBean {
if(messageIdRequired!=null) {
MusicUtil.setMessageIdRequired(messageIdRequired);
}
+
+ if(createLockWaitPeriod!=0) {
+ MusicUtil.setCreateLockWaitPeriod(createLockWaitPeriod);
+ }
+
+ if(createLockWaitIncrement!=0) {
+ MusicUtil.setCreateLockWaitIncrement(createLockWaitIncrement);
+ }
}
public static void loadProperties(Properties properties) {