Package org.rhq.core.domain.operation

Examples of org.rhq.core.domain.operation.GroupOperationHistory


        }

        @Override
        public PageList<ResourceOperationHistory> fetchPage(PageControl pc) {
            Subject subject = EnterpriseFacesContextUtility.getSubject();
            GroupOperationHistory groupHistory = getHistory();

            PageList<ResourceOperationHistory> resourceHistories = null;
            resourceHistories = operationManager.findResourceOperationHistoriesByGroupHistoryId(subject, groupHistory
                .getId(), pc);

            return resourceHistories;
        }
View Full Code Here


        return GROUP_JOB_NAME_PREFIX + group.getId();
    }

    public void execute(JobExecutionContext context) throws JobExecutionException {
        GroupOperationSchedule schedule = null;
        GroupOperationHistory groupHistory;
        Subject user = null;

        try {
            JobDetail jobDetail = context.getJobDetail();
            OperationManagerLocal operationManager = LookupUtil.getOperationManager();

            updateOperationScheduleEntity(jobDetail, context.getNextFireTime(), operationManager);

            // we only got here because the user was allowed to execute / schedule the operation in the first place,
            // thus it's safe to pass in the overlord here
            schedule = operationManager.getGroupOperationSchedule(LookupUtil.getSubjectManager().getOverlord(),
                jobDetail);

            // create a new session even if user is logged in elsewhere, we don't want to attach to that user's session
            user = getUserWithSession(schedule.getSubject(), false);
            ResourceGroup group = schedule.getGroup();

            // we need the operation definition to fill in the history item
            OperationDefinition op;
            op = operationManager.getSupportedGroupOperation(user, group.getId(), schedule.getOperationName(), false);

            // first we need to create an INPROGRESS *group* history item
            Configuration parameters = schedule.getParameters();
            if (parameters != null) {
                parameters = parameters.deepCopy(false); // we need a copy to avoid constraint violations upon delete
            }

            groupHistory = new GroupOperationHistory(jobDetail.getName(), jobDetail.getGroup(), user.getName(), op,
                parameters, group);

            groupHistory = (GroupOperationHistory) operationManager.updateOperationHistory(user, groupHistory);

            // get the resources to operate on, ordered or not
            List<Resource> resourcesToOperateOn;
            if (schedule.getExecutionOrder() != null) {
                resourcesToOperateOn = schedule.getExecutionOrder();
            } else {
                ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
                PageControl pageControl = PageControl.getUnlimitedInstance();
                resourcesToOperateOn = resourceManager.findExplicitResourcesByResourceGroup(user, group, pageControl);
            }

            // now create detail composites from the resource list
            List<ResourceOperationDetailsComposite> resourceComposites = new ArrayList<ResourceOperationDetailsComposite>();
            getUserWithSession(user, true); // refresh our session to reset the timeout clock
            for (Resource nextResourceToOperateOn : resourcesToOperateOn) {
                // create the non-quartz schedule entity for the given job execution context data
                ResourceOperationSchedule resourceSchedule = createScheduleForResource(schedule, jobDetail.getGroup(),
                    user, nextResourceToOperateOn);

                // create the resource-level history entity for the newly created non-quartz schedule entity
                // this method also does the persisting
                ResourceOperationHistory resourceHistory = createOperationHistory(resourceSchedule.getJobName(),
                    resourceSchedule.getJobGroup(), resourceSchedule, groupHistory, operationManager);

                // add all three elements to the composite, which will be iterated over below for the bulk of the work
                resourceComposites.add(new ResourceOperationDetailsComposite(nextResourceToOperateOn, resourceHistory,
                    resourceSchedule));
            }

            // now tell the agents to invoke the operation for all resources
            if (schedule.getExecutionOrder() != null) {
                boolean hadFailure = false;

                // synchronously execute, waiting for each operation to finish before going to the next
                for (ResourceOperationDetailsComposite composite : resourceComposites) {
                    try {
                        if (hadFailure) {
                            // there was a failure during execution of this group operation;
                            // thus, mark all remaining operation histories as cancelled
                            composite.history.setErrorMessage("This has been cancelled due to halt-on-error "
                                + "being set on the parent group operation schedule. "
                                + "A previous resource operation that executed prior "
                                + "to this resource operation failed, thus causing "
                                + "this resource operation to be cancelled.");
                            composite.history.setStatus(OperationRequestStatus.CANCELED);
                            composite.history = (ResourceOperationHistory) operationManager.updateOperationHistory(
                                getUserWithSession(user, true), composite.history);
                            continue;
                        }

                        invokeOperationOnResource(composite, operationManager);

                        int resourceHistoryId = composite.history.getId();
                        OperationHistory updatedOperationHistory = null;
                        long sleep = 1000L; // quick sleep for fast ops, then slow down
                        long maxSleep = 5000L;
                        do {
                            Thread.sleep(sleep);
                            sleep = (sleep == maxSleep) ? sleep : sleep + 1000L;

                            // it's unlikely but possible that a client program could actually query for, process, and
                            // delete the history before this code gets a chance to run.  If the record is gone just
                            // assume things were handled externally.
                            try {
                                updatedOperationHistory = operationManager.getOperationHistoryByHistoryId(
                                    getUserWithSession(user, true), resourceHistoryId);
                            } catch (IllegalArgumentException e) {
                                if (log.isDebugEnabled()) {
                                    log.debug("Failed to find operation history", e);
                                }
                                break;
                            }

                            // if the duration was ridiculously long, let's break out of here. this will rarely
                            // be triggered because our operation manager will timeout long running operations for us
                            // (based on the operation's define timeout).  But, me being paranoid, I want to be able
                            // to break this infinite loop if for some reason the operation manager isn't doing its job.
                            // if the operation took longer than 24 hours, this breaks the loop.

                            if (updatedOperationHistory.getDuration() > (GroupOperationJob.BREAK_VALUE)) {
                                break;
                            }
                        } while (updatedOperationHistory.getStatus() == OperationRequestStatus.INPROGRESS);

                        // halt the rest if we got a failure and were told not to go on
                        if (null != updatedOperationHistory
                            && (updatedOperationHistory.getStatus() != OperationRequestStatus.SUCCESS)
                            && schedule.isHaltOnFailure()) {
                            hadFailure = true;
                        }
                    } catch (Exception e) {
                        // failed to even send to the agent, immediately mark the job as failed
                        groupHistory.setErrorMessage(ThrowableUtil.getStackAsString(e));
                        groupHistory = (GroupOperationHistory) operationManager.updateOperationHistory(
                            getUserWithSession(user, true), groupHistory);

                        if (schedule.isHaltOnFailure()) {
                            hadFailure = true;
                        }
                    }
                }
            } else {
                // send the invocation requests without waiting for each to return
                for (ResourceOperationDetailsComposite composite : resourceComposites) {
                    try {
                        invokeOperationOnResource(composite, operationManager);
                    } catch (Exception e) {
                        if (e instanceof CancelJobException) {
                            throw e;
                        }

                        // failed to even send to the agent, immediately mark the job as failed
                        groupHistory.setErrorMessage(ThrowableUtil.getStackAsString(e));
                        groupHistory = (GroupOperationHistory) operationManager.updateOperationHistory(
                            getUserWithSession(user, true), groupHistory);

                        // Note: in actuality - I don't think users have a way in the user interface to turn on halt-on-failure for parallel execution.
                        // So this isHaltOnFailure will probably always be false. But in case we want to support this, leave this here.
View Full Code Here

        if (history.getStatus() == OperationRequestStatus.INPROGRESS) {
            // if this history isn't done, then by definition the overall group isn't done either
            return;
        }

        GroupOperationHistory groupHistory = ((ResourceOperationHistory) history).getGroupOperationHistory();

        // if this was a resource invocation that was part of a group operation
        // see if the rest of the group members are done too, if so, close out the group history
        if (groupHistory != null) {
            List<ResourceOperationHistory> allResourceHistories = groupHistory.getResourceOperationHistories();
            boolean stillInProgress = false; // assume all are finished
            OperationRequestStatus groupStatus = OperationRequestStatus.SUCCESS; // will be FAILURE if at least one resource operation failed
            StringBuilder groupErrorMessage = null; // will be the group error message if at least one resource operation failed

            for (ResourceOperationHistory resourceHistory : allResourceHistories) {
                if (resourceHistory.getStatus() == OperationRequestStatus.INPROGRESS) {
                    stillInProgress = true;
                    break;
                } else if ((resourceHistory.getStatus() == OperationRequestStatus.FAILURE)
                    || (resourceHistory.getStatus() == OperationRequestStatus.CANCELED)) {
                    groupStatus = OperationRequestStatus.FAILURE;
                    if (groupErrorMessage == null) {
                        groupErrorMessage = new StringBuilder(
                            "The following resources failed to invoke the operation (see group operation history for details) :\n ");
                    } else {
                        groupErrorMessage.append("\n ");
                    }

                    Resource resource = resourceHistory.getResource();
                    String name = resource.getName();
                    Map<Integer, String> ancestryMap = resourceManager
                        .getResourcesAncestry(subjectManager.getOverlord(), new Integer[] { resource.getId() },
                            ResourceAncestryFormat.SIMPLE);
                    String ancestry = ancestryMap.isEmpty() ? "" : ancestryMap.get(resource.getId());
                    groupErrorMessage.append(name + " [" + ancestry + "] " + resourceHistory.getStatus().name());
                }
            }

            if (!stillInProgress) {
                groupHistory.setErrorMessage((groupErrorMessage == null) ? null : groupErrorMessage.toString());
                groupHistory.setStatus(groupStatus);
                notifyAlertConditionCacheManager("checkForCompletedGroupOperation", groupHistory);
            }
        }
    }
View Full Code Here

        List<GroupOperationHistory> list = query.getResultList();

        // don't bother checking permission if there is nothing to see (we wouldn't have the group even if we wanted to)
        // if there is at least one history - get its group and make sure the user has permissions to see
        if ((list != null) && (list.size() > 0)) {
            GroupOperationHistory groupHistory = list.get(0);
            ensureViewPermission(subject, groupHistory);
        }

        PageList<GroupOperationHistory> pageList;
        pageList = new PageList<GroupOperationHistory>(list, (int) totalCount, pc);
View Full Code Here

        List<GroupOperationHistory> list = query.getResultList();

        // don't bother checking permission if there is nothing to see (we wouldn't have the group even if we wanted to)
        // if there is at least one history - get its group and make sure the user has permissions to see
        if ((list != null) && (list.size() > 0)) {
            GroupOperationHistory groupHistory = list.get(0);
            ensureViewPermission(subject, groupHistory);
        }

        PageList<GroupOperationHistory> pageList;
        pageList = new PageList<GroupOperationHistory>(list, (int) totalCount, pc);
View Full Code Here

            history.setParameters(parameters);
        }

        // to avoid TransientObjectExceptions during the merge, we need to attach all resource operation histories, if there are any
        if (history instanceof GroupOperationHistory) {
            GroupOperationHistory groupHistory = (GroupOperationHistory) history;
            List<ResourceOperationHistory> roh = groupHistory.getResourceOperationHistories();
            if (roh != null && roh.size() > 0) {
                List<ResourceOperationHistory> attached = new ArrayList<ResourceOperationHistory>(roh.size());
                for (ResourceOperationHistory unattachedHistory : roh) {
                    attached.add(entityManager.getReference(ResourceOperationHistory.class, unattachedHistory.getId()));
                }
                groupHistory.setResourceOperationHistories(attached);
            }
        }

        history = entityManager.merge(history); // merge will persist if it doesn't exist yet
View Full Code Here

        return criteria;
    }

    @Override
    protected GroupOperationHistory createOperationHistory() {
        return new GroupOperationHistory(null, null, null, null, null, null);
    }
View Full Code Here

                    CoreGUI.getErrorHandler()
                        .handleError(MSG.view_operationHistoryDetails_error_fetchFailure(), caught);
                }

                public void onSuccess(PageList<GroupOperationHistory> result) {
                    GroupOperationHistory groupOperationHistory = result.get(0);
                    displayDetails(groupOperationHistory);
                }
            });
    }
