Search in sources :

Example 26 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class DataCommands method remove.

@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@CliCommand(value = { CliStrings.REMOVE }, help = CliStrings.REMOVE__HELP)
public Result remove(@CliOption(key = { CliStrings.REMOVE__KEY }, help = CliStrings.REMOVE__KEY__HELP, specifiedDefaultValue = "") String key, @CliOption(key = { CliStrings.REMOVE__REGION }, mandatory = true, help = CliStrings.REMOVE__REGION__HELP, optionContext = ConverterHint.REGION_PATH) String regionPath, @CliOption(key = CliStrings.REMOVE__ALL, help = CliStrings.REMOVE__ALL__HELP, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean removeAllKeys, @CliOption(key = { CliStrings.REMOVE__KEYCLASS }, help = CliStrings.REMOVE__KEYCLASS__HELP) String keyClass) {
    InternalCache cache = getCache();
    DataCommandResult dataResult;
    if (StringUtils.isEmpty(regionPath)) {
        return makePresentationResult(DataCommandResult.createRemoveResult(key, null, null, CliStrings.REMOVE__MSG__REGIONNAME_EMPTY, false));
    }
    if (!removeAllKeys && (key == null)) {
        return makePresentationResult(DataCommandResult.createRemoveResult(null, null, null, CliStrings.REMOVE__MSG__KEY_EMPTY, false));
    }
    if (removeAllKeys) {
        this.securityService.authorizeRegionWrite(regionPath);
    } else {
        this.securityService.authorizeRegionWrite(regionPath, key);
    }
    @SuppressWarnings("rawtypes") Region region = cache.getRegion(regionPath);
    DataCommandFunction removefn = new DataCommandFunction();
    if (region == null) {
        Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), false);
        if (CollectionUtils.isNotEmpty(memberList)) {
            DataCommandRequest request = new DataCommandRequest();
            request.setCommand(CliStrings.REMOVE);
            request.setKey(key);
            request.setKeyClass(keyClass);
            request.setRemoveAllKeys(removeAllKeys ? "ALL" : null);
            request.setRegionName(regionPath);
            dataResult = callFunctionForRegion(request, removefn, memberList);
        } else {
            dataResult = DataCommandResult.createRemoveInfoResult(key, null, null, CliStrings.format(CliStrings.REMOVE__MSG__REGION_NOT_FOUND_ON_ALL_MEMBERS, regionPath), false);
        }
    } else {
        dataResult = removefn.remove(key, keyClass, regionPath, removeAllKeys ? "ALL" : null);
    }
    dataResult.setKeyClass(keyClass);
    return makePresentationResult(dataResult);
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) Region(org.apache.geode.cache.Region) DataCommandRequest(org.apache.geode.management.internal.cli.domain.DataCommandRequest) DataCommandResult(org.apache.geode.management.internal.cli.domain.DataCommandResult) DataCommandFunction(org.apache.geode.management.internal.cli.functions.DataCommandFunction) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 27 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class DiskStoreCommands method alterOfflineDiskStore.

