Examples of BundleResourceDeployment


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

        c.fetchResource(true);
        List<BundleResourceDeployment> brds = bundleManager.findBundleResourceDeploymentsByCriteria(overlord, c);
        assertEquals(1, brds.size());
        assertEquals(1, bd1d.getResourceDeployments().size());
        assertEquals(bd1d.getResourceDeployments().get(0).getId(), brds.get(0).getId());
        BundleResourceDeployment brd = brds.get(0);

        assertNotNull(brd.getBundleResourceDeploymentHistories());
        int size = brd.getBundleResourceDeploymentHistories().size();
        assertTrue(size > 0);
        String auditMessage = "BundleTest-Message";
        bundleManager.addBundleResourceDeploymentHistoryInNewTrans(overlord, brd.getId(),
            new BundleResourceDeploymentHistory(overlord.getName(), auditMessage, auditMessage,
                BundleResourceDeploymentHistory.Category.DEPLOY_STEP, BundleResourceDeploymentHistory.Status.SUCCESS,
                auditMessage, auditMessage));

        brds = bundleManager.findBundleResourceDeploymentsByCriteria(overlord, c);
        assertEquals(1, brds.size());
        assertEquals(brd.getId(), brds.get(0).getId());
        brd = brds.get(0);
        assertNotNull(brd.getBundleResourceDeploymentHistories());
        assertTrue((size + 1) == brd.getBundleResourceDeploymentHistories().size());
        BundleResourceDeploymentHistory newHistory = null;
        for (BundleResourceDeploymentHistory h : brd.getBundleResourceDeploymentHistories()) {
            if (auditMessage.equals(h.getMessage())) {
                newHistory = h;
                break;
            }
        }
View Full Code Here

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

        c.fetchResource(true);
        List<BundleResourceDeployment> brds = bundleManager.findBundleResourceDeploymentsByCriteria(subject, c);
        assertEquals(1, brds.size());
        assertEquals(1, bd1d.getResourceDeployments().size());
        assertEquals(bd1d.getResourceDeployments().get(0).getId(), brds.get(0).getId());
        BundleResourceDeployment brd = brds.get(0);

        assertNotNull(brd.getBundleResourceDeploymentHistories());
        int size = brd.getBundleResourceDeploymentHistories().size();
        assertTrue(size > 0);
        String auditMessage = "BundleTest-Message";
        bundleManager.addBundleResourceDeploymentHistoryInNewTrans(overlord, brd.getId(),
            new BundleResourceDeploymentHistory(overlord.getName(), auditMessage, auditMessage,
                BundleResourceDeploymentHistory.Category.DEPLOY_STEP, BundleResourceDeploymentHistory.Status.SUCCESS,
                auditMessage, auditMessage));

        brds = bundleManager.findBundleResourceDeploymentsByCriteria(subject, c);
        assertEquals(1, brds.size());
        assertEquals(brd.getId(), brds.get(0).getId());
        brd = brds.get(0);
        assertNotNull(brd.getBundleResourceDeploymentHistories());
        assertTrue((size + 1) == brd.getBundleResourceDeploymentHistories().size());
        BundleResourceDeploymentHistory newHistory = null;
        for (BundleResourceDeploymentHistory h : brd.getBundleResourceDeploymentHistories()) {
            if (auditMessage.equals(h.getMessage())) {
                newHistory = h;
                break;
            }
        }
View Full Code Here

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

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public BundleResourceDeploymentHistory addBundleResourceDeploymentHistoryInNewTrans(Subject subject,
        int resourceDeploymentId, BundleResourceDeploymentHistory history) throws Exception {

        BundleResourceDeployment resourceDeployment = entityManager.find(BundleResourceDeployment.class,
            resourceDeploymentId);
        if (null == resourceDeployment) {
            throw new IllegalArgumentException("Invalid resourceDeploymentId: " + resourceDeploymentId);
        }

        resourceDeployment.addBundleResourceDeploymentHistory(history);
        this.entityManager.persist(resourceDeployment);

        return history;
    }
View Full Code Here

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

        if (bundleResourceDeploymentsByCriteria.isEmpty()) {
            return Collections.emptyList();
        }

        BundleResourceDeployment resourceDeployment = bundleResourceDeploymentsByCriteria.iterator().next();

        return new ArrayList<BundleResourceDeploymentHistory>(resourceDeployment.getBundleResourceDeploymentHistories());
    }
