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.KeyspaceMetadata;
36 import com.datastax.driver.core.ResultSet;
37 import com.datastax.driver.core.TableMetadata;
39 public class MusicDataStoreHandle {
41 private static MusicDataStore mDstoreHandle = null;
42 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStoreHandle.class);
44 private MusicDataStoreHandle(){
45 throw new IllegalStateException("Utility class");
53 public static MusicDataStore getDSHandle(String remoteIp) {
54 logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle");
55 long start = System.currentTimeMillis();
56 if (mDstoreHandle == null) {
57 mDstoreHandle = new MusicDataStore(remoteIp);
59 long end = System.currentTimeMillis();
60 logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
67 * @throws MusicServiceException
69 public static MusicDataStore getDSHandle() throws MusicServiceException {
70 logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle");
71 long start = System.currentTimeMillis();
72 if (mDstoreHandle == null) {
73 // Quick Fix - Best to put this into every call to getDSHandle?
74 if (!"localhost".equals(MusicUtil.getMyCassaHost())) {
75 mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
77 mDstoreHandle = new MusicDataStore();
80 if(mDstoreHandle.getSession() == null) {
81 String message = "Connection to Cassandra has not been enstablished."
82 + " Please check connection properites and reboot.";
83 logger.info(EELFLoggerDelegate.applicationLogger, message);
84 throw new MusicServiceException(message);
86 long end = System.currentTimeMillis();
87 logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
97 * @throws MusicServiceException
99 public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException {
100 return getDSHandle().returnColumnMetadata(keyspace, tablename);
108 * @throws MusicServiceException
110 public static KeyspaceMetadata returnkeyspaceMetadata(String keyspace) throws MusicServiceException {
111 return getDSHandle().returnKeyspaceMetadata(keyspace);
118 * @throws MusicServiceException
120 public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) throws MusicServiceException {
121 return getDSHandle().marshalData(results);