Search in sources :

Example 31 with ResourceOperation

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

the class PDXCommands method configurePDX.

@CliCommand(value = CliStrings.CONFIGURE_PDX, help = CliStrings.CONFIGURE_PDX__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result configurePDX(@CliOption(key = CliStrings.CONFIGURE_PDX__READ__SERIALIZED, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__READ__SERIALIZED__HELP) Boolean readSerialized, @CliOption(key = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS__HELP) Boolean ignoreUnreadFields, @CliOption(key = CliStrings.CONFIGURE_PDX__DISKSTORE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "", help = CliStrings.CONFIGURE_PDX__DISKSTORE__HELP) String diskStore, @CliOption(key = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES__HELP) String[] patterns, @CliOption(key = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES__HELP) String[] portablePatterns) {
    Result result = null;
    try {
        InfoResultData ird = ResultBuilder.createInfoResultData();
        CacheCreation cache = new CacheCreation(true);
        if ((portablePatterns != null && portablePatterns.length > 0) && (patterns != null && patterns.length > 0)) {
            return ResultBuilder.createUserErrorResult(CliStrings.CONFIGURE_PDX__ERROR__MESSAGE);
        }
        if (!CliUtil.getAllNormalMembers(CliUtil.getCacheIfExists()).isEmpty()) {
            ird.addLine(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING);
        }
        // Set persistent and the disk-store
        if (diskStore != null) {
            cache.setPdxPersistent(true);
            ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
            if (!diskStore.equals("")) {
                cache.setPdxDiskStore(diskStore);
                ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + cache.getPdxDiskStore());
            } else {
                ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + "DEFAULT");
            }
        } else {
            cache.setPdxPersistent(CacheConfig.DEFAULT_PDX_PERSISTENT);
            ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
        }
        // Set read-serialized
        if (readSerialized != null) {
            cache.setPdxReadSerialized(readSerialized);
        } else {
            cache.setPdxReadSerialized(CacheConfig.DEFAULT_PDX_READ_SERIALIZED);
        }
        ird.addLine(CliStrings.CONFIGURE_PDX__READ__SERIALIZED + " = " + cache.getPdxReadSerialized());
        // Set ingoreUnreadFields
        if (ignoreUnreadFields != null) {
            cache.setPdxIgnoreUnreadFields(ignoreUnreadFields);
        } else {
            cache.setPdxIgnoreUnreadFields(CacheConfig.DEFAULT_PDX_IGNORE_UNREAD_FIELDS);
        }
        ird.addLine(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS + " = " + cache.getPdxIgnoreUnreadFields());
        if (portablePatterns != null) {
            ReflectionBasedAutoSerializer autoSerializer = new ReflectionBasedAutoSerializer(portablePatterns);
            cache.setPdxSerializer(autoSerializer);
            ird.addLine("PDX Serializer " + cache.getPdxSerializer().getClass().getName());
            ird.addLine("Portable classes " + Arrays.toString(portablePatterns));
        }
        if (patterns != null) {
            ReflectionBasedAutoSerializer nonPortableAutoSerializer = new ReflectionBasedAutoSerializer(true, patterns);
            cache.setPdxSerializer(nonPortableAutoSerializer);
            ird.addLine("PDX Serializer : " + cache.getPdxSerializer().getClass().getName());
            ird.addLine("Non portable classes :" + Arrays.toString(patterns));
        }
        final StringWriter stringWriter = new StringWriter();
        final PrintWriter printWriter = new PrintWriter(stringWriter);
        CacheXmlGenerator.generate(cache, printWriter, true, false, false);
        printWriter.close();
        String xmlDefinition = stringWriter.toString();
        // TODO jbarrett - shouldn't this use the same loadXmlDefinition that other constructors use?
        XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.PDX).withConfig(xmlDefinition).build();
        result = ResultBuilder.buildResult(ird);
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity, null));
    } catch (Exception e) {
        return ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) StringWriter(java.io.StringWriter) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) Result(org.apache.geode.management.cli.Result) PrintWriter(java.io.PrintWriter) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 32 with ResourceOperation

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

the class QueueCommands method createAsyncEventQueue.

