Package org.rhq.enterprise.server.discovery

Examples of org.rhq.enterprise.server.discovery.DiscoveryBossLocal


    @Test(groups = "integration.ejb3")
    public void discoveryQueueTest() throws Exception {
        getTransactionManager().begin();
        try {
            DiscoveryBossLocal discoveryBoss = LookupUtil.getDiscoveryBoss();
            SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
            Subject rhqadmin = subjectManager.loginUnauthenticated("rhqadmin");
            rhqadmin = createSession(rhqadmin);

            Map<Resource, List<Resource>> queue = discoveryBoss.getQueuedPlatformsAndServers(rhqadmin,
                PageControl.getUnlimitedInstance());
            for (Resource root : queue.keySet()) {
                System.out.println("Queue root resource: " + root);
            }
        } finally {
View Full Code Here


*/
public class ProcessQueueAction extends BaseAction {
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        DiscoveryBossLocal discovery = LookupUtil.getDiscoveryBoss();
        Subject user = SessionUtils.getWebUser(request.getSession()).getSubject();

        AIQueueForm queueForm = (AIQueueForm) form;
        Integer[] platformIds = queueForm.getPlatformsToProcess();
        Integer[] serverIds = queueForm.getServersToProcess();
        int queueAction = queueForm.getQueueAction();
        boolean isApproval = (queueAction == AIQueueForm.Q_DECISION_APPROVE);
        boolean isIgnore = (queueAction == AIQueueForm.Q_DECISION_IGNORE);
        if (!isApproval && !isIgnore) {
            throw new IllegalStateException("Illegal queue action id: " + queueAction);
        }

        List<Resource> selectedPlatforms = new ArrayList<Resource>();
        List<Resource> selectedServers = new ArrayList<Resource>();

        // Grab a fresh view of all platforms and servers with a status of 'NEW'.
        // TODO: don't use unlimited, try to use getQueuedPlatforms to get only those we care about
        Map<Resource, List<Resource>> queuedResources = discovery.getQueuedPlatformsAndServers(user, PageControl
            .getUnlimitedInstance());

        // perform some preprocessing, to make sure selections are valid
        String errorKey = null;
        for (Resource platform : queuedResources.keySet()) {
            if (isIgnore) {
                // March 05, 2009 - to date, it is illegal to ignore servers if the platform hasn't yet been committed
                if (platform.getInventoryStatus() == InventoryStatus.NEW) {
                    errorKey = MessageConstants.ERR_PLATFORM_NOT_COMMITTED;
                    break; // don't process any more platforms
                }
            }
        }
        if (errorKey != null) {
            // premature return, since we know subsequent inventory operations will fail
            //RequestUtils.setError(request, errorKey);
            SessionUtils.setError(request.getSession(), errorKey);
            return returnSuccess(request, mapping);
        }

        for (Resource platform : queuedResources.keySet()) {
            if (!selectedForProcessing(platform, platformIds)) {
                continue;
            }

            // we want to process one platform at a time, so clear any previous platform data
            selectedPlatforms.clear();
            selectedServers.clear();

            // only add the platform if we are approving it
            // you can't ignore/remove a platform (just don't run the agent if you want that!)
            if (isApproval) {
                selectedPlatforms.add(platform);
            }

            // Now check servers on this platform
            for (Resource server : queuedResources.get(platform)) {
                if (isSelectedForProcessing(server, serverIds)) {
                    selectedServers.add(server);

                    // If we're approving stuff, and this platform's not already in the list, add it.
                    if (isApproval && !selectedPlatforms.contains(platform)) {
                        selectedPlatforms.add(platform);
                    }
                }
            }

            // update one platform at a time, so they each get their own transaction
            try {
                InventoryStatus status = isApproval ? InventoryStatus.COMMITTED : InventoryStatus.IGNORED;

                // update the inventory status for all selected resources and tell their agents to pull down their schedules
                discovery.updateInventoryStatus(user, selectedPlatforms, selectedServers, status);
            } catch (Exception e) {
                request.getSession().setAttribute(Constants.IMPORT_ERROR_ATTR, e);
                break; // don't process any more platforms
            }
        }
View Full Code Here

        HttpServletRequest request, HttpServletResponse response) throws Exception {

        Map<DisambiguationReport<Resource>, List<DisambiguationReport<Resource>>> queuedResources = new HashMap<DisambiguationReport<Resource>, List<DisambiguationReport<Resource>>>();

        try {
            DiscoveryBossLocal discoveryBoss = LookupUtil.getDiscoveryBoss();
            ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
           
            WebUser user = SessionUtils.getWebUser(request.getSession());
            if (user == null) {
                // session timed out, return prematurely
                return null;
            }

            WebUserPreferences preferences = user.getWebPreferences();
            Subject subject = user.getSubject();
            AIQueueForm queueForm = (AIQueueForm) form;
            PageControl pageControl;

            try {
                int size = preferences.getAutoDiscoveryRange();
                if (size < 1) {
                    pageControl = PageControl.getUnlimitedInstance();
                } else {
                    pageControl = new PageControl(0, size);
                }
            } catch (Exception e) {
                // should never happen but if somehow there is a bogus number, just fallback to the default
                pageControl = new PageControl(0, 10);
            }

            try {
                queuedResources = disambiguateQueuedResources(discoveryBoss.getQueuedPlatformsAndServers(subject, pageControl), resourceManager);

                // If the queue is empty, check to see if there are ANY agents defined in inventory.
                if (queuedResources.isEmpty()) {
                    int count = LookupUtil.getAgentManager().getAgentCount();
                    request.setAttribute("hasNoAgents", count == 0);
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.discovery.DiscoveryBossLocal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.