Unverified Commit f532853f authored by gabry.wu's avatar gabry.wu Committed by GitHub
Browse files

Merge branch 'dev' into removeUnnecessaryLock

parents f1f9b59b a58d1b3b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -514,6 +514,7 @@ public class DataSourceService extends BaseService{
        }

        Map<String, Object> parameterMap = new LinkedHashMap<String, Object>(6);
        parameterMap.put(TYPE, connectType);
        parameterMap.put(Constants.ADDRESS, address);
        parameterMap.put(Constants.DATABASE, database);
        parameterMap.put(Constants.JDBC_URL, jdbcUrl);
+9 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.service;
import org.apache.dolphinscheduler.api.ApiApplicationServer;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.DbConnectType;
import org.apache.dolphinscheduler.common.enums.DbType;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.dao.entity.User;
@@ -50,4 +51,12 @@ public class DataSourceServiceTest {
        Map<String, Object> map = dataSourceService.queryDataSourceList(loginUser, DbType.MYSQL.ordinal());
        Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
    }

    @Test
    public void buildParameter(){
        String param = dataSourceService.buildParameter("","", DbType.ORACLE, "192.168.9.1","1521","im"
                ,"","test","test", DbConnectType.ORACLE_SERVICE_NAME,"");
        String expected = "{\"type\":\"ORACLE_SERVICE_NAME\",\"address\":\"jdbc:oracle:thin:@//192.168.9.1:1521\",\"database\":\"im\",\"jdbcUrl\":\"jdbc:oracle:thin:@//192.168.9.1:1521/im\",\"user\":\"test\",\"password\":\"test\"}";
        Assert.assertEquals(expected, param);
    }
}
 No newline at end of file
+0 −1
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.api.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.avro.generic.GenericData;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
+12 −3
Original line number Diff line number Diff line
@@ -53,6 +53,12 @@ public class OSUtils {
  private static final SystemInfo SI = new SystemInfo();
  public static final String TWO_DECIMAL = "0.00";

  /**
   * return -1 when the function can not get hardware env info
   * e.g {@link OSUtils#loadAverage()} {@link OSUtils#cpuUsage()}
   */
  public static final double NEGATIVE_ONE = -1;

  private static HardwareAbstractionLayer hal = SI.getHardware();

  private OSUtils() {}
@@ -118,9 +124,11 @@ public class OSUtils {
   */
  public static double loadAverage() {
    double loadAverage =  hal.getProcessor().getSystemLoadAverage();
    if (Double.isNaN(loadAverage)) {
      return NEGATIVE_ONE;
    }

    DecimalFormat df = new DecimalFormat(TWO_DECIMAL);

    df.setRoundingMode(RoundingMode.HALF_UP);
    return Double.parseDouble(df.format(loadAverage));
  }
@@ -133,10 +141,12 @@ public class OSUtils {
  public static double cpuUsage() {
    CentralProcessor processor = hal.getProcessor();
    double cpuUsage = processor.getSystemCpuLoad();
    if (Double.isNaN(cpuUsage)) {
      return NEGATIVE_ONE;
    }

    DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
    df.setRoundingMode(RoundingMode.HALF_UP);

    return Double.parseDouble(df.format(cpuUsage));
  }

@@ -393,7 +403,6 @@ public class OSUtils {
    return null;
  }


  /**
   * whether is macOS
   * @return true if mac
+4 −4
Original line number Diff line number Diff line
@@ -41,15 +41,15 @@ public class OSUtilsTest {
    public void testOSMetric(){
        if (!OSUtils.isWindows()) {
            double availablePhysicalMemorySize = OSUtils.availablePhysicalMemorySize();
            Assert.assertTrue(availablePhysicalMemorySize > 0.0f);
            Assert.assertTrue(availablePhysicalMemorySize >= 0.0d);
            double totalMemorySize = OSUtils.totalMemorySize();
            Assert.assertTrue(totalMemorySize > 0.0f);
            Assert.assertTrue(totalMemorySize >= 0.0d);
            double loadAverage = OSUtils.loadAverage();
            logger.info("loadAverage {}", loadAverage);
            double memoryUsage = OSUtils.memoryUsage();
            Assert.assertTrue(memoryUsage > 0.0f);
            Assert.assertTrue(memoryUsage >= 0.0d);
            double cpuUsage = OSUtils.cpuUsage();
            Assert.assertTrue(cpuUsage > 0.0f);
            Assert.assertTrue(cpuUsage >= 0.0d || cpuUsage == -1.0d);
        } else {
            // TODO window ut
        }
Loading