Package org.rhq.core.domain.bundle

Examples of org.rhq.core.domain.bundle.BundleDeployment


        PageList<BundleDeployment> deployments = bundleManager.findBundleDeploymentsByCriteria(overlord,
            getCriteriaFromContext(context));

        if (deployments.size() > 0) {
            BundleDeployment bundleDeployment = deployments.get(0);
            SchedulerLocal scheduler = LookupUtil.getSchedulerBean();
            JobDetail jobDetail = context.getJobDetail();

            BundleDeploymentStatus bundleDeploymentStatus = bundleManager.determineBundleDeploymentStatus(bundleDeployment.getId());
            if (bundleDeploymentStatus.isTerminal()) {
                // delete this job, we've assigned a final status
                try {
                    context.setResult(bundleDeploymentStatus); // Return status to possible listeners
                    scheduler.deleteJob(jobDetail.getName(), jobDetail.getGroup());
View Full Code Here


            if (!errors.isEmpty()) {
                throw new IllegalArgumentException("Invalid Configuration: " + errors.toString());
            }
        }

        BundleDeployment deployment = new BundleDeployment(bundleVersion, bundleDestination, name);
        deployment.setDescription(description);
        deployment.setConfiguration(configuration);
        deployment.setSubjectName(subject.getName());

        PropertySimple discoveryDelayProperty = configuration.getSimple("org.rhq.discoveryDelay");
        if(discoveryDelayProperty != null) {
            deployment.setDiscoveryDelay(discoveryDelayProperty.getIntegerValue());
        }

        entityManager.persist(deployment);

        return deployment;
View Full Code Here

        if (null == bundleDestination) {
            throw new IllegalArgumentException("Invalid bundleDestinationId: " + bundleDestinationId);
        }

        BundleVersion bundleVersion = null;
        BundleDeployment prevDeployment = null;

        if (bundleVersionId > 0) {
            bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId);
            if (null == bundleVersion) {
                throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId);
View Full Code Here

        criteria.addFilterDestinationId(bundleDestination.getId());
        criteria.addFilterIsLive(true);
        criteria.fetchBundleVersion(true);

        List<BundleDeployment> liveDeployments = bundleManager.findBundleDeploymentsByCriteria(subject, criteria);
        BundleDeployment liveDeployment = (liveDeployments.isEmpty()) ? null : liveDeployments.get(0);

        String deploymentName;
        // always bump up the deploy number, whether its a revert or upgrade
        int deploy;
        boolean isInitialDeployment = (null == liveDeployment);
        if (isInitialDeployment) {
            deploy = 1;
        } else {
            try {
                String liveName = liveDeployment.getName();
                int iStart = liveName.indexOf("[") + 1, iEnd = liveName.indexOf("]");
                deploy = Integer.valueOf(liveName.substring(iStart, iEnd)) + 1;
            } catch (Exception e) {
                // if any odd error happens here, don't abort since this is only needed for the human readable name
                LOG.warn("Cannot determine next deployment number. Using -1. liveDeployment=" + liveDeployment);
                deploy = -1;
            }
        }

        if (null != bundleVersion) {
            String version = bundleVersion.getVersion();
            String dest = bundleDestination.getName();

            if (isInitialDeployment) {
                deploymentName = "Deployment [" + deploy + "] of Version [" + version + "] to [" + dest + "]";
            } else {
                String liveVersion = liveDeployment.getBundleVersion().getVersion();
                if (liveVersion.equals(version)) {
                    // redeploy
                    deploymentName = "Deployment [" + deploy + "] of Version [" + version + "] to [" + dest + "]";
                } else {
                    // upgrade
View Full Code Here

        List<BundleDeployment> liveDeployments = bundleManager.findBundleDeploymentsByCriteria(subject, bdc);
        if (1 != liveDeployments.size()) {
            throw new IllegalArgumentException("No live deployment to purge is found for destinationId ["
                + bundleDestinationId + "]");
        }
        BundleDeployment liveDeployment = liveDeployments.get(0);
        List<BundleResourceDeployment> resourceDeploys = liveDeployment.getResourceDeployments();
        if (resourceDeploys == null || resourceDeploys.isEmpty()) {
            return; // nothing to do
        }

        // Although they likely will, the actual resource deployments may no longer match the members of the destination's
        // resource group (if group membership has changed). We still use the group for authz because that is the more
        // intuitive, manageable way to do this.  Otherwise the subject would need view perms on each of the previously
        // deployed-to resources, and that may be tricky to provide.
        checkDeployBundleAuthz(subject, liveDeployment.getBundleVersion().getBundle().getId(), liveDeployment
            .getDestination().getGroup().getId());

        // we need to obtain the bundle type (the remote plugin container needs it). our first criteria can't fetch this deep, we have to do another query.
        BundleVersionCriteria bvc = new BundleVersionCriteria();
        bvc.addFilterId(liveDeployment.getBundleVersion().getId());
        bvc.fetchBundle(true); // will eagerly fetch the bundle type
        PageList<BundleVersion> bvs = bundleManager.findBundleVersionsByCriteria(subject, bvc);
        liveDeployment.setBundleVersion(bvs.get(0)); // wire up the full bundle version back into the live deployment
        // the bundle type doesn't eagerly load the resource type - the remote plugin container needs that too
        ResourceTypeCriteria rtc = new ResourceTypeCriteria();
        rtc.addFilterIgnored(null); // we are purging, so we don't care if this returns ignored types or not, just purge anyway
        rtc.addFilterBundleTypeId(liveDeployment.getBundleVersion().getBundle().getBundleType().getId());
        PageList<ResourceType> rts = resourceTypeManager.findResourceTypesByCriteria(subject, rtc);
        liveDeployment.getBundleVersion().getBundle().getBundleType().setResourceType(rts.get(0));

        // we need to obtain the resources for all resource deployments - our first criteria can't fetch this deep, we have to do another query.
        List<Integer> resourceDeployIds = new ArrayList<Integer>();
        for (BundleResourceDeployment resourceDeploy : resourceDeploys) {
            resourceDeployIds.add(resourceDeploy.getId());
        }
        final BundleResourceDeploymentCriteria brdc = new BundleResourceDeploymentCriteria();
        brdc.addFilterIds(resourceDeployIds.toArray(new Integer[resourceDeployIds.size()]));
        brdc.fetchResource(true);

        //Use CriteriaQuery to automatically chunk/page through criteria query results
        CriteriaQueryExecutor<BundleResourceDeployment, BundleResourceDeploymentCriteria> queryExecutor = new CriteriaQueryExecutor<BundleResourceDeployment, BundleResourceDeploymentCriteria>() {
            @Override
            public PageList<BundleResourceDeployment> execute(BundleResourceDeploymentCriteria criteria) {
                return bundleManager.findBundleResourceDeploymentsByCriteria(subject, brdc);
            }
        };

        CriteriaQuery<BundleResourceDeployment, BundleResourceDeploymentCriteria> brdResults = new CriteriaQuery<BundleResourceDeployment, BundleResourceDeploymentCriteria>(
            brdc, queryExecutor);

        //        PageList<BundleResourceDeployment> brdResults = bundleManager.findBundleResourceDeploymentsByCriteria(subject,
        //            brdc);
        resourceDeploys.clear();
        //        resourceDeploys.addAll(brdResults);
        // need to wire the live bundle deployment back in - no need for another query or fetch it above because we have it already
        for (BundleResourceDeployment brd : brdResults) {
            resourceDeploys.add(brd);
            brd.setBundleDeployment(liveDeployment);
        }

        // loop through each deployment and purge it on agent
        Map<BundleResourceDeployment, String> failedToPurge = new HashMap<BundleResourceDeployment, String>();
        for (BundleResourceDeployment resourceDeploy : resourceDeploys) {
            try {
                // first put the user name that requested the purge in the audit trail
                BundleResourceDeploymentHistory history = new BundleResourceDeploymentHistory(subject.getName(),
                    "Purge Requested", "User [" + subject.getName() + "] requested to purge this deployment", null,
                    BundleResourceDeploymentHistory.Status.SUCCESS, null, null);
                bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subjectManager.getOverlord(),
                    resourceDeploy.getId(), history);

                // get a connection to the agent and tell it to purge the bundle from the file system
                Subject overlord = subjectManager.getOverlord();
                AgentClient agentClient = agentManager.getAgentClient(overlord, resourceDeploy.getResource().getId());
                BundleAgentService bundleAgentService = agentClient.getBundleAgentService();
                BundlePurgeRequest request = new BundlePurgeRequest(resourceDeploy);
                BundlePurgeResponse results = bundleAgentService.purge(request);
                if (!results.isSuccess()) {
                    String errorMessage = results.getErrorMessage();
                    failedToPurge.put(resourceDeploy, errorMessage);
                }
            } catch (Exception e) {
                String errorMessage = ThrowableUtil.getStackAsString(e);
                failedToPurge.put(resourceDeploy, errorMessage);
            }
        }

        // marks the live deployment "no longer live"
        bundleManager._finalizePurge(subjectManager.getOverlord(), liveDeployment, failedToPurge);

        // throw an exception if we failed to purge one or more resource deployments.
        // since we are not in a tx context, we lose nothing. All DB updates have already been committed by now
        // which is what we want. All this does is inform the caller something went wrong.
        if (!failedToPurge.isEmpty()) {
            int totalDeployments = liveDeployment.getResourceDeployments().size();
            int failedPurges = failedToPurge.size();
            throw new Exception("Failed to purge [" + failedPurges + "] of [" + totalDeployments
                + "] remote resource deployments");
        }
    }
View Full Code Here

        List<BundleDeployment> liveDeployments = bundleManager.findBundleDeploymentsByCriteria(subject, c);
        if (1 != liveDeployments.size()) {
            throw new IllegalArgumentException("No live deployment found for destinationId [" + bundleDestinationId
                + "]");
        }
        BundleDeployment liveDeployment = liveDeployments.get(0);
        Integer prevDeploymentId = liveDeployment.getReplacedBundleDeploymentId();
        if (null == prevDeploymentId) {
            throw new IllegalArgumentException(
                "Live deployment ["
                    + liveDeployment
                    + "] can not be reverted. The Live deployment is either an initial deployment or a reverted deployment for destinationId ["
                    + bundleDestinationId + "]");
        }
        BundleDeployment prevDeployment = entityManager.find(BundleDeployment.class, prevDeploymentId);
        if (null == prevDeployment) {
            throw new IllegalArgumentException("Live deployment [" + liveDeployment
                + "] can not be reverted. There is no prior deployment for destinationId [" + bundleDestinationId + "]");
        }

        checkDeployBundleAuthz(subject, liveDeployment.getBundleVersion().getBundle().getId(), liveDeployment
            .getDestination().getGroup().getId());

        // A revert is done by deploying a new deployment that mirrors "prevDeployment". It uses the same
        // bundleVersion, destination and config as prevDeployment.  It can have a new name and new desc, and
        // may opt to clean the deploy dir.  It must be a new deployment so that all status/auditing/history starts
        // fresh and can be tracked. The key difference in the schedule request is that we set isRevert=true,
        // tell the bundle handler that we are in fact reverting from the current live deployment. The
        // deployment creation is done in a new transaction so it can then be scheduled.
        String name = getBundleDeploymentNameImpl(subject, liveDeployment.getDestination(), null, prevDeployment);
        String desc = (null != deploymentDescription) ? deploymentDescription : prevDeployment.getDescription();
        Configuration config = (null == prevDeployment.getConfiguration()) ? null : prevDeployment.getConfiguration()
            .deepCopy(false);
        BundleDeployment revertDeployment = bundleManager.createBundleDeploymentInNewTrans(subject, prevDeployment
            .getBundleVersion().getId(), bundleDestinationId, name, desc, config);

        return scheduleBundleDeploymentImpl(subject, revertDeployment.getId(), isCleanDeployment, true,
            prevDeployment.getReplacedBundleDeploymentId());
    }
View Full Code Here

    // revertedDeploymentReplacedDeployment is only meaningful if isRevert is true
    private BundleDeployment scheduleBundleDeploymentImpl(Subject subject, int bundleDeploymentId,
        boolean isCleanDeployment, boolean isRevert, Integer revertedDeploymentReplacedDeployment) throws Exception {

        // This work must be committed before we schedule the status check job, so do it in a new trans
        BundleDeployment newDeployment = bundleManager.scheduleBundleDeploymentInNewTransaction(subject,
            bundleDeploymentId, isCleanDeployment, isRevert, revertedDeploymentReplacedDeployment);

        // schedule the bundle deployment completion check. Due to timing issues, we cannot determine
        // the overall completion status of the bundle deployment while receiving the individual resource
        // deployment statuses. This needs to be done out of band by a quartz job.
View Full Code Here

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public BundleDeployment scheduleBundleDeploymentInNewTransaction(Subject subject, int bundleDeploymentId,
        boolean isCleanDeployment, boolean isRevert, Integer revertedDeploymentReplacedDeployment) throws Exception {

        BundleDeployment newDeployment = entityManager.find(BundleDeployment.class, bundleDeploymentId);
        if (null == newDeployment) {
            throw new IllegalArgumentException("Invalid bundleDeploymentId: " + bundleDeploymentId);
        }

        BundleDestination destination = newDeployment.getDestination();
        ResourceGroup group = destination.getGroup();

        // Create and persist updates for each of the group members.
        Set<Resource> groupMembers = group.getExplicitResources();
        if (groupMembers.isEmpty()) {
            throw new IllegalArgumentException("Destination [" + destination
                + "] group has no members. Invalid deployment destination");
        }

        checkDeployBundleAuthz(subject, newDeployment.getBundleVersion().getBundle().getId(), group.getId());

        for (Resource groupMember : groupMembers) {
            try {
                scheduleBundleResourceDeployment(subject, newDeployment, groupMember, isCleanDeployment, isRevert);
            } catch (Throwable t) {
                LOG.error("Failed to complete scheduling of bundle deployment to [" + groupMember
                    + "]. Other bundle deployments to other resources may have been scheduled. ", t);
            }
        }

        // make sure the new deployment is set as the live deployment and properly replaces the
        // previously live deployment.
        destination = entityManager.find(BundleDestination.class, destination.getId());
        List<BundleDeployment> currentDeployments = destination.getDeployments();
        if (null != currentDeployments) {
            for (BundleDeployment d : currentDeployments) {
                if (d.isLive()) {
                    d.setLive(false);
                    if (!isRevert) {
                        newDeployment.setReplacedBundleDeploymentId(d.getId());
                    } else {
                        // we are doing a revert; so our "replacedDeployment" should be what the deployment we
                        // are reverting to replaced. For example, assume I deployed three bundles:
                        //   Deployment #1 - replaced nothing (hence replacedBundleDeploymentId == null)
                        //   Deployment #2 - replaced #1
                        //   Deployment #3 - replaced #2
                        // Now do a revert. Reverting the live deployment #3 means we really want to re-deploy #2.
                        // This new deployment gets a new ID of #4, but it is actually a deployment equivalent to #2.
                        // If our deploy #4 is actually a redeploy of #2, we need to prepare for the user wanting
                        // to revert #4 by setting the replacedBundleDeploymentId to that which #2 had - this being #1.
                        //   Deployment #4 - replaced #1
                        // Now if we ask to revert #4, we will actually be re-deploying #1, which is what we want.
                        // This allows us to revert back multiple steps.
                        newDeployment.setReplacedBundleDeploymentId(revertedDeploymentReplacedDeployment);
                    }
                    break;
                }
            }
        }
        newDeployment.setLive(true);

        return newDeployment;
    }
View Full Code Here

        BundleDeploymentCriteria bdc = new BundleDeploymentCriteria();
        bdc.addFilterId(resourceDeployment.getBundleDeployment().getId());
        bdc.fetchBundleVersion(true);
        bdc.fetchConfiguration(true);
        bdc.fetchDestination(true);
        BundleDeployment deployment = bundleManager.findBundleDeploymentsByCriteria(subject, bdc).get(0);

        BundleCriteria bc = new BundleCriteria();
        bc.addFilterDestinationId(deployment.getDestination().getId());
        Bundle bundle = bundleManager.findBundlesByCriteria(subject, bc).get(0);

        ResourceTypeCriteria rtc = new ResourceTypeCriteria();
        rtc.addFilterIgnored(false); // we only care about those that are not ignored
        rtc.addFilterBundleTypeId(bundle.getBundleType().getId());
        ResourceType resourceType = resourceTypeManager.findResourceTypesByCriteria(subject, rtc).get(0);
        bundle.getBundleType().setResourceType(resourceType);

        deployment.getBundleVersion().setBundle(bundle);
        deployment.getDestination().setBundle(bundle);

        resourceDeployment.setBundleDeployment(deployment);

        // now scrub the hibernate entity to make it a pojo suitable for sending to the client
        HibernateDetachUtility.nullOutUninitializedFields(resourceDeployment, SerializationType.SERIALIZATION);
View Full Code Here

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public BundleResourceDeployment createBundleResourceDeploymentInNewTrans(Subject subject, int bundleDeploymentId,
        int resourceId) throws Exception {

        BundleDeployment deployment = entityManager.find(BundleDeployment.class, bundleDeploymentId);
        if (null == deployment) {
            throw new IllegalArgumentException("Invalid bundleDeploymentId: " + bundleDeploymentId);
        }
        Resource resource = entityManager.find(Resource.class, resourceId);
        if (null == resource) {
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.bundle.BundleDeployment

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.