X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fmusic%2Fdatastore%2FMusicDataStore.java;h=6555ea21bd06e0bc6b71800b4cf02f8e4f8f53d9;hb=89451aaa6bf33be7e9b0457007ba3ecb37eb9582;hp=1260efa09c308f4c01c239ba4d6cccbc36ad1023;hpb=4c8d63c24acd45a9ae19af0434848c273f470ae2;p=music.git diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/MusicDataStore.java index 1260efa0..6555ea21 100755 --- a/src/main/java/org/onap/music/datastore/MusicDataStore.java +++ b/src/main/java/org/onap/music/datastore/MusicDataStore.java @@ -35,17 +35,14 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.apache.commons.jcs.access.CacheAccess; -import org.onap.music.authentication.CachingUtil; 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.main.CipherUtil; import org.onap.music.main.MusicUtil; - -import com.codahale.metrics.JmxReporter; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.ColumnDefinitions; import com.datastax.driver.core.ColumnDefinitions.Definition; @@ -55,7 +52,6 @@ import com.datastax.driver.core.HostDistance; import com.datastax.driver.core.KeyspaceMetadata; import com.datastax.driver.core.Metadata; import com.datastax.driver.core.PoolingOptions; -import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; @@ -64,7 +60,6 @@ import com.datastax.driver.core.TableMetadata; import com.datastax.driver.core.exceptions.AlreadyExistsException; import com.datastax.driver.core.exceptions.InvalidQueryException; import com.datastax.driver.core.exceptions.NoHostAvailableException; -import com.sun.jersey.core.util.Base64; /** * @author nelson24 @@ -179,19 +174,20 @@ public class MusicDataStore { while (it.hasNext()) { try { if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) { + String cassPwd = CipherUtil.decryptPKC(MusicUtil.getCassPwd()); logger.info(EELFLoggerDelegate.applicationLogger, "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd()); cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) - .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) - //.withLoadBalancingPolicy(new RoundRobinPolicy()) - .withoutJMXReporting() - .withPoolingOptions(poolingOptions) - .addContactPoints(addresses).build(); + .withCredentials(MusicUtil.getCassName(), cassPwd) + //.withLoadBalancingPolicy(new RoundRobinPolicy()) + .withoutJMXReporting() + .withPoolingOptions(poolingOptions) + .addContactPoints(addresses).build(); } else cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) - //.withLoadBalancingPolicy(new RoundRobinPolicy()) - .addContactPoints(addresses).build(); + //.withLoadBalancingPolicy(new RoundRobinPolicy()) + .addContactPoints(addresses).build(); Metadata metadata = cluster.getMetadata(); logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster " @@ -227,30 +223,22 @@ public class MusicDataStore { .setConnectionsPerHost(HostDistance.LOCAL, 4, 10) .setConnectionsPerHost(HostDistance.REMOTE, 2, 4); if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) { + String cassPwd = CipherUtil.decryptPKC(MusicUtil.getCassPwd()); logger.info(EELFLoggerDelegate.applicationLogger, - "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd()); - cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) - .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) - //.withLoadBalancingPolicy(new RoundRobinPolicy()) - .withoutJMXReporting() - .withPoolingOptions(poolingOptions) - .addContactPoints(addresses).build(); - } - else { + "Building with credentials "+MusicUtil.getCassName()+" & "+ MusicUtil.getCassPwd()); cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) + .withCredentials(MusicUtil.getCassName(), cassPwd) //.withLoadBalancingPolicy(new RoundRobinPolicy()) .withoutJMXReporting() .withPoolingOptions(poolingOptions) .addContactPoints(addresses).build(); + } else { + cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) + .withoutJMXReporting() + .withPoolingOptions(poolingOptions) + .addContactPoints(addresses).build(); } - // JmxReporter reporter = - // JmxReporter.forRegistry(cluster.getMetrics().getRegistry()) - // .inDomain(cluster.getClusterName() + "-metrics") - // .build(); - - // reporter.start(); - Metadata metadata = cluster.getMetadata(); logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster " + metadata.getClusterName() + " at " + address); @@ -288,6 +276,16 @@ public class MusicDataStore { KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(keyspace); return ks.getTable(tableName); } + + /** + * + * @param keyspace + * @param tableName + * @return TableMetadata + */ + public KeyspaceMetadata returnKeyspaceMetadata(String keyspace) { + return cluster.getMetadata().getKeyspace(keyspace); + } /** @@ -363,10 +361,10 @@ public class MusicDataStore { if(definition.getType().toString().toLowerCase().contains("blob")) { resultOutput.put(definition.getName(), getBlobValue(row, definition.getName(), definition.getType())); - } - else + } else { resultOutput.put(definition.getName(), getColValue(row, definition.getName(), definition.getType())); + } } } resultMap.put("row " + counter, resultOutput); @@ -402,27 +400,10 @@ public class MusicDataStore { throw new MusicQueryException("Ill formed queryObject for the request = " + "[" + queryObject.getQuery() + "]"); } - logger.info(EELFLoggerDelegate.applicationLogger, + logger.debug(EELFLoggerDelegate.applicationLogger, "In preprared Execute Put: the actual insert query:" + queryObject.getQuery() + "; the values" + queryObject.getValues()); -/*<<<<<<< HEAD - PreparedStatement preparedInsert = null; - try { - - preparedInsert = session.prepare(queryObject.getQuery()); - - } catch(InvalidQueryException iqe) { - logger.error("Exception", iqe); - logger.error(EELFLoggerDelegate.errorLogger, iqe.getMessage(),AppMessages.QUERYERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR); - throw new MusicQueryException(iqe.getMessage()); - }catch(Exception e) { - logger.error("Exception", e); - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.QUERYERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR); - throw new MusicQueryException(e.getMessage()); - } - -=======*/ SimpleStatement preparedInsert = null; try { @@ -434,7 +415,7 @@ public class MusicDataStore { logger.info(EELFLoggerDelegate.applicationLogger, "Executing simple put query"); if(queryObject.getConsistency() == null) preparedInsert.setConsistencyLevel(ConsistencyLevel.ONE); - else + else preparedInsert.setConsistencyLevel(MusicUtil.getConsistencyLevel(queryObject.getConsistency())); } else if (consistency.equalsIgnoreCase(MusicUtil.ONE)) { preparedInsert.setConsistencyLevel(ConsistencyLevel.ONE); @@ -451,18 +432,19 @@ public class MusicDataStore { } catch (AlreadyExistsException ae) { - logger.error(EELFLoggerDelegate.errorLogger, ae.getMessage(),AppMessages.SESSIONFAILED+ " [" + - queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, ae); - throw new MusicServiceException(ae.getMessage()); - } - catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.SESSIONFAILED+ " [" + - queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, e); - throw new MusicQueryException("Executing Session Failure for Request = " + "[" - + queryObject.getQuery() + "]" + " Reason = " + e.getMessage()); + // logger.error(EELFLoggerDelegate.errorLogger,"AlreadExistsException: " + ae.getMessage(),AppMessages.QUERYERROR, + // ErrorSeverity.ERROR, ErrorTypes.QUERYERROR); + throw new MusicQueryException("AlreadyExistsException: " + ae.getMessage(),ae); + } catch ( InvalidQueryException e ) { + // logger.error(EELFLoggerDelegate.errorLogger,"InvalidQueryException: " + e.getMessage(),AppMessages.SESSIONFAILED + " [" + // + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR); + throw new MusicQueryException("InvalidQueryException: " + e.getMessage(),e); + } catch (Exception e) { + // logger.error(EELFLoggerDelegate.errorLogger,e.getClass().toString() + ":" + e.getMessage(),AppMessages.SESSIONFAILED + " [" + // + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, e); + throw new MusicServiceException("Executing Session Failure for Request = " + "[" + + queryObject.getQuery() + "]" + " Reason = " + e.getMessage(),e); } - - return result; } @@ -496,11 +478,10 @@ public class MusicDataStore { } if(queryObject.getConsistency() == null) { preparedEventualGet.setConsistencyLevel(ConsistencyLevel.ONE); + } else { + preparedEventualGet.setConsistencyLevel(MusicUtil.getConsistencyLevel(queryObject.getConsistency())); } - else { - preparedEventualGet.setConsistencyLevel(MusicUtil.getConsistencyLevel(queryObject.getConsistency())); - } - results = session.execute(preparedEventualGet.bind(queryObject.getValues().toArray())); + results = session.execute(preparedEventualGet.bind(queryObject.getValues().toArray())); } catch (Exception ex) { logger.error("Exception", ex); @@ -555,10 +536,9 @@ public class MusicDataStore { if (consistencyLevel.equalsIgnoreCase(CONSISTENCY_LEVEL_ONE)) { if(queryObject.getConsistency() == null) { statement.setConsistencyLevel(ConsistencyLevel.ONE); + } else { + statement.setConsistencyLevel(MusicUtil.getConsistencyLevel(queryObject.getConsistency())); } - else { - statement.setConsistencyLevel(MusicUtil.getConsistencyLevel(queryObject.getConsistency())); - } } else if (consistencyLevel.equalsIgnoreCase(CONSISTENCY_LEVEL_QUORUM)) { statement.setConsistencyLevel(ConsistencyLevel.QUORUM); @@ -567,9 +547,9 @@ public class MusicDataStore { results = session.execute(statement); } catch (Exception ex) { - logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.UNKNOWNERROR+ "[" + queryObject + logger.error(EELFLoggerDelegate.errorLogger, "Execute Get Error" + ex.getMessage(),AppMessages.UNKNOWNERROR+ "[" + queryObject .getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, ex); - throw new MusicServiceException(ex.getMessage()); + throw new MusicServiceException("Execute Get Error" + ex.getMessage()); } return results;