Search in sources :

Example 11 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class FunctionCommands method executeFunction.

@CliCommand(value = CliStrings.EXECUTE_FUNCTION, help = CliStrings.EXECUTE_FUNCTION__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_FUNCTION })
@ResourceOperation(resource = Resource.DATA, operation = Operation.WRITE)
public Result executeFunction(// TODO: Add optioncontext for functionID
@CliOption(key = CliStrings.EXECUTE_FUNCTION__ID, mandatory = true, help = CliStrings.EXECUTE_FUNCTION__ID__HELP) String functionId, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONGROUPS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.EXECUTE_FUNCTION__ONGROUPS__HELP) String[] onGroups, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONMEMBER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.EXECUTE_FUNCTION__ONMEMBER__HELP) String onMember, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.REGION_PATH, help = CliStrings.EXECUTE_FUNCTION__ONREGION__HELP) String onRegion, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ARGUMENTS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__ARGUMENTS__HELP) String[] arguments, @CliOption(key = CliStrings.EXECUTE_FUNCTION__RESULTCOLLECTOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__RESULTCOLLECTOR__HELP) String resultCollector, @CliOption(key = CliStrings.EXECUTE_FUNCTION__FILTER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__FILTER__HELP) String filterString) {
    Result result = null;
    CompositeResultData executeFunctionResultTable = ResultBuilder.createCompositeResultData();
    TabularResultData resultTable = executeFunctionResultTable.addSection().addTable("Table1");
    String headerText = "Execution summary";
    resultTable.setHeader(headerText);
    ResultCollector resultCollectorInstance = null;
    Function function;
    Set<String> filters = new HashSet<String>();
    Execution execution = null;
    if (functionId != null) {
        functionId = functionId.trim();
    }
    if (onRegion != null) {
        onRegion = onRegion.trim();
    }
    if (onMember != null) {
        onMember = onMember.trim();
    }
    if (filterString != null) {
        filterString = filterString.trim();
    }
    try {
        // validate otherwise return right away. no need to process anything
        if (functionId == null || functionId.length() == 0) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__MISSING_FUNCTIONID);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        }
        if (onRegion != null && onMember != null && onGroups != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if (onRegion != null && onMember != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if (onMember != null && onGroups != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if (onRegion != null && onGroups != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if (onRegion != null && onMember != null && onGroups != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if ((onRegion == null || onRegion.length() == 0) && (filterString != null)) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__MEMBER_SHOULD_NOT_HAVE_FILTER_FOR_EXECUTION);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        }
        InternalCache cache = getCache();
        if (resultCollector != null) {
            resultCollectorInstance = (ResultCollector) ClassPathLoader.getLatest().forName(resultCollector).newInstance();
        }
        if (filterString != null && filterString.length() > 0) {
            filters.add(filterString);
        }
        if (onRegion == null && onMember == null && onGroups == null) {
            // run function on all the members excluding locators bug#46113
            // if user wish to execute on locator then he can choose --member or --group option
            Set<DistributedMember> dsMembers = CliUtil.getAllNormalMembers(cache);
            if (dsMembers.size() > 0) {
                function = new UserFunctionExecution();
                LogWrapper.getInstance().info(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__EXECUTING_0_ON_ENTIRE_DS, functionId));
                for (DistributedMember member : dsMembers) {
                    executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
                }
                return ResultBuilder.buildResult(resultTable);
            } else {
                return ResultBuilder.createUserErrorResult(CliStrings.EXECUTE_FUNCTION__MSG__DS_HAS_NO_MEMBERS);
            }
        } else if (onRegion != null && onRegion.length() > 0) {
            if (cache.getRegion(onRegion) == null) {
                // find a member where region is present
                DistributedRegionMXBean bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean(onRegion);
                if (bean == null) {
                    bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean(Region.SEPARATOR + onRegion);
                    if (bean == null) {
                        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__MXBEAN_0_FOR_NOT_FOUND, onRegion));
                    }
                }
                DistributedMember member = null;
                String[] membersName = bean.getMembers();
                Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
                Iterator it = dsMembers.iterator();
                boolean matchFound = false;
                if (membersName.length > 0) {
                    while (it.hasNext() && matchFound == false) {
                        DistributedMember dsmember = (DistributedMember) it.next();
                        for (String memberName : membersName) {
                            if (MBeanJMXAdapter.getMemberNameOrId(dsmember).equals(memberName)) {
                                member = dsmember;
                                matchFound = true;
                                break;
                            }
                        }
                    }
                }
                if (matchFound == true) {
                    executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
                    return ResultBuilder.buildResult(resultTable);
                } else {
                    return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__NO_ASSOCIATED_MEMBER_REGION, " " + onRegion));
                }
            } else {
                execution = FunctionService.onRegion(cache.getRegion(onRegion));
                if (execution != null) {
                    if (resultCollectorInstance != null) {
                        execution = execution.withCollector(resultCollectorInstance);
                    }
                    if (filters != null && filters.size() > 0) {
                        execution = execution.withFilter(filters);
                    }
                    if (arguments != null && arguments.length > 0) {
                        execution = execution.setArguments(arguments);
                    }
                    try {
                        List<Object> results = (List<Object>) execution.execute(functionId).getResult();
                        if (results.size() > 0) {
                            StringBuilder strResult = new StringBuilder();
                            for (Object obj : results) {
                                strResult.append(obj);
                            }
                            toTabularResultData(resultTable, cache.getDistributedSystem().getDistributedMember().getId(), strResult.toString());
                        }
                        return ResultBuilder.buildResult(resultTable);
                    } catch (FunctionException e) {
                        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_EXECUTING_0_ON_REGION_1_DETAILS_2, functionId, onRegion, e.getMessage()));
                    }
                } else {
                    return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_EXECUTING_0_ON_REGION_1_DETAILS_2, functionId, onRegion, CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_RETRIEVING_EXECUTOR));
                }
            }
        } else if (onGroups != null) {
            // execute on group members
            Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
            for (String grp : onGroups) {
                dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
            }
            StringBuilder successMessage = new StringBuilder();
            if (dsMembers.size() > 0) {
                for (DistributedMember member : dsMembers) {
                    executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
                }
                return ResultBuilder.buildResult(resultTable);
            } else {
                StringBuilder grps = new StringBuilder();
                for (String grp : onGroups) {
                    grps.append(grp);
                    grps.append(", ");
                }
                return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__GROUPS_0_HAS_NO_MEMBERS, grps.toString().substring(0, grps.toString().length() - 1)));
            }
        } else if (onMember != null && onMember.length() > 0) {
            // fix for bug
            DistributedMember member = CliUtil.getDistributedMemberByNameOrId(onMember);
            // 45658
            if (member != null) {
                executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
            } else {
                toTabularResultData(resultTable, onMember, CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__NO_ASSOCIATED_MEMBER + " " + onMember));
            }
            return ResultBuilder.buildResult(resultTable);
        }
    } catch (InstantiationException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    } catch (IllegalAccessException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    } catch (IllegalArgumentException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    } catch (SecurityException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    } catch (Exception e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    }
    return result;
}
Also used : UserFunctionExecution(org.apache.geode.management.internal.cli.functions.UserFunctionExecution) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) HashSet(java.util.HashSet) Set(java.util.Set) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) Function(org.apache.geode.cache.execute.Function) ListFunctionFunction(org.apache.geode.management.internal.cli.functions.ListFunctionFunction) UnregisterFunction(org.apache.geode.management.internal.cli.functions.UnregisterFunction) UserFunctionExecution(org.apache.geode.management.internal.cli.functions.UserFunctionExecution) Execution(org.apache.geode.cache.execute.Execution) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) FunctionException(org.apache.geode.cache.execute.FunctionException) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) FunctionException(org.apache.geode.cache.execute.FunctionException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) DistributedMember(org.apache.geode.distributed.DistributedMember) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 12 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class FunctionCommands method destroyFunction.

