caishunfeng commented on code in PR #10792:
URL: https://github.com/apache/dolphinscheduler/pull/10792#discussion_r913551447
##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java:
##########
@@ -359,4 +372,41 @@ public Map<String, Object> queryByTenantCode(String
tenantCode) {
}
return result;
}
+
+ /**
+ * Make sure tenant with given name exists, and create the tenant if not
exists
+ *
+ * ONLY for python gateway server, and should not use this in web ui
function
+ *
+ * @param tenantCode tenant code
+ * @param desc The description of tenant object
+ * @param queue The value of queue which current tenant belong
+ * @param queueName The name of queue which current tenant belong
+ * @return Tenant object
+ */
+ @Override
+ public Tenant createTenantIfNotExists(String tenantCode, String desc,
String queue, String queueName) {
+ if (checkTenantExists(tenantCode)) {
+ return tenantMapper.queryByTenantCode(tenantCode);
+ }
+
+ Optional<Map<String, Object>> tenantValidator =
tenantCodeValid(tenantCode);
+ if (tenantValidator.isPresent()) {
+ Map<String, Object> validator = tenantValidator.get();
+ throw new IllegalArgumentException((String)
validator.get(Constants.MSG));
+ }
+ Queue newQueue = queueService.createQueueIfNotExists(queue, queueName);
+
+ Tenant tenant = new Tenant();
+ Date now = new Date();
+ tenant.setTenantCode(tenantCode);
+ tenant.setQueueId(newQueue.getId());
+ tenant.setDescription(desc);
+ tenant.setCreateTime(now);
+ tenant.setUpdateTime(now);
+
+ // save
+ tenantMapper.insert(tenant);
Review Comment:
Please use the original method to insert tenant, then it can keep the
unified logic, such as add permission check, see
https://github.com/apache/dolphinscheduler/pull/10718#discussion_r913337211
##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java:
##########
@@ -77,9 +78,36 @@ public class TenantServiceImpl extends BaseServiceImpl
implements TenantService
@Autowired
private UserMapper userMapper;
+ @Autowired
+ private QueueService queueService;
+
@Autowired(required = false)
private StorageOperate storageOperate;
+ /**
+ * Valid tenantCode when we want to create or update tenant object
+ *
+ * @param tenantCode Tenant code of tenant object
+ * @return Optional of Status map
+ */
+ private Optional<Map<String, Object>> tenantCodeValid(String tenantCode) {
+ Map<String, Object> result = new HashMap<>();
+ if (StringUtils.isEmpty(tenantCode)) {
+ putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, tenantCode);
Review Comment:
Can it throw a ds exception directly? But not use a map as result everywhere.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]