Search in sources :

Example 26 with MBeanException

use of javax.management.MBeanException in project geode by apache.

the class OpenMethod method invokeWithOpenReturn.

Object invokeWithOpenReturn(Object obj, Object[] params) throws MBeanException, IllegalAccessException, InvocationTargetException {
    final Object[] javaParams;
    try {
        javaParams = fromOpenParameters(params);
    } catch (InvalidObjectException e) {
        final String msg = methodName() + ": cannot convert parameters " + "from open values: " + e;
        throw new MBeanException(e, msg);
    }
    final Object javaReturn = method.invoke(obj, javaParams);
    try {
        return returnTypeConverter.toOpenValue(javaReturn);
    } catch (OpenDataException e) {
        final String msg = methodName() + ": cannot convert return " + "value to open value: " + e;
        throw new MBeanException(e, msg);
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) MBeanException(javax.management.MBeanException) InvalidObjectException(java.io.InvalidObjectException)

Example 27 with MBeanException

use of javax.management.MBeanException in project geode by apache.

the class MBeanJMXAdapter method isAttributeAvailable.

public static boolean isAttributeAvailable(String attributeName, String objectName) {
    try {
        ObjectName objName = new ObjectName(objectName);
        mbeanServer.getAttribute(objName, attributeName);
    } catch (MalformedObjectNameException e) {
        return false;
    } catch (NullPointerException e) {
        return false;
    } catch (AttributeNotFoundException e) {
        return false;
    } catch (InstanceNotFoundException e) {
        return false;
    } catch (MBeanException e) {
        return false;
    } catch (ReflectionException e) {
        return false;
    }
    return true;
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 28 with MBeanException

use of javax.management.MBeanException in project geode by apache.

the class ManagementFunction method execute.

/**
   * Actual function execution. It delegates task at managed node according to the request received.
   * 
   * If any exception is encountered it will set the result to UNDEFINED
   */
public void execute(FunctionContext fc) {
    boolean executedSuccessfully = false;
    InternalCache cache = GemFireCacheImpl.getInstance();
    Object[] functionArguments = (Object[]) fc.getArguments();
    ObjectName objectName = (ObjectName) functionArguments[0];
    String methodName = (String) functionArguments[1];
    String[] signature = (String[]) functionArguments[2];
    Object[] args = (Object[]) functionArguments[3];
    String memberName = (String) functionArguments[4];
    Object returnObj = null;
    try {
        final int nargs = (args == null) ? 0 : args.length;
        if (methodName.startsWith("set") && methodName.length() > 3 && nargs == 1) {
            Attribute attr = new Attribute(methodName.substring(3), args[0]);
            mbeanServer.setAttribute(objectName, attr);
            fc.getResultSender().lastResult((Serializable) null);
        } else if (methodName.equals("addNotificationListener")) {
            notificationHub.addHubNotificationListener(memberName, objectName);
            fc.getResultSender().lastResult((Serializable) ManagementConstants.UNDEFINED);
        } else if (methodName.equals("removeNotificationListener")) {
            notificationHub.removeHubNotificationListener(memberName, objectName);
            fc.getResultSender().lastResult((Serializable) ManagementConstants.UNDEFINED);
        } else if (methodName.equals("getNotificationInfo")) {
            fc.getResultSender().lastResult(mbeanServer.getMBeanInfo(objectName));
        } else {
            returnObj = mbeanServer.invoke(objectName, methodName, args, signature);
            fc.getResultSender().lastResult((Serializable) returnObj);
        }
        executedSuccessfully = true;
    } catch (InstanceNotFoundException e) {
        if (cache != null && !cache.isClosed()) {
            sendException(e, fc);
        }
    } catch (ReflectionException e) {
        sendException(e, fc);
    } catch (MBeanException e) {
        sendException(e, fc);
    } catch (NullPointerException e) {
        sendException(e, fc);
    } catch (Exception e) {
        sendException(e, fc);
    } finally {
        if (!executedSuccessfully) {
            if (cache == null || (cache != null && cache.isClosed())) {
                Exception e = new Exception(ManagementStrings.MEMBER_IS_SHUTTING_DOWN.toLocalizedString());
                sendException(e, fc);
                // member is closing or invalid member
                return;
            }
        }
    }
}
Also used : ReflectionException(javax.management.ReflectionException) Serializable(java.io.Serializable) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) InternalCache(org.apache.geode.internal.cache.InternalCache) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException)

Example 29 with MBeanException

use of javax.management.MBeanException in project geode by apache.

the class JMXDataUpdater method updateMemberClient.

/**
   * function used for getting member clients from mbean and update the clients information in
   * member object's client arraylist
   */