@CliCommand(value = CliStrings.CREATE_ASYNC_EVENT_QUEUE, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__HELP)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result createAsyncEventQueue(@CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, mandatory = true, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID__HELP) String id, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP__HELP) String[] groups, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__PARALLEL, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__PARALLEL__HELP) Boolean parallel, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ENABLEBATCHCONFLATION, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ENABLEBATCHCONFLATION__HELP) Boolean enableBatchConflation, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, unspecifiedDefaultValue = "100", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE__HELP) int batchSize, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCHTIMEINTERVAL, unspecifiedDefaultValue = "1000", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCHTIMEINTERVAL__HELP) int batchTimeInterval, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT__HELP) boolean persistent, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISK_STORE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISK_STORE__HELP) String diskStore, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISKSYNCHRONOUS, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISKSYNCHRONOUS__HELP) Boolean diskSynchronous, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__FORWARD_EXPIRATION_DESTROY, unspecifiedDefaultValue = "false", specifiedDefaultValue = "false", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__FORWARD_EXPIRATION_DESTROY__HELP) Boolean ignoreEvictionAndExpiration, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, unspecifiedDefaultValue = "100", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY__HELP) int maxQueueMemory, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISPATCHERTHREADS, unspecifiedDefaultValue = "1", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISPATCHERTHREADS__HELP) Integer dispatcherThreads, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ORDERPOLICY, unspecifiedDefaultValue = "KEY", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ORDERPOLICY__HELP) String orderPolicy, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__GATEWAYEVENTFILTER, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__GATEWAYEVENTFILTER__HELP) String[] gatewayEventFilters, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__SUBSTITUTION_FILTER, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__SUBSTITUTION_FILTER__HELP) String gatewaySubstitutionListener, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER, mandatory = true, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER__HELP) String listener, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER_PARAM_AND_VALUE, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER_PARAM_AND_VALUE__HELP) String[] listenerParamsAndValues) {
    Properties listenerProperties = new Properties();
    try {
        if (listenerParamsAndValues != null) {
            for (int i = 0; i < listenerParamsAndValues.length; i++) {
                final int hashPosition = listenerParamsAndValues[i].indexOf('#');
                if (hashPosition == -1) {
                    listenerProperties.put(listenerParamsAndValues[i], "");
                } else {
                    listenerProperties.put(listenerParamsAndValues[i].substring(0, hashPosition), listenerParamsAndValues[i].substring(hashPosition + 1));
                }
            }
        }
        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);
        }
        AsyncEventQueueFunctionArgs aeqArgs = new AsyncEventQueueFunctionArgs(id, parallel, enableBatchConflation, batchSize, batchTimeInterval, persistent, diskStore, diskSynchronous, maxQueueMemory, dispatcherThreads, orderPolicy, gatewayEventFilters, gatewaySubstitutionListener, listener, listenerProperties, ignoreEvictionAndExpiration);
        ResultCollector<?, ?> rc = CliUtil.executeFunction(new CreateAsyncEventQueueFunction(), aeqArgs, 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 async event queue(s).");
        }
        Result result = ResultBuilder.buildResult(tabularData);
        if (xmlEntity.get() != null) {
            persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
        }
        return result;
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ERROR_WHILE_CREATING_REASON_0, new Object[] { th.getMessage() }));
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) AsyncEventQueueFunctionArgs(org.apache.geode.management.internal.cli.functions.AsyncEventQueueFunctionArgs) AtomicReference(java.util.concurrent.atomic.AtomicReference) Properties(java.util.Properties) CreateAsyncEventQueueFunction(org.apache.geode.management.internal.cli.functions.CreateAsyncEventQueueFunction) ConverterHint(org.apache.geode.management.cli.ConverterHint) 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) DistributedMember(org.apache.geode.distributed.DistributedMember) CliCommand(org.springframework.shell.core.annotation.CliCommand) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 33 with ResourceOperation

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

the class RegionCommands method listRegion.

@CliCommand(value = { CliStrings.LIST_REGION }, help = CliStrings.LIST_REGION__HELP)
@CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.READ)
public Result listRegion(@CliOption(key = { CliStrings.LIST_REGION__GROUP }, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_REGION__GROUP__HELP) String[] group, @CliOption(key = { CliStrings.LIST_REGION__MEMBER }, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_REGION__MEMBER__HELP) String[] memberNameOrId) {
    Result result = null;
    try {
        Set<RegionInformation> regionInfoSet = new LinkedHashSet<RegionInformation>();
        ResultCollector<?, ?> rc = null;
        Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        TabularResultData resultData = ResultBuilder.createTabularResultData();
        rc = CliUtil.executeFunction(getRegionsFunction, null, targetMembers);
        ArrayList<?> resultList = (ArrayList<?>) rc.getResult();
        if (resultList != null) {
            Iterator<?> iters = resultList.iterator();
            while (iters.hasNext()) {
                Object resultObj = iters.next();
                if (resultObj != null) {
                    if (resultObj instanceof Object[]) {
                        Object[] resultObjectArray = (Object[]) resultObj;
                        for (Object regionInfo : resultObjectArray) {
                            if (regionInfo instanceof RegionInformation) {
                                regionInfoSet.add((RegionInformation) regionInfo);
                            }
                        }
                    }
                }
            }
            Set<String> regionNames = new TreeSet<String>();
            for (RegionInformation regionInfo : regionInfoSet) {
                regionNames.add(regionInfo.getName());
                Set<String> subRegionNames = regionInfo.getSubRegionNames();
                for (String subRegionName : subRegionNames) {
                    regionNames.add(subRegionName);
                }
            }
            for (String regionName : regionNames) {
                resultData.accumulate("List of regions", regionName);
            }
            if (!regionNames.isEmpty()) {
                result = ResultBuilder.buildResult(resultData);
            } else {
                result = ResultBuilder.createInfoResult(CliStrings.LIST_REGION__MSG__NOT_FOUND);
            }
        }
    } catch (FunctionInvocationTargetException e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.LIST_REGION));
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.LIST_REGION__MSG__ERROR + " : " + e.getMessage());
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RegionInformation(org.apache.geode.management.internal.cli.domain.RegionInformation) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) Result(org.apache.geode.management.cli.Result) TreeSet(java.util.TreeSet) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 34 with ResourceOperation

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

