Search in sources :

Example 21 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class RegionCreateFunction method execute.

@Override
public void execute(FunctionContext context) {
    ResultSender<Object> resultSender = context.getResultSender();
    Cache cache = CacheFactory.getAnyInstance();
    String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    RegionFunctionArgs regionCreateArgs = (RegionFunctionArgs) context.getArguments();
    if (regionCreateArgs.isSkipIfExists()) {
        Region<Object, Object> region = cache.getRegion(regionCreateArgs.getRegionPath());
        if (region != null) {
            resultSender.lastResult(new CliFunctionResult(memberNameOrId, true, CliStrings.format(CliStrings.CREATE_REGION__MSG__SKIPPING_0_REGION_PATH_1_ALREADY_EXISTS, new Object[] { memberNameOrId, regionCreateArgs.getRegionPath() })));
            return;
        }
    }
    try {
        Region<?, ?> createdRegion = createRegion(cache, regionCreateArgs);
        XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", createdRegion.getName());
        resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format(CliStrings.CREATE_REGION__MSG__REGION_0_CREATED_ON_1, new Object[] { createdRegion.getFullPath(), memberNameOrId })));
    } catch (IllegalStateException e) {
        String exceptionMsg = e.getMessage();
        String localizedString = LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString();
        if (localizedString.equals(e.getMessage())) {
            exceptionMsg = exceptionMsg + " " + CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ONE_OF_THESE_SHORTCUTS_0, new Object[] { String.valueOf(CreateAlterDestroyRegionCommands.PERSISTENT_OVERFLOW_SHORTCUTS) });
        }
        resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, null));
    } catch (IllegalArgumentException e) {
        resultSender.lastResult(handleException(memberNameOrId, e.getMessage(), e));
    } catch (RegionExistsException e) {
        String exceptionMsg = CliStrings.format(CliStrings.CREATE_REGION__MSG__REGION_PATH_0_ALREADY_EXISTS_ON_1, new Object[] { regionCreateArgs.getRegionPath(), memberNameOrId });
        resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
    } catch (CreateSubregionException e) {
        resultSender.lastResult(handleException(memberNameOrId, e.getMessage(), e));
    } catch (Exception e) {
        String exceptionMsg = e.getMessage();
        if (exceptionMsg == null) {
            exceptionMsg = CliUtil.stackTraceAsString(e);
        }
        resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
    }
}
Also used : RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CreateSubregionException(org.apache.geode.management.internal.cli.exceptions.CreateSubregionException) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CreateSubregionException(org.apache.geode.management.internal.cli.exceptions.CreateSubregionException) Cache(org.apache.geode.cache.Cache)

Example 22 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class RegionDestroyFunction method execute.

@Override
public void execute(FunctionContext context) {
    String regionPath = null;
    try {
        String functionId = context.getFunctionId();
        if (getId().equals(functionId)) {
            Object arguments = context.getArguments();
            if (arguments != null) {
                regionPath = (String) arguments;
                Cache cache = CacheFactory.getAnyInstance();
                Region<?, ?> region = cache.getRegion(regionPath);
                region.destroyRegion();
                String regionName = regionPath.startsWith(Region.SEPARATOR) ? regionPath.substring(1) : regionPath;
                XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", regionName);
                context.getResultSender().lastResult(new CliFunctionResult("", xmlEntity, regionPath));
            }
        }
        context.getResultSender().lastResult(new CliFunctionResult("", false, "FAILURE"));
    } catch (IllegalStateException e) {
        context.getResultSender().lastResult(new CliFunctionResult("", e, null));
    } catch (Exception ex) {
        context.getResultSender().lastResult(new CliFunctionResult("", new RuntimeException(CliStrings.format(CliStrings.DESTROY_REGION__MSG__ERROR_WHILE_DESTROYING_REGION_0_REASON_1, new Object[] { regionPath, ex.getMessage() })), null));
    }
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) Cache(org.apache.geode.cache.Cache)

Example 23 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class DestroyDiskStoreFunction method execute.

