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

/**
 * Gets a list of virtual guests for the given host
 * @param loggedInUser The current user/*  ww  w .j  a v  a 2  s .  co m*/
 * @param sid the host system id
 * @return list of VirtualSystemOverview objects
 *
 * @xmlrpc.doc Lists the virtual guests for a given virtual host
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param_desc("int", "sid", "the virtual host's id")
 * @xmlrpc.returntype
 *      #array()
 *          $VirtualSystemOverviewSerializer
 *     #array_end()
 */
public List<VirtualSystemOverview> listVirtualGuests(User loggedInUser, Integer sid) {
    DataResult<VirtualSystemOverview> result = SystemManager.virtualGuestsForHostList(loggedInUser,
            sid.longValue(), null);
    result.elaborate();
    return result;
}

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

/**
 * Returns a list of kickstart variables set for the specified server
 *
 * @param loggedInUser The current user//from ww  w  .j a v a  2  s  .  co  m
 * @param serverId        identifies the server
 * @return map of kickstart variables set for the specified server
 *
 * @xmlrpc.doc Lists kickstart variables set  in the system record
 *  for the specified server.
 *  Note: This call assumes that a system record exists in cobbler for the
 *  given system and will raise an XMLRPC fault if that is not the case.
 *  To create a system record over xmlrpc use system.createSystemRecord
 *
 *  To create a system record in the Web UI  please go to
 *  System -&gt; &lt;Specified System&gt; -&gt; Provisioning -&gt;
 *  Select a Kickstart profile -&gt; Create Cobbler System Record.
 *
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.returntype
 *      #struct("System kickstart variables")
 *          #prop_desc("boolean" "netboot" "netboot enabled")
 *          #prop_array_begin("kickstart variables")
 *              #struct("kickstart variable")
 *                  #prop("string", "key")
 *                  #prop("string or int", "value")
 *              #struct_end()
 *          #prop_array_end()
 *      #struct_end()
 */
public Map<String, Object> getVariables(User loggedInUser, Integer serverId) {

    Server server = null;
    try {
        server = SystemManager.lookupByIdAndUser(serverId.longValue(), loggedInUser);
    } catch (LookupException e) {
        throw new NoSuchSystemException();
    }

    if (!(server.hasEntitlement(EntitlementManager.PROVISIONING))) {
        throw new FaultException(-2, "provisionError", "System does not have provisioning entitlement");
    }

    SystemRecord rec = SystemRecord.lookupById(CobblerXMLRPCHelper.getConnection(loggedInUser),
            server.getCobblerId());
    if (rec == null) {
        throw new NoSuchCobblerSystemRecordException();
    }

    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("netboot", rec.isNetbootEnabled());
    vars.put("variables", rec.getKsMeta());

    return vars;
}

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

/**
 * Delete systems given a list of system ids asynchronously.
 * This call queues the systems for deletion
 * @param loggedInUser The current user//from  w w w.java  2 s  . c  o m
 * @param systemIds A list of systems ids to delete
 * @return Returns the number of systems deleted if successful, fault exception
 * containing ids of systems not deleted otherwise
 * @throws FaultException A FaultException is thrown if the server corresponding to
 * sid cannot be found.
 *
 * @xmlrpc.doc Delete systems given a list of system ids asynchronously.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #array_single("int", "serverId")
 * @xmlrpc.returntype #return_int_success()
 */
public int deleteSystems(User loggedInUser, List<Integer> systemIds) throws FaultException {

    List<Integer> skippedSids = new ArrayList<Integer>();
    List<Long> deletion = new LinkedList<Long>();
    // Loop through the sids and try to delete the server
    for (Integer sysId : systemIds) {
        try {
            if (SystemManager.isAvailableToUser(loggedInUser, sysId.longValue())) {
                deletion.add(sysId.longValue());
            } else {
                skippedSids.add(sysId);
            }
        } catch (Exception e) {
            System.out.println("Exception: " + e);
            e.printStackTrace();
            skippedSids.add(sysId);
        }
    }

    // Fire the request off asynchronously
    SsmDeleteServersEvent event = new SsmDeleteServersEvent(loggedInUser, deletion);
    MessageQueue.publish(event);

    // If we skipped any systems, create an error message and throw a FaultException
    if (skippedSids.size() > 0) {
        StringBuilder msg = new StringBuilder("The following systems were NOT deleted: ");
        for (Integer sid : skippedSids) {
            msg.append("\n" + sid);
        }
        throw new SystemsNotDeletedException(msg.toString());
    }

    return 1;
}

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

