Search in sources :

Example 56 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class CreateAlterDestroyRegionCommands method createRegion.

/**
   * TODO: method createRegion is too complex to analyze
   */
@CliCommand(value = CliStrings.CREATE_REGION, help = CliStrings.CREATE_REGION__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result createRegion(@CliOption(key = CliStrings.CREATE_REGION__REGION, mandatory = true, help = CliStrings.CREATE_REGION__REGION__HELP) String regionPath, @CliOption(key = CliStrings.CREATE_REGION__REGIONSHORTCUT, help = CliStrings.CREATE_REGION__REGIONSHORTCUT__HELP) RegionShortcut regionShortcut, @CliOption(key = CliStrings.CREATE_REGION__USEATTRIBUTESFROM, optionContext = ConverterHint.REGION_PATH, help = CliStrings.CREATE_REGION__USEATTRIBUTESFROM__HELP) String useAttributesFrom, @CliOption(key = CliStrings.CREATE_REGION__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_REGION__GROUP__HELP) String[] groups, @CliOption(key = CliStrings.CREATE_REGION__SKIPIFEXISTS, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true", help = CliStrings.CREATE_REGION__SKIPIFEXISTS__HELP) boolean skipIfExists, // their key string
@CliOption(key = CliStrings.CREATE_REGION__ASYNCEVENTQUEUEID, help = CliStrings.CREATE_REGION__ASYNCEVENTQUEUEID__HELP) String[] asyncEventQueueIds, @CliOption(key = CliStrings.CREATE_REGION__CACHELISTENER, help = CliStrings.CREATE_REGION__CACHELISTENER__HELP) String[] cacheListener, @CliOption(key = CliStrings.CREATE_REGION__CACHELOADER, help = CliStrings.CREATE_REGION__CACHELOADER__HELP) String cacheLoader, @CliOption(key = CliStrings.CREATE_REGION__CACHEWRITER, help = CliStrings.CREATE_REGION__CACHEWRITER__HELP) String cacheWriter, @CliOption(key = CliStrings.CREATE_REGION__COLOCATEDWITH, optionContext = ConverterHint.REGION_PATH, help = CliStrings.CREATE_REGION__COLOCATEDWITH__HELP) String prColocatedWith, @CliOption(key = CliStrings.CREATE_REGION__COMPRESSOR, help = CliStrings.CREATE_REGION__COMPRESSOR__HELP) String compressor, @CliOption(key = CliStrings.CREATE_REGION__CONCURRENCYLEVEL, help = CliStrings.CREATE_REGION__CONCURRENCYLEVEL__HELP) Integer concurrencyLevel, @CliOption(key = CliStrings.CREATE_REGION__DISKSTORE, help = CliStrings.CREATE_REGION__DISKSTORE__HELP) String diskStore, @CliOption(key = CliStrings.CREATE_REGION__ENABLEASYNCCONFLATION, help = CliStrings.CREATE_REGION__ENABLEASYNCCONFLATION__HELP) Boolean enableAsyncConflation, @CliOption(key = CliStrings.CREATE_REGION__CLONINGENABLED, help = CliStrings.CREATE_REGION__CLONINGENABLED__HELP) Boolean cloningEnabled, @CliOption(key = CliStrings.CREATE_REGION__CONCURRENCYCHECKSENABLED, help = CliStrings.CREATE_REGION__CONCURRENCYCHECKSENABLED__HELP) Boolean concurrencyChecksEnabled, @CliOption(key = CliStrings.CREATE_REGION__MULTICASTENABLED, help = CliStrings.CREATE_REGION__MULTICASTENABLED__HELP) Boolean mcastEnabled, @CliOption(key = CliStrings.CREATE_REGION__STATISTICSENABLED, help = CliStrings.CREATE_REGION__STATISTICSENABLED__HELP) Boolean statisticsEnabled, @CliOption(key = CliStrings.CREATE_REGION__ENABLESUBSCRIPTIONCONFLATION, help = CliStrings.CREATE_REGION__ENABLESUBSCRIPTIONCONFLATION__HELP) Boolean enableSubscriptionConflation, @CliOption(key = CliStrings.CREATE_REGION__DISKSYNCHRONOUS, help = CliStrings.CREATE_REGION__DISKSYNCHRONOUS__HELP) Boolean diskSynchronous, @CliOption(key = CliStrings.CREATE_REGION__ENTRYEXPIRATIONIDLETIME, help = CliStrings.CREATE_REGION__ENTRYEXPIRATIONIDLETIME__HELP) Integer entryExpirationIdleTime, @CliOption(key = CliStrings.CREATE_REGION__ENTRYEXPIRATIONIDLETIMEACTION, help = CliStrings.CREATE_REGION__ENTRYEXPIRATIONIDLETIMEACTION__HELP) String entryExpirationIdleTimeAction, @CliOption(key = CliStrings.CREATE_REGION__ENTRYEXPIRATIONTIMETOLIVE, help = CliStrings.CREATE_REGION__ENTRYEXPIRATIONTIMETOLIVE__HELP) Integer entryExpirationTTL, @CliOption(key = CliStrings.CREATE_REGION__ENTRYEXPIRATIONTTLACTION, help = CliStrings.CREATE_REGION__ENTRYEXPIRATIONTTLACTION__HELP) String entryExpirationTTLAction, @CliOption(key = CliStrings.CREATE_REGION__GATEWAYSENDERID, help = CliStrings.CREATE_REGION__GATEWAYSENDERID__HELP) String[] gatewaySenderIds, @CliOption(key = CliStrings.CREATE_REGION__KEYCONSTRAINT, help = CliStrings.CREATE_REGION__KEYCONSTRAINT__HELP) String keyConstraint, @CliOption(key = CliStrings.CREATE_REGION__LOCALMAXMEMORY, help = CliStrings.CREATE_REGION__LOCALMAXMEMORY__HELP) Integer prLocalMaxMemory, @CliOption(key = CliStrings.CREATE_REGION__OFF_HEAP, specifiedDefaultValue = "true", help = CliStrings.CREATE_REGION__OFF_HEAP__HELP) Boolean offHeap, @CliOption(key = CliStrings.CREATE_REGION__PARTITION_RESOLVER, help = CliStrings.CREATE_REGION__PARTITION_RESOLVER__HELP) String partitionResolver, @CliOption(key = CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIME, help = CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIME__HELP) Integer regionExpirationIdleTime, @CliOption(key = CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIMEACTION, help = CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIMEACTION__HELP) String regionExpirationIdleTimeAction, @CliOption(key = CliStrings.CREATE_REGION__REGIONEXPIRATIONTTL, help = CliStrings.CREATE_REGION__REGIONEXPIRATIONTTL__HELP) Integer regionExpirationTTL, @CliOption(key = CliStrings.CREATE_REGION__REGIONEXPIRATIONTTLACTION, help = CliStrings.CREATE_REGION__REGIONEXPIRATIONTTLACTION__HELP) String regionExpirationTTLAction, @CliOption(key = CliStrings.CREATE_REGION__RECOVERYDELAY, help = CliStrings.CREATE_REGION__RECOVERYDELAY__HELP) Long prRecoveryDelay, @CliOption(key = CliStrings.CREATE_REGION__REDUNDANTCOPIES, help = CliStrings.CREATE_REGION__REDUNDANTCOPIES__HELP) Integer prRedundantCopies, @CliOption(key = CliStrings.CREATE_REGION__STARTUPRECOVERYDDELAY, help = CliStrings.CREATE_REGION__STARTUPRECOVERYDDELAY__HELP) Long prStartupRecoveryDelay, @CliOption(key = CliStrings.CREATE_REGION__TOTALMAXMEMORY, help = CliStrings.CREATE_REGION__TOTALMAXMEMORY__HELP) Long prTotalMaxMemory, @CliOption(key = CliStrings.CREATE_REGION__TOTALNUMBUCKETS, help = CliStrings.CREATE_REGION__TOTALNUMBUCKETS__HELP) Integer prTotalNumBuckets, @CliOption(key = CliStrings.CREATE_REGION__VALUECONSTRAINT, help = CliStrings.CREATE_REGION__VALUECONSTRAINT__HELP) String valueConstraint) // NOTICE: keep the region attributes params in alphabetical order
{
    Result result;
    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
    try {
        InternalCache cache = getCache();
        if (regionShortcut != null && useAttributesFrom != null) {
            throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__ONLY_ONE_OF_REGIONSHORTCUT_AND_USEATTRIBUESFROM_CAN_BE_SPECIFIED);
        } else if (regionShortcut == null && useAttributesFrom == null) {
            throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__ONE_OF_REGIONSHORTCUT_AND_USEATTRIBUESFROM_IS_REQUIRED);
        }
        validateRegionPathAndParent(cache, regionPath);
        validateGroups(cache, groups);
        RegionFunctionArgs.ExpirationAttrs entryIdle = null;
        if (entryExpirationIdleTime != null) {
            entryIdle = new RegionFunctionArgs.ExpirationAttrs(RegionFunctionArgs.ExpirationAttrs.ExpirationFor.ENTRY_IDLE, entryExpirationIdleTime, entryExpirationIdleTimeAction);
        }
        RegionFunctionArgs.ExpirationAttrs entryTTL = null;
        if (entryExpirationTTL != null) {
            entryTTL = new RegionFunctionArgs.ExpirationAttrs(RegionFunctionArgs.ExpirationAttrs.ExpirationFor.ENTRY_TTL, entryExpirationTTL, entryExpirationTTLAction);
        }
        RegionFunctionArgs.ExpirationAttrs regionIdle = null;
        if (regionExpirationIdleTime != null) {
            regionIdle = new RegionFunctionArgs.ExpirationAttrs(RegionFunctionArgs.ExpirationAttrs.ExpirationFor.REGION_IDLE, regionExpirationIdleTime, regionExpirationIdleTimeAction);
        }
        RegionFunctionArgs.ExpirationAttrs regionTTL = null;
        if (regionExpirationTTL != null) {
            regionTTL = new RegionFunctionArgs.ExpirationAttrs(RegionFunctionArgs.ExpirationAttrs.ExpirationFor.REGION_TTL, regionExpirationTTL, regionExpirationTTLAction);
        }
        RegionFunctionArgs regionFunctionArgs;
        if (useAttributesFrom != null) {
            if (!regionExists(cache, useAttributesFrom)) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH_FOR_0_REGIONPATH_1_NOT_FOUND, new Object[] { CliStrings.CREATE_REGION__USEATTRIBUTESFROM, useAttributesFrom }));
            }
            FetchRegionAttributesFunctionResult<Object, Object> regionAttributesResult = getRegionAttributes(cache, useAttributesFrom);
            RegionAttributes<?, ?> regionAttributes = regionAttributesResult.getRegionAttributes();
            // give preference to user specified plugins than the ones retrieved from other region
            String[] cacheListenerClasses = cacheListener != null && cacheListener.length != 0 ? cacheListener : regionAttributesResult.getCacheListenerClasses();
            String cacheLoaderClass = cacheLoader != null ? cacheLoader : regionAttributesResult.getCacheLoaderClass();
            String cacheWriterClass = cacheWriter != null ? cacheWriter : regionAttributesResult.getCacheWriterClass();
            regionFunctionArgs = new RegionFunctionArgs(regionPath, useAttributesFrom, skipIfExists, keyConstraint, valueConstraint, statisticsEnabled, entryIdle, entryTTL, regionIdle, regionTTL, diskStore, diskSynchronous, enableAsyncConflation, enableSubscriptionConflation, cacheListenerClasses, cacheLoaderClass, cacheWriterClass, asyncEventQueueIds, gatewaySenderIds, concurrencyChecksEnabled, cloningEnabled, concurrencyLevel, prColocatedWith, prLocalMaxMemory, prRecoveryDelay, prRedundantCopies, prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets, offHeap, mcastEnabled, regionAttributes, partitionResolver);
            if (regionAttributes.getPartitionAttributes() == null && regionFunctionArgs.hasPartitionAttributes()) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__OPTION_0_CAN_BE_USED_ONLY_FOR_PARTITIONEDREGION, regionFunctionArgs.getPartitionArgs().getUserSpecifiedPartitionAttributes()) + " " + CliStrings.format(CliStrings.CREATE_REGION__MSG__0_IS_NOT_A_PARITIONEDREGION, useAttributesFrom));
            }
        } else {
            regionFunctionArgs = new RegionFunctionArgs(regionPath, regionShortcut, useAttributesFrom, skipIfExists, keyConstraint, valueConstraint, statisticsEnabled, entryIdle, entryTTL, regionIdle, regionTTL, diskStore, diskSynchronous, enableAsyncConflation, enableSubscriptionConflation, cacheListener, cacheLoader, cacheWriter, asyncEventQueueIds, gatewaySenderIds, concurrencyChecksEnabled, cloningEnabled, concurrencyLevel, prColocatedWith, prLocalMaxMemory, prRecoveryDelay, prRedundantCopies, prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets, null, compressor, offHeap, mcastEnabled, partitionResolver);
            if (!regionShortcut.name().startsWith("PARTITION") && regionFunctionArgs.hasPartitionAttributes()) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__OPTION_0_CAN_BE_USED_ONLY_FOR_PARTITIONEDREGION, regionFunctionArgs.getPartitionArgs().getUserSpecifiedPartitionAttributes()) + " " + CliStrings.format(CliStrings.CREATE_REGION__MSG__0_IS_NOT_A_PARITIONEDREGION, useAttributesFrom));
            }
        }
        validateRegionFunctionArgs(cache, regionFunctionArgs);
        Set<DistributedMember> membersToCreateRegionOn;
        if (groups != null && groups.length != 0) {
            membersToCreateRegionOn = CliUtil.getDistributedMembersByGroup(cache, groups);
            // have only normal members from the group
            for (Iterator<DistributedMember> it = membersToCreateRegionOn.iterator(); it.hasNext(); ) {
                DistributedMember distributedMember = it.next();
                if (((InternalDistributedMember) distributedMember).getVmKind() == DistributionManager.LOCATOR_DM_TYPE) {
                    it.remove();
                }
            }
        } else {
            membersToCreateRegionOn = CliUtil.getAllNormalMembers(cache);
        }
        if (membersToCreateRegionOn.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_CACHING_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(RegionCreateFunction.INSTANCE, regionFunctionArgs, membersToCreateRegionOn);
        @SuppressWarnings("unchecked") List<CliFunctionResult> regionCreateResults = (List<CliFunctionResult>) resultCollector.getResult();
        TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
        final String errorPrefix = "ERROR: ";
        for (CliFunctionResult regionCreateResult : regionCreateResults) {
            boolean success = regionCreateResult.isSuccessful();
            tabularResultData.accumulate("Member", regionCreateResult.getMemberIdOrName());
            tabularResultData.accumulate("Status", (success ? "" : errorPrefix) + regionCreateResult.getMessage());
            if (success) {
                xmlEntity.set(regionCreateResult.getXmlEntity());
            }
        }
        result = ResultBuilder.buildResult(tabularResultData);
        verifyDistributedRegionMbean(cache, regionPath);
    } catch (IllegalArgumentException | IllegalStateException e) {
        LogWrapper.getInstance().info(e.getMessage());
        result = ResultBuilder.createUserErrorResult(e.getMessage());
    } catch (RuntimeException e) {
        LogWrapper.getInstance().info(e.getMessage(), e);
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    if (xmlEntity.get() != null) {
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) FetchRegionAttributesFunctionResult(org.apache.geode.management.internal.cli.functions.FetchRegionAttributesFunction.FetchRegionAttributesFunctionResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) RegionFunctionArgs(org.apache.geode.management.internal.cli.functions.RegionFunctionArgs) List(java.util.List) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 57 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class DeployCommands method listDeployed.

/**
   * List all currently deployed JARs for members of a group or for all members.
   * 
   * @param group Group for which to list JARs or null for all members
   * @return List of deployed JAR files
   */
@CliCommand(value = { CliStrings.LIST_DEPLOYED }, help = CliStrings.LIST_DEPLOYED__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listDeployed(@CliOption(key = { CliStrings.LIST_DEPLOYED__GROUP }, help = CliStrings.LIST_DEPLOYED__GROUP__HELP) String[] group) {
    try {
        TabularResultData tabularData = ResultBuilder.createTabularResultData();
        boolean accumulatedData = false;
        Set<DistributedMember> targetMembers = CliUtil.findMembers(group, null);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> rc = CliUtil.executeFunction(this.listDeployedFunction, null, targetMembers);
        List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
        for (CliFunctionResult result : results) {
            if (result.getThrowable() != null) {
                tabularData.accumulate("Member", result.getMemberIdOrName());
                tabularData.accumulate("JAR", "");
                tabularData.accumulate("JAR Location", "ERROR: " + result.getThrowable().getClass().getName() + ": " + result.getThrowable().getMessage());
                accumulatedData = true;
                tabularData.setStatus(Status.ERROR);
            } else {
                String[] strings = (String[]) result.getSerializables();
                for (int i = 0; i < strings.length; i += 2) {
                    tabularData.accumulate("Member", result.getMemberIdOrName());
                    tabularData.accumulate("JAR", strings[i]);
                    tabularData.accumulate("JAR Location", strings[i + 1]);
                    accumulatedData = true;
                }
            }
        }
        if (!accumulatedData) {
            return ResultBuilder.createInfoResult(CliStrings.LIST_DEPLOYED__NO_JARS_FOUND_MESSAGE);
        }
        return ResultBuilder.buildResult(tabularData);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        return ResultBuilder.createGemFireErrorResult("Exception while attempting to list deployed: " + th.getClass().getName() + ": " + th.getMessage());
    }
}
Also used : CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) ConverterHint(org.apache.geode.management.cli.ConverterHint) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 58 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class ClientCommands method listClient.

@CliCommand(value = CliStrings.LIST_CLIENTS, help = CliStrings.LIST_CLIENT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_CLIENT })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listClient() {
    Result result = null;
    try {
        CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
        SectionResultData section = compositeResultData.addSection("section1");
        TabularResultData resultTable = section.addTable("TableForClientList");
        String headerText = "ClientList";
        resultTable = resultTable.setHeader(headerText);
        InternalCache cache = getCache();
        ManagementService service = ManagementService.getExistingManagementService(cache);
        ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();
        if (cacheServers.length == 0) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
        }
        Map<String, List<String>> clientServerMap = new HashMap<String, List<String>>();
        for (ObjectName objName : cacheServers) {
            CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class);
            String[] listOfClient = serverMbean.getClientIds();
            if (listOfClient == null || listOfClient.length == 0) {
                continue;
            }
            for (String clietName : listOfClient) {
                String serverDetails = "member=" + objName.getKeyProperty("member") + ",port=" + objName.getKeyProperty("port");
                if (clientServerMap.containsKey(clietName)) {
                    List<String> listServers = clientServerMap.get(clietName);
                    listServers.add(serverDetails);
                } else {
                    List<String> listServer = new ArrayList<String>();
                    listServer.add(serverDetails);
                    clientServerMap.put(clietName, listServer);
                }
            }
        }
        if (clientServerMap.size() == 0) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_COULD_NOT_RETRIEVE_CLIENT_LIST));
        }
        String memberSeparator = ";  ";
        Iterator<Entry<String, List<String>>> it = clientServerMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, List<String>> pairs = (Map.Entry<String, List<String>>) it.next();
            String client = (String) pairs.getKey();
            List<String> servers = (List<String>) pairs.getValue();
            StringBuilder serverListForClient = new StringBuilder();
            int serversSize = servers.size();
            int i = 0;
            for (String server : servers) {
                serverListForClient.append(server);
                if (i < serversSize - 1) {
                    serverListForClient.append(memberSeparator);
                }
                i++;
            }
            resultTable.accumulate(CliStrings.LIST_CLIENT_COLUMN_Clients, client);
            resultTable.accumulate(CliStrings.LIST_CLIENT_COLUMN_SERVERS, serverListForClient.toString());
        }
        result = ResultBuilder.buildResult(compositeResultData);
    } catch (Exception e) {
        LogWrapper.getInstance().warning("Error in list clients. stack trace" + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_CLIENT_LIST_0, e.getMessage()));
    }
    LogWrapper.getInstance().info("list client result " + result);
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) Result(org.apache.geode.management.cli.Result) ObjectName(javax.management.ObjectName) Entry(java.util.Map.Entry) ManagementService(org.apache.geode.management.ManagementService) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 59 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class DataCommands method rebalance.