@Override
public void execute(FunctionContext context) {
    // Declared here so that it's available when returning a Throwable
    String memberId = "";
    try {
        final Object[] args = (Object[]) context.getArguments();
        final String diskStoreName = (String) args[0];
        InternalCache cache = getCache();
        DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        memberId = member.getId();
        // If they set a name use it instead
        if (!member.getName().equals("")) {
            memberId = member.getName();
        }
        DiskStore diskStore = cache.findDiskStore(diskStoreName);
        CliFunctionResult result;
        if (diskStore != null) {
            XmlEntity xmlEntity = new XmlEntity(CacheXml.DISK_STORE, "name", diskStoreName);
            diskStore.destroy();
            result = new CliFunctionResult(memberId, xmlEntity, "Success");
        } else {
            result = new CliFunctionResult(memberId, false, "Disk store not found on this member");
        }
        context.getResultSender().lastResult(result);
    } catch (IllegalStateException isex) {
        CliFunctionResult result = new CliFunctionResult(memberId, false, isex.getMessage());
        context.getResultSender().lastResult(result);
    } catch (CacheClosedException cce) {
        CliFunctionResult result = new CliFunctionResult(memberId, false, null);
        context.getResultSender().lastResult(result);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        logger.error("Could not destroy disk store: {}", th.getMessage(), th);
        CliFunctionResult result = new CliFunctionResult(memberId, th, null);
        context.getResultSender().lastResult(result);
    }
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 24 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class CreateIndexFunction method setResultInSender.

private void setResultInSender(FunctionContext context, IndexInfo indexInfo, String memberId, Cache cache, String regionPath) {
    if (regionPath == null) {
        String message = CliStrings.format(CliStrings.CREATE_INDEX__INVALID__REGIONPATH, indexInfo.getRegionPath());
        context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
    } else {
        XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", cache.getRegion(regionPath).getName());
        context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
    }
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity)

Example 25 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class GatewayReceiverCreateFunction method execute.

@Override
public void execute(FunctionContext context) {
    ResultSender<Object> resultSender = context.getResultSender();
    Cache cache = CacheFactory.getAnyInstance();
    String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    GatewayReceiverFunctionArgs gatewayReceiverCreateArgs = (GatewayReceiverFunctionArgs) context.getArguments();
    try {
        GatewayReceiver createdGatewayReceiver = createGatewayReceiver(cache, gatewayReceiverCreateArgs);
        Map<String, String> attributes = new HashMap<String, String>();
        if (gatewayReceiverCreateArgs.getStartPort() != null) {
            attributes.put("start-port", gatewayReceiverCreateArgs.getStartPort().toString());
        }
        if (gatewayReceiverCreateArgs.getEndPort() != null) {
            attributes.put("end-port", gatewayReceiverCreateArgs.getEndPort().toString());
        }
        if (gatewayReceiverCreateArgs.getBindAddress() != null) {
            attributes.put("bind-address", gatewayReceiverCreateArgs.getBindAddress());
        }
        XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.GATEWAY_RECEIVER).withAttributes(attributes).build();
        resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format(CliStrings.CREATE_GATEWAYRECEIVER__MSG__GATEWAYRECEIVER_CREATED_ON_0_ONPORT_1, new Object[] { memberNameOrId, createdGatewayReceiver.getPort() })));
    } catch (IllegalStateException e) {
        resultSender.lastResult(handleException(memberNameOrId, e.getMessage(), e));
    } catch (Exception e) {
        String exceptionMsg = e.getMessage();
        if (exceptionMsg == null) {
            exceptionMsg = CliUtil.stackTraceAsString(e);
        }
        resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
    }
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) HashMap(java.util.HashMap) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver) Cache(org.apache.geode.cache.Cache)

Aggregations

XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)46 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)25 DistributedMember (org.apache.geode.distributed.DistributedMember)18 Cache (org.apache.geode.cache.Cache)17 Result (org.apache.geode.management.cli.Result)17 CliCommand (org.springframework.shell.core.annotation.CliCommand)16 CliMetaData (org.apache.geode.management.cli.CliMetaData)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 InternalCache (org.apache.geode.internal.cache.InternalCache)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)11 Test (org.junit.Test)10 InputStreamReader (java.io.InputStreamReader)9 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 Document (org.w3c.dom.Document)9 Element (org.w3c.dom.Element)9 NodeList (org.w3c.dom.NodeList)9 ConverterHint (org.apache.geode.management.cli.ConverterHint)7