Skip to content

Commit

Permalink
Merge branch 'dev' into fix/switch_js
Browse files Browse the repository at this point in the history
  • Loading branch information
caishunfeng authored Mar 18, 2024
2 parents 22c6a7e + faa794c commit cd39586
Show file tree
Hide file tree
Showing 74 changed files with 1,649 additions and 1,625 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public void testQueryAccessTokenList() {
@Test
public void testQueryAccessTokenByUser() {
User user = this.getLoginUser();
user.setUserType(UserType.GENERAL_USER);
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
() -> accessTokenService.queryAccessTokenByUser(user, 2));

user.setUserType(UserType.ADMIN_USER);
List<AccessToken> accessTokenList = Lists.newArrayList(this.getEntity());
when(this.accessTokenMapper.queryAccessTokenByUser(Mockito.anyInt())).thenReturn(accessTokenList);
Expand All @@ -106,14 +110,34 @@ public void testQueryAccessTokenByUser() {

@Test
public void testCreateToken() {
User user = getLoginUser();

// Throw ServiceException when user has no permission
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
() -> accessTokenService.createToken(user, 2, getDate(), "AccessTokenServiceTest"));

user.setId(0);

// Throw ServiceException when user is invalid
assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR,
() -> accessTokenService.createToken(user, 0, getDate(), "AccessTokenServiceTest"));

user.setId(1);

// Given Token
when(accessTokenMapper.insert(any(AccessToken.class))).thenReturn(2);
assertDoesNotThrow(() -> {
accessTokenService.createToken(getLoginUser(), 1, getDate(), "AccessTokenServiceTest");
accessTokenService.createToken(user, 1, getDate(), "AccessTokenServiceTest");
});

// Token is absent
assertDoesNotThrow(() -> accessTokenService.createToken(getLoginUser(), 1, getDate(), null));
assertDoesNotThrow(
() -> accessTokenService.createToken(user, 1, getDate(), null));

// Throw Service Exception when insert failed
when(accessTokenMapper.insert(any(AccessToken.class))).thenReturn(0);
assertThrowsServiceException(Status.CREATE_ACCESS_TOKEN_ERROR,
() -> accessTokenService.createToken(user, 1, getDate(), "AccessTokenServiceTest"));
}

@Test
Expand All @@ -127,8 +151,9 @@ public void testGenerateToken() {

@Test
public void testDelAccessTokenById() {
AccessToken accessToken = getEntity();

when(accessTokenMapper.selectById(1)).thenReturn(getEntity());
when(accessTokenMapper.selectById(1)).thenReturn(accessToken);
User userLogin = new User();
userLogin.setId(1);
userLogin.setUserType(UserType.ADMIN_USER);
Expand All @@ -139,10 +164,19 @@ public void testDelAccessTokenById() {
// not exist
assertThrowsServiceException(Status.ACCESS_TOKEN_NOT_EXIST,
() -> accessTokenService.deleteAccessTokenById(userLogin, 0));

// no operate
userLogin.setId(2);
userLogin.setUserType(UserType.GENERAL_USER);

when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 2,
ACCESS_TOKEN_DELETE, baseServiceLogger)).thenReturn(true);
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null,
2, baseServiceLogger)).thenReturn(true);

assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
() -> accessTokenService.deleteAccessTokenById(userLogin, 1));

// success
userLogin.setId(1);
userLogin.setUserType(UserType.ADMIN_USER);
Expand All @@ -153,9 +187,12 @@ public void testDelAccessTokenById() {

@Test
public void testUpdateToken() {
User user = new User();
user.setId(1);
user.setUserType(UserType.ADMIN_USER);
// operation perm check
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
ACCESS_TOKEN_UPDATE, baseServiceLogger)).thenReturn(false);
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
() -> accessTokenService.updateToken(getLoginUser(), 1, 1, getDate(), "token"));

when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
ACCESS_TOKEN_UPDATE, baseServiceLogger)).thenReturn(true);
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
Expand All @@ -176,6 +213,23 @@ public void testUpdateToken() {
baseServiceLogger)).thenReturn(true);
assertThrowsServiceException(Status.ACCESS_TOKEN_NOT_EXIST,
() -> accessTokenService.updateToken(getLoginUser(), 2, Integer.MAX_VALUE, getDate(), "token"));

// resource perm check
User user = getLoginUser();
user.setUserType(UserType.GENERAL_USER);
user.setId(2);
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 2,
ACCESS_TOKEN_UPDATE, baseServiceLogger)).thenReturn(true);
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 2,
baseServiceLogger)).thenReturn(true);

assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
() -> accessTokenService.updateToken(user, 1, Integer.MAX_VALUE, getDate(), "token"));

// Throw Service Exception when update failed
when(accessTokenMapper.updateById(any(AccessToken.class))).thenReturn(0);
assertThrowsServiceException(Status.ACCESS_TOKEN_NOT_EXIST,
() -> accessTokenService.updateToken(getLoginUser(), 1, Integer.MAX_VALUE, getDate(), "token"));
}