the class FunctionCommands method listFunction.

@CliCommand(value = CliStrings.LIST_FUNCTION, help = CliStrings.LIST_FUNCTION__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_FUNCTION })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listFunction(@CliOption(key = CliStrings.LIST_FUNCTION__MATCHES, help = CliStrings.LIST_FUNCTION__MATCHES__HELP) String matches, @CliOption(key = CliStrings.LIST_FUNCTION__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_FUNCTION__GROUP__HELP) String[] groups, @CliOption(key = CliStrings.LIST_FUNCTION__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_FUNCTION__MEMBER__HELP) String[] members) {
    TabularResultData tabularData = ResultBuilder.createTabularResultData();
    boolean accumulatedData = false;
    InternalCache cache = getCache();
    Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, members);
    if (targetMembers.isEmpty()) {
        return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
    }
    try {
        ResultCollector<?, ?> rc = CliUtil.executeFunction(this.listFunctionFunction, new Object[] { matches }, targetMembers);
        List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
        for (CliFunctionResult result : results) {
            if (result.getThrowable() != null) {
                tabularData.accumulate("Member", result.getMemberIdOrName());
                tabularData.accumulate("Function", "<ERROR: " + result.getThrowable().getMessage() + ">");
                accumulatedData = true;
                tabularData.setStatus(Status.ERROR);
            } else if (result.isSuccessful()) {
                String[] strings = (String[]) result.getSerializables();
                Arrays.sort(strings);
                for (int i = 0; i < strings.length; i++) {
                    tabularData.accumulate("Member", result.getMemberIdOrName());
                    tabularData.accumulate("Function", strings[i]);
                    accumulatedData = true;
                }
            }
        }
        if (!accumulatedData) {
            return ResultBuilder.createInfoResult(CliStrings.LIST_FUNCTION__NO_FUNCTIONS_FOUND_ERROR_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 functions: " + 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) InternalCache(org.apache.geode.internal.cache.InternalCache) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 35 with ResourceOperation

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

the class DeployCommands method undeploy.

/**
   * Undeploy one or more JAR files from members of a group or all members.
   * 
   * @param groups Group(s) to undeploy the JAR from or null for all members
   * @param jars JAR(s) to undeploy (separated by comma)
   * @return The result of the attempt to undeploy
   */
@CliCommand(value = { CliStrings.UNDEPLOY }, help = CliStrings.UNDEPLOY__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result undeploy(@CliOption(key = { CliStrings.UNDEPLOY__GROUP }, help = CliStrings.UNDEPLOY__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) String[] groups, @CliOption(key = { CliStrings.UNDEPLOY__JAR }, help = CliStrings.UNDEPLOY__JAR__HELP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE) String jars) {
    try {
        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(this.undeployFunction, new Object[] { jars }, targetMembers);
        List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
        for (CliFunctionResult result : results) {
            if (result.getThrowable() != null) {
                tabularData.accumulate("Member", result.getMemberIdOrName());
                tabularData.accumulate("Un-Deployed JAR", "");
                tabularData.accumulate("Un-Deployed 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("Un-Deployed JAR", strings[i]);
                    tabularData.accumulate("Un-Deployed From JAR Location", strings[i + 1]);
                    accumulatedData = true;
                }
            }
        }
        if (!accumulatedData) {
            return ResultBuilder.createInfoResult(CliStrings.UNDEPLOY__NO_JARS_FOUND_MESSAGE);
        }
        Result result = ResultBuilder.buildResult(tabularData);
        if (tabularData.getStatus().equals(Status.OK)) {
            persistClusterConfiguration(result, () -> getSharedConfiguration().removeJars(jars == null ? null : jars.split(","), groups));
        }
        return result;
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        return ResultBuilder.createGemFireErrorResult("Exception while attempting to un-deploy: " + th.getClass().getName() + ": " + th.getMessage());
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ConverterHint(org.apache.geode.management.cli.ConverterHint) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) FileResult(org.apache.geode.management.internal.cli.result.FileResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) 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)

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