@CliCommand(value = CliStrings.DESTROY_FUNCTION, help = CliStrings.DESTROY_FUNCTION__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_FUNCTION }, interceptor = "org.apache.geode.management.internal.cli.commands.FunctionCommands$Interceptor")
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public // TODO: Add optioncontext for functionId
Result destroyFunction(@CliOption(key = CliStrings.DESTROY_FUNCTION__ID, mandatory = true, help = CliStrings.DESTROY_FUNCTION__HELP) String functionId, @CliOption(key = CliStrings.DESTROY_FUNCTION__ONGROUPS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.DESTROY_FUNCTION__ONGROUPS__HELP) String[] groups, @CliOption(key = CliStrings.DESTROY_FUNCTION__ONMEMBER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.DESTROY_FUNCTION__ONMEMBER__HELP) String memberId) {
    Result result = null;
    try {
        InternalCache cache = getCache();
        Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
        if (groups != null && memberId != null) {
            return ResultBuilder.createUserErrorResult(CliStrings.DESTROY_FUNCTION__MSG__PROVIDE_OPTION);
        } else if (groups != null && groups.length > 0) {
            // execute on group members
            for (String grp : groups) {
                dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
            }
            @SuppressWarnings("unchecked") Result results = executeFunction(cache, dsMembers, functionId);
            return results;
        } else if (memberId != null) {
            // execute on member
            dsMembers.add(getMember(cache, memberId));
            @SuppressWarnings("unchecked") Result results = executeFunction(cache, dsMembers, functionId);
            return results;
        } else {
            // no option provided.
            @SuppressWarnings("unchecked") Result results = executeFunction(cache, cache.getMembers(), functionId);
            return results;
        }
    } catch (Exception e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    }
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) FunctionException(org.apache.geode.cache.execute.FunctionException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) HashSet(java.util.HashSet) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 13 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class DurableClientCommands method closeDurableCqs.

@CliCommand(value = CliStrings.CLOSE_DURABLE_CQS, help = CliStrings.CLOSE_DURABLE_CQS__HELP)
@CliMetaData(shellOnly = false)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result closeDurableCqs(@CliOption(key = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID__HELP) final String durableClientId, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__NAME, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__NAME__HELP) final String cqName, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__MEMBER, mandatory = false, help = CliStrings.CLOSE_DURABLE_CQS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__GROUP, mandatory = false, help = CliStrings.CLOSE_DURABLE_CQS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) {
    Result result = null;
    try {
        Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        String[] params = new String[2];
        params[0] = durableClientId;
        params[1] = cqName;
        final ResultCollector<?, ?> rc = CliUtil.executeFunction(new CloseDurableCqFunction(), params, targetMembers);
        final List<MemberResult> results = (List<MemberResult>) rc.getResult();
        String failureHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__FAILURE__HEADER, cqName, durableClientId);
        String successHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__SUCCESS, cqName, durableClientId);
        result = buildResult(results, successHeader, failureHeader);
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
}
Also used : CloseDurableCqFunction(org.apache.geode.management.internal.cli.functions.CloseDurableCqFunction) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) DistributedMember(org.apache.geode.distributed.DistributedMember) LinkedList(java.util.LinkedList) List(java.util.List) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) SubscriptionQueueSizeResult(org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult) DurableCqNamesResult(org.apache.geode.management.internal.cli.domain.DurableCqNamesResult) Result(org.apache.geode.management.cli.Result) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 14 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class MiscellaneousCommands method showMetrics.

