Search in sources :

Example 21 with InstanceNotFoundException

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

the class MBeanProcessController method invokeOperationOnTargetMBean.

/**
   * Connects to the process and use its MBean to stop it.
   * 
   * @param namePattern the name pattern of the MBean to use for stopping
   * @param pidAttribute the name of the MBean attribute with the process id to compare against
   * @param methodName the name of the MBean operation to invoke
   * @param attributes the names of the MBean attributes to compare with expected values
   * @param values the expected values of the specified MBean attributes
   *
   * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
   *         in the process
   * @throws IOException if a communication problem occurred when talking to the MBean server
   * @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason
   */
private Object invokeOperationOnTargetMBean(final ObjectName namePattern, final String pidAttribute, final String methodName, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException {
    ObjectName objectName = namePattern;
    connect();
    try {
        final QueryExp constraint = buildQueryExp(pidAttribute, attributes, values);
        final Set<ObjectName> mbeanNames = this.server.queryNames(namePattern, constraint);
        if (mbeanNames.isEmpty()) {
            throw new MBeanInvocationFailedException("Failed to find mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
        }
        if (mbeanNames.size() > 1) {
            throw new MBeanInvocationFailedException("Found more than one mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
        }
        objectName = mbeanNames.iterator().next();
        return invoke(objectName, methodName);
    } catch (InstanceNotFoundException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } catch (MBeanException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } catch (ReflectionException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } finally {
        disconnect();
    }
}
Also used : ReflectionException(javax.management.ReflectionException) QueryExp(javax.management.QueryExp) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 22 with InstanceNotFoundException

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

the class LocalProcessController method invokeOperationOnTargetMBean.

/**
   * Connects to the process and use its MBean to stop it.
   * 
   * @param namePattern the name pattern of the MBean to use for stopping
   * @param pidAttribute the name of the MBean attribute with the process id to compare against
   * @param methodName the name of the MBean operation to invoke
   * @param attributes the names of the MBean attributes to compare with expected values
   * @param values the expected values of the specified MBean attributes
   *
   * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
   *         in the process
   * @throws IOException if a communication problem occurred when talking to the MBean server
   * @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason
   * @throws PidUnavailableException if parsing the pid from the RuntimeMXBean name fails
   */
private Object invokeOperationOnTargetMBean(final ObjectName namePattern, final String pidAttribute, final String methodName, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException, PidUnavailableException {
    ObjectName objectName = namePattern;
    connect();
    try {
        final QueryExp constraint = buildQueryExp(pidAttribute, attributes, values);
        final Set<ObjectName> mbeanNames = this.server.queryNames(namePattern, constraint);
        if (mbeanNames.isEmpty()) {
            throw new MBeanInvocationFailedException("Failed to find mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
        }
        if (mbeanNames.size() > 1) {
            throw new MBeanInvocationFailedException("Found more than one mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
        }
        objectName = mbeanNames.iterator().next();
        return invoke(objectName, methodName);
    } catch (InstanceNotFoundException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } catch (MBeanException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } catch (ReflectionException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } finally {
        disconnect();
    }
}
Also used : ReflectionException(javax.management.ReflectionException) QueryExp(javax.management.QueryExp) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 23 with InstanceNotFoundException

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

the class DistributedSystemBridge method addMemberToSystem.

/**
   * Add a proxy to the map to be used by bridge.
   *
   * @param objectName object name of the proxy
   * @param proxy actual proxy instance
   */
public void addMemberToSystem(ObjectName objectName, MemberMXBean proxy, FederationComponent newState) {
    if (objectName.equals(thisMemberName)) {
        ObjectName distrObjectName = MBeanJMXAdapter.getDistributedSystemName();
        DistributedSystemMXBean systemMBean = new DistributedSystemMBean(this);
        service.registerInternalMBean(systemMBean, distrObjectName);
        this.systemLevelNotifEmitter = (DistributedSystemMBean) service.getDistributedSystemMXBean();
        this.distListener = new DistributedSystemNotifListener();
    }
    if (mapOfMembers != null) {
        mapOfMembers.put(objectName, proxy);
        memberSetSize = mapOfMembers.values().size();
    }
    updateMember(objectName, newState, null);
    try {
        mbeanServer.addNotificationListener(objectName, distListener, null, null);
    } catch (InstanceNotFoundException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage());
        }
        logger.info(LocalizedMessage.create(ManagementStrings.INSTANCE_NOT_FOUND, objectName));
    }
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectName(javax.management.ObjectName)

Example 24 with InstanceNotFoundException

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

the class ManagementAdapter method handleManagerStart.

/**
   * Handles all the distributed mbean creation part when a Manager is started
   */
public void handleManagerStart() throws ManagementException {
    if (!isServiceInitialised("handleManagerStart")) {
        return;
    }
    MBeanJMXAdapter jmxAdapter = service.getJMXAdapter();
    Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean();
    DistributedSystemBridge dsBridge = new DistributedSystemBridge(service);
    this.aggregator = new MBeanAggregator(dsBridge);
    // register the aggregator for Federation framework to use
    service.addProxyListener(aggregator);
    /*
     * get the local member mbean as it need to be provided to aggregator first
     */
    MemberMXBean localMember = service.getMemberMXBean();
    ObjectName memberObjectName = MBeanJMXAdapter.getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());
    FederationComponent addedComp = service.getLocalManager().getFedComponents().get(memberObjectName);
    service.afterCreateProxy(memberObjectName, MemberMXBean.class, localMember, addedComp);
    for (ObjectName objectName : registeredMBeans.keySet()) {
        if (objectName.equals(memberObjectName)) {
            continue;
        }
        Object object = registeredMBeans.get(objectName);
        ObjectInstance instance;
        try {
            instance = mbeanServer.getObjectInstance(objectName);
            String className = instance.getClassName();
            Class cls = ClassLoadUtil.classFromName(className);
            Type[] intfTyps = cls.getGenericInterfaces();
            FederationComponent newObj = service.getLocalManager().getFedComponents().get(objectName);
            for (Type intfTyp1 : intfTyps) {
                Class intfTyp = (Class) intfTyp1;
                service.afterCreateProxy(objectName, intfTyp, object, newObj);
            }
        } catch (InstanceNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean ");
            }
            throw new ManagementException(e);
        } catch (ClassNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean");
            }
            throw new ManagementException(e);
        }
    }
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) MemberMXBean(org.apache.geode.management.MemberMXBean) Type(java.lang.reflect.Type) JMXNotificationType(org.apache.geode.management.JMXNotificationType) ManagementException(org.apache.geode.management.ManagementException) MBeanJMXAdapter(org.apache.geode.management.internal.MBeanJMXAdapter) FederationComponent(org.apache.geode.management.internal.FederationComponent)

Example 25 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException 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)

Aggregations

InstanceNotFoundException (javax.management.InstanceNotFoundException)102 ObjectName (javax.management.ObjectName)59 ReflectionException (javax.management.ReflectionException)44 MBeanException (javax.management.MBeanException)32 MalformedObjectNameException (javax.management.MalformedObjectNameException)28 MBeanRegistrationException (javax.management.MBeanRegistrationException)25 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)19 MBeanServer (javax.management.MBeanServer)17 IOException (java.io.IOException)16 AttributeNotFoundException (javax.management.AttributeNotFoundException)16 Attribute (javax.management.Attribute)15 IntrospectionException (javax.management.IntrospectionException)14 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)14 AttributeList (javax.management.AttributeList)12 ObjectInstance (javax.management.ObjectInstance)12 MBeanInfo (javax.management.MBeanInfo)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)10 RuntimeOperationsException (javax.management.RuntimeOperationsException)9 ArrayList (java.util.ArrayList)7 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)7