diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/pom.xml new file mode 100644 index 0000000000..9b7452a099 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/pom.xml @@ -0,0 +1,84 @@ + + + + + dolphinscheduler-alert-plugin + org.apache.dolphinscheduler + ${revision} + + 4.0.0 + + org.apache.dolphinscheduler + dolphinscheduler-alert-slack + dolphinscheduler-plugin + + + + + org.apache.dolphinscheduler + dolphinscheduler-spi + provided + + + + org.apache.httpcomponents + httpclient + + + + com.google.guava + guava + + + + ch.qos.logback + logback-classic + + + + org.slf4j + slf4j-api + + + + com.fasterxml.jackson.core + jackson-annotations + provided + + + + junit + junit + test + + + + org.mockito + mockito-core + jar + test + + + + + dolphinscheduler-alert-slack-${project.version} + + + \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java new file mode 100644 index 0000000000..6399d8bca9 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.slack; + +import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.spi.alert.AlertData; +import org.apache.dolphinscheduler.spi.alert.AlertInfo; +import org.apache.dolphinscheduler.spi.alert.AlertResult; + +import java.util.Map; + +/** + * SlackAlertChannel + */ +public class SlackAlertChannel implements AlertChannel { + + @Override + public AlertResult process(AlertInfo alertInfo) { + AlertData alertData = alertInfo.getAlertData(); + Map alertParams = alertInfo.getAlertParams(); + if (alertParams == null || alertParams.size() == 0) { + return new AlertResult("false", "Slack alert params is empty"); + } + SlackSender slackSender = new SlackSender(alertParams); + String response = slackSender.sendMessage(alertData.getTitle(), alertData.getContent()); + return new AlertResult("ok".equals(response) ? "true" : "false", response); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java new file mode 100644 index 0000000000..f3f135ebec --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.slack; + +import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; +import org.apache.dolphinscheduler.spi.params.InputParam; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import org.apache.dolphinscheduler.spi.params.base.Validate; + +import java.util.LinkedList; +import java.util.List; + +/** + * Slack alert factory, see {@link AlertChannelFactory} + */ +public class SlackAlertChannelFactory implements AlertChannelFactory { + + @Override + public String getName() { + return "Slack"; + } + + @Override + public List getParams() { + List paramsList = new LinkedList<>(); + + InputParam webHookParam = InputParam.newBuilder(SlackParamsConstants.SLACK_WEN_HOOK_URL_NAME, SlackParamsConstants.SLACK_WEB_HOOK_URL) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .setPlaceholder("Input WebHook Url") + .build(); + + InputParam botName = InputParam.newBuilder(SlackParamsConstants.SLACK_BOT_NAME, SlackParamsConstants.SLACK_BOT) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .setPlaceholder("Input the bot username") + .build(); + + paramsList.add(webHookParam); + paramsList.add(botName); + return paramsList; + } + + @Override + public AlertChannel create() { + return new SlackAlertChannel(); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPlugin.java new file mode 100644 index 0000000000..59c45ae4ac --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPlugin.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.slack; + +import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; + +import com.google.common.collect.ImmutableList; + +/** + * Slack alert plugin + */ +public class SlackAlertPlugin implements DolphinSchedulerPlugin { + + @Override + public Iterable getAlertChannelFactorys() { + return ImmutableList.of(new SlackAlertChannelFactory()); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java new file mode 100644 index 0000000000..fd191c5d55 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.slack; + +public class SlackParamsConstants { + + private SlackParamsConstants() { + + } + + public static final String SLACK_WEB_HOOK_URL = "WebHook"; + public static final String SLACK_WEN_HOOK_URL_NAME = "webHook"; + public static final String SLACK_BOT = "Username"; + public static final String SLACK_BOT_NAME = "username"; + public static final String TEXT = "text"; + public static final String ATTACHMENT = "attachments"; + + public static final Integer MAX_SHOW_NUMBER = 100; +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java new file mode 100644 index 0000000000..21a8286211 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.slack; + +import org.apache.dolphinscheduler.spi.utils.JSONUtils; +import org.apache.dolphinscheduler.spi.utils.StringUtils; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Preconditions; + +public class SlackSender { + + private static final Logger logger = LoggerFactory.getLogger(SlackSender.class); + + private String webHookUrl; + + private String botName; + + public SlackSender(Map slackAlertParam) { + webHookUrl = slackAlertParam.get(SlackParamsConstants.SLACK_WEN_HOOK_URL_NAME); + botName = slackAlertParam.get(SlackParamsConstants.SLACK_BOT_NAME); + Preconditions.checkArgument(!Objects.isNull(webHookUrl), "SlackWebHookURL can not be null"); + Preconditions.checkArgument(webHookUrl.startsWith("https://hooks.slack.com/services/"), "SlackWebHookURL invalidate"); + Preconditions.checkArgument(!Objects.isNull(botName), "slack bot name can not be null"); + } + + /** + * Send message to slack channel + * + * @param title title + * @param content content + * @return slack response + */ + public String sendMessage(String title, String content) { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + Map paramMap = new HashMap<>(); + paramMap.put(SlackParamsConstants.SLACK_BOT_NAME, botName); + paramMap.put(SlackParamsConstants.TEXT, title); + if (StringUtils.isNotEmpty(content)) { + Map attachmentTable = new HashMap<>(); + attachmentTable.put(SlackParamsConstants.TEXT, generateMarkDownTable(content)); + List> attachments = new ArrayList<>(); + attachments.add(attachmentTable); + paramMap.put(SlackParamsConstants.ATTACHMENT, attachments); + } + + HttpPost httpPost = new HttpPost(webHookUrl); + httpPost.setEntity(new StringEntity(JSONUtils.toJsonString(paramMap), "UTF-8")); + CloseableHttpResponse response = httpClient.execute(httpPost); + + HttpEntity entity = response.getEntity(); + return EntityUtils.toString(entity, "UTF-8"); + } catch (Exception e) { + logger.error("Send message to slack error.", e); + return "System Exception"; + } + } + + /** + * Because the slack does not support table we can transform to specific markdown table + * + * @param content sql data content + */ + private String generateMarkDownTable(String content) { + List linkedHashMaps = JSONUtils.toList(content, LinkedHashMap.class); + if (linkedHashMaps.size() > SlackParamsConstants.MAX_SHOW_NUMBER) { + linkedHashMaps = linkedHashMaps.subList(0, SlackParamsConstants.MAX_SHOW_NUMBER); + } + int maxLen = 0; + List headers = new LinkedList<>(); + LinkedHashMap tmp = linkedHashMaps.get(0); + for (Entry entry : tmp.entrySet()) { + maxLen = Math.max(maxLen, entry.getKey().length()); + headers.add(entry.getKey()); + } + List> elements = new ArrayList<>(tmp.size()); + // build header + for (LinkedHashMap linkedHashMap : linkedHashMaps) { + List element = new ArrayList<>(linkedHashMap.size()); + for (Object value : linkedHashMap.values()) { + String valueStr = value.toString(); + maxLen = Math.max(maxLen, valueStr.length()); + element.add(valueStr); + } + elements.add(element); + } + final int elementLen = maxLen; + StringBuilder stringBuilder = new StringBuilder(200); + stringBuilder.append(headers.stream() + .map(header -> generateString(header, elementLen, " ")) + .collect(Collectors.joining("|"))); + stringBuilder.append("\n"); + for (List element : elements) { + stringBuilder.append(element.stream() + .map(lement -> generateString("", elementLen, "-")) + .collect(Collectors.joining("|"))); + stringBuilder.append("\n"); + stringBuilder.append(element.stream() + .map(e -> generateString(e, elementLen, " ")) + .collect(Collectors.joining("|"))); + stringBuilder.append("\n"); + } + return String.format("```%s```", stringBuilder); + } + + private String generateString(String value, int len, String supplement) { + StringBuilder stringBuilder = new StringBuilder(len); + stringBuilder.append(value); + for (int i = 0; i < len - stringBuilder.length(); i++) { + stringBuilder.append(supplement); + } + return stringBuilder.toString(); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java new file mode 100644 index 0000000000..e294365da7 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.slack; + +import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +public class SlackAlertChannelFactoryTest { + + private SlackAlertChannelFactory slackAlertChannelFactory = new SlackAlertChannelFactory(); + + @Test + public void testTestGetName() { + Assert.assertEquals("Slack", slackAlertChannelFactory.getName()); + } + + @Test + public void testGetParams() { + List params = slackAlertChannelFactory.getParams(); + Assert.assertEquals(2, params.size()); + } + + @Test + public void testCreate() { + AlertChannel alertChannel = slackAlertChannelFactory.create(); + Assert.assertTrue(alertChannel instanceof SlackAlertChannel); + } +} \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPluginTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPluginTest.java new file mode 100644 index 0000000000..5086352a46 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPluginTest.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.slack; + +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; + +import org.junit.Assert; +import org.junit.Test; + +public class SlackAlertPluginTest { + + private SlackAlertPlugin slackAlertPlugin = new SlackAlertPlugin(); + + @Test + public void testGetAlertChannelFactorys() { + Iterable alertChannelFactorys = slackAlertPlugin.getAlertChannelFactorys(); + for (AlertChannelFactory alertChannelFactory : alertChannelFactorys) { + Assert.assertTrue(alertChannelFactory instanceof SlackAlertChannelFactory); + } + } +} \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java new file mode 100644 index 0000000000..a488026b42 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.slack; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +public class SlackSenderTest { + + @Test + public void testSendMessage() { + Map alertparam = new HashMap<>(); + alertparam.put(SlackParamsConstants.SLACK_WEN_HOOK_URL_NAME, + "https://hooks.slack.com/services/123456"); + alertparam.put(SlackParamsConstants.SLACK_BOT_NAME, "Dolphinscheduler"); + + SlackSender slackSender = new SlackSender(alertparam); + String response = slackSender.sendMessage("test title", "test content"); + Assert.assertNotEquals("ok", response); + } +} \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/pom.xml b/dolphinscheduler-alert-plugin/pom.xml index a10f7de254..dba2776759 100644 --- a/dolphinscheduler-alert-plugin/pom.xml +++ b/dolphinscheduler-alert-plugin/pom.xml @@ -36,7 +36,7 @@ dolphinscheduler-alert-script dolphinscheduler-alert-http dolphinscheduler-alert-feishu + dolphinscheduler-alert-slack - \ No newline at end of file diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java index d0fb66af4b..f0ab241e19 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -30,6 +30,7 @@ import org.apache.dolphinscheduler.common.thread.Stopper; import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.DaoFactory; +import org.apache.dolphinscheduler.dao.PluginDao; import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.remote.NettyRemotingServer; import org.apache.dolphinscheduler.remote.command.CommandType; @@ -47,7 +48,14 @@ import com.google.common.collect.ImmutableList; * alert of start */ public class AlertServer { + private static final Logger logger = LoggerFactory.getLogger(AlertServer.class); + + /** + * Plugin Dao + */ + private PluginDao pluginDao = DaoFactory.getDaoInstance(PluginDao.class); + /** * Alert Dao */ @@ -55,8 +63,6 @@ public class AlertServer { private AlertSender alertSender; - private static AlertServer instance; - private AlertPluginManager alertPluginManager; private DolphinPluginManagerConfig alertPluginManagerConfig; @@ -78,13 +84,19 @@ public class AlertServer { public static final AlertServer getInstance() { return AlertServerHolder.INSTANCE; - } private AlertServer() { } + private void checkTable() { + if (!pluginDao.checkPluginDefineTableExist()) { + logger.error("Plugin Define Table t_ds_plugin_define Not Exist . Please Create it First !"); + System.exit(1); + } + } + private void initPlugin() { alertPluginManager = new AlertPluginManager(); alertPluginManagerConfig = new DolphinPluginManagerConfig(); @@ -101,7 +113,7 @@ public class AlertServer { try { alertPluginLoader.loadPlugins(); } catch (Exception e) { - throw new RuntimeException("load Alert Plugin Failed !", e); + throw new RuntimeException("Load Alert Plugin Failed !", e); } } @@ -128,7 +140,7 @@ public class AlertServer { Thread.currentThread().interrupt(); } if (alertPluginManager == null || alertPluginManager.getAlertChannelMap().size() == 0) { - logger.warn("No Alert Plugin . Can not send alert info. "); + logger.warn("No Alert Plugin . Cannot send alert info. "); } else { List alerts = alertDao.listWaitExecutionAlert(); alertSender = new AlertSender(alerts, alertDao, alertPluginManager); @@ -142,6 +154,7 @@ public class AlertServer { */ public void start() { PropertyUtils.loadPropertyFile(ALERT_PROPERTIES_PATH); + checkTable(); initPlugin(); initRemoteServer(); logger.info("alert server ready start "); diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java index 662518b41e..1257856265 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java @@ -56,6 +56,7 @@ public class AlertServerTest { PluginDao pluginDao = PowerMockito.mock(PluginDao.class); PowerMockito.when(DaoFactory.getDaoInstance(PluginDao.class)).thenReturn(pluginDao); + PowerMockito.when(pluginDao.checkPluginDefineTableExist()).thenReturn(true); AlertChannel alertChannelMock = PowerMockito.mock(AlertChannel.class); @@ -80,15 +81,11 @@ public class AlertServerTest { AlertServer alertServer = AlertServer.getInstance(); Assert.assertNotNull(alertServer); - new Thread(() -> { - alertServer.start(); - }) - .start(); + new Thread(() -> alertServer.start()).start(); Thread.sleep(5 * Constants.ALERT_SCAN_INTERVAL); alertServer.stop(); - } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAnnotation.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAnnotation.java new file mode 100644 index 0000000000..a7bee62a7e --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAnnotation.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.aspect; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface AccessLogAnnotation { + // ignore request args + String[] ignoreRequestArgs() default {}; + + boolean ignoreRequest() default false; + + boolean ignoreResponse() default true; +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAspect.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAspect.java new file mode 100644 index 0000000000..03c343b8c0 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAspect.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.aspect; + +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +@Aspect +@Component +public class AccessLogAspect { + private static final Logger logger = LoggerFactory.getLogger(AccessLogAspect.class); + + @Pointcut("@annotation(org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation)") + public void logPointCut(){ + // Do nothing because of it's a pointcut + } + + @Around("logPointCut()") + public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { + long startTime = System.currentTimeMillis(); + + // fetch AccessLogAnnotation + MethodSignature sign = (MethodSignature) proceedingJoinPoint.getSignature(); + Method method = sign.getMethod(); + AccessLogAnnotation annotation = method.getAnnotation(AccessLogAnnotation.class); + + String tranceId = UUID.randomUUID().toString(); + + // log request + if (!annotation.ignoreRequest()) { + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes != null) { + HttpServletRequest request = attributes.getRequest(); + + // handle login info + String userName = parseLoginInfo(request); + + // handle args + String argsString = parseArgs(proceedingJoinPoint, annotation); + logger.info("REQUEST TRANCE_ID:{}, LOGIN_USER:{}, URI:{}, METHOD:{}, HANDLER:{}, ARGS:{}", + tranceId, + userName, + request.getRequestURI(), + request.getMethod(), + proceedingJoinPoint.getSignature().getDeclaringTypeName() + "." + proceedingJoinPoint.getSignature().getName(), + argsString); + + } + } + + Object ob = proceedingJoinPoint.proceed(); + + // log response + if (!annotation.ignoreResponse()) { + logger.info("RESPONSE TRANCE_ID:{}, BODY:{}, REQUEST DURATION:{} milliseconds", tranceId, ob, (System.currentTimeMillis() - startTime)); + } + + return ob; + } + + private String parseArgs(ProceedingJoinPoint proceedingJoinPoint, AccessLogAnnotation annotation) { + Object[] args = proceedingJoinPoint.getArgs(); + String argsString = Arrays.toString(args); + if (annotation.ignoreRequestArgs().length > 0) { + String[] parameterNames = ((MethodSignature) proceedingJoinPoint.getSignature()).getParameterNames(); + if (parameterNames.length > 0) { + List ignoreList = Arrays.stream(annotation.ignoreRequestArgs()).collect(Collectors.toList()); + HashMap argsMap = new HashMap<>(); + + for (int i = 0; i < parameterNames.length; i++) { + if (!ignoreList.contains(parameterNames[i])) { + argsMap.put(parameterNames[i], args[i]); + } + } + argsString = argsMap.toString(); + } + } + return argsString; + } + + private String parseLoginInfo(HttpServletRequest request) { + String userName = "NOT LOGIN"; + User loginUser = (User) (request.getAttribute(Constants.SESSION_USER)); + if (loginUser != null) { + userName = loginUser.getUserName(); + } + return userName; + } + +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java index e2360db0b1..109f950132 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java @@ -23,6 +23,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.GENERATE_TOKEN_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ACCESSTOKEN_LIST_PAGING_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ACCESS_TOKEN_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.AccessTokenService; @@ -33,8 +34,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -59,10 +58,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/access-token") public class AccessTokenController extends BaseController { - - private static final Logger logger = LoggerFactory.getLogger(AccessTokenController.class); - - @Autowired private AccessTokenService accessTokenService; @@ -79,12 +74,11 @@ public class AccessTokenController extends BaseController { @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_ACCESS_TOKEN_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createToken(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userId") int userId, @RequestParam(value = "expireTime") String expireTime, @RequestParam(value = "token") String token) { - logger.info("login user {}, create token , userId : {} , token expire time : {} , token : {}", loginUser.getUserName(), - userId, expireTime, token); Map result = accessTokenService.createToken(loginUser, userId, expireTime, token); return returnDataList(result); @@ -102,10 +96,10 @@ public class AccessTokenController extends BaseController { @PostMapping(value = "/generate") @ResponseStatus(HttpStatus.CREATED) @ApiException(GENERATE_TOKEN_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result generateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userId") int userId, @RequestParam(value = "expireTime") String expireTime) { - logger.info("login user {}, generate token , userId : {} , token expire time : {}", loginUser, userId, expireTime); Map result = accessTokenService.generateToken(loginUser, userId, expireTime); return returnDataList(result); } @@ -128,12 +122,11 @@ public class AccessTokenController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryAccessTokenList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize) { - logger.info("login user {}, list access token paging, pageNo: {}, searchVal: {}, pageSize: {}", - loginUser.getUserName(), pageNo, searchVal, pageSize); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { @@ -155,9 +148,9 @@ public class AccessTokenController extends BaseController { @PostMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_ACCESS_TOKEN_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result delAccessTokenById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id) { - logger.info("login user {}, delete access token, id: {},", loginUser.getUserName(), id); Map result = accessTokenService.delAccessTokenById(loginUser, id); return returnDataList(result); } @@ -177,13 +170,12 @@ public class AccessTokenController extends BaseController { @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_ACCESS_TOKEN_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id, @RequestParam(value = "userId") int userId, @RequestParam(value = "expireTime") String expireTime, @RequestParam(value = "token") String token) { - logger.info("login user {}, update token , userId : {} , token expire time : {} , token : {}", loginUser.getUserName(), - userId, expireTime, token); Map result = accessTokenService.updateToken(loginUser, id, userId, expireTime, token); return returnDataList(result); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java index dd76753e14..4ddc3c9d2a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java @@ -23,10 +23,10 @@ import static org.apache.dolphinscheduler.api.enums.Status.LIST_PAGING_ALERT_GRO import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_ALERTGROUP_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_GROUP_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.AlertGroupService; -import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.ParameterUtils; @@ -83,13 +83,11 @@ public class AlertGroupController extends BaseController { @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_ALERT_GROUP_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "groupName") String groupName, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "alertInstanceIds") String alertInstanceIds) { - logger.info("loginUser user {}, create alert group, groupName: {}, desc: {},alertInstanceIds:{}", - RegexUtils.escapeNRT(loginUser.getUserName()), RegexUtils.escapeNRT(groupName), - RegexUtils.escapeNRT(description), RegexUtils.escapeNRT(alertInstanceIds)); Map result = alertGroupService.createAlertgroup(loginUser, groupName, description, alertInstanceIds); return returnDataList(result); } @@ -104,9 +102,9 @@ public class AlertGroupController extends BaseController { @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_ALL_ALERTGROUP_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}, query all alertGroup", - loginUser.getUserName()); + Map result = alertGroupService.queryAlertgroup(); return returnDataList(result); } @@ -129,12 +127,11 @@ public class AlertGroupController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(LIST_PAGING_ALERT_GROUP_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { - logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}", - loginUser.getUserName(), pageNo, searchVal, pageSize); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -164,15 +161,13 @@ public class AlertGroupController extends BaseController { @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_ALERT_GROUP_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id, @RequestParam(value = "groupName") String groupName, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "alertInstanceIds") String alertInstanceIds) { - logger.info("login user {}, updateProcessInstance alert group, groupName: {}, desc: {}", - RegexUtils.escapeNRT(loginUser.getUserName()), - RegexUtils.escapeNRT(groupName), - RegexUtils.escapeNRT(description)); + Map result = alertGroupService.updateAlertgroup(loginUser, id, groupName, description, alertInstanceIds); return returnDataList(result); } @@ -191,9 +186,9 @@ public class AlertGroupController extends BaseController { @PostMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_ALERT_GROUP_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result delAlertgroupById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id) { - logger.info("login user {}, delete AlertGroup, id: {},", loginUser.getUserName(), id); Map result = alertGroupService.delAlertgroupById(loginUser, id); return returnDataList(result); } @@ -212,9 +207,9 @@ public class AlertGroupController extends BaseController { }) @GetMapping(value = "/verify-group-name") @ResponseStatus(HttpStatus.OK) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyGroupName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "groupName") String groupName) { - logger.info("login user {}, verify group name: {}", loginUser.getUserName(), groupName); boolean exist = alertGroupService.existGroupName(groupName); Result result = new Result(); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java index 21ff2506af..42c5536042 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java @@ -24,10 +24,10 @@ import static org.apache.dolphinscheduler.api.enums.Status.LIST_PAGING_ALERT_PLU import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_ALERT_PLUGIN_INSTANCE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_PLUGIN_INSTANCE_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService; -import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.dao.entity.User; @@ -84,13 +84,11 @@ public class AlertPluginInstanceController extends BaseController { @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_ALERT_PLUGIN_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "pluginDefineId") int pluginDefineId, @RequestParam(value = "instanceName") String instanceName, @RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) { - logger.info("login user {},create alert plugin instance, instanceName:{} ", - RegexUtils.escapeNRT(loginUser.getUserName()), - RegexUtils.escapeNRT(instanceName)); Map result = alertPluginInstanceService.create(loginUser, pluginDefineId, instanceName, pluginInstanceParams); return returnDataList(result); } @@ -113,11 +111,11 @@ public class AlertPluginInstanceController extends BaseController { @GetMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_ALERT_PLUGIN_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "alertPluginInstanceId") int alertPluginInstanceId, @RequestParam(value = "instanceName") String instanceName, @RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) { - logger.info("login user {},update alert plugin instance id {}", RegexUtils.escapeNRT(loginUser.getUserName()), alertPluginInstanceId); Map result = alertPluginInstanceService.update(loginUser, alertPluginInstanceId, instanceName, pluginInstanceParams); return returnDataList(result); } @@ -136,9 +134,9 @@ public class AlertPluginInstanceController extends BaseController { @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_ALERT_PLUGIN_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id) { - logger.info("login user {},delete alert plugin instance id {}", RegexUtils.escapeNRT(loginUser.getUserName()), id); Map result = alertPluginInstanceService.delete(loginUser, id); return returnDataList(result); @@ -155,9 +153,9 @@ public class AlertPluginInstanceController extends BaseController { @PostMapping(value = "/get") @ResponseStatus(HttpStatus.OK) @ApiException(GET_ALERT_PLUGIN_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result getAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id) { - logger.info("login user {},get alert plugin instance, id {}", RegexUtils.escapeNRT(loginUser.getUserName()), id); Map result = alertPluginInstanceService.get(loginUser, id); return returnDataList(result); } @@ -172,8 +170,8 @@ public class AlertPluginInstanceController extends BaseController { @PostMapping(value = "/queryAll") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_ALL_ALERT_PLUGIN_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result getAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}, query all alert plugin instance", RegexUtils.escapeNRT(loginUser.getUserName())); Map result = alertPluginInstanceService.queryAll(); return returnDataList(result); } @@ -191,9 +189,9 @@ public class AlertPluginInstanceController extends BaseController { }) @GetMapping(value = "/verify-alert-instance-name") @ResponseStatus(HttpStatus.OK) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyGroupName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "alertInstanceName") String alertInstanceName) { - logger.info("login user {},verify alert instance name: {}", RegexUtils.escapeNRT(loginUser.getUserName()), RegexUtils.escapeNRT(alertInstanceName)); boolean exist = alertPluginInstanceService.checkExistPluginInstanceName(alertInstanceName); Result result = new Result(); @@ -224,10 +222,10 @@ public class AlertPluginInstanceController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(LIST_PAGING_ALERT_PLUGIN_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { - logger.info("login user {}, list paging, pageNo: {}, pageSize: {}", RegexUtils.escapeNRT(loginUser.getUserName()), pageNo, pageSize); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java index eac0b63097..e7b0dd6211 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java @@ -23,6 +23,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_INSTANC import static org.apache.dolphinscheduler.api.enums.Status.QUEUE_COUNT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.TASK_INSTANCE_STATE_COUNT_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.DataAnalysisService; import org.apache.dolphinscheduler.api.utils.Result; @@ -31,8 +32,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -56,9 +55,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("projects/analysis") public class DataAnalysisController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(DataAnalysisController.class); - - @Autowired DataAnalysisService dataAnalysisService; @@ -80,12 +76,12 @@ public class DataAnalysisController extends BaseController { @GetMapping(value = "/task-state-count") @ResponseStatus(HttpStatus.OK) @ApiException(TASK_INSTANCE_STATE_COUNT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result countTaskState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "endDate", required = false) String endDate, @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { - logger.info("count task state, user:{}, start date: {}, end date:{}, project id {}", - loginUser.getUserName(), startDate, endDate, projectId); + Map result = dataAnalysisService.countTaskStateByProject(loginUser, projectId, startDate, endDate); return returnDataList(result); } @@ -108,12 +104,12 @@ public class DataAnalysisController extends BaseController { @GetMapping(value = "/process-state-count") @ResponseStatus(HttpStatus.OK) @ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result countProcessInstanceState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "endDate", required = false) String endDate, @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { - logger.info("count process instance state, user:{}, start date: {}, end date:{}, project id:{}", - loginUser.getUserName(), startDate, endDate, projectId); + Map result = dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectId, startDate, endDate); return returnDataList(result); } @@ -132,10 +128,10 @@ public class DataAnalysisController extends BaseController { @GetMapping(value = "/define-user-count") @ResponseStatus(HttpStatus.OK) @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result countDefinitionByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { - logger.info("count process definition , user:{}, project id:{}", - loginUser.getUserName(), projectId); + Map result = dataAnalysisService.countDefinitionByUser(loginUser, projectId); return returnDataList(result); } @@ -159,12 +155,12 @@ public class DataAnalysisController extends BaseController { @GetMapping(value = "/command-state-count") @ResponseStatus(HttpStatus.OK) @ApiException(COMMAND_STATE_COUNT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result countCommandState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "endDate", required = false) String endDate, @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { - logger.info("count command state, user:{}, start date: {}, end date:{}, project id {}", - loginUser.getUserName(), startDate, endDate, projectId); + Map result = dataAnalysisService.countCommandState(loginUser, projectId, startDate, endDate); return returnDataList(result); } @@ -183,10 +179,10 @@ public class DataAnalysisController extends BaseController { @GetMapping(value = "/queue-count") @ResponseStatus(HttpStatus.OK) @ApiException(QUEUE_COUNT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { - logger.info("count command state, user:{}, project id {}", - loginUser.getUserName(), projectId); + Map result = dataAnalysisService.countQueueState(loginUser, projectId); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java index 98951f26a7..6c35cd3ac4 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java @@ -28,10 +28,10 @@ import static org.apache.dolphinscheduler.api.enums.Status.UNAUTHORIZED_DATASOUR import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_DATASOURCE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_DATASOURCE_NAME_FAILURE; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.DataSourceService; -import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.datasource.BaseDataSourceParamDTO; @@ -44,8 +44,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -72,8 +70,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("datasources") public class DataSourceController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(DataSourceController.class); - @Autowired private DataSourceService dataSourceService; @@ -88,11 +84,10 @@ public class DataSourceController extends BaseController { @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_DATASOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "DATA_SOURCE_PARAM", required = true) @RequestBody BaseDataSourceParamDTO dataSourceParam) { - String userName = RegexUtils.escapeNRT(loginUser.getUserName()); - logger.info("login user {} create datasource : {}", userName, dataSourceParam); return dataSourceService.createDataSource(loginUser, dataSourceParam); } @@ -111,10 +106,9 @@ public class DataSourceController extends BaseController { @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_DATASOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestBody BaseDataSourceParamDTO dataSourceParam) { - String userName = RegexUtils.escapeNRT(loginUser.getUserName()); - logger.info("login user {} updateProcessInstance datasource : {}", userName, dataSourceParam); return dataSourceService.updateDataSource(dataSourceParam.getId(), loginUser, dataSourceParam); } @@ -133,10 +127,10 @@ public class DataSourceController extends BaseController { @PostMapping(value = "/update-ui") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATASOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") int id) { - logger.info("login user {}, query datasource: {}", - loginUser.getUserName(), id); + Map result = dataSourceService.queryDataSource(id); return returnDataList(result); } @@ -155,6 +149,7 @@ public class DataSourceController extends BaseController { @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATASOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryDataSourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("type") DbType type) { Map result = dataSourceService.queryDataSourceList(loginUser, type.ordinal()); @@ -179,6 +174,7 @@ public class DataSourceController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATASOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryDataSourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageNo") Integer pageNo, @@ -206,10 +202,9 @@ public class DataSourceController extends BaseController { @PostMapping(value = "/connect") @ResponseStatus(HttpStatus.OK) @ApiException(CONNECT_DATASOURCE_FAILURE) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result connectDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestBody BaseDataSourceParamDTO dataSourceParam) { - String userName = RegexUtils.escapeNRT(loginUser.getUserName()); - logger.info("login user {}, connect datasource: {}", userName, dataSourceParam); DatasourceUtil.checkDatasourceParam(dataSourceParam); ConnectionParam connectionParams = DatasourceUtil.buildConnectionParams(dataSourceParam); return dataSourceService.checkConnection(dataSourceParam.getType(), connectionParams); @@ -229,9 +224,9 @@ public class DataSourceController extends BaseController { @GetMapping(value = "/connect-by-id") @ResponseStatus(HttpStatus.OK) @ApiException(CONNECTION_TEST_FAILURE) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result connectionTest(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") int id) { - logger.info("connection test, login user:{}, id:{}", loginUser.getUserName(), id); return dataSourceService.connectionTest(id); } @@ -249,9 +244,9 @@ public class DataSourceController extends BaseController { @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_DATA_SOURCE_FAILURE) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result delete(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") int id) { - logger.info("delete datasource,login user:{}, id:{}", loginUser.getUserName(), id); return dataSourceService.delete(loginUser, id); } @@ -269,12 +264,10 @@ public class DataSourceController extends BaseController { @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_DATASOURCE_NAME_FAILURE) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyDataSourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "name") String name ) { - logger.info("login user {}, verfiy datasource name: {}", - loginUser.getUserName(), name); - return dataSourceService.verifyDataSourceName(name); } @@ -293,10 +286,10 @@ public class DataSourceController extends BaseController { @GetMapping(value = "/unauth-datasource") @ResponseStatus(HttpStatus.OK) @ApiException(UNAUTHORIZED_DATASOURCE) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result unauthDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - logger.info("unauthorized datasource, login user:{}, unauthorized userId:{}", - loginUser.getUserName(), userId); + Map result = dataSourceService.unauthDatasource(loginUser, userId); return returnDataList(result); } @@ -316,10 +309,10 @@ public class DataSourceController extends BaseController { @GetMapping(value = "/authed-datasource") @ResponseStatus(HttpStatus.OK) @ApiException(AUTHORIZED_DATA_SOURCE) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result authedDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - logger.info("authorized data source, login user:{}, authorized useId:{}", - loginUser.getUserName(), userId); + Map result = dataSourceService.authedDatasource(loginUser, userId); return returnDataList(result); } @@ -334,8 +327,8 @@ public class DataSourceController extends BaseController { @GetMapping(value = "/kerberos-startup-state") @ResponseStatus(HttpStatus.OK) @ApiException(KERBEROS_STARTUP_STATE) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result getKerberosStartupState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}", loginUser.getUserName()); // if upload resource is HDFS and kerberos startup is true , else false return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState()); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java index a84554af17..24e9242d11 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java @@ -21,6 +21,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.CHECK_PROCESS_DEFINIT import static org.apache.dolphinscheduler.api.enums.Status.EXECUTE_PROCESS_INSTANCE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.START_PROCESS_INSTANCE_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.ExecuteType; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ExecutorService; @@ -37,8 +38,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PathVariable; @@ -64,8 +63,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("projects/{projectName}/executors") public class ExecutorController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(ExecutorController.class); - @Autowired private ExecutorService execService; @@ -106,6 +103,7 @@ public class ExecutorController extends BaseController { @PostMapping(value = "start-process-instance") @ResponseStatus(HttpStatus.OK) @ApiException(START_PROCESS_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result startProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processDefinitionId") int processDefinitionId, @@ -121,12 +119,6 @@ public class ExecutorController extends BaseController { @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @RequestParam(value = "timeout", required = false) Integer timeout, @RequestParam(value = "startParams", required = false) String startParams) { - logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, " - + "failure policy: {}, node name: {}, node dep: {}, notify type: {}, " - + "notify group id: {}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}, startParams: {} ", - loginUser.getUserName(), projectName, processDefinitionId, scheduleTime, - failureStrategy, startNodeList, taskDependType, warningType, workerGroup, runMode, processInstancePriority, - workerGroup, timeout, startParams); if (timeout == null) { timeout = Constants.MAX_TASK_TIMEOUT; @@ -159,13 +151,12 @@ public class ExecutorController extends BaseController { @PostMapping(value = "/execute") @ResponseStatus(HttpStatus.OK) @ApiException(EXECUTE_PROCESS_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result execute(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processInstanceId") Integer processInstanceId, @RequestParam("executeType") ExecuteType executeType ) { - logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}", - loginUser.getUserName(), projectName, processInstanceId, executeType); Map result = execService.execute(loginUser, projectName, processInstanceId, executeType); return returnDataList(result); } @@ -184,9 +175,9 @@ public class ExecutorController extends BaseController { @PostMapping(value = "/start-check") @ResponseStatus(HttpStatus.OK) @ApiException(CHECK_PROCESS_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result startCheckProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "processDefinitionId") int processDefinitionId) { - logger.info("login user {}, check process definition {}", loginUser.getUserName(), processDefinitionId); Map result = execService.startCheckByProcessDefinedId(processDefinitionId); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java index 1c80f8f00a..5d6c044792 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java @@ -20,14 +20,13 @@ package org.apache.dolphinscheduler.api.controller; import static org.apache.dolphinscheduler.api.enums.Status.DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_INSTANCE_LOG_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.LoggerService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.dao.entity.User; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -54,9 +53,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/log") public class LoggerController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(LoggerController.class); - - @Autowired private LoggerService loggerService; @@ -78,12 +74,11 @@ public class LoggerController extends BaseController { @GetMapping(value = "/detail") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TASK_INSTANCE_LOG_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryLog(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "taskInstanceId") int taskInstanceId, @RequestParam(value = "skipLineNum") int skipNum, @RequestParam(value = "limit") int limit) { - logger.info( - "login user {}, view {} task instance log ,skipLineNum {} , limit {}", loginUser.getUserName(), taskInstanceId, skipNum, limit); return loggerService.queryLog(taskInstanceId, skipNum, limit); } @@ -102,6 +97,7 @@ public class LoggerController extends BaseController { @GetMapping(value = "/download-log") @ResponseBody @ApiException(DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public ResponseEntity downloadTaskLog(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "taskInstanceId") int taskInstanceId) { byte[] logBytes = loggerService.getLogBytes(taskInstanceId); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java index 0254a62a9f..dda9192232 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java @@ -21,6 +21,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.IP_IS_EMPTY; import static org.apache.dolphinscheduler.api.enums.Status.SIGN_OUT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.USER_LOGIN_FAILURE; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.security.Authenticator; @@ -38,8 +39,6 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestAttribute; @@ -61,9 +60,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("") public class LoginController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(LoginController.class); - - @Autowired private SessionService sessionService; @@ -87,12 +83,11 @@ public class LoginController extends BaseController { }) @PostMapping(value = "/login") @ApiException(USER_LOGIN_FAILURE) + @AccessLogAnnotation(ignoreRequestArgs = {"userPassword", "request", "response"}) public Result login(@RequestParam(value = "userName") String userName, @RequestParam(value = "userPassword") String userPassword, HttpServletRequest request, HttpServletResponse response) { - logger.info("login user name: {} ", userName); - //user name check if (StringUtils.isEmpty(userName)) { return error(Status.USER_NAME_NULL.getCode(), @@ -132,9 +127,9 @@ public class LoginController extends BaseController { @ApiOperation(value = "signOut", notes = "SIGNOUT_NOTES") @PostMapping(value = "/signOut") @ApiException(SIGN_OUT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "request"}) public Result signOut(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, HttpServletRequest request) { - logger.info("login user:{} sign out", loginUser.getUserName()); String ip = getClientIpAddress(request); sessionService.signOut(ip, loginUser); //clear session diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java index 329575b29a..92c9858fb1 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java @@ -22,6 +22,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.LIST_WORKERS_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_DATABASE_STATE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ZOOKEEPER_STATE_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.MonitorService; import org.apache.dolphinscheduler.api.utils.Result; @@ -30,8 +31,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -52,8 +51,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/monitor") public class MonitorController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(MonitorController.class); - @Autowired private MonitorService monitorService; @@ -67,9 +64,8 @@ public class MonitorController extends BaseController { @GetMapping(value = "/master/list") @ResponseStatus(HttpStatus.OK) @ApiException(LIST_MASTERS_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result listMaster(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user: {}, query all master", loginUser.getUserName()); - logger.info("list master, user:{}", loginUser.getUserName()); Map result = monitorService.queryMaster(loginUser); return returnDataList(result); } @@ -84,8 +80,8 @@ public class MonitorController extends BaseController { @GetMapping(value = "/worker/list") @ResponseStatus(HttpStatus.OK) @ApiException(LIST_WORKERS_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result listWorker(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user: {}, query all workers", loginUser.getUserName()); Map result = monitorService.queryWorker(loginUser); return returnDataList(result); } @@ -100,8 +96,8 @@ public class MonitorController extends BaseController { @GetMapping(value = "/database") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATABASE_STATE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryDatabaseState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user: {}, query database state", loginUser.getUserName()); Map result = monitorService.queryDatabaseState(loginUser); return returnDataList(result); } @@ -116,8 +112,8 @@ public class MonitorController extends BaseController { @GetMapping(value = "/zookeeper/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_ZOOKEEPER_STATE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryZookeeperState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user: {}, query zookeeper state", loginUser.getUserName()); Map result = monitorService.queryZookeeperState(loginUser); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java index 3f369e0d05..94a2dc986c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java @@ -34,6 +34,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.SWITCH_PROCESS_DEFINI import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROCESS_DEFINITION_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; @@ -112,6 +113,7 @@ public class ProcessDefinitionController extends BaseController { @PostMapping(value = "/save") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_PROCESS_DEFINITION) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "name", required = true) String name, @@ -120,9 +122,6 @@ public class ProcessDefinitionController extends BaseController { @RequestParam(value = "connects", required = true) String connects, @RequestParam(value = "description", required = false) String description) throws JsonProcessingException { - logger.info("login user {}, create process definition, project name: {}, process definition name: {}, " - + "process_definition_json: {}, desc: {} locations:{}, connects:{}", - loginUser.getUserName(), projectName, name, json, description, locations, connects); Map result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, json, description, locations, connects); return returnDataList(result); @@ -145,16 +144,11 @@ public class ProcessDefinitionController extends BaseController { @PostMapping(value = "/copy") @ResponseStatus(HttpStatus.OK) @ApiException(BATCH_COPY_PROCESS_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result copyProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processDefinitionIds", required = true) String processDefinitionIds, @RequestParam(value = "targetProjectId", required = true) int targetProjectId) { - logger.info("batch copy process definition, login user:{}, project name:{}, process definition ids:{},target project id:{}", - RegexUtils.escapeNRT(loginUser.getUserName()), - RegexUtils.escapeNRT(projectName), - RegexUtils.escapeNRT(processDefinitionIds), - RegexUtils.escapeNRT(String.valueOf(targetProjectId))); - return returnDataList( processDefinitionService.batchCopyProcessDefinition(loginUser, projectName, processDefinitionIds, targetProjectId)); } @@ -176,16 +170,11 @@ public class ProcessDefinitionController extends BaseController { @PostMapping(value = "/move") @ResponseStatus(HttpStatus.OK) @ApiException(BATCH_MOVE_PROCESS_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result moveProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processDefinitionIds", required = true) String processDefinitionIds, @RequestParam(value = "targetProjectId", required = true) int targetProjectId) { - logger.info("batch move process definition, login user:{}, project name:{}, process definition ids:{},target project id:{}", - RegexUtils.escapeNRT(loginUser.getUserName()), - RegexUtils.escapeNRT(projectName), - RegexUtils.escapeNRT(processDefinitionIds), - RegexUtils.escapeNRT(String.valueOf(targetProjectId))); - return returnDataList( processDefinitionService.batchMoveProcessDefinition(loginUser, projectName, processDefinitionIds, targetProjectId)); } @@ -205,11 +194,10 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyProcessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "name", required = true) String name) { - logger.info("verify process definition name unique, user:{}, project name:{}, process definition name:{}", - loginUser.getUserName(), projectName, name); Map result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectName, name); return returnDataList(result); } @@ -241,6 +229,7 @@ public class ProcessDefinitionController extends BaseController { @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_PROCESS_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "name", required = true) String name, @@ -251,9 +240,6 @@ public class ProcessDefinitionController extends BaseController { @RequestParam(value = "description", required = false) String description, @RequestParam(value = "releaseState", required = false, defaultValue = "OFFLINE") ReleaseState releaseState) { - logger.info("login user {}, update process define, project name: {}, process define name: {}, " - + "process_definition_json: {}, desc: {}, locations:{}, connects:{}", - loginUser.getUserName(), projectName, name, processDefinitionJson, description, locations, connects); Map result = processDefinitionService.updateProcessDefinition(loginUser, projectName, id, name, processDefinitionJson, description, locations, connects); // If the update fails, the result will be returned directly @@ -287,13 +273,12 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/versions") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_DEFINITION_VERSIONS_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionVersions(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, @RequestParam(value = "processDefinitionCode") long processDefinitionCode) { - logger.info("login user {}, query process versions, project name: {}, pageNo: {}, pageSize: {}, processDefinitionCode: {}", - loginUser.getUserName(), projectName, pageNo, pageSize, processDefinitionCode); Map result = processDefinitionService.queryProcessDefinitionVersions(loginUser , projectName, pageNo, pageSize, processDefinitionCode); @@ -317,12 +302,11 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/version/switch") @ResponseStatus(HttpStatus.OK) @ApiException(SWITCH_PROCESS_DEFINITION_VERSION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result switchProcessDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processDefinitionId") int processDefinitionId, @RequestParam(value = "version") long version) { - logger.info("login user {}, switch process version, project name: {}, processDefinitionId: {}, version: {}", - loginUser.getUserName(), projectName, processDefinitionId, version); Map result = processDefinitionService.switchProcessDefinitionVersion(loginUser, projectName , processDefinitionId, version); return returnDataList(result); @@ -345,12 +329,11 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/version/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_PROCESS_DEFINITION_VERSION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteProcessDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processDefinitionId") int processDefinitionId, @RequestParam(value = "version") long version) { - logger.info("login user {}, delete process definition, project name: {}, processDefinitionId: {}, version: {}", - loginUser.getUserName(), projectName, processDefinitionId, version); Map result = processDefinitionService.deleteByProcessDefinitionIdAndVersion(loginUser, projectName, processDefinitionId, version); return returnDataList(result); } @@ -373,13 +356,12 @@ public class ProcessDefinitionController extends BaseController { @PostMapping(value = "/release") @ResponseStatus(HttpStatus.OK) @ApiException(RELEASE_PROCESS_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result releaseProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processId", required = true) int processId, @RequestParam(value = "releaseState", required = true) ReleaseState releaseState) { - logger.info("login user {}, release process definition, project name: {}, release state: {}", - loginUser.getUserName(), projectName, releaseState); Map result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, processId, releaseState); return returnDataList(result); } @@ -399,12 +381,11 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/select-by-id") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processId") Integer processId ) { - logger.info("query detail of process definition, login user:{}, project name:{}, process definition id:{}", - loginUser.getUserName(), projectName, processId); Map result = processDefinitionService.queryProcessDefinitionById(loginUser, projectName, processId); return returnDataList(result); } @@ -424,6 +405,7 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/select-by-name") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionByName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processDefinitionName") String processDefinitionName @@ -443,11 +425,10 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_DEFINITION_LIST) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName ) { - logger.info("query process definition list, login user:{}, project name:{}", - loginUser.getUserName(), projectName); Map result = processDefinitionService.queryProcessDefinitionList(loginUser, projectName); return returnDataList(result); } @@ -473,13 +454,13 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_DEFINITION_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId, @RequestParam("pageSize") Integer pageSize) { - logger.info("query process definition list paging, login user:{}, project name:{}", loginUser.getUserName(), projectName); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -506,6 +487,7 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/view-tree") @ResponseStatus(HttpStatus.OK) @ApiException(ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processId") Integer id, @@ -558,9 +540,6 @@ public class ProcessDefinitionController extends BaseController { @ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processDefinitionCodeList") String processDefinitionCodeList) { - - logger.info("query task node name list by definitionId list, login user:{}, project name:{}, code list: {}", - loginUser.getUserName(), projectName, processDefinitionCodeList); Map result = processDefinitionService.getTaskNodeListByDefinitionCodeList(processDefinitionCodeList); return returnDataList(result); } @@ -580,12 +559,11 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_PROCESS_DEFINE_BY_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processDefinitionId") Integer processDefinitionId ) { - logger.info("delete process definition by id, login user:{}, project name:{}, process definition id:{}", - loginUser.getUserName(), projectName, processDefinitionId); Map result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); return returnDataList(result); } @@ -605,13 +583,11 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/batch-delete") @ResponseStatus(HttpStatus.OK) @ApiException(BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result batchDeleteProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processDefinitionIds") String processDefinitionIds ) { - logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}", - loginUser.getUserName(), projectName, processDefinitionIds); - Map result = new HashMap<>(); List deleteFailedIdList = new ArrayList<>(); if (StringUtils.isNotEmpty(processDefinitionIds)) { @@ -654,13 +630,12 @@ public class ProcessDefinitionController extends BaseController { }) @GetMapping(value = "/export") @ResponseBody + @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "response"}) public void batchExportProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processDefinitionIds") String processDefinitionIds, HttpServletResponse response) { try { - logger.info("batch export process definition by ids, login user:{}, project name:{}, process definition ids:{}", - loginUser.getUserName(), projectName, processDefinitionIds); processDefinitionService.batchExportProcessDefinitionByIds(loginUser, projectName, processDefinitionIds, response); } catch (Exception e) { logger.error(Status.BATCH_EXPORT_PROCESS_DEFINE_BY_IDS_ERROR.getMsg(), e); @@ -678,10 +653,9 @@ public class ProcessDefinitionController extends BaseController { @GetMapping(value = "/queryProcessDefinitionAllByProjectId") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_DEFINITION_LIST) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionAllByProjectId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectId") Integer projectId) { - logger.info("query process definition list, login user:{}, project id:{}", - loginUser.getUserName(), projectId); Map result = processDefinitionService.queryProcessDefinitionAllByProjectId(projectId); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java index cac3431e3f..cf63019238 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java @@ -28,6 +28,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_SUB_PROCESS_INS import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROCESS_INSTANCE_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ProcessInstanceService; @@ -111,6 +112,7 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessInstanceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processDefinitionId", required = false, defaultValue = "0") Integer processDefinitionId, @@ -122,10 +124,7 @@ public class ProcessInstanceController extends BaseController { @RequestParam(value = "endDate", required = false) String endTime, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { - logger.info("query all process instance list, login user:{},project name:{}, define id:{}," + - "search value:{},executor name:{},state type:{},host:{},start time:{}, end time:{},page number:{}, page size:{}", - loginUser.getUserName(), projectName, processDefinitionId, searchVal, executorName, stateType, host, - startTime, endTime, pageNo, pageSize); + Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -151,12 +150,11 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/task-list-by-process-id") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTaskListByProcessId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processInstanceId") Integer processInstanceId ) throws IOException { - logger.info("query task instance list by process instance id, login user:{}, project name:{}, process instance id:{}", - loginUser.getUserName(), projectName, processInstanceId); Map result = processInstanceService.queryTaskListByProcessId(loginUser, projectName, processInstanceId); return returnDataList(result); } @@ -188,6 +186,7 @@ public class ProcessInstanceController extends BaseController { @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_PROCESS_INSTANCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processInstanceJson", required = false) String processInstanceJson, @@ -198,10 +197,6 @@ public class ProcessInstanceController extends BaseController { @RequestParam(value = "connects", required = false) String connects, @RequestParam(value = "flag", required = false) Flag flag ) throws ParseException { - logger.info("updateProcessInstance process instance, login user:{}, project name:{}, process instance json:{}," + - "process instance id:{}, schedule time:{}, sync define:{}, flag:{}, locations:{}, connects:{}", - loginUser.getUserName(), projectName, processInstanceJson, processInstanceId, scheduleTime, - syncDefine, flag, locations, connects); Map result = processInstanceService.updateProcessInstance(loginUser, projectName, processInstanceId, processInstanceJson, scheduleTime, syncDefine, flag, locations, connects); return returnDataList(result); @@ -222,12 +217,11 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/select-by-id") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processInstanceId") Integer processInstanceId ) { - logger.info("query process instance detail by id, login user:{},project name:{}, process instance id:{}", - loginUser.getUserName(), projectName, processInstanceId); Map result = processInstanceService.queryProcessInstanceById(loginUser, projectName, processInstanceId); return returnDataList(result); } @@ -251,6 +245,7 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/top-n") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTopNLongestRunningProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("size") Integer size, @@ -259,8 +254,6 @@ public class ProcessInstanceController extends BaseController { ) { projectName=ParameterUtils.handleEscapes(projectName); - logger.info("query top {} SUCCESS process instance order by running time whprojectNameich started between {} and {} ,login user:{},project name:{}", size, startTime, endTime, - loginUser.getUserName(), projectName); Map result=processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectName, size, startTime, endTime); return returnDataList(result); } @@ -281,12 +274,11 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_PROCESS_INSTANCE_BY_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processInstanceId") Integer processInstanceId ) { - logger.info("delete process instance by id, login user:{}, project name:{}, process instance id:{}", - loginUser.getUserName(), projectName, processInstanceId); // task queue Map result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); return returnDataList(result); @@ -307,6 +299,7 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/select-sub-process") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result querySubProcessInstanceByTaskId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("taskId") Integer taskId) { @@ -329,6 +322,7 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/select-parent-process") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR) + @AccessLogAnnotation public Result queryParentInstanceBySubId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("subId") Integer subId) { @@ -350,6 +344,7 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/view-variables") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR) + @AccessLogAnnotation public Result viewVariables(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("processInstanceId") Integer processInstanceId) throws Exception { Map result = processInstanceService.viewVariables(processInstanceId); @@ -371,6 +366,7 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/view-gantt") @ResponseStatus(HttpStatus.OK) @ApiException(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR) + @AccessLogAnnotation public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processInstanceId") Integer processInstanceId) throws Exception { @@ -390,12 +386,11 @@ public class ProcessInstanceController extends BaseController { @GetMapping(value = "/batch-delete") @ResponseStatus(HttpStatus.OK) @ApiException(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR) + @AccessLogAnnotation public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, @PathVariable String projectName, @RequestParam("processInstanceIds") String processInstanceIds ) { - logger.info("delete process instance by ids, login user:{}, project name:{}, process instance ids :{}", - loginUser.getUserName(), projectName, processInstanceIds); // task queue Map result = new HashMap<>(); List deleteFailedIdList = new ArrayList<>(); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java index bdd7d6d7ea..75387f6d6c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java @@ -27,11 +27,11 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_DETAILS import static org.apache.dolphinscheduler.api.enums.Status.QUERY_UNAUTHORIZED_PROJECT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; import org.apache.dolphinscheduler.api.service.ProjectService; -import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.ParameterUtils; @@ -39,8 +39,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -66,8 +64,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("projects") public class ProjectController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(ProjectController.class); - @Autowired private ProjectService projectService; @@ -90,11 +86,11 @@ public class ProjectController extends BaseController { @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_PROJECT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectName") String projectName, @RequestParam(value = "description", required = false) String description) { - logger.info("login user {}, create project name: {}, desc: {}", loginUser.getUserName(), projectName, description); Map result = projectService.createProject(loginUser, projectName, description); return returnDataList(result); } @@ -112,17 +108,19 @@ public class ProjectController extends BaseController { @ApiImplicitParams({ @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", dataType = "String"), - @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String") + @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", dataType = "String"), }) @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_PROJECT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectId") Integer projectId, @RequestParam("projectName") String projectName, - @RequestParam(value = "description", required = false) String description) { - logger.info("login user {} , updateProcessInstance project name: {}, desc: {}", loginUser.getUserName(), projectName, description); - Map result = projectService.update(loginUser, projectId, projectName, description); + @RequestParam(value = "description", required = false) String description, + @RequestParam(value = "userName") String userName) { + Map result = projectService.update(loginUser, projectId, projectName, description, userName); return returnDataList(result); } @@ -140,9 +138,9 @@ public class ProjectController extends BaseController { @GetMapping(value = "/query-by-id") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROJECT_DETAILS_BY_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProjectById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectId") Integer projectId) { - logger.info("login user {}, query project by id: {}", loginUser.getUserName(), projectId); Map result = projectService.queryById(projectId); return returnDataList(result); @@ -166,13 +164,13 @@ public class ProjectController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProjectListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageNo") Integer pageNo ) { - logger.info("login user {}, query project list paging", loginUser.getUserName()); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -196,11 +194,11 @@ public class ProjectController extends BaseController { @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_PROJECT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectId") Integer projectId ) { - logger.info("login user {}, delete project: {}.", loginUser.getUserName(), projectId); Map result = projectService.deleteProject(loginUser, projectId); return returnDataList(result); } @@ -219,9 +217,9 @@ public class ProjectController extends BaseController { @GetMapping(value = "/unauth-project") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_UNAUTHORIZED_PROJECT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUnauthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - logger.info("login user {}, query unauthorized project by user id: {}.", loginUser.getUserName(), userId); Map result = projectService.queryUnauthorizedProject(loginUser, userId); return returnDataList(result); } @@ -241,9 +239,9 @@ public class ProjectController extends BaseController { @GetMapping(value = "/authed-project") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_AUTHORIZED_PROJECT) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryAuthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - logger.info("login user {}, query authorized project by user id: {}.", loginUser.getUserName(), userId); Map result = projectService.queryAuthorizedProject(loginUser, userId); return returnDataList(result); } @@ -258,10 +256,8 @@ public class ProjectController extends BaseController { @GetMapping(value = "/created-and-authorized-project") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProjectCreatedAndAuthorizedByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}, query authorized and user created project by user id: {}.", - RegexUtils.escapeNRT(loginUser.getUserName()), - RegexUtils.escapeNRT(String.valueOf(loginUser.getId()))); Map result = projectService.queryProjectCreatedAndAuthorizedByUser(loginUser); return returnDataList(result); } @@ -281,11 +277,10 @@ public class ProjectController extends BaseController { }) @PostMapping(value = "/import-definition") @ApiException(IMPORT_PROCESS_DEFINE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "file"}) public Result importProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("file") MultipartFile file, @RequestParam("projectName") String projectName) { - logger.info("import process definition by id, login user:{}, project: {}", - loginUser.getUserName(), projectName); Map result = processDefinitionService.importProcessDefinition(loginUser, file, projectName); return returnDataList(result); } @@ -300,8 +295,8 @@ public class ProjectController extends BaseController { @GetMapping(value = "/query-project-list") @ResponseStatus(HttpStatus.OK) @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryAllProjectList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}, query all project list", loginUser.getUserName()); Map result = projectService.queryAllProjectList(); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java index 7c196ba3fb..111571ae60 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java @@ -22,6 +22,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_QUEUE_LIST_ERRO import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_QUEUE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_QUEUE_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.QueueService; @@ -32,8 +33,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -58,8 +57,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/queue") public class QueueController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(QueueController.class); - @Autowired private QueueService queueService; @@ -74,8 +71,8 @@ public class QueueController extends BaseController { @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_QUEUE_LIST_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}, query queue list", loginUser.getUserName()); Map result = queueService.queryList(loginUser); return returnDataList(result); } @@ -98,11 +95,11 @@ public class QueueController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_QUEUE_LIST_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryQueueListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize) { - logger.info("login user {}, query queue list,search value:{}", loginUser.getUserName(), searchVal); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -129,11 +126,10 @@ public class QueueController extends BaseController { @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_QUEUE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "queue") String queue, @RequestParam(value = "queueName") String queueName) { - logger.info("login user {}, create queue, queue: {}, queueName: {}", - loginUser.getUserName(), queue, queueName); Map result = queueService.createQueue(loginUser, queue, queueName); return returnDataList(result); } @@ -156,12 +152,11 @@ public class QueueController extends BaseController { @PostMapping(value = "/update") @ResponseStatus(HttpStatus.CREATED) @ApiException(UPDATE_QUEUE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id, @RequestParam(value = "queue") String queue, @RequestParam(value = "queueName") String queueName) { - logger.info("login user {}, update queue, id: {}, queue: {}, queueName: {}", - loginUser.getUserName(), id, queue, queueName); Map result = queueService.updateQueue(loginUser, id, queue, queueName); return returnDataList(result); } @@ -183,13 +178,12 @@ public class QueueController extends BaseController { @PostMapping(value = "/verify-queue") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_QUEUE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "queue") String queue, @RequestParam(value = "queueName") String queueName ) { - logger.info("login user {}, verfiy queue: {} queue name: {}", - loginUser.getUserName(), queue, queueName); return queueService.verifyQueue(queue, queueName); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java index 68904b51f2..d4689d56d2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java @@ -41,6 +41,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_UDF_FUNCTION_N import static org.apache.dolphinscheduler.api.enums.Status.VIEW_RESOURCE_FILE_ON_LINE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.VIEW_UDF_FUNCTION_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ResourcesService; @@ -114,14 +115,13 @@ public class ResourcesController extends BaseController { }) @PostMapping(value = "/directory/create") @ApiException(CREATE_RESOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createDirectory(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type, @RequestParam(value = "name") String alias, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "pid") int pid, @RequestParam(value = "currentDir") String currentDir) { - logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}", - loginUser.getUserName(), type, alias, description, pid, currentDir); return resourceService.createDirectory(loginUser, alias, description, type, pid, currentDir); } @@ -147,6 +147,7 @@ public class ResourcesController extends BaseController { }) @PostMapping(value = "/create") @ApiException(CREATE_RESOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type, @RequestParam(value = "name") String alias, @@ -154,8 +155,6 @@ public class ResourcesController extends BaseController { @RequestParam("file") MultipartFile file, @RequestParam(value = "pid") int pid, @RequestParam(value = "currentDir") String currentDir) { - logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}", - loginUser.getUserName(), type, alias, description, file.getName(), file.getOriginalFilename()); return resourceService.createResource(loginUser, alias, description, type, file, pid, currentDir); } @@ -180,14 +179,13 @@ public class ResourcesController extends BaseController { }) @PostMapping(value = "/update") @ApiException(UPDATE_RESOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int resourceId, @RequestParam(value = "type") ResourceType type, @RequestParam(value = "name") String alias, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "file" ,required = false) MultipartFile file) { - logger.info("login user {}, update resource, type: {}, resource alias: {}, desc: {}, file: {}", - loginUser.getUserName(), type, alias, description, file); return resourceService.updateResource(loginUser, resourceId, alias, description, type, file); } @@ -205,10 +203,10 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_RESOURCES_LIST_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryResourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type ) { - logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type); Map result = resourceService.queryResourceList(loginUser, type); return returnDataList(result); } @@ -234,6 +232,7 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_RESOURCES_LIST_PAGING) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryResourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type, @RequestParam(value = "id") int id, @@ -241,8 +240,6 @@ public class ResourcesController extends BaseController { @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize ) { - logger.info("query resource list, login user:{}, resource type:{}, search value:{}", - loginUser.getUserName(), type, searchVal); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -268,11 +265,10 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_RESOURCE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int resourceId ) throws Exception { - logger.info("login user {}, delete resource id: {}", - loginUser.getUserName(), resourceId); return resourceService.delete(loginUser, resourceId); } @@ -293,13 +289,11 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_RESOURCE_BY_NAME_AND_TYPE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyResourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "fullName") String fullName, @RequestParam(value = "type") ResourceType type ) { - logger.info("login user {}, verfiy resource alias: {},resource type: {}", - loginUser.getUserName(), fullName, type); - return resourceService.verifyResourceName(fullName, type, loginUser); } @@ -317,12 +311,11 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/list/jar") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_RESOURCES_LIST_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryResourceJarList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type, @RequestParam(value = "programType",required = false) ProgramType programType ) { - String programTypeName = programType == null ? "" : programType.name(); - logger.info("query resource list, resource type:{}, program type:{}", type, programTypeName); Map result = resourceService.queryResourceByProgramType(loginUser, type,programType); return returnDataList(result); } @@ -345,13 +338,12 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/queryResource") @ResponseStatus(HttpStatus.OK) @ApiException(RESOURCE_NOT_EXIST) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "fullName", required = false) String fullName, @RequestParam(value = "id", required = false) Integer id, @RequestParam(value = "type") ResourceType type ) { - logger.info("login user {}, query resource by full name: {} or id: {},resource type: {}", - loginUser.getUserName(), fullName, id, type); return resourceService.queryResource(fullName, id, type); } @@ -373,14 +365,12 @@ public class ResourcesController extends BaseController { }) @GetMapping(value = "/view") @ApiException(VIEW_RESOURCE_FILE_ON_LINE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result viewResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int resourceId, @RequestParam(value = "skipLineNum") int skipLineNum, @RequestParam(value = "limit") int limit ) { - logger.info("login user {}, view resource : {}, skipLineNum {} , limit {}", - loginUser.getUserName(), resourceId, skipLineNum, limit); - return resourceService.readResource(resourceId, skipLineNum, limit); } @@ -408,6 +398,7 @@ public class ResourcesController extends BaseController { }) @PostMapping(value = "/online-create") @ApiException(CREATE_RESOURCE_FILE_ON_LINE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result onlineCreateResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type, @RequestParam(value = "fileName") String fileName, @@ -417,8 +408,6 @@ public class ResourcesController extends BaseController { @RequestParam(value = "pid") int pid, @RequestParam(value = "currentDir") String currentDir ) { - logger.info("login user {}, online create resource! fileName : {}, type : {}, suffix : {},desc : {},content : {}", - loginUser.getUserName(), fileName, type, fileSuffix, description, content, pid, currentDir); if (StringUtils.isEmpty(content)) { logger.error("resource file contents are not allowed to be empty"); return error(Status.RESOURCE_FILE_IS_EMPTY.getCode(), RESOURCE_FILE_IS_EMPTY.getMsg()); @@ -441,12 +430,11 @@ public class ResourcesController extends BaseController { }) @PostMapping(value = "/update-content") @ApiException(EDIT_RESOURCE_FILE_ON_LINE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateResourceContent(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int resourceId, @RequestParam(value = "content") String content ) { - logger.info("login user {}, updateProcessInstance resource : {}", - loginUser.getUserName(), resourceId); if (StringUtils.isEmpty(content)) { logger.error("The resource file contents are not allowed to be empty"); return error(Status.RESOURCE_FILE_IS_EMPTY.getCode(), RESOURCE_FILE_IS_EMPTY.getMsg()); @@ -468,10 +456,9 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/download") @ResponseBody @ApiException(DOWNLOAD_RESOURCE_FILE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public ResponseEntity downloadResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int resourceId) throws Exception { - logger.info("login user {}, download resource : {}", - loginUser.getUserName(), resourceId); Resource file = resourceService.downloadResource(resourceId); if (file == null) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Status.RESOURCE_NOT_EXIST.getMsg()); @@ -510,6 +497,7 @@ public class ResourcesController extends BaseController { @PostMapping(value = "/udf-func/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_UDF_FUNCTION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") UdfType type, @RequestParam(value = "funcName") String funcName, @@ -518,8 +506,6 @@ public class ResourcesController extends BaseController { @RequestParam(value = "database", required = false) String database, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "resourceId") int resourceId) { - logger.info("login user {}, create udf function, type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}", - loginUser.getUserName(), type, funcName, argTypes, database, description, resourceId); return udfFuncService.createUdfFunction(loginUser, funcName, className, argTypes, database, description, type, resourceId); } @@ -538,10 +524,9 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/udf-func/update-ui") @ResponseStatus(HttpStatus.OK) @ApiException(VIEW_UDF_FUNCTION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result viewUIUdfFunction(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") int id) { - logger.info("login user {}, query udf{}", - loginUser.getUserName(), id); Map map = udfFuncService.queryUdfFuncDetail(id); return returnDataList(map); } @@ -574,6 +559,7 @@ public class ResourcesController extends BaseController { }) @PostMapping(value = "/udf-func/update") @ApiException(UPDATE_UDF_FUNCTION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int udfFuncId, @RequestParam(value = "type") UdfType type, @@ -583,8 +569,6 @@ public class ResourcesController extends BaseController { @RequestParam(value = "database", required = false) String database, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "resourceId") int resourceId) { - logger.info("login user {}, updateProcessInstance udf function id: {},type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}", - loginUser.getUserName(), udfFuncId, type, funcName, argTypes, database, description, resourceId); Map result = udfFuncService.updateUdfFunc(udfFuncId, funcName, className, argTypes, database, description, type, resourceId); return returnDataList(result); } @@ -607,13 +591,12 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/udf-func/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_UDF_FUNCTION_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUdfFuncListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize ) { - logger.info("query udf functions list, login user:{},search value:{}", - loginUser.getUserName(), searchVal); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -637,9 +620,9 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/udf-func/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATASOURCE_BY_TYPE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUdfFuncList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("type") UdfType type) { - logger.info("query udf func list, type:{}", type); Map result = udfFuncService.queryUdfFuncList(loginUser, type.ordinal()); return returnDataList(result); } @@ -659,11 +642,10 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/udf-func/verify-name") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_UDF_FUNCTION_NAME_ERROR) + @AccessLogAnnotation public Result verifyUdfFuncName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "name") String name ) { - logger.info("login user {}, verfiy udf function name: {}", - loginUser.getUserName(), name); return udfFuncService.verifyUdfFuncByName(name); } @@ -682,10 +664,10 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/udf-func/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_UDF_FUNCTION_ERROR) + @AccessLogAnnotation public Result deleteUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int udfFuncId ) { - logger.info("login user {}, delete udf function id: {}", loginUser.getUserName(), udfFuncId); return udfFuncService.delete(udfFuncId); } @@ -703,9 +685,9 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/authed-file") @ResponseStatus(HttpStatus.CREATED) @ApiException(AUTHORIZED_FILE_RESOURCE_ERROR) + @AccessLogAnnotation public Result authorizedFile(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - logger.info("authorized file resource, user: {}, user id:{}", loginUser.getUserName(), userId); Map result = resourceService.authorizedFile(loginUser, userId); return returnDataList(result); } @@ -725,9 +707,9 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/authorize-resource-tree") @ResponseStatus(HttpStatus.CREATED) @ApiException(AUTHORIZE_RESOURCE_TREE) + @AccessLogAnnotation public Result authorizeResourceTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - logger.info("all resource file, user:{}, user id:{}", loginUser.getUserName(), userId); Map result = resourceService.authorizeResourceTree(loginUser, userId); return returnDataList(result); } @@ -747,9 +729,9 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/unauth-udf-func") @ResponseStatus(HttpStatus.CREATED) @ApiException(UNAUTHORIZED_UDF_FUNCTION_ERROR) + @AccessLogAnnotation public Result unauthUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - logger.info("unauthorized udf function, login user:{}, unauthorized user id:{}", loginUser.getUserName(), userId); Map result = resourceService.unauthorizedUDFFunction(loginUser, userId); return returnDataList(result); @@ -770,10 +752,10 @@ public class ResourcesController extends BaseController { @GetMapping(value = "/authed-udf-func") @ResponseStatus(HttpStatus.CREATED) @ApiException(AUTHORIZED_UDF_FUNCTION_ERROR) + @AccessLogAnnotation public Result authorizedUDFFunction(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - logger.info("auth udf function, login user:{}, auth user id:{}", loginUser.getUserName(), userId); Map result = resourceService.authorizedUDFFunction(loginUser, userId); return returnDataList(result); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java index f4848d86ed..772fdceda3 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java @@ -27,10 +27,10 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_SCHEDULE_LIST_P import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_SCHEDULE_ERROR; import static org.apache.dolphinscheduler.common.Constants.SESSION_USER; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.SchedulerService; -import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.FailureStrategy; @@ -42,8 +42,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -70,7 +68,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/projects/{projectName}/schedule") public class SchedulerController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(SchedulerController.class); public static final String DEFAULT_WARNING_TYPE = "NONE"; public static final String DEFAULT_NOTIFY_GROUP_ID = "1"; public static final String DEFAULT_FAILURE_POLICY = "CONTINUE"; @@ -107,6 +104,7 @@ public class SchedulerController extends BaseController { @PostMapping("/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_SCHEDULE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processDefinitionId") Integer processDefinitionId, @@ -116,10 +114,6 @@ public class SchedulerController extends BaseController { @RequestParam(value = "failureStrategy", required = false, defaultValue = DEFAULT_FAILURE_POLICY) FailureStrategy failureStrategy, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @RequestParam(value = "processInstancePriority", required = false, defaultValue = DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) { - logger.info("login user {},project name: {}, process name: {}, create schedule: {}, warning type: {}, warning group id: {}," - + "failure policy: {},processInstancePriority : {}, workGroupId:{}", - RegexUtils.escapeNRT(loginUser.getUserName()), RegexUtils.escapeNRT(projectName), processDefinitionId, schedule, warningType, warningGroupId, - failureStrategy, processInstancePriority, workerGroup); Map result = schedulerService.insertSchedule(loginUser, projectName, processDefinitionId, schedule, warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup); @@ -152,6 +146,7 @@ public class SchedulerController extends BaseController { }) @PostMapping("/update") @ApiException(UPDATE_SCHEDULE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "id") Integer id, @@ -161,10 +156,6 @@ public class SchedulerController extends BaseController { @RequestParam(value = "failureStrategy", required = false, defaultValue = "END") FailureStrategy failureStrategy, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) { - logger.info("login user {},project name: {},id: {}, updateProcessInstance schedule: {}, notify type: {}, notify mails: {}, " - + "failure policy: {},processInstancePriority : {},workerGroupId:{}", - RegexUtils.escapeNRT(loginUser.getUserName()), RegexUtils.escapeNRT(projectName), id, schedule, warningType, warningGroupId, failureStrategy, - processInstancePriority, workerGroup); Map result = schedulerService.updateSchedule(loginUser, projectName, id, schedule, warningType, warningGroupId, failureStrategy, null, processInstancePriority, workerGroup); @@ -185,11 +176,10 @@ public class SchedulerController extends BaseController { }) @PostMapping("/online") @ApiException(PUBLISH_SCHEDULE_ONLINE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result online(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("id") Integer id) { - logger.info("login user {}, schedule setScheduleState, project name: {}, id: {}", - loginUser.getUserName(), projectName, id); Map result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.ONLINE); return returnDataList(result); } @@ -208,11 +198,10 @@ public class SchedulerController extends BaseController { }) @PostMapping("/offline") @ApiException(OFFLINE_SCHEDULE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result offline(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("id") Integer id) { - logger.info("login user {}, schedule offline, project name: {}, process definition id: {}", - loginUser.getUserName(), projectName, id); Map result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.OFFLINE); return returnDataList(result); @@ -239,14 +228,14 @@ public class SchedulerController extends BaseController { }) @GetMapping("/list-paging") @ApiException(QUERY_SCHEDULE_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryScheduleListPaging(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam Integer processDefinitionId, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { - logger.info("login user {}, query schedule, project name: {}, process definition id: {}", - loginUser.getUserName(), projectName, processDefinitionId); + Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -271,12 +260,11 @@ public class SchedulerController extends BaseController { @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_SCHEDULE_CRON_BY_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteScheduleById(@RequestAttribute(value = SESSION_USER) User loginUser, @PathVariable String projectName, @RequestParam("scheduleId") Integer scheduleId ) { - logger.info("delete schedule by id, login user:{}, project name:{}, schedule id:{}", - loginUser.getUserName(), projectName, scheduleId); Map result = schedulerService.deleteScheduleById(loginUser, projectName, scheduleId); return returnDataList(result); } @@ -291,10 +279,9 @@ public class SchedulerController extends BaseController { @ApiOperation(value = "queryScheduleList", notes = "QUERY_SCHEDULE_LIST_NOTES") @PostMapping("/list") @ApiException(QUERY_SCHEDULE_LIST_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryScheduleList(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName) { - logger.info("login user {}, query schedule list, project name: {}", - loginUser.getUserName(), projectName); Map result = schedulerService.queryScheduleList(loginUser, projectName); return returnDataList(result); } @@ -314,12 +301,11 @@ public class SchedulerController extends BaseController { @PostMapping("/preview") @ResponseStatus(HttpStatus.CREATED) @ApiException(PREVIEW_SCHEDULE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result previewSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "schedule") String schedule ) { - logger.info("login user {}, project name: {}, preview schedule: {}", - loginUser.getUserName(), projectName, schedule); Map result = schedulerService.previewSchedule(loginUser, projectName, schedule); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java index 42358bd65f..8ac91b880d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java @@ -20,10 +20,10 @@ package org.apache.dolphinscheduler.api.controller; import static org.apache.dolphinscheduler.api.enums.Status.FORCE_TASK_SUCCESS_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_LIST_PAGING_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.TaskInstanceService; -import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.ExecutionStatus; @@ -32,8 +32,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -60,7 +58,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/projects/{projectName}/task-instance") public class TaskInstanceController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(TaskInstanceController.class); @Autowired TaskInstanceService taskInstanceService; @@ -98,6 +95,7 @@ public class TaskInstanceController extends BaseController { @GetMapping("/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TASK_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTaskListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processInstanceId", required = false, defaultValue = "0") Integer processInstanceId, @@ -112,17 +110,6 @@ public class TaskInstanceController extends BaseController { @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { - logger.info("query task instance list, projectName:{}, processInstanceId:{}, processInstanceName:{}, search value:{}, taskName:{}, executorName: {}, stateType:{}, host:{}, start:{}, end:{}", - RegexUtils.escapeNRT(projectName), - processInstanceId, - RegexUtils.escapeNRT(processInstanceName), - RegexUtils.escapeNRT(searchVal), - RegexUtils.escapeNRT(taskName), - RegexUtils.escapeNRT(executorName), - stateType, - RegexUtils.escapeNRT(host), - RegexUtils.escapeNRT(startTime), - RegexUtils.escapeNRT(endTime)); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { @@ -149,10 +136,10 @@ public class TaskInstanceController extends BaseController { @PostMapping(value = "/force-success") @ResponseStatus(HttpStatus.OK) @ApiException(FORCE_TASK_SUCCESS_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result forceTaskSuccess(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "taskInstanceId") Integer taskInstanceId) { - logger.info("force task success, project: {}, task instance id: {}", projectName, taskInstanceId); Map result = taskInstanceService.forceTaskSuccess(loginUser, projectName, taskInstanceId); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java index bf58e09d78..38867fe174 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java @@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.controller; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_RECORD_LIST_PAGING_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.TaskRecordService; import org.apache.dolphinscheduler.api.utils.Result; @@ -27,8 +28,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -48,10 +47,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/projects/task-record") public class TaskRecordController extends BaseController { - - private static final Logger logger = LoggerFactory.getLogger(TaskRecordController.class); - - @Autowired TaskRecordService taskRecordService; @@ -73,6 +68,7 @@ public class TaskRecordController extends BaseController { @GetMapping("/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TASK_RECORD_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTaskRecordListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "taskName", required = false) String taskName, @RequestParam(value = "state", required = false) String state, @@ -85,8 +81,6 @@ public class TaskRecordController extends BaseController { @RequestParam("pageSize") Integer pageSize ) { - logger.info("query task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}", - taskName, state, taskDate, startTime, endTime); Map result = taskRecordService.queryTaskRecordListPaging(false, taskName, startTime, taskDate, sourceTable, destTable, endTime, state, pageNo, pageSize); return returnDataListPaging(result); } @@ -109,6 +103,7 @@ public class TaskRecordController extends BaseController { @GetMapping("/history-list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TASK_RECORD_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryHistoryTaskRecordListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "taskName", required = false) String taskName, @RequestParam(value = "state", required = false) String state, @@ -121,8 +116,6 @@ public class TaskRecordController extends BaseController { @RequestParam("pageSize") Integer pageSize ) { - logger.info("query hisotry task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}", - taskName, state, taskDate, startTime, endTime); Map result = taskRecordService.queryTaskRecordListPaging(true, taskName, startTime, taskDate, sourceTable, destTable, endTime, state, pageNo, pageSize); return returnDataListPaging(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java index 41eff97e0c..54cfdb38dc 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java @@ -24,10 +24,10 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TENANT_LIST_PAG import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_TENANT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_OS_TENANT_CODE_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.TenantService; -import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.ParameterUtils; @@ -35,8 +35,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -61,8 +59,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/tenant") public class TenantController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(TenantController.class); - @Autowired private TenantService tenantService; @@ -85,13 +81,12 @@ public class TenantController extends BaseController { @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_TENANT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "tenantCode") String tenantCode, @RequestParam(value = "queueId") int queueId, @RequestParam(value = "description", required = false) String description) throws Exception { - logger.info("login user {}, create tenant, tenantCode: {}, queueId: {}, desc: {}", - RegexUtils.escapeNRT(loginUser.getUserName()), RegexUtils.escapeNRT(tenantCode), - queueId, RegexUtils.escapeNRT(description)); + Map result = tenantService.createTenant(loginUser, tenantCode, queueId, description); return returnDataList(result); } @@ -114,12 +109,11 @@ public class TenantController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TENANT_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTenantlistPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { - logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}", - loginUser.getUserName(), pageNo, searchVal, pageSize); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -140,8 +134,8 @@ public class TenantController extends BaseController { @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TENANT_LIST_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTenantlist(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}, query tenant list", loginUser.getUserName()); Map result = tenantService.queryTenantList(loginUser); return returnDataList(result); } @@ -168,15 +162,13 @@ public class TenantController extends BaseController { @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_TENANT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id, @RequestParam(value = "tenantCode") String tenantCode, @RequestParam(value = "queueId") int queueId, @RequestParam(value = "description", required = false) String description) throws Exception { - String userReplace = RegexUtils.escapeNRT(loginUser.getUserName()); - String tenantCodeReplace = RegexUtils.escapeNRT(tenantCode); - String descReplace = RegexUtils.escapeNRT(description); - logger.info("login user {}, create tenant, tenantCode: {}, queueId: {}, desc: {}", userReplace, tenantCodeReplace, queueId, descReplace); + Map result = tenantService.updateTenant(loginUser, id, tenantCode, queueId, description); return returnDataList(result); } @@ -196,9 +188,9 @@ public class TenantController extends BaseController { @PostMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_TENANT_BY_ID_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteTenantById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id) throws Exception { - logger.info("login user {}, delete tenant, tenantId: {},", loginUser.getUserName(), id); Map result = tenantService.deleteTenantById(loginUser, id); return returnDataList(result); } @@ -217,10 +209,9 @@ public class TenantController extends BaseController { @GetMapping(value = "/verify-tenant-code") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_OS_TENANT_CODE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyTenantCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "tenantCode") String tenantCode) { - logger.info("login user {}, verfiy tenant code: {}", - loginUser.getUserName(), tenantCode); return tenantService.verifyTenantCode(tenantCode); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java index f0d262d29f..95db27405e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java @@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.controller; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PLUGINS_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.UiPluginService; import org.apache.dolphinscheduler.api.utils.Result; @@ -28,8 +29,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PostMapping; @@ -56,8 +55,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("ui-plugins") public class UiPluginController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(UiPluginController.class); - @Autowired UiPluginService uiPluginService; @@ -68,10 +65,10 @@ public class UiPluginController extends BaseController { @PostMapping(value = "/queryUiPluginsByType") @ResponseStatus(HttpStatus.CREATED) @ApiException(QUERY_PLUGINS_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUiPluginsByType(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "pluginType") PluginType pluginType) { - logger.info("query plugins by type , pluginType: {}", pluginType); Map result = uiPluginService.queryUiPluginsByType(pluginType); return returnDataList(result); } @@ -83,10 +80,10 @@ public class UiPluginController extends BaseController { @PostMapping(value = "/queryUiPluginDetailById") @ResponseStatus(HttpStatus.CREATED) @ApiException(QUERY_PLUGINS_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUiPluginDetailById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pluginId") Integer pluginId) { - logger.info("query plugin detail by id , pluginId: {}", pluginId); Map result = uiPluginService.queryUiPluginDetailById(pluginId); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java index 853e301efd..9c31ff4a7e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java @@ -31,6 +31,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_USER_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.USER_LIST_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_USERNAME_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.UsersService; @@ -100,6 +101,7 @@ public class UsersController extends BaseController { @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_USER_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "userPassword"}) public Result createUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userName") String userName, @RequestParam(value = "userPassword") String userPassword, @@ -108,8 +110,6 @@ public class UsersController extends BaseController { @RequestParam(value = "email") String email, @RequestParam(value = "phone", required = false) String phone, @RequestParam(value = "state", required = false) int state) throws Exception { - logger.info("login user {}, create user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, user queue: {}, state: {}", - loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone, queue, state); Map result = usersService.createUser(loginUser, userName, userPassword, email, tenantId, phone, queue, state); return returnDataList(result); } @@ -132,12 +132,11 @@ public class UsersController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_USER_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUserList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam(value = "searchVal", required = false) String searchVal) { - logger.info("login user {}, list user paging, pageNo: {}, searchVal: {}, pageSize: {}", - loginUser.getUserName(), pageNo, searchVal, pageSize); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -175,6 +174,7 @@ public class UsersController extends BaseController { @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_USER_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "userPassword"}) public Result updateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id, @RequestParam(value = "userName") String userName, @@ -184,8 +184,6 @@ public class UsersController extends BaseController { @RequestParam(value = "tenantId") int tenantId, @RequestParam(value = "phone", required = false) String phone, @RequestParam(value = "state", required = false) int state) throws Exception { - logger.info("login user {}, updateProcessInstance user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, user queue: {}, state: {}", - loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone, queue, state); Map result = usersService.updateUser(loginUser, id, userName, userPassword, email, tenantId, phone, queue, state); return returnDataList(result); } @@ -204,9 +202,9 @@ public class UsersController extends BaseController { @PostMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_USER_BY_ID_ERROR) + @AccessLogAnnotation public Result delUserById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id) throws Exception { - logger.info("login user {}, delete user, userId: {},", loginUser.getUserName(), id); Map result = usersService.deleteUserById(loginUser, id); return returnDataList(result); } @@ -227,10 +225,10 @@ public class UsersController extends BaseController { @PostMapping(value = "/grant-project") @ResponseStatus(HttpStatus.OK) @ApiException(GRANT_PROJECT_ERROR) + @AccessLogAnnotation public Result grantProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userId") int userId, @RequestParam(value = "projectIds") String projectIds) { - logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId, projectIds); Map result = usersService.grantProject(loginUser, userId, projectIds); return returnDataList(result); } @@ -251,10 +249,10 @@ public class UsersController extends BaseController { @PostMapping(value = "/grant-file") @ResponseStatus(HttpStatus.OK) @ApiException(GRANT_RESOURCE_ERROR) + @AccessLogAnnotation public Result grantResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userId") int userId, @RequestParam(value = "resourceIds") String resourceIds) { - logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId, resourceIds); Map result = usersService.grantResources(loginUser, userId, resourceIds); return returnDataList(result); } @@ -276,10 +274,10 @@ public class UsersController extends BaseController { @PostMapping(value = "/grant-udf-func") @ResponseStatus(HttpStatus.OK) @ApiException(GRANT_UDF_FUNCTION_ERROR) + @AccessLogAnnotation public Result grantUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userId") int userId, @RequestParam(value = "udfIds") String udfIds) { - logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId, udfIds); Map result = usersService.grantUDFFunction(loginUser, userId, udfIds); return returnDataList(result); } @@ -301,10 +299,10 @@ public class UsersController extends BaseController { @PostMapping(value = "/grant-datasource") @ResponseStatus(HttpStatus.OK) @ApiException(GRANT_DATASOURCE_ERROR) + @AccessLogAnnotation public Result grantDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userId") int userId, @RequestParam(value = "datasourceIds") String datasourceIds) { - logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId, datasourceIds); Map result = usersService.grantDataSource(loginUser, userId, datasourceIds); return returnDataList(result); } @@ -320,8 +318,8 @@ public class UsersController extends BaseController { @GetMapping(value = "/get-user-info") @ResponseStatus(HttpStatus.OK) @ApiException(GET_USER_INFO_ERROR) + @AccessLogAnnotation public Result getUserInfo(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {},get user info", loginUser.getUserName()); Map result = usersService.getUserInfo(loginUser); return returnDataList(result); } @@ -336,8 +334,8 @@ public class UsersController extends BaseController { @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(USER_LIST_ERROR) + @AccessLogAnnotation public Result listUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}, user list", loginUser.getUserName()); Map result = usersService.queryAllGeneralUsers(loginUser); return returnDataList(result); } @@ -352,8 +350,8 @@ public class UsersController extends BaseController { @GetMapping(value = "/list-all") @ResponseStatus(HttpStatus.OK) @ApiException(USER_LIST_ERROR) + @AccessLogAnnotation public Result listAll(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("login user {}, user list", loginUser.getUserName()); Map result = usersService.queryUserList(loginUser); return returnDataList(result); } @@ -373,11 +371,10 @@ public class UsersController extends BaseController { @GetMapping(value = "/verify-user-name") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_USERNAME_ERROR) + @AccessLogAnnotation public Result verifyUserName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userName") String userName ) { - logger.info("login user {}, verfiy user name: {}", - loginUser.getUserName(), userName); return usersService.verifyUserName(userName); } @@ -396,10 +393,9 @@ public class UsersController extends BaseController { @GetMapping(value = "/unauth-user") @ResponseStatus(HttpStatus.OK) @ApiException(UNAUTHORIZED_USER_ERROR) + @AccessLogAnnotation public Result unauthorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("alertgroupId") Integer alertgroupId) { - logger.info("unauthorized user, login user:{}, alert group id:{}", - loginUser.getUserName(), alertgroupId); Map result = usersService.unauthorizedUser(loginUser, alertgroupId); return returnDataList(result); } @@ -419,11 +415,10 @@ public class UsersController extends BaseController { @GetMapping(value = "/authed-user") @ResponseStatus(HttpStatus.OK) @ApiException(AUTHORIZED_USER_ERROR) + @AccessLogAnnotation public Result authorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("alertgroupId") Integer alertgroupId) { try { - logger.info("authorized user , login user:{}, alert group id:{}", - loginUser.getUserName(), alertgroupId); Map result = usersService.authorizedUser(loginUser, alertgroupId); return returnDataList(result); } catch (Exception e) { @@ -450,6 +445,7 @@ public class UsersController extends BaseController { @PostMapping("/register") @ResponseStatus(HttpStatus.OK) @ApiException(CREATE_USER_ERROR) + @AccessLogAnnotation public Result registerUser(@RequestParam(value = "userName") String userName, @RequestParam(value = "userPassword") String userPassword, @RequestParam(value = "repeatPassword") String repeatPassword, @@ -458,8 +454,6 @@ public class UsersController extends BaseController { userPassword = ParameterUtils.handleEscapes(userPassword); repeatPassword = ParameterUtils.handleEscapes(repeatPassword); email = ParameterUtils.handleEscapes(email); - logger.info("user self-register, userName: {}, userPassword {}, repeatPassword {}, eamil {}", - userName, Constants.PASSWORD_DEFAULT, Constants.PASSWORD_DEFAULT, email); Map result = usersService.registerUser(userName, userPassword, repeatPassword, email); return returnDataList(result); } @@ -476,11 +470,10 @@ public class UsersController extends BaseController { @PostMapping("/activate") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_USER_ERROR) + @AccessLogAnnotation public Result activateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "userName") String userName) { userName = ParameterUtils.handleEscapes(userName); - logger.info("login user {}, activate user, userName: {}", - loginUser.getUserName(), userName); Map result = usersService.activateUser(loginUser, userName); return returnDataList(result); } @@ -497,10 +490,10 @@ public class UsersController extends BaseController { @PostMapping("/batch/activate") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_USER_ERROR) + @AccessLogAnnotation public Result batchActivateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestBody List userNames) { List formatUserNames = userNames.stream().map(ParameterUtils::handleEscapes).collect(Collectors.toList()); - logger.info(" activate userNames: {}", formatUserNames); Map result = usersService.batchActivateUser(loginUser, formatUserNames); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java index a92769263a..6119ec5c69 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java @@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.controller; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_LINEAGE_ERROR; import static org.apache.dolphinscheduler.common.Constants.SESSION_USER; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.service.WorkFlowLineageService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.utils.ParameterUtils; @@ -61,6 +62,7 @@ public class WorkFlowLineageController extends BaseController { @GetMapping(value = "/list-name") @ResponseStatus(HttpStatus.OK) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result> queryWorkFlowLineageByName(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectId", value = "PROJECT_ID", required = true, example = "1") @PathVariable int projectId, @ApiIgnore @RequestParam(value = "searchVal", required = false) String searchVal) { @@ -76,6 +78,7 @@ public class WorkFlowLineageController extends BaseController { @GetMapping(value = "/list-ids") @ResponseStatus(HttpStatus.OK) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result> queryWorkFlowLineageByIds(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectId", value = "PROJECT_ID", required = true, example = "1") @PathVariable int projectId, @ApiIgnore @RequestParam(value = "ids", required = false) String ids) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java index 4211feebd1..884add2ddc 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java @@ -22,10 +22,10 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKER_ADDRESS_ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKER_GROUP_FAIL; import static org.apache.dolphinscheduler.api.enums.Status.SAVE_ERROR; +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.WorkerGroupService; -import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.ParameterUtils; @@ -33,8 +33,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -59,8 +57,6 @@ import springfox.documentation.annotations.ApiIgnore; @RequestMapping("/worker-group") public class WorkerGroupController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(WorkerGroupController.class); - @Autowired WorkerGroupService workerGroupService; @@ -82,13 +78,12 @@ public class WorkerGroupController extends BaseController { @PostMapping(value = "/save") @ResponseStatus(HttpStatus.OK) @ApiException(SAVE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result saveWorkerGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id", required = false, defaultValue = "0") int id, @RequestParam(value = "name") String name, @RequestParam(value = "addrList") String addrList ) { - logger.info("save worker group: login user {}, id:{}, name: {}, addrList: {} ", - RegexUtils.escapeNRT(loginUser.getUserName()), id, RegexUtils.escapeNRT(name), RegexUtils.escapeNRT(addrList)); Map result = workerGroupService.saveWorkerGroup(loginUser, id, name, addrList); return returnDataList(result); } @@ -111,13 +106,12 @@ public class WorkerGroupController extends BaseController { @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_WORKER_GROUP_FAIL) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryAllWorkerGroupsPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam(value = "searchVal", required = false) String searchVal ) { - logger.info("query all worker group paging: login user {}, pageNo:{}, pageSize:{}, searchVal:{}", - RegexUtils.escapeNRT(loginUser.getUserName()), pageNo, pageSize, searchVal); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -137,8 +131,8 @@ public class WorkerGroupController extends BaseController { @GetMapping(value = "/all-groups") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_WORKER_GROUP_FAIL) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryAllWorkerGroups(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("query all worker group: login user {}", RegexUtils.escapeNRT(loginUser.getUserName())); Map result = workerGroupService.queryAllGroup(); return returnDataList(result); } @@ -157,10 +151,10 @@ public class WorkerGroupController extends BaseController { @PostMapping(value = "/delete-by-id") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_WORKER_GROUP_FAIL) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") Integer id ) { - logger.info("delete worker group: login user {}, id:{} ", RegexUtils.escapeNRT(loginUser.getUserName()), id); Map result = workerGroupService.deleteWorkerGroupById(loginUser, id); return returnDataList(result); } @@ -175,8 +169,8 @@ public class WorkerGroupController extends BaseController { @GetMapping(value = "/worker-address-list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_WORKER_ADDRESS_LIST_FAIL) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryWorkerAddressList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - logger.info("query worker address list: login user {}", RegexUtils.escapeNRT(loginUser.getUserName())); Map result = workerGroupService.getWorkerAddressList(); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 5195ac2b21..8372a69355 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -210,6 +210,7 @@ public enum Status { DELETE_WORKER_GROUP_FORBIDDEN_IN_DOCKER(10176, "delete worker group forbidden in docker ", "删除worker分组在docker中禁止"), WORKER_ADDRESS_INVALID(10177, "worker address {0} invalid", "worker地址[{0}]无效"), QUERY_WORKER_ADDRESS_LIST_FAIL(10178, "query worker address list fail ", "查询worker地址列表失败"), + TRANSFORM_PROJECT_OWNERSHIP(10179, "Please transform project ownership [{0}]", "请先转移项目所有权[{0}]"), UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found", "UDF函数不存在"), UDF_FUNCTION_EXISTS(20002, "UDF function already exists", "UDF函数已存在"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java index cd6ac2b622..b90a4bde7e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java @@ -48,3 +48,4 @@ public class ApiExceptionHandler { } } + diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java index 205393f527..08b77a9448 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java @@ -84,9 +84,10 @@ public interface ProjectService { * @param projectId project id * @param projectName project name * @param desc description + * @param userName project owner * @return update result code */ - Map update(User loginUser, Integer projectId, String projectName, String desc); + Map update(User loginUser, Integer projectId, String projectName, String desc, String userName); /** * query unauthorized project diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java index 3831ad0892..02a564a75f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java @@ -32,7 +32,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -45,6 +48,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @Service public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroupService { + private Logger logger = LoggerFactory.getLogger(AlertGroupServiceImpl.class); + @Autowired private AlertGroupMapper alertGroupMapper; @@ -121,13 +126,14 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup alertGroup.setCreateUserId(loginUser.getId()); // insert - int insert = alertGroupMapper.insert(alertGroup); - - if (insert > 0) { - putMsg(result, Status.SUCCESS); - } else { - putMsg(result, Status.CREATE_ALERT_GROUP_ERROR); + try { + int insert = alertGroupMapper.insert(alertGroup); + putMsg(result, insert > 0 ? Status.SUCCESS : Status.CREATE_ALERT_GROUP_ERROR); + } catch (DuplicateKeyException ex) { + logger.error("Create alert group error.", ex); + putMsg(result, Status.ALERT_GROUP_EXIST); } + return result; } @@ -166,8 +172,13 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup alertGroup.setUpdateTime(now); alertGroup.setCreateUserId(loginUser.getId()); alertGroup.setAlertInstanceIds(alertInstanceIds); - alertGroupMapper.updateById(alertGroup); - putMsg(result, Status.SUCCESS); + try { + alertGroupMapper.updateById(alertGroup); + putMsg(result, Status.SUCCESS); + } catch (DuplicateKeyException ex) { + logger.error("Update alert group error.", ex); + putMsg(result, Status.ALERT_GROUP_EXIST); + } return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java index 8d86690d2b..8869db366e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java @@ -46,6 +46,7 @@ import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -103,9 +104,13 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource dataSource.setConnectionParams(JSONUtils.toJsonString(connectionParam)); dataSource.setCreateTime(now); dataSource.setUpdateTime(now); - dataSourceMapper.insert(dataSource); - - putMsg(result, Status.SUCCESS); + try { + dataSourceMapper.insert(dataSource); + putMsg(result, Status.SUCCESS); + } catch (DuplicateKeyException ex) { + logger.error("Create datasource error.", ex); + putMsg(result, Status.DATASOURCE_EXIST); + } return result; } @@ -164,8 +169,13 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource dataSource.setType(dataSource.getType()); dataSource.setConnectionParams(JSONUtils.toJsonString(connectionParam)); dataSource.setUpdateTime(now); - dataSourceMapper.updateById(dataSource); - putMsg(result, Status.SUCCESS); + try { + dataSourceMapper.updateById(dataSource); + putMsg(result, Status.SUCCESS); + } catch (DuplicateKeyException ex) { + logger.error("Update datasource error.", ex); + putMsg(result, Status.DATASOURCE_EXIST); + } return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java index 980588b5ef..4406d9ee1a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java @@ -33,6 +33,7 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; +import org.apache.dolphinscheduler.dao.mapper.UserMapper; import java.util.ArrayList; import java.util.Date; @@ -42,6 +43,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -63,6 +66,11 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic @Autowired private ProcessDefinitionMapper processDefinitionMapper; + @Autowired + private UserMapper userMapper; + + private Logger logger = LoggerFactory.getLogger(ProjectServiceImpl.class); + /** * create project * @@ -263,10 +271,11 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic * @param projectId project id * @param projectName project name * @param desc description + * @param userName project owner * @return update result code */ @Override - public Map update(User loginUser, Integer projectId, String projectName, String desc) { + public Map update(User loginUser, Integer projectId, String projectName, String desc, String userName) { Map result = new HashMap<>(); Map descCheck = checkDesc(desc); @@ -284,10 +293,15 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic putMsg(result, Status.PROJECT_ALREADY_EXISTS, projectName); return result; } + User user = userMapper.queryByUserNameAccurately(userName); + if (user == null) { + putMsg(result, Status.USER_NOT_EXIST, userName); + return result; + } project.setName(projectName); project.setDescription(desc); project.setUpdateTime(new Date()); - + project.setUserId(user.getId()); int update = projectMapper.updateById(project); if (update > 0) { putMsg(result, Status.SUCCESS); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java index a4bb7c3bf3..0d28d68bd6 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java @@ -36,6 +36,7 @@ import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.DatasourceUser; +import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.ProjectUser; import org.apache.dolphinscheduler.dao.entity.Resource; import org.apache.dolphinscheduler.dao.entity.ResourcesUser; @@ -45,6 +46,7 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.DataSourceUserMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; +import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; import org.apache.dolphinscheduler.dao.mapper.ResourceMapper; import org.apache.dolphinscheduler.dao.mapper.ResourceUserMapper; @@ -108,6 +110,9 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { @Autowired private ProcessDefinitionMapper processDefinitionMapper; + @Autowired + private ProjectMapper projectMapper; + /** * create user, only system admin have permission @@ -490,6 +495,13 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { putMsg(result, Status.USER_NOT_EXIST, id); return result; } + // check if is a project owner + List projects = projectMapper.queryProjectCreatedByUser(id); + if (CollectionUtils.isNotEmpty(projects)) { + String projectNames = projects.stream().map(Project::getName).collect(Collectors.joining(",")); + putMsg(result, Status.TRANSFORM_PROJECT_OWNERSHIP, projectNames); + return result; + } // delete user User user = userMapper.queryTenantCodeByUserId(id); diff --git a/dolphinscheduler-api/src/main/resources/logback-api.xml b/dolphinscheduler-api/src/main/resources/logback-api.xml index 0f06b9cff5..ed655a0870 100644 --- a/dolphinscheduler-api/src/main/resources/logback-api.xml +++ b/dolphinscheduler-api/src/main/resources/logback-api.xml @@ -58,4 +58,4 @@ - \ No newline at end of file + diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java index 7a4a51a9b6..f86d898546 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java @@ -87,6 +87,7 @@ public class ProjectControllerTest extends AbstractControllerTest { paramsMap.add("projectId", projectId); paramsMap.add("projectName","project_test_update"); paramsMap.add("desc","the test project update"); + paramsMap.add("userName", "the project owner"); MvcResult mvcResult = mockMvc.perform(post("/projects/update") .header(SESSION_ID, sessionId) @@ -96,7 +97,7 @@ public class ProjectControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); + Assert.assertEquals(Status.USER_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info("update project return result:{}", mvcResult.getResponse().getContentAsString()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java index 0f5843bca0..8466bee591 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java @@ -43,6 +43,7 @@ import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.dao.DuplicateKeyException; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -109,6 +110,17 @@ public class AlertGroupServiceTest { Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } + @Test + public void testCreateAlertgroupDuplicate() { + + Mockito.when(alertGroupMapper.insert(any(AlertGroup.class))).thenThrow(new DuplicateKeyException("group name exist")); + User user = new User(); + user.setUserType(UserType.ADMIN_USER); + Map result = alertGroupService.createAlertgroup(user, groupName, groupName, null); + logger.info(result.toString()); + Assert.assertEquals(Status.ALERT_GROUP_EXIST, result.get(Constants.STATUS)); + } + @Test public void testUpdateAlertgroup() { @@ -130,6 +142,16 @@ public class AlertGroupServiceTest { } + @Test + public void testUpdateAlertgroupDuplicate() { + User user = new User(); + user.setUserType(UserType.ADMIN_USER); + Mockito.when(alertGroupMapper.selectById(2)).thenReturn(getEntity()); + Mockito.when(alertGroupMapper.updateById(Mockito.any())).thenThrow(new DuplicateKeyException("group name exist")); + Map result = alertGroupService.updateAlertgroup(user, 2, groupName, groupName, null); + Assert.assertEquals(Status.ALERT_GROUP_EXIST, result.get(Constants.STATUS)); + } + @Test public void testDelAlertgroupById() { diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java index 0a8be1257b..24567d5333 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java @@ -30,6 +30,7 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; +import org.apache.dolphinscheduler.dao.mapper.UserMapper; import java.util.ArrayList; import java.util.Collections; @@ -70,6 +71,9 @@ public class ProjectServiceTest { @Mock private ProcessDefinitionMapper processDefinitionMapper; + @Mock + private UserMapper userMapper; + private String projectName = "ProjectServiceTest"; private String userName = "ProjectServiceTest"; @@ -240,19 +244,24 @@ public class ProjectServiceTest { Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); Mockito.when(projectMapper.selectById(1)).thenReturn(getProject()); // PROJECT_NOT_FOUNT - Map result = projectService.update(loginUser, 12, projectName, "desc"); + Map result = projectService.update(loginUser, 12, projectName, "desc", "testUser"); logger.info(result.toString()); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS)); //PROJECT_ALREADY_EXISTS - result = projectService.update(loginUser, 1, projectName, "desc"); + result = projectService.update(loginUser, 1, projectName, "desc", "testUser"); logger.info(result.toString()); Assert.assertEquals(Status.PROJECT_ALREADY_EXISTS, result.get(Constants.STATUS)); + Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(null); + result = projectService.update(loginUser, 1, "test", "desc", "testuser"); + Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); + //success + Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(new User()); project.setUserId(1); Mockito.when(projectMapper.updateById(Mockito.any(Project.class))).thenReturn(1); - result = projectService.update(loginUser, 1, "test", "desc"); + result = projectService.update(loginUser, 1, "test", "desc", "testUser"); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java index d8bcdb8070..8ae16b8639 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java @@ -31,11 +31,13 @@ import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.utils.CollectionUtils; import org.apache.dolphinscheduler.common.utils.EncryptionUtils; import org.apache.dolphinscheduler.dao.entity.AlertGroup; +import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Resource; import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.DataSourceUserMapper; +import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; import org.apache.dolphinscheduler.dao.mapper.ResourceMapper; import org.apache.dolphinscheduler.dao.mapper.ResourceUserMapper; @@ -61,6 +63,7 @@ import org.slf4j.LoggerFactory; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.collect.Lists; /** * users service test @@ -97,6 +100,9 @@ public class UsersServiceTest { @Mock private UDFUserMapper udfUserMapper; + @Mock + private ProjectMapper projectMapper; + private String queueName = "UsersServiceTestQueue"; @Before @@ -292,7 +298,13 @@ public class UsersServiceTest { logger.info(result.toString()); Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); + // user is project owner + Mockito.when(projectMapper.queryProjectCreatedByUser(1)).thenReturn(Lists.newArrayList(new Project())); + result = usersService.deleteUserById(loginUser, 1); + Assert.assertEquals(Status.TRANSFORM_PROJECT_OWNERSHIP, result.get(Constants.STATUS)); + //success + Mockito.when(projectMapper.queryProjectCreatedByUser(1)).thenReturn(null); result = usersService.deleteUserById(loginUser, 1); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); @@ -301,7 +313,6 @@ public class UsersServiceTest { Assert.assertTrue(false); } - } @Test diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java index 646307496b..b6aa9e5591 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java @@ -44,6 +44,15 @@ public class PluginDao extends AbstractBaseDao { pluginDefineMapper = ConnectionFactory.getInstance().getMapper(PluginDefineMapper.class); } + /** + * check plugin define table exist + * + * @return boolean + */ + public boolean checkPluginDefineTableExist() { + return pluginDefineMapper.checkTableExist() > 0; + } + /** * add pluginDefine * diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ConnectionFactory.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ConnectionFactory.java index 2664273724..25fe5927d3 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ConnectionFactory.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ConnectionFactory.java @@ -26,12 +26,14 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.transaction.TransactionFactory; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; -import org.mybatis.spring.SqlSessionTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import java.sql.SQLException; import javax.sql.DataSource; +import org.mybatis.spring.SqlSessionTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * not spring manager connection, only use for init db, and alert module for non-spring application @@ -81,7 +83,7 @@ public class ConnectionFactory extends SpringConnectionFactory { * * @return druid dataSource */ - private DataSource buildDataSource() { + private DataSource buildDataSource() throws SQLException { DruidDataSource druidDataSource = dataSource(); return druidDataSource; diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SpringConnectionFactory.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SpringConnectionFactory.java index 5a0e6353d0..a58955da19 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SpringConnectionFactory.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SpringConnectionFactory.java @@ -28,6 +28,7 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.type.JdbcType; +import java.sql.SQLException; import java.util.Properties; import org.mybatis.spring.SqlSessionTemplate; @@ -77,7 +78,7 @@ public class SpringConnectionFactory { * @return druid dataSource */ @Bean(destroyMethod = "") - public DruidDataSource dataSource() { + public DruidDataSource dataSource() throws SQLException { DruidDataSource druidDataSource = new DruidDataSource(); @@ -104,6 +105,7 @@ public class SpringConnectionFactory { druidDataSource.setValidationQueryTimeout(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_VALIDATION_QUERY_TIMEOUT, 3)); //auto commit druidDataSource.setDefaultAutoCommit(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_DEFAULT_AUTO_COMMIT, true)); + druidDataSource.init(); return druidDataSource; } @@ -113,7 +115,7 @@ public class SpringConnectionFactory { * @return DataSourceTransactionManager */ @Bean - public DataSourceTransactionManager transactionManager() { + public DataSourceTransactionManager transactionManager() throws SQLException { return new DataSourceTransactionManager(dataSource()); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java index e2d08b5222..1ce76707aa 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java @@ -27,6 +27,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; public interface PluginDefineMapper extends BaseMapper { + /** + * check table exist + * + * @return boolean + */ + int checkTableExist(); + /** * query all plugin define * diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml index 49abe7cb2d..0a105edcb0 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml @@ -18,6 +18,10 @@ + +