Browse Source
* support multi environments * add some test cases * add an environment vue component * improve environment form * improve environment form * add environment worker group relation * add environment worker group relation * add the environment choice for formModel * set an environment for the task * modify the modal form of starting process * add the environment config to TaskExecutionContext * add the environment config to the timing form * fix conflicts * fix issues of the code style * fix some issues of the code style * fix some issues of the code style * fix some issues of the code style * fix some issues of the code style * fix some issues of the code style * fix some bugs in the code review * add the same table and columns to support H2 * fix some bugs2.0.7-release
Hua Jiang
3 years ago
committed by
GitHub
70 changed files with 3876 additions and 146 deletions
@ -0,0 +1,240 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.controller; |
||||||
|
|
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.CREATE_ENVIRONMENT_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_ENVIRONMENT_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ENVIRONMENT_BY_CODE_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ENVIRONMENT_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ENVIRONMENT_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_ENVIRONMENT_ERROR; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; |
||||||
|
import org.apache.dolphinscheduler.api.exceptions.ApiException; |
||||||
|
import org.apache.dolphinscheduler.api.service.EnvironmentService; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.common.utils.ParameterUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestAttribute; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import springfox.documentation.annotations.ApiIgnore; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment controller |
||||||
|
*/ |
||||||
|
@Api(tags = "ENVIRONMENT_TAG") |
||||||
|
@RestController |
||||||
|
@RequestMapping("environment") |
||||||
|
public class EnvironmentController extends BaseController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private EnvironmentService environmentService; |
||||||
|
|
||||||
|
/** |
||||||
|
* create environment |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param name environment name |
||||||
|
* @param config config |
||||||
|
* @param description description |
||||||
|
* @return returns an error if it exists |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "createEnvironment", notes = "CREATE_ENVIRONMENT_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "name", value = "ENVIRONMENT_NAME", required = true, dataType = "String"), |
||||||
|
@ApiImplicitParam(name = "config", value = "CONFIG", required = true, dataType = "String"), |
||||||
|
@ApiImplicitParam(name = "description", value = "ENVIRONMENT_DESC", dataType = "String"), |
||||||
|
@ApiImplicitParam(name = "workerGroups", value = "WORKER_GROUP_LIST", dataType = "String") |
||||||
|
}) |
||||||
|
@PostMapping(value = "/create") |
||||||
|
@ResponseStatus(HttpStatus.CREATED) |
||||||
|
@ApiException(CREATE_ENVIRONMENT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result createProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("name") String name, |
||||||
|
@RequestParam("config") String config, |
||||||
|
@RequestParam(value = "description", required = false) String description, |
||||||
|
@RequestParam(value = "workerGroups", required = false) String workerGroups) { |
||||||
|
|
||||||
|
Map<String, Object> result = environmentService.createEnvironment(loginUser, name, config, description, workerGroups); |
||||||
|
return returnDataList(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* update environment |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param code environment code |
||||||
|
* @param name environment name |
||||||
|
* @param config environment config |
||||||
|
* @param description description |
||||||
|
* @return update result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "updateEnvironment", notes = "UPDATE_ENVIRONMENT_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "code", value = "ENVIRONMENT_CODE", required = true, dataType = "Long", example = "100"), |
||||||
|
@ApiImplicitParam(name = "name", value = "ENVIRONMENT_NAME", required = true, dataType = "String"), |
||||||
|
@ApiImplicitParam(name = "config", value = "ENVIRONMENT_CONFIG", required = true, dataType = "String"), |
||||||
|
@ApiImplicitParam(name = "description", value = "ENVIRONMENT_DESC", dataType = "String"), |
||||||
|
@ApiImplicitParam(name = "workerGroups", value = "WORKER_GROUP_LIST", dataType = "String") |
||||||
|
}) |
||||||
|
@PostMapping(value = "/update") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(UPDATE_ENVIRONMENT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result updateEnvironment(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("code") Long code, |
||||||
|
@RequestParam("name") String name, |
||||||
|
@RequestParam("config") String config, |
||||||
|
@RequestParam(value = "description", required = false) String description, |
||||||
|
@RequestParam(value = "workerGroups", required = false) String workerGroups) { |
||||||
|
Map<String, Object> result = environmentService.updateEnvironmentByCode(loginUser, code, name, config, description, workerGroups); |
||||||
|
return returnDataList(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment details by code |
||||||
|
* |
||||||
|
* @param environmentCode environment code |
||||||
|
* @return environment detail information |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryEnvironmentByCode", notes = "QUERY_ENVIRONMENT_BY_CODE_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "environmentCode", value = "ENVIRONMENT_CODE", required = true, dataType = "Long", example = "100") |
||||||
|
}) |
||||||
|
@GetMapping(value = "/query-by-code") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_ENVIRONMENT_BY_CODE_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result queryEnvironmentByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("environmentCode") Long environmentCode) { |
||||||
|
|
||||||
|
Map<String, Object> result = environmentService.queryEnvironmentByCode(environmentCode); |
||||||
|
return returnDataList(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment list paging |
||||||
|
* |
||||||
|
* @param searchVal search value |
||||||
|
* @param pageSize page size |
||||||
|
* @param pageNo page number |
||||||
|
* @return environment list which the login user have permission to see |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryEnvironmentListPaging", notes = "QUERY_ENVIRONMENT_LIST_PAGING_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), |
||||||
|
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20"), |
||||||
|
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1") |
||||||
|
}) |
||||||
|
@GetMapping(value = "/list-paging") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_ENVIRONMENT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result queryEnvironmentListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam(value = "searchVal", required = false) String searchVal, |
||||||
|
@RequestParam("pageSize") Integer pageSize, |
||||||
|
@RequestParam("pageNo") Integer pageNo |
||||||
|
) { |
||||||
|
|
||||||
|
Result result = checkPageParams(pageNo, pageSize); |
||||||
|
if (!result.checkResult()) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
searchVal = ParameterUtils.handleEscapes(searchVal); |
||||||
|
result = environmentService.queryEnvironmentListPaging(pageNo, pageSize, searchVal); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete environment by code |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param environmentCode environment code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "deleteEnvironmentByCode", notes = "DELETE_ENVIRONMENT_BY_CODE_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "environmentCode", value = "ENVIRONMENT_CODE", required = true, dataType = "Long", example = "100") |
||||||
|
}) |
||||||
|
@PostMapping(value = "/delete") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(DELETE_ENVIRONMENT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result deleteEnvironment(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("environmentCode") Long environmentCode |
||||||
|
) { |
||||||
|
|
||||||
|
Map<String, Object> result = environmentService.deleteEnvironmentByCode(loginUser, environmentCode); |
||||||
|
return returnDataList(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query all environment list |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @return all environment list |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryAllEnvironmentList", notes = "QUERY_ALL_ENVIRONMENT_LIST_NOTES") |
||||||
|
@GetMapping(value = "/query-environment-list") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_ENVIRONMENT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result queryAllEnvironmentList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { |
||||||
|
Map<String, Object> result = environmentService.queryAllEnvironmentList(); |
||||||
|
return returnDataList(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* verify environment and environment name |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param environmentName environment name |
||||||
|
* @return true if the environment name not exists, otherwise return false |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "verifyEnvironment", notes = "VERIFY_ENVIRONMENT_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "environmentName", value = "ENVIRONMENT_NAME", required = true, dataType = "String") |
||||||
|
}) |
||||||
|
@PostMapping(value = "/verify-environment") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(VERIFY_ENVIRONMENT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result verifyEnvironment(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam(value = "environmentName") String environmentName |
||||||
|
) { |
||||||
|
Map<String, Object> result = environmentService.verifyEnvironment(environmentName); |
||||||
|
return returnDataList(result); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,129 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.dto; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* EnvironmentDto |
||||||
|
*/ |
||||||
|
public class EnvironmentDto { |
||||||
|
|
||||||
|
private int id; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment code |
||||||
|
*/ |
||||||
|
private Long code; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment name |
||||||
|
*/ |
||||||
|
private String name; |
||||||
|
|
||||||
|
/** |
||||||
|
* config content |
||||||
|
*/ |
||||||
|
private String config; |
||||||
|
|
||||||
|
private String description; |
||||||
|
|
||||||
|
private List<String> workerGroups; |
||||||
|
|
||||||
|
/** |
||||||
|
* operator user id |
||||||
|
*/ |
||||||
|
private Integer operator; |
||||||
|
|
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
private Date updateTime; |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public Long getCode() { |
||||||
|
return this.code; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCode(Long code) { |
||||||
|
this.code = code; |
||||||
|
} |
||||||
|
|
||||||
|
public String getConfig() { |
||||||
|
return this.config; |
||||||
|
} |
||||||
|
|
||||||
|
public void setConfig(String config) { |
||||||
|
this.config = config; |
||||||
|
} |
||||||
|
|
||||||
|
public String getDescription() { |
||||||
|
return this.description; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDescription(String description) { |
||||||
|
this.description = description; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getOperator() { |
||||||
|
return this.operator; |
||||||
|
} |
||||||
|
|
||||||
|
public void setOperator(Integer operator) { |
||||||
|
this.operator = operator; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getCreateTime() { |
||||||
|
return createTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) { |
||||||
|
this.createTime = createTime; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getUpdateTime() { |
||||||
|
return updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUpdateTime(Date updateTime) { |
||||||
|
this.updateTime = updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
public List<String> getWorkerGroups() { |
||||||
|
return workerGroups; |
||||||
|
} |
||||||
|
|
||||||
|
public void setWorkerGroups(List<String> workerGroups) { |
||||||
|
this.workerGroups = workerGroups; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,102 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment service |
||||||
|
*/ |
||||||
|
public interface EnvironmentService { |
||||||
|
|
||||||
|
/** |
||||||
|
* create environment |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param name environment name |
||||||
|
* @param config environment config |
||||||
|
* @param desc environment desc |
||||||
|
* @param workerGroups worker groups |
||||||
|
*/ |
||||||
|
Map<String, Object> createEnvironment(User loginUser, String name, String config, String desc, String workerGroups); |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment |
||||||
|
* |
||||||
|
* @param name environment name |
||||||
|
*/ |
||||||
|
Map<String, Object> queryEnvironmentByName(String name); |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment |
||||||
|
* |
||||||
|
* @param code environment code |
||||||
|
*/ |
||||||
|
Map<String, Object> queryEnvironmentByCode(Long code); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* delete environment |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param code environment code |
||||||
|
*/ |
||||||
|
Map<String, Object> deleteEnvironmentByCode(User loginUser, Long code); |
||||||
|
|
||||||
|
/** |
||||||
|
* update environment |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param code environment code |
||||||
|
* @param name environment name |
||||||
|
* @param config environment config |
||||||
|
* @param desc environment desc |
||||||
|
* @param workerGroups worker groups |
||||||
|
*/ |
||||||
|
Map<String, Object> updateEnvironmentByCode(User loginUser, Long code, String name, String config, String desc, String workerGroups); |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment paging |
||||||
|
* |
||||||
|
* @param pageNo page number |
||||||
|
* @param searchVal search value |
||||||
|
* @param pageSize page size |
||||||
|
* @return environment list page |
||||||
|
*/ |
||||||
|
Result queryEnvironmentListPaging(Integer pageNo, Integer pageSize, String searchVal); |
||||||
|
|
||||||
|
/** |
||||||
|
* query all environment |
||||||
|
* |
||||||
|
* @return all environment list |
||||||
|
*/ |
||||||
|
Map<String, Object> queryAllEnvironmentList(); |
||||||
|
|
||||||
|
/** |
||||||
|
* verify environment name |
||||||
|
* |
||||||
|
* @param environmentName environment name |
||||||
|
* @return true if the environment name not exists, otherwise return false |
||||||
|
*/ |
||||||
|
Map<String, Object> verifyEnvironment(String environmentName); |
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment worker group relation service |
||||||
|
*/ |
||||||
|
public interface EnvironmentWorkerGroupRelationService { |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment worker group relation |
||||||
|
* |
||||||
|
* @param environmentCode environment code |
||||||
|
*/ |
||||||
|
Map<String, Object> queryEnvironmentWorkerGroupRelation(Long environmentCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* query all environment worker group relation |
||||||
|
* |
||||||
|
* @return all relation list |
||||||
|
*/ |
||||||
|
Map<String, Object> queryAllEnvironmentWorkerGroupRelationList(); |
||||||
|
} |
||||||
|
|
@ -0,0 +1,463 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service.impl; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.dto.EnvironmentDto; |
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.EnvironmentService; |
||||||
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.common.utils.CollectionUtils; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.common.utils.SnowFlakeUtils; |
||||||
|
import org.apache.dolphinscheduler.common.utils.SnowFlakeUtils.SnowFlakeException; |
||||||
|
import org.apache.dolphinscheduler.common.utils.StringUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Environment; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
||||||
|
|
||||||
|
import org.apache.commons.collections4.SetUtils; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Objects; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.TreeSet; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.BeanUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import com.fasterxml.jackson.core.type.TypeReference; |
||||||
|
|
||||||
|
/** |
||||||
|
* task definition service impl |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class EnvironmentServiceImpl extends BaseServiceImpl implements EnvironmentService { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(EnvironmentServiceImpl.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private EnvironmentMapper environmentMapper; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private EnvironmentWorkerGroupRelationMapper relationMapper; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TaskDefinitionMapper taskDefinitionMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* create environment |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param name environment name |
||||||
|
* @param config environment config |
||||||
|
* @param desc environment desc |
||||||
|
* @param workerGroups worker groups |
||||||
|
*/ |
||||||
|
@Transactional(rollbackFor = RuntimeException.class) |
||||||
|
@Override |
||||||
|
public Map<String, Object> createEnvironment(User loginUser, String name, String config, String desc, String workerGroups) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
if (isNotAdmin(loginUser, result)) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
Map<String, Object> checkResult = checkParams(name,config,workerGroups); |
||||||
|
if (checkResult.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return checkResult; |
||||||
|
} |
||||||
|
|
||||||
|
Environment environment = environmentMapper.queryByEnvironmentName(name); |
||||||
|
if (environment != null) { |
||||||
|
putMsg(result, Status.ENVIRONMENT_NAME_EXISTS, name); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
Environment env = new Environment(); |
||||||
|
env.setName(name); |
||||||
|
env.setConfig(config); |
||||||
|
env.setDescription(desc); |
||||||
|
env.setOperator(loginUser.getId()); |
||||||
|
env.setCreateTime(new Date()); |
||||||
|
env.setUpdateTime(new Date()); |
||||||
|
long code = 0L; |
||||||
|
try { |
||||||
|
code = SnowFlakeUtils.getInstance().nextId(); |
||||||
|
env.setCode(code); |
||||||
|
} catch (SnowFlakeException e) { |
||||||
|
logger.error("Environment code get error, ", e); |
||||||
|
} |
||||||
|
if (code == 0L) { |
||||||
|
putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS, "Error generating environment code"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
if (environmentMapper.insert(env) > 0) { |
||||||
|
if (StringUtils.isNotEmpty(workerGroups)) { |
||||||
|
List<String> workerGroupList = JSONUtils.parseObject(workerGroups, new TypeReference<List<String>>(){}); |
||||||
|
if (CollectionUtils.isNotEmpty(workerGroupList)) { |
||||||
|
workerGroupList.stream().forEach(workerGroup -> { |
||||||
|
if (StringUtils.isNotEmpty(workerGroup)) { |
||||||
|
EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation(); |
||||||
|
relation.setEnvironmentCode(env.getCode()); |
||||||
|
relation.setWorkerGroup(workerGroup); |
||||||
|
relation.setOperator(loginUser.getId()); |
||||||
|
relation.setCreateTime(new Date()); |
||||||
|
relation.setUpdateTime(new Date()); |
||||||
|
relationMapper.insert(relation); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
result.put(Constants.DATA_LIST, env.getCode()); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} else { |
||||||
|
putMsg(result, Status.CREATE_ENVIRONMENT_ERROR); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment paging |
||||||
|
* |
||||||
|
* @param pageNo page number |
||||||
|
* @param searchVal search value |
||||||
|
* @param pageSize page size |
||||||
|
* @return environment list page |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Result queryEnvironmentListPaging(Integer pageNo, Integer pageSize, String searchVal) { |
||||||
|
Result result = new Result(); |
||||||
|
|
||||||
|
Page<Environment> page = new Page<>(pageNo, pageSize); |
||||||
|
|
||||||
|
IPage<Environment> environmentIPage = environmentMapper.queryEnvironmentListPaging(page, searchVal); |
||||||
|
|
||||||
|
PageInfo<EnvironmentDto> pageInfo = new PageInfo<>(pageNo, pageSize); |
||||||
|
pageInfo.setTotal((int) environmentIPage.getTotal()); |
||||||
|
|
||||||
|
if (CollectionUtils.isNotEmpty(environmentIPage.getRecords())) { |
||||||
|
Map<Long, List<String>> relationMap = relationMapper.selectList(null).stream() |
||||||
|
.collect(Collectors.groupingBy(EnvironmentWorkerGroupRelation::getEnvironmentCode,Collectors.mapping(EnvironmentWorkerGroupRelation::getWorkerGroup,Collectors.toList()))); |
||||||
|
|
||||||
|
List<EnvironmentDto> dtoList = environmentIPage.getRecords().stream().map(environment -> { |
||||||
|
EnvironmentDto dto = new EnvironmentDto(); |
||||||
|
BeanUtils.copyProperties(environment,dto); |
||||||
|
List<String> workerGroups = relationMap.getOrDefault(environment.getCode(),new ArrayList<String>()); |
||||||
|
dto.setWorkerGroups(workerGroups); |
||||||
|
return dto; |
||||||
|
}).collect(Collectors.toList()); |
||||||
|
|
||||||
|
pageInfo.setTotalList(dtoList); |
||||||
|
} else { |
||||||
|
pageInfo.setTotalList(new ArrayList<>()); |
||||||
|
} |
||||||
|
|
||||||
|
result.setData(pageInfo); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query all environment |
||||||
|
* |
||||||
|
* @return all environment list |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> queryAllEnvironmentList() { |
||||||
|
Map<String,Object> result = new HashMap<>(); |
||||||
|
List<Environment> environmentList = environmentMapper.queryAllEnvironmentList(); |
||||||
|
|
||||||
|
if (CollectionUtils.isNotEmpty(environmentList)) { |
||||||
|
Map<Long, List<String>> relationMap = relationMapper.selectList(null).stream() |
||||||
|
.collect(Collectors.groupingBy(EnvironmentWorkerGroupRelation::getEnvironmentCode,Collectors.mapping(EnvironmentWorkerGroupRelation::getWorkerGroup,Collectors.toList()))); |
||||||
|
|
||||||
|
List<EnvironmentDto> dtoList = environmentList.stream().map(environment -> { |
||||||
|
EnvironmentDto dto = new EnvironmentDto(); |
||||||
|
BeanUtils.copyProperties(environment,dto); |
||||||
|
List<String> workerGroups = relationMap.getOrDefault(environment.getCode(),new ArrayList<String>()); |
||||||
|
dto.setWorkerGroups(workerGroups); |
||||||
|
return dto; |
||||||
|
}).collect(Collectors.toList()); |
||||||
|
result.put(Constants.DATA_LIST,dtoList); |
||||||
|
} else { |
||||||
|
result.put(Constants.DATA_LIST, new ArrayList<>()); |
||||||
|
} |
||||||
|
|
||||||
|
putMsg(result,Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment |
||||||
|
* |
||||||
|
* @param code environment code |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> queryEnvironmentByCode(Long code) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
|
||||||
|
Environment env = environmentMapper.queryByEnvironmentCode(code); |
||||||
|
|
||||||
|
if (env == null) { |
||||||
|
putMsg(result, Status.QUERY_ENVIRONMENT_BY_CODE_ERROR, code); |
||||||
|
} else { |
||||||
|
List<String> workerGroups = relationMapper.queryByEnvironmentCode(env.getCode()).stream() |
||||||
|
.map(item -> item.getWorkerGroup()) |
||||||
|
.collect(Collectors.toList()); |
||||||
|
|
||||||
|
EnvironmentDto dto = new EnvironmentDto(); |
||||||
|
BeanUtils.copyProperties(env,dto); |
||||||
|
dto.setWorkerGroups(workerGroups); |
||||||
|
result.put(Constants.DATA_LIST, dto); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment |
||||||
|
* |
||||||
|
* @param name environment name |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> queryEnvironmentByName(String name) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
|
||||||
|
Environment env = environmentMapper.queryByEnvironmentName(name); |
||||||
|
if (env == null) { |
||||||
|
putMsg(result, Status.QUERY_ENVIRONMENT_BY_NAME_ERROR, name); |
||||||
|
} else { |
||||||
|
List<String> workerGroups = relationMapper.queryByEnvironmentCode(env.getCode()).stream() |
||||||
|
.map(item -> item.getWorkerGroup()) |
||||||
|
.collect(Collectors.toList()); |
||||||
|
|
||||||
|
EnvironmentDto dto = new EnvironmentDto(); |
||||||
|
BeanUtils.copyProperties(env,dto); |
||||||
|
dto.setWorkerGroups(workerGroups); |
||||||
|
result.put(Constants.DATA_LIST, dto); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete environment |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param code environment code |
||||||
|
*/ |
||||||
|
@Transactional(rollbackFor = RuntimeException.class) |
||||||
|
@Override |
||||||
|
public Map<String, Object> deleteEnvironmentByCode(User loginUser, Long code) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
if (isNotAdmin(loginUser, result)) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
Integer relatedTaskNumber = taskDefinitionMapper |
||||||
|
.selectCount(new QueryWrapper<TaskDefinition>().lambda().eq(TaskDefinition::getEnvironmentCode,code)); |
||||||
|
|
||||||
|
if (relatedTaskNumber > 0) { |
||||||
|
putMsg(result, Status.DELETE_ENVIRONMENT_RELATED_TASK_EXISTS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
int delete = environmentMapper.deleteByCode(code); |
||||||
|
if (delete > 0) { |
||||||
|
relationMapper.delete(new QueryWrapper<EnvironmentWorkerGroupRelation>() |
||||||
|
.lambda() |
||||||
|
.eq(EnvironmentWorkerGroupRelation::getEnvironmentCode,code)); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} else { |
||||||
|
putMsg(result, Status.DELETE_ENVIRONMENT_ERROR); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* update environment |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param code environment code |
||||||
|
* @param name environment name |
||||||
|
* @param config environment config |
||||||
|
* @param desc environment desc |
||||||
|
* @param workerGroups worker groups |
||||||
|
*/ |
||||||
|
@Transactional(rollbackFor = RuntimeException.class) |
||||||
|
@Override |
||||||
|
public Map<String, Object> updateEnvironmentByCode(User loginUser, Long code, String name, String config, String desc, String workerGroups) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
if (isNotAdmin(loginUser, result)) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
Map<String, Object> checkResult = checkParams(name,config,workerGroups); |
||||||
|
if (checkResult.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return checkResult; |
||||||
|
} |
||||||
|
|
||||||
|
Environment environment = environmentMapper.queryByEnvironmentName(name); |
||||||
|
if (environment != null && !environment.getCode().equals(code)) { |
||||||
|
putMsg(result, Status.ENVIRONMENT_NAME_EXISTS, name); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
Set<String> workerGroupSet; |
||||||
|
if (StringUtils.isNotEmpty(workerGroups)) { |
||||||
|
workerGroupSet = JSONUtils.parseObject(workerGroups, new TypeReference<Set<String>>() {}); |
||||||
|
} else { |
||||||
|
workerGroupSet = new TreeSet<>(); |
||||||
|
} |
||||||
|
|
||||||
|
Set<String> existWorkerGroupSet = relationMapper |
||||||
|
.queryByEnvironmentCode(code) |
||||||
|
.stream() |
||||||
|
.map(item -> item.getWorkerGroup()) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
|
||||||
|
Set<String> deleteWorkerGroupSet = SetUtils.difference(existWorkerGroupSet,workerGroupSet).toSet(); |
||||||
|
Set<String> addWorkerGroupSet = SetUtils.difference(workerGroupSet,existWorkerGroupSet).toSet(); |
||||||
|
|
||||||
|
// verify whether the relation of this environment and worker groups can be adjusted
|
||||||
|
checkResult = checkUsedEnvironmentWorkerGroupRelation(deleteWorkerGroupSet, name, code); |
||||||
|
if (checkResult.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return checkResult; |
||||||
|
} |
||||||
|
|
||||||
|
Environment env = new Environment(); |
||||||
|
env.setCode(code); |
||||||
|
env.setName(name); |
||||||
|
env.setConfig(config); |
||||||
|
env.setDescription(desc); |
||||||
|
env.setOperator(loginUser.getId()); |
||||||
|
env.setUpdateTime(new Date()); |
||||||
|
|
||||||
|
int update = environmentMapper.update(env, new UpdateWrapper<Environment>().lambda().eq(Environment::getCode,code)); |
||||||
|
if (update > 0) { |
||||||
|
deleteWorkerGroupSet.stream().forEach(key -> { |
||||||
|
if (StringUtils.isNotEmpty(key)) { |
||||||
|
relationMapper.delete(new QueryWrapper<EnvironmentWorkerGroupRelation>() |
||||||
|
.lambda() |
||||||
|
.eq(EnvironmentWorkerGroupRelation::getEnvironmentCode,code)); |
||||||
|
} |
||||||
|
}); |
||||||
|
addWorkerGroupSet.stream().forEach(key -> { |
||||||
|
if (StringUtils.isNotEmpty(key)) { |
||||||
|
EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation(); |
||||||
|
relation.setEnvironmentCode(code); |
||||||
|
relation.setWorkerGroup(key); |
||||||
|
relation.setUpdateTime(new Date()); |
||||||
|
relation.setCreateTime(new Date()); |
||||||
|
relation.setOperator(loginUser.getId()); |
||||||
|
relationMapper.insert(relation); |
||||||
|
} |
||||||
|
}); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} else { |
||||||
|
putMsg(result, Status.UPDATE_ENVIRONMENT_ERROR, name); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* verify environment name |
||||||
|
* |
||||||
|
* @param environmentName environment name |
||||||
|
* @return true if the environment name not exists, otherwise return false |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> verifyEnvironment(String environmentName) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
|
||||||
|
if (StringUtils.isEmpty(environmentName)) { |
||||||
|
putMsg(result, Status.ENVIRONMENT_NAME_IS_NULL); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
Environment environment = environmentMapper.queryByEnvironmentName(environmentName); |
||||||
|
if (environment != null) { |
||||||
|
putMsg(result, Status.ENVIRONMENT_NAME_EXISTS, environmentName); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
result.put(Constants.STATUS, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String, Object> checkUsedEnvironmentWorkerGroupRelation(Set<String> deleteKeySet,String environmentName, Long environmentCode) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
for (String workerGroup : deleteKeySet) { |
||||||
|
TaskDefinition taskDefinition = taskDefinitionMapper |
||||||
|
.selectOne(new QueryWrapper<TaskDefinition>().lambda() |
||||||
|
.eq(TaskDefinition::getEnvironmentCode,environmentCode) |
||||||
|
.eq(TaskDefinition::getWorkerGroup,workerGroup)); |
||||||
|
|
||||||
|
if (Objects.nonNull(taskDefinition)) { |
||||||
|
putMsg(result, Status.UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR,workerGroup,environmentName,taskDefinition.getName()); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
result.put(Constants.STATUS, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
public Map<String, Object> checkParams(String name, String config, String workerGroups) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
if (StringUtils.isEmpty(name)) { |
||||||
|
putMsg(result, Status.ENVIRONMENT_NAME_IS_NULL); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (StringUtils.isEmpty(config)) { |
||||||
|
putMsg(result, Status.ENVIRONMENT_CONFIG_IS_NULL); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (StringUtils.isNotEmpty(workerGroups)) { |
||||||
|
List<String> workerGroupList = JSONUtils.parseObject(workerGroups, new TypeReference<List<String>>(){}); |
||||||
|
if (Objects.isNull(workerGroupList)) { |
||||||
|
putMsg(result, Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
result.put(Constants.STATUS, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,76 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service.impl; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.EnvironmentWorkerGroupRelationService; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* task definition service impl |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class EnvironmentWorkerGroupRelationServiceImpl extends BaseServiceImpl implements |
||||||
|
EnvironmentWorkerGroupRelationService { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(EnvironmentWorkerGroupRelationServiceImpl.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private EnvironmentWorkerGroupRelationMapper environmentWorkerGroupRelationMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment worker group relation |
||||||
|
* |
||||||
|
* @param environmentCode environment code |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> queryEnvironmentWorkerGroupRelation(Long environmentCode) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
List<EnvironmentWorkerGroupRelation> relations = environmentWorkerGroupRelationMapper.queryByEnvironmentCode(environmentCode); |
||||||
|
result.put(Constants.DATA_LIST, relations); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query all environment worker group relation |
||||||
|
* |
||||||
|
* @return all relation list |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> queryAllEnvironmentWorkerGroupRelationList() { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
|
||||||
|
List<EnvironmentWorkerGroupRelation> relations = environmentWorkerGroupRelationMapper.selectList(null); |
||||||
|
|
||||||
|
result.put(Constants.DATA_LIST,relations); |
||||||
|
putMsg(result,Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,208 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.controller; |
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.common.utils.Preconditions; |
||||||
|
|
||||||
|
import org.junit.After; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.test.web.servlet.MvcResult; |
||||||
|
import org.springframework.util.LinkedMultiValueMap; |
||||||
|
import org.springframework.util.MultiValueMap; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment controller test |
||||||
|
*/ |
||||||
|
public class EnvironmentControllerTest extends AbstractControllerTest { |
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(EnvironmentControllerTest.class); |
||||||
|
|
||||||
|
private String environmentCode; |
||||||
|
|
||||||
|
public static final String environmentName = "Env1"; |
||||||
|
|
||||||
|
public static final String config = "this is config content"; |
||||||
|
|
||||||
|
public static final String desc = "this is environment description"; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void before() throws Exception { |
||||||
|
testCreateEnvironment(); |
||||||
|
} |
||||||
|
|
||||||
|
@After |
||||||
|
public void after() throws Exception { |
||||||
|
testDeleteEnvironment(); |
||||||
|
} |
||||||
|
|
||||||
|
public void testCreateEnvironment() throws Exception { |
||||||
|
|
||||||
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
||||||
|
paramsMap.add("name",environmentName); |
||||||
|
paramsMap.add("config",config); |
||||||
|
paramsMap.add("description",desc); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(post("/environment/create") |
||||||
|
.header(SESSION_ID, sessionId) |
||||||
|
.params(paramsMap)) |
||||||
|
.andExpect(status().isCreated()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), new TypeReference<Result<String>>() {}); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertTrue(result != null && result.isSuccess()); |
||||||
|
Assert.assertNotNull(result.getData()); |
||||||
|
logger.info("create environment return result:{}", mvcResult.getResponse().getContentAsString()); |
||||||
|
|
||||||
|
environmentCode = (String)result.getData(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testUpdateEnvironment() throws Exception { |
||||||
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
||||||
|
paramsMap.add("code", environmentCode); |
||||||
|
paramsMap.add("name","environment_test_update"); |
||||||
|
paramsMap.add("config","this is config content"); |
||||||
|
paramsMap.add("desc","the test environment update"); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(post("/environment/update") |
||||||
|
.header(SESSION_ID, sessionId) |
||||||
|
.params(paramsMap)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertTrue(result != null && result.isSuccess()); |
||||||
|
logger.info("update environment return result:{}", mvcResult.getResponse().getContentAsString()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryEnvironmentByCode() throws Exception { |
||||||
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
||||||
|
paramsMap.add("environmentCode", environmentCode); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(get("/environment/query-by-code") |
||||||
|
.header(SESSION_ID, sessionId) |
||||||
|
.params(paramsMap)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertTrue(result != null && result.isSuccess()); |
||||||
|
logger.info(mvcResult.getResponse().getContentAsString()); |
||||||
|
logger.info("query environment by id :{}, return result:{}", environmentCode, mvcResult.getResponse().getContentAsString()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryEnvironmentListPaging() throws Exception { |
||||||
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
||||||
|
paramsMap.add("searchVal","test"); |
||||||
|
paramsMap.add("pageSize","2"); |
||||||
|
paramsMap.add("pageNo","2"); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(get("/environment/list-paging") |
||||||
|
.header(SESSION_ID, sessionId) |
||||||
|
.params(paramsMap)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertTrue(result != null && result.isSuccess()); |
||||||
|
logger.info("query list-paging environment return result:{}", mvcResult.getResponse().getContentAsString()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryAllEnvironmentList() throws Exception { |
||||||
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(get("/environment/query-environment-list") |
||||||
|
.header(SESSION_ID, sessionId) |
||||||
|
.params(paramsMap)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertTrue(result != null && result.isSuccess()); |
||||||
|
logger.info("query all environment return result:{}", mvcResult.getResponse().getContentAsString()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testVerifyEnvironment() throws Exception { |
||||||
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
||||||
|
paramsMap.add("environmentName",environmentName); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(post("/environment/verify-environment") |
||||||
|
.header(SESSION_ID, sessionId) |
||||||
|
.params(paramsMap)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertTrue(result.isStatus(Status.ENVIRONMENT_NAME_EXISTS)); |
||||||
|
logger.info("verify environment return result:{}", mvcResult.getResponse().getContentAsString()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void testDeleteEnvironment() throws Exception { |
||||||
|
Preconditions.checkNotNull(environmentCode); |
||||||
|
|
||||||
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
||||||
|
paramsMap.add("environmentCode", environmentCode); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(post("/environment/delete") |
||||||
|
.header(SESSION_ID, sessionId) |
||||||
|
.params(paramsMap)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertTrue(result != null && result.isSuccess()); |
||||||
|
logger.info("delete environment return result:{}", mvcResult.getResponse().getContentAsString()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,310 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.impl.EnvironmentServiceImpl; |
||||||
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.common.enums.UserType; |
||||||
|
import org.apache.dolphinscheduler.common.utils.CollectionUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Environment; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.assertj.core.util.Lists; |
||||||
|
import org.junit.After; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.InjectMocks; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment service test |
||||||
|
*/ |
||||||
|
@RunWith(MockitoJUnitRunner.class) |
||||||
|
public class EnvironmentServiceTest { |
||||||
|
|
||||||
|
public static final Logger logger = LoggerFactory.getLogger(EnvironmentServiceTest.class); |
||||||
|
|
||||||
|
@InjectMocks |
||||||
|
private EnvironmentServiceImpl environmentService; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private EnvironmentMapper environmentMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private EnvironmentWorkerGroupRelationMapper relationMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private TaskDefinitionMapper taskDefinitionMapper; |
||||||
|
|
||||||
|
public static final String testUserName = "environmentServerTest"; |
||||||
|
|
||||||
|
public static final String environmentName = "Env1"; |
||||||
|
|
||||||
|
public static final String workerGroups = "[\"default\"]"; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp(){ |
||||||
|
} |
||||||
|
|
||||||
|
@After |
||||||
|
public void after(){ |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testCreateEnvironment() { |
||||||
|
User loginUser = getGeneralUser(); |
||||||
|
Map<String, Object> result = environmentService.createEnvironment(loginUser,environmentName,getConfig(),getDesc(),workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
loginUser = getAdminUser(); |
||||||
|
result = environmentService.createEnvironment(loginUser,environmentName,"",getDesc(),workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_CONFIG_IS_NULL, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
result = environmentService.createEnvironment(loginUser,"",getConfig(),getDesc(),workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_NAME_IS_NULL, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
result = environmentService.createEnvironment(loginUser,environmentName,getConfig(),getDesc(),"test"); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
Mockito.when(environmentMapper.queryByEnvironmentName(environmentName)).thenReturn(getEnvironment()); |
||||||
|
result = environmentService.createEnvironment(loginUser,environmentName,getConfig(),getDesc(),workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_NAME_EXISTS, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
Mockito.when(environmentMapper.insert(Mockito.any(Environment.class))).thenReturn(1); |
||||||
|
Mockito.when(relationMapper.insert(Mockito.any(EnvironmentWorkerGroupRelation.class))).thenReturn(1); |
||||||
|
result = environmentService.createEnvironment(loginUser,"testName","test","test",workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testCheckParams() { |
||||||
|
Map<String, Object> result = environmentService.checkParams(environmentName,getConfig(),"test"); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID, result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testUpdateEnvironmentByCode() { |
||||||
|
User loginUser = getGeneralUser(); |
||||||
|
Map<String, Object> result = environmentService.updateEnvironmentByCode(loginUser,1L,environmentName,getConfig(),getDesc(),workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
loginUser = getAdminUser(); |
||||||
|
result = environmentService.updateEnvironmentByCode(loginUser,1L,environmentName,"",getDesc(),workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_CONFIG_IS_NULL, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
result = environmentService.updateEnvironmentByCode(loginUser,1L,"",getConfig(),getDesc(),workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_NAME_IS_NULL, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
result = environmentService.updateEnvironmentByCode(loginUser,1L,environmentName,getConfig(),getDesc(),"test"); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
Mockito.when(environmentMapper.queryByEnvironmentName(environmentName)).thenReturn(getEnvironment()); |
||||||
|
result = environmentService.updateEnvironmentByCode(loginUser,2L,environmentName,getConfig(),getDesc(),workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_NAME_EXISTS, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
Mockito.when(environmentMapper.update(Mockito.any(Environment.class),Mockito.any(Wrapper.class))).thenReturn(1); |
||||||
|
result = environmentService.updateEnvironmentByCode(loginUser,1L,"testName","test","test",workerGroups); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryAllEnvironmentList() { |
||||||
|
Mockito.when(environmentMapper.queryAllEnvironmentList()).thenReturn(Lists.newArrayList(getEnvironment())); |
||||||
|
Map<String, Object> result = environmentService.queryAllEnvironmentList(); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
List<Environment> list = (List<Environment>)(result.get(Constants.DATA_LIST)); |
||||||
|
Assert.assertEquals(1,list.size()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryEnvironmentListPaging() { |
||||||
|
IPage<Environment> page = new Page<>(1, 10); |
||||||
|
page.setRecords(getList()); |
||||||
|
page.setTotal(1L); |
||||||
|
Mockito.when(environmentMapper.queryEnvironmentListPaging(Mockito.any(Page.class), Mockito.eq(environmentName))).thenReturn(page); |
||||||
|
|
||||||
|
Result result = environmentService.queryEnvironmentListPaging(1, 10, environmentName); |
||||||
|
logger.info(result.toString()); |
||||||
|
PageInfo<Environment> pageInfo = (PageInfo<Environment>) result.getData(); |
||||||
|
Assert.assertTrue(CollectionUtils.isNotEmpty(pageInfo.getTotalList())); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryEnvironmentByName() { |
||||||
|
Mockito.when(environmentMapper.queryByEnvironmentName(environmentName)).thenReturn(null); |
||||||
|
Map<String, Object> result = environmentService.queryEnvironmentByName(environmentName); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.QUERY_ENVIRONMENT_BY_NAME_ERROR,result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
Mockito.when(environmentMapper.queryByEnvironmentName(environmentName)).thenReturn(getEnvironment()); |
||||||
|
result = environmentService.queryEnvironmentByName(environmentName); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryEnvironmentByCode() { |
||||||
|
Mockito.when(environmentMapper.queryByEnvironmentCode(1L)).thenReturn(null); |
||||||
|
Map<String, Object> result = environmentService.queryEnvironmentByCode(1L); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.QUERY_ENVIRONMENT_BY_CODE_ERROR,result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
Mockito.when(environmentMapper.queryByEnvironmentCode(1L)).thenReturn(getEnvironment()); |
||||||
|
result = environmentService.queryEnvironmentByCode(1L); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testDeleteEnvironmentByCode() { |
||||||
|
User loginUser = getGeneralUser(); |
||||||
|
Map<String, Object> result = environmentService.deleteEnvironmentByCode(loginUser,1L); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
loginUser = getAdminUser(); |
||||||
|
Mockito.when(taskDefinitionMapper.selectCount(Mockito.any(LambdaQueryWrapper.class))).thenReturn(1); |
||||||
|
result = environmentService.deleteEnvironmentByCode(loginUser,1L); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.DELETE_ENVIRONMENT_RELATED_TASK_EXISTS, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
Mockito.when(taskDefinitionMapper.selectCount(Mockito.any(LambdaQueryWrapper.class))).thenReturn(0); |
||||||
|
Mockito.when(environmentMapper.deleteByCode(1L)).thenReturn(1); |
||||||
|
result = environmentService.deleteEnvironmentByCode(loginUser,1L); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testVerifyEnvironment() { |
||||||
|
Map<String, Object> result = environmentService.verifyEnvironment(""); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_NAME_IS_NULL, result.get(Constants.STATUS)); |
||||||
|
|
||||||
|
Mockito.when(environmentMapper.queryByEnvironmentName(environmentName)).thenReturn(getEnvironment()); |
||||||
|
result = environmentService.verifyEnvironment(environmentName); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.ENVIRONMENT_NAME_EXISTS, result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
private Environment getEnvironment() { |
||||||
|
Environment environment = new Environment(); |
||||||
|
environment.setId(1); |
||||||
|
environment.setCode(1L); |
||||||
|
environment.setName(environmentName); |
||||||
|
environment.setConfig(getConfig()); |
||||||
|
environment.setDescription(getDesc()); |
||||||
|
environment.setOperator(1); |
||||||
|
return environment; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* create an environment description |
||||||
|
*/ |
||||||
|
private String getDesc() { |
||||||
|
return "create an environment to test "; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* create an environment config |
||||||
|
*/ |
||||||
|
private String getConfig() { |
||||||
|
return "export HADOOP_HOME=/opt/hadoop-2.6.5\n" |
||||||
|
+ "export HADOOP_CONF_DIR=/etc/hadoop/conf\n" |
||||||
|
+ "export SPARK_HOME1=/opt/soft/spark1\n" |
||||||
|
+ "export SPARK_HOME2=/opt/soft/spark2\n" |
||||||
|
+ "export PYTHON_HOME=/opt/soft/python\n" |
||||||
|
+ "export JAVA_HOME=/opt/java/jdk1.8.0_181-amd64\n" |
||||||
|
+ "export HIVE_HOME=/opt/soft/hive\n" |
||||||
|
+ "export FLINK_HOME=/opt/soft/flink\n" |
||||||
|
+ "export DATAX_HOME=/opt/soft/datax\n" |
||||||
|
+ "export YARN_CONF_DIR=\"/etc/hadoop/conf\"\n" |
||||||
|
+ "\n" |
||||||
|
+ "export PATH=$HADOOP_HOME/bin:$SPARK_HOME1/bin:$SPARK_HOME2/bin:$PYTHON_HOME/bin:$JAVA_HOME/bin:$HIVE_HOME/bin:$FLINK_HOME/bin:$DATAX_HOME/bin:$PATH\n" |
||||||
|
+ "\n" |
||||||
|
+ "export HADOOP_CLASSPATH=`hadoop classpath`\n" |
||||||
|
+ "\n" |
||||||
|
+ "#echo \"HADOOP_CLASSPATH=\"$HADOOP_CLASSPATH"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* create general user |
||||||
|
*/ |
||||||
|
private User getGeneralUser() { |
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
loginUser.setUserName(testUserName); |
||||||
|
loginUser.setId(1); |
||||||
|
return loginUser; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* create admin user |
||||||
|
*/ |
||||||
|
private User getAdminUser() { |
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setUserType(UserType.ADMIN_USER); |
||||||
|
loginUser.setUserName(testUserName); |
||||||
|
loginUser.setId(1); |
||||||
|
return loginUser; |
||||||
|
} |
||||||
|
|
||||||
|
private List<Environment> getList() { |
||||||
|
List<Environment> list = new ArrayList<>(); |
||||||
|
list.add(getEnvironment()); |
||||||
|
return list; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,69 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.impl.EnvironmentWorkerGroupRelationServiceImpl; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.assertj.core.util.Lists; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.InjectMocks; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment service test |
||||||
|
*/ |
||||||
|
@RunWith(MockitoJUnitRunner.class) |
||||||
|
public class EnvironmentWorkerGroupRelationServiceTest { |
||||||
|
|
||||||
|
public static final Logger logger = LoggerFactory.getLogger(EnvironmentWorkerGroupRelationServiceTest.class); |
||||||
|
|
||||||
|
@InjectMocks |
||||||
|
private EnvironmentWorkerGroupRelationServiceImpl relationService; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private EnvironmentWorkerGroupRelationMapper relationMapper; |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryEnvironmentWorkerGroupRelation() { |
||||||
|
Mockito.when(relationMapper.queryByEnvironmentCode(1L)).thenReturn(Lists.newArrayList(new EnvironmentWorkerGroupRelation())); |
||||||
|
Map<String, Object> result = relationService.queryEnvironmentWorkerGroupRelation(1L); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryAllEnvironmentWorkerGroupRelationList() { |
||||||
|
Mockito.when(relationMapper.selectList(Mockito.any())).thenReturn(Lists.newArrayList(new EnvironmentWorkerGroupRelation())); |
||||||
|
Map<String, Object> result = relationService.queryAllEnvironmentWorkerGroupRelationList(); |
||||||
|
logger.info(result.toString()); |
||||||
|
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,142 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.entity; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
|
|
||||||
|
/** |
||||||
|
* Environment |
||||||
|
*/ |
||||||
|
@TableName("t_ds_environment") |
||||||
|
public class Environment { |
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private int id; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment code |
||||||
|
*/ |
||||||
|
private Long code; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment name |
||||||
|
*/ |
||||||
|
private String name; |
||||||
|
|
||||||
|
/** |
||||||
|
* config content |
||||||
|
*/ |
||||||
|
private String config; |
||||||
|
|
||||||
|
private String description; |
||||||
|
|
||||||
|
/** |
||||||
|
* operator user id |
||||||
|
*/ |
||||||
|
private Integer operator; |
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||||
|
private Date updateTime; |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public Long getCode() { |
||||||
|
return this.code; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCode(Long code) { |
||||||
|
this.code = code; |
||||||
|
} |
||||||
|
|
||||||
|
public String getConfig() { |
||||||
|
return this.config; |
||||||
|
} |
||||||
|
|
||||||
|
public void setConfig(String config) { |
||||||
|
this.config = config; |
||||||
|
} |
||||||
|
|
||||||
|
public String getDescription() { |
||||||
|
return this.description; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDescription(String description) { |
||||||
|
this.description = description; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getOperator() { |
||||||
|
return this.operator; |
||||||
|
} |
||||||
|
|
||||||
|
public void setOperator(Integer operator) { |
||||||
|
this.operator = operator; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getCreateTime() { |
||||||
|
return createTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) { |
||||||
|
this.createTime = createTime; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getUpdateTime() { |
||||||
|
return updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUpdateTime(Date updateTime) { |
||||||
|
this.updateTime = updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "Environment{" |
||||||
|
+ "id= " + id |
||||||
|
+ ", code= " + code |
||||||
|
+ ", name= " + name |
||||||
|
+ ", config= " + config |
||||||
|
+ ", description= " + description |
||||||
|
+ ", operator= " + operator |
||||||
|
+ ", createTime= " + createTime |
||||||
|
+ ", updateTime= " + updateTime |
||||||
|
+ "}"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,117 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.entity; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
|
|
||||||
|
/** |
||||||
|
* EnvironmentWorkerGroupRelation |
||||||
|
*/ |
||||||
|
@TableName("t_ds_environment_worker_group_relation") |
||||||
|
public class EnvironmentWorkerGroupRelation { |
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private int id; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment code |
||||||
|
*/ |
||||||
|
private Long environmentCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group id |
||||||
|
*/ |
||||||
|
private String workerGroup; |
||||||
|
|
||||||
|
/** |
||||||
|
* operator user id |
||||||
|
*/ |
||||||
|
private Integer operator; |
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||||
|
private Date updateTime; |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getWorkerGroup() { |
||||||
|
return workerGroup; |
||||||
|
} |
||||||
|
|
||||||
|
public void setWorkerGroup(String workerGroup) { |
||||||
|
this.workerGroup = workerGroup; |
||||||
|
} |
||||||
|
|
||||||
|
public Long getEnvironmentCode() { |
||||||
|
return this.environmentCode; |
||||||
|
} |
||||||
|
|
||||||
|
public void setEnvironmentCode(Long environmentCode) { |
||||||
|
this.environmentCode = environmentCode; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getOperator() { |
||||||
|
return this.operator; |
||||||
|
} |
||||||
|
|
||||||
|
public void setOperator(Integer operator) { |
||||||
|
this.operator = operator; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getCreateTime() { |
||||||
|
return createTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) { |
||||||
|
this.createTime = createTime; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getUpdateTime() { |
||||||
|
return updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUpdateTime(Date updateTime) { |
||||||
|
this.updateTime = updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "EnvironmentWorkerGroupRelation{" |
||||||
|
+ "id= " + id |
||||||
|
+ ", environmentCode= " + environmentCode |
||||||
|
+ ", workerGroup= " + workerGroup |
||||||
|
+ ", operator= " + operator |
||||||
|
+ ", createTime= " + createTime |
||||||
|
+ ", updateTime= " + updateTime |
||||||
|
+ "}"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,71 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.mapper; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.dao.entity.Environment; |
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment mapper interface
|
||||||
|
*/ |
||||||
|
public interface EnvironmentMapper extends BaseMapper<Environment> { |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment by name |
||||||
|
* |
||||||
|
* @param name name |
||||||
|
* @return environment |
||||||
|
*/ |
||||||
|
Environment queryByEnvironmentName(@Param("environmentName") String name); |
||||||
|
|
||||||
|
/** |
||||||
|
* query environment by code |
||||||
|
* |
||||||
|
* @param environmentCode environmentCode |
||||||
|
* @return environment |
||||||
|
*/ |
||||||
|
Environment queryByEnvironmentCode(@Param("environmentCode") Long environmentCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* query all environment list |
||||||
|
* @return environment list |
||||||
|
*/ |
||||||
|
List<Environment> queryAllEnvironmentList(); |
||||||
|
|
||||||
|
/** |
||||||
|
* environment page |
||||||
|
* @param page page |
||||||
|
* @param searchName searchName |
||||||
|
* @return environment IPage |
||||||
|
*/ |
||||||
|
IPage<Environment> queryEnvironmentListPaging(IPage<Environment> page, @Param("searchName") String searchName); |
||||||
|
|
||||||
|
/** |
||||||
|
* delete environment by code |
||||||
|
* |
||||||
|
* @param code code |
||||||
|
* @return int |
||||||
|
*/ |
||||||
|
int deleteByCode(@Param("code") Long code); |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.mapper; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; |
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* environment worker group relation mapper interface
|
||||||
|
*/ |
||||||
|
public interface EnvironmentWorkerGroupRelationMapper extends BaseMapper<EnvironmentWorkerGroupRelation> { |
||||||
|
|
||||||
|
/** |
||||||
|
* environment worker group relation by environmentCode |
||||||
|
* |
||||||
|
* @param environmentCode environmentCode |
||||||
|
* @return EnvironmentWorkerGroupRelation list |
||||||
|
*/ |
||||||
|
List<EnvironmentWorkerGroupRelation> queryByEnvironmentCode(@Param("environmentCode") Long environmentCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* environment worker group relation by workerGroupName |
||||||
|
* |
||||||
|
* @param workerGroupName workerGroupName |
||||||
|
* @return EnvironmentWorkerGroupRelation list |
||||||
|
*/ |
||||||
|
List<EnvironmentWorkerGroupRelation> queryByWorkerGroupName(@Param("workerGroupName") String workerGroupName); |
||||||
|
|
||||||
|
/** |
||||||
|
* delete environment worker group relation by processCode |
||||||
|
* |
||||||
|
* @param environmentCode environmentCode |
||||||
|
* @param workerGroupName workerGroupName |
||||||
|
* @return int |
||||||
|
*/ |
||||||
|
int deleteByCode(@Param("environmentCode") Long environmentCode, @Param("workerGroupName") String workerGroupName); |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||||
|
<!-- |
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
~ contributor license agreements. See the NOTICE file distributed with |
||||||
|
~ this work for additional information regarding copyright ownership. |
||||||
|
~ The ASF licenses this file to You 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. |
||||||
|
--> |
||||||
|
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||||
|
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper"> |
||||||
|
<sql id="baseSql"> |
||||||
|
id, code, name, config, description, operator, create_time, update_time |
||||||
|
</sql> |
||||||
|
<select id="queryByEnvironmentName" resultType="org.apache.dolphinscheduler.dao.entity.Environment"> |
||||||
|
select |
||||||
|
<include refid="baseSql"/> |
||||||
|
from t_ds_environment |
||||||
|
WHERE name = #{environmentName} |
||||||
|
</select> |
||||||
|
<select id="queryAllEnvironmentList" resultType="org.apache.dolphinscheduler.dao.entity.Environment"> |
||||||
|
select |
||||||
|
<include refid="baseSql"/> |
||||||
|
from t_ds_environment |
||||||
|
order by create_time desc |
||||||
|
</select> |
||||||
|
<select id="queryEnvironmentListPaging" resultType="org.apache.dolphinscheduler.dao.entity.Environment"> |
||||||
|
select |
||||||
|
<include refid="baseSql"/> |
||||||
|
from t_ds_environment |
||||||
|
where 1=1 |
||||||
|
<if test="searchName!=null and searchName != ''"> |
||||||
|
and name like concat('%', #{searchName}, '%') |
||||||
|
</if> |
||||||
|
order by create_time desc |
||||||
|
</select> |
||||||
|
<select id="queryByEnvironmentCode" resultType="org.apache.dolphinscheduler.dao.entity.Environment"> |
||||||
|
select |
||||||
|
<include refid="baseSql"/> |
||||||
|
from t_ds_environment |
||||||
|
where code = #{environmentCode} |
||||||
|
</select> |
||||||
|
<delete id="deleteByCode"> |
||||||
|
delete from t_ds_environment where code = #{code} |
||||||
|
</delete> |
||||||
|
</mapper> |
@ -0,0 +1,40 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||||
|
<!-- |
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
~ contributor license agreements. See the NOTICE file distributed with |
||||||
|
~ this work for additional information regarding copyright ownership. |
||||||
|
~ The ASF licenses this file to You 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. |
||||||
|
--> |
||||||
|
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||||
|
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper"> |
||||||
|
<sql id="baseSql"> |
||||||
|
id, environment_code, worker_group, operator, create_time, update_time |
||||||
|
</sql> |
||||||
|
<select id="queryByEnvironmentCode" resultType="org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation"> |
||||||
|
select |
||||||
|
<include refid="baseSql"/> |
||||||
|
from t_ds_environment_worker_group_relation |
||||||
|
WHERE environment_code = #{environmentCode} |
||||||
|
</select> |
||||||
|
<select id="queryByWorkerGroupName" resultType="org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation"> |
||||||
|
select |
||||||
|
<include refid="baseSql"/> |
||||||
|
from t_ds_environment_worker_group_relation |
||||||
|
WHERE worker_group = #{workerGroupName} |
||||||
|
</select> |
||||||
|
<delete id="deleteByCode"> |
||||||
|
delete from t_ds_environment_worker_group_relation |
||||||
|
WHERE environment_code = #{environmentCode} and worker_group = #{workerGroupName} |
||||||
|
</delete> |
||||||
|
</mapper> |
@ -0,0 +1,199 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.mapper; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.dao.entity.Environment; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.junit.After; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||||
|
import org.springframework.test.annotation.Rollback; |
||||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
|
||||||
|
@RunWith(SpringRunner.class) |
||||||
|
@SpringBootTest |
||||||
|
@Transactional |
||||||
|
@Rollback(false) |
||||||
|
public class EnvironmentMapperTest { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
EnvironmentMapper environmentMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* insert |
||||||
|
* |
||||||
|
* @return Environment |
||||||
|
*/ |
||||||
|
private Environment insertOne() { |
||||||
|
//insertOne
|
||||||
|
Environment environment = new Environment(); |
||||||
|
environment.setName("testEnv"); |
||||||
|
environment.setCode(1L); |
||||||
|
environment.setOperator(1); |
||||||
|
environment.setConfig(getConfig()); |
||||||
|
environment.setDescription(getDesc()); |
||||||
|
environment.setCreateTime(new Date()); |
||||||
|
environment.setUpdateTime(new Date()); |
||||||
|
environmentMapper.insert(environment); |
||||||
|
return environment; |
||||||
|
} |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() { |
||||||
|
clearTestData(); |
||||||
|
} |
||||||
|
|
||||||
|
@After |
||||||
|
public void after() { |
||||||
|
clearTestData(); |
||||||
|
} |
||||||
|
|
||||||
|
public void clearTestData() { |
||||||
|
environmentMapper.queryAllEnvironmentList().stream().forEach(environment -> { |
||||||
|
environmentMapper.deleteByCode(environment.getCode()); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test update |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testUpdate() { |
||||||
|
//insertOne
|
||||||
|
Environment environment = insertOne(); |
||||||
|
environment.setDescription("new description info"); |
||||||
|
//update
|
||||||
|
int update = environmentMapper.updateById(environment); |
||||||
|
Assert.assertEquals(update, 1); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test delete |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testDelete() { |
||||||
|
Environment environment = insertOne(); |
||||||
|
int delete = environmentMapper.deleteById(environment.getId()); |
||||||
|
Assert.assertEquals(delete, 1); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test query |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testQuery() { |
||||||
|
insertOne(); |
||||||
|
//query
|
||||||
|
List<Environment> environments = environmentMapper.selectList(null); |
||||||
|
Assert.assertEquals(environments.size(), 1); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test query environment by name |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testQueryByEnvironmentName() { |
||||||
|
Environment entity = insertOne(); |
||||||
|
Environment environment = environmentMapper.queryByEnvironmentName(entity.getName()); |
||||||
|
Assert.assertEquals(entity.toString(),environment.toString()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test query environment by code |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testQueryByEnvironmentCode() { |
||||||
|
Environment entity = insertOne(); |
||||||
|
Environment environment = environmentMapper.queryByEnvironmentCode(entity.getCode()); |
||||||
|
Assert.assertEquals(entity.toString(),environment.toString()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test query all environments |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testQueryAllEnvironmentList() { |
||||||
|
Environment entity = insertOne(); |
||||||
|
List<Environment> environments = environmentMapper.queryAllEnvironmentList(); |
||||||
|
Assert.assertEquals(environments.size(), 1); |
||||||
|
Assert.assertEquals(entity.toString(),environments.get(0).toString()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test query environment list paging |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testQueryEnvironmentListPaging() { |
||||||
|
Environment entity = insertOne(); |
||||||
|
Page<Environment> page = new Page<>(1, 10); |
||||||
|
IPage<Environment> environmentIPage = environmentMapper.queryEnvironmentListPaging(page,""); |
||||||
|
List<Environment> environmentList = environmentIPage.getRecords(); |
||||||
|
Assert.assertEquals(environmentList.size(), 1); |
||||||
|
|
||||||
|
environmentIPage = environmentMapper.queryEnvironmentListPaging(page,"abc"); |
||||||
|
environmentList = environmentIPage.getRecords(); |
||||||
|
Assert.assertEquals(environmentList.size(), 0); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test query all environments |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testDeleteByCode() { |
||||||
|
Environment entity = insertOne(); |
||||||
|
int delete = environmentMapper.deleteByCode(entity.getCode()); |
||||||
|
Assert.assertEquals(delete, 1); |
||||||
|
} |
||||||
|
|
||||||
|
private String getDesc() { |
||||||
|
return "create an environment to test "; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* create an environment config |
||||||
|
*/ |
||||||
|
private String getConfig() { |
||||||
|
return "export HADOOP_HOME=/opt/hadoop-2.6.5\n" |
||||||
|
+ "export HADOOP_CONF_DIR=/etc/hadoop/conf\n" |
||||||
|
+ "export SPARK_HOME1=/opt/soft/spark1\n" |
||||||
|
+ "export SPARK_HOME2=/opt/soft/spark2\n" |
||||||
|
+ "export PYTHON_HOME=/opt/soft/python\n" |
||||||
|
+ "export JAVA_HOME=/opt/java/jdk1.8.0_181-amd64\n" |
||||||
|
+ "export HIVE_HOME=/opt/soft/hive\n" |
||||||
|
+ "export FLINK_HOME=/opt/soft/flink\n" |
||||||
|
+ "export DATAX_HOME=/opt/soft/datax\n" |
||||||
|
+ "export YARN_CONF_DIR=\"/etc/hadoop/conf\"\n" |
||||||
|
+ "\n" |
||||||
|
+ "export PATH=$HADOOP_HOME/bin:$SPARK_HOME1/bin:$SPARK_HOME2/bin:$PYTHON_HOME/bin:$JAVA_HOME/bin:$HIVE_HOME/bin:$FLINK_HOME/bin:$DATAX_HOME/bin:$PATH\n" |
||||||
|
+ "\n" |
||||||
|
+ "export HADOOP_CLASSPATH=`hadoop classpath`\n" |
||||||
|
+ "\n" |
||||||
|
+ "#echo \"HADOOP_CLASSPATH=\"$HADOOP_CLASSPATH"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,109 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.mapper; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.junit.After; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||||
|
import org.springframework.test.annotation.Rollback; |
||||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
@RunWith(SpringRunner.class) |
||||||
|
@SpringBootTest |
||||||
|
@Transactional |
||||||
|
@Rollback(true) |
||||||
|
public class EnvironmentWorkerGroupRelationMapperTest { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
EnvironmentWorkerGroupRelationMapper environmentWorkerGroupRelationMapper; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() { |
||||||
|
clearTestData(); |
||||||
|
} |
||||||
|
|
||||||
|
@After |
||||||
|
public void after() { |
||||||
|
clearTestData(); |
||||||
|
} |
||||||
|
|
||||||
|
public void clearTestData() { |
||||||
|
environmentWorkerGroupRelationMapper.selectList(null).stream().forEach(environment -> { |
||||||
|
environmentWorkerGroupRelationMapper.deleteById(environment.getId()); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* insert |
||||||
|
* |
||||||
|
* @return ProcessDefinition |
||||||
|
*/ |
||||||
|
private EnvironmentWorkerGroupRelation insertOne() { |
||||||
|
//insertOne
|
||||||
|
EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation(); |
||||||
|
relation.setEnvironmentCode(1L); |
||||||
|
relation.setWorkerGroup("default"); |
||||||
|
relation.setOperator(1); |
||||||
|
relation.setUpdateTime(new Date()); |
||||||
|
relation.setCreateTime(new Date()); |
||||||
|
environmentWorkerGroupRelationMapper.insert(relation); |
||||||
|
return relation; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* test query |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testQuery() { |
||||||
|
insertOne(); |
||||||
|
//query
|
||||||
|
List<EnvironmentWorkerGroupRelation> relations = environmentWorkerGroupRelationMapper.selectList(null); |
||||||
|
Assert.assertEquals(relations.size(), 1); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryByEnvironmentCode() { |
||||||
|
EnvironmentWorkerGroupRelation relation = insertOne(); |
||||||
|
List<EnvironmentWorkerGroupRelation> environmentWorkerGroupRelations = environmentWorkerGroupRelationMapper.queryByEnvironmentCode(1L); |
||||||
|
Assert.assertNotEquals(environmentWorkerGroupRelations.size(), 0); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryByWorkerGroupName() { |
||||||
|
EnvironmentWorkerGroupRelation relation = insertOne(); |
||||||
|
List<EnvironmentWorkerGroupRelation> environmentWorkerGroupRelations = environmentWorkerGroupRelationMapper.queryByWorkerGroupName("default"); |
||||||
|
Assert.assertNotEquals(environmentWorkerGroupRelations.size(), 0); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testDeleteByCode() { |
||||||
|
EnvironmentWorkerGroupRelation relation = insertOne(); |
||||||
|
int i = environmentWorkerGroupRelationMapper.deleteByCode(1L, "default"); |
||||||
|
Assert.assertNotEquals(i, 0); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,120 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
<template> |
||||||
|
<el-select |
||||||
|
:disabled="isDetails" |
||||||
|
clearable |
||||||
|
@change="_onChange" |
||||||
|
v-model="selectedValue" |
||||||
|
size="small" |
||||||
|
style="width: 180px"> |
||||||
|
<el-option |
||||||
|
v-for="item in environmentOptions" |
||||||
|
:key="item.code" |
||||||
|
:value="item.code" |
||||||
|
:label="item.name"> |
||||||
|
</el-option> |
||||||
|
</el-select> |
||||||
|
</template> |
||||||
|
<script> |
||||||
|
import disabledState from '@/module/mixin/disabledState' |
||||||
|
export default { |
||||||
|
name: 'form-related-environment', |
||||||
|
data () { |
||||||
|
return { |
||||||
|
selectedValue: '', |
||||||
|
selectedWorkerGroup: this.workerGroup, |
||||||
|
environmentOptions: [], |
||||||
|
environmentList: [] |
||||||
|
} |
||||||
|
}, |
||||||
|
mixins: [disabledState], |
||||||
|
props: { |
||||||
|
value: { |
||||||
|
type: String |
||||||
|
}, |
||||||
|
workerGroup: { |
||||||
|
type: String |
||||||
|
} |
||||||
|
}, |
||||||
|
model: { |
||||||
|
prop: 'value', |
||||||
|
event: 'environmentCodeEvent' |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
_onChange (o) { |
||||||
|
this.$emit('environmentCodeEvent', o) |
||||||
|
}, |
||||||
|
_getEnvironmentAll () { |
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
this.store.dispatch('security/getEnvironmentAll').then(res => { |
||||||
|
resolve(res) |
||||||
|
}).catch(e => { |
||||||
|
reject(e) |
||||||
|
}) |
||||||
|
}) |
||||||
|
}, |
||||||
|
_initEnvironmentOptions (workerGroup) { |
||||||
|
this.environmentOptions = [] |
||||||
|
if (this.environmentList && workerGroup) { |
||||||
|
this.environmentList.forEach(item => { |
||||||
|
if (item.workerGroups && item.workerGroups.length > 0) { |
||||||
|
if (item.workerGroups.indexOf(workerGroup) >= 0) { |
||||||
|
this.environmentOptions.push({ code: item.code, name: item.name }) |
||||||
|
if (item.code === this.value) { |
||||||
|
this.selectedValue = this.value |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
if (this.environmentOptions.length > 0) { |
||||||
|
/// default to select this environment when only have one environment |
||||||
|
if (this.environmentOptions.length === 1 && this.selectedValue === '') { |
||||||
|
this.selectedValue = this.environmentOptions[0].code |
||||||
|
this.$emit('environmentCodeEvent', this.selectedValue) |
||||||
|
} |
||||||
|
} else { |
||||||
|
this.selectedValue = '' |
||||||
|
this.$emit('environmentCodeEvent', this.selectedValue) |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
watch: { |
||||||
|
value: function (val) { |
||||||
|
}, |
||||||
|
workerGroup: function (val) { |
||||||
|
this.selectedWorkerGroup = val |
||||||
|
this._initEnvironmentOptions(this.selectedWorkerGroup) |
||||||
|
} |
||||||
|
}, |
||||||
|
created () { |
||||||
|
let stateEnvironmentList = this.store.state.security.environmentListAll || [] |
||||||
|
|
||||||
|
if (stateEnvironmentList.length && stateEnvironmentList.length > 0) { |
||||||
|
this.environmentList = stateEnvironmentList |
||||||
|
this._initEnvironmentOptions(this.workerGroup) |
||||||
|
} else { |
||||||
|
this._getEnvironmentAll().then(res => { |
||||||
|
this.environmentList = res |
||||||
|
this._initEnvironmentOptions(this.workerGroup) |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
@ -0,0 +1,226 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
<template> |
||||||
|
<m-popover ref="popover" :ok-text="item && item.name ? $t('Edit') : $t('Submit')" @ok="_ok" @close="close"> |
||||||
|
<template slot="content"> |
||||||
|
<div class="create-environment-model"> |
||||||
|
<m-list-box-f> |
||||||
|
<template slot="name"><strong>*</strong>{{$t('Environment Name')}}</template> |
||||||
|
<template slot="content"> |
||||||
|
<el-input |
||||||
|
type="input" |
||||||
|
v-model="name" |
||||||
|
maxlength="60" |
||||||
|
size="mini" |
||||||
|
:placeholder="$t('Please enter name')"> |
||||||
|
</el-input> |
||||||
|
</template> |
||||||
|
</m-list-box-f> |
||||||
|
<m-list-box-f> |
||||||
|
<template slot="name"><strong>*</strong>{{$t('Environment Config')}}</template> |
||||||
|
<template slot="content"> |
||||||
|
<el-input |
||||||
|
type="textarea" |
||||||
|
:autosize="{ minRows: 10, maxRows: 20 }" |
||||||
|
v-model="config" |
||||||
|
:placeholder="configExample"> |
||||||
|
</el-input> |
||||||
|
</template> |
||||||
|
</m-list-box-f> |
||||||
|
<m-list-box-f> |
||||||
|
<template slot="name"><strong>*</strong>{{$t('Environment Desc')}}</template> |
||||||
|
<template slot="content"> |
||||||
|
<el-input |
||||||
|
type="input" |
||||||
|
v-model="description" |
||||||
|
maxlength="60" |
||||||
|
size="mini" |
||||||
|
:placeholder="$t('Please enter environment desc')"> |
||||||
|
</el-input> |
||||||
|
</template> |
||||||
|
</m-list-box-f> |
||||||
|
<m-list-box-f> |
||||||
|
<template slot="name">{{$t('Environment Worker Group')}}</template> |
||||||
|
<template slot="content"> |
||||||
|
<el-select |
||||||
|
v-model="workerGroups" |
||||||
|
size="mini" |
||||||
|
multiple |
||||||
|
collapse-tags |
||||||
|
style="display: block;" |
||||||
|
:placeholder="$t('Please select worker groups')"> |
||||||
|
<el-option |
||||||
|
v-for="item in workerGroupOptions" |
||||||
|
:key="item.id" |
||||||
|
:label="item.id" |
||||||
|
:value="item.name"> |
||||||
|
</el-option> |
||||||
|
</el-select> |
||||||
|
</template> |
||||||
|
</m-list-box-f> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
</m-popover> |
||||||
|
</template> |
||||||
|
<script> |
||||||
|
import _ from 'lodash' |
||||||
|
import { mapActions } from 'vuex' |
||||||
|
import i18n from '@/module/i18n' |
||||||
|
import store from '@/conf/home/store' |
||||||
|
import mPopover from '@/module/components/popup/popover' |
||||||
|
import mListBoxF from '@/module/components/listBoxF/listBoxF' |
||||||
|
|
||||||
|
export default { |
||||||
|
name: 'create-environment', |
||||||
|
data () { |
||||||
|
return { |
||||||
|
store, |
||||||
|
workerGroups: [], |
||||||
|
workerGroupOptions: [], |
||||||
|
environment: '', |
||||||
|
name: '', |
||||||
|
config: '', |
||||||
|
description: '', |
||||||
|
configExample: 'export HADOOP_HOME=/opt/hadoop-2.6.5\n' + |
||||||
|
'export HADOOP_CONF_DIR=/etc/hadoop/conf\n' + |
||||||
|
'export SPARK_HOME=/opt/soft/spark\n' + |
||||||
|
'export PYTHON_HOME=/opt/soft/python\n' + |
||||||
|
'export JAVA_HOME=/opt/java/jdk1.8.0_181-amd64\n' + |
||||||
|
'export HIVE_HOME=/opt/soft/hive\n' + |
||||||
|
'export FLINK_HOME=/opt/soft/flink\n' + |
||||||
|
'export DATAX_HOME=/opt/soft/datax\n' + |
||||||
|
'export YARN_CONF_DIR=/etc/hadoop/conf\n' + |
||||||
|
'export PATH=$HADOOP_HOME/bin:$SPARK_HOME/bin:$PYTHON_HOME/bin:$JAVA_HOME/bin:$HIVE_HOME/bin:$FLINK_HOME/bin:$DATAX_HOME/bin:$PATH\n' + |
||||||
|
'export HADOOP_CLASSPATH=`hadoop classpath`\n' |
||||||
|
} |
||||||
|
}, |
||||||
|
props: { |
||||||
|
item: Object |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
...mapActions('security', ['getWorkerGroupsAll']), |
||||||
|
_getWorkerGroupList () { |
||||||
|
this.getWorkerGroupsAll().then(res => { |
||||||
|
this.workerGroups = res |
||||||
|
console.log('get Worker Group List') |
||||||
|
console.log(this.workerGroups) |
||||||
|
}) |
||||||
|
}, |
||||||
|
_ok () { |
||||||
|
if (!this._verification()) { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
let param = { |
||||||
|
name: _.trim(this.name), |
||||||
|
config: _.trim(this.config), |
||||||
|
description: _.trim(this.description), |
||||||
|
workerGroups: JSON.stringify(this.workerGroups) |
||||||
|
} |
||||||
|
|
||||||
|
let $then = (res) => { |
||||||
|
this.$emit('onUpdate') |
||||||
|
this.$message.success(res.msg) |
||||||
|
this.$refs.popover.spinnerLoading = false |
||||||
|
} |
||||||
|
|
||||||
|
let $catch = (e) => { |
||||||
|
this.$message.error(e.msg || '') |
||||||
|
this.$refs.popover.spinnerLoading = false |
||||||
|
} |
||||||
|
|
||||||
|
if (this.item && this.item.name) { |
||||||
|
this.$refs.popover.spinnerLoading = true |
||||||
|
let updateParam = { |
||||||
|
code: this.item.code, |
||||||
|
name: _.trim(this.name), |
||||||
|
config: _.trim(this.config), |
||||||
|
description: _.trim(this.description), |
||||||
|
workerGroups: JSON.stringify(this.workerGroups) |
||||||
|
} |
||||||
|
this.store.dispatch('security/updateEnvironment', updateParam).then(res => { |
||||||
|
$then(res) |
||||||
|
}).catch(e => { |
||||||
|
$catch(e) |
||||||
|
}) |
||||||
|
} else { |
||||||
|
this._verifyName(param).then(() => { |
||||||
|
this.$refs.popover.spinnerLoading = true |
||||||
|
this.store.dispatch('security/createEnvironment', param).then(res => { |
||||||
|
$then(res) |
||||||
|
}).catch(e => { |
||||||
|
$catch(e) |
||||||
|
}) |
||||||
|
}).catch(e => { |
||||||
|
this.$message.error(e.msg || '') |
||||||
|
}) |
||||||
|
} |
||||||
|
}, |
||||||
|
_verification () { |
||||||
|
if (!this.name.replace(/\s*/g, '')) { |
||||||
|
this.$message.warning(`${i18n.$t('Please enter name')}`) |
||||||
|
return false |
||||||
|
} |
||||||
|
if (!this.config.replace(/\s*/g, '')) { |
||||||
|
this.$message.warning(`${i18n.$t('Please enter environment config')}`) |
||||||
|
return false |
||||||
|
} |
||||||
|
if (!this.description.replace(/\s*/g, '')) { |
||||||
|
this.$message.warning(`${i18n.$t('Please enter environment desc')}`) |
||||||
|
return false |
||||||
|
} |
||||||
|
return true |
||||||
|
}, |
||||||
|
_verifyName (param) { |
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
this.store.dispatch('security/verifyEnvironment', { environmentName: param.name }).then(res => { |
||||||
|
resolve() |
||||||
|
}).catch(e => { |
||||||
|
reject(e) |
||||||
|
}) |
||||||
|
}) |
||||||
|
}, |
||||||
|
close () { |
||||||
|
this.$emit('close') |
||||||
|
} |
||||||
|
}, |
||||||
|
watch: { |
||||||
|
item: { |
||||||
|
handler (val, oldVal) { |
||||||
|
this.name = val.name |
||||||
|
this.config = val.config |
||||||
|
this.description = val.description |
||||||
|
this.workerGroups = val.workerGroups |
||||||
|
this.workerGroupOptions = val.workerGroupOptions |
||||||
|
}, |
||||||
|
deep: true |
||||||
|
} |
||||||
|
}, |
||||||
|
created () { |
||||||
|
if (this.item && this.item.name) { |
||||||
|
this.name = this.item.name |
||||||
|
this.config = this.item.config |
||||||
|
this.description = this.item.description |
||||||
|
this.workerGroups = this.item.workerGroups |
||||||
|
} |
||||||
|
this.workerGroupOptions = this.item.workerGroupOptions |
||||||
|
}, |
||||||
|
mounted () { |
||||||
|
}, |
||||||
|
components: { mPopover, mListBoxF } |
||||||
|
} |
||||||
|
</script> |
@ -0,0 +1,116 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
<template> |
||||||
|
<div class="list-model"> |
||||||
|
<div class="table-box"> |
||||||
|
<el-table :data="list" size="mini" style="width: 100%"> |
||||||
|
<el-table-column type="index" :label="$t('#')" width="50"></el-table-column> |
||||||
|
<el-table-column prop="name" :label="$t('Environment Name')" width="150"></el-table-column> |
||||||
|
<el-table-column prop="config" :label="$t('Environment Config')"></el-table-column> |
||||||
|
<el-table-column prop="description" :label="$t('Environment Desc')" min-width="50"></el-table-column> |
||||||
|
<el-table-column :label="$t('Environment Worker Group')" min-width="50"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<span>{{ scope.row.workerGroups ? scope.row.workerGroups.join(",") : "" }}</span> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column :label="$t('Create Time')" min-width="50"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<span>{{scope.row.createTime | formatDate}}</span> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column :label="$t('Update Time')" min-width="50"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<span>{{scope.row.updateTime | formatDate}}</span> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column :label="$t('Operation')" width="100"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<el-tooltip :content="$t('Edit')" placement="top"> |
||||||
|
<el-button type="primary" size="mini" icon="el-icon-edit-outline" @click="_edit(scope.row)" circle></el-button> |
||||||
|
</el-tooltip> |
||||||
|
<el-tooltip :content="$t('Delete')" placement="top"> |
||||||
|
<el-button type="danger" size="mini" icon="el-icon-delete" circle></el-button> |
||||||
|
<el-popconfirm |
||||||
|
:confirmButtonText="$t('Confirm')" |
||||||
|
:cancelButtonText="$t('Cancel')" |
||||||
|
icon="el-icon-info" |
||||||
|
iconColor="red" |
||||||
|
:title="$t('Delete?')" |
||||||
|
@onConfirm="_delete(scope.row,scope.row.id)" |
||||||
|
> |
||||||
|
<el-button type="danger" size="mini" icon="el-icon-delete" circle slot="reference"></el-button> |
||||||
|
</el-popconfirm> |
||||||
|
</el-tooltip> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
</el-table> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
<script> |
||||||
|
import { mapActions } from 'vuex' |
||||||
|
|
||||||
|
export default { |
||||||
|
name: 'environment-list', |
||||||
|
data () { |
||||||
|
return { |
||||||
|
list: [] |
||||||
|
} |
||||||
|
}, |
||||||
|
props: { |
||||||
|
environmentList: Array, |
||||||
|
pageNo: Number, |
||||||
|
pageSize: Number |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
...mapActions('security', ['deleteEnvironment']), |
||||||
|
_delete (item, i) { |
||||||
|
this.deleteEnvironment({ |
||||||
|
environmentCode: item.code |
||||||
|
}).then(res => { |
||||||
|
let newList = [] |
||||||
|
this.list.forEach(item => { |
||||||
|
if (item.id !== i) { |
||||||
|
newList.push(item) |
||||||
|
} |
||||||
|
}) |
||||||
|
this.list = newList |
||||||
|
this.$message.success(res.msg) |
||||||
|
}).catch(e => { |
||||||
|
this.$message.error(e.msg || '') |
||||||
|
}) |
||||||
|
}, |
||||||
|
_edit (item) { |
||||||
|
this.$emit('on-edit', item) |
||||||
|
} |
||||||
|
}, |
||||||
|
watch: { |
||||||
|
environmentList (a) { |
||||||
|
this.list = [] |
||||||
|
setTimeout(() => { |
||||||
|
this.list = a |
||||||
|
}) |
||||||
|
} |
||||||
|
}, |
||||||
|
created () { |
||||||
|
this.list = this.environmentList |
||||||
|
}, |
||||||
|
mounted () { |
||||||
|
}, |
||||||
|
components: { } |
||||||
|
} |
||||||
|
</script> |
@ -0,0 +1,163 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
<template> |
||||||
|
<m-list-construction :title="$t('Environment manage')"> |
||||||
|
<template slot="conditions"> |
||||||
|
<m-conditions @on-conditions="_onConditions"> |
||||||
|
<template slot="button-group" v-if="isADMIN"> |
||||||
|
<el-button size="mini" @click="_create()">{{$t('Create environment')}}</el-button> |
||||||
|
<el-dialog |
||||||
|
:title="item && item.name ? $t('Edit environment') : $t('Create environment')" |
||||||
|
:v-if="createEnvironmentDialog" |
||||||
|
:visible.sync="createEnvironmentDialog" |
||||||
|
width="auto"> |
||||||
|
<m-create-environment :item="item" @onUpdate="onUpdate" @close="close"></m-create-environment> |
||||||
|
</el-dialog> |
||||||
|
</template> |
||||||
|
</m-conditions> |
||||||
|
</template> |
||||||
|
|
||||||
|
<template slot="content"> |
||||||
|
<template v-if="environmentList.length || total>0"> |
||||||
|
<m-list @on-edit="_onEdit" |
||||||
|
:environment-list="environmentList" |
||||||
|
:page-no="searchParams.pageNo" |
||||||
|
:page-size="searchParams.pageSize"> |
||||||
|
|
||||||
|
</m-list> |
||||||
|
<div class="page-box"> |
||||||
|
<el-pagination |
||||||
|
background |
||||||
|
@current-change="_page" |
||||||
|
@size-change="_pageSize" |
||||||
|
:page-size="searchParams.pageSize" |
||||||
|
:current-page.sync="searchParams.pageNo" |
||||||
|
:page-sizes="[10, 30, 50]" |
||||||
|
layout="sizes, prev, pager, next, jumper" |
||||||
|
:total="total"> |
||||||
|
</el-pagination> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
<template v-if="!environmentList.length && total<=0"> |
||||||
|
<m-no-data></m-no-data> |
||||||
|
</template> |
||||||
|
<m-spin :is-spin="isLoading" :is-left="isLeft"></m-spin> |
||||||
|
</template> |
||||||
|
</m-list-construction> |
||||||
|
</template> |
||||||
|
<script> |
||||||
|
import _ from 'lodash' |
||||||
|
import { mapActions } from 'vuex' |
||||||
|
import mList from './_source/list' |
||||||
|
import store from '@/conf/home/store' |
||||||
|
import mSpin from '@/module/components/spin/spin' |
||||||
|
import mCreateEnvironment from './_source/createEnvironment' |
||||||
|
import mNoData from '@/module/components/noData/noData' |
||||||
|
import listUrlParamHandle from '@/module/mixin/listUrlParamHandle' |
||||||
|
import mConditions from '@/module/components/conditions/conditions' |
||||||
|
import mListConstruction from '@/module/components/listConstruction/listConstruction' |
||||||
|
|
||||||
|
export default { |
||||||
|
name: 'environment-index', |
||||||
|
data () { |
||||||
|
return { |
||||||
|
total: null, |
||||||
|
isLoading: true, |
||||||
|
environmentList: [], |
||||||
|
workerGroupList: [], |
||||||
|
environmentWorkerGroupRelationList: [], |
||||||
|
searchParams: { |
||||||
|
pageSize: 10, |
||||||
|
pageNo: 1, |
||||||
|
searchVal: '' |
||||||
|
}, |
||||||
|
isLeft: true, |
||||||
|
isADMIN: store.state.user.userInfo.userType === 'ADMIN_USER', |
||||||
|
item: {}, |
||||||
|
createEnvironmentDialog: false |
||||||
|
} |
||||||
|
}, |
||||||
|
mixins: [listUrlParamHandle], |
||||||
|
props: {}, |
||||||
|
methods: { |
||||||
|
...mapActions('security', ['getEnvironmentListPaging', 'getWorkerGroupsAll']), |
||||||
|
/** |
||||||
|
* Query |
||||||
|
*/ |
||||||
|
_onConditions (o) { |
||||||
|
this.searchParams = _.assign(this.searchParams, o) |
||||||
|
this.searchParams.pageNo = 1 |
||||||
|
}, |
||||||
|
_page (val) { |
||||||
|
this.searchParams.pageNo = val |
||||||
|
}, |
||||||
|
_pageSize (val) { |
||||||
|
this.searchParams.pageSize = val |
||||||
|
}, |
||||||
|
_onEdit (item) { |
||||||
|
this.item = item |
||||||
|
this.createEnvironmentDialog = true |
||||||
|
}, |
||||||
|
_create () { |
||||||
|
this.item = { workerGroupOptions: this.workerGroupList } |
||||||
|
this.createEnvironmentDialog = true |
||||||
|
}, |
||||||
|
onUpdate () { |
||||||
|
this._debounceGET('false') |
||||||
|
this.createEnvironmentDialog = false |
||||||
|
}, |
||||||
|
close () { |
||||||
|
this.createEnvironmentDialog = false |
||||||
|
}, |
||||||
|
_getList (flag) { |
||||||
|
if (sessionStorage.getItem('isLeft') === 0) { |
||||||
|
this.isLeft = false |
||||||
|
} else { |
||||||
|
this.isLeft = true |
||||||
|
} |
||||||
|
this.isLoading = !flag |
||||||
|
Promise.all([this.getEnvironmentListPaging(this.searchParams), this.getWorkerGroupsAll()]).then((values) => { |
||||||
|
if (this.searchParams.pageNo > 1 && values[0].totalList.length === 0) { |
||||||
|
this.searchParams.pageNo = this.searchParams.pageNo - 1 |
||||||
|
} else { |
||||||
|
this.environmentList = [] |
||||||
|
this.environmentList = values[0].totalList |
||||||
|
this.total = values[0].total |
||||||
|
this.isLoading = false |
||||||
|
} |
||||||
|
this.workerGroupList = values[1] |
||||||
|
this.environmentList.forEach(item => { |
||||||
|
item.workerGroupOptions = this.workerGroupList |
||||||
|
}) |
||||||
|
}).catch(e => { |
||||||
|
this.isLoading = false |
||||||
|
}) |
||||||
|
} |
||||||
|
}, |
||||||
|
watch: { |
||||||
|
// router |
||||||
|
'$route' (a) { |
||||||
|
// url no params get instance list |
||||||
|
this.searchParams.pageNo = _.isEmpty(a.query) ? 1 : a.query.pageNo |
||||||
|
} |
||||||
|
}, |
||||||
|
beforeDestroy () { |
||||||
|
sessionStorage.setItem('isLeft', 1) |
||||||
|
}, |
||||||
|
components: { mList, mListConstruction, mConditions, mSpin, mNoData, mCreateEnvironment } |
||||||
|
} |
||||||
|
</script> |
Loading…
Reference in new issue