use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class QueryDataFunction method queryData.
public static Object queryData(final String query, final String members, final int limit, final boolean zipResult, final int queryResultSetLimit, final int queryCollectionsDepth) throws Exception {
if (query == null || query.isEmpty()) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__QUERY_EMPTY.toLocalizedString()).toString();
}
Set<DistributedMember> inputMembers = null;
if (StringUtils.isNotBlank(members)) {
inputMembers = new HashSet<>();
StringTokenizer st = new StringTokenizer(members, ",");
while (st.hasMoreTokens()) {
String member = st.nextToken();
DistributedMember distributedMember = BeanUtilFuncs.getDistributedMemberByNameOrId(member);
inputMembers.add(distributedMember);
if (distributedMember == null) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__INVALID_MEMBER.toLocalizedString(member)).toString();
}
}
}
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
try {
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
Set<String> regionsInQuery = compileQuery(cache, query);
// Validate region existence
if (regionsInQuery.size() > 0) {
for (String regionPath : regionsInQuery) {
DistributedRegionMXBean regionMBean = service.getDistributedRegionMXBean(regionPath);
if (regionMBean == null) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND.toLocalizedString(regionPath)).toString();
} else {
Set<DistributedMember> associatedMembers = DataCommands.getRegionAssociatedMembers(regionPath, cache, true);
if (inputMembers != null && inputMembers.size() > 0) {
if (!associatedMembers.containsAll(inputMembers)) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND_ON_MEMBERS.toLocalizedString(regionPath)).toString();
}
}
}
}
} else {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__INVALID_QUERY.toLocalizedString("Region mentioned in query probably missing /")).toString();
}
// Validate
if (regionsInQuery.size() > 1 && inputMembers == null) {
for (String regionPath : regionsInQuery) {
DistributedRegionMXBean regionMBean = service.getDistributedRegionMXBean(regionPath);
if (regionMBean.getRegionType().equals(DataPolicy.PARTITION.toString()) || regionMBean.getRegionType().equals(DataPolicy.PERSISTENT_PARTITION.toString())) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__JOIN_OP_EX.toLocalizedString()).toString();
}
}
}
String randomRegion = regionsInQuery.iterator().next();
Set<DistributedMember> associatedMembers = // First
DataCommands.getQueryRegionsAssociatedMembers(regionsInQuery, cache, false);
if (associatedMembers != null && associatedMembers.size() > 0) {
Object[] functionArgs = new Object[6];
if (inputMembers != null && inputMembers.size() > 0) {
// on input
// members
functionArgs[DISPLAY_MEMBERWISE] = true;
functionArgs[QUERY] = query;
functionArgs[REGION] = randomRegion;
functionArgs[LIMIT] = limit;
functionArgs[QUERY_RESULTSET_LIMIT] = queryResultSetLimit;
functionArgs[QUERY_COLLECTIONS_DEPTH] = queryCollectionsDepth;
return callFunction(functionArgs, inputMembers, zipResult);
} else {
// Query on any random member
functionArgs[DISPLAY_MEMBERWISE] = false;
functionArgs[QUERY] = query;
functionArgs[REGION] = randomRegion;
functionArgs[LIMIT] = limit;
functionArgs[QUERY_RESULTSET_LIMIT] = queryResultSetLimit;
functionArgs[QUERY_COLLECTIONS_DEPTH] = queryCollectionsDepth;
return callFunction(functionArgs, associatedMembers, zipResult);
}
} else {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND.toLocalizedString(regionsInQuery.toString())).toString();
}
} catch (QueryInvalidException qe) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__INVALID_QUERY.toLocalizedString(qe.getMessage())).toString();
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class ConfigCommands method exportConfig.
/**
* Export the cache configuration in XML format.
*
* @param member Member for which to write the configuration
* @param group Group or groups for which to write the configuration
* @return Results of the attempt to write the configuration
*/
@CliCommand(value = { CliStrings.EXPORT_CONFIG }, help = CliStrings.EXPORT_CONFIG__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.ConfigCommands$Interceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportConfig(@CliOption(key = { CliStrings.EXPORT_CONFIG__MEMBER }, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_CONFIG__MEMBER__HELP) String[] member, @CliOption(key = { CliStrings.EXPORT_CONFIG__GROUP }, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.EXPORT_CONFIG__GROUP__HELP) String[] group, @CliOption(key = { CliStrings.EXPORT_CONFIG__DIR }, help = CliStrings.EXPORT_CONFIG__DIR__HELP) String dir) {
InfoResultData infoData = ResultBuilder.createInfoResultData();
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, member);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
try {
ResultCollector<?, ?> rc = CliUtil.executeFunction(this.exportConfigFunction, null, targetMembers);
List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
for (CliFunctionResult result : results) {
if (result.getThrowable() != null) {
infoData.addLine(CliStrings.format(CliStrings.EXPORT_CONFIG__MSG__EXCEPTION, result.getMemberIdOrName(), result.getThrowable()));
} else if (result.isSuccessful()) {
String cacheFileName = result.getMemberIdOrName() + "-cache.xml";
String propsFileName = result.getMemberIdOrName() + "-gf.properties";
String[] fileContent = (String[]) result.getSerializables();
infoData.addAsFile(cacheFileName, fileContent[0], "Downloading Cache XML file: {0}", false);
infoData.addAsFile(propsFileName, fileContent[1], "Downloading properties file: {0}", false);
}
}
return ResultBuilder.buildResult(infoData);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
th.printStackTrace(System.err);
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXPORT_CONFIG__MSG__EXCEPTION, th.getClass().getName() + ": " + th.getMessage()));
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class CreateAlterDestroyRegionCommands method getMembersByIds.
private Set<DistributedMember> getMembersByIds(InternalCache cache, Set<String> memberIds) {
Set<DistributedMember> foundMembers = Collections.emptySet();
if (memberIds != null && !memberIds.isEmpty()) {
foundMembers = new HashSet<>();
Set<DistributedMember> allNormalMembers = CliUtil.getAllNormalMembers(cache);
for (String memberId : memberIds) {
for (DistributedMember distributedMember : allNormalMembers) {
if (memberId.equals(distributedMember.getId()) || memberId.equals(distributedMember.getName())) {
foundMembers.add(distributedMember);
}
}
}
}
return foundMembers;
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class CliUtil method findMembers.
/**
* Finds all Servers which belong to the given arrays of groups or members. Does not include
* locators.
*/
public static Set<DistributedMember> findMembers(String[] groups, String[] members) {
InternalCache cache = getInternalCache();
Set<DistributedMember> allNormalMembers = getAllNormalMembers(cache);
return findMembers(allNormalMembers, groups, members);
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class AbstractRegion method initPostCreateRegionMembershipListeners.
/**
* Initialize any wrapped RegionMembershipListeners in the cache listener list
*/
void initPostCreateRegionMembershipListeners(Set initialMembers) {
synchronized (this.clSync) {
DistributedMember[] members = null;
CacheListener[] newListeners = null;
for (int i = 0; i < this.cacheListeners.length; i++) {
CacheListener cl = this.cacheListeners[i];
if (cl instanceof WrappedRegionMembershipListener) {
WrappedRegionMembershipListener wrml = (WrappedRegionMembershipListener) cl;
if (!wrml.isInitialized()) {
if (members == null) {
members = (DistributedMember[]) initialMembers.toArray(new DistributedMember[initialMembers.size()]);
}
wrml.initialMembers(this, members);
if (newListeners == null) {
newListeners = new CacheListener[this.cacheListeners.length];
System.arraycopy(this.cacheListeners, 0, newListeners, 0, newListeners.length);
}
newListeners[i] = wrml.getWrappedListener();
}
}
}
if (newListeners != null) {
this.cacheListeners = newListeners;
}
}
}
Aggregations