use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class DistributedRegion method initMembershipRoles.
private void initMembershipRoles() {
synchronized (this.advisorListener) {
// hold sync to prevent listener from changing initial members
Set others = this.distAdvisor.addMembershipListenerAndAdviseGeneric(this.advisorListener);
this.advisorListener.addMembers(others);
// initialize missing required roles with initial member info
if (getMembershipAttributes().hasRequiredRoles()) {
// AdvisorListener will also sync on missingRequiredRoles
synchronized (this.missingRequiredRoles) {
this.missingRequiredRoles.addAll(getMembershipAttributes().getRequiredRoles());
// remove all the roles we are playing since they will never be
// missing
this.missingRequiredRoles.removeAll(getSystem().getDistributedMember().getRoles());
for (Object other1 : others) {
DistributedMember other = (DistributedMember) other1;
this.missingRequiredRoles.removeAll(other.getRoles());
}
}
}
}
if (getMembershipAttributes().hasRequiredRoles()) {
// wait up to memberTimeout for required roles...
// boolean requiredRolesAreMissing = false;
int memberTimeout = getSystem().getConfig().getMemberTimeout();
if (logger.isDebugEnabled()) {
logger.debug("Waiting up to {} for required roles.", memberTimeout);
}
try {
if (this.giiMissingRequiredRoles) {
// force reliability loss and possibly resumption
this.isInitializingThread = true;
synchronized (this.advisorListener) {
synchronized (this.missingRequiredRoles) {
// forcing state of loss because of bad GII
this.isMissingRequiredRoles = true;
getCachePerfStats().incReliableRegionsMissing(1);
if (getMembershipAttributes().getLossAction().isAllAccess())
// rahul
getCachePerfStats().incReliableRegionsMissingFullAccess(1);
else if (getMembershipAttributes().getLossAction().isLimitedAccess())
getCachePerfStats().incReliableRegionsMissingLimitedAccess(1);
else if (getMembershipAttributes().getLossAction().isNoAccess())
getCachePerfStats().incReliableRegionsMissingNoAccess(1);
// pur code to increment the stats.
if (logger.isDebugEnabled()) {
logger.debug("GetInitialImage had missing required roles.");
}
// TODO: will this work with RECONNECT and REINITIALIZE?
this.isInitializingThread = true;
lostReliability(null, null);
if (this.missingRequiredRoles.isEmpty()) {
// all required roles are present so force resumption
this.isMissingRequiredRoles = false;
getCachePerfStats().incReliableRegionsMissing(-1);
if (getMembershipAttributes().getLossAction().isAllAccess())
// rahul
getCachePerfStats().incReliableRegionsMissingFullAccess(-1);
else if (getMembershipAttributes().getLossAction().isLimitedAccess())
getCachePerfStats().incReliableRegionsMissingLimitedAccess(-1);
else if (getMembershipAttributes().getLossAction().isNoAccess())
getCachePerfStats().incReliableRegionsMissingNoAccess(-1);
// pur code to increment the stats.
boolean async = resumeReliability(null, null);
if (async) {
this.advisorListener.destroyed = true;
}
}
}
}
} else {
if (!getSystem().isLoner()) {
waitForRequiredRoles(memberTimeout);
}
synchronized (this.advisorListener) {
synchronized (this.missingRequiredRoles) {
if (this.missingRequiredRoles.isEmpty()) {
Assert.assertTrue(!this.isMissingRequiredRoles);
if (logger.isDebugEnabled()) {
logger.debug("Initialization completed with all required roles present.");
}
} else {
// starting in state of loss...
this.isMissingRequiredRoles = true;
getCachePerfStats().incReliableRegionsMissing(1);
if (getMembershipAttributes().getLossAction().isAllAccess())
// rahul
getCachePerfStats().incReliableRegionsMissingFullAccess(1);
else if (getMembershipAttributes().getLossAction().isLimitedAccess())
getCachePerfStats().incReliableRegionsMissingLimitedAccess(1);
else if (getMembershipAttributes().getLossAction().isNoAccess())
getCachePerfStats().incReliableRegionsMissingNoAccess(1);
if (logger.isDebugEnabled()) {
logger.debug("Initialization completed with missing required roles: {}", this.missingRequiredRoles);
}
this.isInitializingThread = true;
lostReliability(null, null);
}
}
}
}
} catch (RegionDestroyedException ignore) {
// ignore to fix bug 34639 may be thrown by waitForRequiredRoles
} catch (CancelException e) {
// ignore to fix bug 34639 may be thrown by waitForRequiredRoles
if (this.isInitializingThread) {
throw e;
}
} catch (Exception e) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributedRegion_UNEXPECTED_EXCEPTION), e);
}
}
// open latch which will allow any threads in lostReliability to proceed
this.initializationLatchAfterMemberTimeout.countDown();
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PartitionedRegion method executeOnBucketSet.
public ResultCollector executeOnBucketSet(final Function function, PartitionedRegionFunctionExecutor execution, ResultCollector rc, Set<Integer> bucketSet) {
Set<Integer> actualBucketSet = this.getRegionAdvisor().getBucketSet();
try {
bucketSet.retainAll(actualBucketSet);
} catch (NoSuchElementException ignore) {
// done
}
HashMap<InternalDistributedMember, HashSet<Integer>> memberToBuckets = FunctionExecutionNodePruner.groupByMemberToBuckets(this, bucketSet, function.optimizeForWrite());
if (memberToBuckets.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("Executing on bucketset : {} executeOnBucketSet Member to buckets map is : {} bucketSet is empty", bucketSet, memberToBuckets);
}
throw new EmptyRegionFunctionException(LocalizedStrings.PartitionedRegion_FUNCTION_NOT_EXECUTED_AS_REGION_IS_EMPTY.toLocalizedString());
} else {
if (logger.isDebugEnabled()) {
logger.debug("Executing on bucketset : {} executeOnBucketSet Member to buckets map is : {}", bucketSet, memberToBuckets);
}
}
if (memberToBuckets.size() > 1) {
for (InternalDistributedMember targetNode : memberToBuckets.keySet()) {
if (!targetNode.equals(getMyId())) {
for (Integer bucketId : memberToBuckets.get(targetNode)) {
Set<ServerBucketProfile> profiles = this.getRegionAdvisor().getClientBucketProfiles(bucketId);
if (profiles != null) {
for (ServerBucketProfile profile : profiles) {
if (profile.getDistributedMember().equals(targetNode)) {
if (logger.isDebugEnabled()) {
logger.debug("FunctionServiceSingleHop: Found multiple nodes for executing on bucket set.{}", getMyId());
}
throw new InternalFunctionInvocationTargetException(LocalizedStrings.PartitionedRegion_MULTIPLE_TARGET_NODE_FOUND_FOR.toLocalizedString());
}
}
}
}
}
}
}
execution = (PartitionedRegionFunctionExecutor) execution.withFilter(new HashSet());
while (!execution.getFailedNodes().isEmpty()) {
Set memberKeySet = memberToBuckets.keySet();
RetryTimeKeeper retryTime = new RetryTimeKeeper(this.retryTimeout);
Iterator iterator = memberKeySet.iterator();
boolean hasRemovedNode = false;
while (iterator.hasNext()) {
if (execution.getFailedNodes().contains(((DistributedMember) iterator.next()).getId())) {
hasRemovedNode = true;
}
}
if (hasRemovedNode) {
if (retryTime.overMaximum()) {
PRHARedundancyProvider.timedOut(this, null, null, "doing function execution", this.retryTimeout);
// NOTREACHED
}
retryTime.waitToRetryNode();
memberToBuckets = FunctionExecutionNodePruner.groupByMemberToBuckets(this, bucketSet, function.optimizeForWrite());
} else {
execution.clearFailedNodes();
}
}
Set<InternalDistributedMember> dest = memberToBuckets.keySet();
if (function.optimizeForWrite() && cache.getInternalResourceManager().getHeapMonitor().containsHeapCriticalMembers(dest) && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
Set<InternalDistributedMember> hcm = cache.getResourceAdvisor().adviseCritialMembers();
Set<DistributedMember> sm = SetUtils.intersection(hcm, dest);
throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(function.getId(), sm), sm);
}
boolean isSelf = false;
execution.setExecutionNodes(dest);
final Set localBucketSet = memberToBuckets.remove(getMyId());
if (localBucketSet != null) {
isSelf = true;
}
final HashMap<InternalDistributedMember, FunctionRemoteContext> recipMap = new HashMap<InternalDistributedMember, FunctionRemoteContext>();
for (InternalDistributedMember recip : dest) {
FunctionRemoteContext context = new FunctionRemoteContext(function, execution.getArgumentsForMember(recip.getId()), null, memberToBuckets.get(recip), execution.isReExecute(), execution.isFnSerializationReqd());
recipMap.put(recip, context);
}
final LocalResultCollector<?, ?> localRC = execution.getLocalResultCollector(function, rc);
final DM dm = getDistributionManager();
final PartitionedRegionFunctionResultSender resultSender = new PartitionedRegionFunctionResultSender(dm, this, 0L, localRC, execution.getServerResultSender(), recipMap.isEmpty(), !isSelf, execution.isForwardExceptions(), function, localBucketSet);
// execute locally and collect the result
if (isSelf && this.dataStore != null) {
final RegionFunctionContextImpl prContext = new RegionFunctionContextImpl(function.getId(), PartitionedRegion.this, execution.getArgumentsForMember(getMyId().getId()), null, ColocationHelper.constructAndGetAllColocatedLocalDataSet(PartitionedRegion.this, localBucketSet), localBucketSet, resultSender, execution.isReExecute());
execution.executeFunctionOnLocalNode(function, prContext, resultSender, dm, isTX());
}
PartitionedRegionFunctionResultWaiter resultReciever = new PartitionedRegionFunctionResultWaiter(getSystem(), this.getPRId(), localRC, function, resultSender);
return resultReciever.getPartitionedDataFrom(recipMap, this, execution);
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class ClientCommands method describeClient.
@CliCommand(value = CliStrings.DESCRIBE_CLIENT, help = CliStrings.DESCRIBE_CLIENT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_CLIENT })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeClient(@CliOption(key = CliStrings.DESCRIBE_CLIENT__ID, mandatory = true, help = CliStrings.DESCRIBE_CLIENT__ID__HELP) String clientId) {
Result result = null;
if (clientId.startsWith("\"")) {
clientId = clientId.substring(1);
}
if (clientId.endsWith("\"")) {
clientId = clientId.substring(0, clientId.length() - 2);
}
if (clientId.endsWith("\";")) {
clientId = clientId.substring(0, clientId.length() - 2);
}
try {
CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
SectionResultData sectionResult = compositeResultData.addSection("InfoSection");
InternalCache cache = getCache();
ManagementService service = ManagementService.getExistingManagementService(cache);
ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();
if (cacheServers.length == 0) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
}
ClientHealthStatus clientHealthStatus = null;
for (ObjectName objName : cacheServers) {
CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class);
List<String> listOfClient = new ArrayList<String>(Arrays.asList((String[]) serverMbean.getClientIds()));
if (listOfClient.contains(clientId)) {
if (clientHealthStatus == null) {
try {
clientHealthStatus = serverMbean.showClientStats(clientId);
if (clientHealthStatus == null) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_STATS_FOR_CLIENT_0, clientId));
}
} catch (Exception eee) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_STATS_FOR_CLIENT_0_REASON_1, clientId, eee.getMessage()));
}
}
}
}
if (clientHealthStatus == null) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT__CLIENT__ID__NOT__FOUND__0, clientId));
}
Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
String isDurable = null;
List<String> primaryServers = new ArrayList<String>();
List<String> secondaryServers = new ArrayList<String>();
if (dsMembers.size() > 0) {
ContunuousQueryFunction contunuousQueryFunction = new ContunuousQueryFunction();
FunctionService.registerFunction(contunuousQueryFunction);
List<?> resultList = (List<?>) CliUtil.executeFunction(contunuousQueryFunction, clientId, dsMembers).getResult();
for (int i = 0; i < resultList.size(); i++) {
try {
Object object = resultList.get(i);
if (object instanceof Throwable) {
LogWrapper.getInstance().warning("Exception in Describe Client " + ((Throwable) object).getMessage(), ((Throwable) object));
continue;
}
if (object != null) {
ClientInfo objectResult = (ClientInfo) object;
isDurable = objectResult.isDurable;
if (objectResult.primaryServer != null && objectResult.primaryServer.length() > 0) {
if (primaryServers.size() == 0) {
primaryServers.add(objectResult.primaryServer);
} else {
primaryServers.add(" ,");
primaryServers.add(objectResult.primaryServer);
}
}
if (objectResult.secondaryServer != null && objectResult.secondaryServer.length() > 0) {
if (secondaryServers.size() == 0) {
secondaryServers.add(objectResult.secondaryServer);
} else {
secondaryServers.add(" ,");
secondaryServers.add(objectResult.secondaryServer);
}
}
}
} catch (Exception e) {
LogWrapper.getInstance().info(CliStrings.DESCRIBE_CLIENT_ERROR_FETCHING_STATS_0 + " :: " + CliUtil.stackTraceAsString(e));
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_ERROR_FETCHING_STATS_0, e.getMessage()));
}
}
buildTableResult(sectionResult, clientHealthStatus, isDurable, primaryServers, secondaryServers);
result = ResultBuilder.buildResult(compositeResultData);
} else {
return ResultBuilder.createGemFireErrorResult(CliStrings.DESCRIBE_CLIENT_NO_MEMBERS);
}
} catch (Exception e) {
LogWrapper.getInstance().info("Error in decribe clients. stack trace" + CliUtil.stackTraceAsString(e));
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_CLIENT_0, e.getMessage()));
}
LogWrapper.getInstance().info("decribe client result " + result);
return result;
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class ConfigCommands method alterRuntimeConfig.
@CliCommand(value = { CliStrings.ALTER_RUNTIME_CONFIG }, help = CliStrings.ALTER_RUNTIME_CONFIG__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG }, interceptor = "org.apache.geode.management.internal.cli.commands.ConfigCommands$AlterRuntimeInterceptor")
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE)
public Result alterRuntimeConfig(@CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__MEMBER }, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.ALTER_RUNTIME_CONFIG__MEMBER__HELP) String[] memberNameOrId, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__GROUP }, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.ALTER_RUNTIME_CONFIG__MEMBER__HELP) String[] group, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT }, help = CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT__HELP) Integer archiveDiskSpaceLimit, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT }, help = CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT__HELP) Integer archiveFileSizeLimit, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT }, help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT__HELP) Integer logDiskSpaceLimit, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT }, help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT__HELP) Integer logFileSizeLimit, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL }, optionContext = ConverterHint.LOG_LEVEL, help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL__HELP) String logLevel, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE }, help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE__HELP) String statisticArchiveFile, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE }, help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE__HELP) Integer statisticSampleRate, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED }, help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED__HELP) Boolean statisticSamplingEnabled, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ }, specifiedDefaultValue = "false", help = CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ__HELP) Boolean setCopyOnRead, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE }, help = CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE__HELP) Integer lockLease, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT }, help = CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT__HELP) Integer lockTimeout, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL }, help = CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL__HELP) Integer messageSyncInterval, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT }, help = CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT__HELP) Integer searchTimeout) {
Map<String, String> runTimeDistributionConfigAttributes = new HashMap<>();
Map<String, String> rumTimeCacheAttributes = new HashMap<>();
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
if (archiveDiskSpaceLimit != null) {
runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, archiveDiskSpaceLimit.toString());
}
if (archiveFileSizeLimit != null) {
runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, archiveFileSizeLimit.toString());
}
if (logDiskSpaceLimit != null) {
runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, logDiskSpaceLimit.toString());
}
if (logFileSizeLimit != null) {
runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, logFileSizeLimit.toString());
}
if (logLevel != null && !logLevel.isEmpty()) {
runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, logLevel);
}
if (statisticArchiveFile != null && !statisticArchiveFile.isEmpty()) {
runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, statisticArchiveFile);
}
if (statisticSampleRate != null) {
runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, statisticSampleRate.toString());
}
if (statisticSamplingEnabled != null) {
runTimeDistributionConfigAttributes.put(STATISTIC_SAMPLING_ENABLED, statisticSamplingEnabled.toString());
}
// Attributes that are set on the cache.
if (setCopyOnRead != null) {
rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ, setCopyOnRead.toString());
}
if (lockLease != null && lockLease > 0 && lockLease < Integer.MAX_VALUE) {
rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE, lockLease.toString());
}
if (lockTimeout != null && lockTimeout > 0 && lockTimeout < Integer.MAX_VALUE) {
rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT, lockTimeout.toString());
}
if (messageSyncInterval != null && messageSyncInterval > 0 && messageSyncInterval < Integer.MAX_VALUE) {
rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL, messageSyncInterval.toString());
}
if (searchTimeout != null && searchTimeout > 0 && searchTimeout < Integer.MAX_VALUE) {
rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT, searchTimeout.toString());
}
if (runTimeDistributionConfigAttributes.isEmpty() && rumTimeCacheAttributes.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.ALTER_RUNTIME_CONFIG__RELEVANT__OPTION__MESSAGE);
}
Map<String, String> allRunTimeAttributes = new HashMap<>();
allRunTimeAttributes.putAll(runTimeDistributionConfigAttributes);
allRunTimeAttributes.putAll(rumTimeCacheAttributes);
ResultCollector<?, ?> rc = CliUtil.executeFunction(alterRunTimeConfigFunction, allRunTimeAttributes, targetMembers);
List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
Set<String> successfulMembers = new TreeSet<>();
Set<String> errorMessages = new TreeSet<>();
for (CliFunctionResult result : results) {
if (result.getThrowable() != null) {
logger.info("Function failed: " + result.getThrowable());
errorMessages.add(result.getThrowable().getMessage());
} else {
successfulMembers.add(result.getMemberIdOrName());
}
}
final String lineSeparator = System.getProperty("line.separator");
if (!successfulMembers.isEmpty()) {
StringBuilder successMessageBuilder = new StringBuilder();
successMessageBuilder.append(CliStrings.ALTER_RUNTIME_CONFIG__SUCCESS__MESSAGE);
successMessageBuilder.append(lineSeparator);
for (String member : successfulMembers) {
successMessageBuilder.append(member);
successMessageBuilder.append(lineSeparator);
}
Properties properties = new Properties();
properties.putAll(runTimeDistributionConfigAttributes);
Result result = ResultBuilder.createInfoResult(successMessageBuilder.toString());
// Set the Cache attributes to be modified
final XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.CACHE).withAttributes(rumTimeCacheAttributes).build();
persistClusterConfiguration(result, () -> getSharedConfiguration().modifyXmlAndProperties(properties, xmlEntity, group));
return result;
} else {
StringBuilder errorMessageBuilder = new StringBuilder();
errorMessageBuilder.append("Following errors occurred while altering runtime config");
errorMessageBuilder.append(lineSeparator);
for (String errorMessage : errorMessages) {
errorMessageBuilder.append(errorMessage);
errorMessageBuilder.append(lineSeparator);
}
return ResultBuilder.createUserErrorResult(errorMessageBuilder.toString());
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class ConfigCommands method describeConfig.
@CliCommand(value = { CliStrings.DESCRIBE_CONFIG }, help = CliStrings.DESCRIBE_CONFIG__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeConfig(@CliOption(key = CliStrings.DESCRIBE_CONFIG__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_CONFIG__MEMBER__HELP, mandatory = true) String memberNameOrId, @CliOption(key = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS, help = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS__HELP, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true") boolean hideDefaults) {
Result result = null;
try {
DistributedMember targetMember = null;
if (memberNameOrId != null && !memberNameOrId.isEmpty()) {
targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
}
if (targetMember != null) {
ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberConfigFunction, new Boolean(hideDefaults), targetMember);
ArrayList<?> output = (ArrayList<?>) rc.getResult();
Object obj = output.get(0);
if (obj != null && obj instanceof MemberConfigurationInfo) {
MemberConfigurationInfo memberConfigInfo = (MemberConfigurationInfo) obj;
CompositeResultData crd = ResultBuilder.createCompositeResultData();
crd.setHeader(CliStrings.format(CliStrings.DESCRIBE_CONFIG__HEADER__TEXT, memberNameOrId));
List<String> jvmArgsList = memberConfigInfo.getJvmInputArguments();
TabularResultData jvmInputArgs = crd.addSection().addSection().addTable();
for (String jvmArg : jvmArgsList) {
jvmInputArgs.accumulate("JVM command line arguments", jvmArg);
}
addSection(crd, memberConfigInfo.getGfePropsSetUsingApi(), "GemFire properties defined using the API");
addSection(crd, memberConfigInfo.getGfePropsRuntime(), "GemFire properties defined at the runtime");
addSection(crd, memberConfigInfo.getGfePropsSetFromFile(), "GemFire properties defined with the property file");
addSection(crd, memberConfigInfo.getGfePropsSetWithDefaults(), "GemFire properties using default values");
addSection(crd, memberConfigInfo.getCacheAttributes(), "Cache attributes");
List<Map<String, String>> cacheServerAttributesList = memberConfigInfo.getCacheServerAttributes();
if (cacheServerAttributesList != null && !cacheServerAttributesList.isEmpty()) {
SectionResultData cacheServerSection = crd.addSection();
cacheServerSection.setHeader("Cache-server attributes");
for (Map<String, String> cacheServerAttributes : cacheServerAttributesList) {
addSubSection(cacheServerSection, cacheServerAttributes, "");
}
}
result = ResultBuilder.buildResult(crd);
}
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(CliStrings.format(CliStrings.DESCRIBE_CONFIG__MEMBER__NOT__FOUND, new Object[] { memberNameOrId }));
result = ResultBuilder.buildResult(erd);
}
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.DESCRIBE_CONFIG));
} catch (Exception e) {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(e.getMessage());
result = ResultBuilder.buildResult(erd);
}
return result;
}
Aggregations