Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[WIP][Feature]New user configuration function added to the management console #4948

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,20 @@ private[conf] object BDPConfiguration extends Logging {

private[common] def formatValue[T](defaultValue: T, value: Option[String]): Option[T] = {
if (value.isEmpty || value.exists(StringUtils.isEmpty)) return Option(defaultValue)
val trimValue = value.map(_.trim)
val formattedValue = defaultValue match {
case _: String => value
case _: Byte => value.map(_.toByte)
case _: Short => value.map(_.toShort)
case _: Char => value.map(_.toCharArray.apply(0))
case _: Int => value.map(_.toInt)
case _: Long => value.map(_.toLong)
case _: Float => value.map(_.toFloat)
case _: Double => value.map(_.toDouble)
case _: Boolean => value.map(_.toBoolean)
case _: TimeType => value.map(new TimeType(_))
case _: ByteType => value.map(new ByteType(_))
case null => value
case _: String => trimValue
case _: Byte => trimValue.map(_.toByte)
case _: Short => trimValue.map(_.toShort)
case _: Char => trimValue.map(_.toCharArray.apply(0))
case _: Int => trimValue.map(_.toInt)
case _: Long => trimValue.map(_.toLong)
case _: Float => trimValue.map(_.toFloat)
case _: Double => trimValue.map(_.toDouble)
case _: Boolean => trimValue.map(_.toBoolean)
case _: TimeType => trimValue.map(new TimeType(_))
case _: ByteType => trimValue.map(new ByteType(_))
case null => trimValue
}
formattedValue.asInstanceOf[Option[T]]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object LogUtils {
}

def generateERROR(rawLog: String): String = {
getTimeFormat + " " + "ERROR" + " " + rawLog
getTimeFormat + " " + ERROR_STR + " " + rawLog
}

def generateWarn(rawLog: String): String = {
Expand All @@ -52,4 +52,6 @@ object LogUtils {
getTimeFormat + " " + "SYSTEM-WARN" + " " + rawLog
}

val ERROR_STR = "ERROR"

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ object TaskUtils {
}
} else params.put(key, waitToAdd)

private def clearMap(params: util.Map[String, AnyRef], key: String): Unit =
if (params != null && params.containsKey(key)) {
params.get(key) match {
case map: util.Map[String, AnyRef] => map.clear()
case _ => params.put(key, new util.HashMap[String, AnyRef]())
}
}

private def getConfigurationMap(
params: util.Map[String, AnyRef],
key: String
Expand Down Expand Up @@ -84,13 +92,20 @@ object TaskUtils {
def addStartupMap(params: util.Map[String, AnyRef], startupMap: util.Map[String, AnyRef]): Unit =
addConfigurationMap(params, startupMap, TaskConstant.PARAMS_CONFIGURATION_STARTUP)

def clearStartupMap(params: util.Map[String, AnyRef]): Unit = {
val configurationMap = getMap(params, TaskConstant.PARAMS_CONFIGURATION)
if (!configurationMap.isEmpty) {
clearMap(configurationMap, TaskConstant.PARAMS_CONFIGURATION_STARTUP)
}
}

def addRuntimeMap(params: util.Map[String, AnyRef], runtimeMap: util.Map[String, AnyRef]): Unit =
addConfigurationMap(params, runtimeMap, TaskConstant.PARAMS_CONFIGURATION_RUNTIME)

def addSpecialMap(params: util.Map[String, AnyRef], specialMap: util.Map[String, AnyRef]): Unit =
addConfigurationMap(params, specialMap, TaskConstant.PARAMS_CONFIGURATION_SPECIAL)

// tdoo
// todo
def getLabelsMap(params: util.Map[String, AnyRef]): util.Map[String, AnyRef] =
getMap(params, TaskConstant.LABELS)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,30 @@ public static void createNewFileWithFileSystem(
}
}

/**
* create new file and set file owner by FileSystem
*
* @param fileSystem
* @param filePath
* @param user
* @param createParentWhenNotExists
*/
public static void createNewFileAndSetOwnerWithFileSystem(
FileSystem fileSystem, FsPath filePath, String user, boolean createParentWhenNotExists)
throws Exception {
if (!fileSystem.exists(filePath)) {
if (!fileSystem.exists(filePath.getParent())) {
if (!createParentWhenNotExists) {
throw new IOException(
"parent dir " + filePath.getParent().getPath() + " dose not exists.");
}
mkdirs(fileSystem, filePath.getParent(), user);
}
fileSystem.createNewFile(filePath);
fileSystem.setOwner(filePath, user);
}
}

/**
* Recursively create a directory
*
Expand Down Expand Up @@ -133,4 +157,39 @@ public static boolean mkdirs(FileSystem fileSystem, FsPath dest, String user) th
}
return true;
}

/**
* Recursively create a directory(递归创建目录) add owner info
*
* @param fileSystem
* @param dest
* @param user
* @throws IOException
* @return
*/
public static boolean mkdirsAndSetOwner(FileSystem fileSystem, FsPath dest, String user)
throws IOException {
FsPath parentPath = dest.getParent();
Stack<FsPath> dirsToMake = new Stack<>();
dirsToMake.push(dest);
while (!fileSystem.exists(parentPath)) {
dirsToMake.push(parentPath);

if (Objects.isNull(parentPath.getParent())) {
// parent path of root is null
break;
}

parentPath = parentPath.getParent();
}
if (!fileSystem.canExecute(parentPath)) {
throw new IOException("You have not permission to access path " + dest.getPath());
}
while (!dirsToMake.empty()) {
FsPath path = dirsToMake.pop();
fileSystem.mkdir(path);
fileSystem.setOwner(path, user);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.linkis.cli.application.operator.ujes.LinkisJobOper;
import org.apache.linkis.cli.application.operator.ujes.UJESClientFactory;
import org.apache.linkis.cli.application.utils.CliUtils;
import org.apache.linkis.cli.application.utils.LoggerManager;

import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -135,14 +136,22 @@ public static InteractiveJobDesc build(CliCtx ctx) {
}

if (StringUtils.isBlank(code) && StringUtils.isNotBlank(codePath)) {
code = CliUtils.readFile(codePath);
try {
code = CliUtils.readFile(codePath);
} catch (Exception e) {
LoggerManager.getInformationLogger().error("Failed to read file", e);
throw e;
}
}

executionMap.put(LinkisKeys.KEY_CODE, code);
labelMap.put(LinkisKeys.KEY_ENGINETYPE, engineType);
labelMap.put(LinkisKeys.KEY_CODETYPE, runType);
labelMap.put(LinkisKeys.KEY_USER_CREATOR, proxyUsr + "-" + creator);
sourceMap.put(LinkisKeys.KEY_SCRIPT_PATH, scriptPath);
if (ctx.getExtraMap().containsKey(CliKeys.VERSION)) {
sourceMap.put(LinkisKeys.CLI_VERSION, ctx.getExtraMap().get(CliKeys.VERSION));
}
runtimeMap.put(LinkisKeys.KEY_HIVE_RESULT_DISPLAY_TBALE, true);

desc.setCreator(creator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public static void writeToFile(
String pathName, String fileName, String content, Boolean overWrite) {

File dir = new File(pathName);
File file = new File(fileName);

if (!dir.exists()) {
try {
Expand All @@ -47,6 +46,8 @@ public static void writeToFile(
}
}

File file = new File(dir.getAbsolutePath() + File.separator + fileName);

if (overWrite || !file.exists()) {
try {
file.createNewFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.linkis.configuration.conf;

public class AcrossClusterRuleKeys {

public static final String KEY_QUEUE_SUFFIX = "suffix";

public static final String KEY_ACROSS_CLUSTER_QUEUE_SUFFIX = "bdap2bdp";

public static final String KEY_START_TIME = "startTime";

public static final String KEY_END_TIME = "endTime";

public static final String KEY_CPU_THRESHOLD = "CPUThreshold";

public static final String KEY_MEMORY_THRESHOLD = "MemoryThreshold";

public static final String KEY_CPU_PERCENTAGE_THRESHOLD = "CPUPercentageThreshold";

public static final String KEY_MEMORY_PERCENTAGE_THRESHOLD = "MemoryPercentageThreshold";

public static final String KEY_QUEUE_RULE = "queueRule";

public static final String KEY_TIME_RULE = "timeRule";

public static final String KEY_THRESHOLD_RULE = "thresholdRule";
}
Original file line number Diff line number Diff line change
@@ -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.linkis.configuration.dao;

import org.apache.linkis.configuration.entity.AcrossClusterRule;

import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface AcrossClusterRuleMapper {

AcrossClusterRule getAcrossClusterRule(@Param("id") Long id);

void deleteAcrossClusterRule(
@Param("creator") String creator, @Param("username") String username);

void updateAcrossClusterRule(@Param("acrossClusterRule") AcrossClusterRule acrossClusterRule);

void insertAcrossClusterRule(@Param("acrossClusterRule") AcrossClusterRule acrossClusterRule);

List<AcrossClusterRule> queryAcrossClusterRuleList(
@Param("username") String username,
@Param("creator") String creator,
@Param("clusterName") String clusterName);

void validAcrossClusterRule(@Param("isValid") String isValid, @Param("id") Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.linkis.configuration.dao;

import org.apache.linkis.configuration.entity.ConfigKeyLimitForUser;
import org.apache.linkis.configuration.entity.ConfigKeyLimitVo;

import org.apache.ibatis.annotations.Param;

import java.util.List;

/** for table linkis_ps_configuration_key_limit_for_user @Description */
public interface ConfigKeyLimitForUserMapper {

int batchInsertList(List<ConfigKeyLimitForUser> list);

int updateByPrimaryKey(ConfigKeyLimitForUser configKeyLimitForUser);

int batchInsertOrUpdateList(List<ConfigKeyLimitForUser> list);

List<ConfigKeyLimitVo> selectByLabelAndKeyIds(
@Param("label") String label, @Param("keyIdList") List<Long> keyIdList);

ConfigKeyLimitVo selectByLabelAndKeyId(@Param("label") String label, @Param("keyId") Long keyId);
}
Loading