View Full Code Here

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

        AgentClient agentClient = agentManager.getAgentClient(subjectManager.getOverlord(), bundleTargetResourceId);
        BundleAgentService bundleAgentService = agentClient.getBundleAgentService();

        // The BundleResourceDeployment record must exist in the db before the agent request because the agent may try
        // to add History to it during immediate deployments. So, create and persist it (requires a new trans).
        BundleResourceDeployment resourceDeployment = bundleManager.createBundleResourceDeploymentInNewTrans(
            subjectManager.getOverlord(), deployment.getId(), bundleTargetResourceId);

        if (null != bundleTarget.getResourceType().getResourceTypeBundleConfiguration()) {

            // Ask the agent to schedule the request. The agent should add history as needed.
            try {
                BundleScheduleRequest request = bundleManager.getScheduleRequest(subject, resourceDeployment.getId(),
                    isCleanDeployment, isRevert);

                // add the deployment request history (in a new trans)
                BundleResourceDeploymentHistory history = new BundleResourceDeploymentHistory(subject.getName(),
                    AUDIT_ACTION_DEPLOYMENT_REQUESTED, deployment.getName(), null,
                    BundleResourceDeploymentHistory.Status.SUCCESS, "Requested deployment time: "
                        + request.getRequestedDeployTimeAsString(), null);
                bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subjectManager.getOverlord(),
                    resourceDeployment.getId(), history);

                BundleScheduleResponse response = bundleAgentService.schedule(request);

                if (!response.isSuccess()) {
                    // Handle Schedule Failures. This may include deployment failures for immediate deployment request
                    bundleManager.setBundleResourceDeploymentStatusInNewTransaction(subject,
                        resourceDeployment.getId(), BundleDeploymentStatus.FAILURE);
                    history = new BundleResourceDeploymentHistory(subject.getName(), AUDIT_ACTION_DEPLOYMENT,
                        deployment.getName(), null, BundleResourceDeploymentHistory.Status.FAILURE,
                        response.getErrorMessage(), null);
                    bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subject, resourceDeployment.getId(),
                        history);
                }
            } catch (Throwable t) {
                // fail the unlaunched resource deployment
                BundleResourceDeploymentHistory failureHistory = new BundleResourceDeploymentHistory(subject.getName(),
                    AUDIT_ACTION_DEPLOYMENT, deployment.getName(), null,
                    BundleResourceDeploymentHistory.Status.FAILURE, "Failed to schedule, agent on [" + bundleTarget
                        + "] may be down: " + t, null);
                bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subject, resourceDeployment.getId(),
                    failureHistory);
                bundleManager.setBundleResourceDeploymentStatusInNewTransaction(subject, resourceDeployment.getId(),
                    BundleDeploymentStatus.FAILURE);
            }

        } else {
            bundleManager.setBundleResourceDeploymentStatusInNewTransaction(subject, resourceDeployment.getId(),
                BundleDeploymentStatus.FAILURE);
            BundleResourceDeploymentHistory history = new BundleResourceDeploymentHistory(subject.getName(),
                AUDIT_ACTION_DEPLOYMENT, deployment.getName(), null, BundleResourceDeploymentHistory.Status.FAILURE,
                "Target resource is not of a type that can have bundles deployed to it [resource="
                    + bundleTarget.getName() + "; id=" + bundleTarget.getId() + "]. Fix target group for destination ["
                    + deployment.getDestination().getName() + "]", null);
            bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subject, resourceDeployment.getId(), history);
        }

        return resourceDeployment;
    }
View Full Code Here

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

            subject, brdc);
        if (null == resourceDeployments || resourceDeployments.isEmpty()) {
            throw new IllegalArgumentException("Can not deploy using invalid resourceDeploymentId ["
                + resourceDeploymentId + "].");
        }
        BundleResourceDeployment resourceDeployment = resourceDeployments.get(0);

        ResourceCriteria rc = new ResourceCriteria();
        rc.addFilterId(resourceDeployment.getResource().getId());
        rc.fetchTags(true);
        Resource resource = resourceManager.findResourcesByCriteria(subject, rc).get(0);
        resourceDeployment.setResource(resource);

        // make sure the deployment contains the info required by the schedule service
        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);

        BundleScheduleRequest request = new BundleScheduleRequest(resourceDeployment);