@CliCommand(value = CliStrings.REBALANCE, help = CliStrings.REBALANCE__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result rebalance(@CliOption(key = CliStrings.REBALANCE__INCLUDEREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.REBALANCE__INCLUDEREGION__HELP) String[] includeRegions, @CliOption(key = CliStrings.REBALANCE__EXCLUDEREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.REBALANCE__EXCLUDEREGION__HELP) String[] excludeRegions, @CliOption(key = CliStrings.REBALANCE__TIMEOUT, unspecifiedDefaultValue = "-1", help = CliStrings.REBALANCE__TIMEOUT__HELP) long timeout, @CliOption(key = CliStrings.REBALANCE__SIMULATE, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.REBALANCE__SIMULATE__HELP) boolean simulate) {
    ExecutorService commandExecutors = Executors.newSingleThreadExecutor();
    List<Future<Result>> commandResult = new ArrayList<>();
    Result result;
    try {
        commandResult.add(commandExecutors.submit(new ExecuteRebalanceWithTimeout(includeRegions, excludeRegions, simulate)));
        Future<Result> fs = commandResult.get(0);
        if (timeout > 0) {
            result = fs.get(timeout, TimeUnit.SECONDS);
        } else {
            result = fs.get();
        }
    } catch (TimeoutException timeoutException) {
        result = ResultBuilder.createInfoResult(CliStrings.REBALANCE__MSG__REBALANCE_WILL_CONTINUE);
    } catch (Exception ex) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.REBALANCE__MSG__EXCEPTION_OCCRED_WHILE_REBALANCING_0, ex.getMessage()));
    }
    LogWrapper.getInstance().info("Rebalance returning result >>>" + result);
    return result;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) TimeoutException(java.util.concurrent.TimeoutException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Result(org.apache.geode.management.cli.Result) DataCommandResult(org.apache.geode.management.internal.cli.domain.DataCommandResult) TimeoutException(java.util.concurrent.TimeoutException) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 60 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class ShellCommands method exit.

@CliCommand(value = { CliStrings.EXIT, "quit" }, help = CliStrings.EXIT__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH })
public ExitShellRequest exit() throws IOException {
    Gfsh gfshInstance = getGfsh();
    gfshInstance.stop();
    ExitShellRequest exitShellRequest = gfshInstance.getExitShellRequest();
    if (exitShellRequest == null) {
        // shouldn't really happen, but we'll fallback to this anyway
        exitShellRequest = ExitShellRequest.NORMAL_EXIT;
    }
    return exitShellRequest;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) ExitShellRequest(org.springframework.shell.core.ExitShellRequest) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Aggregations

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