Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,36 @@ public void testReplaceVariables_VariableNotExists_ReplaceEmptyString() {

Assert.assertEquals(expected, actual);
}

@Test
public void testGetLocalMessage_NullLocale_ReturnTemplate() {
String template = "fake template";
String message = MessageTemplateProcessor.getLocalMessage(null, template);
Assert.assertEquals(template, message);
}

@Test
public void testGetLocalMessage_VariousLocale_Success() {
Locale locale1 = new Locale("en", "US");
String template1 = "${com.oceanbase.odc.builtin-resource.collaboration.environment.dev.name}";
String message1 = MessageTemplateProcessor.getLocalMessage(locale1, template1);
Assert.assertEquals("dev", message1);
Locale locale2 = new Locale("zh", "TW");
String template2 = "${com.oceanbase.odc.builtin-resource.collaboration.environment.dev.name}";
String message2 = MessageTemplateProcessor.getLocalMessage(locale2, template2);
Assert.assertEquals("開發", message2);
Locale locale3 = new Locale("zh", "CN");
String template3 = "${com.oceanbase.odc.builtin-resource.collaboration.environment.dev.name}";
String message3 = MessageTemplateProcessor.getLocalMessage(locale3, template3);
Assert.assertEquals("开发", message3);
}

@Test
public void testGetLocalMessage_NullTemplate_ReturnNull() {
Locale locale = new Locale("zh", "CN");
String template = null;
String message = MessageTemplateProcessor.getLocalMessage(locale, template);
Assert.assertEquals(null, message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package com.oceanbase.odc.common.i18n;

import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -31,7 +31,7 @@

public class I18nOutputSerializer extends JsonSerializer<String> {
private static final Pattern I18N_RESOURCE_PATTERN = Pattern.compile("\\$\\{([^{^}]*)\\}");
private static final Map<Locale, Map<String, String>> MESSAGES_MAP = new HashMap<>();
private static final Map<Locale, Map<String, String>> MESSAGES_MAP = new ConcurrentHashMap<>();

@Override
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
Expand All @@ -49,9 +49,8 @@ protected String convertString(String resource) {
if (!matcher.find()) {
return resource;
}

Locale currentLocale = LocaleContextHolder.getLocale();
MESSAGES_MAP.putIfAbsent(currentLocale, new HashMap<>());
MESSAGES_MAP.putIfAbsent(currentLocale, new ConcurrentHashMap<>());
int cursor = 0;
while (matcher.find(cursor)) {
String key = matcher.group();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public enum Symbols implements Translatable {
/**
* ]
*/
RIGHT_BRACKET;
RIGHT_BRACKET,
/**
* ,
*/
COMMA;

@Override
public String code() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ com.oceanbase.odc.ResourceType.ODC_NOTIFICATION_CHANNEL=Notification Channel
com.oceanbase.odc.ResourceType.ODC_NOTIFICATION_POLICY=Notification Policy
com.oceanbase.odc.ResourceType.ODC_NOTIFICATION_MESSAGE=Notification Message
com.oceanbase.odc.ResourceType.ODC_STRUCTURE_COMPARISON_TASK=Structure Comparison Task
com.oceanbase.odc.ResourceType.ODC_DATABASE_CHANGE_ORDER_TEMPLATE=Database change order template
com.oceanbase.odc.ResourceType.ODC_DATABASE_CHANGE_ORDER_TEMPLATE=Database Change Order Template

#
# Batch Import
Expand Down Expand Up @@ -109,6 +109,7 @@ com.oceanbase.odc.FieldName.USER_DESCRIPTION=Comment

com.oceanbase.odc.Symbols.LEFT_BRACKET=[
com.oceanbase.odc.Symbols.RIGHT_BRACKET=]
com.oceanbase.odc.Symbols.COMMA=,


#
Expand Down Expand Up @@ -194,7 +195,7 @@ com.oceanbase.odc.AuditEventAction.EXECUTE_TASK=Execute task
com.oceanbase.odc.AuditEventAction.APPROVE=Approve
com.oceanbase.odc.AuditEventAction.REJECT=Reject
com.oceanbase.odc.AuditEventAction.CREATE_ASYNC_TASK=Create database change task
com.oceanbase.odc.AuditEventAction.CREATE_MULTIPLE_ASYNC_TASK=Create multiple database change task
com.oceanbase.odc.AuditEventAction.CREATE_MULTIPLE_ASYNC_TASK=Create batch change database task
com.oceanbase.odc.AuditEventAction.CREATE_MOCKDATA_TASK=Create mock data task
com.oceanbase.odc.AuditEventAction.CREATE_IMPORT_TASK=Create import task
com.oceanbase.odc.AuditEventAction.CREATE_EXPORT_TASK=Create export task
Expand All @@ -208,7 +209,7 @@ com.oceanbase.odc.AuditEventAction.CREATE_ONLINE_SCHEMA_CHANGE_TASK=Create onlin
com.oceanbase.odc.AuditEventAction.CREATE_APPLY_PROJECT_PERMISSION_TASK=Create apply project permission task
com.oceanbase.odc.AuditEventAction.CREATE_APPLY_DATABASE_PERMISSION_TASK=Create apply database permission task
com.oceanbase.odc.AuditEventAction.STOP_ASYNC_TASK=Stop database change task
com.oceanbase.odc.AuditEventAction.STOP_MULTIPLE_ASYNC_TASK=Stop multiple database change task
com.oceanbase.odc.AuditEventAction.STOP_MULTIPLE_ASYNC_TASK=Stop batch change database task
com.oceanbase.odc.AuditEventAction.STOP_MOCKDATA_TASK=Stop mock data task
com.oceanbase.odc.AuditEventAction.STOP_IMPORT_TASK=Stop import task
com.oceanbase.odc.AuditEventAction.STOP_EXPORT_TASK=Stop export task
Expand All @@ -221,7 +222,7 @@ com.oceanbase.odc.AuditEventAction.STOP_ONLINE_SCHEMA_CHANGE_TASK=Stop online sc
com.oceanbase.odc.AuditEventAction.STOP_APPLY_PROJECT_PERMISSION_TASK=Stop apply project permission task
com.oceanbase.odc.AuditEventAction.STOP_APPLY_DATABASE_PERMISSION_TASK=Stop apply database permission task
com.oceanbase.odc.AuditEventAction.EXECUTE_ASYNC_TASK=Execute database change task
com.oceanbase.odc.AuditEventAction.EXECUTE_MULTIPLE_ASYNC_TASK=Execute multiple database change task
com.oceanbase.odc.AuditEventAction.EXECUTE_MULTIPLE_ASYNC_TASK=Execute batch change database task
com.oceanbase.odc.AuditEventAction.EXECUTE_MOCKDATA_TASK=Execute mock data task
com.oceanbase.odc.AuditEventAction.EXECUTE_IMPORT_TASK=Execute import task
com.oceanbase.odc.AuditEventAction.EXECUTE_EXPORT_TASK=Execute export task
Expand All @@ -232,7 +233,7 @@ com.oceanbase.odc.AuditEventAction.EXECUTE_PARTITION_PLAN_TASK=Execute partition
com.oceanbase.odc.AuditEventAction.EXECUTE_ALTER_SCHEDULE_TASK=Execute alter schedule task
com.oceanbase.odc.AuditEventAction.EXECUTE_ONLINE_SCHEMA_CHANGE_TASK=Execute online schema change task
com.oceanbase.odc.AuditEventAction.APPROVE_ASYNC_TASK=Approve database change task
com.oceanbase.odc.AuditEventAction.APPROVE_MULTIPLE_ASYNC_TASK=Approve multiple database change task
com.oceanbase.odc.AuditEventAction.APPROVE_MULTIPLE_ASYNC_TASK=Approve batch change database task
com.oceanbase.odc.AuditEventAction.APPROVE_MOCKDATA_TASK=Approve mock data task
com.oceanbase.odc.AuditEventAction.APPROVE_IMPORT_TASK=Approve import task
com.oceanbase.odc.AuditEventAction.APPROVE_EXPORT_TASK=Approve export task
Expand All @@ -246,7 +247,7 @@ com.oceanbase.odc.AuditEventAction.APPROVE_ONLINE_SCHEMA_CHANGE_TASK=Approve onl
com.oceanbase.odc.AuditEventAction.APPROVE_APPLY_PROJECT_PERMISSION_TASK=Approve apply project permission task
com.oceanbase.odc.AuditEventAction.APPROVE_APPLY_DATABASE_PERMISSION_TASK=Approve apply database permission task
com.oceanbase.odc.AuditEventAction.REJECT_ASYNC_TASK=Reject database change task
com.oceanbase.odc.AuditEventAction.REJECT_MULTIPLE_ASYNC_TASK=Reject multiple database change task
com.oceanbase.odc.AuditEventAction.REJECT_MULTIPLE_ASYNC_TASK=Reject batch change database task
com.oceanbase.odc.AuditEventAction.REJECT_MOCKDATA_TASK=Reject mock data task
com.oceanbase.odc.AuditEventAction.REJECT_IMPORT_TASK=Reject import task
com.oceanbase.odc.AuditEventAction.REJECT_EXPORT_TASK=Reject export task
Expand Down Expand Up @@ -299,9 +300,9 @@ com.oceanbase.odc.AuditEventAction.BATCH_UPDATE_SENSITIVE_COLUMNS=Batch update s
com.oceanbase.odc.AuditEventAction.BATCH_DELETE_SENSITIVE_COLUMNS=Batch delete sensitive columns
com.oceanbase.odc.AuditEventAction.ENABLE_SENSITIVE_COLUMN=Enable sensitive column
com.oceanbase.odc.AuditEventAction.DISABLE_SENSITIVE_COLUMN=Disable sensitive column
com.oceanbase.odc.AuditEventAction.CREATE_DATABASE_CHANGE_CHANGING_ORDER_TEMPLATE=Create database change changing order template
com.oceanbase.odc.AuditEventAction.UPDATE_DATABASE_CHANGE_CHANGING_ORDER_TEMPLATE=Update database change changing order template
com.oceanbase.odc.AuditEventAction.DELETE_DATABASE_CHANGE_CHANGING_ORDER_TEMPLATE=Delete database change changing order template
com.oceanbase.odc.AuditEventAction.CREATE_DATABASE_CHANGE_CHANGING_ORDER_TEMPLATE=Create database change order template
com.oceanbase.odc.AuditEventAction.UPDATE_DATABASE_CHANGE_CHANGING_ORDER_TEMPLATE=Update database change order template
com.oceanbase.odc.AuditEventAction.DELETE_DATABASE_CHANGE_CHANGING_ORDER_TEMPLATE=Delete database change order template


#
Expand All @@ -317,7 +318,7 @@ com.oceanbase.odc.AuditEventType.RESOURCE_GROUP_MANAGEMENT=Resource group manage
com.oceanbase.odc.AuditEventType.MEMBER_MANAGEMENT=Member management
com.oceanbase.odc.AuditEventType.AUDIT_EVENT=Audit event
com.oceanbase.odc.AuditEventType.FLOW_CONFIG=Flow config
com.oceanbase.odc.AuditEventType.MULTIPLE_ASYNC=Multiple database Change
com.oceanbase.odc.AuditEventType.MULTIPLE_ASYNC=Batch change database
com.oceanbase.odc.AuditEventType.ASYNC=Database change
com.oceanbase.odc.AuditEventType.MOCKDATA=Mock data
com.oceanbase.odc.AuditEventType.IMPORT=Import
Expand All @@ -343,7 +344,7 @@ com.oceanbase.odc.AuditEventType.AUTOMATION_RULE_MANAGEMENT=Automation rule mana
com.oceanbase.odc.AuditEventType.NOTIFICATION_MANAGEMENT=Notification management
com.oceanbase.odc.AuditEventType.SENSITIVE_COLUMN_MANAGEMENT=Sensitive column management
com.oceanbase.odc.AuditEventType.STRUCTURE_COMPARISON=Structure comparison
com.oceanbase.odc.AuditEventType.DATABASE_CHANGE_CHANGING_ORDER_TEMPLATE_MANAGEMENT=Database change changing order template management
com.oceanbase.odc.AuditEventType.DATABASE_CHANGE_CHANGING_ORDER_TEMPLATE_MANAGEMENT=Database change order template management


#
Expand Down Expand Up @@ -804,7 +805,7 @@ com.oceanbase.odc.OBInstanceType.ORACLE_TENANT=Oracle Tenant
#
# TaskType
#
com.oceanbase.odc.TaskType.MULTIPLE_ASYNC=Multiple Database Change
com.oceanbase.odc.TaskType.MULTIPLE_ASYNC=Batch Change Database
com.oceanbase.odc.TaskType.ASYNC=Database Change
com.oceanbase.odc.TaskType.IMPORT=Import
com.oceanbase.odc.TaskType.EXPORT=Export
Expand Down Expand Up @@ -850,6 +851,11 @@ com.oceanbase.odc.notification.channel-test-message=【ODC】Channel verificatio
com.oceanbase.odc.builtin-resource.permission-apply.project.description=Requesting [{1}] permissions for project [{0}]
com.oceanbase.odc.builtin-resource.permission-apply.database.description=Requesting [{0}] permissions for databases

#
# Multiple Async
#
com.oceanbase.odc.builtin-resource.multiple-async.sub-ticket.description=[{0}]batch change database {1} batch no.{2} {3}.{4}

#
# ResourceRoleName
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ com.oceanbase.odc.FieldName.USER_DESCRIPTION=备注

com.oceanbase.odc.Symbols.LEFT_BRACKET=【
com.oceanbase.odc.Symbols.RIGHT_BRACKET=】
com.oceanbase.odc.Symbols.COMMA=,

#
# LimitMetric
Expand Down Expand Up @@ -787,6 +788,11 @@ com.oceanbase.odc.notification.channel-test-message=【ODC】消息通道验证
com.oceanbase.odc.builtin-resource.permission-apply.project.description=申请项目【{0}】的【{1}】权限
com.oceanbase.odc.builtin-resource.permission-apply.database.description=申请数据库的【{0}】权限

#
# Multiple Async
#
com.oceanbase.odc.builtin-resource.multiple-async.sub-ticket.description=【{0}】多库变更 {1} 第{2}批 {3}.{4}

#
# ResourceRoleName
#
Expand All @@ -811,5 +817,4 @@ com.oceanbase.odc.DatabasePermissionType.EXPORT=导出
com.oceanbase.odc.PartitionPlanVariableKey.INTERVAL=间隔
com.oceanbase.odc.PartitionPlanVariableKey.LAST_PARTITION_VALUE=最后一个分区规则对应位置表达式的值
com.oceanbase.odc.partitionplan.TimeDataType=时间类型
com.oceanbase.odc.partitionplan.NumberDataType=数字类型

com.oceanbase.odc.partitionplan.NumberDataType=数字类型
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ com.oceanbase.odc.FieldName.USER_DESCRIPTION=備註

com.oceanbase.odc.Symbols.LEFT_BRACKET=【
com.oceanbase.odc.Symbols.RIGHT_BRACKET=】
com.oceanbase.odc.Symbols.COMMA=,

#
# LimitMetric
Expand Down Expand Up @@ -856,6 +857,11 @@ com.oceanbase.odc.notification.channel-test-message=【ODC】消息通道驗證
com.oceanbase.odc.builtin-resource.permission-apply.project.description=申請項目【{0}】的【{1}】權限
com.oceanbase.odc.builtin-resource.permission-apply.database.description=申請數據庫的【{0}】權限

#
# Multiple Async
#
com.oceanbase.odc.builtin-resource.multiple-async.sub-ticket.description=【{0}】多庫變更 {1} 第{2}批 {3}.{4}

#
# ResourceRoleName
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
package com.oceanbase.odc.service.databasechange;

import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;

import com.oceanbase.odc.core.shared.PreConditions;
import com.oceanbase.odc.core.shared.constant.ErrorCodes;
Expand Down Expand Up @@ -86,6 +88,9 @@ public void process(CreateFlowInstanceReq req) {
req.setProjectId(parameters.getProjectId());
req.setProjectName(project.getName());
DescriptionGenerator.generateDescription(req);
// Localization of father-son ticket is consistent
Locale locale = LocaleContextHolder.getLocale();
parameters.setLocale(locale);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.flowable.engine.delegate.DelegateExecution;
Expand All @@ -26,6 +28,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.oceanbase.odc.common.i18n.I18n;
import com.oceanbase.odc.common.json.JsonUtils;
import com.oceanbase.odc.core.shared.constant.FlowStatus;
import com.oceanbase.odc.core.shared.constant.TaskErrorStrategy;
Expand All @@ -49,6 +52,7 @@
import com.oceanbase.odc.service.flow.util.FlowTaskUtil;
import com.oceanbase.odc.service.iam.model.User;
import com.oceanbase.odc.service.iam.util.SecurityContextUtils;
import com.oceanbase.odc.service.notification.helper.MessageTemplateProcessor;
import com.oceanbase.odc.service.task.TaskService;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -135,6 +139,9 @@ protected Void start(Long taskId, TaskService taskService, DelegateExecution exe
multipleDatabaseChangeParameters.getOrderedDatabaseIds().get(this.batchId);
List<Long> flowInstanceIds = new ArrayList<>();
this.taskCreator = FlowTaskUtil.getTaskCreator(execution);
Map<Long, DatabaseChangeDatabase> map = multipleDatabaseChangeParameters.getDatabases().stream()
.collect(Collectors.toMap(DatabaseChangeDatabase::getId, Function.identity()));
Locale locale = multipleDatabaseChangeParameters.getLocale();
for (Long batchDatabaseId : batchDatabaseIds) {
CreateFlowInstanceReq createFlowInstanceReq = new CreateFlowInstanceReq();
createFlowInstanceReq.setDatabaseId(batchDatabaseId);
Expand All @@ -143,6 +150,8 @@ protected Void start(Long taskId, TaskService taskService, DelegateExecution exe
createFlowInstanceReq.setParentFlowInstanceId(FlowTaskUtil.getFlowInstanceId(execution));
createFlowInstanceReq.setParameters(multipleDatabaseChangeParameters
.convertIntoDatabaseChangeParameters(multipleDatabaseChangeParameters));
createFlowInstanceReq.setDescription(
generateDescription(locale, map.get(batchDatabaseId), getFlowInstanceId(), this.batchId));
List<FlowInstanceDetailResp> individualFlowInstance = flowInstanceService.createWithoutApprovalNode(
createFlowInstanceReq);
flowInstanceIds.add(individualFlowInstance.get(0).getId());
Expand Down Expand Up @@ -325,4 +334,15 @@ public List<Class<? extends ExecutionListener>> getExecutionListenerClasses() {
return null;
}

private String generateDescription(Locale locale, DatabaseChangeDatabase database, Long flowInstanceId,
Integer batchId) {
String i18nKey = "com.oceanbase.odc.builtin-resource.multiple-async.sub-ticket.description";
String description = I18n.translate(
i18nKey,
new Object[] {database.getEnvironment().getName(),
flowInstanceId, batchId + 1,
database.getDataSource().getName(), database.getName()},
locale);
return MessageTemplateProcessor.getLocalMessage(locale, description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.oceanbase.odc.service.flow.task.model;

import java.util.List;
import java.util.Locale;

import com.oceanbase.odc.core.shared.constant.TaskErrorStrategy;
import com.oceanbase.odc.service.databasechange.model.DatabaseChangeDatabase;
Expand Down Expand Up @@ -52,6 +53,10 @@ public class MultipleDatabaseChangeParameters extends DatabaseChangeParameters {
* TimeoutMillis in multiple databases manual execution mode
*/
private Long manualTimeoutMillis = 1000 * 60 * 60 * 24 * 2L;// 2d for default
/**
* Use the same locale to localize parent and child ticket‘s description
*/
private Locale locale;

public DatabaseChangeParameters convertIntoDatabaseChangeParameters(MultipleDatabaseChangeParameters parameter) {
DatabaseChangeParameters databaseChangeParameters = new DatabaseChangeParameters();
Expand Down
Loading