云服务器内容精选

  • 代码样例 取消冷热时间线。 public void testModifyTable() { LOG.info("Entering testModifyTable."); // Specify the column family name. byte[] familyName = Bytes.toBytes("info"); Admin admin = null; try { // Instantiate an Admin object. admin = conn.getAdmin(); // Obtain the table descriptor. HTableDescriptor htd = admin.getTableDescriptor(tableName); // Check whether the column family is specified before modification. if (!htd.hasFamily(familyName)) { // Create the column descriptor. HColumnDescriptor hcd = new HColumnDescriptor(familyName); //Disable hot and cold separation. hcd .setValue(HColumnDescriptor.COLD_BOUNDARY, null); htd.addFamily(hcd); // Disable the table to get the table offline before modifying // the table. admin.disableTable(tableName); // Submit a modifyTable request. admin.modifyTable(tableName, htd); //注[1] // Enable the table to get the table online after modifying the // table. admin.enableTable(tableName); } LOG.info("Modify table successfully."); } catch (IOException e) { LOG.error("Modify table failed " ,e); } finally { if (admin != null) { try { // Close the Admin object. admin.close(); } catch (IOException e) { LOG.error("Close admin failed " ,e); } } } LOG.info("Exiting testModifyTable."); } 注意事项。 注[1] 只有在调用disableTable接口后, 再调用modifyTable接口才能将表修改成功。之后,请调用enableTable接口重新启用表。 注[1] 指的是代码样例中的“admin.modifyTable(tableName, htd); //注[1]”。
  • 代码样例 以下代码片段是调用firstAccess接口完成登录认证的示例,在rest.UserManager类的main方法中。 BasicAuthAccess authAccess = new BasicAuthAccess(); HttpClient httpClient = authAccess.loginAndAccess(webUrl, userName, password, userTLSVersion); LOG.info("Start to access REST API."); HttpManager httpManager = new HttpManager(); String operationName = ""; String operationUrl = ""; String jsonFilePath = "";
  • 前提条件 配置用户的集群信息和登录账号信息: 配置文件:“样例工程文件夹\conf\UserInfo.properties”。 参数说明: userName:登录Manager系统的用户名。 password:userName对应的用户密码。密码明文存储存在安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全。 webUrl:Manager首页地址。 填写“UserInfo.properties”文件中的参数,注意填写的准确性,可以仿照以下参数示例进行填写,其中,“IP_Address”填写FusionInsight Manager对应的浮动IP地址。 如果需要使用其他用户进行操作,请先登录FusionInsight Manager创建用户。 userName= admin password= adminPassWord webUrl= https://IP_Address:28443/web/
  • 前提条件 配置用户的集群信息和登录账号信息: 配置文件:“样例工程文件夹\conf\UserInfo.properties”。 参数说明: userName:登录Manager系统的用户名。 password:userName对应的用户密码。 webUrl:Manager首页地址。 填写“UserInfo.properties”文件中的参数,注意填写的准确性,可以仿照以下参数示例进行填写,其中,“IP_Address”填写FusionInsight Manager对应的浮动IP地址。 如果需要使用其他用户进行操作,请先登录FusionInsight Manager创建用户。 userName= admin password= adminPassWord webUrl= https://IP_Address:28443/web/
  • 代码样例 以下代码片段是调用firstAccess接口完成登录认证的示例,在“rest”包的“UserManager”类的main方法中。 BasicAuthAccess authAccess = new BasicAuthAccess(); HttpClient httpClient = authAccess.loginAndAccess(webUrl, userName, password, userTLSVersion); LOG.info("Start to access REST API."); HttpManager httpManager = new HttpManager(); String operationName = ""; String operationUrl = ""; String jsonFilePath = "";
  • 代码样例 通过SpringBoot实现Kafka生产消费的样例代码如下: @RestController public class MessageController { private final static Logger LOG = LoggerFactory.getLogger(MessageController.class); @Autowired private KafkaProperties kafkaProperties; @GetMapping("/produce") public String produce() { Producer producerThread = new Producer(); producerThread.init(this.kafkaProperties); producerThread.start(); String message = "Start to produce messages"; LOG.info(message); return message; } @GetMapping("/consume") public String consume() { Consumer consumerThread = new Consumer(); consumerThread.init(this.kafkaProperties); consumerThread.start(); LOG.info("Start to consume messages"); // 等到180s后将consumer关闭,实际执行过程中可修改 try { Thread.sleep(consumerThread.getThreadAliveTime()); } catch (InterruptedException e) { LOG.info("Occurred InterruptedException: ", e); } finally { consumerThread.close(); } return String.format("Finished consume messages"); } }
  • 代码样例 以下代码片段是添加用户的示例,在rest.UserManager类的main方法中。 密码明文存储存在安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全。 //访问Manager接口完成添加用户 operationName = "AddUser"; operationUrl = webUrl + ADD_USER_URL; jsonFilePath = "./conf/addUser.json"; httpManager.sendHttpPostRequest(httpClient, operationUrl, jsonFilePath, operationName)
  • 建立连接 以下代码片段在“ClickhouseJDBCHaDemo”类的initConnection方法中。在创建连接时传入表1中配置的user和password作为认证凭据,ClickHouse会带着用户名和密码在服务端进行安全认证。 MRS 3.3.0之前版本: clickHouseProperties.setPassword(userPass); clickHouseProperties.setUser(userName); BalancedClickhouseDataSource balancedClickhouseDataSource = new BalancedClickhouseDataSource(JDBC_PREFIX + UriList, clickHouseProperties); MRS 3.3.0及之后版本: clickHouseProperties.setProperty(ClickHouseDefaults.USER.getKey(), userName); clickHouseProperties.setProperty(ClickHouseDefaults.PASSWORD.getKey(), userPass); try { clickHouseProperties.setProperty(ClickHouseClientOption.FAILOVER.getKey(), "21"); clickHouseProperties.setProperty(ClickHouseClientOption.LOAD_BALANCING_POLICY.getKey(), "roundRobin"); balancedClickhouseDataSource = new ClickHouseDataSource(JDBC_PREFIX + UriList, clickHouseProperties); } catch (Exception e) { LOG.error("Failed to create balancedClickHouseProperties."); throw e; } 父主题: 样例代码说明
  • 代码样例 Properties clickHouseProperties = new Properties(); clickHouseProperties.setProperty(ClickHouseClientOption.CONNECTION_TIMEOUT.getKey(), Integer.toString(60000)); clickHouseProperties.setProperty(ClickHouseClientOption.SSL.getKey(), Boolean.toString(false)); clickHouseProperties.setProperty(ClickHouseClientOption.SSL_MODE.getKey(), "none");