2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
6 * Modifications Copyright (C) 2019 IBM.
7 * ===================================================================
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * ============LICENSE_END=============================================
23 * ====================================================================
26 package org.onap.music.datastore;
28 import java.util.HashMap;
31 import org.onap.music.eelf.logging.EELFLoggerDelegate;
32 import org.onap.music.exceptions.MusicServiceException;
33 import org.onap.music.main.MusicUtil;
35 import com.datastax.driver.core.ResultSet;
36 import com.datastax.driver.core.TableMetadata;
38 public class MusicDataStoreHandle {
40 private MusicDataStoreHandle(){
41 throw new IllegalStateException("Utility class");
44 public static MusicDataStore mDstoreHandle = null;
45 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStoreHandle.class);
52 public static MusicDataStore getDSHandle(String remoteIp) {
53 logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle");
54 long start = System.currentTimeMillis();
55 if (mDstoreHandle == null) {
56 mDstoreHandle = new MusicDataStore(remoteIp);
58 long end = System.currentTimeMillis();
59 logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
66 * @throws MusicServiceException
68 public static MusicDataStore getDSHandle() throws MusicServiceException {
69 logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle");
70 long start = System.currentTimeMillis();
71 if (mDstoreHandle == null) {
72 // Quick Fix - Best to put this into every call to getDSHandle?
73 if (!"localhost".equals(MusicUtil.getMyCassaHost())) {
74 mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
76 mDstoreHandle = new MusicDataStore();
79 if(mDstoreHandle.getSession() == null) {
80 String message = "Connection to Cassandra has not been enstablished."
81 + " Please check connection properites and reboot.";
82 logger.info(EELFLoggerDelegate.applicationLogger, message);
83 throw new MusicServiceException(message);
85 long end = System.currentTimeMillis();
86 logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
96 * @throws MusicServiceException
98 public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException {
99 return getDSHandle().returnColumnMetadata(keyspace, tablename);
106 * @throws MusicServiceException
108 public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) throws MusicServiceException {
109 return getDSHandle().marshalData(results);