Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cassandra Connection String Changes #3585

Merged
merged 18 commits into from
Apr 11, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 55 additions & 10 deletions Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
#endregion

using Amdocs.Ginger.Common;
using Amdocs.Ginger.CoreNET.RunLib.CLILib;
using Cassandra;
using GingerCore.Actions;
using GingerCore.NoSqlBase.DataAccess;
using HBaseNet.Const;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Authentication;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

Expand All @@ -37,32 +40,73 @@
dynamic myclass = null;
string mUDTName = null;



public override bool Connect()
{
try
{
string queryTimeoutString = "querytimeout=";
const string queryTimeoutString = "querytimeout=";
const string sslString = "ssl=";
int queryTimeout = 20000;//default timeout (20 seconds).
if (Db.DatabaseOperations.TNSCalculated.ToLower().Contains(queryTimeoutString.ToLower()))
string[] queryArray = Db.DatabaseOperations.TNSCalculated.Split(';');
aditydha marked this conversation as resolved.
Show resolved Hide resolved
if (queryArray[1].ToLower().Contains(queryTimeoutString))
{
string queryTimeoutValue = Db.DatabaseOperations.TNSCalculated.Substring(Db.DatabaseOperations.TNSCalculated.ToLower().IndexOf(queryTimeoutString.ToLower()) + queryTimeoutString.Length);
string queryTimeoutValue = queryArray[1].Substring(queryArray[1].ToLower().IndexOf(queryTimeoutString) + queryTimeoutString.Length);
aditydha marked this conversation as resolved.
Show resolved Hide resolved
queryTimeout = Convert.ToInt32(queryTimeoutValue) * 1000;
}
SSLOptions sslOptions=null;
try
{
if (queryArray[2].ToLower().Contains(sslString))
{
string sslValue = queryArray[2].Substring(queryArray[2].ToLower().IndexOf(sslString) + sslString.Length);
sslOptions = new SSLOptions(
Enum.Parse<SslProtocols>(sslValue), false,
(_, certificate, chain, errors) => { return true; });

Check notice on line 64 in Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs#L64

'certificate' is not used. Use discard parameter instead.
aditydha marked this conversation as resolved.
Show resolved Hide resolved

string[] HostKeySpace = Db.DatabaseOperations.TNSCalculated.Split('/');
}

}
catch (Exception e)
{
Reporter.ToLog(eLogLevel.ERROR, "SSL Value Not Correct. Please Enter SSL value like Default, None, Ssl2, Ssl3, Tls, Tls11, Tls12, Tls13", e);
throw (e);
}
aditydha marked this conversation as resolved.
Show resolved Hide resolved
string[] HostKeySpace = queryArray[0].ToLower().Replace("http://", "").Replace("https://", "").Split('/');
string[] HostPort = HostKeySpace[0].Split(':');

aditydha marked this conversation as resolved.
Show resolved Hide resolved
if (HostPort.Length == 2)
{
if (string.IsNullOrEmpty(Db.Pass) && string.IsNullOrEmpty(Db.User))
{
cluster = Cluster.Builder().AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build();
if (sslOptions ==null)
{
cluster = Cluster.Builder().AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build();
}
else
{
cluster = Cluster.Builder()
.AddContactPoint(HostPort[0])
.WithPort(Int32.Parse(HostPort[1]))
.WithSSL(sslOptions)
.WithQueryTimeout(queryTimeout)
.Build();
}
}
else
{
cluster = Cluster.Builder().WithCredentials(Db.User.ToString(), Db.Pass.ToString()).AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build();
if (sslOptions == null) {
cluster = Cluster.Builder().WithCredentials(Db.User.ToString(), Db.Pass.ToString()).AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build();
}
else
{
cluster = Cluster.Builder()
.AddContactPoint(HostPort[0])
.WithPort(Int32.Parse(HostPort[1]))
.WithAuthProvider(new PlainTextAuthProvider(Db.User, Db.Pass))
.WithSSL(sslOptions)
.WithQueryTimeout(queryTimeout)
.Build();
}
}
}
else
Expand Down Expand Up @@ -94,7 +138,7 @@
{
try
{
if (session != null)
if (session != null && !session.IsDisposed)
aditydha marked this conversation as resolved.
Show resolved Hide resolved
{
Metadata m = cluster.Metadata;
ICollection<string> Keyspaces = m.GetKeyspaces();
Expand Down Expand Up @@ -184,6 +228,7 @@
{
session.Dispose();
cluster.Dispose();
session = null;
aditydha marked this conversation as resolved.
Show resolved Hide resolved
}

public Type TypeConverter(RowSet RS, string Type1)
Expand Down
Loading