forked from apache/linkis
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge remote-tracking branch 'origin/master'
Showing
469 changed files
with
23,273 additions
and
2,468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule chart-testing-action
updated
5 files
+13 −0 | .github/dependabot.yml | |
+9 −8 | .github/workflows/test-action.yml | |
+5 −5 | README.md | |
+4 −4 | action.yml | |
+26 −26 | ct.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ommons/linkis-protocol/src/main/scala/org/apache/linkis/protocol/engine/JobInstance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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.protocol.engine | ||
|
||
case class JobInstance( | ||
status: String, | ||
instances: String, | ||
jobReqId: String, | ||
createTimestamp: Long, | ||
instanceRegistryTimestamp: Long | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ance-common/src/main/java/org/apache/linkis/governance/common/constant/CodeConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.governance.common.constant; | ||
|
||
public class CodeConstants { | ||
// will auto append at end of scala code; make sure the last line is not a comment | ||
public static String SCALA_CODE_AUTO_APPEND_CODE = "val linkisVar=123"; | ||
} |
79 changes: 79 additions & 0 deletions
79
...ance-common/src/main/java/org/apache/linkis/governance/common/entity/TemplateConfKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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.governance.common.entity; | ||
|
||
public class TemplateConfKey { | ||
|
||
private String templateUuid; | ||
|
||
private String key; | ||
|
||
private String templateName; | ||
|
||
private String configValue; | ||
|
||
public String getTemplateUuid() { | ||
return templateUuid; | ||
} | ||
|
||
public void setTemplateUuid(String templateUuid) { | ||
this.templateUuid = templateUuid; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getTemplateName() { | ||
return templateName; | ||
} | ||
|
||
public void setTemplateName(String templateName) { | ||
this.templateName = templateName; | ||
} | ||
|
||
public String getConfigValue() { | ||
return configValue; | ||
} | ||
|
||
public void setConfigValue(String configValue) { | ||
this.configValue = configValue; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TemplateKey{" | ||
+ "templateUuid='" | ||
+ templateUuid | ||
+ '\'' | ||
+ ", key='" | ||
+ key | ||
+ '\'' | ||
+ ", templateName='" | ||
+ templateName | ||
+ '\'' | ||
+ ", configValue='" | ||
+ configValue | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../src/main/java/org/apache/linkis/governance/common/protocol/conf/TemplateConfRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.governance.common.protocol.conf; | ||
|
||
import org.apache.linkis.protocol.message.RequestProtocol; | ||
|
||
public class TemplateConfRequest implements RequestProtocol { | ||
|
||
private String templateUuid; | ||
|
||
private String templateName; | ||
|
||
public TemplateConfRequest(String templateUuid, String templateName) { | ||
this.templateUuid = templateUuid; | ||
this.templateName = templateName; | ||
} | ||
|
||
public TemplateConfRequest(String templateUuid) { | ||
this.templateUuid = templateUuid; | ||
} | ||
|
||
public String getTemplateUuid() { | ||
return templateUuid; | ||
} | ||
|
||
public void setTemplateUuid(String templateUuid) { | ||
this.templateUuid = templateUuid; | ||
} | ||
|
||
public String getTemplateName() { | ||
return templateName; | ||
} | ||
|
||
public void setTemplateName(String templateName) { | ||
this.templateName = templateName; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...src/main/java/org/apache/linkis/governance/common/protocol/conf/TemplateConfResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.linkis.governance.common.protocol.conf; | ||
|
||
import org.apache.linkis.governance.common.entity.TemplateConfKey; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TemplateConfResponse { | ||
|
||
private List<TemplateConfKey> list = new ArrayList<>(); | ||
|
||
public List<TemplateConfKey> getList() { | ||
return list; | ||
} | ||
|
||
public void setList(List<TemplateConfKey> list) { | ||
this.list = list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
...-engineconn-manager-server/src/main/java/org/apache/linkis/ecm/restful/ECMRestfulApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* | ||
* 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.ecm.restful; | ||
|
||
import org.apache.linkis.common.conf.Configuration; | ||
import org.apache.linkis.server.Message; | ||
import org.apache.linkis.server.utils.ModuleUserUtils; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.http.Consts; | ||
|
||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import java.io.*; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.nio.file.attribute.FileOwnerAttributeView; | ||
import java.nio.file.attribute.UserPrincipal; | ||
import java.text.MessageFormat; | ||
|
||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiImplicitParam; | ||
import io.swagger.annotations.ApiImplicitParams; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.apache.linkis.ecm.errorcode.EngineconnServerErrorCodeSummary.*; | ||
|
||
@Api(tags = "ECM") | ||
@RequestMapping(path = "/engineconnManager") | ||
@RestController | ||
public class ECMRestfulApi { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(ECMRestfulApi.class); | ||
|
||
/** | ||
* * Reason for using the get method: Added gateway forwarding rules, which only support get | ||
* requests | ||
* | ||
* @param req | ||
* @param response | ||
* @param emInstance | ||
* @param instance | ||
* @param logDirSuffix | ||
* @param logType | ||
* @throws IOException | ||
*/ | ||
@ApiOperation( | ||
value = "downloadEngineLog", | ||
notes = "download engine log", | ||
response = Message.class) | ||
@ApiImplicitParams({ | ||
@ApiImplicitParam( | ||
name = "emInstance", | ||
required = true, | ||
dataType = "String", | ||
example = "xxx0002:9102"), | ||
@ApiImplicitParam( | ||
name = "instance", | ||
required = true, | ||
dataType = "String", | ||
example = "xxx0002:35873"), | ||
@ApiImplicitParam(name = "logDirSuffix", required = true, dataType = "String"), | ||
@ApiImplicitParam(name = "logType", required = true, dataType = "String") | ||
}) | ||
@ApiOperationSupport(ignoreParameters = {"json"}) | ||
@RequestMapping(path = "/downloadEngineLog", method = RequestMethod.GET) | ||
public Message downloadEngineLog( | ||
HttpServletRequest req, | ||
HttpServletResponse response, | ||
@RequestParam(value = "emInstance") String emInstance, | ||
@RequestParam(value = "instance") String instance, | ||
@RequestParam(value = "logDirSuffix") String logDirSuffix, | ||
@RequestParam(value = "logType") String logType) | ||
throws IOException { | ||
String userName = ModuleUserUtils.getOperationUser(req, "downloadEngineLog"); | ||
if (StringUtils.isBlank(instance)) { | ||
return Message.error(MessageFormat.format(PARAMETER_NOT_NULL.getErrorDesc(), "instance")); | ||
} | ||
if (StringUtils.isBlank(logDirSuffix)) { | ||
return Message.error(MessageFormat.format(PARAMETER_NOT_NULL.getErrorDesc(), "logDirSuffix")); | ||
} | ||
if (StringUtils.isBlank(logType)) { | ||
return Message.error(MessageFormat.format(PARAMETER_NOT_NULL.getErrorDesc(), "logType")); | ||
} else if (!logType.equals("stdout") | ||
&& !logType.equals("stderr") | ||
&& !logType.equals("gc") | ||
&& !logType.equals("yarnApp")) { | ||
return Message.error(LOGTYPE_ERROR.getErrorDesc()); | ||
} | ||
// 获取文件的权限归属者 | ||
FileOwnerAttributeView ownerView = | ||
Files.getFileAttributeView( | ||
Paths.get(logDirSuffix + "/" + logType), FileOwnerAttributeView.class); | ||
UserPrincipal owner = ownerView.getOwner(); | ||
if (!owner.getName().equals(userName) | ||
&& Configuration.isNotAdmin(userName) | ||
&& Configuration.isNotJobHistoryAdmin(userName)) { | ||
return Message.error( | ||
MessageFormat.format(NOT_PERMISSION.getErrorDesc(), userName, emInstance)); | ||
} | ||
File inputFile = new File(logDirSuffix, logType); | ||
if (!inputFile.exists()) { | ||
return Message.error(MessageFormat.format(LOG_IS_NOT_EXISTS.getErrorDesc(), logDirSuffix)); | ||
} else { | ||
long fileSizeInBytes = inputFile.length(); | ||
long fileSizeInMegabytes = fileSizeInBytes / (1024 * 1024); | ||
if (fileSizeInMegabytes > 100) { | ||
return Message.error(MessageFormat.format(FILE_IS_OVERSIZE.getErrorDesc(), logDirSuffix)); | ||
} | ||
ServletOutputStream outputStream = null; | ||
FileInputStream inputStream = null; | ||
BufferedInputStream fis = null; | ||
PrintWriter writer = null; | ||
try { | ||
inputStream = new FileInputStream(inputFile); | ||
fis = new BufferedInputStream(inputStream); | ||
byte[] buffer = new byte[1024]; | ||
int bytesRead = 0; | ||
response.setCharacterEncoding(Consts.UTF_8.toString()); | ||
java.nio.file.Path source = Paths.get(inputFile.getPath()); | ||
response.addHeader("Content-Type", Files.probeContentType(source)); | ||
// filename eg:xxx002_11529_stdout.txt | ||
response.addHeader( | ||
"Content-Disposition", | ||
"attachment;filename=" + instance.replace(":", "_") + "_" + logType + ".txt"); | ||
response.addHeader("Content-Length", fileSizeInBytes + ""); | ||
outputStream = response.getOutputStream(); | ||
while ((bytesRead = fis.read(buffer, 0, 1024)) != -1) { | ||
outputStream.write(buffer, 0, bytesRead); | ||
} | ||
} catch (IOException e) { | ||
logger.warn("Download EngineLog Failed Msg :", e); | ||
response.reset(); | ||
response.setCharacterEncoding(Consts.UTF_8.toString()); | ||
response.setContentType("text/plain; charset=utf-8"); | ||
writer = response.getWriter(); | ||
writer.append("error(错误):" + e.getMessage()); | ||
writer.flush(); | ||
} finally { | ||
if (outputStream != null) { | ||
outputStream.flush(); | ||
} | ||
IOUtils.closeQuietly(outputStream); | ||
IOUtils.closeQuietly(fis); | ||
IOUtils.closeQuietly(inputStream); | ||
} | ||
return Message.ok(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceConsumerRestfulApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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.entrance.restful; | ||
|
||
import org.apache.linkis.common.conf.Configuration; | ||
import org.apache.linkis.entrance.EntranceServer; | ||
import org.apache.linkis.scheduler.queue.ConsumerManager; | ||
import org.apache.linkis.server.Message; | ||
import org.apache.linkis.server.utils.ModuleUserUtils; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Api(tags = "entrance lable manager") | ||
@RestController | ||
@RequestMapping(path = "/entrance/operation/consumer") | ||
public class EntranceConsumerRestfulApi { | ||
|
||
private EntranceServer entranceServer; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(EntranceConsumerRestfulApi.class); | ||
|
||
@Autowired | ||
public void setEntranceServer(EntranceServer entranceServer) { | ||
this.entranceServer = entranceServer; | ||
} | ||
|
||
@ApiOperation(value = "kill-consumer", notes = "kill consumer", response = Message.class) | ||
@RequestMapping(path = "/kill", method = RequestMethod.GET) | ||
public Message killConsumer( | ||
HttpServletRequest req, @RequestParam(value = "groupName") String groupName) { | ||
String operationUser = ModuleUserUtils.getOperationUser(req, "kill consumer"); | ||
if (Configuration.isNotAdmin(operationUser)) { | ||
return Message.error("only admin can do this"); | ||
} | ||
logger.info("user {} to kill consumer {}", operationUser, groupName); | ||
ConsumerManager consumerManager = | ||
entranceServer | ||
.getEntranceContext() | ||
.getOrCreateScheduler() | ||
.getSchedulerContext() | ||
.getOrCreateConsumerManager(); | ||
consumerManager.destroyConsumer(groupName); | ||
logger.info("user {} finished to kill consumer {}", operationUser, groupName); | ||
return Message.ok(); | ||
} | ||
|
||
@ApiOperation(value = "consumer-info", notes = "list consumers info", response = Message.class) | ||
@RequestMapping(path = "/info", method = RequestMethod.GET) | ||
public Message countConsumer(HttpServletRequest req) { | ||
String operationUser = ModuleUserUtils.getOperationUser(req, "kill consumer"); | ||
if (Configuration.isNotAdmin(operationUser)) { | ||
return Message.error("only admin can do this"); | ||
} | ||
ConsumerManager consumerManager = | ||
entranceServer | ||
.getEntranceContext() | ||
.getOrCreateScheduler() | ||
.getSchedulerContext() | ||
.getOrCreateConsumerManager(); | ||
return Message.ok().data("consumerNum", consumerManager.listConsumers().length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
490 changes: 366 additions & 124 deletions
490
.../linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceRestfulApi.java
Large diffs are not rendered by default.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
...entrance/src/main/java/org/apache/linkis/entrance/scheduler/CreatorECTypeDefaultConf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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.entrance.scheduler; | ||
|
||
import org.apache.linkis.common.conf.Configuration; | ||
import org.apache.linkis.entrance.conf.EntranceConfiguration; | ||
import org.apache.linkis.entrance.utils.EntranceUtils; | ||
import org.apache.linkis.governance.common.protocol.conf.RequestQueryEngineConfig; | ||
import org.apache.linkis.governance.common.protocol.conf.ResponseQueryConfig; | ||
import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel; | ||
import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel; | ||
import org.apache.linkis.rpc.Sender; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import scala.Tuple2; | ||
|
||
import com.google.common.cache.CacheBuilder; | ||
import com.google.common.cache.CacheLoader; | ||
import com.google.common.cache.LoadingCache; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CreatorECTypeDefaultConf { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(CreatorECTypeDefaultConf.class); | ||
|
||
public static Sender confSender = | ||
Sender.getSender( | ||
Configuration.CLOUD_CONSOLE_CONFIGURATION_SPRING_APPLICATION_NAME().getValue()); | ||
|
||
private static LoadingCache<String, Integer> confCache = | ||
CacheBuilder.newBuilder() | ||
.maximumSize(1000) | ||
.expireAfterWrite( | ||
(long) EntranceConfiguration.ENTRANCE_CREATOR_JOB_LIMIT_CONF_CACHE().getValue(), | ||
TimeUnit.MINUTES) | ||
.build( | ||
new CacheLoader<String, Integer>() { | ||
@Override | ||
public Integer load(String key) throws Exception { | ||
Tuple2<UserCreatorLabel, EngineTypeLabel> tuple2 = | ||
EntranceUtils.fromKeyGetLabels(key); | ||
RequestQueryEngineConfig requestQueryEngineConfig = | ||
new RequestQueryEngineConfig(tuple2._1, tuple2._2(), null); | ||
int jobLimit = | ||
(int) EntranceConfiguration.ENTRANCE_CREATOR_JOB_LIMIT().getValue(); | ||
try { | ||
Object response = confSender.ask(requestQueryEngineConfig); | ||
if (response instanceof ResponseQueryConfig) { | ||
jobLimit = | ||
(int) | ||
EntranceConfiguration.ENTRANCE_CREATOR_JOB_LIMIT() | ||
.getValue(((ResponseQueryConfig) response).getKeyAndValue()); | ||
} | ||
} catch (Exception e) { | ||
logger.warn("Failed to get key {} from conf", key, e); | ||
} | ||
return jobLimit; | ||
} | ||
}); | ||
|
||
public static int getCreatorECTypeMaxRunningJobs(String creator, String ecType) { | ||
int jobLimit = (int) EntranceConfiguration.ENTRANCE_CREATOR_JOB_LIMIT().getValue(); | ||
if (StringUtils.isNoneBlank(creator, ecType)) { | ||
try { | ||
String key = EntranceUtils.getDefaultCreatorECTypeKey(creator, ecType); | ||
jobLimit = confCache.get(key); | ||
} catch (Exception e) { | ||
logger.warn("Failed to get key creator {} ecType {} from cache", creator, ecType, e); | ||
} | ||
} | ||
int entranceNumber = EntranceUtils.getRunningEntranceNumber(); | ||
return jobLimit / entranceNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
...s-entrance/src/main/java/org/apache/linkis/entrance/server/EntranceFailoverJobServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* 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.entrance.server; | ||
|
||
import org.apache.linkis.common.ServiceInstance; | ||
import org.apache.linkis.common.utils.Utils; | ||
import org.apache.linkis.entrance.EntranceServer; | ||
import org.apache.linkis.entrance.conf.EntranceConfiguration; | ||
import org.apache.linkis.entrance.constant.ServiceNameConsts; | ||
import org.apache.linkis.entrance.scheduler.EntranceSchedulerContext; | ||
import org.apache.linkis.entrance.utils.JobHistoryHelper; | ||
import org.apache.linkis.governance.common.entity.job.JobRequest; | ||
import org.apache.linkis.publicservice.common.lock.entity.CommonLock; | ||
import org.apache.linkis.publicservice.common.lock.service.CommonLockService; | ||
import org.apache.linkis.rpc.Sender; | ||
import org.apache.linkis.scheduler.queue.SchedulerEventState; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.ContextClosedEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.*; | ||
import java.util.stream.Collectors; | ||
|
||
import scala.Enumeration; | ||
import scala.collection.Iterator; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Component(ServiceNameConsts.ENTRANCE_FAILOVER_SERVER) | ||
public class EntranceFailoverJobServer { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(EntranceFailoverJobServer.class); | ||
|
||
@Autowired private EntranceServer entranceServer; | ||
|
||
@Autowired private CommonLockService commonLockService; | ||
|
||
private static String ENTRANCE_FAILOVER_LOCK = "ENTRANCE_FAILOVER_LOCK"; | ||
|
||
private ScheduledExecutorService scheduledExecutor; | ||
|
||
private Future future; | ||
|
||
@PostConstruct | ||
public void init() { | ||
if (EntranceConfiguration.ENTRANCE_FAILOVER_ENABLED()) { | ||
this.scheduledExecutor = | ||
Executors.newSingleThreadScheduledExecutor( | ||
Utils.threadFactory("Linkis-Failover-Scheduler-Thread-", true)); | ||
failoverTask(); | ||
} | ||
} | ||
|
||
@EventListener | ||
private void shutdownFailover(ContextClosedEvent event) { | ||
if (future != null && !future.isDone()) { | ||
future.cancel(true); | ||
} | ||
if (scheduledExecutor != null) { | ||
scheduledExecutor.shutdown(); | ||
logger.info("Entrance Failover Server exit!"); | ||
} | ||
} | ||
|
||
public void failoverTask() { | ||
future = | ||
scheduledExecutor.scheduleWithFixedDelay( | ||
() -> { | ||
EntranceSchedulerContext schedulerContext = | ||
(EntranceSchedulerContext) | ||
entranceServer | ||
.getEntranceContext() | ||
.getOrCreateScheduler() | ||
.getSchedulerContext(); | ||
|
||
// entrance do not failover job when it is offline | ||
if (schedulerContext.getOfflineFlag()) return; | ||
|
||
CommonLock commonLock = new CommonLock(); | ||
commonLock.setLockObject(ENTRANCE_FAILOVER_LOCK); | ||
Boolean locked = false; | ||
try { | ||
locked = commonLockService.lock(commonLock, 30 * 1000L); | ||
if (!locked) return; | ||
logger.info("success locked {}", ENTRANCE_FAILOVER_LOCK); | ||
|
||
// get all entrance server from eureka | ||
ServiceInstance[] serviceInstances = | ||
Sender.getInstances(Sender.getThisServiceInstance().getApplicationName()); | ||
if (serviceInstances == null || serviceInstances.length <= 0) return; | ||
|
||
// serverInstance to map | ||
Map<String, Long> serverInstanceMap = | ||
Arrays.stream(serviceInstances) | ||
.collect( | ||
Collectors.toMap( | ||
ServiceInstance::getInstance, | ||
ServiceInstance::getRegistryTimestamp, | ||
(k1, k2) -> k2)); | ||
|
||
// It is very important to avoid repeated execute job | ||
// when failover self job, if self instance is empty, the job can be repeated | ||
// execute | ||
if (!serverInstanceMap.containsKey(Sender.getThisInstance())) { | ||
logger.warn( | ||
"server has just started and has not get self info, it does not failover"); | ||
return; | ||
} | ||
|
||
// get failover job expired time (获取任务故障转移过期时间,配置为0表示不过期, 过期则不处理) | ||
long expiredTimestamp = 0L; | ||
if (EntranceConfiguration.ENTRANCE_FAILOVER_DATA_INTERVAL_TIME() > 0) { | ||
expiredTimestamp = | ||
System.currentTimeMillis() | ||
- EntranceConfiguration.ENTRANCE_FAILOVER_DATA_INTERVAL_TIME(); | ||
} | ||
|
||
List<JobRequest> jobRequests = | ||
JobHistoryHelper.queryWaitForFailoverTask( | ||
serverInstanceMap, | ||
getUnCompleteStatus(), | ||
expiredTimestamp, | ||
EntranceConfiguration.ENTRANCE_FAILOVER_DATA_NUM_LIMIT()); | ||
if (jobRequests.isEmpty()) return; | ||
List<Long> ids = | ||
jobRequests.stream().map(JobRequest::getId).collect(Collectors.toList()); | ||
logger.info("success query failover jobs , job size: {}, ids: {}", ids.size(), ids); | ||
|
||
// failover to local server | ||
for (JobRequest jobRequest : jobRequests) { | ||
entranceServer.failoverExecute(jobRequest); | ||
} | ||
logger.info("finished execute failover jobs, job ids: {}", ids); | ||
|
||
} catch (Exception e) { | ||
logger.error("failover failed", e); | ||
} finally { | ||
if (locked) commonLockService.unlock(commonLock); | ||
} | ||
}, | ||
EntranceConfiguration.ENTRANCE_FAILOVER_SCAN_INIT_TIME(), | ||
EntranceConfiguration.ENTRANCE_FAILOVER_SCAN_INTERVAL(), | ||
TimeUnit.MILLISECONDS); | ||
} | ||
|
||
private List<String> getUnCompleteStatus() { | ||
List<String> status = new ArrayList<>(); | ||
Enumeration.ValueSet values = SchedulerEventState.values(); | ||
Iterator<Enumeration.Value> iterator = values.iterator(); | ||
while (iterator.hasNext()) { | ||
Enumeration.Value next = iterator.next(); | ||
if (!SchedulerEventState.isCompleted(next)) status.add(next.toString()); | ||
} | ||
return status; | ||
} | ||
} |
522 changes: 497 additions & 25 deletions
522
...governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/EntranceServer.scala
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../src/main/scala/org/apache/linkis/entrance/interceptor/impl/TemplateConfInterceptor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.linkis.entrance.interceptor.impl | ||
|
||
import org.apache.linkis.entrance.conf.EntranceConfiguration | ||
import org.apache.linkis.entrance.interceptor.EntranceInterceptor | ||
import org.apache.linkis.governance.common.entity.job.JobRequest | ||
|
||
import java.lang | ||
|
||
class TemplateConfInterceptor extends EntranceInterceptor { | ||
|
||
override def apply(jobRequest: JobRequest, logAppender: lang.StringBuilder): JobRequest = { | ||
if (EntranceConfiguration.TEMPLATE_CONF_SWITCH.getValue) { | ||
TemplateConfUtils.dealWithTemplateConf(jobRequest, logAppender) | ||
} else { | ||
jobRequest | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.