Tuesday 12 June 2018

git error pathspec did not match Remote branch not showing up in “git branch -r”

Problem::

Remote branch not showing up in “git branch -r”
git error pathspec did not match

Solution:

git config -e
it will open an file
For me it was like  " fetch = +refs/heads/master:refs/remotes/origin/master " before solved.

The remote section specifies also fetch rules. You could make sure  something like this exists:
fetch = +refs/heads/*:refs/remotes/origin/*


Thursday 19 April 2018

Opensource DB UI Tool for Cassandra DB- DBweaver


DBweaver ::

Best opensource tool for CASSANDRA .

I spent lot of time to find open source tool for cassandra , atlast this is the right solution.


#dbeaver-cassandra cassandra db gui

1. Download dbeaver (Community Edition): dbweaver-Download
2. Download cassandra jdbc jar files: http://www.dbschema.com/cassandra-jdbc-driver.html or direct link CassandraJdbcDriver.zip
3. extract cassandra jdbc zip
4. run dbeaver.exe
5. go to Database > Driver Manager
6. click New
7. Fill in details as follow:
   - Driver Name: Cassandra (or whatever you want it to say)
   - Driver Type: Generic
   - Class Name: com.dbschema.CassandraJdbcDriver
   - URL Template: jdbc:cassandra://{host}[:{port}][/{database}]
   - Default Port: 9042
   - Embedded: no
   - Category: <leave blank>
   - Description: Cassandra (or whatever you want it to say)
8. click Add File and add all of the jars in the cassandra jdbc zip
9. click Find Class to make sure the Class Name is found okay
10. click OK
11. Create New Connection, selecting the database driver you just added
dbschema.com
Cassandra JDBC Driver | DbSchema Cassandra Designer
Cassandra free JDBC driver provided by DbSchema Cassandra Admin GUI Tool - best interface for complex Cassandra databases.

Thursday 25 January 2018

Cassandra java driver With SSL

I want to present you an java code for cassandra client with SSL and Cluster. I am not sharing keystores but i pressume you can get that info from google. I also want to provide you and reference sites i have gone through:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import java.io.File;
import java.io.InputStream;
import java.security.KeyStore;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;

import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Cluster.Builder;
import com.datastax.driver.core.Host;
import com.datastax.driver.core.JdkSSLOptions;
import com.datastax.driver.core.Metadata;
import com.datastax.driver.core.Session;

/**
 *  "dbinfo": {
      "port": 9042,
      "truststorepath":"/path/to/truststore.jks",
      "truststoresecret":"password of truststore",
      "nodes": [
         "127.0.0.2",
         "127.0.0.1"
      ],
      "ssl": false
   },
 * 
 * 
 * 
 * This is an implementation of a simple Java Cassandra client.
 *
 */
public class CassandraClient {
 private static final Logger logme = LoggerFactory.getLogger(CassandraClient.class);

 private Cluster cluster;

 private Session session;

 /**
  * For single node instance setup
  * 
  * @param node
  * @param port
  */
 public void connectToServer(final String node, final Integer port) {

  Builder b = Cluster.builder().addContactPoint(node);

  if (port != null) {
   b.withPort(port);
  }
  cluster = b.build();

  Metadata metadata = cluster.getMetadata();
  logme.info("Cassandra: Cluster name: " + metadata.getClusterName());

  for (Host host : metadata.getAllHosts()) {
   logme.info("Cassandra:Datacenter: " + host.getDatacenter() + " Host: " + host.getAddress() + " Rack: "
     + host.getRack());
  }

  session = cluster.connect();
 }

 /**
  * 
  * For multi node instance setup
  * 
  * @param cfg
  */
 public void connectToServer(JSONObject cfg) {

  Builder b = Cluster.builder();

  JSONObject cassandra = cfg.getJSONObject("dbinfo");
  JSONArray nodes = cassandra.getJSONArray("nodes");

  for (Object node : nodes) {
   b.addContactPoint(node.toString());

  }
  boolean ssl = cassandra.optBoolean("ssl", false);
  int port = cassandra.optInt("port", 9042);
  b.withPort(port);

  if (ssl) {

   String trustPath = cassandra.getString("truststorepath");
   String trustSecret = cassandra.getString("truststoresecret");
   if (trustPath == null || trustSecret == null) {
    logme.error(" *********   Please provide truststore details for cassandra ****************");
   }
   JdkSSLOptions sslOptions = getSSLOptionsFromTrustStore(trustPath, trustSecret);
   b.withSSL(sslOptions);
  }

  cluster = b.build();

  Metadata metadata = cluster.getMetadata();
  logme.info("Cassandra: Cluster name: " + metadata.getClusterName());

  for (Host host : metadata.getAllHosts()) {
   logme.info("Cassandra:Datacenter: " + host.getDatacenter() + " Host: " + host.getAddress() + " Rack: "
     + host.getRack());
  }

  session = cluster.connect();
 }

 public Session getSession() {
  return this.session;
 }

 public void close() {
  session.close();
  cluster.close();
 }

 private JdkSSLOptions getSSLOptionsFromTrustStore(String trustStoreLocation, String trustStorePassword) {
  Cluster cluster;
  SSLContext sslcontext = null;

  try {

   InputStream is = FileUtils.openInputStream(new File(trustStoreLocation));
   KeyStore keystore = KeyStore.getInstance("jks");
   char[] pwd = trustStorePassword.toCharArray();
   keystore.load(is, pwd);
   TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
   tmf.init(keystore);
   TrustManager[] tm = tmf.getTrustManagers();

   sslcontext = SSLContext.getInstance("TLSv1");
   sslcontext.init(null, tm, null);

  } catch (Exception e) {
   logme.error(e.getMessage(), e);
  }

  JdkSSLOptions sslOptions = JdkSSLOptions.builder().withSSLContext(sslcontext).build();

  return sslOptions;
 }

}