Search in sources :

Example 6 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpErrorHandlerAgent method getNext.

/**
     * Processes a <CODE>getNext</CODE> operation. It will throw an exception for V1 requests or it will set exceptions within the list for V2 requests..
     *
     * @param inRequest The SnmpMibRequest object holding the list of variables to be retrieved.
     *
     * @exception SnmpStatusException An error occurred during the operation.
     */
@Override
public void getNext(SnmpMibRequest inRequest) throws SnmpStatusException {
    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "getNext", "GetNext in Exception");
    if (inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
        throw new SnmpStatusException(SnmpStatusException.noSuchName);
    Enumeration<SnmpVarBind> l = inRequest.getElements();
    while (l.hasMoreElements()) {
        SnmpVarBind varbind = l.nextElement();
        varbind.setEndOfMibView();
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 7 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpGenericObjectServer method set.

/**
     * Set the value of an SNMP variable.
     *
     * <p><b><i>
     * You should never need to use this method directly.
     * </i></b></p>
     *
     * @param meta  The impacted metadata object
     * @param name  The ObjectName of the impacted MBean
     * @param x     The new requested SnmpValue
     * @param id    The OID arc identifying the variable we're trying to set.
     * @param data  User contextual data allocated through the
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
     *
     * @return The new value of the variable after the operation.
     *
     * @exception SnmpStatusException whenever an SNMP exception must be
     *      raised. Raising an exception will abort the request. <br>
     *      Exceptions should never be raised directly, but only by means of
     * <code>
     * req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     **/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
    final String attname = meta.getAttributeName(id);
    final Object attvalue = meta.buildAttributeValue(id, x);
    final Attribute att = new Attribute(attname, attvalue);
    Object result = null;
    try {
        server.setAttribute(name, att);
        result = server.getAttribute(name, attname);
    } catch (InvalidAttributeValueException iv) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
    } catch (InstanceNotFoundException f) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    }
    return meta.buildSnmpValue(id, result);
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 8 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpGenericObjectServer method check.

/**
     * Checks whether a SET operation can be performed on a given SNMP
     * variable.
     *
     * @param meta  The impacted metadata object
     * @param name  The ObjectName of the impacted MBean
     * @param x     The new requested SnmpValue
     * @param id    The OID arc identifying the variable we're trying to set.
     * @param data  User contextual data allocated through the
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
     *
     * <p>
     * This method calls checkSetAccess() on the meta object, and then
     * tries to invoke the check<i>AttributeName</i>() method on the MBean.
     * If this method is not defined then it is assumed that the SET
     * won't fail.
     * </p>
     *
     * <p><b><i>
     * This method is called internally by <code>mibgen</code> generated
     * objects and you should never need to call it directly.
     * </i></b></p>
     *
     * @exception SnmpStatusException if the requested SET operation must
     *      be rejected. Raising an exception will abort the request. <br>
     *      Exceptions should never be raised directly, but only by means of
     * <code>
     * req.registerCheckException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     *
     **/
