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

Transform commands of pkg klass100 #1285

Merged
merged 18 commits into from
Jul 10, 2020
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
Expand Up @@ -6,12 +6,13 @@
import com.taobao.arthas.core.command.model.ChangeResultVO;
import com.taobao.arthas.core.command.model.OptionVO;
import com.taobao.arthas.core.command.model.OptionsModel;
import com.taobao.arthas.core.command.model.StatusModel;
import com.taobao.arthas.core.shell.cli.CliToken;
import com.taobao.arthas.core.shell.cli.Completion;
import com.taobao.arthas.core.shell.cli.CompletionUtils;
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
import com.taobao.arthas.core.shell.command.CommandProcess;
import com.taobao.arthas.core.shell.command.ExitStatus;
import com.taobao.arthas.core.util.CommandUtils;
import com.taobao.arthas.core.util.StringUtils;
import com.taobao.arthas.core.util.TokenUtils;
import com.taobao.arthas.core.util.matcher.EqualsMatcher;
Expand Down Expand Up @@ -70,23 +71,19 @@ public void setOptionValue(String optionValue) {
@Override
public void process(CommandProcess process) {
try {
StatusModel statusModel = null;
ExitStatus status = null;
if (isShow()) {
statusModel = processShow(process);
status = processShow(process);
} else if (isShowName()) {
statusModel = processShowName(process);
status = processShowName(process);
} else {
statusModel = processChangeNameValue(process);
status = processChangeNameValue(process);
}

if (statusModel != null) {
process.end(statusModel.getStatusCode(), statusModel.getMessage());
} else {
process.end(-1, "command was not processed");
}
CommandUtils.end(process, status);
} catch (Throwable t) {
logger.error("process options command error", t);
process.end(-1, "process options command error");
logger.error("processing error", t);
process.end(-1, "processing error");
}
}

Expand All @@ -110,24 +107,24 @@ public void complete(Completion completion) {
}
}

private StatusModel processShow(CommandProcess process) throws IllegalAccessException {
private ExitStatus processShow(CommandProcess process) throws IllegalAccessException {
Collection<Field> fields = findOptionFields(new RegexMatcher(".*"));
process.appendResult(new OptionsModel(convertToOptionVOs(fields)));
return StatusModel.success();
return ExitStatus.success();
}

private StatusModel processShowName(CommandProcess process) throws IllegalAccessException {
private ExitStatus processShowName(CommandProcess process) throws IllegalAccessException {
Collection<Field> fields = findOptionFields(new EqualsMatcher<String>(optionName));
process.appendResult(new OptionsModel(convertToOptionVOs(fields)));
return StatusModel.success();
return ExitStatus.success();
}

private StatusModel processChangeNameValue(CommandProcess process) throws IllegalAccessException {
private ExitStatus processChangeNameValue(CommandProcess process) throws IllegalAccessException {
Collection<Field> fields = findOptionFields(new EqualsMatcher<String>(optionName));

// name not exists
if (fields.isEmpty()) {
return StatusModel.failure(-1, format("options[%s] not found.", optionName));
return ExitStatus.failure(-1, format("options[%s] not found.", optionName));
}

Field field = fields.iterator().next();
Expand Down Expand Up @@ -155,16 +152,16 @@ private StatusModel processChangeNameValue(CommandProcess process) throws Illega
} else if (isIn(type, short.class, String.class)) {
FieldUtils.writeStaticField(field, afterValue = optionValue);
} else {
return StatusModel.failure(-1, format("Options[%s] type[%s] was unsupported.", optionName, type.getSimpleName()));
return ExitStatus.failure(-1, format("Options[%s] type[%s] was unsupported.", optionName, type.getSimpleName()));
}

} catch (Throwable t) {
return StatusModel.failure(-1, format("Cannot cast option value[%s] to type[%s].", optionValue, type.getSimpleName()));
return ExitStatus.failure(-1, format("Cannot cast option value[%s] to type[%s].", optionValue, type.getSimpleName()));
}

ChangeResultVO changeResultVO = new ChangeResultVO(optionAnnotation.name(), beforeValue, afterValue);
process.appendResult(new OptionsModel(changeResultVO));
return StatusModel.success();
return ExitStatus.success();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public void process(CommandProcess process) {
try {
EnhancerAffect enhancerAffect = Enhancer.reset(inst, matcher);
process.appendResult(new ResetModel(enhancerAffect));
process.end();
} catch (UnmodifiableClassException e) {
// ignore
} finally {
process.end();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ public void process(CommandProcess process) {
result.put(envName, value);
}
process.appendResult(result);
process.end();
} catch (Throwable t) {
process.end(-1, "Error during setting system env: " + t.getMessage());
} finally {
process.end();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.command.model.MessageModel;
import com.taobao.arthas.core.command.model.StatusModel;
import com.taobao.arthas.core.command.model.SystemPropertyModel;
import com.taobao.arthas.core.shell.cli.Completion;
import com.taobao.arthas.core.shell.cli.CompletionUtils;
Expand Down Expand Up @@ -60,10 +59,9 @@ public void process(CommandProcess process) {
process.appendResult(new MessageModel("Successfully changed the system property."));
process.appendResult(new SystemPropertyModel(propertyName, System.getProperty(propertyName)));
}
process.end();
} catch (Throwable t) {
process.end(-1, "Error during setting system property: " + t.getMessage());
} finally {
process.end();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private static void run(CommandProcess process, String name, String value) {
VMOption option = hotSpotDiagnosticMXBean.getVMOption(name);
if (option == null) {
process.end(-1, "In order to change the system properties, you must specify the property value.");
return;
} else {
process.appendResult(new VMOptionModel(Arrays.asList(option)));
}
Expand All @@ -82,11 +83,10 @@ private static void run(CommandProcess process, String name, String value) {
process.appendResult(new VMOptionModel(new ChangeResultVO(name, originValue,
hotSpotDiagnosticMXBean.getVMOption(name).getValue())));
}
process.end();
} catch (Throwable t) {
logger.error("Error during setting vm option", t);
process.end(-1, "Error during setting vm option: " + t.getMessage());
} finally {
process.end();
}
}

Expand Down
Loading