macksonmu commented on code in PR #1866:
URL:
https://github.com/apache/incubator-streampark/pull/1866#discussion_r1001406909
##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java:
##########
@@ -79,4 +105,73 @@ public Variable findByVariableCode(Long teamId, String
variableCode) {
public List<Variable> findByTeamId(Long teamId) {
return baseMapper.selectByTeamId(teamId);
}
+
+ /**
+ * Replace placeholders with defined variable codes.
+ * @param teamId
+ * @param paramWithPlaceholders Parameters with placeholders, e.g.
"--cluster ${kafka.cluster}"
+ * @return
+ */
+ @Override
+ public String replacePlaceholder(Long teamId, String
paramWithPlaceholders) {
+ if (StringUtils.isEmpty(paramWithPlaceholders)) {
+ return paramWithPlaceholders;
+ }
+ String restore = paramWithPlaceholders;
+ Matcher matcher = placeholderPattern.matcher(paramWithPlaceholders);
+ while (matcher.find()) {
+ String placeholder = matcher.group();
+ String variableCode = getCodeFromPlaceholder(placeholder);
+ Variable variable = findByVariableCode(teamId, variableCode);
+ if (variable != null) {
+ restore = restore.replace(placeholder,
variable.getVariableValue());
+ }
+ }
+ return restore;
+ }
+
+ private boolean isDependByApplications(Variable variable) {
+ // Detect whether the variable is dependent on the args of the
application
+ List<Application> applications =
applicationService.getByTeamId(variable.getTeamId());
+ if (applications != null) {
+ Iterator<Application> appIt = applications.iterator();
+ while (appIt.hasNext()) {
+ Application application = appIt.next();
+ if (isDepend(variable.getVariableCode(),
application.getArgs())) {
+ return true;
+ }
+ }
Review Comment:
You are right, I originally wanted to use sqlIt.remove to get the list of
dependencies, but it will be reflected in the next PR
##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java:
##########
@@ -79,4 +105,73 @@ public Variable findByVariableCode(Long teamId, String
variableCode) {
public List<Variable> findByTeamId(Long teamId) {
return baseMapper.selectByTeamId(teamId);
}
+
+ /**
+ * Replace placeholders with defined variable codes.
+ * @param teamId
+ * @param paramWithPlaceholders Parameters with placeholders, e.g.
"--cluster ${kafka.cluster}"
+ * @return
+ */
+ @Override
+ public String replacePlaceholder(Long teamId, String
paramWithPlaceholders) {
+ if (StringUtils.isEmpty(paramWithPlaceholders)) {
+ return paramWithPlaceholders;
+ }
+ String restore = paramWithPlaceholders;
+ Matcher matcher = placeholderPattern.matcher(paramWithPlaceholders);
+ while (matcher.find()) {
+ String placeholder = matcher.group();
+ String variableCode = getCodeFromPlaceholder(placeholder);
+ Variable variable = findByVariableCode(teamId, variableCode);
+ if (variable != null) {
+ restore = restore.replace(placeholder,
variable.getVariableValue());
+ }
+ }
+ return restore;
+ }
+
+ private boolean isDependByApplications(Variable variable) {
+ // Detect whether the variable is dependent on the args of the
application
+ List<Application> applications =
applicationService.getByTeamId(variable.getTeamId());
+ if (applications != null) {
+ Iterator<Application> appIt = applications.iterator();
+ while (appIt.hasNext()) {
+ Application application = appIt.next();
+ if (isDepend(variable.getVariableCode(),
application.getArgs())) {
+ return true;
+ }
+ }
+ }
+
+ // Detect whether variables are dependent on all versions of flink sql
+ List<FlinkSql> sqls =
flinkSqlService.getByTeamId(variable.getTeamId());
+ if (sqls != null) {
+ Iterator<FlinkSql> sqlIt = sqls.iterator();
Review Comment:
You are right, I originally wanted to use sqlIt.remove to get the list of
dependencies, but it will be reflected in the next PR
--
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]