浏览代码

服务注册与发现

vincent 3 年之前
父节点
当前提交
e1fd2dfefe

+ 211 - 0
config/application.yml

@@ -0,0 +1,211 @@
+#  <<
+#  Davinci
+#  ==
+#  Copyright (C) 2016 - 2019 EDP
+#  ==
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#        http://www.apache.org/licenses/LICENSE-2.0
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#  >>
+
+
+server:
+  protocol: http
+  address: 127.0.0.1
+  port: ${SERVER_PORT:8080}
+
+  servlet:
+    context-path: /
+
+  # Used for mail and download services, can be empty, careful configuration
+  # By default, 'server.address' and 'server.port' is used as the string value.
+  # access:
+  #  address:
+  #  port:
+
+
+## jwt is one of the important configuration of the application
+## jwt config cannot be null or empty
+jwtToken:
+  secret: secret
+  timeout: 1800000
+  algorithm: HS512
+
+
+## your datasource config
+source:
+  initial-size: 1
+  min-idle: 1
+  max-wait: 30000
+  max-active: 10
+  break-after-acquire-failure: false
+  connection-error-retry-attempts: 1
+  time-between-eviction-runs-millis: 2000
+  min-evictable-idle-time-millis: 600000
+  max-evictable-idle-time-millis: 900000
+  time-between-connect-error-millis: 60000
+  test-while-idle: true
+  test-on-borrow: false
+  test-on-return: false
+  validation-query: select 1
+  validation-query-timeout: 10
+  keep-alive: false
+  filters: stat
+
+  enable-query-log: false
+  result-limit: 1000000
+
+
+spring:
+  mvc:
+    async:
+      request-timeout: 30s
+  rest:
+    proxy-host:
+    proxy-port:
+    proxy-ignore:
+
+
+  ## davinci datasource config
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    url: jdbc:mysql://${DATABASE_HOST:61.132.52.38}:${DATABASE_PORT:20002}/${DATABASE_NAME:davinci0.3}?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
+    username: ${DATABASE_USER:root}
+    password: ${DATABASE_PWD:root}
+    driver-class-name: com.mysql.jdbc.Driver
+    initial-size: 1
+    min-idle: 1
+    max-wait: 30000
+    max-active: 10
+    break-after-acquire-failure: false
+    connection-error-retry-attempts: 1
+    time-between-eviction-runs-millis: 2000
+    min-evictable-idle-time-millis: 600000
+    max-evictable-idle-time-millis: 900000
+    time-between-connect-error-millis: 60000
+    test-while-idle: true
+    test-on-borrow: false
+    test-on-return: false
+    validation-query: select 1
+    validation-query-timeout: 10
+    keep-alive: false
+    filters: stat
+
+  ## redis config
+  ## please choose either of the two ways
+  redis:
+    isEnable: false
+
+  ## standalone config
+    host: 127.0.0.1
+    port: 6379
+
+  ## cluster config
+  #  cluster:
+  #       nodes:
+
+    password:
+    database: 0
+    timeout: 1000
+    jedis:
+      pool:
+        max-active: 8
+        max-wait: 1
+        max-idle: 8
+        min-idle: 0
+
+  ## mail is one of the important configuration of the application
+  ## mail config cannot be null or empty
+  ## some mailboxes need to be set separately password for the SMTP service)
+  mail:
+    host: smtp.qq.com
+    port: 465
+    username: 372237882@qq.com
+    fromAddress: 372237882@qq.com
+    password: pdjjxdplzwwzbhic
+    nickname: vincent
+
+    properties:
+      smtp:
+        starttls:
+          enable: true
+          required: true
+        auth: true
+      mail:
+        smtp:
+          ssl:
+            enable: false
+
+  ldap:
+    urls:
+    username:
+    password:
+    base:
+    domainName:    # domainName 指 企业邮箱后缀,如企业邮箱为:xxx@example.com,这里值为 '@example.com'
+
+  security:
+    oauth2:
+      enable: false
+#      client:
+#        registration:
+#          cas:
+#            provider: cas
+#            client-id: "xxxxx"
+#            client-name: "Sign in with XXX"
+#            client-secret: "xxxxx"
+#            authorization-grant-type: authorization_code
+#            client-authentication-method: post
+#            redirect-uri-template: "{baseUrl}/login/oauth2/code/{registrationId}"
+#            scope: userinfo
+#        provider:
+#          cas:
+#            authorization-uri: https://cas.xxxxx.cn/cas/oauth2.0/authorize
+#            token-uri: https://cas.xxxxx.cn/cas/oauth2.0/accessToken
+#            user-info-uri: https://cas.xxxxx.cn/cas/oauth2.0/profile
+#            user-name-attribute: id
+#            userMapping:
+#              email: "attributes.Email"
+#              name: "attributes.CnName1"
+#              avatar: "attributes.Avatar"
+
+screenshot:
+  default_browser: CHROME
+  timeout_second: 600
+  chromedriver_path: $your_chromedriver_path$
+  remote_webdriver_url: $your_remote_webdriver_url$
+
+data-auth-center:
+  channels:
+    - name:
+      base-url:
+      auth-code:
+
+statistic:
+  enable: false
+
+  # You can use external elasticsearch storage [127.0.0.1:9300]
+  elastic_urls:
+  elastic_user:
+  elastic_index_prefix:
+
+  # You can also use external mysql storage
+  mysql_url:
+  mysql_username:
+  mysql_password:
+
+  # You can also use external kafka
+  kafka.bootstrap.servers:
+  kafka.topic:
+  java.security.krb5.conf:
+  java.security.keytab:
+  java.security.principal:
+
+encryption:
+  maxEncryptSize: 1024
+  type: Off # Off is to turn off encryption, to enable encryption, please select AES or RSA