/**
 * Creates a cobbler system record//w w  w  . ja v  a2  s  .  c  o  m
 * @param loggedInUser The current user
 * @param serverId the host system id
 * @param ksLabel identifies the kickstart profile
 *
 * @return int - 1 on success, exception thrown otherwise.
 *
 * @xmlrpc.doc Creates a cobbler system record with the specified kickstart label
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #param("string", "ksLabel")
 * @xmlrpc.returntype #return_int_success()
 */
public int createSystemRecord(User loggedInUser, Integer serverId, String ksLabel) {
    Server server = null;
    try {
        server = SystemManager.lookupByIdAndUser(serverId.longValue(), loggedInUser);
    } catch (LookupException e) {
        throw new NoSuchSystemException();
    }

    if (!(server.hasEntitlement(EntitlementManager.PROVISIONING))) {
        throw new FaultException(-2, "provisionError", "System does not have provisioning entitlement");
    }

    KickstartData ksData = lookupKsData(ksLabel, loggedInUser.getOrg());
    CobblerSystemCreateCommand cmd = new CobblerSystemCreateCommand(loggedInUser, server,
            ksData.getCobblerObject(loggedInUser).getName());
    cmd.store();

    return 1;
}

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

/**
 * Schedules an action to set the guests memory usage
 * @param loggedInUser The current user// www.  j av  a 2  s  .  c o m
 * @param sid the server ID of the guest
 * @param memory the amount of memory to set the guest to use
 * @return the action id of the scheduled action
 *
 * @xmlrpc.doc Schedule an action of a guest's host, to set that guest's memory
 *          allocation
 * @xmlrpc.param #session_key()
 * @xmlrpc.param #param_desc("int", "sid", "The guest's system id")
 * @xmlrpc.param #param_desc("int", "memory", "The amount of memory to
 *          allocate to the guest")
 *  @xmlrpc.returntype int actionID - the action Id for the schedule action
 *              on the host system.
 *
 */
public int setGuestMemory(User loggedInUser, Integer sid, Integer memory) {
    VirtualInstance vi = VirtualInstanceFactory.getInstance().lookupByGuestId(loggedInUser.getOrg(),
            sid.longValue());

    Map<String, String> context = new HashMap<String, String>();
    //convert from mega to kilo bytes
    context.put(VirtualizationSetMemoryAction.SET_MEMORY_STRING, new Integer(memory * 1024).toString());

    VirtualizationActionCommand cmd = new VirtualizationActionCommand(loggedInUser, new Date(),
            ActionFactory.TYPE_VIRTUALIZATION_SET_MEMORY, vi.getHostSystem(), vi.getUuid(), context);
    cmd.store();
    return cmd.getAction().getId().intValue();
}

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

/**
 * Schedules an actino to set the guests CPU allocation
 * @param loggedInUser The current user/*from   ww  w .  ja  v a  2  s.c om*/
 * @param sid the server ID of the guest
 * @param numOfCpus the num of cpus to set
 * @return the action id of the scheduled action
 *
 * @xmlrpc.doc Schedule an action of a guest's host, to set that guest's CPU
 *          allocation
 * @xmlrpc.param #session_key()
 * @xmlrpc.param #param_desc("int", "sid", "The guest's system id")
 * @xmlrpc.param #param_desc("int", "numOfCpus", "The number of virtual cpus to
 *          allocate to the guest")
 *  @xmlrpc.returntype int actionID - the action Id for the schedule action
 *              on the host system.
 *
 */
public int setGuestCpus(User loggedInUser, Integer sid, Integer numOfCpus) {
    VirtualInstance vi = VirtualInstanceFactory.getInstance().lookupByGuestId(loggedInUser.getOrg(),
            sid.longValue());

    Map<String, String> context = new HashMap<String, String>();
    context.put(VirtualizationSetVcpusAction.SET_CPU_STRING, numOfCpus.toString());

    VirtualizationActionCommand cmd = new VirtualizationActionCommand(loggedInUser, new Date(),
            ActionFactory.TYPE_VIRTUALIZATION_SET_VCPUS, vi.getHostSystem(), vi.getUuid(), context);
    cmd.store();
    return cmd.getAction().getId().intValue();
}

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

/**
 * Set server lock status./*w w w. j a va  2  s . c om*/
 *
 * @param loggedInUser The current user
 * @param serverId ID of server to lookup details for.
 * @param lockStatus to set. True to lock the system, False to unlock the system.
 * @return 1 on success, exception thrown otherwise.
 *
 * @xmlrpc.doc Set server lock status.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #param_desc("boolean", "lockStatus", "true to lock the system,
 * false to unlock the system.")
 *
 *  @xmlrpc.returntype #return_int_success()
 */
