Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced the error log cause by batch activate template when some devices are already activated #14661

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all 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 @@ -445,6 +445,7 @@ public TSStatus visitActivateTemplate(
public TSStatus visitBatchActivateTemplate(
final BatchActivateTemplateNode node, final ISchemaRegion schemaRegion) {
final List<TSStatus> statusList = new ArrayList<>();
final List<PartialPath> alreadyActivatedDeviceList = new ArrayList<>();
for (final Map.Entry<PartialPath, Pair<Integer, Integer>> entry :
node.getTemplateActivationMap().entrySet()) {
final Template template =
Expand All @@ -455,10 +456,20 @@ public TSStatus visitBatchActivateTemplate(
entry.getKey(), entry.getValue().right, entry.getValue().left),
template);
} catch (final MetadataException e) {
logger.error(e.getMessage(), e);
statusList.add(RpcUtils.getStatus(e.getErrorCode(), e.getMessage()));
if (e.getErrorCode() == TSStatusCode.TEMPLATE_IS_IN_USE.getStatusCode()) {
alreadyActivatedDeviceList.add(entry.getKey());
} else {
logger.error(e.getMessage(), e);
statusList.add(RpcUtils.getStatus(e.getErrorCode(), e.getMessage()));
}
}
}
if (!alreadyActivatedDeviceList.isEmpty()) {
final TemplateIsInUseException e =
new TemplateIsInUseException(alreadyActivatedDeviceList.toString());
logger.error(e.getMessage(), e);
statusList.add(RpcUtils.getStatus(e.getErrorCode(), e.getMessage()));
}
return statusList.isEmpty() ? RpcUtils.SUCCESS_STATUS : RpcUtils.getStatus(statusList);
}

Expand Down
Loading