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));
}
}
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));
}
}
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);
}
}
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));
}
}
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));
}
}
Aggregations