private void updateMemberClient(ObjectName mbeanName) throws IOException {
    try {
        String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER);
        if (cluster.getMembersHMap().containsKey(memberName)) {
            Cluster.Member existingMember = cluster.getMembersHMap().get(memberName);
            HashMap<String, Cluster.Client> memberClientsHM = new HashMap<String, Cluster.Client>();
            existingMember.setMemberPort("" + this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_PORT));
            this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS_ALT);
            existingMember.setHostnameForClients((String) this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS_ALT));
            existingMember.setBindAddress((String) this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_BINDADDRESS));
            CompositeData[] compositeData = (CompositeData[]) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_SHOWALLCLIENTS, null, null));
            for (CompositeData cmd : compositeData) {
                Cluster.Client client = new Cluster.Client();
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID)) {
                    client.setId((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NAME)) {
                    client.setName((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NAME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME)) {
                    client.setHost((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE)) {
                    client.setQueueSize((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME)) {
                    client.setProcessCpuTime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_UPTIME)) {
                    client.setUptime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_UPTIME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS)) {
                    client.setThreads((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS)) {
                    client.setGets((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS)) {
                    client.setPuts((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpus((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CPUS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpuUsage(0);
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CONNECTED)) {
                    client.setConnected((Boolean) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTED));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTCQCOUNT)) {
                    client.setClientCQCount((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTCQCOUNT));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_SUBSCRIPTIONENABLED)) {
                    client.setSubscriptionEnabled((Boolean) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_SUBSCRIPTIONENABLED));
                }
                memberClientsHM.put(client.getId(), client);
            }
            existingMember.updateMemberClientsHMap(memberClientsHM);
        }
    } catch (InstanceNotFoundException | ReflectionException | AttributeNotFoundException | MBeanException infe) {
        logger.warn(infe);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

Example 30 with MBeanException

use of javax.management.MBeanException in project geode by apache.

the class JMXDataUpdater method updateClusterSystem.

/**
   * function used to get attribute values of Cluster System and map them to cluster vo
   * 
   * @param mbeanName Cluster System MBean
   */
private void updateClusterSystem(ObjectName mbeanName) throws IOException {
    try {
        if (!this.isAddedNotiListner) {
            this.mbs.addNotificationListener(mbeanName, this, null, new Object());
            this.isAddedNotiListner = true;
        }
        String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTSERVERS, null, null));
        cluster.setServerCount(serverCnt.length);
        TabularData table = (TabularData) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_VIEWREMOTECLUSTERSTATUS, null, null));
        Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
        cluster.getWanInformationObject().clear();
        for (CompositeData row : rows) {
            final Object key = row.get("key");
            final Object value = row.get("value");
            cluster.getWanInformationObject().put((String) key, (Boolean) value);
        }
        AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.CLUSTER_MBEAN_ATTRIBUTES);
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);
            String name = attribute.getName();
            switch(name) {
                case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT:
                    cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS:
                    cluster.setClientConnectionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID:
                    cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT:
                    cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION:
                    try {
                        cluster.setRunningFunctionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setRunningFunctionCount(0);
                        continue;
                    }
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT:
                    cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS:
                    cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED:
                    cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK:
                    cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE:
                    cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_USEDHEAPSIZE:
                    try {
                        cluster.setUsedHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setUsedHeapSize((long) 0);
                        continue;
                    }
                    cluster.getMemoryUsageTrend().add(cluster.getUsedHeapSize());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT:
                    cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT:
                    cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE:
                    try {
                        cluster.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setTotalBytesOnDisk((long) 0);
                        continue;
                    }
                    cluster.getTotalBytesOnDiskTrend().add(cluster.getTotalBytesOnDisk());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                    cluster.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES:
                    try {
                        cluster.setWritePerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setWritePerSec(0);
                        continue;
                    }
                    cluster.getWritePerSecTrend().add(cluster.getWritePerSec());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS:
                    try {
                        cluster.setReadPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setReadPerSec(0);
                        continue;
                    }
                    cluster.getReadPerSecTrend().add(cluster.getReadPerSec());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE:
                    cluster.setQueriesPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                    cluster.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES:
                    long trendVal = determineCurrentJVMPauses(PulseConstants.JVM_PAUSES_TYPE_CLUSTER, "", getLongAttribute(attribute.getValue(), attribute.getName()));
                    cluster.setGarbageCollectionCount(trendVal);
                    cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT:
                    cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
            }
        }
    } catch (InstanceNotFoundException | ReflectionException | MBeanException infe) {
        logger.warn(infe);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) CompositeData(javax.management.openmbean.CompositeData) InstanceNotFoundException(javax.management.InstanceNotFoundException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) TabularData(javax.management.openmbean.TabularData) Collection(java.util.Collection) MBeanException(javax.management.MBeanException)

Aggregations

MBeanException (javax.management.MBeanException)101 ReflectionException (javax.management.ReflectionException)47 InstanceNotFoundException (javax.management.InstanceNotFoundException)39 AttributeNotFoundException (javax.management.AttributeNotFoundException)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)31 ObjectName (javax.management.ObjectName)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)25 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 MalformedObjectNameException (javax.management.MalformedObjectNameException)17 RuntimeOperationsException (javax.management.RuntimeOperationsException)17 ServiceNotFoundException (javax.management.ServiceNotFoundException)17 RuntimeErrorException (javax.management.RuntimeErrorException)14 Attribute (javax.management.Attribute)12 Method (java.lang.reflect.Method)10 DynamicMBean (javax.management.DynamicMBean)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)10 Descriptor (javax.management.Descriptor)9 MalformedURLException (java.net.MalformedURLException)7 MBeanRegistrationException (javax.management.MBeanRegistrationException)7 MBeanServer (javax.management.MBeanServer)7