cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Server (Deployed) generation with Java

ilvetz
Super Contributor

Hi all!

 

We are developing CMDB integration between our CMDB (not service Now) and HOPEX (V2R1) using a custom Java API middleware.

 

What are the mandatory and suggested attributes/objetcs to insert/update "Server (Deployed)" objects?

We would like to link the operating system running on the server and the "IT Server" object which describe the logical details and use of the server.

 

At the moment, we just create the core object with no details, using this code:

 

        MegaRoot root = connector.getRoot();

        if (systems == null)
            systems = root.getCollection(HOPEXID);

        LOG.debug("Target collection size: " + systems.size());

        try
        {
            // TODO: check existence. how? using exception?

            LOG.trace("Loading " + system.toString());
            MegaObject newServer = systems.add(system.getName());
            LOG.trace("New server is " + newServer.getProp("Name"));

            /* TODO: now, I want to upload operating system detail. how?
            */

            // commit updates
            root.megaCommit();
            LOG.trace("Committed!");
        }
        catch (Exception e) {
            // MegaCollection#add non genera una MegaException
            LOG.warn(e.getMessage());
        } finally {
            connector.close();
        }

 

Thanks a lot!

1 Reply

ilvetz
Super Contributor

Hi all.

 

Thank you to anyone who can give support.

 

The following code add a Server(Deployed) object and, eventually, a Software Technology from its Operating System. Then I create a "Deployed Technology" object which is linked to the Software Technology and the Server(Deployed) using setProp methods.

 

This produces a collection of Deployed Technology objects that counts as many objects as the Server deployed collection.

 

I would like to link a single "Deployed Technology" object to many "Server (Deployed)" but I can't find the right MetaAssociation and how to use that in Java.

 

Any idea is appreciated. Thanks.

 

MyComputerSystem system = [...];

MegaCollection systems = root.getCollection(ServerDeployed.ID);

try {
    MegaObject addThis = null;

    if (system.getGuid() != null && system.getGuid().length() > 1) {
        addThis = root.getSelection("Select [Server (Deployed)] Where [CMDB_GUID] Like \"#" + system.getGuid() + "#\" ").get(1);
    }

    if (addThis == null || !addThis.exists()) {
        addThis = systems.add(system.getName());
        addThis.setProp("Comment", system.getGuid());
    } else {
        addThis.setProp("Short Name", system.getName());
    }

    if (addThis != null && system.getOSName() != null && system.getOSName().length() > 1) {
        MegaObject techOS = root.getSelection("Select [Software Technology] Where [Short Name] = \"" + system.getOSName() + "\"").get(1);

        if (techOS == null || !techOS.exists())
        {
            MegaCollection technologies = root.getCollection(SoftwareTechnology.ID);
            techOS = technologies.add(system.getOSName());
        } else {
            techOS.setProp("Short Name", system.getOSName());
        }

        MegaObject deployedOS = root.getSelection("Select [Deployed Technology] Where " +
                "[Deployable Technology]:[Software Technology].[Short Name] = \"" + system.getOSName() + "\" " +
                "And [Deployment Support]:[Server (Deployed)].[CMDB_GUID] Like \"#" + system.getGuid() + "#\" "
        ).get(1);
        if (deployedOS == null || !deployedOS.exists())
        {
            MegaCollection deployedTechs = root.getCollection(DeployedTechnology.ID);
            deployedOS = deployedTechs.add(system.getOSName() + " on " + system.getName());
            deployedOS.setProp("Deployable Object", techOS.getProp("Absolute Identifier"));
            deployedOS.setProp("Deployment Support", addThis.getProp("Absolute Identifier"));
        } else {
            deployedOS.setProp("Short Name", system.getOSName() + " on " + system.getName());
        }
    }

    root.megaCommit();
} catch (Exception e) {
    LOG.warn(e.getMessage());
} finally {
    connector.close();
}