@CliCommand(value = CliStrings.ALTER_DISK_STORE, help = CliStrings.ALTER_DISK_STORE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
public Result alterOfflineDiskStore(@CliOption(key = CliStrings.ALTER_DISK_STORE__DISKSTORENAME, mandatory = true, help = CliStrings.ALTER_DISK_STORE__DISKSTORENAME__HELP) String diskStoreName, @CliOption(key = CliStrings.ALTER_DISK_STORE__REGIONNAME, mandatory = true, help = CliStrings.ALTER_DISK_STORE__REGIONNAME__HELP) String regionName, @CliOption(key = CliStrings.ALTER_DISK_STORE__DISKDIRS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__DISKDIRS__HELP, mandatory = true) String[] diskDirs, @CliOption(key = CliStrings.ALTER_DISK_STORE__COMPRESSOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "none", help = CliStrings.ALTER_DISK_STORE__COMPRESSOR__HELP) String compressorClassName, @CliOption(key = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL__HELP) Integer concurrencyLevel, @CliOption(key = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED__HELP) Boolean statisticsEnabled, @CliOption(key = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY__HELP) Integer initialCapacity, @CliOption(key = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR__HELP) Float loadFactor, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION__HELP) String lruEvictionAction, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM__HELP) String lruEvictionAlgo, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT__HELP) Integer lruEvictionLimit, @CliOption(key = CliStrings.ALTER_DISK_STORE__OFF_HEAP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__OFF_HEAP__HELP) Boolean offHeap, @CliOption(key = CliStrings.ALTER_DISK_STORE__REMOVE, help = CliStrings.ALTER_DISK_STORE__REMOVE__HELP, mandatory = false, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean remove) {
    Result result = null;
    try {
        File[] dirs = null;
        if (diskDirs != null) {
            dirs = new File[diskDirs.length];
            for (int i = 0; i < diskDirs.length; i++) {
                dirs[i] = new File((diskDirs[i]));
            }
        }
        if (regionName.equals(Region.SEPARATOR)) {
            return ResultBuilder.createUserErrorResult(CliStrings.INVALID_REGION_NAME);
        }
        if ((lruEvictionAlgo != null) || (lruEvictionAction != null) || (lruEvictionLimit != null) || (concurrencyLevel != null) || (initialCapacity != null) || (loadFactor != null) || (compressorClassName != null) || (offHeap != null) || (statisticsEnabled != null)) {
            if (!remove) {
                String lruEvictionLimitString = lruEvictionLimit == null ? null : lruEvictionLimit.toString();
                String concurrencyLevelString = concurrencyLevel == null ? null : concurrencyLevel.toString();
                String initialCapacityString = initialCapacity == null ? null : initialCapacity.toString();
                String loadFactorString = loadFactor == null ? null : loadFactor.toString();
                String statisticsEnabledString = statisticsEnabled == null ? null : statisticsEnabled.toString();
                String offHeapString = offHeap == null ? null : offHeap.toString();
                if ("none".equals(compressorClassName)) {
                    compressorClassName = "";
                }
                String resultMessage = DiskStoreImpl.modifyRegion(diskStoreName, dirs, "/" + regionName, lruEvictionAlgo, lruEvictionAction, lruEvictionLimitString, concurrencyLevelString, initialCapacityString, loadFactorString, compressorClassName, statisticsEnabledString, offHeapString, false);
                result = ResultBuilder.createInfoResult(resultMessage);
            } else {
                result = ResultBuilder.createParsingErrorResult("Cannot use the --remove=true parameter with any other parameters");
            }
        } else {
            if (remove) {
                DiskStoreImpl.destroyRegion(diskStoreName, dirs, "/" + regionName);
                result = ResultBuilder.createInfoResult("The region " + regionName + " was successfully removed from the disk store " + diskStoreName);
            } else {
                // Please provide an option
                result = ResultBuilder.createParsingErrorResult("Please provide a relevant parameter");
            }
        }
    // Catch the IllegalArgumentException thrown by the modifyDiskStore function and sent the
    } catch (IllegalArgumentException e) {
        String message = "Please check the parameters";
        message += "\n" + e.getMessage();
        result = ResultBuilder.createGemFireErrorResult(message);
    } catch (IllegalStateException e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    } catch (CacheExistsException e) {
        // Indicates that the command is being used when a cache is open
        result = ResultBuilder.createGemFireErrorResult("Cannot execute " + CliStrings.ALTER_DISK_STORE + " when a cache exists (Offline command)");
    } catch (Exception e) {
        result = createErrorResult(e.getMessage());
    }
    return result;
}
Also used : CacheExistsException(org.apache.geode.cache.CacheExistsException) File(java.io.File) ConverterHint(org.apache.geode.management.cli.ConverterHint) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) CacheExistsException(org.apache.geode.cache.CacheExistsException) MemberNotFoundException(org.apache.geode.management.internal.cli.util.MemberNotFoundException) DiskStoreNotFoundException(org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 28 with CliCommand

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) DM(org.apache.geode.distributed.internal.DM) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) CacheExistsException(org.apache.geode.cache.CacheExistsException) MemberNotFoundException(org.apache.geode.management.internal.cli.util.MemberNotFoundException) DiskStoreNotFoundException(org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) File(java.io.File) BackupStatus(org.apache.geode.admin.BackupStatus) PersistentID(org.apache.geode.cache.persistence.PersistentID) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 29 with CliCommand

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() }));
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConverterHint(org.apache.geode.management.cli.ConverterHint) CreateDiskStoreFunction(org.apache.geode.management.internal.cli.functions.CreateDiskStoreFunction) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) DiskStoreAttributes(org.apache.geode.internal.cache.DiskStoreAttributes) File(java.io.File) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 30 with CliCommand

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;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) TreeSet(java.util.TreeSet) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Result(org.apache.geode.management.cli.Result) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

CliCommand (org.springframework.shell.core.annotation.CliCommand)100 CliMetaData (org.apache.geode.management.cli.CliMetaData)94 Result (org.apache.geode.management.cli.Result)66 DistributedMember (org.apache.geode.distributed.DistributedMember)60 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)58 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)42 InternalCache (org.apache.geode.internal.cache.InternalCache)37 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)35 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)31 ArrayList (java.util.ArrayList)29 List (java.util.List)24 ConverterHint (org.apache.geode.management.cli.ConverterHint)24 IOException (java.io.IOException)20 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)17 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)16 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)16 ExecutionException (java.util.concurrent.ExecutionException)15 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)15 HashSet (java.util.HashSet)14 ObjectName (javax.management.ObjectName)14