Search in sources :

Example 1 with Result

use of org.apache.dolphinscheduler.api.utils.Result in project dolphinscheduler by apache.

the class DataSourceService method verifyDataSourceName.

/**
 * verify datasource exists
 *
 * @param loginUser login user
 * @param name datasource name
 * @return true if data datasource not exists, otherwise return false
 */
public Result verifyDataSourceName(User loginUser, String name) {
    Result result = new Result();
    List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(name);
    if (dataSourceList != null && dataSourceList.size() > 0) {
        logger.error("datasource name:{} has exist, can't create again.", name);
        putMsg(result, Status.DATASOURCE_EXIST);
    } else {
        putMsg(result, Status.SUCCESS);
    }
    return result;
}
Also used : Result(org.apache.dolphinscheduler.api.utils.Result) DataSource(org.apache.dolphinscheduler.dao.entity.DataSource)

Example 2 with Result

use of org.apache.dolphinscheduler.api.utils.Result in project dolphinscheduler by apache.

the class BaseController method success.

/**
 * success does not need to return data
 *
 * @param msg success message
 * @return success result code
 */
public Result success(String msg) {
    Result result = new Result();
    result.setCode(Status.SUCCESS.getCode());
    result.setMsg(msg);
    return result;
}
Also used : Result(org.apache.dolphinscheduler.api.utils.Result)

Example 3 with Result

use of org.apache.dolphinscheduler.api.utils.Result in project dolphinscheduler by apache.

the class BaseController method success.

/**
 * return data with paging
 *
 * @param totalList success object list
 * @param currentPage current page
 * @param total total
 * @param totalPage  total page
 * @return success result code
 */
public Result success(Object totalList, Integer currentPage, Integer total, Integer totalPage) {
    Result result = new Result();
    result.setCode(Status.SUCCESS.getCode());
    result.setMsg(Status.SUCCESS.getMsg());
    Map<String, Object> map = new HashMap<>(4);
    map.put(Constants.TOTAL_LIST, totalList);
    map.put(Constants.CURRENT_PAGE, currentPage);
    map.put(Constants.TOTAL_PAGE, totalPage);
    map.put(Constants.TOTAL, total);
    result.setData(map);
    return result;
}
Also used : HashMap(java.util.HashMap) Result(org.apache.dolphinscheduler.api.utils.Result)

Example 4 with Result

use of org.apache.dolphinscheduler.api.utils.Result in project dolphinscheduler by apache.

the class BaseController method success.

/**
 * success
 *
 * @return success result code
 */
public Result success() {
    Result result = new Result();
    result.setCode(Status.SUCCESS.getCode());
    result.setMsg(Status.SUCCESS.getMsg());
    return result;
}
Also used : Result(org.apache.dolphinscheduler.api.utils.Result)

Example 5 with Result

use of org.apache.dolphinscheduler.api.utils.Result in project dolphinscheduler by apache.

the class LoggerServiceTest method testQueryDataSourceList.

@Test
public void testQueryDataSourceList() {
    TaskInstance taskInstance = new TaskInstance();
    Mockito.when(processService.findTaskInstanceById(1)).thenReturn(taskInstance);
    Result result = loggerService.queryLog(2, 1, 1);
    // TASK_INSTANCE_NOT_FOUND
    Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND.getCode(), result.getCode().intValue());
    try {
        // HOST NOT FOUND OR ILLEGAL
        result = loggerService.queryLog(1, 1, 1);
    } catch (RuntimeException e) {
        Assert.assertTrue(true);
        logger.error("testQueryDataSourceList error {}", e.getMessage());
    }
    Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND.getCode(), result.getCode().intValue());
    // SUCCESS
    taskInstance.setHost("127.0.0.1:8080");
    taskInstance.setLogPath("/temp/log");
    Mockito.when(processService.findTaskInstanceById(1)).thenReturn(taskInstance);
    result = loggerService.queryLog(1, 1, 1);
    Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
}
Also used : TaskInstance(org.apache.dolphinscheduler.dao.entity.TaskInstance) Result(org.apache.dolphinscheduler.api.utils.Result) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Result (org.apache.dolphinscheduler.api.utils.Result)184 Test (org.junit.Test)155 MvcResult (org.springframework.test.web.servlet.MvcResult)121 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)99 HashMap (java.util.HashMap)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 JSONObject (com.alibaba.fastjson.JSONObject)12 IOException (java.io.IOException)10 User (org.apache.dolphinscheduler.dao.entity.User)9 Ignore (org.junit.Ignore)9 Transactional (org.springframework.transaction.annotation.Transactional)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ServiceException (org.apache.dolphinscheduler.api.exceptions.ServiceException)6 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)6 BeanMap (org.apache.commons.collections.BeanMap)5 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Method (java.lang.reflect.Method)2 ApiException (org.apache.dolphinscheduler.api.exceptions.ApiException)2 DataSource (org.apache.dolphinscheduler.dao.entity.DataSource)2