View Full Code Here

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

        Resource resource = entityManager.find(Resource.class, resourceId);
        if (null == resource) {
            throw new IllegalArgumentException("Invalid resourceId (Resource does not exist): " + resourceId);
        }

        BundleResourceDeployment resourceDeployment = new BundleResourceDeployment(deployment, resource);

        entityManager.persist(resourceDeployment);
        return resourceDeployment;
    }
View Full Code Here

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

    @Override
    public BundleResourceDeployment setBundleResourceDeploymentStatusInNewTransaction(Subject subject,
        int resourceDeploymentId, BundleDeploymentStatus status) throws Exception {

        // set the status of the individual resource deployment
        BundleResourceDeployment resourceDeployment = entityManager.find(BundleResourceDeployment.class,
            resourceDeploymentId);
        if (null == resourceDeployment) {
            throw new IllegalArgumentException("Invalid bundleDeploymentId: " + resourceDeploymentId);
        }

        // update the status
        resourceDeployment.setStatus(status);

        return resourceDeployment;
    }
View Full Code Here

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

            if (!authorizationManager.canViewResources(subject, resourceIds)) {
                for (Integer resourceId : resourceIds) {
                    if (!authorizationManager.canViewResource(subject, resourceId)) {
                        for (Iterator<BundleResourceDeployment> i = result.iterator(); i.hasNext();) {
                            BundleResourceDeployment brd = i.next();
                            if (brd.getResource().getId() == resourceId.intValue()) {
                                i.remove();
                            }
                        }
                    }
                }
View Full Code Here

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

    @Override
    public BundleScheduleResponse schedule(final BundleScheduleRequest request) {
        final BundleScheduleResponse response = new BundleScheduleResponse();

        try {
            final BundleResourceDeployment resourceDeployment = request.getBundleResourceDeployment();
            final BundleDeployment bundleDeployment = resourceDeployment.getBundleDeployment();

            // find the resource that will handle the bundle processing
            BundleType bundleType = bundleDeployment.getBundleVersion().getBundle().getBundleType();
            ResourceType resourceType = bundleType.getResourceType();
            Set<Resource> resources = inventoryManager.getResourcesWithType(resourceType);
            if (resources.isEmpty()) {
                throw new Exception("No bundle plugin supports bundle type [" + bundleType + "]");
            }
            final int bundleHandlerResourceId = resources.iterator().next().getId();
            final ResourceContainer resourceContainer = inventoryManager.getResourceContainer(bundleHandlerResourceId);
            if (null == resourceContainer.getResourceContext()) {
                throw new Exception("No bundle plugin resource available to handle deployment for bundle type ["
                    + bundleType
                    + "]. Ensure the bundle plugin is deployed and its resource is imported into inventory.");
            }

            auditDeployment(resourceDeployment, AUDIT_DEPLOYMENT_SCHEDULED, bundleDeployment.getName(),
                "Scheduled deployment time: " + request.getRequestedDeployTimeAsString());

            Runnable deployerRunnable = new Runnable() {
                @Override
                public void run() {
                    try {
                        // pull down the bundle files that the plugin will need in order to process the bundle
                        File pluginTmpDir = resourceContainer.getResourceContext().getTemporaryDirectory();
                        File bundleFilesDir = new File(pluginTmpDir, "bundle-versions/"
                            + bundleDeployment.getBundleVersion().getId());
                        bundleFilesDir.mkdirs();

                        // clean up any old downloads we may have retrieved before. This helps clean out
                        // our temp directory so we don't unnecessarily fill up our file system with obsolete files
                        removeOldDownloadedBundleFiles(bundleFilesDir);

                        // now download the bundle files we need for the current deployment
                        Map<PackageVersion, File> downloadedFiles = downloadBundleFiles(resourceDeployment,
                            bundleFilesDir);

                        // deploy the bundle utilizing the bundle facet object
                        String deploymentMessage = "Deployment [" + bundleDeployment + "] to ["
                            + resourceDeployment.getResource() + "]";
                        auditDeployment(resourceDeployment, AUDIT_DEPLOYMENT_STARTED, bundleDeployment.getName(),
                            deploymentMessage);

                        BundleDeployRequest deployRequest = new BundleDeployRequest();
                        deployRequest.setBundleManagerProvider(BundleManager.this);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.