@CliCommand(value = CliStrings.SHOW_METRICS, help = CliStrings.SHOW_METRICS__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_STATISTICS })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showMetrics(@CliOption(key = { CliStrings.SHOW_METRICS__MEMBER }, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.SHOW_METRICS__MEMBER__HELP) String memberNameOrId, @CliOption(key = { CliStrings.SHOW_METRICS__REGION }, optionContext = ConverterHint.REGION_PATH, help = CliStrings.SHOW_METRICS__REGION__HELP) String regionName, @CliOption(key = { CliStrings.SHOW_METRICS__FILE }, help = CliStrings.SHOW_METRICS__FILE__HELP) String export_to_report_to, @CliOption(key = { CliStrings.SHOW_METRICS__CACHESERVER__PORT }, help = CliStrings.SHOW_METRICS__CACHESERVER__PORT__HELP) String cacheServerPortString, @CliOption(key = { CliStrings.SHOW_METRICS__CATEGORY }, help = CliStrings.SHOW_METRICS__CATEGORY__HELP) String[] categories) {
    Result result = null;
    try {
        if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
            if (!export_to_report_to.endsWith(".csv")) {
                return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, ".csv"));
            }
        }
        if (regionName != null && !regionName.isEmpty()) {
            if (!org.apache.geode.internal.lang.StringUtils.isBlank(cacheServerPortString)) {
                return ResultBuilder.createUserErrorResult(CliStrings.SHOW_METRICS__CANNOT__USE__CACHESERVERPORT);
            }
            // MBean names contain the forward slash
            if (!regionName.startsWith("/")) {
                regionName = "/" + regionName;
            }
            if (memberNameOrId == null || memberNameOrId.isEmpty()) {
                result = ResultBuilder.buildResult(getDistributedRegionMetrics(regionName, export_to_report_to, categories));
            } else {
                DistributedMember member = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
                if (member != null) {
                    result = ResultBuilder.buildResult(getRegionMetricsFromMember(regionName, member, export_to_report_to, categories));
                } else {
                    ErrorResultData erd = ResultBuilder.createErrorResultData();
                    erd.addLine(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, memberNameOrId));
                    result = ResultBuilder.buildResult(erd);
                }
            }
        } else if (memberNameOrId != null && !memberNameOrId.isEmpty()) {
            DistributedMember member = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
            if (member != null) {
                int cacheServerPort = -1;
                if (cacheServerPortString != null && !cacheServerPortString.isEmpty()) {
                    try {
                        cacheServerPort = Integer.parseInt(cacheServerPortString);
                    } catch (NumberFormatException nfe) {
                        return ResultBuilder.createUserErrorResult("Invalid port");
                    }
                }
                result = ResultBuilder.buildResult(getMemberMetrics(member, export_to_report_to, categories, cacheServerPort));
            } else {
                ErrorResultData erd = ResultBuilder.createErrorResultData();
                erd.addLine(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, memberNameOrId));
                result = ResultBuilder.buildResult(erd);
            }
        } else {
            if (!org.apache.geode.internal.lang.StringUtils.isBlank(cacheServerPortString)) {
                return ResultBuilder.createUserErrorResult(CliStrings.SHOW_METRICS__CANNOT__USE__CACHESERVERPORT);
            }
            result = ResultBuilder.buildResult(getSystemWideMetrics(export_to_report_to, categories));
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return ResultBuilder.createGemFireErrorResult(CliUtil.stackTraceAsString(e));
    }
    return result;
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) TimeoutException(java.util.concurrent.TimeoutException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) FunctionException(org.apache.geode.cache.execute.FunctionException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) NetstatFunctionResult(org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 15 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class PDXCommands method pdxRename.

@CliCommand(value = CliStrings.PDX_RENAME, help = CliStrings.PDX_RENAME__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result pdxRename(@CliOption(key = CliStrings.PDX_RENAME_OLD, mandatory = true, help = CliStrings.PDX_RENAME_OLD__HELP) String oldClassName, @CliOption(key = CliStrings.PDX_RENAME_NEW, mandatory = true, help = CliStrings.PDX_RENAME_NEW__HELP) String newClassName, @CliOption(key = CliStrings.PDX_DISKSTORE, mandatory = true, help = CliStrings.PDX_DISKSTORE__HELP) String diskStore, @CliOption(key = CliStrings.PDX_DISKDIR, mandatory = true, help = CliStrings.PDX_DISKDIR__HELP) String[] diskDirs) {
    try {
        final File[] dirs = new File[diskDirs.length];
        for (int i = 0; i < diskDirs.length; i++) {
            dirs[i] = new File((diskDirs[i]));
        }
        Collection<Object> results = DiskStoreImpl.pdxRename(diskStore, dirs, oldClassName, newClassName);
        if (results.isEmpty()) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.PDX_RENAME__EMPTY));
        }
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(outputStream);
        for (Object p : results) {
            if (p instanceof PdxType) {
                ((PdxType) p).toStream(printStream, false);
            } else {
                ((EnumInfo) p).toStream(printStream);
            }
        }
        String resultString = CliStrings.format(CliStrings.PDX_RENAME__SUCCESS, outputStream.toString());
        return ResultBuilder.createInfoResult(resultString.toString());
    } catch (Exception e) {
        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.PDX_RENAME__ERROR, e.getMessage()));
    }
}
Also used : PrintStream(java.io.PrintStream) PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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)

Aggregations

ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)58 CliCommand (org.springframework.shell.core.annotation.CliCommand)57 CliMetaData (org.apache.geode.management.cli.CliMetaData)55 DistributedMember (org.apache.geode.distributed.DistributedMember)49 Result (org.apache.geode.management.cli.Result)49 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)32 InternalCache (org.apache.geode.internal.cache.InternalCache)30 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)30 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)27 ArrayList (java.util.ArrayList)18 List (java.util.List)18 ExecutionException (java.util.concurrent.ExecutionException)15 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)14 ObjectName (javax.management.ObjectName)13 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)13 IOException (java.io.IOException)11 HashSet (java.util.HashSet)11 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)11 HashMap (java.util.HashMap)10 ConverterHint (org.apache.geode.management.cli.ConverterHint)10