* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
- * Modifications Copyright (c) 2018 IBM.
+ * 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.
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 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 org.onap.music.service.impl.MusicZKCore;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.DataType;
public static final String USERID = "userId";
public static final String PASSWORD = "password";
public static final String CASSANDRA = "cassandra";
- public static final String ZOOKEEPER = "zookeeper";
public static final String AUTHORIZATION = "Authorization";
private static int cacheObjectMaxLife = -1;
private static String lockUsing = MusicUtil.CASSANDRA;
private static boolean isCadi = false;
+ private static boolean isKeyspaceActive = false;
private static boolean debug = true;
- private static String version = "2.3.0";
+ private static String version = "0.0.0";
+ private static String build = "";
private static String musicRestIp = LOCALHOST;
private static String musicPropertiesFilePath = PROPERTIES_FILE;
private static long defaultLockLeasePeriod = 6000;
- private static final String[] propKeys = new String[] { "zookeeper.host", "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 int retryCount = 3;
+ 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","retry.count"};
private static final String[] cosistencyLevel = new String[] {
- "ALL","EACH_QUORUM","QUORUM","LOCAL_QUORUM","ONE","TWO","THREE","LOCAL_ONE","ANY","SERIAL","LOCAL_SERIAL"};
+ "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);
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";
+ private static String musicNamespace= "org.onap.music.api";
+ private static String adminAafRole= "org.onap.music.api.admin_api";
public static final long MusicEternityEpochMillis = 1533081600000L; // Wednesday, August 1, 2018 12:00:00 AM
MusicUtil.adminPass = adminPass;
}
-
private MusicUtil() {
throw new IllegalStateException("Utility Class");
}
}
/**
- * Return the version property file value - version
+ * Return the version property file value - version.
*
* @return
*/
}
/**
- * Get MyZkHost - Zookeeper Hostname - Default = localhost property file
- * value - zookeeper.host
- *
- * @return
+ * Set the build of project which is a combination of the
+ * version and the date.
+ *
+ * @param build - version-date.
*/
- public static String getMyZkHost() {
- return myZkHost;
+ public static void setBuild(String build) {
+ MusicUtil.build = build;
}
/**
- * Set MyZkHost - Zookeeper Hostname
- *
- * @param myZkHost
+ * Return the build version-date.
*/
- public static void setMyZkHost(String myZkHost) {
- MusicUtil.myZkHost = myZkHost;
+ public static String getBuild() {
+ return build;
}
/**
/**
* Set MyCassHost - Cassandra Hostname
*
- * @param myCassaHost
+ * @param myCassaHost .
*/
public static void setMyCassaHost(String myCassaHost) {
MusicUtil.myCassaHost = myCassaHost;
/**
* Set DefaultMusicIp
*
- * @param defaultMusicIp
+ * @param defaultMusicIp .
*/
public static void setDefaultMusicIp(String defaultMusicIp) {
MusicUtil.defaultMusicIp = defaultMusicIp;
}
-
+
/**
- *
+ * Gey default retry count
* @return
*/
+ public static int getRetryCount() {
+ return retryCount;
+ }
+
+ /**
+ * Set retry count
+ * @param retryCount .
+ */
+ public static void setRetryCount(int retryCount) {
+ MusicUtil.retryCount = retryCount;
+ }
+
+
+ /**
+ * This is used to turn keyspace creation api on/off.
+ *
+ */
+ public static void setKeyspaceActive(Boolean keyspaceActive) {
+ MusicUtil.isKeyspaceActive = keyspaceActive;
+ }
+
+ /**
+ * This is used to turn keyspace creation api on/off.
+ * @return boolean isKeyspaceActive
+ */
+ public static boolean isKeyspaceActive() {
+ return isKeyspaceActive;
+ }
+
+ /**
+ * .
+ * @return String
+ */
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
+ String batchSize = fileScanner.next();// ignore the my public ip line
fileScanner.close();
} catch (FileNotFoundException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), e);
}
return testType;
try {
Thread.sleep(time);
} catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), e);
Thread.currentThread().interrupt();
}
}
}
public static ByteBuffer convertToActualDataType(DataType colType, byte[] valueObj) {
- ByteBuffer buffer = ByteBuffer.wrap(valueObj);
- return buffer;
+ ByteBuffer buffer = ByteBuffer.wrap(valueObj);
+ return buffer;
}
/**
input = MusicUtil.class.getClassLoader().getResourceAsStream("music.properties");
prop.load(input);
} catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Unable to find properties file.");
+ logger.error(EELFLoggerDelegate.errorLogger, "Unable to find properties file.", ex);
throw new Exception();
} finally {
if (input != null) {
input.close();
} catch (IOException e) {
e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger, e);
}
}
}
// get the property value and return it
MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
- String zkHosts = prop.getProperty("zookeeper.host");
- MusicUtil.setMyZkHost(zkHosts);
MusicUtil.setCassName(prop.getProperty("cassandra.user"));
MusicUtil.setCassPwd(prop.getProperty("cassandra.password"));
MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty("cassandra.port")));
public static MusicCoreService getMusicCoreService() {
if(getLockUsing().equals(MusicUtil.CASSANDRA))
return MusicCassaCore.getInstance();
- else if (getLockUsing().equals(MusicUtil.ZOOKEEPER))
- return MusicZKCore.getInstance();
else
return MusicCassaCore.getInstance();
}
public static void setIsCadi(boolean isCadi) {
- // TODO Auto-generated method stub
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, e);
+ }
+ }
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;
+ }
+
}