X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fmusic%2Fdatastore%2FMusicDataStoreHandle.java;h=d546a016f18cde6681e03ee7de03cf26f0647f04;hb=66aac8e2b8f61f075b285f969c1f8a88fdb313bd;hp=bb8f3cbdb5d16df3494dc49412ea630c3b263601;hpb=a627a5b2d6cd2823c079fcc842a188f3faf2bf5d;p=music.git diff --git a/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java b/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java index bb8f3cbd..d546a016 100644 --- a/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java +++ b/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java @@ -3,6 +3,9 @@ * org.onap.music * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property + * Modifications Copyright (C) 2019 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. @@ -28,16 +31,18 @@ import java.util.Map; import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.exceptions.MusicServiceException; import org.onap.music.main.MusicUtil; -import org.onap.music.service.impl.MusicZKCore; +import com.datastax.driver.core.KeyspaceMetadata; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.TableMetadata; public class MusicDataStoreHandle { - - - - public static MusicDataStore mDstoreHandle = null; + + private MusicDataStoreHandle(){ + throw new IllegalStateException("Utility class"); + } + + private static MusicDataStore mDstoreHandle = null; private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStoreHandle.class); /** @@ -45,45 +50,45 @@ public class MusicDataStoreHandle { * @param remoteIp * @return */ - public static MusicDataStore getDSHandle(String remoteIp) { - logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle"); - long start = System.currentTimeMillis(); - if (mDstoreHandle == null) { - mDstoreHandle = new MusicDataStore(remoteIp); - } - long end = System.currentTimeMillis(); - logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms"); - return mDstoreHandle; - } + public static MusicDataStore getDSHandle(String remoteIp) { + logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle"); + long start = System.currentTimeMillis(); + if (mDstoreHandle == null) { + mDstoreHandle = new MusicDataStore(remoteIp); + } + long end = System.currentTimeMillis(); + logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms"); + return mDstoreHandle; + } /** * * @return * @throws MusicServiceException */ - public static MusicDataStore getDSHandle() throws MusicServiceException { - logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle"); - long start = System.currentTimeMillis(); - if (mDstoreHandle == null) { - // Quick Fix - Best to put this into every call to getDSHandle? - if (! MusicUtil.getMyCassaHost().equals("localhost") ) { - mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost()); - } else { - mDstoreHandle = new MusicDataStore(); - } - } - if(mDstoreHandle.getSession() == null) { - String message = "Connection to Cassandra has not been enstablished." - + " Please check connection properites and reboot."; - logger.info(EELFLoggerDelegate.applicationLogger, message); - throw new MusicServiceException(message); - } - long end = System.currentTimeMillis(); - logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms"); - return mDstoreHandle; - } - - + public static MusicDataStore getDSHandle() throws MusicServiceException { + logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle"); + long start = System.currentTimeMillis(); + if (mDstoreHandle == null) { + // Quick Fix - Best to put this into every call to getDSHandle? + if (!"localhost".equals(MusicUtil.getMyCassaHost())) { + mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost()); + } else { + mDstoreHandle = new MusicDataStore(); + } + } + if(mDstoreHandle.getSession() == null) { + String message = "Connection to Cassandra has not been enstablished." + + " Please check connection properites and reboot."; + logger.info(EELFLoggerDelegate.applicationLogger, message); + throw new MusicServiceException(message); + } + long end = System.currentTimeMillis(); + logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms"); + return mDstoreHandle; + } + + /** * * @param keyspace @@ -91,18 +96,29 @@ public class MusicDataStoreHandle { * @return * @throws MusicServiceException */ - public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException { - return getDSHandle().returnColumnMetadata(keyspace, tablename); - } - + public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException { + return getDSHandle().returnColumnMetadata(keyspace, tablename); + } + + /** + * + * @param keyspace + * @param tablename + * @return + * @throws MusicServiceException + */ + public static KeyspaceMetadata returnkeyspaceMetadata(String keyspace) throws MusicServiceException { + return getDSHandle().returnKeyspaceMetadata(keyspace); + } + /** * * @param results * @return * @throws MusicServiceException */ - public static Map> marshallResults(ResultSet results) throws MusicServiceException { - return getDSHandle().marshalData(results); - } + public static Map> marshallResults(ResultSet results) throws MusicServiceException { + return getDSHandle().marshalData(results); + } }