use of org.apache.geode.management.internal.JmxManagerAdvisor.JmxManagerProfile in project geode by apache.
the class LocatorMBeanBridge method listPotentialManagers.
public String[] listPotentialManagers() {
if (cache != null) {
List<JmxManagerProfile> willingToManage = this.cache.getJmxManagerAdvisor().adviseWillingToManage();
if (!willingToManage.isEmpty()) {
String[] managers = new String[willingToManage.size()];
int j = 0;
for (JmxManagerProfile profile : willingToManage) {
managers[j] = profile.getDistributedMember().getId();
j++;
}
return managers;
}
}
return ManagementConstants.NO_DATA_STRING;
}
use of org.apache.geode.management.internal.JmxManagerAdvisor.JmxManagerProfile in project geode by apache.
the class LocatorJUnitTest method testGfshConnectShouldSucceedIfJmxManagerStartIsTrueInLocator.
/**
* TRAC #45804: if jmx-manager-start is true in a locator then gfsh connect will fail
*/
@Test
public void testGfshConnectShouldSucceedIfJmxManagerStartIsTrueInLocator() throws Exception {
Properties dsprops = new Properties();
int jmxPort = getRandomAvailablePort(SOCKET);
dsprops.setProperty(MCAST_PORT, "0");
dsprops.setProperty(JMX_MANAGER_PORT, "" + jmxPort);
dsprops.setProperty(JMX_MANAGER_START, "true");
dsprops.setProperty(JMX_MANAGER_HTTP_PORT, "0");
dsprops.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
dsprops.setProperty(LOG_FILE, "");
// not
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "disableManagement", "false");
// needed
try {
locator = Locator.startLocatorAndDS(port, null, dsprops);
List<JmxManagerProfile> alreadyManaging = GemFireCacheImpl.getInstance().getJmxManagerAdvisor().adviseAlreadyManaging();
assertEquals(1, alreadyManaging.size());
assertEquals(GemFireCacheImpl.getInstance().getMyId(), alreadyManaging.get(0).getDistributedMember());
} finally {
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "enabledManagement");
}
}
use of org.apache.geode.management.internal.JmxManagerAdvisor.JmxManagerProfile in project geode by apache.
the class LocatorMBeanBridge method listManagers.
public String[] listManagers() {
if (cache != null) {
List<JmxManagerProfile> alreadyManaging = this.cache.getJmxManagerAdvisor().adviseAlreadyManaging();
if (!alreadyManaging.isEmpty()) {
String[] managers = new String[alreadyManaging.size()];
int j = 0;
for (JmxManagerProfile profile : alreadyManaging) {
managers[j] = profile.getDistributedMember().getId();
j++;
}
return managers;
}
}
return ManagementConstants.NO_DATA_STRING;
}
use of org.apache.geode.management.internal.JmxManagerAdvisor.JmxManagerProfile in project geode by apache.
the class JmxManagerAdvisee method fillInProfile.
@Override
public void fillInProfile(Profile profile) {
assert profile instanceof JmxManagerProfile;
JmxManagerProfile jmxp = (JmxManagerProfile) profile;
DistributionConfig dc = getSystem().getConfig();
boolean jmxManager = dc.getJmxManager();
String host = "";
int port = 0;
boolean ssl = false;
boolean started = false;
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(this.cache);
if (service != null) {
jmxManager = service.isManagerCreated();
started = service.isManager();
}
if (jmxManager) {
port = dc.getJmxManagerPort();
boolean usingJdkConfig = false;
if (port == 0) {
port = Integer.getInteger("com.sun.management.jmxremote.port", 0);
if (port != 0) {
usingJdkConfig = true;
// the jdk default
ssl = true;
if (System.getProperty("com.sun.management.jmxremote.ssl") != null) {
ssl = Boolean.getBoolean("com.sun.management.jmxremote.ssl");
}
}
}
if (port != 0) {
if (!usingJdkConfig) {
SSLConfig jmxSSL = SSLConfigurationFactory.getSSLConfigForComponent(SecurableCommunicationChannel.JMX);
ssl = jmxSSL.isEnabled();
host = dc.getJmxManagerHostnameForClients();
if (host == null || host.equals("")) {
host = dc.getJmxManagerBindAddress();
}
}
if (host == null || host.equals("")) {
try {
// fixes 46317
host = SocketCreator.getLocalHost().getHostAddress();
} catch (UnknownHostException ex) {
host = "127.0.0.1";
}
}
}
}
jmxp.setInfo(jmxManager, host, port, ssl, started);
this.myMostRecentProfile = jmxp;
}
use of org.apache.geode.management.internal.JmxManagerAdvisor.JmxManagerProfile in project geode by apache.
the class JmxManagerLocator method findJmxManager.
private JmxManagerLocatorResponse findJmxManager(JmxManagerLocatorRequest request) {
if (logger.isDebugEnabled()) {
logger.debug("Locator requested to find or start jmx manager");
}
List<JmxManagerProfile> alreadyManaging = this.cache.getJmxManagerAdvisor().adviseAlreadyManaging();
if (alreadyManaging.isEmpty()) {
List<JmxManagerProfile> willingToManage = this.cache.getJmxManagerAdvisor().adviseWillingToManage();
if (!willingToManage.isEmpty()) {
synchronized (this) {
alreadyManaging = this.cache.getJmxManagerAdvisor().adviseAlreadyManaging();
if (alreadyManaging.isEmpty()) {
willingToManage = this.cache.getJmxManagerAdvisor().adviseWillingToManage();
if (!willingToManage.isEmpty()) {
JmxManagerProfile p = willingToManage.get(0);
if (p.getDistributedMember().equals(this.cache.getMyId())) {
if (logger.isDebugEnabled()) {
logger.debug("Locator starting jmx manager in its JVM");
}
try {
ManagementService.getManagementService(this.cache).startManager();
} catch (CancelException ex) {
// ignore
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
SystemFailure.checkFailure();
return new JmxManagerLocatorResponse(null, 0, false, t);
}
} else {
p = startJmxManager(willingToManage);
if (p != null) {
if (logger.isDebugEnabled()) {
logger.debug("Locator started jmx manager in {}", p.getDistributedMember());
}
}
// bug 46041 is caused by a race in which the function reply comes
// before we have received the profile update. So pause for a bit
// if our advisor still does not know about a manager and the member
// we asked to start one is still in the ds.
alreadyManaging = this.cache.getJmxManagerAdvisor().adviseAlreadyManaging();
int sleepCount = 0;
while (sleepCount < 20 && alreadyManaging.isEmpty() && this.cache.getDistributionManager().getDistributionManagerIds().contains(p.getDistributedMember())) {
sleepCount++;
try {
// TODO: call to sleep while synchronized
Thread.sleep(100);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
alreadyManaging = this.cache.getJmxManagerAdvisor().adviseAlreadyManaging();
}
}
if (alreadyManaging.isEmpty()) {
alreadyManaging = this.cache.getJmxManagerAdvisor().adviseAlreadyManaging();
}
}
}
}
// sync
}
}
JmxManagerLocatorResponse result = null;
if (!alreadyManaging.isEmpty()) {
JmxManagerProfile p = alreadyManaging.get(0);
result = new JmxManagerLocatorResponse(p.getHost(), p.getPort(), p.getSsl(), null);
if (logger.isDebugEnabled()) {
logger.debug("Found jmx manager: " + p);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Did not find a jmx manager");
}
result = new JmxManagerLocatorResponse();
}
return result;
}
Aggregations