public Integer setLockStatus(User loggedInUser, Integer serverId, boolean lockStatus) {

    Server server = null;
    try {
        server = SystemManager.lookupByIdAndUser(new Long(serverId.longValue()), loggedInUser);
    } catch (LookupException e) {
        throw new NoSuchSystemException();
    }

    LocalizationService ls = LocalizationService.getInstance();

    if (lockStatus) {
        // lock the server, if it isn't already locked.
        if (server.getLock() == null) {
            SystemManager.lockServer(loggedInUser, server, ls.getMessage("sdc.details.overview.lock.reason"));
        }
    } else {
        // unlock the server, if it isn't already locked.
        if (server.getLock() != null) {
            SystemManager.unlockServer(loggedInUser, server);
        }
    }

    return 1;
}

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

/**
 * Deletes all notes from the server./*ww w .j  av a2 s .co  m*/
 *
 * @param loggedInUser The current user
 * @param sid        identifies the server on which the note resides
 * @return 1 if successful, exception otherwise
 * @throws NoSuchSystemException A NoSuchSystemException is thrown if the server
 * corresponding to sid cannot be found.
 *
 * @xmlrpc.doc Deletes all notes from the server.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.returntype #return_int_success()
 */
public int deleteNotes(User loggedInUser, Integer sid) {
    if (sid == null) {
        throw new IllegalArgumentException("sid cannot be null");
    }

    SystemManager.deleteNotes(loggedInUser, sid.longValue());

    return 1;
}

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

/**
 * Schedule package removal for a system.
 *
 * @param loggedInUser The current user//w w w.  j a v  a2s.  c  o m
 * @param sid ID of the server
 * @param packageIds List of package IDs to remove (as Integers)
 * @param earliestOccurrence Earliest occurrence of the package install
 * @return 1 if successful, exception thrown otherwise
 *
 * @xmlrpc.doc Schedule package removal for a system.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.param #array_single("int", "packageId")
 * @xmlrpc.param dateTime.iso8601 earliestOccurrence
 * @xmlrpc.returntype int - ID of the action scheduled, otherwise exception thrown
 * on error
 */
public int schedulePackageRemove(User loggedInUser, Integer sid, List<Integer> packageIds,
        Date earliestOccurrence) {

    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 remove.");
    }

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

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

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

/**
 *  schedules the specified action on the guest
 * @param loggedInUser The current user//from  www . j a  v a2s.c o  m
 * @param sid the id of the system
 * @param state one of the following: 'start', 'suspend', 'resume', 'restart',
 *          'shutdown'
 * @param date the date to schedule it
 * @return action ID
 *
 * @xmlrpc.doc Schedules a guest action for the specified virtual guest for a given
 *          date/time.
 * @xmlrpc.param #session_key()
 * @xmlrpc.param #param_desc("int", "sid", "the system Id of the guest")
 * @xmlrpc.param #param_desc("string", "state", "One of the following actions  'start',
 *          'suspend', 'resume', 'restart', 'shutdown'.")
 * @xmlrpc.param  #param_desc($date, "date", "the time/date to schedule the action")
 * @xmlrpc.returntype int actionId - The action id of the scheduled action
 */
public int scheduleGuestAction(User loggedInUser, Integer sid, String state, Date date) {
    VirtualInstance vi = VirtualInstanceFactory.getInstance().lookupByGuestId(loggedInUser.getOrg(),
            sid.longValue());

    ActionType action;
    if (state.equals("start")) {
        action = ActionFactory.TYPE_VIRTUALIZATION_START;
    } else if (state.equals("suspend")) {
        action = ActionFactory.TYPE_VIRTUALIZATION_SUSPEND;
    } else if (state.equals("resume")) {
        action = ActionFactory.TYPE_VIRTUALIZATION_RESUME;
    } else if (state.equals("restart")) {
        action = ActionFactory.TYPE_VIRTUALIZATION_REBOOT;
    } else if (state.equals("shutdown")) {
        action = ActionFactory.TYPE_VIRTUALIZATION_SHUTDOWN;
    } else {
        throw new InvalidActionTypeException();
    }

    VirtualizationActionCommand cmd = new VirtualizationActionCommand(loggedInUser,
            date == null ? new Date() : date, action, vi.getHostSystem(), vi.getUuid(),
            new HashMap<String, String>());
    cmd.store();
    return cmd.getAction().getId().intValue();
}