2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=============================================
22 * ====================================================================
25 package org.onap.music.datastore;
27 import java.util.HashMap;
30 import org.onap.music.eelf.logging.EELFLoggerDelegate;
31 import org.onap.music.exceptions.MusicServiceException;
32 import org.onap.music.main.MusicUtil;
34 import com.datastax.driver.core.ResultSet;
35 import com.datastax.driver.core.TableMetadata;
37 public class MusicDataStoreHandle {
39 private MusicDataStoreHandle(){
40 throw new IllegalStateException("Utility class");
43 public static MusicDataStore mDstoreHandle = null;
44 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStoreHandle.class);
51 public static MusicDataStore getDSHandle(String remoteIp) {
52 logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle");
53 long start = System.currentTimeMillis();
54 if (mDstoreHandle == null) {
55 mDstoreHandle = new MusicDataStore(remoteIp);
57 long end = System.currentTimeMillis();
58 logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
65 * @throws MusicServiceException
67 public static MusicDataStore getDSHandle() throws MusicServiceException {
68 logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle");
69 long start = System.currentTimeMillis();
70 if (mDstoreHandle == null) {
71 // Quick Fix - Best to put this into every call to getDSHandle?
72 if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
73 mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
75 mDstoreHandle = new MusicDataStore();
78 if(mDstoreHandle.getSession() == null) {
79 String message = "Connection to Cassandra has not been enstablished."
80 + " Please check connection properites and reboot.";
81 logger.info(EELFLoggerDelegate.applicationLogger, message);
82 throw new MusicServiceException(message);
84 long end = System.currentTimeMillis();
85 logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
95 * @throws MusicServiceException
97 public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException {
98 return getDSHandle().returnColumnMetadata(keyspace, tablename);
105 * @throws MusicServiceException
107 public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) throws MusicServiceException {
108 return getDSHandle().marshalData(results);