use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.
the class DiskStoreCommands method backupDiskStore.
@CliCommand(value = CliStrings.BACKUP_DISK_STORE, help = CliStrings.BACKUP_DISK_STORE__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
@ResourceOperation(resource = Resource.DATA, operation = Operation.READ)
public Result backupDiskStore(@CliOption(key = CliStrings.BACKUP_DISK_STORE__DISKDIRS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.BACKUP_DISK_STORE__DISKDIRS__HELP, mandatory = true) String targetDir, @CliOption(key = CliStrings.BACKUP_DISK_STORE__BASELINEDIR, help = CliStrings.BACKUP_DISK_STORE__BASELINEDIR__HELP) String baselineDir) {
Result result = null;
try {
InternalCache cache = getCache();
DM dm = cache.getDistributionManager();
BackupStatus backupStatus = null;
if (baselineDir != null && !baselineDir.isEmpty()) {
backupStatus = AdminDistributedSystemImpl.backupAllMembers(dm, new File(targetDir), new File(baselineDir));
} else {
backupStatus = AdminDistributedSystemImpl.backupAllMembers(dm, new File(targetDir), null);
}
Map<DistributedMember, Set<PersistentID>> backedupMemberDiskstoreMap = backupStatus.getBackedUpDiskStores();
Set<DistributedMember> backedupMembers = backedupMemberDiskstoreMap.keySet();
CompositeResultData crd = ResultBuilder.createCompositeResultData();
if (!backedupMembers.isEmpty()) {
SectionResultData backedupDiskStoresSection = crd.addSection();
backedupDiskStoresSection.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_BACKED_UP_DISK_STORES);
TabularResultData backedupDiskStoresTable = backedupDiskStoresSection.addTable();
for (DistributedMember member : backedupMembers) {
Set<PersistentID> backedupDiskStores = backedupMemberDiskstoreMap.get(member);
boolean printMember = true;
String memberName = member.getName();
if (memberName == null || memberName.isEmpty()) {
memberName = member.getId();
}
for (PersistentID persistentId : backedupDiskStores) {
if (persistentId != null) {
String UUID = persistentId.getUUID().toString();
String hostName = persistentId.getHost().getHostName();
String directory = persistentId.getDirectory();
if (printMember) {
writeToBackupDisktoreTable(backedupDiskStoresTable, memberName, UUID, hostName, directory);
printMember = false;
} else {
writeToBackupDisktoreTable(backedupDiskStoresTable, "", UUID, hostName, directory);
}
}
}
}
} else {
SectionResultData noMembersBackedUp = crd.addSection();
noMembersBackedUp.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_NO_DISKSTORES_BACKED_UP);
}
Set<PersistentID> offlineDiskStores = backupStatus.getOfflineDiskStores();
if (!offlineDiskStores.isEmpty()) {
SectionResultData offlineDiskStoresSection = crd.addSection();
TabularResultData offlineDiskStoresTable = offlineDiskStoresSection.addTable();
offlineDiskStoresSection.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_OFFLINE_DISK_STORES);
for (PersistentID offlineDiskStore : offlineDiskStores) {
offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_UUID, offlineDiskStore.getUUID().toString());
offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_HOST, offlineDiskStore.getHost().getHostName());
offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_DIRECTORY, offlineDiskStore.getDirectory());
}
}
result = ResultBuilder.buildResult(crd);
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.
the class DiskStoreCommands method createDiskStore.
@CliCommand(value = CliStrings.CREATE_DISK_STORE, help = CliStrings.CREATE_DISK_STORE__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result createDiskStore(@CliOption(key = CliStrings.CREATE_DISK_STORE__NAME, mandatory = true, optionContext = ConverterHint.DISKSTORE, help = CliStrings.CREATE_DISK_STORE__NAME__HELP) String name, @CliOption(key = CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION__HELP) boolean allowForceCompaction, @CliOption(key = CliStrings.CREATE_DISK_STORE__AUTO_COMPACT, specifiedDefaultValue = "true", unspecifiedDefaultValue = "true", help = CliStrings.CREATE_DISK_STORE__AUTO_COMPACT__HELP) boolean autoCompact, @CliOption(key = CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD, unspecifiedDefaultValue = "50", help = CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD__HELP) int compactionThreshold, @CliOption(key = CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE, unspecifiedDefaultValue = "1024", help = CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE__HELP) int maxOplogSize, @CliOption(key = CliStrings.CREATE_DISK_STORE__QUEUE_SIZE, unspecifiedDefaultValue = "0", help = CliStrings.CREATE_DISK_STORE__QUEUE_SIZE__HELP) int queueSize, @CliOption(key = CliStrings.CREATE_DISK_STORE__TIME_INTERVAL, unspecifiedDefaultValue = "1000", help = CliStrings.CREATE_DISK_STORE__TIME_INTERVAL__HELP) long timeInterval, @CliOption(key = CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE, unspecifiedDefaultValue = "32768", help = CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE__HELP) int writeBufferSize, @CliOption(key = CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, mandatory = true, help = CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE__HELP) String[] directoriesAndSizes, @CliOption(key = CliStrings.CREATE_DISK_STORE__GROUP, help = CliStrings.CREATE_DISK_STORE__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) String[] groups, @CliOption(key = CliStrings.CREATE_DISK_STORE__DISK_USAGE_WARNING_PCT, unspecifiedDefaultValue = "90", help = CliStrings.CREATE_DISK_STORE__DISK_USAGE_WARNING_PCT__HELP) float diskUsageWarningPercentage, @CliOption(key = CliStrings.CREATE_DISK_STORE__DISK_USAGE_CRITICAL_PCT, unspecifiedDefaultValue = "99", help = CliStrings.CREATE_DISK_STORE__DISK_USAGE_CRITICAL_PCT__HELP) float diskUsageCriticalPercentage) {
try {
DiskStoreAttributes diskStoreAttributes = new DiskStoreAttributes();
diskStoreAttributes.allowForceCompaction = allowForceCompaction;
diskStoreAttributes.autoCompact = autoCompact;
diskStoreAttributes.compactionThreshold = compactionThreshold;
diskStoreAttributes.maxOplogSizeInBytes = maxOplogSize * (1024 * 1024);
diskStoreAttributes.queueSize = queueSize;
diskStoreAttributes.timeInterval = timeInterval;
diskStoreAttributes.writeBufferSize = writeBufferSize;
File[] directories = new File[directoriesAndSizes.length];
int[] sizes = new int[directoriesAndSizes.length];
for (int i = 0; i < directoriesAndSizes.length; i++) {
final int hashPosition = directoriesAndSizes[i].indexOf('#');
if (hashPosition == -1) {
directories[i] = new File(directoriesAndSizes[i]);
sizes[i] = Integer.MAX_VALUE;
} else {
directories[i] = new File(directoriesAndSizes[i].substring(0, hashPosition));
sizes[i] = Integer.parseInt(directoriesAndSizes[i].substring(hashPosition + 1));
}
}
diskStoreAttributes.diskDirs = directories;
diskStoreAttributes.diskDirSizes = sizes;
diskStoreAttributes.setDiskUsageWarningPercentage(diskUsageWarningPercentage);
diskStoreAttributes.setDiskUsageCriticalPercentage(diskUsageCriticalPercentage);
TabularResultData tabularData = ResultBuilder.createTabularResultData();
boolean accumulatedData = false;
Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, null);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ResultCollector<?, ?> rc = CliUtil.executeFunction(new CreateDiskStoreFunction(), new Object[] { name, diskStoreAttributes }, targetMembers);
List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
for (CliFunctionResult result : results) {
if (result.getThrowable() != null) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("Result", "ERROR: " + result.getThrowable().getClass().getName() + ": " + result.getThrowable().getMessage());
accumulatedData = true;
tabularData.setStatus(Status.ERROR);
} else if (result.isSuccessful()) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("Result", result.getMessage());
accumulatedData = true;
if (xmlEntity.get() == null) {
xmlEntity.set(result.getXmlEntity());
}
}
}
if (!accumulatedData) {
return ResultBuilder.createInfoResult("Unable to create disk store(s).");
}
Result result = ResultBuilder.buildResult(tabularData);
if (xmlEntity.get() != null) {
persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
}
return ResultBuilder.buildResult(tabularData);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.CREATE_DISK_STORE__ERROR_WHILE_CREATING_REASON_0, new Object[] { th.getMessage() }));
}
}
use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.
the class MemberCommands method listMember.
@CliCommand(value = { CliStrings.LIST_MEMBER }, help = CliStrings.LIST_MEMBER__HELP)
@CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listMember(@CliOption(key = { CliStrings.LIST_MEMBER__GROUP }, unspecifiedDefaultValue = "", optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_MEMBER__GROUP__HELP) String group) {
Result result = null;
// TODO: Add the code for identifying the system services
try {
Set<DistributedMember> memberSet = new TreeSet<DistributedMember>();
InternalCache cache = getCache();
// default get all the members in the DS
if (group.isEmpty()) {
memberSet.addAll(CliUtil.getAllMembers(cache));
} else {
memberSet.addAll(cache.getDistributedSystem().getGroupMembers(group));
}
if (memberSet.isEmpty()) {
result = ResultBuilder.createInfoResult(CliStrings.LIST_MEMBER__MSG__NO_MEMBER_FOUND);
} else {
TabularResultData resultData = ResultBuilder.createTabularResultData();
Iterator<DistributedMember> memberIters = memberSet.iterator();
while (memberIters.hasNext()) {
DistributedMember member = memberIters.next();
resultData.accumulate("Name", member.getName());
resultData.accumulate("Id", member.getId());
}
result = ResultBuilder.buildResult(resultData);
}
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult("Could not fetch the list of members. " + e.getMessage());
LogWrapper.getInstance().warning(e.getMessage(), e);
}
return result;
}
use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.
the class MemberCommands method describeMember.
@CliCommand(value = { CliStrings.DESCRIBE_MEMBER }, help = CliStrings.DESCRIBE_MEMBER__HELP)
@CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeMember(@CliOption(key = CliStrings.DESCRIBE_MEMBER__IDENTIFIER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_MEMBER__HELP, mandatory = true) String memberNameOrId) {
Result result = null;
try {
DistributedMember memberToBeDescribed = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
if (memberToBeDescribed != null) {
// This information should be available through the MBeans too. We might not need
// the function.
// Yes, but then the command is subject to Mbean availability, which would be
// affected once MBean filters are used.
ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberInformation, null, memberToBeDescribed);
ArrayList<?> output = (ArrayList<?>) rc.getResult();
Object obj = output.get(0);
if (obj != null && (obj instanceof MemberInformation)) {
CompositeResultData crd = ResultBuilder.createCompositeResultData();
MemberInformation memberInformation = (MemberInformation) obj;
memberInformation.setName(memberToBeDescribed.getName());
memberInformation.setId(memberToBeDescribed.getId());
memberInformation.setHost(memberToBeDescribed.getHost());
memberInformation.setProcessId("" + memberToBeDescribed.getProcessId());
SectionResultData section = crd.addSection();
section.addData("Name", memberInformation.getName());
section.addData("Id", memberInformation.getId());
section.addData("Host", memberInformation.getHost());
section.addData("Regions", CliUtil.convertStringSetToString(memberInformation.getHostedRegions(), '\n'));
section.addData("PID", memberInformation.getProcessId());
section.addData("Groups", memberInformation.getGroups());
section.addData("Used Heap", memberInformation.getHeapUsage() + "M");
section.addData("Max Heap", memberInformation.getMaxHeapSize() + "M");
String offHeapMemorySize = memberInformation.getOffHeapMemorySize();
if (offHeapMemorySize != null && !offHeapMemorySize.isEmpty()) {
section.addData("Off Heap Size", offHeapMemorySize);
}
section.addData("Working Dir", memberInformation.getWorkingDirPath());
section.addData("Log file", memberInformation.getLogFilePath());
section.addData("Locators", memberInformation.getLocators());
if (memberInformation.isServer()) {
SectionResultData clientServiceSection = crd.addSection();
List<CacheServerInfo> csList = memberInformation.getCacheServeInfo();
if (csList != null) {
Iterator<CacheServerInfo> iters = csList.iterator();
clientServiceSection.setHeader("Cache Server Information");
while (iters.hasNext()) {
CacheServerInfo cacheServerInfo = iters.next();
clientServiceSection.addData("Server Bind", cacheServerInfo.getBindAddress());
clientServiceSection.addData("Server Port", cacheServerInfo.getPort());
clientServiceSection.addData("Running", cacheServerInfo.isRunning());
}
clientServiceSection.addData("Client Connections", memberInformation.getClientCount());
}
}
result = ResultBuilder.buildResult(crd);
} else {
result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESCRIBE_MEMBER__MSG__INFO_FOR__0__COULD_NOT_BE_RETRIEVED, new Object[] { memberNameOrId }));
}
} else {
result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESCRIBE_MEMBER__MSG__NOT_FOUND, new Object[] { memberNameOrId }));
}
} catch (CacheClosedException e) {
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.
the class MiscellaneousCommands method gc.
@CliCommand(value = CliStrings.GC, help = CliStrings.GC__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE)
public Result gc(@CliOption(key = CliStrings.GC__GROUP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.GC__GROUP__HELP) String[] groups, @CliOption(key = CliStrings.GC__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.GC__MEMBER__HELP) String memberId) {
InternalCache cache = getCache();
Result result = null;
CompositeResultData gcResultTable = ResultBuilder.createCompositeResultData();
TabularResultData resultTable = gcResultTable.addSection().addTable("Table1");
String headerText = "GC Summary";
resultTable.setHeader(headerText);
Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
if (memberId != null && memberId.length() > 0) {
DistributedMember member = CliUtil.getDistributedMemberByNameOrId(memberId);
if (member == null) {
return ResultBuilder.createGemFireErrorResult(memberId + CliStrings.GC__MSG__MEMBER_NOT_FOUND);
}
dsMembers.add(member);
result = executeAndBuildResult(resultTable, dsMembers);
} else if (groups != null && groups.length > 0) {
for (String group : groups) {
dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(group));
}
result = executeAndBuildResult(resultTable, dsMembers);
} else {
// gc on entire cluster
// exclude locators
dsMembers = CliUtil.getAllNormalMembers(cache);
result = executeAndBuildResult(resultTable, dsMembers);
}
return result;
}
Aggregations