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

New ECM should be add to the last of the choice array. #2243

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -49,6 +49,8 @@ object AMConfiguration {

val EM_LABEL_INIT_WAIT = CommonVars("wds.linkis.manager.am.em.label.init.wait", new TimeType("5m"))

val EM_NEW_WAIT_MILLS = CommonVars("wds.linkis.manager.am.em.new.wait.mills", 1000 * 60L)

val ENGINECONN_SPRING_APPLICATION_NAME = CommonVars("wds.linkis.engineconn.application.name", "linkis-cg-engineplugin")

val ENGINECONN_DEBUG_ENABLED = CommonVars("wds.linkis.engineconn.debug.mode.enable", false)
Expand Down
@@ -0,0 +1,76 @@
/*
* 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.manager.am.selector.rule

import org.apache.linkis.common.utils.{Logging, Utils}
import org.apache.linkis.manager.am.conf.AMConfiguration
import org.apache.linkis.manager.common.entity.node.{EMNode, Node}
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Component

import scala.collection.mutable.ArrayBuffer

/**
* new ecm node will be added to last
*/
@Component
@Order(7)
class NewECMStandbyRule extends NodeSelectRule with Logging {

override def ruleFiltering(nodes: Array[Node]): Array[Node] = {
if (null != nodes && !nodes.isEmpty) {
Utils.tryCatch {
if (nodes.head.isInstanceOf[EMNode]) {
val newEcmArray = new ArrayBuffer[EMNode]()
val nullStarttimeArray = new ArrayBuffer[EMNode]()
val sortedArray = new ArrayBuffer[EMNode](nodes.size)
val nowTime = System.currentTimeMillis()
nodes.map(_.asInstanceOf[EMNode]).foreach(node => {
if (null != node.getStartTime) {
if (nowTime - node.getStartTime.getTime < AMConfiguration.EM_NEW_WAIT_MILLS.getValue) {
logger.info(s"EMNode : ${node.getServiceInstance.getInstance} with createTime : ${node.getStartTime} is new, will standby.")
newEcmArray.append(node)
} else {
sortedArray.append(node)
}
} else {
nullStarttimeArray.append(node)
}
})
if (newEcmArray.size > 0) {
newEcmArray.sortWith((n1, n2) => n1.getStartTime.getTime < n2.getStartTime.getTime).foreach(node => sortedArray.append(node))
}
if (nullStarttimeArray.size > 0) {
nullStarttimeArray.foreach(node => sortedArray.append(node))
}
return sortedArray.toArray
} else {
return nodes
}
} {
case e: Exception =>
logger.error(s"Sort Failed because : ${e.getMessage}, will not sort.")
return nodes
}
} else {
nodes
}
}

}