Open manodnyab opened 1 year ago
public void validate(DatabaseConfig databaseConfig) { try { if(databaseConfig.getDriver().equals(EnumDriver.MONGODB.getCode())){ ProcessBuilder processBuilder = new ProcessBuilder(); String mongoShellV4Path = System.getProperty(MongoShellPathProperty.MONGO_SHELL_PATH_V4); //根据密码是否为空去判断是否走验证。 String parsedCommand = "db.version()"; String connectUrl = ""; if(EmptyUtil.isNotEmpty(databaseConfig.getValidateType())){ EnumMongoDbValidateType enumMongoDbValidateType = EnumMongoDbValidateType.valueOf(databaseConfig.getValidateType().toUpperCase(Locale.ROOT)); switch (enumMongoDbValidateType){ case NONE: connectUrl = mongoShellV4Path+" &&./mongo "+ databaseConfig.getDbUrl()+"/" + databaseConfig.getDbName() +" --quiet --eval " +"'"+parsedCommand + "'"; break; case PASSWORD: if(EmptyUtil.isNotEmpty(databaseConfig.getUsername()) && EmptyUtil.isNotEmpty(databaseConfig.getPassword())){ connectUrl = mongoShellV4Path+"&&./mongo "+ databaseConfig.getDbUrl()+"/" + databaseConfig.getDbName() +" --authenticationDatabase "+ databaseConfig.getDbName() +" -u "+ databaseConfig.getUsername() +" -p "+ databaseConfig.getPassword() +" --quiet --eval "+ "'"+parsedCommand + "'"; } break; case LDAP: if(EmptyUtil.isNotEmpty(databaseConfig.getUsername()) && EmptyUtil.isNotEmpty(databaseConfig.getPassword())){ connectUrl = mongoShellV4Path+"&&./mongo "+ databaseConfig.getDbUrl()+"/" + databaseConfig.getDbName() +" --authenticationDatabase "+ databaseConfig.getDbName() +" -u "+ databaseConfig.getUsername() +" -p "+ databaseConfig.getPassword() +" --authenticationMechanism PLAIN --quiet --eval "+ "'"+parsedCommand + "'"; } break; default: log.error("未查询到验证的类型"); } } log.warn("[nosql-mongo]:执行命令的连接字符串为:{}",connectUrl);
processBuilder.command("bash", "-c", "cd "+connectUrl );
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder resultBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null ){
resultBuilder.append(line);
}
int exitCode = process.waitFor();
if(exitCode != 0){
TIException.throwException(resultBuilder.toString());
}
return;
}
if(databaseConfig.getDriver().equals(EnumDriver.HBASE.getCode())){
//添加hosts
if(EmptyUtil.isNotEmpty(databaseConfig.getHosts())){
DnsCacheManipulatorUtils.addHosts(databaseConfig.getHosts());
}
int retryTimes = 3;
boolean success = false;
for (int i = 0; i < retryTimes; i++) {
if(!success){
FutureTask futureTask = new FutureTask(new Callable() {
@Override
public Object call() throws Exception {
Connection connection = null;
try {
Class.forName(databaseConfig.getDriver());
Properties properties = new Properties();
properties.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, "true");
connection = DriverManager.getConnection(databaseConfig.getDbUrl(),properties);
}finally {
if(connection != null){
connection.close();
}
}
return connection;
};
});
Thread thread = new Thread(futureTask);
thread.start();
try {
futureTask.get(databaseConfig.getTimeout(), MILLISECONDS);
success = true;
} catch (TimeoutException e) {
success = false;
if(i==2){
TIException.throwException(e.toString());
}
}catch (Exception e){
TIException.throwException(e.toString());
}
}else {
break;
}
}
if(EmptyUtil.isNotEmpty(databaseConfig.getHosts())) DnsCacheManipulatorUtils.removeHosts(databaseConfig.getHosts());
return ;
}
if(databaseConfig.getDriver().equals(EnumDriver.REDIS.getCode())){
Set<HostAndPort> nodes = new HashSet();
String url = databaseConfig.getDbUrl();
String[] array = url.split(",");
List<String> list = Arrays.asList(array);
for (int i = 0; i < list.size(); i++) {
nodes.add(HostAndPort.from(list.get(i)));
}
//区分单机和集群
if(nodes.size() == 1){
Jedis jedis = null;
try {
jedis = new Jedis(nodes.stream().findFirst().get().getHost(),nodes.stream().findFirst().get().getPort());
if(EmptyUtil.isNotEmpty(databaseConfig.getPassword()) && EmptyUtil.isEmpty(databaseConfig.getUsername())){
jedis.auth(databaseConfig.getPassword());
}
if(EmptyUtil.isNotEmpty(databaseConfig.getPassword()) && EmptyUtil.isNotEmpty(databaseConfig.getUsername())){
jedis.auth(databaseConfig.getUsername(),databaseConfig.getPassword());
}
String ping = jedis.ping();
if (ping.equalsIgnoreCase("PONG")) {
return ;
};
} catch (Exception e) {
TIException.throwException(e.getMessage());
}finally {
if(jedis != null){
jedis.close();
}
};
}else{
JedisCluster cluster = null;
try {
if(EmptyUtil.isNotEmpty(databaseConfig.getPassword()) && EmptyUtil.isEmpty(databaseConfig.getUsername())){
cluster = new JedisCluster(nodes, (int)databaseConfig.getTimeout(), (int)databaseConfig.getTimeout(), 3,databaseConfig.getPassword(), new GenericObjectPoolConfig<>());
}else if(EmptyUtil.isNotEmpty(databaseConfig.getUsername()) && EmptyUtil.isNotEmpty(databaseConfig.getPassword())){
cluster = new JedisCluster(nodes, (int)databaseConfig.getTimeout(), (int)databaseConfig.getTimeout(), 3, databaseConfig.getUsername(),databaseConfig.getPassword(),null,new GenericObjectPoolConfig<>());
}else{
cluster = new JedisCluster(nodes, (int)databaseConfig.getTimeout(), (int)databaseConfig.getTimeout(), 3, new GenericObjectPoolConfig<>());
}
cluster.randomKey();
} catch (Exception e) {
TIException.throwException(e.getMessage());
}finally {
if(cluster != null){
cluster.close();
}
}
}
return;
}
DriverManager.getConnection(databaseConfig.getDbUrl(), databaseConfig.getUsername(), databaseConfig.getPassword());
} catch (Exception e) {
TIException.throwException(e.getMessage());
}
}
}
Issue: CodeWhisperer Start Button not available in the Developer Tools Tab
The CodeWhisperer documentation lists a Start Node to Get Started, however the CodeWhisperer Node in the Toolkit has the following options:
Solution:
If you see the above issue, please: - Upgrade to the latest version of the JetBrains IDE(minimum version 2022.2) then - Install the latest version of the Toolkit
Cause: