/** @deprecated since 0.6.0; use {@link #getJmxAgentJarMavenArtifact()} */ @Deprecated public String getJmxAgentJarBasename() { MavenArtifact artifact = getJmxAgentJarMavenArtifact(); if (artifact==null) throw new IllegalStateException("Either JMX is not enabled or there is an error in the configuration (JMX mode "+getJmxAgentMode()+" does not support agent JAR)"); return artifact.getFilename(); }
public List<String> getJmxJavaConfigOptions() { if (getJmxAgentMode()==JmxAgentModes.NONE) return MutableList.of(); return MutableList.of(String.format("-javaagent:%s", getJmxAgentJarDestinationFilePath())); }
@Nullable public MavenArtifact getJmxAgentJarMavenArtifact() { switch (getJmxAgentMode()) { case JMXMP: MavenArtifact result = BrooklynMavenArtifacts.artifact(null, "brooklyn-jmxmp-agent", "jar", "with-dependencies"); // the "with-dependencies" variant is needed; however the filename then has the classifier segment _replaced_ by "shaded" when this filename is created result.setCustomFileNameAfterArtifactMarker("shaded"); result.setClassifierFileNameMarker(""); return result; case JMX_RMI_CUSTOM_AGENT: return BrooklynMavenArtifacts.jar("brooklyn-jmxrmi-agent"); default: return null; } }
/** returns URL for accessing the java agent, throwing if not applicable; * prefers on classpath where it should be, but will fall back to taking from maven hosted * (known problem in Eclipse where JARs are not always copied) */ public String getJmxAgentJarUrl() { MavenArtifact artifact = getJmxAgentJarMavenArtifact(); if (artifact==null) throw new IllegalStateException("Either JMX is not enabled or there is an error in the configuration (JMX mode "+getJmxAgentMode()+" does not support agent JAR)"); String jar = "classpath://" + artifact.getFilename(); if (ResourceUtils.create(this).doesUrlExist(jar)) return jar; String result = MavenRetriever.localUrl(artifact); if (warnedAboutNotOnClasspath) { log.debug("JMX JAR for "+artifact+" is not on the classpath; taking from "+result); } else { log.warn("JMX JAR for "+artifact+" is not on the classpath; taking from "+result+" (subsequent similar messages will be logged at debug)"); warnedAboutNotOnClasspath = true; } return result; }
public String getJmxUrl() { init(); String host = entity.getAttribute(Attributes.HOSTNAME); if (host==null) { SshMachineLocation machine = EffectorTasks.getSshMachine(entity); host = machine.getAddress().getHostName(); } if (getJmxAgentMode()==JmxAgentModes.JMXMP) { return JmxHelper.toJmxmpUrl(host, entity.getAttribute(JMX_PORT)); } else { if (getJmxAgentMode()==JmxAgentModes.NONE) { fixPortsForModeNone(); } // this will work for agent or agentless return JmxHelper.toRmiJmxUrl(host, entity.getAttribute(JMX_PORT), entity.getAttribute(RMI_REGISTRY_PORT), entity.getAttribute(JMX_CONTEXT)); } }
/** mode NONE cannot set a JMX (RMI server) port; it needs an RMI registry port, * then gets redirected to an anonymous RMI server port; * both the hostname and the anonymous port must be accessible to use this mode * (hence the use of the other agents in most cases) */ protected int fixPortsForModeNone() { assert getJmxAgentMode()==JmxAgentModes.NONE; Integer jmxRemotePort = getEntity().getAttribute(JMX_PORT); Integer rmiRegistryPort = getEntity().getAttribute(RMI_REGISTRY_PORT); if (rmiRegistryPort!=null && rmiRegistryPort>0) { if (jmxRemotePort==null || jmxRemotePort!=rmiRegistryPort) { if (jmxRemotePort!=null && jmxRemotePort>0) { // ignore RMI registry port when mode 'none' is set -- set same as JMX port here // (bit irritating, but JMX_PORT will be ignored in this mode) log.warn("Ignoring JMX_PORT "+jmxRemotePort+" when configuring agentless JMX on "+getEntity()+"; will use RMI_REGISTRY_PORT "+rmiRegistryPort); } jmxRemotePort = rmiRegistryPort; ((EntityLocal)getEntity()).setAttribute(JMX_PORT, jmxRemotePort); } } else { if (jmxRemotePort==null || jmxRemotePort<=0) { throw new IllegalStateException("Invalid JMX_PORT "+jmxRemotePort+" and RMI_REGISTRY_PORT "+rmiRegistryPort+" when configuring JMX "+getJmxAgentMode()+" on "+getEntity()); } ((EntityLocal)getEntity()).setAttribute(RMI_REGISTRY_PORT, jmxRemotePort); } return jmxRemotePort; }
/** installs files needed for JMX, to the runDir given in constructor, assuming the runDir has been created */ public void install() { if (getJmxAgentMode()!=JmxAgentModes.NONE) { getMachine().get().copyTo(ResourceUtils.create(this).getResourceFromUrl( getJmxAgentJarUrl()), getJmxAgentJarDestinationFilePath()); } if (isSecure()) { getJmxSslSupport().install(); } }
switch (getJmxAgentMode()) { case JMXMP: jmxRemotePort = getEntity().getAttribute(JMX_PORT); if (jmxRemotePort==null || jmxRemotePort<=0) throw new IllegalStateException("Unsupported JMX port "+jmxRemotePort+" - when applying system properties ("+getJmxAgentMode()+" / "+getEntity()+")"); result.put(JmxmpAgent.JMXMP_PORT_PROPERTY, jmxRemotePort); jmxRemotePort = getEntity().getAttribute(JMX_PORT); if (jmxRemotePort==null || jmxRemotePort<=0) throw new IllegalStateException("Unsupported JMX port "+jmxRemotePort+" - when applying system properties ("+getJmxAgentMode()+" / "+getEntity()+")"); result.put(JmxRmiAgent.RMI_REGISTRY_PORT_PROPERTY, Preconditions.checkNotNull(entity.getAttribute(UsesJmx.RMI_REGISTRY_PORT), "registry port")); break; default: throw new IllegalStateException("Unsupported JMX mode - when applying system properties ("+getJmxAgentMode()+" / "+getEntity()+")");