// XXX xxx ZZZ zzz Maybe we should go through the MBeanInfo here?
public void check(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
    meta.checkSetAccess(x, id, data);
    try {
        final String attname = meta.getAttributeName(id);
        final Object attvalue = meta.buildAttributeValue(id, x);
        final Object[] params = new Object[1];
        final String[] signature = new String[1];
        params[0] = attvalue;
        signature[0] = attvalue.getClass().getName();
        server.invoke(name, "check" + attname, params, signature);
    } catch (SnmpStatusException e) {
        throw e;
    } catch (InstanceNotFoundException i) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
    // checkXXXX() not defined => do nothing
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 9 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpMibTable method findNextHandlingNode.

// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode. The algorithm is very
// largely inspired from the original getNext() method.
//
// ---------------------------------------------------------------------
@Override
final synchronized long[] findNextHandlingNode(SnmpVarBind varbind, long[] oid, int pos, int depth, SnmpRequestTree handlers, AcmChecker checker) throws SnmpStatusException {
    int length = oid.length;
    if (handlers == null) {
        //
        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
    }
    final Object data = handlers.getUserData();
    final int pduVersion = handlers.getRequestPduVersion();
    long var = -1;
    //
    if (pos >= length) {
        // this will have the side effect to set
        //    oid[pos] = nodeId
        // and
        //    (pos+1) = length
        // so we won't fall into the "else if" cases below -
        // so using "else if" rather than "if ..." is guaranteed
        // to be safe.
        //
        oid = new long[1];
        oid[0] = nodeId;
        pos = 0;
        length = 1;
    } else if (oid[pos] > nodeId) {
        //
        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
    } else if (oid[pos] < nodeId) {
        // we must return the first leaf under the first columnar
        // object, so we are back to our first case where pos was
        // out of bounds... => reset the oid to contain only the
        // arc of the xxxEntry object.
        //
        oid = new long[1];
        oid[0] = nodeId;
        pos = 0;
        length = 0;
    } else if ((pos + 1) < length) {
        // The arc at the position "pos+1" is the id of the columnar
        // object (ie: the id of the variable in the table entry)
        //
        var = oid[pos + 1];
    }
    // Now that we've got everything right we can begin.
    SnmpOid entryoid;
    if (pos == (length - 1)) {
        // pos points to the last arc in the oid, and this arc is
        // guaranteed to be the xxxEntry id (we have handled all
        // the other possibilities before)
        //
        // We must therefore return the first leaf below the first
        // columnar object in the table.
        //
        // Get the first index. If an exception is raised,
        // then it means that the table is empty. We thus do not
        // have to catch the exception - we let it propagate to
        // the caller.
        //
        entryoid = getNextOid(data);
        var = getNextVarEntryId(entryoid, var, data, pduVersion);
    } else if (pos == (length - 2)) {
        // In that case we have (pos+1) = (length-1), so pos
        // points to the arc of the querried variable (columnar object).
        // Since the requested oid stops there, it means we have
        // to return the first leaf under this columnar object.
        //
        // So we first get the first index:
        // Note: if this raises an exception, this means that the table
        // is empty, so we can let the exception propagate to the caller.
        //
        entryoid = getNextOid(data);
        //
        if (skipEntryVariable(entryoid, var, data, pduVersion)) {
            var = getNextVarEntryId(entryoid, var, data, pduVersion);
        }
    } else {
        //
        try {
            entryoid = getNextOid(oid, pos + 2, data);
            //
            if (skipEntryVariable(entryoid, var, data, pduVersion)) {
                throw new SnmpStatusException(SnmpStatusException.noSuchObject);
            }
        } catch (SnmpStatusException se) {
            entryoid = getNextOid(data);
            var = getNextVarEntryId(entryoid, var, data, pduVersion);
        }
    }
    return findNextAccessibleOid(entryoid, varbind, oid, depth, handlers, checker, data, var);
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid)

Example 10 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpMibTable method getNextOid.

/**
     * Get the <CODE>SnmpOid</CODE> index of the row that follows
     * the given <CODE>oid</CODE> in the table. The given <CODE>
     * oid</CODE> does not need to be a valid row OID index.
     *
     * <p>
     * @param oid The OID from which the search will begin.
     *
     * @param userData A contextual object containing user-data.
     *        This object is allocated through the <code>
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}</code>
     *        for each incoming SNMP request.
     *
     * @return The next <CODE>SnmpOid</CODE> index.
     *
     * @exception SnmpStatusException There is no index following the
     *     specified <CODE>oid</CODE> in the table.
     */
protected SnmpOid getNextOid(SnmpOid oid, Object userData) throws SnmpStatusException {
    if (size == 0) {
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }
    final SnmpOid resOid = oid;
    // Just a simple check to speed up retrieval of last element ...
    //
    // XX SnmpOid last= (SnmpOid) oids.lastElement();
    SnmpOid last = tableoids[tablecount - 1];
    if (last.equals(resOid)) {
        //
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }
    // First find the oid. This will allow to speed up retrieval process
    // during smart discovery of table (using the getNext) as the
    // management station will use the valid index returned during a
    // previous getNext ...
    //
    // Returns the position following the position at which resOid
    // is found, or the position at which resOid should be inserted.
    //
    final int newPos = getInsertionPoint(resOid, false);
    //
    if (newPos > -1 && newPos < size) {
        try {
            // XX last = (SnmpOid) oids.elementAt(newPos);
            last = tableoids[newPos];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
        }
    } else {
        //
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }
    return last;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid)

Aggregations

SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)64 SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)18 SnmpTableHandler (sun.management.snmp.util.SnmpTableHandler)18 SnmpOid (com.sun.jmx.snmp.SnmpOid)15 SnmpMessage (com.sun.jmx.snmp.SnmpMessage)5 SnmpTooBigException (com.sun.jmx.snmp.SnmpTooBigException)5 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)5 MBeanException (javax.management.MBeanException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ReflectionException (javax.management.ReflectionException)5 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 SnmpString (com.sun.jmx.snmp.SnmpString)4 BerDecoder (com.sun.jmx.snmp.BerDecoder)3 BerException (com.sun.jmx.snmp.BerException)3 Attribute (javax.management.Attribute)3 SnmpPduPacket (com.sun.jmx.snmp.SnmpPduPacket)2 SnmpScopedPduPacket (com.sun.jmx.snmp.SnmpScopedPduPacket)2