Search in sources :

Example 46 with Attribute

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

the class MBeanServerWrapper method getAttributes.

@Override
public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException {
    AttributeList results = new AttributeList();
    for (String attribute : attributes) {
        try {
            Object value = getAttribute(name, attribute);
            Attribute att = new Attribute(attribute, value);
            results.add(att);
        } catch (Exception e) {
            throw new GemFireSecurityException("error getting value of " + attribute + " from " + name, e);
        }
    }
    return results;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) OperationsException(javax.management.OperationsException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException)

Example 47 with Attribute

use of javax.management.Attribute 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 48 with Attribute

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

the class JMXDataUpdater method initializeMember.

/**
   * function used to iterate through all member attributes and return the updated member
   */
private Cluster.Member initializeMember(ObjectName mbeanName, Cluster.Member member) throws InstanceNotFoundException, ReflectionException, IOException {
    AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.MEMBER_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_GEMFIREVERSION:
                if (member.getGemfireVersion() == null) {
                    // Set Member's GemFire Version if not set already
                    String gemfireVersion = obtainGemfireVersion(getStringAttribute(attribute.getValue(), attribute.getName()));
                    member.setGemfireVersion(gemfireVersion);
                }
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_MANAGER:
                member.setManager(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT:
                member.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_LOCATOR:
                member.setLocator(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE:
                member.setTotalDiskUsage(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_SERVER:
                member.setServer(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_TOTALFILEDESCRIPTOROPEN:
                member.setTotalFileDescriptorOpen(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_LOADAVERAGE:
                member.setLoadAverage(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                member.setThroughputWrites(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                member.getThroughputWritesTrend().add(member.getThroughputWrites());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                member.setThroughputReads(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                member.getThroughputReadsTrend().add(member.getThroughputReads());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES:
                long trendVal = determineCurrentJVMPauses(PulseConstants.JVM_PAUSES_TYPE_MEMBER, member.getName(), getLongAttribute(attribute.getValue(), attribute.getName()));
                member.setGarbageCollectionCount(trendVal);
                member.getGarbageCollectionSamples().add(member.getGarbageCollectionCount());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_USEDMEMORY:
                member.setCurrentHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                member.getHeapUsageSamples().add(member.getCurrentHeapSize());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_MAXMEMORY:
                member.setMaxHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_NUMTHREADS:
                member.setNumThreads(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_MEMBERUPTIME:
                member.setUptime(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_HOST:
                member.setHost(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS:
                member.setHostnameForClients(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_BINDADDRESS:
                member.setBindAddress(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_TOTALBYTESONDISK:
                member.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName()));
                member.getTotalBytesOnDiskSamples().add(member.getTotalBytesOnDisk());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_CPUUSAGE:
                member.setCpuUsage(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                member.getCpuUsageSamples().add(member.getCpuUsage());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_HOSTCPUUSAGE:
                // Float value is expected for host cpu usage.
                // TODO Remove Float.valueOf() when float value is provided in mbean
                member.setHostCpuUsage(Double.valueOf(getIntegerAttribute(attribute.getValue(), attribute.getName())));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_MEMBER:
                member.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_ID:
                member.setId(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS:
                member.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                member.getGetsPerSecond().add(member.getGetsRate());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES:
                member.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                member.getPutsPerSecond().add(member.getPutsRate());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_OFFHEAPFREESIZE:
                member.setOffHeapFreeSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_OFFHEAPUSEDSIZE:
                member.setOffHeapUsedSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_SERVERGROUPS:
                String[] sgValues = (String[]) attribute.getValue();
                member.getServerGroups().clear();
                for (int k = 0; k < sgValues.length; k++) {
                    member.getServerGroups().add(sgValues[k]);
                }
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_REDUNDANCYZONES:
                String rzValue = "";
                if (null != attribute.getValue()) {
                    rzValue = getStringAttribute(attribute.getValue(), attribute.getName());
                }
                member.getRedundancyZones().clear();
                if (!rzValue.isEmpty()) {
                    member.getRedundancyZones().add(rzValue);
                }
                break;
        }
    }
    return member;
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList)

Example 49 with Attribute

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

the class JMXDataUpdater method initGatewaySender.

/**
   * function used to get attribute values of Gateway Sender and map them to GatewaySender inner
   * class object
   */
private Cluster.GatewaySender initGatewaySender(ObjectName mbeanName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException, AttributeNotFoundException, MBeanException {
    Cluster.GatewaySender gatewaySender = new Cluster.GatewaySender();
    AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.GATEWAYSENDER_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_EVENTRECEIVEDDATE:
                gatewaySender.setLinkThroughput(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_BATCHSIZE:
                gatewaySender.setBatchSize(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_SENDERID:
                gatewaySender.setId(getStringAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_EVENTQUEUESIZE:
                gatewaySender.setQueueSize(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_RUNNING:
                gatewaySender.setStatus(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_PRIMARY:
                gatewaySender.setPrimary(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_PERSISTENCEENABLED:
                gatewaySender.setPersistenceEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_PARALLEL:
                gatewaySender.setSenderType(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_REMOTE_DS_ID:
                gatewaySender.setRemoteDSId(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_EVENTS_EXCEEDING_ALERT_THRESHOLD:
                gatewaySender.setEventsExceedingAlertThreshold(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
        }
    }
    return gatewaySender;
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList)

Example 50 with Attribute

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

the class JMXDataUpdater method updateClusterStatement.

private void updateClusterStatement(ObjectName mbeanName) throws IOException {
    try {
        AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.STATEMENT_MBEAN_ATTRIBUTES);
        // retrieve the full path of the region
        String statementDefinition = mbeanName.getKeyProperty("name");
        if (isQuoted(statementDefinition)) {
            statementDefinition = ObjectName.unquote(statementDefinition);
        }
        Cluster.Statement statement = cluster.getClusterStatements().get(statementDefinition);
        if (null == statement) {
            statement = new Cluster.Statement();
            statement.setQueryDefinition(statementDefinition);
        }
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);
            String name = attribute.getName();
            switch(name) {
                case PulseConstants.MBEAN_ATTRIBUTE_NUMTIMESCOMPILED:
                    statement.setNumTimesCompiled(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMEXECUTION:
                    statement.setNumExecution(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMEXECUTIONSINPROGRESS:
                    statement.setNumExecutionsInProgress(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMTIMESGLOBALINDEXLOOKUP:
                    statement.setNumTimesGlobalIndexLookup(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMROWSMODIFIED:
                    statement.setNumRowsModified(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_PARSETIME:
                    statement.setParseTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_BINDTIME:
                    statement.setBindTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_OPTIMIZETIME:
                    statement.setOptimizeTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_ROUTINGINFOTIME:
                    statement.setRoutingInfoTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_GENERATETIME:
                    statement.setGenerateTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALCOMPILATIONTIME:
                    statement.setTotalCompilationTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_EXECUTIONTIME:
                    statement.setExecutionTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_PROJECTIONTIME:
                    statement.setProjectionTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALEXECUTIONTIME:
                    statement.setTotalExecutionTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_ROWSMODIFICATIONTIME:
                    statement.setRowsModificationTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_QNNUMROWSSEEN:
                    statement.setqNNumRowsSeen(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_QNMSGSENDTIME:
                    statement.setqNMsgSendTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_QNMSGSERTIME:
                    statement.setqNMsgSerTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_QNRESPDESERTIME:
                    statement.setqNRespDeSerTime(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
            }
        }
        cluster.addClusterStatement(statementDefinition, statement);
    // TODO : to store data for sparklines later
    /*
       * region.getPutsPerSecTrend().add(region.getPutsRate());
       * region.getGetsPerSecTrend().add(region.getGetsRate());
       */
    } catch (InstanceNotFoundException | ReflectionException infe) {
        logger.warn(infe);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException)

Aggregations

Attribute (javax.management.Attribute)157 ObjectName (javax.management.ObjectName)94 MBeanServer (javax.management.MBeanServer)56 AttributeList (javax.management.AttributeList)46 Test (org.junit.Test)38 ReflectionException (javax.management.ReflectionException)29 MBeanException (javax.management.MBeanException)25 HashMap (java.util.HashMap)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)22 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)21 AttributeNotFoundException (javax.management.AttributeNotFoundException)20 MBeanServerConnection (javax.management.MBeanServerConnection)15 MBeanInfo (javax.management.MBeanInfo)14 JMXConnector (javax.management.remote.JMXConnector)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)12 List (java.util.List)10 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ArrayList (java.util.ArrayList)9