Skip to content

Commit

Permalink
YARN-11483. Fix CheckStyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 committed Nov 4, 2023
1 parent c9e5a2b commit ea90937
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ////////////////////////
//////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, RouterCmdUsageInfos> ADMIN_USAGE =
ImmutableMap.<String, RouterCmdUsageInfos>builder()
// Command1: deregisterSubCluster
Expand Down Expand Up @@ -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 ?
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit ea90937

Please sign in to comment.