Skip to content
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.
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
@@ -0,0 +1,81 @@
/*
* 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.rm.external.yarn;

/** Enumeration of Yarn application states. */
public enum YarnAppState {

/** Application has been submitted but not yet accepted by ResourceManager. */
NEW("NEW"),

/** Application is being saved to persistent storage. */
NEW_SAVING("NEW_SAVING"),

/** Application has been submitted and is waiting for scheduling. */
SUBMITTED("SUBMITTED"),

/** Application has been accepted by ResourceManager and waiting for resource allocation. */
ACCEPTED("ACCEPTED"),

/** Application is running with at least one container executing. */
RUNNING("RUNNING"),

/** Application has completed successfully. */
FINISHED("FINISHED"),

/** Application execution has failed. */
FAILED("FAILED"),

/** Application has been manually terminated. */
KILLED("KILLED");

private final String state;

YarnAppState(String state) {
this.state = state;
}

public String getState() {
return state;
}

/**
* Check if the state is active (RUNNING or ACCEPTED). These states represent applications that
* are consuming or about to consume cluster resources.
*
* @return true if the state is active
*/
public boolean isActive() {
return this == RUNNING || this == ACCEPTED;
}

/**
* Parse string to YarnAppState enum.
*
* @param state the state string
* @return YarnAppState enum
*/
public static YarnAppState fromString(String state) {
for (YarnAppState appState : YarnAppState.values()) {
if (appState.state.equals(state)) {
return appState;
}
}
throw new IllegalArgumentException("Unknown YarnAppState: " + state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.linkis.manager.rm.external.yarn;

import org.apache.linkis.engineplugin.server.conf.EngineConnPluginConfiguration;
import org.apache.linkis.manager.common.conf.RMConfiguration;
import org.apache.linkis.manager.common.entity.resource.CommonNodeResource;
import org.apache.linkis.manager.common.entity.resource.NodeResource;
import org.apache.linkis.manager.common.entity.resource.ResourceType;
Expand Down Expand Up @@ -313,8 +314,23 @@ public List<ExternalAppInfo> requestAppInfo(

String queueName = ((YarnResourceIdentifier) identifier).getQueueName();
String realQueueName = queuePrefix + queueName;
JsonNode resp;
if (RMConfiguration.YARN_APPS_FILTER_ENABLED.getValue()) {
// Build query parameters to filter apps at Yarn API level using active states only
String queryParams =
"?queue="
+ realQueueName
+ "&states="
+ YarnAppState.RUNNING.getState()
+ ","
+ YarnAppState.ACCEPTED.getState();
resp =
getResponseByUrl("apps" + queryParams, rmWebAddress, provider).path("apps").path("app");
} else {
// Fetch all apps without filtering (for backward compatibility)
resp = getResponseByUrl("apps", rmWebAddress, provider).path("apps").path("app");
}

JsonNode resp = getResponseByUrl("apps", rmWebAddress, provider).path("apps").path("app");
if (resp.isMissingNode()) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ public class RMConfiguration {

public static final CommonVars<Boolean> GET_RESOURCE_BY_LABEL_VALUE_ENABLED =
CommonVars.apply("wds.linkis.get.resource.by.label.value.enable", false);

public static final CommonVars<Boolean> YARN_APPS_FILTER_ENABLED =
CommonVars.apply("wds.linkis.rm.yarn.apps.filter.enabled", true);
}
Loading