From ea909373470ced9b225bf60b835bbd5a3fd0711e Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sat, 4 Nov 2023 11:51:47 +0800 Subject: [PATCH] YARN-11483. Fix CheckStyle. --- .../DeleteFederationApplicationRequest.java | 50 ++++++++++ .../DeleteFederationApplicationResponse.java | 47 ++++++++++ ...erver_resourcemanager_service_protos.proto | 8 ++ .../hadoop/yarn/client/cli/RouterCLI.java | 56 ++++++++++-- ...eteFederationApplicationRequestPBImpl.java | 91 +++++++++++++++++++ 5 files changed, 246 insertions(+), 6 deletions(-) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DeleteFederationApplicationRequest.java create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DeleteFederationApplicationResponse.java create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DeleteFederationApplicationRequestPBImpl.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DeleteFederationApplicationRequest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DeleteFederationApplicationRequest.java new file mode 100644 index 0000000000000..8444d6ac9cb6a --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DeleteFederationApplicationRequest.java @@ -0,0 +1,50 @@ +/** + * 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.hadoop.yarn.server.api.protocolrecords; + +import org.apache.hadoop.classification.InterfaceAudience.Private; +import org.apache.hadoop.classification.InterfaceAudience.Public; +import org.apache.hadoop.classification.InterfaceStability.Unstable; +import org.apache.hadoop.yarn.util.Records; + +/** + * This class is used for cleaning up an application that exists in the FederationStateStore. + * This is a user-specified operation; we typically use this command to clean up an expired application. + * However, it can also be used to clean up non-expired application, although it is not recommended. + */ +@Private +@Unstable +public abstract class DeleteFederationApplicationRequest { + + @Private + @Unstable + public static DeleteFederationApplicationRequest newInstance(String application) { + DeleteFederationApplicationRequest request = + Records.newRecord(DeleteFederationApplicationRequest.class); + request.setApplication(application); + return request; + } + + @Public + @Unstable + public abstract String getApplication(); + + @Public + @Unstable + public abstract void setApplication(String application); +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DeleteFederationApplicationResponse.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DeleteFederationApplicationResponse.java new file mode 100644 index 0000000000000..d75515ff633ec --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/DeleteFederationApplicationResponse.java @@ -0,0 +1,47 @@ +/** + * 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.hadoop.yarn.server.api.protocolrecords; + +import org.apache.hadoop.classification.InterfaceAudience.Public; +import org.apache.hadoop.classification.InterfaceAudience.Private; +import org.apache.hadoop.classification.InterfaceStability.Unstable; +import org.apache.hadoop.yarn.util.Records; + +@Private +@Unstable +public abstract class DeleteFederationApplicationResponse { + + public static DeleteFederationApplicationResponse newInstance() { + return Records.newRecord(DeleteFederationApplicationResponse.class); + } + + public static DeleteFederationApplicationResponse newInstance(String msg) { + DeleteFederationApplicationResponse response = + Records.newRecord(DeleteFederationApplicationResponse.class); + response.setMessage(msg); + return response; + } + + @Public + @Unstable + public abstract String getMessage(); + + @Public + @Unstable + public abstract void setMessage(String msg); +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto index a2945f1eb1ee1..ba18e514a7dfa 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto @@ -203,6 +203,14 @@ message QueryFederationQueuePoliciesResponseProto { repeated FederationQueueWeightProto federationQueueWeights = 5; } +message DeleteFederationApplicationRequestProto { + optional string application = 1; +} + +message DeleteFederationApplicationResponseProto { + optional string message = 1; +} + ////////////////////////////////////////////////////////////////// ///////////// RM Failover related records //////////////////////// ////////////////////////////////////////////////////////////////// diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java index e52dbaafd9163..e977dc8746c4e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java @@ -17,12 +17,7 @@ */ package org.apache.hadoop.yarn.client.cli; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.MissingArgumentException; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.*; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -247,6 +242,9 @@ public class RouterCLI extends Configured implements Tool { .addExampleDescs(APPLICATION_DELETE_USAGE.args, APPLICATION_DELETE_USAGE_EXAMPLE_DESC) .addExample(APPLICATION_DELETE_USAGE.args, APPLICATION_DELETE_USAGE_EXAMPLE_1); + // delete application + private static final String OPTION_DELETE_APP = "delete"; + protected final static Map ADMIN_USAGE = ImmutableMap.builder() // Command1: deregisterSubCluster @@ -836,6 +834,50 @@ protected int handListPolicies(int pageSize, int currentPage, String queue, List } } + + private int handleDeleteApplication(String application) { + LOG.info("Delete Application = {}.", application); + try { + /*SaveFederationQueuePolicyRequest request = parsePolicy(policy); + ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol(); + SaveFederationQueuePolicyResponse response = adminProtocol.saveFederationQueuePolicy(request); + System.out.println(response.getMessage());*/ + return EXIT_SUCCESS; + } catch (Exception e) { + LOG.error("handleSavePolicy error.", e); + return EXIT_ERROR; + } + } + + private int handleApplication(String[] args) + throws IOException, YarnException, ParseException { + // Prepare Options. + Options opts = new Options(); + opts.addOption("application", false, + "We provide a set of commands to query and clean applications."); + Option deleteOpt = new Option(null, OPTION_DELETE_APP, true, + "We will clean up the provided application."); + opts.addOption(deleteOpt); + + // Parse command line arguments. + CommandLine cliParser; + try { + cliParser = new DefaultParser().parse(opts, args); + } catch (MissingArgumentException ex) { + System.out.println("Missing argument for options"); + printUsage(args[0]); + return EXIT_ERROR; + } + + if (cliParser.hasOption(OPTION_DELETE_APP)) { + String application = cliParser.getOptionValue(OPTION_DELETE_APP); + // return handleSavePolicy(policy); + } else { + + } + return 0; + } + @Override public int run(String[] args) throws Exception { YarnConfiguration yarnConf = getConf() == null ? @@ -861,6 +903,8 @@ public int run(String[] args) throws Exception { return handleDeregisterSubCluster(args); } else if (CMD_POLICY.equals(cmd)) { return handlePolicy(args); + } else if (CMD_APPLICATION.equals(cmd)) { + return handleApplication(args); } else { System.out.println("No related commands found."); printHelp(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DeleteFederationApplicationRequestPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DeleteFederationApplicationRequestPBImpl.java new file mode 100644 index 0000000000000..ee11f48cfaeee --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/DeleteFederationApplicationRequestPBImpl.java @@ -0,0 +1,91 @@ +/** + * 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.hadoop.yarn.server.api.protocolrecords.impl.pb; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.hadoop.classification.InterfaceAudience.Private; +import org.apache.hadoop.classification.InterfaceStability.Unstable; +import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.DeleteFederationApplicationRequestProto; +import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.DeleteFederationApplicationRequestProtoOrBuilder; +import org.apache.hadoop.yarn.server.api.protocolrecords.DeleteFederationApplicationRequest; + +@Private +@Unstable +public class DeleteFederationApplicationRequestPBImpl extends DeleteFederationApplicationRequest { + + private DeleteFederationApplicationRequestProto proto = + DeleteFederationApplicationRequestProto.getDefaultInstance(); + private DeleteFederationApplicationRequestProto.Builder builder = null; + private boolean viaProto = false; + + public DeleteFederationApplicationRequestPBImpl() { + builder = DeleteFederationApplicationRequestProto.newBuilder(); + } + + public DeleteFederationApplicationRequestPBImpl(DeleteFederationApplicationRequestProto proto) { + this.proto = proto; + viaProto = true; + } + + private synchronized void maybeInitBuilder() { + if (viaProto || builder == null) { + builder = DeleteFederationApplicationRequestProto.newBuilder(proto); + } + viaProto = false; + } + + public DeleteFederationApplicationRequestProto getProto() { + proto = viaProto ? proto : builder.build(); + viaProto = true; + return proto; + } + + @Override + public int hashCode() { + return getProto().hashCode(); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof DeleteFederationApplicationRequest)) { + return false; + } + DeleteFederationApplicationRequestPBImpl otherImpl = this.getClass().cast(other); + return new EqualsBuilder().append(this.getProto(), otherImpl.getProto()).isEquals(); + } + + @Override + public String getApplication() { + DeleteFederationApplicationRequestProtoOrBuilder p = viaProto ? proto : builder; + boolean hasApplication = p.hasApplication(); + if (hasApplication) { + return p.getApplication(); + } + return null; + } + + @Override + public void setApplication(String application) { + maybeInitBuilder(); + if (application == null) { + builder.clearApplication(); + return; + } + builder.setApplication(application); + } +}