Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlertDefinitionCommand sync fails with class cast error #22

Open
rmc3 opened this issue Dec 15, 2012 · 1 comment
Open

AlertDefinitionCommand sync fails with class cast error #22

rmc3 opened this issue Dec 15, 2012 · 1 comment

Comments

@rmc3
Copy link

rmc3 commented Dec 15, 2012

Attempting to sync the following XML via hqapi.sh alertdefinition sync --file produces the error immediately after it.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AlertDefinitionResponse>
    <Status>Success</Status>
    <AlertDefinition mtime="1354626457188" ctime="1353803425597" id="298258" name="Linux Platform Availability - PROBLEM" description="https://extranet.contegix.com/display/CNT/Platform+Availability" parent="98431" priority="2" enabled="false" active="false" frequency="0" count="0" range="0" willRecover="true" notifyFiltered="false" controlFiltered="false">
        <Resource id="178032" name="rmc-testing.contegix.com"/>
        <Escalation id="11009" name="RMC Escalation" description="Test escalation for Rich" pauseAllowed="false" maxPauseTime="9223372036854775807" notifyAll="false" repeat="true"/>
        <AlertCondition required="true" type="1" thresholdValue="1.0" thresholdComparator="!=" thresholdMetric="Availability"/>
        <AlertAction id="11744316" className="org.hyperic.hq.measurement.action.MetricAlertAction"/>
    </AlertDefinition>
</AlertDefinitionResponse>

Error running command: null
java.lang.ClassCastException
at java.lang.Class.cast(Class.java:2990)
at org.hyperic.hq.hqapi1.XmlUtil.deserialize(XmlUtil.java:68)
at org.hyperic.hq.hqapi1.tools.AlertDefinitionCommand.sync(AlertDefinitionCommand.java:439)
at org.hyperic.hq.hqapi1.tools.AlertDefinitionCommand.handleCommand(AlertDefinitionCommand.java:152)
at org.hyperic.hq.hqapi1.tools.Shell.dispatchCommand(Shell.java:244)
at org.hyperic.hq.hqapi1.tools.Shell.main(Shell.java:259)

Digging into the source, the issue seems to be that the sync method in AlertDefinitionCommand.java passes an object of type AlertDefinitionsResponse to XmlUtil.deserialize, which then attempts to cast it to an object of type AlertDefinitionResponse. I confirmed this by modifying the deserialize method in XmlUtil.java to have some debugging text:

    public static <T> T deserialize(Class<T> res, InputStream is)
        throws JAXBException
    {
        String pkg = res.getPackage().getName();
        JAXBContext jc = getCachedContext(pkg);
        Unmarshaller u = jc.createUnmarshaller();
        u.setEventHandler(new DefaultValidationEventHandler());
        Object unmarshalOut = u.unmarshal(is);
        System.out.println(res.getName());
        System.out.println(unmarshalOut.getClass().getName());
        return res.cast(unmarshalOut);
    }

When built and run with the same command, it produces the following output:

org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse
org.hyperic.hq.hqapi1.types.AlertDefinitionResponse
Error running command: null
java.lang.ClassCastException
at java.lang.Class.cast(Class.java:2990)
at org.hyperic.hq.hqapi1.XmlUtil.deserialize(XmlUtil.java:68)
at org.hyperic.hq.hqapi1.tools.AlertDefinitionCommand.sync(AlertDefinitionCommand.java:439)
at org.hyperic.hq.hqapi1.tools.AlertDefinitionCommand.handleCommand(AlertDefinitionCommand.java:152)
at org.hyperic.hq.hqapi1.tools.Shell.dispatchCommand(Shell.java:244)
at org.hyperic.hq.hqapi1.tools.Shell.main(Shell.java:259)

This demonstrates that the res object is of type org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse while the object returned by the JAXB unmarshaller is of type org.hyperic.hq.hqapi1.types.AlertDefinitionResponse.

The only workaround I have found so far is to manually change the root node of the XML to be synced to be AlertDefinitionsResponse instead of AlertDefinitionResponse, such as the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AlertDefinitionsResponse>
    <Status>Success</Status>
    <AlertDefinition mtime="1354626457188" ctime="1353803425597" id="298258" name="Linux Platform Availability - PROBLEM" description="https://extranet.contegix.com/display/CNT/Platform+Availability" parent="98431" priority="2" enabled="false" active="false" frequency="0" count="0" range="0" willRecover="true" notifyFiltered="false" controlFiltered="false">
        <Resource id="178032" name="rmc-testing.contegix.com"/>
        <Escalation id="11009" name="RMC Escalation" description="Test escalation for Rich" pauseAllowed="false" maxPauseTime="9223372036854775807" notifyAll="false" repeat="true"/>
        <AlertCondition required="true" type="1" thresholdValue="1.0" thresholdComparator="!=" thresholdMetric="Availability"/>
        <AlertAction id="11744316" className="org.hyperic.hq.measurement.action.MetricAlertAction"/>
    </AlertDefinition>
</AlertDefinitionsResponse>

This issue has also been reported here: http://communities.vmware.com/message/2164480

@rmc3
Copy link
Author

rmc3 commented Dec 15, 2012

A note: The original XML was generated by hqapi.sh alertdefinition list and had two fields changed. The issue then is that the output from the HQAPI's alertdefinition list command cannot be synced back in with alertdefinition sync without further modification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant