use of org.apache.geode.management.internal.SystemManagementService 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.management.internal.SystemManagementService in project geode by apache.
the class WanCommands method statusGatewaySender.
@CliCommand(value = CliStrings.STATUS_GATEWAYSENDER, help = CliStrings.STATUS_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result statusGatewaySender(@CliOption(key = CliStrings.STATUS_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.STATUS_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.STATUS_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STATUS_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STATUS_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STATUS_GATEWAYSENDER__MEMBER__HELP) String[] onMember) {
Result result = null;
if (senderId != null)
senderId = senderId.trim();
try {
InternalCache cache = getCache();
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
GatewaySenderMXBean bean = null;
CompositeResultData crd = ResultBuilder.createCompositeResultData();
TabularResultData availableSenderData = crd.addSection(CliStrings.SECTION_GATEWAY_SENDER_AVAILABLE).addTable(CliStrings.TABLE_GATEWAY_SENDER);
TabularResultData notAvailableSenderData = crd.addSection(CliStrings.SECTION_GATEWAY_SENDER_NOT_AVAILABLE).addTable(CliStrings.TABLE_GATEWAY_SENDER);
Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
if (dsMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
for (DistributedMember member : dsMembers) {
if (cache.getDistributedSystem().getDistributedMember().getId().equals(member.getId())) {
bean = service.getLocalGatewaySenderMXBean(senderId);
} else {
ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
}
if (bean != null) {
buildSenderStatus(member.getId(), bean, availableSenderData);
} else {
buildSenderStatus(member.getId(), bean, notAvailableSenderData);
}
}
result = ResultBuilder.buildResult(crd);
} catch (Exception e) {
LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.SystemManagementService in project geode by apache.
the class WanCommands method stopGatewayReceiver.
@CliCommand(value = CliStrings.STOP_GATEWAYRECEIVER, help = CliStrings.STOP_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result stopGatewayReceiver(@CliOption(key = CliStrings.STOP_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STOP_GATEWAYRECEIVER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STOP_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STOP_GATEWAYRECEIVER__MEMBER__HELP) String[] onMember) {
Result result = null;
try {
InternalCache cache = getCache();
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
GatewayReceiverMXBean receieverBean = null;
TabularResultData resultData = ResultBuilder.createTabularResultData();
Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
if (dsMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
for (DistributedMember member : dsMembers) {
ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
if (gatewayReceiverObjectName != null) {
receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
if (receieverBean != null) {
if (receieverBean.isRunning()) {
receieverBean.stop();
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_STOPPED_ON_MEMBER_0, new Object[] { member.getId() }));
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_RUNNING_ON_MEMBER_0, new Object[] { member.getId() }));
}
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0, new Object[] { member.getId() }));
}
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0, new Object[] { member.getId() }));
}
}
result = ResultBuilder.buildResult(resultData);
} catch (CommandResultException crex) {
result = handleCommandResultException(crex);
} catch (Exception e) {
LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.SystemManagementService in project geode by apache.
the class WanCommands method startGatewaySender.
@CliCommand(value = CliStrings.START_GATEWAYSENDER, help = CliStrings.START_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result startGatewaySender(@CliOption(key = CliStrings.START_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.START_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.START_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.START_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.START_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.START_GATEWAYSENDER__MEMBER__HELP) String[] onMember) {
Result result = null;
final String id = senderId.trim();
try {
final InternalCache cache = getCache();
final SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
TabularResultData resultData = ResultBuilder.createTabularResultData();
Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
if (dsMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ExecutorService execService = Executors.newCachedThreadPool(new ThreadFactory() {
AtomicInteger threadNum = new AtomicInteger();
public Thread newThread(final Runnable r) {
Thread result = new Thread(r, "Start Sender Command Thread " + threadNum.incrementAndGet());
result.setDaemon(true);
return result;
}
});
List<Callable<List>> callables = new ArrayList<Callable<List>>();
for (final DistributedMember member : dsMembers) {
callables.add(new Callable<List>() {
public List call() throws Exception {
GatewaySenderMXBean bean = null;
ArrayList<String> statusList = new ArrayList<String>();
if (cache.getDistributedSystem().getDistributedMember().getId().equals(member.getId())) {
bean = service.getLocalGatewaySenderMXBean(id);
} else {
ObjectName objectName = service.getGatewaySenderMBeanName(member, id);
bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
}
if (bean != null) {
if (bean.isRunning()) {
statusList.add(member.getId());
statusList.add(CliStrings.GATEWAY_ERROR);
statusList.add(CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_ALREADY_STARTED_ON_MEMBER_1, new Object[] { id, member.getId() }));
} else {
bean.start();
statusList.add(member.getId());
statusList.add(CliStrings.GATEWAY_OK);
statusList.add(CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_STARTED_ON_MEMBER_1, new Object[] { id, member.getId() }));
}
} else {
statusList.add(member.getId());
statusList.add(CliStrings.GATEWAY_ERROR);
statusList.add(CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1, new Object[] { id, member.getId() }));
}
return statusList;
}
});
}
Iterator<DistributedMember> memberIterator = dsMembers.iterator();
List<Future<List>> futures = null;
try {
futures = execService.invokeAll(callables);
} catch (InterruptedException ite) {
accumulateStartResult(resultData, null, CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_INVOKED_DUE_TO_1, new Object[] { id, ite.getMessage() }));
}
for (Future<List> future : futures) {
DistributedMember member = memberIterator.next();
List<String> memberStatus = null;
try {
memberStatus = future.get();
accumulateStartResult(resultData, memberStatus.get(0), memberStatus.get(1), memberStatus.get(2));
} catch (InterruptedException ite) {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_STARTED_ON_MEMBER_DUE_TO_1, new Object[] { id, ite.getMessage() }));
continue;
} catch (ExecutionException ee) {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_STARTED_ON_MEMBER_DUE_TO_1, new Object[] { id, ee.getMessage() }));
continue;
}
}
execService.shutdown();
result = ResultBuilder.buildResult(resultData);
} catch (Exception e) {
LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.SystemManagementService in project geode by apache.
the class WanCommands method stopGatewaySender.
@CliCommand(value = CliStrings.STOP_GATEWAYSENDER, help = CliStrings.STOP_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result stopGatewaySender(@CliOption(key = CliStrings.STOP_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.STOP_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.STOP_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STOP_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STOP_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STOP_GATEWAYSENDER__MEMBER__HELP) String[] onMember) {
Result result = null;
if (senderId != null)
senderId = senderId.trim();
try {
InternalCache cache = getCache();
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
GatewaySenderMXBean bean = null;
TabularResultData resultData = ResultBuilder.createTabularResultData();
Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
if (dsMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
for (DistributedMember member : dsMembers) {
if (cache.getDistributedSystem().getDistributedMember().getId().equals(member.getId())) {
bean = service.getLocalGatewaySenderMXBean(senderId);
} else {
ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
}
if (bean != null) {
if (bean.isRunning()) {
bean.stop();
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_STOPPED_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_RUNNING_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
}
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
}
}
result = ResultBuilder.buildResult(resultData);
} catch (Exception e) {
LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
}
return result;
}
Aggregations