@Override public DistributedMember getMemberWithName(String name) { for (DistributedMember id : members.values()) { if (Objects.equals(id.getName(), name)) { return id; } } if (Objects.equals(localAddress, name)) { return localAddress; } return null; }
@Override public DistributedMember getMemberWithName(String name) { for (DistributedMember id : canonicalIds.values()) { if (Objects.equals(id.getName(), name)) { return id; } } if (Objects.equals(localAddress.getName(), name)) { return localAddress; } return null; }
public static String getMemberNameOrId(DistributedMember distributedMember) { String nameOrId = null; if (distributedMember != null) { nameOrId = distributedMember.getName(); nameOrId = nameOrId != null && !nameOrId.isEmpty() ? nameOrId : distributedMember.getId(); } return nameOrId; }
@Override public DistributedMember findDistributedMember(String name) { for (DistributedMember member : dm.getDistributionManagerIdsIncludingAdmin()) { if (member.getName().equals(name)) { return member; } } return null; }
/** * This method returns the name that will be used for a DistributedMember when it is registered as * a JMX bean. * * @param member Member to find the name for * @return The name used to register this member as a JMX bean. */ public static String getMemberNameOrUniqueId(DistributedMember member) { if (member.getName() != null && !member.getName().equals("")) { return makeCompliantName(member.getName()); } return makeCompliantName(member.getUniqueId()); }
public static DistributedMember getDistributedMemberByNameOrId(String memberNameOrId, InternalCache cache) { if (memberNameOrId == null) { return null; } Set<DistributedMember> memberSet = CliUtil.getAllMembers(cache); return memberSet.stream().filter(member -> memberNameOrId.equalsIgnoreCase(member.getId()) || memberNameOrId.equalsIgnoreCase(member.getName())).findFirst().orElse(null); }
public void downloadJarFromLocator(String groupName, String jarName, DistributedMember sourceLocator) throws IllegalStateException, IOException { logger.info("Downloading jar {} from locator {}", jarName, sourceLocator.getName()); createConfigDirIfNecessary(groupName); File jarFile = downloadJar(sourceLocator, groupName, jarName); File jarToWrite = getPathToJarOnThisLocator(groupName, jarName).toFile(); Files.copy(jarFile.toPath(), jarToWrite.toPath(), StandardCopyOption.REPLACE_EXISTING); }
@Test public void getMemberNameOrUniqueIdReturnsNameIfProvided() { String memberName = "member-name"; when(distMember.getName()).thenReturn(memberName); String result = MBeanJMXAdapter.getMemberNameOrUniqueId(distMember); assertThat(result).isEqualTo(memberName); }
@Test public void getMemberNameOrUniqueIdReturnsUniqueIdIfNameIsNotProvided() { when(distMember.getName()).thenReturn(""); String result = MBeanJMXAdapter.getMemberNameOrUniqueId(distMember); assertThat(result).isEqualTo(UNIQUE_ID); } }
@Test public void getMemberReturnsMemberNameInsteadOfId() throws Exception { when(distributedMember.getId()).thenReturn("myId"); when(distributedMember.getName()).thenReturn("myName"); String member = jdbcCommandFunctionContext.getMember(context); assertThat(member).isEqualTo("myName"); }
@Before public void before() { command = spy(ListMembersCommand.class); members = new HashSet<>(); doReturn(members).when(command).findMembersIncludingLocators(any(), any()); member1 = mock(DistributedMember.class); when(member1.getName()).thenReturn("name"); when(member1.getId()).thenReturn("id"); doReturn(member1).when(command).getCoordinator(); member2 = mock(DistributedMember.class); when(member2.getName()).thenReturn("name2"); when(member2.getId()).thenReturn("id2"); // This will enforce the sort order in TreeSet used by ListMembersCommand. when(member1.compareTo(member2)).thenReturn(-1); when(member2.compareTo(member1)).thenReturn(1); }
@Before public void setup() { counter = new AtomicLong(0L); testResultSender = new TestResultSender(); mockQueryService = mock(QueryService.class, "QueryService"); mockFunctionContext = mock(FunctionContext.class, "FunctionContext"); final Cache mockCache = mock(Cache.class, "Cache"); final DistributedSystem mockDistributedSystem = mock(DistributedSystem.class, "DistributedSystem"); final DistributedMember mockDistributedMember = mock(DistributedMember.class, "DistributedMember"); when(mockCache.getQueryService()).thenReturn(mockQueryService); when(mockCache.getDistributedSystem()).thenReturn(mockDistributedSystem); when(mockDistributedSystem.getDistributedMember()).thenReturn(mockDistributedMember); when(mockDistributedMember.getId()).thenReturn(mockMemberId); when(mockDistributedMember.getName()).thenReturn(mockMemberName); when(mockFunctionContext.getCache()).thenReturn(mockCache); when(mockFunctionContext.getResultSender()).thenReturn(testResultSender); }
/** * a convenience method to get the name of the member this function executes on. call this * function once in your function execution to avoid performance issues. * * @return member name or id if name is blank */ default String getMemberName() { DistributedMember member = getCache().getDistributedSystem().getDistributedMember(); // if this member has name, use it, otherwise, use the id String memberName = member.getName(); if (!Strings.isBlank(memberName)) { return memberName; } return member.getId(); } }
@Override public void execute(final FunctionContext context) { final Set<LuceneIndexDetails> indexDetailsSet = new HashSet<>(); final Cache cache = context.getCache(); final String serverName = cache.getDistributedSystem().getDistributedMember().getName(); LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache); for (LuceneIndexCreationProfile profile : service.getAllDefinedIndexes()) { indexDetailsSet .add(new LuceneIndexDetails(profile, serverName, LuceneIndexStatus.NOT_INITIALIZED)); } for (LuceneIndex index : service.getAllIndexes()) { LuceneIndexStatus initialized; if (index.isIndexingInProgress()) { initialized = LuceneIndexStatus.INDEXING_IN_PROGRESS; } else { initialized = LuceneIndexStatus.INITIALIZED; } indexDetailsSet.add(new LuceneIndexDetails((LuceneIndexImpl) index, serverName, initialized)); } context.getResultSender().lastResult(indexDetailsSet); } }
@Override public void execute(final FunctionContext context) { final Set<DiskStoreDetails> memberDiskStores = new HashSet<DiskStoreDetails>(); try { final Cache cache = context.getCache(); if (cache instanceof InternalCache) { final InternalCache gemfireCache = (InternalCache) cache; final DistributedMember member = gemfireCache.getMyId(); for (final DiskStore memberDiskStore : gemfireCache.listDiskStoresIncludingRegionOwned()) { memberDiskStores.add(new DiskStoreDetails(memberDiskStore.getDiskStoreUUID(), memberDiskStore.getName(), member.getId(), member.getName())); } } context.getResultSender().lastResult(memberDiskStores); } catch (Exception e) { context.getResultSender().sendException(e); } } }
@Override public void execute(FunctionContext context) { InternalLocator locator = InternalLocator.getLocator(); InternalCache cache = (InternalCache) context.getCache(); DistributedMember member = cache.getDistributedSystem().getDistributedMember(); SharedConfigurationStatus status = locator.getSharedConfigurationStatus().getStatus(); String memberId = member.getName(); if (StringUtils.isBlank(memberId)) { memberId = member.getId(); } CliFunctionResult result = new CliFunctionResult(memberId, status.name(), null); context.getResultSender().lastResult(result); }
@Override public void execute(FunctionContext context) { try { Cache cache = context.getCache(); String memberNameOrId = cache.getDistributedSystem().getDistributedMember().getName(); if (memberNameOrId == null) { memberNameOrId = cache.getDistributedSystem().getDistributedMember().getId(); } StackTracesPerMember stackTracePerMember = new StackTracesPerMember(memberNameOrId, OSProcess.zipStacks()); context.getResultSender().lastResult(stackTracePerMember); } catch (Exception e) { context.getResultSender().sendException(e); } }
@Override public void execute(FunctionContext context) { String regionPath = (String) context.getArguments(); try { Cache cache = ((InternalCache) context.getCache()).getCacheForProcessingClientRequests(); Region<?, ?> region = cache.getRegion(regionPath); if (region != null) { String memberName = cache.getDistributedSystem().getDistributedMember().getName(); RegionDescriptionPerMember regionDescription = new RegionDescriptionPerMember(region, memberName); context.getResultSender().lastResult(regionDescription); } else { context.getResultSender().lastResult(null); } } catch (Exception e) { context.getResultSender().sendException(e); } } }
@Override public void execute(final FunctionContext context) { LuceneIndexDetails result = null; final Cache cache = context.getCache(); final String serverName = cache.getDistributedSystem().getDistributedMember().getName(); final LuceneIndexInfo indexInfo = (LuceneIndexInfo) context.getArguments(); LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache); LuceneIndex index = service.getIndex(indexInfo.getIndexName(), indexInfo.getRegionPath()); LuceneIndexCreationProfile profile = service.getDefinedIndex(indexInfo.getIndexName(), indexInfo.getRegionPath()); if (index != null) { result = new LuceneIndexDetails((LuceneIndexImpl) index, serverName); } else if (profile != null) { result = new LuceneIndexDetails(profile, serverName); } context.getResultSender().lastResult(result); } }
public IndexDetails(final DistributedMember member, final Index index) { this(member.getId(), index.getRegion().getFullPath(), index.getName()); setFromClause(index.getFromClause()); setIndexedExpression(index.getIndexedExpression()); setIndexType(index.getType()); setMemberName(member.getName()); setProjectionAttributes(index.getProjectionAttributes()); setRegionName(index.getRegion().getName()); if (index instanceof AbstractIndex) { setIsValid(((AbstractIndex) index).isValid()); } else { setIsValid(false); } if (index.getStatistics() != null) { setIndexStatisticsDetails(createIndexStatisticsDetails(index.getStatistics())); } }