Search in sources :

Example 6 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class GemfireDataCommandsDUnitTest method validateResult.

private void validateResult(CommandResult cmdResult, boolean expected) {
    if (ResultData.TYPE_COMPOSITE.equals(cmdResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
        SectionResultData section = rd.retrieveSectionByIndex(0);
        boolean result = (Boolean) section.retrieveObject("Result");
        assertEquals(expected, result);
    } else
        fail("Expected CompositeResult Returned Result Type " + cmdResult.getType());
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 7 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class GemfireDataCommandsDUnitTest method validateSelectResult.

private void validateSelectResult(CommandResult cmdResult, boolean expectedFlag, int expectedRows, String[] cols) {
    if (ResultData.TYPE_COMPOSITE.equals(cmdResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
        SectionResultData section = rd.retrieveSectionByIndex(0);
        boolean result = (Boolean) section.retrieveObject("Result");
        assertEquals(expectedFlag, result);
        if (expectedFlag && expectedRows != -1) {
            int rowsReturned = (Integer) section.retrieveObject("Rows");
            assertEquals(expectedRows, rowsReturned);
            if (rowsReturned > 0 && cols != null) {
                try {
                    TabularResultData table = section.retrieveTableByIndex(0);
                    GfJsonArray array = table.getHeaders();
                    assertEquals(cols.length, array.size());
                    for (String col : cols) {
                        boolean found = false;
                        getLogWriter().info("Validating column " + col);
                        for (int i = 0; i < array.size(); i++) {
                            String header = (String) array.get(i);
                            if (col.equals(header))
                                found = true;
                        }
                        assertEquals(true, found);
                    }
                } catch (GfJsonException e) {
                    fail("Error accessing table data", e);
                }
            }
        }
    } else
        fail("Expected CompositeResult Returned Result Type " + cmdResult.getType());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 8 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class GemfireDataCommandsDUnitTest method validateLocationsResult.

private void validateLocationsResult(CommandResult cmdResult, int expected) {
    if (ResultData.TYPE_COMPOSITE.equals(cmdResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
        SectionResultData section = rd.retrieveSectionByIndex(0);
        int result = (Integer) section.retrieveObject("Locations Found");
        assertEquals(expected, result);
    } else
        fail("Expected CompositeResult Returned Result Type " + cmdResult.getType());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 9 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData 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 10 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData 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;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) ArrayList(java.util.ArrayList) CacheClosedException(org.apache.geode.cache.CacheClosedException) CacheServerInfo(org.apache.geode.management.internal.cli.domain.CacheServerInfo) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Result(org.apache.geode.management.cli.Result) MemberInformation(org.apache.geode.management.internal.cli.domain.MemberInformation) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)49 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)39 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)30 DistributedMember (org.apache.geode.distributed.DistributedMember)15 InternalCache (org.apache.geode.internal.cache.InternalCache)14 Result (org.apache.geode.management.cli.Result)14 CliMetaData (org.apache.geode.management.cli.CliMetaData)13 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)13 CliCommand (org.springframework.shell.core.annotation.CliCommand)13 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)12 HashSet (java.util.HashSet)10 ArrayList (java.util.ArrayList)9 ObjectName (javax.management.ObjectName)9 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)9 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)8 Test (org.junit.Test)8 List (java.util.List)6 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)6