Example usage for java.lang Integer longValue

List of usage examples for java.lang Integer longValue

Introduction

In this page you can find the example usage for java.lang Integer longValue.

Prototype

public long longValue() 

Source Link

Document

Returns the value of this Integer as a long after a widening primitive conversion.

Usage

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Compare a system's packages against a package profile.
 *
 * @param loggedInUser The current user/*  w  w w.j  av  a  2 s. co  m*/
 * @param serverId ID of server
 * @param profileLabel the label of the package profile
 * @return 1 on success
 *
 * @xmlrpc.doc Compare a system's packages against a package profile.  In
 * the result returned, 'this_system' represents the server provided as an input
 * and 'other_system' represents the profile provided as an input.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #param("string", "profileLabel")
 * @xmlrpc.returntype
 *          #array()
 *              $PackageMetadataSerializer
 *          #array_end()
 */
public Object[] comparePackageProfile(User loggedInUser, Integer serverId, String profileLabel) {

    Long sid = new Long(serverId.longValue());
    SystemManager.lookupByIdAndUser(sid, loggedInUser);

    Profile profile = ProfileFactory.findByNameAndOrgId(profileLabel, loggedInUser.getOrg().getId());

    if (profile == null) {
        throw new InvalidProfileLabelException(profileLabel);
    }

    DataResult dr = ProfileManager.compareServerToProfile(sid, profile.getId(), loggedInUser.getOrg().getId(),
            null);

    return dr.toArray();
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Lists all of the packages that are installed on a system that also belong
 *  to a particular channel.  NOTE: when the arch for an installed package is
 *  unavailable we do not take it into concern, meaning that it is arch unaware.
 *  This is usually the case for RHEL 4 or older.  RHEL 5 started uploading
 *  arch information, so that information is taken into account when matching
 *  packages.//from w w  w. j ava  2  s.c  om
 * @param loggedInUser The current user
 * @param sid the system Id
 * @param channelLabel the channel label
 * @return Array of Package objects representing the intersection of the channel
 *          packages and the system's installed packages
 *
 *
 * @xmlrpc.doc Provides a list of packages installed on a system that are also
 *          contained in the given channel.  The installed package list did not
 *          include arch information before RHEL 5, so it is arch unaware.  RHEL 5
 *          systems do upload the arch information, and thus are arch aware.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #param("string", "channelLabel")
 * @xmlrpc.returntype
 *  #array()
 *      $PackageSerializer
 *  #array_end()
 */
public List<Map<String, Object>> listPackagesFromChannel(User loggedInUser, Integer sid, String channelLabel) {
    SystemManager.lookupByIdAndUser(new Long(sid.longValue()), loggedInUser);
    Channel channel = ChannelFactory.lookupByLabelAndUser(channelLabel, loggedInUser);
    return SystemManager.packagesFromChannel(sid.longValue(), channel.getId());
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Returns the running kernel of the given system.
 *
 * @param loggedInUser The current user// w ww .  j  ava  2  s . c o m
 * @param sid Server ID to lookup.
 * @return Running kernel string.
 *
 * @xmlrpc.doc Returns the running kernel of the given system.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.returntype string
 */
public String getRunningKernel(User loggedInUser, Integer sid) {
    try {
        Server server = SystemManager.lookupByIdAndUser(new Long(sid.longValue()), loggedInUser);
        if (server.getRunningKernel() != null) {
            return server.getRunningKernel();
        }
        return LocalizationService.getInstance().getMessage("server.runningkernel.unknown");
    } catch (LookupException e) {
        throw new NoSuchSystemException(e);
    }
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Schedule a system reboot//from www  .j  a v a  2s  .co  m
 *
 * @param loggedInUser The current user
 * @param sid ID of the server.
 * @param earliestOccurrence Earliest occurrence of the reboot.
 * @return action id, exception thrown otherwise
 * @since 13.0
 *
 * @xmlrpc.doc Schedule a reboot for a system.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #param("dateTime.iso860", "earliestOccurrence")
 * @xmlrpc.returntype int actionId - The action id of the scheduled action
 */
public Long scheduleReboot(User loggedInUser, Integer sid, Date earliestOccurrence) {
    Server server = SystemManager.lookupByIdAndUser(new Long(sid.longValue()), loggedInUser);

    Action a = ActionManager.scheduleRebootAction(loggedInUser, server, earliestOccurrence);
    a = ActionFactory.save(a);
    return a.getId();
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Schedule a hardware refresh for a system.
 *
 * @param loggedInUser The current user/* w ww.ja  v  a 2 s .  c o  m*/
 * @param sid ID of the server.
 * @param earliestOccurrence Earliest occurrence of the hardware refresh.
 * @return action id, exception thrown otherwise
 * @since 13.0
 *
 * @xmlrpc.doc Schedule a hardware refresh for a system.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #param("dateTime.iso8601",  "earliestOccurrence")
 * @xmlrpc.returntype int actionId - The action id of the scheduled action
 */
public Long scheduleHardwareRefresh(User loggedInUser, Integer sid, Date earliestOccurrence) {
    Server server = SystemManager.lookupByIdAndUser(new Long(sid.longValue()), loggedInUser);

    Action a = ActionManager.scheduleHardwareRefreshAction(loggedInUser, server, earliestOccurrence);
    Action action = ActionFactory.save(a);

    return action.getId();
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Schedule a package list refresh for a system.
 *
 * @param loggedInUser The current user//www.j a  v  a 2s.c  o m
 * @param sid ID of the server.
 * @param earliestOccurrence Earliest occurrence of the refresh.
 * @return the id of the action scheduled, exception thrown otherwise
 *
 * @xmlrpc.doc Schedule a package list refresh for a system.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #param("dateTime.iso8601",  "earliestOccurrence")
 * @xmlrpc.returntype int - ID of the action scheduled, otherwise exception thrown
 * on error
 */
public int schedulePackageRefresh(User loggedInUser, Integer sid, Date earliestOccurrence) {
    Server server = SystemManager.lookupByIdAndUser(new Long(sid.longValue()), loggedInUser);

    Action a = ActionManager.schedulePackageRefresh(loggedInUser, server, earliestOccurrence);
    ActionFactory.save(a);

    return a.getId().intValue();
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Creates a new stored Package Profile/* ww  w.ja v  a2 s.  c  o  m*/
 *
 * @param loggedInUser The current user
 * @param sid ID of server to lookup details for.
 * @param profileLabel the label of the profile to be created
 * @param desc the description of the profile to be created
 * @return 1 on success
 *
 * @xmlrpc.doc Create a new stored Package Profile from a systems
 *      installed package list.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #param("string", "profileLabel")
 * @xmlrpc.param #param("string", "description")
 * @xmlrpc.returntype #return_int_success()
 */
public int createPackageProfile(User loggedInUser, Integer sid, String profileLabel, String desc) {

    Server server = SystemManager.lookupByIdAndUser(new Long(sid.longValue()), loggedInUser);

    try {
        Profile profile = ProfileManager.createProfile(loggedInUser, server, profileLabel, desc);
        ProfileManager.copyFrom(server, profile);
    } catch (DuplicateProfileNameException dbe) {
        throw new DuplicateProfileNameException(
                "Package Profile already exists " + "with name: " + profileLabel);
    } catch (NoBaseChannelFoundException nbcfe) {
        throw new ProfileNoBaseChannelException();
    }

    ProfileFactory.findByNameAndOrgId(profileLabel, loggedInUser.getOrg().getId());

    return 1;
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Get system details./*  ww  w . jav a 2s. c  o  m*/
 *
 * @param loggedInUser The current user
 * @param serverId ID of server to lookup details for.
 * @return Server object. (converted to XMLRPC struct by serializer)
 *
 * @xmlrpc.doc Get system details.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.returntype
 *          $ServerSerializer
 */
public Object getDetails(User loggedInUser, Integer serverId) {
    Server server = null;
    try {
        server = SystemManager.lookupByIdAndUser(new Long(serverId.longValue()), loggedInUser);
    } catch (LookupException e) {
        throw new NoSuchSystemException();
    }
    return server; // serializer will take care of the rest
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Schedule package installation for a system.
 *
 * @param loggedInUser The current user//  ww w. j  a  v  a2s  . c  o m
 * @param sids IDs of the servers
 * @param packageIds List of package IDs to install (as Integers)
 * @param earliestOccurrence Earliest occurrence of the package install
 * @return package action id
 *
 * @xmlrpc.doc Schedule package installation for a system.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #array_single("int", "serverId")
 * @xmlrpc.param #array_single("int", "packageId")
 * @xmlrpc.param dateTime.iso8601 earliestOccurrence
 * @xmlrpc.returntype #array_single("int", "actionId")
 */
public Long[] schedulePackageInstall(User loggedInUser, List<Integer> sids, List<Integer> packageIds,
        Date earliestOccurrence) {
    List<Long> actionIds = new ArrayList<Long>();
    for (Integer sid : sids) {
        Server server = SystemManager.lookupByIdAndUser(new Long(sid.longValue()), loggedInUser);

        // Would be nice to do this check at the Manager layer but upset many tests,
        // some of which were not cooperative when being fixed. Placing here for now.
        if (!SystemManager.hasEntitlement(server.getId(), EntitlementManager.MANAGEMENT)) {
            throw new MissingEntitlementException(EntitlementManager.MANAGEMENT.getHumanReadableLabel());
        }

        // Build a list of maps in the format the ActionManager wants:
        List<Map<String, Long>> packageMaps = new LinkedList<Map<String, Long>>();
        for (Iterator<Integer> it = packageIds.iterator(); it.hasNext();) {
            Integer pkgId = it.next();
            Map<String, Long> pkgMap = new HashMap<String, Long>();

            Package p = PackageManager.lookupByIdAndUser(new Long(pkgId.longValue()), loggedInUser);
            if (p == null) {
                throw new InvalidPackageException(pkgId.toString());
            }

            pkgMap.put("name_id", p.getPackageName().getId());
            pkgMap.put("evr_id", p.getPackageEvr().getId());
            pkgMap.put("arch_id", p.getPackageArch().getId());
            packageMaps.add(pkgMap);
        }

        if (packageMaps.isEmpty()) {
            throw new InvalidParameterException("No packages to install.");
        }

        Action action = null;
        try {
            action = ActionManager.schedulePackageInstall(loggedInUser, server, packageMaps,
                    earliestOccurrence);
        } catch (MissingEntitlementException e) {
            throw new com.redhat.rhn.frontend.xmlrpc.MissingEntitlementException();
        }

        actionIds.add(action.getId());
    }
    return actionIds.toArray(new Long[actionIds.size()]);
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Delete a package profile//from www.  ja  v  a 2 s  .c  o m
 *
 * @param loggedInUser The current user
 * @param profileId The package profile ID to delete.
 * @return 1 on success
 *
 * @xmlrpc.doc Delete a package profile
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "profileId")
 * @xmlrpc.returntype #return_int_success()
 */
public int deletePackageProfile(User loggedInUser, Integer profileId) {

    // make sure the user can access this profile
    Profile profile = ProfileManager.lookupByIdAndOrg(profileId.longValue(), loggedInUser.getOrg());

    return ProfileManager.deleteProfile(profile);
}