List of usage examples for javax.management ObjectName getDomain
public String getDomain()
From source file:com.sun.grizzly.http.jk.server.JkMain.java
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { oname = name;/* w w w .j av a 2 s .c o m*/ mserver = server; domain = name.getDomain(); return name; }
From source file:org.apache.webapp.admin.context.SaveContextAction.java
/** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed.//ww w . ja v a2 s.c o m * * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Acquire the resources that we need HttpSession session = request.getSession(); Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY); if (resources == null) { resources = getServlet().getResources(); } // Acquire a reference to the MBeanServer containing our MBeans try { mBServer = ((ApplicationServlet) getServlet()).getServer(); } catch (Throwable t) { throw new ServletException("Cannot acquire MBeanServer reference", t); } // Identify the requested action ContextForm cform = (ContextForm) form; String adminAction = cform.getAdminAction(); String cObjectName = cform.getObjectName(); String lObjectName = cform.getLoaderObjectName(); String mObjectName = cform.getManagerObjectName(); if ((cform.getPath() == null) || (cform.getPath().length() < 1)) { cform.setPath("/"); } // Perform a "Create Context" transaction (if requested) if ("Create".equals(adminAction)) { String operation = null; Object values[] = null; try { // get the parent host name String parentName = cform.getParentObjectName(); ObjectName honame = new ObjectName(parentName); // Ensure that the requested context name is unique ObjectName oname = new ObjectName(honame.getDomain() + ":j2eeType=WebModule,name=//" + honame.getKeyProperty("host") + cform.getPath() + // FIXME set J2EEApplication and J2EEServer ",J2EEApplication=none,J2EEServer=none"); if (mBServer.isRegistered(oname)) { ActionErrors errors = new ActionErrors(); errors.add("contextName", new ActionError("error.contextName.exists")); saveErrors(request, errors); return (new ActionForward(mapping.getInput())); } // Look up our MBeanFactory MBean ObjectName fname = TomcatTreeBuilder.getMBeanFactory(); // Create a new StandardContext object values = new Object[3]; values[0] = parentName; values[1] = cform.getPath(); values[2] = cform.getDocBase(); operation = "createStandardContext"; cObjectName = (String) mBServer.invoke(fname, operation, values, createStandardContextTypes); // Create a new Loader object values = new String[1]; // parent of loader is the newly created context values[0] = cObjectName.toString(); operation = "createWebappLoader"; lObjectName = (String) mBServer.invoke(fname, operation, values, createStandardLoaderTypes); // Create a new StandardManager object values = new String[1]; // parent of manager is the newly created Context values[0] = cObjectName.toString(); operation = "createStandardManager"; mObjectName = (String) mBServer.invoke(fname, operation, values, createStandardManagerTypes); if (mObjectName == null) { operation = "removeLoader"; values[0] = lObjectName; mBServer.invoke(fname, operation, values, removeContextTypes); operation = "removeContext"; values[0] = cObjectName; mBServer.invoke(fname, operation, values, removeContextTypes); Registry.getRegistry().unregisterComponent(new ObjectName(cObjectName)); request.setAttribute("warning", "error.context.directory"); return (mapping.findForward("Save Unsuccessful")); } // Add the new Context to our tree control node addToTreeControlNode(oname, cObjectName, parentName, resources, session); } catch (Exception e) { getServlet().log(resources.getMessage(locale, "users.error.invoke", operation), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, resources.getMessage(locale, "users.error.invoke", operation)); return (null); } } // Perform attribute updates as requested String attribute = null; try { ObjectName coname = new ObjectName(cObjectName); ObjectName loname = new ObjectName(lObjectName); ObjectName moname = new ObjectName(mObjectName); attribute = "debug"; int debug = 0; try { debug = Integer.parseInt(cform.getDebugLvl()); } catch (Throwable t) { debug = 0; } mBServer.setAttribute(coname, new Attribute("debug", new Integer(debug))); attribute = "path"; String path = ""; try { path = cform.getPath(); } catch (Throwable t) { path = ""; } mBServer.setAttribute(coname, new Attribute("path", path)); attribute = "workDir"; String workDir = ""; workDir = cform.getWorkDir(); if ((workDir != null) && (workDir.length() >= 1)) { mBServer.setAttribute(coname, new Attribute("workDir", workDir)); } attribute = "cookies"; String cookies = "false"; try { cookies = cform.getCookies(); } catch (Throwable t) { cookies = "false"; } mBServer.setAttribute(coname, new Attribute("cookies", new Boolean(cookies))); attribute = "crossContext"; String crossContext = "false"; try { crossContext = cform.getCrossContext(); } catch (Throwable t) { crossContext = "false"; } mBServer.setAttribute(coname, new Attribute("crossContext", new Boolean(crossContext))); attribute = "override"; String override = "false"; try { override = cform.getOverride(); } catch (Throwable t) { override = "false"; } mBServer.setAttribute(coname, new Attribute("override", new Boolean(override))); attribute = "reloadable"; String reloadable = "false"; try { reloadable = cform.getReloadable(); } catch (Throwable t) { reloadable = "false"; } mBServer.setAttribute(coname, new Attribute("reloadable", new Boolean(reloadable))); attribute = "swallowOutput"; String swallowOutput = "false"; try { swallowOutput = cform.getSwallowOutput(); } catch (Throwable t) { swallowOutput = "false"; } mBServer.setAttribute(coname, new Attribute("swallowOutput", new Boolean(swallowOutput))); attribute = "useNaming"; String useNaming = "false"; try { useNaming = cform.getUseNaming(); } catch (Throwable t) { useNaming = "false"; } mBServer.setAttribute(coname, new Attribute("useNaming", new Boolean(useNaming))); // Loader properties attribute = "reloadable"; try { reloadable = cform.getLdrReloadable(); } catch (Throwable t) { reloadable = "false"; } mBServer.setAttribute(loname, new Attribute("reloadable", new Boolean(reloadable))); attribute = "debug"; try { debug = Integer.parseInt(cform.getLdrDebugLvl()); } catch (Throwable t) { debug = 0; } mBServer.setAttribute(loname, new Attribute("debug", new Integer(debug))); //attribute = "checkInterval"; //int checkInterval = 15; //try { // checkInterval = Integer.parseInt(cform.getLdrCheckInterval()); //} catch (Throwable t) { // checkInterval = 15; //} //mBServer.setAttribute(loname, // new Attribute("checkInterval", new Integer(checkInterval))); // Manager properties attribute = "entropy"; String entropy = cform.getMgrSessionIDInit(); if ((entropy != null) && (entropy.length() >= 1)) { mBServer.setAttribute(moname, new Attribute("entropy", entropy)); } attribute = "debug"; try { debug = Integer.parseInt(cform.getMgrDebugLvl()); } catch (Throwable t) { debug = 0; } mBServer.setAttribute(moname, new Attribute("debug", new Integer(debug))); //attribute = "checkInterval"; //try { // checkInterval = Integer.parseInt(cform.getMgrCheckInterval()); //} catch (Throwable t) { // checkInterval = 60; //} //mBServer.setAttribute(moname, // new Attribute("checkInterval", new Integer(checkInterval))); attribute = "maxActiveSessions"; int maxActiveSessions = -1; try { maxActiveSessions = Integer.parseInt(cform.getMgrMaxSessions()); } catch (Throwable t) { maxActiveSessions = -1; } mBServer.setAttribute(moname, new Attribute("maxActiveSessions", new Integer(maxActiveSessions))); } catch (Exception e) { getServlet().log(resources.getMessage(locale, "users.error.attribute.set", attribute), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, resources.getMessage(locale, "users.error.attribute.set", attribute)); return (null); } // Forward to the success reporting page session.removeAttribute(mapping.getAttribute()); return (mapping.findForward("Save Successful")); }
From source file:io.hawt.osgi.jmx.RBACDecorator.java
/** * If we have access to {@link ConfigurationAdmin}, we can add RBAC information * @param result// ww w .ja v a 2s. co m */ @Override @SuppressWarnings("unchecked") public void decorate(Map<String, Object> result) throws Exception { try { ServiceReference<ConfigurationAdmin> cmRef = bundleContext .getServiceReference(ConfigurationAdmin.class); ServiceReference<JMXSecurityMBean> jmxSecRef = bundleContext .getServiceReference(JMXSecurityMBean.class); if (cmRef != null && jmxSecRef != null) { ConfigurationAdmin configAdmin = bundleContext.getService(cmRef); JMXSecurityMBean jmxSec = bundleContext.getService(jmxSecRef); if (configAdmin != null && jmxSec != null) { // 1. each pair of MBean/operation has to be marked with RBAC flag (can/can't invoke) // 2. the information is provided by org.apache.karaf.management.JMXSecurityMBean.canInvoke(java.util.Map) // 3. we'll peek into available configadmin jmx.acl* configs, to see which MBeans/operations have to // be examined and which will produce same results // 4. only then we'll prepare Map as parameter for canInvoke() Configuration[] configurations = configAdmin.listConfigurations("(service.pid=jmx.acl*)"); List<String> allJmxAclPids = new LinkedList<>(); for (Configuration cfg : configurations) { allJmxAclPids.add(cfg.getPid()); } if (allJmxAclPids.size() == 0) { return; } Map<String, Map<String, Object>> domains = (Map<String, Map<String, Object>>) result .get("domains"); // cache contains MBeanInfos for different MBeans/ObjectNames Map<String, Map<String, Object>> cache = (Map<String, Map<String, Object>>) result.get("cache"); // new cache will contain MBeanInfos + RBAC info Map<String, Map<String, Object>> rbacCache = new HashMap<>(); // the fact that some MBeans share JSON MBeanInfo doesn't mean that they can share RBAC info // - each MBean's name may have RBAC information configured in different PIDs. // when iterating through all reapeating MBeans that share MBeanInfo (that doesn't have RBAC info // yet), we have to decide if it'll use shared info after RBAC check or will switch to dedicated // info. we have to be careful not to end with most MBeans *not* sharing MBeanInfo (in case if // somehow the shared info will be "special case" from RBAC point of view) Map<String, List<String>> queryForMBeans = new HashMap<>(); Map<String, List<String>> queryForMBeanOperations = new HashMap<>(); for (String domain : domains.keySet()) { Map<String, Object> domainMBeansCheck = new HashMap<>(domains.get(domain)); Map<String, Object> domainMBeans = domains.get(domain); for (String name : domainMBeansCheck.keySet()) { Object mBeanInfo = domainMBeansCheck.get(name); String fullName = domain + ":" + name; ObjectName n = new ObjectName(fullName); if (mBeanInfo instanceof Map) { // not shared JSONified MBeanInfo prepareKarafRbacInvocations(fullName, (Map<String, Object>) mBeanInfo, queryForMBeans, queryForMBeanOperations); } else /*if (mBeanInfo instanceof String)*/ { // shared JSONified MBeanInfo // shard mbeanNames sharing MBeanInfo by the hierarchy of jmx.acl* PIDs used to // check RBAC info String key = (String) mBeanInfo; String pidListKey = pidListKey(allJmxAclPids, n); if (!rbacCache.containsKey(key + ":" + pidListKey)) { // shallow copy - we can share op/not/attr/desc, but we put specific // canInvoke/opByString keys HashMap<String, Object> sharedMBeanAndRbacInfo = new HashMap<>(cache.get(key)); rbacCache.put(key + ":" + pidListKey, sharedMBeanAndRbacInfo); // we'll be checking RBAC only for single (first) MBean having this pidListKey prepareKarafRbacInvocations(fullName, sharedMBeanAndRbacInfo, queryForMBeans, queryForMBeanOperations); } // switch key from shared MBeanInfo-only to shared MBean+RbacInfo domainMBeans.put(name, key + ":" + pidListKey); } } } // RBAC per MBeans (can invoke *any* operation or attribute?) TabularData dataForMBeans = jmxSec.canInvoke(queryForMBeans); Collection<?> results = dataForMBeans.values(); for (Object cd : results) { ObjectName objectName = new ObjectName((String) ((CompositeData) cd).get("ObjectName")); boolean canInvoke = ((CompositeData) cd).get("CanInvoke") != null ? (Boolean) ((CompositeData) cd).get("CanInvoke") : false; Object mBeanInfoOrKey = domains.get(objectName.getDomain()) .get(objectName.getKeyPropertyListString()); Map<String, Object> mBeanInfo; if (mBeanInfoOrKey instanceof Map) { mBeanInfo = (Map<String, Object>) mBeanInfoOrKey; } else /*if (mBeanInfoOrKey instanceof String) */ { mBeanInfo = rbacCache.get(mBeanInfoOrKey.toString()); } if (mBeanInfo != null) { mBeanInfo.put("canInvoke", canInvoke); } } // RBAC per { MBean,operation } (can invoke status for each operation) TabularData dataForMBeanOperations = jmxSec.canInvoke(queryForMBeanOperations); results = dataForMBeanOperations.values(); for (Object cd : results) { ObjectName objectName = new ObjectName((String) ((CompositeData) cd).get("ObjectName")); String method = (String) ((CompositeData) cd).get("Method"); boolean canInvoke = ((CompositeData) cd).get("CanInvoke") != null ? (Boolean) ((CompositeData) cd).get("CanInvoke") : false; Object mBeanInfoOrKey = domains.get(objectName.getDomain()) .get(objectName.getKeyPropertyListString()); Map<String, Object> mBeanInfo; if (mBeanInfoOrKey instanceof Map) { mBeanInfo = (Map<String, Object>) mBeanInfoOrKey; } else /*if (mBeanInfoOrKey instanceof String) */ { mBeanInfo = rbacCache.get(mBeanInfoOrKey.toString()); } if (mBeanInfo != null) { ((Map<String, Object>) ((Map<String, Object>) mBeanInfo.get("opByString")).get(method)) .put("canInvoke", canInvoke); } } result.remove("cache"); result.put("cache", rbacCache); } } } catch (Exception e) { LOG.error(e.getMessage(), e); // simply do not decorate } }
From source file:io.fabric8.mq.autoscaler.MQAutoScaler.java
private void bounceBroker(BrokerVitalSigns broker) throws Exception { if (broker.getTotalConnections() > 0) { ObjectName root = broker.getRoot(); Hashtable<String, String> props = root.getKeyPropertyList(); props.put("connector", "clientConnectors"); props.put("connectorName", "*"); String objectName = root.getDomain() + ":" + getOrderedProperties(props); /**/*from w w w. j a v a2s. com*/ * not interested in StatisticsEnabled, just need a real attribute so we can get the root which we * can execute against */ List<String> roots = new ArrayList<>(); J4pResponse<J4pReadRequest> response = broker.getClient() .execute(new J4pReadRequest(objectName, "StatisticsEnabled")); JSONObject value = response.getValue(); for (Object key : value.keySet()) { roots.add(key.toString()); } for (String key : roots) { broker.getClient().execute(new J4pExecRequest(key, "stop")); LOG.info("Stopping all clients " + " on broker " + broker.getBrokerIdentifier() + ": connector = " + key); } Thread.sleep(1000); for (String key : roots) { broker.getClient().execute(new J4pExecRequest(key, "start")); } } }
From source file:io.fabric8.mq.autoscaler.MQAutoScaler.java
private void bounceConnections(BrokerVitalSigns broker, int number) throws Exception { if (number > 0) { ObjectName root = broker.getRoot(); Hashtable<String, String> props = root.getKeyPropertyList(); props.put("connector", "clientConnectors"); props.put("connectorName", "*"); String objectName = root.getDomain() + ":" + getOrderedProperties(props); /**//from w w w. j a v a 2 s . c om * not interested in StatisticsEnabled, just need a real attribute so we can get the root which we * can execute against */ List<String> connectors = new ArrayList<>(); J4pResponse<J4pReadRequest> response = broker.getClient() .execute(new J4pReadRequest(objectName, "StatisticsEnabled")); JSONObject value = response.getValue(); for (Object key : value.keySet()) { connectors.add(key.toString()); } List<String> targets = new ArrayList<>(); for (String key : connectors) { ObjectName on = new ObjectName(key); Hashtable<String, String> p = on.getKeyPropertyList(); p.put("connectionName", "*"); p.put("connectionViewType", "clientId"); String clientObjectName = root.getDomain() + ":" + getOrderedProperties(p); ObjectName on1 = new ObjectName(clientObjectName); J4pResponse<J4pReadRequest> response1 = broker.getClient().execute(new J4pReadRequest(on1, "Slow")); JSONObject value1 = response1.getValue(); for (Object k : value1.keySet()) { targets.add(k.toString()); } } int count = 0; for (String key : targets) { broker.getClient().execute(new J4pExecRequest(key, "stop")); LOG.info("Stopping Client " + key + " on broker " + broker.getBrokerIdentifier()); if (++count >= number) { break; } } } }
From source file:io.fabric8.mq.autoscaler.MQAutoScaler.java
private BrokerVitalSigns populateDestinations(DestinationVitalSigns.Type type, BrokerVitalSigns brokerVitalSigns) { try {/*from w w w . j ava 2 s . c om*/ ObjectName root = brokerVitalSigns.getRoot(); Hashtable<String, String> props = root.getKeyPropertyList(); props.put("destinationType", type == DestinationVitalSigns.Type.QUEUE ? "Queue" : "Topic"); props.put("destinationName", "*"); String objectName = root.getDomain() + ":" + getOrderedProperties(props); J4pResponse<J4pReadRequest> response = brokerVitalSigns.getClient() .execute(new J4pReadRequest(objectName, "Name", "QueueSize", "ConsumerCount", "ProducerCount")); JSONObject value = response.getValue(); for (Object key : value.keySet()) { //get the destinations JSONObject jsonObject = (JSONObject) value.get(key); String name = jsonObject.get("Name").toString(); String producerCount = jsonObject.get("ProducerCount").toString().trim(); String consumerCount = jsonObject.get("ConsumerCount").toString().trim(); String queueSize = jsonObject.get("QueueSize").toString().trim(); if (!name.contains("Advisory") && !name.contains(ActiveMQDestination.TEMP_DESTINATION_NAME_PREFIX)) { ActiveMQDestination destination = type == DestinationVitalSigns.Type.QUEUE ? new ActiveMQQueue(name) : new ActiveMQTopic(name); DestinationVitalSigns destinationVitalSigns = new DestinationVitalSigns(destination); destinationVitalSigns.setNumberOfConsumers(Integer.parseInt(consumerCount)); destinationVitalSigns.setNumberOfProducers(Integer.parseInt(producerCount)); destinationVitalSigns.setQueueDepth(Integer.parseInt(queueSize)); brokerVitalSigns.addDestinationVitalSigns(destinationVitalSigns); } } } catch (Exception ex) { // Destinations don't exist yet on the broker LOG.debug("populateDestinations failed", ex); } return brokerVitalSigns; }
From source file:org.apache.catalina.realm.RealmBase.java
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { oname = name;//w w w . jav a 2 s . c o m mserver = server; domain = name.getDomain(); type = name.getKeyProperty("type"); host = name.getKeyProperty("host"); path = name.getKeyProperty("path"); return name; }
From source file:org.apache.coyote.tomcat5.MapperListener.java
public void handleNotification(Notification notification, java.lang.Object handback) { if (notification instanceof MBeanServerNotification) { ObjectName objectName = ((MBeanServerNotification) notification).getMBeanName(); String j2eeType = objectName.getKeyProperty("j2eeType"); String engineName = null; if (j2eeType != null) { if ((j2eeType.equals("WebModule")) || (j2eeType.equals("Servlet"))) { if (mBeanServer.isRegistered(objectName)) { try { engineName = (String) mBeanServer.getAttribute(objectName, "engineName"); } catch (Exception e) { // Ignore }/*from www . j a v a2s . c o m*/ } } } // At deployment time, engineName is always = null. if ((!"*".equals(domain)) && (!domain.equals(objectName.getDomain())) && ((!domain.equals(engineName)) && (engineName != null))) { return; } log.debug("Handle " + objectName); if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) { String type = objectName.getKeyProperty("type"); if ("Host".equals(type)) { try { registerHost(objectName); } catch (Exception e) { log.warn("Error registering Host " + objectName, e); } } if (j2eeType != null) { if (j2eeType.equals("WebModule")) { try { registerContext(objectName); } catch (Throwable t) { log.warn("Error registering Context " + objectName, t); } } else if (j2eeType.equals("Servlet")) { try { registerWrapper(objectName); } catch (Throwable t) { log.warn("Error registering Wrapper " + objectName, t); } } } } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { String type = objectName.getKeyProperty("type"); if ("Host".equals(type)) { try { unregisterHost(objectName); } catch (Exception e) { log.warn("Error unregistering Host " + objectName, e); } } if (j2eeType != null) { if (j2eeType.equals("WebModule")) { try { unregisterContext(objectName); } catch (Throwable t) { log.warn("Error unregistering webapp " + objectName, t); } } } } } }
From source file:com.googlecode.jmxtrans.model.Query.java
public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { MBeanInfo info = mbeanServer.getMBeanInfo(queryName); ObjectInstance oi = mbeanServer.getObjectInstance(queryName); List<String> attributes; if (attr.isEmpty()) { attributes = new ArrayList<>(); for (MBeanAttributeInfo attrInfo : info.getAttributes()) { attributes.add(attrInfo.getName()); }//from w w w . j ava 2s .c o m } else { attributes = attr; } try { if (!attributes.isEmpty()) { logger.debug("Executing queryName [{}] from query [{}]", queryName.getCanonicalName(), this); AttributeList al = mbeanServer.getAttributes(queryName, attributes.toArray(new String[attributes.size()])); return new JmxResultProcessor(this, oi, al.asList(), info.getClassName(), queryName.getDomain()) .getResults(); } } catch (UnmarshalException ue) { if ((ue.getCause() != null) && (ue.getCause() instanceof ClassNotFoundException)) { logger.debug("Bad unmarshall, continuing. This is probably ok and due to something like this: " + "http://ehcache.org/xref/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#52", ue.getMessage()); } else { throw ue; } } return ImmutableList.of(); }
From source file:org.apache.catalina.loader.WebappLoader.java
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { oname = name;//from w ww . jav a2s. co m mserver = server; domain = name.getDomain(); return name; }