17e3fcf69aacc14d9acec94e5c208ce2016e3cf1
[music.git] / src / main / java / org / onap / music / main / MusicUtil.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  * ===================================================================
7  *  Modifications Copyright (c) 2018 IBM.
8  *  Modifications Copyright (c) 2019 Samsung.
9  * ===================================================================
10  *  Licensed under the Apache License, Version 2.0 (the "License");
11  *  you may not use this file except in compliance with the License.
12  *  You may obtain a copy of the License at
13  *
14  *     http://www.apache.org/licenses/LICENSE-2.0
15  *
16  *  Unless required by applicable law or agreed to in writing, software
17  *  distributed under the License is distributed on an "AS IS" BASIS,
18  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  *  See the License for the specific language governing permissions and
20  *  limitations under the License.
21  *
22  * ============LICENSE_END=============================================
23  * ====================================================================
24  */
25
26 package org.onap.music.main;
27
28 import com.datastax.driver.core.ColumnDefinitions;
29 import com.datastax.driver.core.ColumnDefinitions.Definition;
30 import com.datastax.driver.core.ResultSet;
31 import com.datastax.driver.core.Row;
32 import java.io.File;
33 import java.io.FileNotFoundException;
34 import java.io.IOException;
35 import java.io.InputStream;
36 import java.math.BigInteger;
37 import java.nio.ByteBuffer;
38 import java.util.ArrayList;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Map;
42 import java.util.Properties;
43 import java.util.Scanner;
44 import java.util.StringTokenizer;
45 import java.util.UUID;
46 import java.util.concurrent.ConcurrentHashMap;
47 import java.util.concurrent.ConcurrentMap;
48
49 import javax.ws.rs.core.Response;
50 import javax.ws.rs.core.Response.ResponseBuilder;
51 import org.onap.music.datastore.MusicDataStoreHandle;
52 import org.onap.music.datastore.PreparedQueryObject;
53 import org.onap.music.eelf.logging.EELFLoggerDelegate;
54 import org.onap.music.eelf.logging.format.AppMessages;
55 import org.onap.music.eelf.logging.format.ErrorSeverity;
56 import org.onap.music.eelf.logging.format.ErrorTypes;
57 import org.onap.music.exceptions.MusicQueryException;
58 import org.onap.music.exceptions.MusicServiceException;
59 import org.onap.music.service.MusicCoreService;
60 import org.onap.music.service.impl.MusicCassaCore;
61
62 import com.datastax.driver.core.ConsistencyLevel;
63 import com.datastax.driver.core.DataType;
64 import com.sun.jersey.core.util.Base64;
65
66 /**
67  * @author nelson24
68  *
69  *         Properties This will take Properties and load them into MusicUtil.
70  *         This is a hack for now. Eventually it would bebest to do this in
71  *         another way.
72  *
73  */
74 public class MusicUtil {
75     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
76
77     // Consistancy Constants
78     public static final String ATOMIC = "atomic";
79     public static final String EVENTUAL = "eventual";
80     public static final String CRITICAL = "critical";
81     public static final String EVENTUAL_NB = "eventual_nb";
82     public static final String ALL = "all";
83     public static final String QUORUM = "quorum";
84     public static final String ONE = "one";
85     public static final String ATOMICDELETELOCK = "atomic_delete_lock";
86
87     // Header Constants
88     private static final String XLATESTVERSION = "X-latestVersion";
89     private static final String XMINORVERSION = "X-minorVersion";
90     private static final String XPATCHVERSION = "X-patchVersion";
91     public static final String AUTHORIZATION = "Authorization";
92
93     // CQL Constants
94     public static final String SELECT = "select";
95     public static final String INSERT = "insert";
96     public static final String UPDATE = "update";
97     public static final String UPSERT = "upsert";
98     public static final String USERID = "userId";
99     public static final String PASSWORD = "";
100     public static final String CASSANDRA = "cassandra";
101
102     private static final String LOCALHOST = "localhost";
103     private static final String PROPERTIES_FILE = "/opt/app/music/etc/music.properties";
104     public static final String DEFAULTKEYSPACENAME = "TBD";
105
106     private static String myCassaHost = LOCALHOST;
107     private static String defaultMusicIp = LOCALHOST;
108     private static int cassandraPort = 9042;
109     private static int notifytimeout = 30000;
110     private static int notifyinterval = 5000;
111     private static long defaultLockLeasePeriod = 6000;
112     private static int retryCount = 3;
113     private static int cacheObjectMaxLife = -1;
114     private static String lockUsing = MusicUtil.CASSANDRA;
115     private static boolean isCadi = false;
116     private static boolean isKeyspaceActive = false;
117     private static boolean debug = true;
118     private static String version = "0.0.0";
119     private static String build = "";
120
121     private static String musicPropertiesFilePath = PROPERTIES_FILE;
122     private static final String[] propKeys = new String[] { "cassandra.host", "music.ip", "debug",
123         "version", "music.rest.ip", "music.properties", "lock.lease.period", "id", "all.ids", 
124         "public.ip","all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url",
125         "admin.username","admin.password","aaf.admin.url","music.namespace","admin.aaf.role",
126         "cassandra.port","lock.using","retry.count","transId.header.required",
127         "conversation.header.required","clientId.header.required","messageId.header.required",
128         "transId.header.prefix","conversation.header.prefix","clientId.header.prefix",
129         "messageId.header.prefix"};
130     private static final String[] cosistencyLevel = new String[] {
131         "ALL","EACH_QUORUM","QUORUM","LOCAL_QUORUM","ONE","TWO",
132         "THREE","LOCAL_ONE","ANY","SERIAL","LOCAL_SERIAL"};
133     private static final Map<String,ConsistencyLevel> consistencyName = new HashMap<>();
134     static {
135         consistencyName.put("ONE",ConsistencyLevel.ONE);
136         consistencyName.put("TWO",ConsistencyLevel.TWO);
137         consistencyName.put("THREE",ConsistencyLevel.THREE);
138         consistencyName.put("SERIAL",ConsistencyLevel.SERIAL);
139         consistencyName.put("ALL",ConsistencyLevel.ALL);
140         consistencyName.put("EACH_QUORUM",ConsistencyLevel.EACH_QUORUM);
141         consistencyName.put("QUORUM",ConsistencyLevel.QUORUM);
142         consistencyName.put("LOCAL_QUORUM",ConsistencyLevel.LOCAL_QUORUM);
143         consistencyName.put("LOCAL_ONE",ConsistencyLevel.LOCAL_ONE);
144         consistencyName.put("LOCAL_SERIAL",ConsistencyLevel.LOCAL_SERIAL);
145     }
146     private static String cassName = "cassandra";
147     private static String cassPwd;
148     private static String aafEndpointUrl = null;
149     private static String adminId = "username";
150     private static String adminPass= "password";
151     private static String aafAdminUrl= null;
152     private static String musicNamespace= "org.onap.music.api";
153     private static String adminAafRole= "org.onap.music.api.admin_api";
154
155     public static final long MusicEternityEpochMillis = 1533081600000L; // Wednesday, August 1, 2018 12:00:00 AM
156     public static final long MaxLockReferenceTimePart = 1000000000000L; // millis after eternity (eq sometime in 2050)
157     public static final long MaxCriticalSectionDurationMillis = 1L * 24 * 60 * 60 * 1000; // 1 day
158
159     private static String transIdPrefix= "false";
160         private static String conversationIdPrefix= "false";
161     private static String clientIdPrefix= "false";
162     private static String messageIdPrefix= "false";
163         private static String transIdRequired= "false";
164         private static String conversationIdRequired= "false";
165     private static String clientIdRequired= "false";
166     private static String messageIdRequired= "false";
167
168     public static String getLockUsing() {
169         return lockUsing;
170     }
171
172
173     public static void setLockUsing(String lockUsing) {
174         MusicUtil.lockUsing = lockUsing;
175     }
176     
177     public static String getAafAdminUrl() {
178         return aafAdminUrl;
179     }
180
181
182     public static void setAafAdminUrl(String aafAdminUrl) {
183         MusicUtil.aafAdminUrl = aafAdminUrl;
184     }
185
186
187     public static String getMusicNamespace() {
188         return musicNamespace;
189     }
190
191
192     public static void setMusicNamespace(String musicNamespace) {
193         MusicUtil.musicNamespace = musicNamespace;
194     }
195
196
197     public static String getAdminAafRole() {
198         return adminAafRole;
199     }
200
201
202     public static void setAdminAafRole(String adminAafRole) {
203         MusicUtil.adminAafRole = adminAafRole;
204     }
205
206
207
208     public static String getAdminId() {
209         return adminId;
210     }
211
212
213     public static void setAdminId(String adminId) {
214         MusicUtil.adminId = adminId;
215     }
216
217
218     public static String getAdminPass() {
219         return adminPass;
220     }
221
222     public static void setAdminPass(String adminPass) {
223         MusicUtil.adminPass = adminPass;
224     }
225
226     private MusicUtil() {
227         throw new IllegalStateException("Utility Class");
228     }
229     /**
230      *
231      * @return cassandra port
232      */
233     public static int getCassandraPort() {
234         return cassandraPort;
235     }
236
237     /**
238      * set cassandra port
239      * @param cassandraPort
240      */
241     public static void setCassandraPort(int cassandraPort) {
242         MusicUtil.cassandraPort = cassandraPort;
243     }
244     /**
245      * @return the cassName
246      */
247     public static String getCassName() {
248         return cassName;
249     }
250
251     /**
252      * @return the cassPwd
253      */
254     public static String getCassPwd() {
255         return cassPwd;
256     }
257
258     /**
259      * @return the aafEndpointUrl
260      */
261     public static String getAafEndpointUrl() {
262         return aafEndpointUrl;
263     }
264
265     /**
266      *
267      * @param aafEndpointUrl
268      */
269     public static void setAafEndpointUrl(String aafEndpointUrl) {
270         MusicUtil.aafEndpointUrl = aafEndpointUrl;
271     }
272
273
274     /**
275      * Returns An array of property names that should be in the Properties
276      * files.
277      *
278      * @return
279      */
280     public static String[] getPropkeys() {
281         return propKeys.clone();
282     }
283
284     /**
285      * Get MusicPropertiesFilePath - Default = /opt/music/music.properties
286      * property file value - music.properties
287      *
288      * @return
289      */
290     public static String getMusicPropertiesFilePath() {
291         return musicPropertiesFilePath;
292     }
293
294     /**
295      * Set MusicPropertiesFilePath
296      *
297      * @param musicPropertiesFilePath
298      */
299     public static void setMusicPropertiesFilePath(String musicPropertiesFilePath) {
300         MusicUtil.musicPropertiesFilePath = musicPropertiesFilePath;
301     }
302
303     /**
304      * Get DefaultLockLeasePeriod - Default = 6000 property file value -
305      * lock.lease.period
306      *
307      * @return
308      */
309     public static long getDefaultLockLeasePeriod() {
310         return defaultLockLeasePeriod;
311     }
312
313     /**
314      * Set DefaultLockLeasePeriod
315      *
316      * @param defaultLockLeasePeriod
317      */
318     public static void setDefaultLockLeasePeriod(long defaultLockLeasePeriod) {
319         MusicUtil.defaultLockLeasePeriod = defaultLockLeasePeriod;
320     }
321
322     /**
323      * Set Debug
324      *
325      * @param debug
326      */
327     public static void setDebug(boolean debug) {
328         MusicUtil.debug = debug;
329     }
330
331     /**
332      * Is Debug - Default = true property file value - debug
333      *
334      * @return
335      */
336     public static boolean isDebug() {
337         return debug;
338     }
339
340     /**
341      * Set Version
342      *
343      * @param version
344      */
345     public static void setVersion(String version) {
346         MusicUtil.version = version;
347     }
348
349     /**
350      * Return the version property file value - version.
351      *
352      * @return
353      */
354     public static String getVersion() {
355         return version;
356     }
357
358     /**
359      * Set the build of project which is a combination of the 
360      * version and the date.
361      * 
362      * @param build - version-date.
363      */
364     public static void setBuild(String build) {
365         MusicUtil.build = build;
366     }
367
368     /**
369      * Return the build version-date.
370      */
371     public static String getBuild() {
372         return build;
373     }
374
375     /**
376      * Get MyCassHost - Cassandra Hostname - Default = localhost property file
377      * value - cassandra.host
378      *
379      * @return
380      */
381     public static String getMyCassaHost() {
382         return myCassaHost;
383     }
384
385     /**
386      * Set MyCassHost - Cassandra Hostname
387      *
388      * @param myCassaHost .
389      */
390     public static void setMyCassaHost(String myCassaHost) {
391         MusicUtil.myCassaHost = myCassaHost;
392     }
393
394     /**
395      * Get DefaultMusicIp - Default = localhost property file value - music.ip
396      *
397      * @return
398      */
399     public static String getDefaultMusicIp() {
400         return defaultMusicIp;
401     }
402
403     /**
404      * Set DefaultMusicIp
405      *
406      * @param defaultMusicIp .
407      */
408     public static void setDefaultMusicIp(String defaultMusicIp) {
409         MusicUtil.defaultMusicIp = defaultMusicIp;
410     }
411     
412     /**
413      * Gey default retry count
414      * @return
415      */
416     public static int getRetryCount() {
417         return retryCount;
418     }
419
420     /**
421      * Set retry count
422      * @param retryCount .
423      */
424     public static void setRetryCount(int retryCount) {
425         MusicUtil.retryCount = retryCount;
426     }
427
428
429     /**
430      * This is used to turn keyspace creation api on/off.
431      * 
432      */
433     public static void setKeyspaceActive(Boolean keyspaceActive) {
434         MusicUtil.isKeyspaceActive = keyspaceActive;
435     }
436
437     /**
438      * This is used to turn keyspace creation api on/off.
439      * @return boolean isKeyspaceActive
440      */
441     public static boolean isKeyspaceActive() {
442         return isKeyspaceActive;
443     }
444
445     /**
446      * .
447      * @return String
448      */
449     public static String getTestType() {
450         String testType = "";
451         try {
452             Scanner fileScanner = new Scanner(new File(""));
453             testType = fileScanner.next();// ignore the my id line
454             @SuppressWarnings("unused")
455             String batchSize = fileScanner.next();// ignore the my public ip line
456             fileScanner.close();
457         } catch (FileNotFoundException e) {
458             logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), e);
459         }
460         return testType;
461
462     }
463
464     /**
465      *
466      * @param time
467      */
468     public static void sleep(long time) {
469         try {
470             Thread.sleep(time);
471         } catch (InterruptedException e) {
472             logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), e);
473             Thread.currentThread().interrupt();
474         }
475     }
476
477     /**
478      * Utility function to check if the query object is valid.
479      *
480      * @param withparams
481      * @param queryObject
482      * @return
483      */
484     public static boolean isValidQueryObject(boolean withparams, PreparedQueryObject queryObject) {
485         if (withparams) {
486             int noOfValues = queryObject.getValues().size();
487             int noOfParams = 0;
488             char[] temp = queryObject.getQuery().toCharArray();
489             for (int i = 0; i < temp.length; i++) {
490                 if (temp[i] == '?')
491                     noOfParams++;
492             }
493             return (noOfValues == noOfParams);
494         } else {
495             return !queryObject.getQuery().isEmpty();
496         }
497
498     }
499
500     public static void setCassName(String cassName) {
501         MusicUtil.cassName = cassName;
502     }
503
504     public static void setCassPwd(String cassPwd) {
505         MusicUtil.cassPwd = cassPwd;
506     }
507
508     @SuppressWarnings("unchecked")
509     public static String convertToCQLDataType(DataType type, Object valueObj) throws Exception {
510
511         String value = "";
512         switch (type.getName()) {
513         case UUID:
514             value = valueObj + "";
515             break;
516         case TEXT:
517         case VARCHAR:
518             String valueString = valueObj + "";
519             valueString = valueString.replace("'", "''");
520             value = "'" + valueString + "'";
521             break;
522         case MAP: {
523             Map<String, Object> otMap = (Map<String, Object>) valueObj;
524             value = "{" + jsonMaptoSqlString(otMap, ",") + "}";
525             break;
526         }
527         default:
528             value = valueObj + "";
529             break;
530         }
531         return value;
532     }
533
534     /**
535      *
536      * @param colType
537      * @param valueObj
538      * @return
539      * @throws MusicTypeConversionException
540      * @throws Exception
541      */
542     @SuppressWarnings("unchecked")
543     public static Object convertToActualDataType(DataType colType, Object valueObj) throws Exception {
544         String valueObjString = valueObj + "";
545         switch (colType.getName()) {
546             case UUID:
547                 return UUID.fromString(valueObjString);
548             case VARINT:
549                 return BigInteger.valueOf(Long.parseLong(valueObjString));
550             case BIGINT:
551                 return Long.parseLong(valueObjString);
552             case INT:
553                 return Integer.parseInt(valueObjString);
554             case FLOAT:
555                 return Float.parseFloat(valueObjString);
556             case DOUBLE:
557                 return Double.parseDouble(valueObjString);
558             case BOOLEAN:
559                 return Boolean.parseBoolean(valueObjString);
560             case MAP:
561                 return (Map<String, Object>) valueObj;
562             case LIST:
563                 return (List<Object>)valueObj;
564             case BLOB:
565
566             default:
567                 return valueObjString;
568         }
569     }
570
571     public static ByteBuffer convertToActualDataType(DataType colType, byte[] valueObj) {
572         ByteBuffer buffer = ByteBuffer.wrap(valueObj);
573         return buffer;
574     }
575
576     /**
577      *
578      * Utility function to parse json map into sql like string
579      *
580      * @param jMap
581      * @param lineDelimiter
582      * @return
583      */
584
585     public static String jsonMaptoSqlString(Map<String, Object> jMap, String lineDelimiter) throws Exception{
586         StringBuilder sqlString = new StringBuilder();
587         int counter = 0;
588         for (Map.Entry<String, Object> entry : jMap.entrySet()) {
589             Object ot = entry.getValue();
590             String value = ot + "";
591             if (ot instanceof String) {
592                 value = "'" + value.replace("'", "''") + "'";
593             }
594             sqlString.append("'" + entry.getKey() + "':" + value);
595             if (counter != jMap.size() - 1)
596                 sqlString.append(lineDelimiter);
597             counter = counter + 1;
598         }
599         return sqlString.toString();
600     }
601
602     @SuppressWarnings("unused")
603     public static String buildVersion(String major, String minor, String patch) {
604         if (minor != null) {
605             major += "." + minor;
606             if (patch != null) {
607                 major += "." + patch;
608             }
609         }
610         return major;
611     }
612
613     /**
614      * Currently this will build a header with X-latestVersion, X-minorVersion and X-pathcVersion
615      * X-latestVerstion will be equal to the latest full version.
616      * X-minorVersion - will be equal to the latest minor version.
617      * X-pathVersion - will be equal to the latest patch version.
618      * Future plans will change this.
619      * @param response
620      * @param major
621      * @param minor
622      * @param patch
623      * @return
624      */
625     public static ResponseBuilder buildVersionResponse(String major, String minor, String patch) {
626         ResponseBuilder response = Response.noContent();
627         String versionIn = buildVersion(major,minor,patch);
628         String version = MusicUtil.getVersion();
629         String[] verArray = version.split("\\.",3);
630         if ( minor != null ) {
631             response.header(XMINORVERSION,minor);
632         } else {
633             response.header(XMINORVERSION,verArray[1]);
634         }
635         if ( patch != null ) {
636             response.header(XPATCHVERSION,patch);
637         } else {
638             response.header(XPATCHVERSION,verArray[2]);
639         }
640         response.header(XLATESTVERSION,version);
641         logger.info(EELFLoggerDelegate.applicationLogger,"Version In:" + versionIn);
642         return response;
643     }
644
645     public static boolean isValidConsistency(String consistency) {
646         for (String string : cosistencyLevel) {
647             if (string.equalsIgnoreCase(consistency))
648                 return true;
649         }
650         return false;
651
652     }
653
654     public static ConsistencyLevel getConsistencyLevel(String consistency) {
655         return consistencyName.get(consistency.toUpperCase());
656         }
657
658         public static void loadProperties() throws Exception {
659         Properties prop = new Properties();
660         InputStream input = null;
661         try {
662             // load the properties file
663             input = MusicUtil.class.getClassLoader().getResourceAsStream("music.properties");
664             prop.load(input);
665         } catch (Exception ex) {
666             logger.error(EELFLoggerDelegate.errorLogger, "Unable to find properties file.", ex);
667             throw new Exception();
668         } finally {
669             if (input != null) {
670                 try {
671                     input.close();
672                 } catch (IOException e) {
673                     e.printStackTrace();
674                     logger.error(EELFLoggerDelegate.errorLogger, e);
675                 }
676             }
677         }
678         // get the property value and return it
679         MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
680         MusicUtil.setCassName(prop.getProperty("cassandra.user"));
681         MusicUtil.setCassPwd(prop.getProperty("cassandra.password"));
682         MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty("cassandra.port")));
683         MusicUtil.setNotifyTimeOut(Integer.parseInt(prop.getProperty("notify.timeout")));
684         MusicUtil.setNotifyInterval(Integer.parseInt(prop.getProperty("notify.interval")));
685         MusicUtil.setCacheObjectMaxLife(Integer.parseInt(prop.getProperty("cacheobject.maxlife")));
686     }
687
688     public static void setNotifyInterval(int notifyinterval) {
689         MusicUtil.notifyinterval = notifyinterval;
690     }
691     public static void setNotifyTimeOut(int notifytimeout) {
692         MusicUtil.notifytimeout = notifytimeout;
693     }
694
695     public static int getNotifyInterval() {
696         return MusicUtil.notifyinterval;
697     }
698
699     public static int getNotifyTimeout() {
700         return MusicUtil.notifytimeout;
701     }
702
703     public static int getCacheObjectMaxLife() {
704         return MusicUtil.cacheObjectMaxLife;
705     }
706
707     public static void setCacheObjectMaxLife(int cacheObjectMaxLife) {
708         MusicUtil.cacheObjectMaxLife = cacheObjectMaxLife;
709     }
710     
711     /**
712      * Given the time of write for an update in a critical section, this method provides a transformed timestamp
713      * that ensures that a previous lock holder who is still alive can never corrupt a later critical section.
714      * The main idea is to us the lock reference to clearly demarcate the timestamps across critical sections.
715      * @param the UUID lock reference associated with the write.
716      * @param the long timeOfWrite which is the actual time at which the write took place
717      * @throws MusicServiceException
718      * @throws MusicQueryException
719      */
720     public static long v2sTimeStampInMicroseconds(long ordinal, long timeOfWrite) throws MusicServiceException, MusicQueryException {
721         // TODO: use acquire time instead of music eternity epoch
722         long ts = ordinal * MaxLockReferenceTimePart + (timeOfWrite - MusicEternityEpochMillis);
723
724         return ts;
725     }
726     
727     public static MusicCoreService  getMusicCoreService() {
728         if(getLockUsing().equals(MusicUtil.CASSANDRA))
729             return MusicCassaCore.getInstance();
730         else
731             return MusicCassaCore.getInstance();
732     }
733     
734     /**
735      * @param lockName
736      * @return
737      */
738     public static Map<String, Object> validateLock(String lockName) {
739         Map<String, Object> resultMap = new HashMap<>();
740         String[] locks = lockName.split("\\.");
741         if(locks.length < 3) {
742             resultMap.put("Error", "Invalid lock. Please make sure lock is of the type keyspaceName.tableName.primaryKey");
743             return resultMap;
744         }
745         String keyspace= locks[0];
746         if(keyspace.startsWith("$"))
747             keyspace = keyspace.substring(1);
748         resultMap.put("keyspace",keyspace);
749         return resultMap;
750     }
751
752
753     public static void setIsCadi(boolean isCadi) {
754         MusicUtil.isCadi = isCadi;
755     }
756
757     public static void writeBackToQuorum(PreparedQueryObject selectQuery, String primaryKeyName,
758         PreparedQueryObject updateQuery, String keyspace, String table,
759         Object cqlFormattedPrimaryKeyValue)
760         throws Exception {
761         try {
762             ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(selectQuery);
763             // write it back to a quorum
764             Row row = results.one();
765             ColumnDefinitions colInfo = row.getColumnDefinitions();
766             int totalColumns = colInfo.size();
767             int counter = 1;
768             StringBuilder fieldValueString = new StringBuilder("");
769             for (Definition definition : colInfo) {
770                 String colName = definition.getName();
771                 if (colName.equals(primaryKeyName))
772                     continue;
773                 DataType colType = definition.getType();
774                 Object valueObj = MusicDataStoreHandle.getDSHandle().getColValue(row, colName, colType);
775                 Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
776                 fieldValueString.append(colName + " = ?");
777                 updateQuery.addValue(valueString);
778                 if (counter != (totalColumns - 1))
779                     fieldValueString.append(",");
780                 counter = counter + 1;
781             }
782             updateQuery.appendQueryString("UPDATE " + keyspace + "." + table + " SET "
783                 + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
784             updateQuery.addValue(cqlFormattedPrimaryKeyValue);
785
786             MusicDataStoreHandle.getDSHandle().executePut(updateQuery, "critical");
787         } catch (MusicServiceException | MusicQueryException e) {
788             logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery ,
789                 ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR, e);
790         }
791     }
792     
793     public static boolean getIsCadi() {
794         return MusicUtil.isCadi;
795     }
796
797
798     /**
799      * @return a random uuid
800      */
801     public static String generateUUID() {
802         String uuid = UUID.randomUUID().toString();
803         logger.info(EELFLoggerDelegate.applicationLogger,"New AID generated: "+uuid);
804         return uuid;
805     }
806
807     private static String checkPrefix(String prefix){
808         if (prefix == null || "".equals(prefix) || prefix.endsWith("-")) {
809             return prefix;
810         } else {
811             return prefix + "-";
812         }
813     }
814
815     /**
816      * @return the transIdPrefix
817      */
818     public static String getTransIdPrefix() {
819         return transIdPrefix;
820     }
821
822     /**
823      * @param transIdPrefix the transIdPrefix to set
824      */
825     public static void setTransIdPrefix(String transIdPrefix) {
826         MusicUtil.transIdPrefix = checkPrefix(transIdPrefix);
827     }
828
829     /**
830      * @return the conversationIdPrefix
831      */
832     public static String getConversationIdPrefix() {
833         return conversationIdPrefix;
834     }
835
836     /**
837      * @param conversationIdPrefix the conversationIdPrefix to set
838      */
839     public static void setConversationIdPrefix(String conversationIdPrefix) {
840         MusicUtil.conversationIdPrefix = checkPrefix(conversationIdPrefix);
841     }
842
843     /**
844      * @return the clientIdPrefix
845      */
846     public static String getClientIdPrefix() {
847         return clientIdPrefix;
848     }
849
850     /**
851      * @param clientIdPrefix the clientIdPrefix to set
852      */
853     public static void setClientIdPrefix(String clientIdPrefix) {
854         MusicUtil.clientIdPrefix = checkPrefix(clientIdPrefix);
855     }
856
857     /**
858      * @return the messageIdPrefix
859      */
860     public static String getMessageIdPrefix() {
861         return messageIdPrefix;
862     }
863
864     /**
865      * @param messageIdPrefix the messageIdPrefix to set
866      */
867     public static void setMessageIdPrefix(String messageIdPrefix) {
868         MusicUtil.messageIdPrefix = checkPrefix(messageIdPrefix);
869     }
870
871         /**
872          * @return the transIdRequired
873          */
874         public static String getTransIdRequired() {
875                 return transIdRequired;
876         }
877
878
879         /**
880          * @param transIdRequired the transIdRequired to set
881          */
882         public static void setTransIdRequired(String transIdRequired) {
883                 MusicUtil.transIdRequired = transIdRequired;
884         }
885
886
887         /**
888          * @return the conversationIdRequired
889          */
890         public static String getConversationIdRequired() {
891                 return conversationIdRequired;
892         }
893
894
895         /**
896          * @param conversationIdRequired the conversationIdRequired to set
897          */
898         public static void setConversationIdRequired(String conversationIdRequired) {
899                 MusicUtil.conversationIdRequired = conversationIdRequired;
900         }
901
902
903         /**
904          * @return the clientIdRequired
905          */
906         public static String getClientIdRequired() {
907                 return clientIdRequired;
908         }
909
910
911         /**
912          * @param clientIdRequired the clientIdRequired to set
913          */
914         public static void setClientIdRequired(String clientIdRequired) {
915                 MusicUtil.clientIdRequired = clientIdRequired;
916         }
917
918
919         /**
920          * @return the messageIdRequired
921          */
922         public static String getMessageIdRequired() {
923                 return messageIdRequired;
924         }
925
926
927         /**
928          * @param messageIdRequired the messageIdRequired to set
929          */
930         public static void setMessageIdRequired(String messageIdRequired) {
931                 MusicUtil.messageIdRequired = messageIdRequired;
932         }
933
934
935
936 }
937