use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class IndexCommands method clearDefinedIndexes.
@CliCommand(value = CliStrings.CLEAR_DEFINED_INDEXES, help = CliStrings.CLEAR_DEFINED__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public // TODO : Add optionContext for indexName
Result clearDefinedIndexes() {
indexDefinitions.clear();
final InfoResultData infoResult = ResultBuilder.createInfoResultData();
infoResult.addLine(CliStrings.CLEAR_DEFINED_INDEX__SUCCESS__MSG);
return ResultBuilder.buildResult(infoResult);
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class LauncherLifecycleCommands method startServer.
@CliCommand(value = CliStrings.START_SERVER, help = CliStrings.START_SERVER__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_SERVER, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result startServer(@CliOption(key = CliStrings.START_SERVER__NAME, help = CliStrings.START_SERVER__NAME__HELP) String memberName, @CliOption(key = CliStrings.START_SERVER__ASSIGN_BUCKETS, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.START_SERVER__ASSIGN_BUCKETS__HELP) final Boolean assignBuckets, @CliOption(key = CliStrings.START_SERVER__BIND_ADDRESS, help = CliStrings.START_SERVER__BIND_ADDRESS__HELP) final String bindAddress, @CliOption(key = CliStrings.START_SERVER__CACHE_XML_FILE, optionContext = ConverterHint.FILE_PATH, help = CliStrings.START_SERVER__CACHE_XML_FILE__HELP) String cacheXmlPathname, @CliOption(key = CliStrings.START_SERVER__CLASSPATH, /* optionContext = ConverterHint.FILE_PATH, // there's an issue with TAB here */
help = CliStrings.START_SERVER__CLASSPATH__HELP) final String classpath, @CliOption(key = CliStrings.START_SERVER__CRITICAL__HEAP__PERCENTAGE, help = CliStrings.START_SERVER__CRITICAL__HEAP__HELP) final Float criticalHeapPercentage, @CliOption(key = CliStrings.START_SERVER__CRITICAL_OFF_HEAP_PERCENTAGE, help = CliStrings.START_SERVER__CRITICAL_OFF_HEAP__HELP) final Float criticalOffHeapPercentage, @CliOption(key = CliStrings.START_SERVER__DIR, help = CliStrings.START_SERVER__DIR__HELP) String workingDirectory, @CliOption(key = CliStrings.START_SERVER__DISABLE_DEFAULT_SERVER, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.START_SERVER__DISABLE_DEFAULT_SERVER__HELP) final Boolean disableDefaultServer, @CliOption(key = CliStrings.START_SERVER__DISABLE_EXIT_WHEN_OUT_OF_MEMORY, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.START_SERVER__DISABLE_EXIT_WHEN_OUT_OF_MEMORY_HELP) final Boolean disableExitWhenOutOfMemory, @CliOption(key = CliStrings.START_SERVER__ENABLE_TIME_STATISTICS, specifiedDefaultValue = "true", help = CliStrings.START_SERVER__ENABLE_TIME_STATISTICS__HELP) final Boolean enableTimeStatistics, @CliOption(key = CliStrings.START_SERVER__EVICTION__HEAP__PERCENTAGE, help = CliStrings.START_SERVER__EVICTION__HEAP__PERCENTAGE__HELP) final Float evictionHeapPercentage, @CliOption(key = CliStrings.START_SERVER__EVICTION_OFF_HEAP_PERCENTAGE, help = CliStrings.START_SERVER__EVICTION_OFF_HEAP_PERCENTAGE__HELP) final Float evictionOffHeapPercentage, @CliOption(key = CliStrings.START_SERVER__FORCE, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.START_SERVER__FORCE__HELP) final Boolean force, @CliOption(key = CliStrings.START_SERVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.START_SERVER__GROUP__HELP) final String group, @CliOption(key = CliStrings.START_SERVER__HOSTNAME__FOR__CLIENTS, help = CliStrings.START_SERVER__HOSTNAME__FOR__CLIENTS__HELP) final String hostNameForClients, @CliOption(key = CliStrings.START_SERVER__INCLUDE_SYSTEM_CLASSPATH, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.START_SERVER__INCLUDE_SYSTEM_CLASSPATH__HELP) final Boolean includeSystemClasspath, @CliOption(key = CliStrings.START_SERVER__INITIAL_HEAP, help = CliStrings.START_SERVER__INITIAL_HEAP__HELP) final String initialHeap, @CliOption(key = CliStrings.START_SERVER__J, optionContext = GfshParser.J_OPTION_CONTEXT, help = CliStrings.START_SERVER__J__HELP) final String[] jvmArgsOpts, @CliOption(key = CliStrings.START_SERVER__LOCATORS, optionContext = ConverterHint.LOCATOR_DISCOVERY_CONFIG, help = CliStrings.START_SERVER__LOCATORS__HELP) final String locators, @CliOption(key = CliStrings.START_SERVER__LOCATOR_WAIT_TIME, help = CliStrings.START_SERVER__LOCATOR_WAIT_TIME_HELP) final Integer locatorWaitTime, @CliOption(key = CliStrings.START_SERVER__LOCK_MEMORY, specifiedDefaultValue = "true", help = CliStrings.START_SERVER__LOCK_MEMORY__HELP) final Boolean lockMemory, @CliOption(key = CliStrings.START_SERVER__LOG_LEVEL, optionContext = ConverterHint.LOG_LEVEL, help = CliStrings.START_SERVER__LOG_LEVEL__HELP) final String logLevel, @CliOption(key = CliStrings.START_SERVER__MAX__CONNECTIONS, help = CliStrings.START_SERVER__MAX__CONNECTIONS__HELP) final Integer maxConnections, @CliOption(key = CliStrings.START_SERVER__MAXHEAP, help = CliStrings.START_SERVER__MAXHEAP__HELP) final String maxHeap, @CliOption(key = CliStrings.START_SERVER__MAX__MESSAGE__COUNT, help = CliStrings.START_SERVER__MAX__MESSAGE__COUNT__HELP) final Integer maxMessageCount, @CliOption(key = CliStrings.START_SERVER__MAX__THREADS, help = CliStrings.START_SERVER__MAX__THREADS__HELP) final Integer maxThreads, @CliOption(key = CliStrings.START_SERVER__MCAST_ADDRESS, help = CliStrings.START_SERVER__MCAST_ADDRESS__HELP) final String mcastBindAddress, @CliOption(key = CliStrings.START_SERVER__MCAST_PORT, help = CliStrings.START_SERVER__MCAST_PORT__HELP) final Integer mcastPort, @CliOption(key = CliStrings.START_SERVER__MEMCACHED_PORT, help = CliStrings.START_SERVER__MEMCACHED_PORT__HELP) final Integer memcachedPort, @CliOption(key = CliStrings.START_SERVER__MEMCACHED_PROTOCOL, help = CliStrings.START_SERVER__MEMCACHED_PROTOCOL__HELP) final String memcachedProtocol, @CliOption(key = CliStrings.START_SERVER__MEMCACHED_BIND_ADDRESS, help = CliStrings.START_SERVER__MEMCACHED_BIND_ADDRESS__HELP) final String memcachedBindAddress, @CliOption(key = CliStrings.START_SERVER__REDIS_PORT, help = CliStrings.START_SERVER__REDIS_PORT__HELP) final Integer redisPort, @CliOption(key = CliStrings.START_SERVER__REDIS_BIND_ADDRESS, help = CliStrings.START_SERVER__REDIS_BIND_ADDRESS__HELP) final String redisBindAddress, @CliOption(key = CliStrings.START_SERVER__REDIS_PASSWORD, help = CliStrings.START_SERVER__REDIS_PASSWORD__HELP) final String redisPassword, @CliOption(key = CliStrings.START_SERVER__MESSAGE__TIME__TO__LIVE, help = CliStrings.START_SERVER__MESSAGE__TIME__TO__LIVE__HELP) final Integer messageTimeToLive, @CliOption(key = CliStrings.START_SERVER__OFF_HEAP_MEMORY_SIZE, help = CliStrings.START_SERVER__OFF_HEAP_MEMORY_SIZE__HELP) final String offHeapMemorySize, @CliOption(key = CliStrings.START_SERVER__PROPERTIES, optionContext = ConverterHint.FILE_PATH, help = CliStrings.START_SERVER__PROPERTIES__HELP) String gemfirePropertiesPathname, @CliOption(key = CliStrings.START_SERVER__REBALANCE, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.START_SERVER__REBALANCE__HELP) final Boolean rebalance, @CliOption(key = CliStrings.START_SERVER__SECURITY_PROPERTIES, optionContext = ConverterHint.FILE_PATH, help = CliStrings.START_SERVER__SECURITY_PROPERTIES__HELP) String gemfireSecurityPropertiesPathname, @CliOption(key = CliStrings.START_SERVER__SERVER_BIND_ADDRESS, unspecifiedDefaultValue = CacheServer.DEFAULT_BIND_ADDRESS, help = CliStrings.START_SERVER__SERVER_BIND_ADDRESS__HELP) final String serverBindAddress, @CliOption(key = CliStrings.START_SERVER__SERVER_PORT, unspecifiedDefaultValue = ("" + CacheServer.DEFAULT_PORT), help = CliStrings.START_SERVER__SERVER_PORT__HELP) final Integer serverPort, @CliOption(key = CliStrings.START_SERVER__SOCKET__BUFFER__SIZE, help = CliStrings.START_SERVER__SOCKET__BUFFER__SIZE__HELP) final Integer socketBufferSize, @CliOption(key = CliStrings.START_SERVER__SPRING_XML_LOCATION, help = CliStrings.START_SERVER__SPRING_XML_LOCATION_HELP) final String springXmlLocation, @CliOption(key = CliStrings.START_SERVER__STATISTIC_ARCHIVE_FILE, help = CliStrings.START_SERVER__STATISTIC_ARCHIVE_FILE__HELP) final String statisticsArchivePathname, @CliOption(key = CliStrings.START_SERVER__USE_CLUSTER_CONFIGURATION, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true", help = CliStrings.START_SERVER__USE_CLUSTER_CONFIGURATION__HELP) final Boolean requestSharedConfiguration, @CliOption(key = CliStrings.START_SERVER__REST_API, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.START_SERVER__REST_API__HELP) final Boolean startRestApi, @CliOption(key = CliStrings.START_SERVER__HTTP_SERVICE_PORT, unspecifiedDefaultValue = "", help = CliStrings.START_SERVER__HTTP_SERVICE_PORT__HELP) final String httpServicePort, @CliOption(key = CliStrings.START_SERVER__HTTP_SERVICE_BIND_ADDRESS, unspecifiedDefaultValue = "", help = CliStrings.START_SERVER__HTTP_SERVICE_BIND_ADDRESS__HELP) final String httpServiceBindAddress, @CliOption(key = CliStrings.START_SERVER__USERNAME, unspecifiedDefaultValue = "", help = CliStrings.START_SERVER__USERNAME__HELP) final String userName, @CliOption(key = START_SERVER__PASSWORD, unspecifiedDefaultValue = "", help = CliStrings.START_SERVER__PASSWORD__HELP) String passwordToUse) // NOTICE: keep the parameters in alphabetical order based on their CliStrings.START_SERVER_* text
{
try {
if (StringUtils.isBlank(memberName)) {
// when the user doesn't give us a name, we make one up!
memberName = nameGenerator.generate('-');
}
// prompt for password is username is specified in the command
if (StringUtils.isNotBlank(userName)) {
if (StringUtils.isBlank(passwordToUse)) {
passwordToUse = getGfsh().readPassword(START_SERVER__PASSWORD + ": ");
}
if (StringUtils.isBlank(passwordToUse)) {
return ResultBuilder.createConnectionErrorResult(CliStrings.START_SERVER__MSG__PASSWORD_MUST_BE_SPECIFIED);
}
}
workingDirectory = resolveWorkingDir(workingDirectory, memberName);
cacheXmlPathname = CliUtil.resolvePathname(cacheXmlPathname);
if (StringUtils.isNotBlank(cacheXmlPathname) && !IOUtils.isExistingPathname(cacheXmlPathname)) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.CACHE_XML_NOT_FOUND_MESSAGE, cacheXmlPathname));
}
gemfirePropertiesPathname = CliUtil.resolvePathname(gemfirePropertiesPathname);
if (StringUtils.isNotBlank(gemfirePropertiesPathname) && !IOUtils.isExistingPathname(gemfirePropertiesPathname)) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, StringUtils.EMPTY, gemfirePropertiesPathname));
}
gemfireSecurityPropertiesPathname = CliUtil.resolvePathname(gemfireSecurityPropertiesPathname);
if (StringUtils.isNotBlank(gemfireSecurityPropertiesPathname) && !IOUtils.isExistingPathname(gemfireSecurityPropertiesPathname)) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, "Security ", gemfireSecurityPropertiesPathname));
}
File serverPidFile = new File(workingDirectory, ProcessType.SERVER.getPidFileName());
final int oldPid = readPid(serverPidFile);
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty(BIND_ADDRESS, StringUtils.defaultString(bindAddress));
gemfireProperties.setProperty(CACHE_XML_FILE, StringUtils.defaultString(cacheXmlPathname));
gemfireProperties.setProperty(ENABLE_TIME_STATISTICS, StringUtils.defaultString(enableTimeStatistics));
gemfireProperties.setProperty(GROUPS, StringUtils.defaultString(group));
gemfireProperties.setProperty(LOCATORS, StringUtils.defaultString(locators));
gemfireProperties.setProperty(LOCATOR_WAIT_TIME, StringUtils.defaultString(locatorWaitTime));
gemfireProperties.setProperty(LOG_LEVEL, StringUtils.defaultString(logLevel));
gemfireProperties.setProperty(MCAST_ADDRESS, StringUtils.defaultString(mcastBindAddress));
gemfireProperties.setProperty(MCAST_PORT, StringUtils.defaultString(mcastPort));
gemfireProperties.setProperty(MEMCACHED_PORT, StringUtils.defaultString(memcachedPort));
gemfireProperties.setProperty(MEMCACHED_PROTOCOL, StringUtils.defaultString(memcachedProtocol));
gemfireProperties.setProperty(MEMCACHED_BIND_ADDRESS, StringUtils.defaultString(memcachedBindAddress));
gemfireProperties.setProperty(REDIS_PORT, StringUtils.defaultString(redisPort));
gemfireProperties.setProperty(REDIS_BIND_ADDRESS, StringUtils.defaultString(redisBindAddress));
gemfireProperties.setProperty(REDIS_PASSWORD, StringUtils.defaultString(redisPassword));
gemfireProperties.setProperty(STATISTIC_ARCHIVE_FILE, StringUtils.defaultString(statisticsArchivePathname));
gemfireProperties.setProperty(USE_CLUSTER_CONFIGURATION, StringUtils.defaultString(requestSharedConfiguration, Boolean.TRUE.toString()));
gemfireProperties.setProperty(LOCK_MEMORY, StringUtils.defaultString(lockMemory));
gemfireProperties.setProperty(OFF_HEAP_MEMORY_SIZE, StringUtils.defaultString(offHeapMemorySize));
gemfireProperties.setProperty(START_DEV_REST_API, StringUtils.defaultString(startRestApi));
gemfireProperties.setProperty(HTTP_SERVICE_PORT, StringUtils.defaultString(httpServicePort));
gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, StringUtils.defaultString(httpServiceBindAddress));
// properties file
if (StringUtils.isNotBlank(userName)) {
gemfireProperties.setProperty(ResourceConstants.USER_NAME, userName);
gemfireProperties.setProperty(ResourceConstants.PASSWORD, passwordToUse);
}
// read the OSProcess enable redirect system property here -- TODO: replace with new GFSH
// argument
final boolean redirectOutput = Boolean.getBoolean(OSProcess.ENABLE_OUTPUT_REDIRECTION_PROPERTY);
ServerLauncher.Builder serverLauncherBuilder = new ServerLauncher.Builder().setAssignBuckets(assignBuckets).setDisableDefaultServer(disableDefaultServer).setForce(force).setRebalance(rebalance).setRedirectOutput(redirectOutput).setServerBindAddress(serverBindAddress).setServerPort(serverPort).setSpringXmlLocation(springXmlLocation).setWorkingDirectory(workingDirectory).setCriticalHeapPercentage(criticalHeapPercentage).setEvictionHeapPercentage(evictionHeapPercentage).setCriticalOffHeapPercentage(criticalOffHeapPercentage).setEvictionOffHeapPercentage(evictionOffHeapPercentage).setMaxConnections(maxConnections).setMaxMessageCount(maxMessageCount).setMaxThreads(maxThreads).setMessageTimeToLive(messageTimeToLive).setSocketBufferSize(socketBufferSize);
if (hostNameForClients != null) {
serverLauncherBuilder.setHostNameForClients(hostNameForClients);
}
if (memberName != null) {
serverLauncherBuilder.setMemberName(memberName);
}
ServerLauncher serverLauncher = serverLauncherBuilder.build();
String[] serverCommandLine = createStartServerCommandLine(serverLauncher, gemfirePropertiesPathname, gemfireSecurityPropertiesPathname, gemfireProperties, classpath, includeSystemClasspath, jvmArgsOpts, disableExitWhenOutOfMemory, initialHeap, maxHeap);
if (getGfsh().getDebug()) {
getGfsh().logInfo(StringUtils.join(serverCommandLine, StringUtils.SPACE), null);
}
Process serverProcess = new ProcessBuilder(serverCommandLine).directory(new File(serverLauncher.getWorkingDirectory())).start();
serverProcess.getInputStream().close();
serverProcess.getOutputStream().close();
// fix TRAC bug #51967 by using NON_BLOCKING on Windows
final ReadingMode readingMode = SystemUtils.isWindows() ? ReadingMode.NON_BLOCKING : ReadingMode.BLOCKING;
// need thread-safe StringBuffer
final StringBuffer message = new StringBuffer();
InputListener inputListener = new InputListener() {
@Override
public void notifyInputLine(String line) {
message.append(line);
if (readingMode == ReadingMode.BLOCKING) {
message.append(StringUtils.LINE_SEPARATOR);
}
}
};
ProcessStreamReader stderrReader = new ProcessStreamReader.Builder(serverProcess).inputStream(serverProcess.getErrorStream()).inputListener(inputListener).readingMode(readingMode).continueReadingMillis(2 * 1000).build().start();
ServerState serverState;
String previousServerStatusMessage = null;
LauncherSignalListener serverSignalListener = new LauncherSignalListener();
final boolean registeredServerSignalListener = getGfsh().getSignalHandler().registerListener(serverSignalListener);
try {
getGfsh().logInfo(String.format(CliStrings.START_SERVER__RUN_MESSAGE, IOUtils.tryGetCanonicalPathElseGetAbsolutePath(new File(serverLauncher.getWorkingDirectory()))), null);
serverState = ServerState.fromDirectory(workingDirectory, memberName);
do {
if (serverProcess.isAlive()) {
Gfsh.print(".");
synchronized (this) {
TimeUnit.MILLISECONDS.timedWait(this, 500);
}
serverState = ServerState.fromDirectory(workingDirectory, memberName);
String currentServerStatusMessage = serverState.getStatusMessage();
if (serverState.isStartingOrNotResponding() && !(StringUtils.isBlank(currentServerStatusMessage) || currentServerStatusMessage.equalsIgnoreCase(previousServerStatusMessage) || currentServerStatusMessage.trim().toLowerCase().equals("null"))) {
Gfsh.println();
Gfsh.println(currentServerStatusMessage);
previousServerStatusMessage = currentServerStatusMessage;
}
} else {
final int exitValue = serverProcess.exitValue();
return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_SERVER__PROCESS_TERMINATED_ABNORMALLY_ERROR_MESSAGE, exitValue, serverLauncher.getWorkingDirectory(), message.toString()));
}
} while (!(registeredServerSignalListener && serverSignalListener.isSignaled()) && serverState.isStartingOrNotResponding());
} finally {
// stop will close
stderrReader.stopAsync(PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS);
// ErrorStream
getGfsh().getSignalHandler().unregisterListener(serverSignalListener);
}
Gfsh.println();
final boolean asyncStart = ServerState.isStartingNotRespondingOrNull(serverState);
if (asyncStart) {
// async start
Gfsh.print(String.format(CliStrings.ASYNC_PROCESS_LAUNCH_MESSAGE, SERVER_TERM_NAME));
return ResultBuilder.createInfoResult("");
} else {
return ResultBuilder.createInfoResult(serverState.toString());
}
} catch (IllegalArgumentException e) {
String message = e.getMessage();
if (message != null && message.matches(LocalizedStrings.Launcher_Builder_UNKNOWN_HOST_ERROR_MESSAGE.toLocalizedString(".+"))) {
message = CliStrings.format(CliStrings.LAUNCHERLIFECYCLECOMMANDS__MSG__FAILED_TO_START_0_REASON_1, SERVER_TERM_NAME, message);
}
return ResultBuilder.createUserErrorResult(message);
} catch (IllegalStateException e) {
return ResultBuilder.createUserErrorResult(e.getMessage());
} catch (ClusterConfigurationNotAvailableException e) {
return ResultBuilder.createShellClientErrorResult(e.getMessage());
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_SERVER__GENERAL_ERROR_MESSAGE, toString(t, getGfsh().getDebug())));
}
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class MiscellaneousCommands method exportStackTrace.
/**
* Current implementation supports writing it to a file and returning the location of the file
*/
@CliCommand(value = CliStrings.EXPORT_STACKTRACE, help = CliStrings.EXPORT_STACKTRACE__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportStackTrace(@CliOption(key = CliStrings.EXPORT_STACKTRACE__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_STACKTRACE__HELP) String[] memberNameOrId, @CliOption(key = CliStrings.EXPORT_STACKTRACE__GROUP, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_STACKTRACE__GROUP) String[] group, @CliOption(key = CliStrings.EXPORT_STACKTRACE__FILE, help = CliStrings.EXPORT_STACKTRACE__FILE__HELP) String fileName, @CliOption(key = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT, unspecifiedDefaultValue = "false", help = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT__HELP) boolean failIfFilePresent) {
Result result = null;
StringBuffer filePrefix = new StringBuffer("stacktrace");
if (fileName == null) {
fileName = filePrefix.append("_").append(System.currentTimeMillis()).toString();
}
final File outFile = new File(fileName);
try {
if (outFile.exists() && failIfFilePresent) {
return ResultBuilder.createShellClientErrorResult(CliStrings.format(CliStrings.EXPORT_STACKTRACE__ERROR__FILE__PRESENT, outFile.getCanonicalPath()));
}
InternalCache cache = getCache();
InternalDistributedSystem ads = cache.getInternalDistributedSystem();
InfoResultData resultData = ResultBuilder.createInfoResultData();
Map<String, byte[]> dumps = new HashMap<String, byte[]>();
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ResultCollector<?, ?> rc = CliUtil.executeFunction(getStackTracesFunction, null, targetMembers);
ArrayList<Object> resultList = (ArrayList<Object>) rc.getResult();
for (Object resultObj : resultList) {
if (resultObj instanceof StackTracesPerMember) {
StackTracesPerMember stackTracePerMember = (StackTracesPerMember) resultObj;
dumps.put(stackTracePerMember.getMemberNameOrId(), stackTracePerMember.getStackTraces());
}
}
String filePath = writeStacksToFile(dumps, fileName);
resultData.addLine(CliStrings.format(CliStrings.EXPORT_STACKTRACE__SUCCESS, filePath));
resultData.addLine(CliStrings.EXPORT_STACKTRACE__HOST + ads.getDistributedMember().getHost());
result = ResultBuilder.buildResult(resultData);
} catch (IOException ex) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.EXPORT_STACKTRACE__ERROR + ex.getMessage());
}
return result;
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class MiscellaneousCommands method changeLogLevel.
@CliCommand(value = CliStrings.CHANGE_LOGLEVEL, help = CliStrings.CHANGE_LOGLEVEL__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_LOGS }, interceptor = "org.apache.geode.management.internal.cli.commands.MiscellaneousCommands$ChangeLogLevelInterceptor")
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.WRITE)
public Result changeLogLevel(@CliOption(key = CliStrings.CHANGE_LOGLEVEL__MEMBER, help = CliStrings.CHANGE_LOGLEVEL__MEMBER__HELP) String[] memberIds, @CliOption(key = CliStrings.CHANGE_LOGLEVEL__GROUPS, unspecifiedDefaultValue = "", help = CliStrings.CHANGE_LOGLEVEL__GROUPS__HELP) String[] grps, @CliOption(key = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL, optionContext = ConverterHint.LOG_LEVEL, mandatory = true, unspecifiedDefaultValue = "", help = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL__HELP) String logLevel) {
try {
if ((memberIds == null || memberIds.length == 0) && (grps == null || grps.length == 0)) {
return ResultBuilder.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__SPECIFY_GRP_OR_MEMBER);
}
InternalCache cache = GemFireCacheImpl.getInstance();
LogWriter logger = cache.getLogger();
Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
Set<DistributedMember> ds = CliUtil.getAllMembers(cache);
if (grps != null && grps.length > 0) {
for (String grp : grps) {
dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
}
}
if (memberIds != null && memberIds.length > 0) {
for (String member : memberIds) {
Iterator<DistributedMember> it = ds.iterator();
while (it.hasNext()) {
DistributedMember mem = it.next();
if (mem.getName() == null ? false : mem.getName().equals(member) || mem.getId().equals(member)) {
dsMembers.add(mem);
break;
}
}
}
}
if (dsMembers.size() == 0) {
return ResultBuilder.createGemFireErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG_NO_MEMBERS);
}
Function logFunction = new ChangeLogLevelFunction();
FunctionService.registerFunction(logFunction);
Object[] functionArgs = new Object[1];
functionArgs[0] = logLevel;
CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
SectionResultData section = compositeResultData.addSection("section");
TabularResultData resultTable = section.addTable("ChangeLogLevel");
resultTable = resultTable.setHeader("Summary");
Execution execution = FunctionService.onMembers(dsMembers).setArguments(functionArgs);
if (execution == null) {
return ResultBuilder.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__CANNOT_EXECUTE);
}
List<?> resultList = (List<?>) execution.execute(logFunction).getResult();
for (Object object : resultList) {
try {
if (object instanceof Throwable) {
logger.warning("Exception in ChangeLogLevelFunction " + ((Throwable) object).getMessage(), ((Throwable) object));
continue;
}
if (object != null) {
Map<String, String> resultMap = (Map<String, String>) object;
Entry<String, String> entry = resultMap.entrySet().iterator().next();
if (entry.getValue().contains("ChangeLogLevelFunction exception")) {
resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, entry.getKey());
resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, "false");
} else {
resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, entry.getKey());
resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, "true");
}
}
} catch (Exception ex) {
LogWrapper.getInstance().warning("change log level command exception " + ex);
continue;
}
}
Result result = ResultBuilder.buildResult(compositeResultData);
logger.info("change log-level command result=" + result);
return result;
} catch (Exception ex) {
GemFireCacheImpl.getInstance().getLogger().error("GFSH Changeloglevel exception: " + ex);
return ResultBuilder.createUserErrorResult(ex.getMessage());
}
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class MiscellaneousCommands method shutdown.
@CliCommand(value = CliStrings.SHUTDOWN, help = CliStrings.SHUTDOWN__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_LIFECYCLE }, interceptor = "org.apache.geode.management.internal.cli.commands.MiscellaneousCommands$Interceptor")
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE)
public Result shutdown(@CliOption(key = CliStrings.SHUTDOWN__TIMEOUT, unspecifiedDefaultValue = DEFAULT_TIME_OUT, help = CliStrings.SHUTDOWN__TIMEOUT__HELP) int userSpecifiedTimeout, @CliOption(key = CliStrings.INCLUDE_LOCATORS, unspecifiedDefaultValue = "false", help = CliStrings.INCLUDE_LOCATORS_HELP) boolean shutdownLocators) {
try {
if (userSpecifiedTimeout < Integer.parseInt(DEFAULT_TIME_OUT)) {
return ResultBuilder.createInfoResult(CliStrings.SHUTDOWN__MSG__IMPROPER_TIMEOUT);
}
// convert to mili-seconds
long timeout = userSpecifiedTimeout * 1000;
InternalCache cache = getCache();
int numDataNodes = CliUtil.getAllNormalMembers(cache).size();
Set<DistributedMember> locators = CliUtil.getAllMembers(cache);
Set<DistributedMember> dataNodes = CliUtil.getAllNormalMembers(cache);
locators.removeAll(dataNodes);
if (!shutdownLocators && numDataNodes == 0) {
return ResultBuilder.createInfoResult(CliStrings.SHUTDOWN__MSG__NO_DATA_NODE_FOUND);
}
String managerName = cache.getJmxManagerAdvisor().getDistributionManager().getId().getId();
final DistributedMember manager = CliUtil.getDistributedMemberByNameOrId(managerName);
dataNodes.remove(manager);
// shut down all data members excluding this manager if manager is a data node
long timeElapsed = shutDownNodeWithTimeOut(timeout, dataNodes);
timeout = timeout - timeElapsed;
// shut down locators one by one
if (shutdownLocators) {
if (manager == null) {
return ResultBuilder.createUserErrorResult(CliStrings.SHUTDOWN__MSG__MANAGER_NOT_FOUND);
}
// remove current locator as that would get shutdown last
if (locators.contains(manager)) {
locators.remove(manager);
}
for (DistributedMember locator : locators) {
Set<DistributedMember> lsSet = new HashSet<DistributedMember>();
lsSet.add(locator);
long elapsedTime = shutDownNodeWithTimeOut(timeout, lsSet);
timeout = timeout - elapsedTime;
}
}
if (locators.contains(manager) && !shutdownLocators) {
// should not stop the manager
return ResultBuilder.createInfoResult("Shutdown is triggered");
}
// now shut down this manager
Set<DistributedMember> mgrSet = new HashSet<DistributedMember>();
mgrSet.add(manager);
// No need to check further timeout as this is the last node we will be
// shutting down
shutDownNodeWithTimeOut(timeout, mgrSet);
} catch (TimeoutException tex) {
return ResultBuilder.createInfoResult(CliStrings.SHUTDOWN_TIMEDOUT);
} catch (Exception ex) {
ex.printStackTrace();
return ResultBuilder.createUserErrorResult(ex.getMessage());
}
// @TODO. List all the nodes which could be successfully shutdown
return ResultBuilder.createInfoResult("Shutdown is triggered");
}
Aggregations