Package org.rhq.enterprise.server.content

Examples of org.rhq.enterprise.server.content.ContentManagerLocal


        assertNotNull("Failed create bundle for [name: " + bundleName + "]", bundle);
    }

    void createPackage(String packageName, String resourceTypeName, String pluginName) throws Exception {
        SubjectManagerLocal subjectMgr = LookupUtil.getSubjectManager();
        ContentManagerLocal contentMgr = LookupUtil.getContentManager();

        List<PackageType> packageTypes = contentMgr.findPackageTypes(subjectMgr.getOverlord(), resourceTypeName,
            pluginName);
        Package pkg = new Package(packageName, packageTypes.get(0));

        contentMgr.persistPackage(pkg);
    }
View Full Code Here


        Map<String, String> formFields, HttpServletRequest request, HttpServletResponse response) throws IOException {

        String successMsg;

        try {
            ContentManagerLocal contentManager = LookupUtil.getContentManager();

            // note that this assumes 1 and only 1 file is uploaded
            File file = files.values().iterator().next();

            int packageTypeId = Integer.parseInt(getFormField(formFields, "packageTypeId", null));
            String packageName = getFormField(formFields, "name", file.getName());
            packageName = FileUtil.getFileName(FileUtil.useForwardSlash(packageName), "/"); // strip path, get just filename
            String version = getFormField(formFields, "version", "0");
            String archIdField = getFormField(formFields, "archId", null);
            int architectureId = (null != archIdField) ? Integer.parseInt(archIdField) : contentManager
                .getNoArchitecture().getId();
            Integer repoId = null;
            String repoIdS = getFormField(formFields, "repoId", null);
            if (repoIdS != null) {
                repoId = Integer.parseInt(repoIdS);
            }

            //use getUploadedPackageVersion instead of createPackageVersion here
            //because createPackageVersion successfully returns an already existing
            //package version with the provided "location". This is not what we want
            //here since we want to make sure that the uploaded file actually gets
            //persisted.
            Map<String, String> metaData = new HashMap<String, String>();
            metaData.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE, Long.toString(file.lastModified()));
            metaData.put(ContentManagerLocal.UPLOAD_FILE_NAME, packageName);
            InputStream fileStream = new FileInputStream(file);
            try {
                PackageVersion packageVersion = contentManager.getUploadedPackageVersion(subject, packageName,
                    packageTypeId, version, architectureId, fileStream, metaData, repoId);
                successMsg = "success [packageVersionId=" + packageVersion.getId() + ",packageId="
                    + packageVersion.getGeneralPackage().getId() + "]";
            } finally {
                fileStream.close();
View Full Code Here

        Subject subject = EnterpriseFacesContextUtility.getSubject();
        String[] selectedPackages = FacesContextUtility.getRequest().getParameterValues("selectedPackages");
        int repoId = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));

        RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
        ContentManagerLocal contentManager = LookupUtil.getContentManager();

        int[] packageIds = new int[selectedPackages.length];
        for (int i = 0; i < packageIds.length; i++) {
            packageIds[i] = Integer.parseInt(selectedPackages[i]);
        }

        try {
            List<Resource> resources = repoManager.findSubscribedResources(subject, repoId, PageControl
                .getUnlimitedInstance());
            int[] resourceIds = new int[resources.size()];
            for (int i = 0; i < resourceIds.length; i++) {
                resourceIds[i] = resources.get(i).getId();
            }

            contentManager.deployPackagesWithNote(subject, resourceIds, packageIds, "Repository package install");
        } catch (Exception e) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to deploy packages: " + packageIds
                + " to Resources subscribed to repository: " + repoId + " Error: " + e.getMessage());
        }
    }
View Full Code Here

    }

    public List<PackageVersion> getAllBundleVersionPackageVersions(int bundleVersionId) {
        try {
            final BundleManagerLocal bm = LookupUtil.getBundleManager();
            ContentManagerLocal cm = LookupUtil.getContentManager();
            final Subject subject = LookupUtil.getSubjectManager().getOverlord();
            final BundleFileCriteria bfc = new BundleFileCriteria();
            PackageVersionCriteria pvc = new PackageVersionCriteria();

            bfc.addFilterBundleVersionId(bundleVersionId);
            bfc.fetchPackageVersion(true);

            //Use CriteriaQuery to automatically chunk/page through criteria query results
            CriteriaQueryExecutor<BundleFile, BundleFileCriteria> queryExecutor = new CriteriaQueryExecutor<BundleFile, BundleFileCriteria>() {
                @Override
                public PageList<BundleFile> execute(BundleFileCriteria criteria) {
                    return bm.findBundleFilesByCriteria(subject, bfc);
                }
            };

            CriteriaQuery<BundleFile, BundleFileCriteria> bundleFiles = new CriteriaQuery<BundleFile, BundleFileCriteria>(
                bfc, queryExecutor);

            List<PackageVersion> packageVersions = new ArrayList<PackageVersion>();
            PackageVersion packageVersion = null;
            for (BundleFile bundleFile : bundleFiles) {
                pvc.addFilterId(bundleFile.getPackageVersion().getId());
                packageVersion = cm.findPackageVersionsByCriteria(subject, pvc).get(0);
                HibernateDetachUtility.nullOutUninitializedFields(packageVersion, SerializationType.SERIALIZATION);
                packageVersions.add(packageVersion);
            }
            return packageVersions;
        } catch (Exception e) {
View Full Code Here

        Subject subject = EnterpriseFacesContextUtility.getSubject();
        Resource resource = EnterpriseFacesContextUtility.getResource();

        try {
            ContentManagerLocal contentManager = LookupUtil.getContentManager();
            contentManager.deployPackagesWithNote(subject, new int[] { resource.getId() }, packagesVersionsIdsToDeploy, notes);
        } catch (Exception e) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Could not send deploy request to agent", e);
        }

        return "successOrFailure";
View Full Code Here

            installedPackageIds[i] = Integer.parseInt(selectedPackages[i]);
        }

        // Execute the delete
        try {
            ContentManagerLocal contentManager = LookupUtil.getContentManager();
            contentManager.deletePackages(subject, resource.getId(), installedPackageIds, notes);
        } catch (Exception e) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to delete packages. Cause: " + e);
        }

        // Sleep just enough to let "fast" operations complete before being redirected