private User getLoginUser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,142 +19,27 @@

import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.OSUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.plugin.task.api.TaskConstants;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Nullable;

import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

import org.slf4j.Logger;

/**
* mainly used to get the start command line of a process.
*/
@Slf4j
public class ProcessUtils {

/**
* Initialization regularization, solve the problem of pre-compilation performance,
* avoid the thread safety problem of multi-thread operation
*/
private static final Pattern MACPATTERN = Pattern.compile("-[+|-]-\\s(\\d+)");

/**
* Expression of PID recognition in Windows scene
*/
private static final Pattern WINDOWSATTERN = Pattern.compile("\\w+\\((\\d+)\\)");

/**
* get kerberos init command
*/
static String getKerberosInitCommand() {
log.info("get kerberos init command");
StringBuilder kerberosCommandBuilder = new StringBuilder();
boolean hadoopKerberosState =
PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false);
if (hadoopKerberosState) {
kerberosCommandBuilder.append("export KRB5_CONFIG=")
.append(PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH))
.append("\n\n")
.append(String.format("kinit -k -t %s %s || true",
PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH),
PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME)))
.append("\n\n");
log.info("kerberos init command: {}", kerberosCommandBuilder);
}
return kerberosCommandBuilder.toString();
}

/**
* build kill command for yarn application
*
* @param logger logger
* @param tenantCode tenant code
* @param appId app id
* @param commandFile command file
* @param cmd cmd
*/
private static void execYarnKillCommand(Logger logger, String tenantCode, String appId, String commandFile,
String cmd) {
try {
StringBuilder sb = new StringBuilder();
sb.append("#!/bin/sh\n");
sb.append("BASEDIR=$(cd `dirname $0`; pwd)\n");
sb.append("cd $BASEDIR\n");
if (CommonUtils.getSystemEnvPath() != null) {
sb.append("source ").append(CommonUtils.getSystemEnvPath()).append("\n");
}
sb.append("\n\n");
sb.append(cmd);

File f = new File(commandFile);

if (!f.exists()) {
org.apache.commons.io.FileUtils.writeStringToFile(new File(commandFile), sb.toString(),
StandardCharsets.UTF_8);
}

String runCmd = String.format("%s %s", Constants.SH, commandFile);
runCmd = OSUtils.getSudoCmd(tenantCode, runCmd);
log.info("kill cmd:{}", runCmd);
OSUtils.exeCmd(runCmd);
} catch (Exception e) {
log.error(String.format("Kill yarn application app id [%s] failed: [%s]", appId, e.getMessage()));
}
}

/**
* get pids str.
*
* @param processId process id
* @return pids pid String
* @throws Exception exception
*/
public static String getPidsStr(int processId) throws Exception {
List<String> pidList = new ArrayList<>();
Matcher mat = null;
// pstree pid get sub pids
if (SystemUtils.IS_OS_MAC) {
String pids = OSUtils.exeCmd(String.format("%s -sp %d", Constants.PSTREE, processId));
if (null != pids) {
mat = MACPATTERN.matcher(pids);
}
} else {
String pids = OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, processId));
if (null != pids) {
mat = WINDOWSATTERN.matcher(pids);
}
}

if (null != mat) {
while (mat.find()) {
pidList.add(mat.group(1));
}
}

if (OSUtils.isSudoEnable() && !pidList.isEmpty()) {
pidList = pidList.subList(1, pidList.size());
}
return String.join(" ", pidList).trim();
}

/**
* find logs and kill yarn tasks.
*
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion dolphinscheduler-ui/src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export const workflowExecutionState = (
icon: HourglassOutlined,
isSpin: false,
classNames: 'wait_to_run'
},
}
})

/**
Expand Down
2 changes: 1 addition & 1 deletion dolphinscheduler-ui/src/components/chart/modules/Bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const BarChart = defineComponent({
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
}
},
grid: {
left: '3%',
Expand Down
8 changes: 1 addition & 7 deletions dolphinscheduler-ui/src/components/chart/modules/Gauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
* limitations under the License.
*/

import {
defineComponent,
onMounted,
onBeforeUnmount,
PropType,
ref
} from 'vue'
import { defineComponent, onMounted, onBeforeUnmount, PropType, ref } from 'vue'
import initChart from '@/components/chart'
import type { Ref } from 'vue'

Expand Down
8 changes: 4 additions & 4 deletions dolphinscheduler-ui/src/layouts/content/use-dataList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ export function useDataList() {
{
label: t('menu.project_overview'),
key: `/projects/${projectCode}`,
payload: { projectName: projectName },
payload: { projectName: projectName }
},
{
label: t('menu.project_parameter'),
key: `/projects/${projectCode}/parameter`,
payload: { projectName: projectName },
payload: { projectName: projectName }
},
{
label: t('menu.project_preferences'),
key: `/projects/${projectCode}/preferences`,
payload: { projectName: projectName },
},
payload: { projectName: projectName }
}
]
},
{
Expand Down
Loading

0 comments on commit cd39586

Please sign in to comment.