View Full Code Here

                "Resource");
            resourceItem.setValue(this.disambiguatedResourceName);
            items.add(1, resourceItem);
        }

        GroupOperationHistory groupOperationHistory = operationHistory.getGroupOperationHistory();
        if (groupOperationHistory != null) {
            StaticTextItem groupOperationHistoryItem = new StaticTextItem(
                ResourceOperationHistoryDataSource.Field.GROUP_OPERATION_HISTORY, "Parent Group Execution");
            String groupOperationHistoryUrl = LinkManager.getGroupOperationHistoryLink(
                groupOperationHistory.getGroup(), groupOperationHistory.getId());
            String value = "<a href=\"" + groupOperationHistoryUrl + "\">" + groupOperationHistory.getId()
                + "</a> (on group '" + groupOperationHistory.getGroup().getName() + "')";
            groupOperationHistoryItem.setValue(value);
            items.add(groupOperationHistoryItem);
        }

        return items;
View Full Code Here

        PageList<GroupOperationHistory> results;
        results = operationManager.findCompletedGroupOperationHistories(overlord(), newGroup.getId(),
            PageControl.getUnlimitedInstance());
        assert results.size() == 1 : "Expected 1 result, but got " + results.size();
        final GroupOperationHistory groupOpHistory = results.get(0);

        // We'll throw in a time based purge test here. We can't purge before current time because we could wipe out
        // stuff generated by other tests.  To try and limit what we wipe out, set the ctime of the group history to
        // be very old...
        executeInTransaction(false, new TransactionCallback() {
            @Override
            public void execute() throws Exception {
                Query q = em.createQuery("update GroupOperationHistory h set h.createdTime = 900 where h.id = "
                    + groupOpHistory.getId());
                int numUpdated = q.executeUpdate();
                assertEquals(1, numUpdated);
            }
        });
        assertEquals(1, operationManager.purgeOperationHistory(new Date(1000)));
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.operation.GroupOperationHistory

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.