View Full Code Here

    private final Log log = LogFactory.getLog(this.getClass());

    public String loadSteps() {
        ContentUIManagerLocal contentUIManager = LookupUtil.getContentUIManager();
        ContentManagerLocal contentManager = LookupUtil.getContentManager();

        HttpServletRequest request = FacesContextUtility.getRequest();
        selectedPackageId = Integer.parseInt(request.getParameter("selectedPackageId"));

        log.info("Loading package version for ID: " + selectedPackageId);

        packageVersion = contentUIManager.getPackageVersion(selectedPackageId);

        Resource resource = EnterpriseFacesContextUtility.getResource();

        // Going forward, we'll need to create this earlier and store the user entered configuration in these
        // objects.  jdobies, Mar 3, 2008
        ResourcePackageDetails details = ContentUtils.toResourcePackageDetails(packageVersion);

        try {
            deploySteps = contentManager.translateInstallationSteps(resource.getId(), details);
        } catch (Exception e) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Could not retrieve installation steps", e);
        }

        log.info("Translated number of steps: " + (deploySteps != null ? deploySteps.size() : null));
View Full Code Here

                       now, don't worry about that. The rest of this will be written assuming it's part of the deploy
                       workflow and we'll deal with the refactoring later.
                       jdobies, Feb 27, 2008
                     */
                    try {
                        ContentManagerLocal contentManager = LookupUtil.getContentManager();

                        //store information about uploaded file for packageDetails as most of it is already available
                        Map<String, String> packageUploadDetails = new HashMap<String, String>();
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_SIZE,
                            String.valueOf(fileItem.getFileSize()));
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE,
                            String.valueOf(System.currentTimeMillis()));
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_OWNER, subject.getName());
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_NAME, fileItem.getFileName());

                        String sha = null;
                        String md5 = null;
                        try {//Easier to implement here than in server side bean. Shouldn't affect performance too much.
                            md5 = new MessageDigestGenerator(MessageDigestGenerator.MD5).calcDigestString(fileItem
                                .getFile());
                            sha = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(fileItem
                                .getFile());
                        } catch (IOException e1) {
                            log.warn("Error calculating file digest(s)", e1);
                        }

                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_MD5, md5);
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_SHA256, sha);
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_DISPLAY_VERSION, displayVersion);

                        //For package types that handle their own versioning, etc. let's use what the user passed in
                        //as a version. For the standard, i.e. agent-plugin defined, package types use what we want
                        //to use for them - sha-based versions to deal with improper versions discovered/declared by
                        //the packages (i.e. versions in MANIFEST.MF not properly updated)
                        //
                        //Did I say I can't wait for all this to disappear with the new provisioning? :)
                        boolean nonStandardPackageType = ContentManagerHelper.getPackageTypePluginContainer().getPluginManager().getBehavior(packageTypeId) != null;
                        String versionToUse = nonStandardPackageType ? displayVersion : formatVersion(sha);

                        Integer iRepoId = usingARepo ? Integer.parseInt(repoId) : null;
                        packageVersion = contentManager.getUploadedPackageVersion(subject, packageName, packageTypeId,
                            versionToUse, architectureId, packageStream, packageUploadDetails, iRepoId);

                    } catch (NoResultException nre) {
                        //eat the exception.  Some of the queries return no results if no package yet exists which is fine.
                    } catch (Exception e) {
View Full Code Here

        return "success";
    }

    public SelectItem[] getArchitectures() {
        Subject subject = EnterpriseFacesContextUtility.getSubject();
        ContentManagerLocal contentManager = LookupUtil.getContentManager();
        List<Architecture> architectures = contentManager.findArchitectures(subject);

        SelectItem[] items = new SelectItem[architectures.size()];
        int itemCounter = 0;
        for (Architecture arch : architectures) {
            SelectItem item = new SelectItem(arch.getId(), arch.getName());
View Full Code Here

    public InstalledPackage lookupBackingPackage() {
        if (backingPackage == null) {
            Resource resource = EnterpriseFacesContextUtility.getResource();

            ContentManagerLocal contentManager = LookupUtil.getContentManager();
            backingPackage = contentManager.getBackingPackageForResource(EnterpriseFacesContextUtility.getSubject(),
                resource.getId());
        }

        return backingPackage;
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.content.ContentManagerLocal

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.