+ 65 - 0
config/datasource_driver.yml

@@ -0,0 +1,65 @@
+##  <<
+##  Davinci
+##  ==
+##  Copyright (C) 2016 - 2019 EDP
+##  ==
+##  Licensed under the Apache License, Version 2.0 (the "License");
+##  you may not use this file except in compliance with the License.
+##  You may obtain a copy of the License at
+##        http://www.apache.org/licenses/LICENSE-2.0
+##   Unless required by applicable law or agreed to in writing, software
+##   distributed under the License is distributed on an "AS IS" BASIS,
+##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+##   See the License for the specific language governing permissions and
+##   limitations under the License.
+##  >>
+
+## This file is used to add databases with jdbc drivers that are not supported by Davinci,
+## ignore this file if your datasource is already supported,
+## the datasource list that have been supported by Davinci:
+##     mysql:           com.mysql.jdbc.Driver
+##     oracle:          oracle.jdbc.driver.OracleDriver
+##     sqlserver:       com.microsoft.sqlserver.jdbc.SQLServerDriver
+##     h2:              org.h2.Driver
+##     phoenix:         org.apache.phoenix.jdbc.PhoenixDriver
+##     mongodb:         mongodb.jdbc.MongoDriver
+##     elasticSearch:   nl.anchormen.sql4es.jdbc.ESDriver
+##     presto:          com.facebook.presto.jdbc.PrestoDriver
+##     moonbox:         moonbox.jdbc.MbDriver
+##     cassandra:       com.github.adejanovski.cassandra.jdbc.CassandraDriver
+##     clickhouse:      ru.yandex.clickhouse.ClickHouseDriver
+##     kylin:           org.apache.kylin.jdbc.Driver
+##     vertica:         com.vertica.jdbc.Driver
+##     hana:            com.sap.db.jdbc.Driver
+##     impala:          com.cloudera.impala.jdbc41.Driver
+## this means that if your datasource is in the above list, you don't need to use this way,
+## unless you know what you are doing.
+
+## How to use:
+##     1. configure your datasource like examples below,
+##     2. add the corresponding dependency file (jar) in lib package,
+##     3. restart your Davinci server
+##  In theory, all databases with jdbc drivers are supported,
+##  if you have problems during using, please with contact us.
+
+## Configuration is as follows:
+
+ mysql:
+   name: mysql
+   desc: mysql
+   version:
+   driver: com.mysql.jdbc.Driver
+   keyword_prefix: \`
+   keyword_suffix: \`
+   alias_prefix: \'
+   alias_suffix: \'
+
+# oracle:
+#   name: oracle
+#   desc: oracle
+#   version: 
+#   driver: oracle.jdbc.driver.OracleDriver
+#   keyword_prefix: \"
+#   keyword_suffix: \"
+#   alias_prefix: \'
+#   alias_suffix: \'

+ 8 - 1
server/src/main/java/edp/DavinciServerApplication.java

@@ -19,11 +19,13 @@
 
 package edp;
 
+
 import com.alibaba.nacos.api.annotation.NacosInjected;
+import com.alibaba.nacos.api.config.annotation.NacosValue;
 import com.alibaba.nacos.api.exception.NacosException;
 import com.alibaba.nacos.api.naming.NamingService;
 import com.alibaba.nacos.client.naming.utils.CollectionUtils;
-import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscovery;
+import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -36,6 +38,7 @@ import javax.annotation.PostConstruct;
         org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration.class,
         org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
 })
+@NacosPropertySource(dataId = "taihu-analysis", autoRefreshed = true)
 @EnableScheduling
 public class DavinciServerApplication {
 
@@ -45,6 +48,9 @@ public class DavinciServerApplication {
     @Value("${server.port}")
     private int serverPort;
 
+    @NacosValue(value = "${person.name}", autoRefreshed = true)
+    private String name;
+
     @Value("${nacos.discovery.server-addr}")
     private String serverAddr;
 
@@ -54,6 +60,7 @@ public class DavinciServerApplication {
     @PostConstruct
     public void registerInstance() throws NacosException
     {
+        System.out.println(name);
         if(CollectionUtils.isEmpty(namingService.getAllInstances(applicationName))){
             namingService.registerInstance(applicationName,serverAddr,serverPort);
         }

+ 1 - 1
server/src/main/java/edp/davinci/controller/SourceController.java

@@ -87,7 +87,7 @@ public class SourceController extends BaseController {
      * @return
      */
     @ApiOperation(value = "get tree sources")
-    @GetMapping
+    @GetMapping(value = "/treeSources")
     public ResponseEntity getTreeSources(@RequestParam Long projectId,
                                      @ApiIgnore @CurrentUser User user,
                                      HttpServletRequest request) {

+ 6 - 0
server/src/main/resources/application.yml

@@ -59,6 +59,12 @@ spring:
 logging:
   config: file:${DAVINCI3_HOME}/config/logback.xml
 
+## nacos 配置
+nacos:
+  discovery:
+    server-addr: 127.0.1.1:8848
+  config:
+    server-addr: 127.0.0.1:8848
 
 springfox:
   documentation:

+ 4 - 4
server/src/main/resources/bootstrap.properties

@@ -1,12 +1,12 @@
 #nacos config
-spring.cloud.nacos.config.server-addr           =${NACOS_CONFIG_SERVER_ADDR:127.0.0.1:8848}
+nacos.config.server-addr           =${NACOS_CONFIG_SERVER_ADDR:127.0.0.1:8848}
 # Nacos Console add configuration:
 # Data ID:maxkey.properties
 # Group:DEFAULT_GROUP
 # configuration:useLocalCache=true
 spring.application.name                         =taihu-analysis
 # Suffix for the configuration. Supports properties,yaml,yml,default is properties
-spring.cloud.nacos.config.file-extension        =properties
-#spring.cloud.nacos.config.file-extension=yaml
+#spring.cloud.nacos.config.file-extension        =properties
+nacos.config.file-extension=yaml
 #nacos enabled
-spring.cloud.nacos.config.enabled               =${NACOS_CONFIG_ENABLED:true}
+nacos.config.enabled               =${NACOS_CONFIG_ENABLED:true}