zhongjiajie commented on code in PR #10792:
URL: https://github.com/apache/dolphinscheduler/pull/10792#discussion_r913834932
##########
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:
But I can indeed possible to abstract the insert part like below to a new
private function:
```java
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);
```
--
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]