Package org.rhq.core.domain.content

Examples of org.rhq.core.domain.content.PackageVersion


                repoId = FacesContextUtility.getRequiredRequestParameter("id");
            }
        }

        try {
            PackageVersion packageVersion = null;
            try {
                log.debug("Streaming new package bits from uploaded file: " + fileItem.getFile());

                // Grab a stream for the file being uploaded
                InputStream packageStream = new FileInputStream(fileItem.getFile());
                try {
                    // Ask the bean to create the package

                    /* Currently, this is just used in the workflow for deploying a new package. This will probably get
                       refactored in the future for a general way of adding packages to the repo as its own operation. For
                       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) {
                        String errorMessages = ThrowableUtil.getAllMessages(e);
                        FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to create package ["
                            + packageName + "] in repository. Cause: " + errorMessages);
                        return "failure";
                    }
                } finally {
                    packageStream.close();
                }
            } catch (IOException e) {
                String errorMessages = ThrowableUtil.getAllMessages(e);
                FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
                    "Failed to retrieve the input stream. Cause: " + errorMessages);
                return "failure";
            }

            int[] packageVersionList = new int[] { packageVersion.getId() };

            // Put the package ID in the session so it can fit into the deploy existing package workflow
            HttpSession session = request.getSession();
            session.setAttribute("selectedPackages", packageVersionList);
        } finally {
View Full Code Here


        return backingPackage;
    }

    public String getBackingPackageName() {
        InstalledPackage installedPackage = lookupBackingPackage();
        PackageVersion packageVersion = installedPackage.getPackageVersion();
        Package pkg = packageVersion.getGeneralPackage();

        return pkg.getName();
    }
View Full Code Here

        return pkg.getName();
    }

    public int getBackingPackageArchitectureId() {
        InstalledPackage ip = lookupBackingPackage();
        PackageVersion pv = ip.getPackageVersion();

        return pv.getArchitecture().getId();
    }
View Full Code Here

        return pv.getArchitecture().getId();
    }

    public int getBackingPackageTypeId() {
        InstalledPackage ip = lookupBackingPackage();
        PackageVersion pv = ip.getPackageVersion();
        Package p = pv.getGeneralPackage();

        return p.getPackageType().getId();
    }
View Full Code Here

        return pc;
    }
   
    public static ResourcePackageDetails installedPackageToDetails(InstalledPackage installedPackage) {
        PackageVersion packageVersion = installedPackage.getPackageVersion();
        ResourcePackageDetails details = packageVersionToDetails(packageVersion);

        return details;
    }
View Full Code Here

    }

    private static BitsAndFileExtension getPackageBits(int packageId, int repoId) throws IOException {
        final ContentSourceManagerLocal csm = LookupUtil.getContentSourceManager();
        RepoManagerLocal rm = LookupUtil.getRepoManagerLocal();
        final PackageVersion versionToUse = rm.getLatestPackageVersion(LookupUtil.getSubjectManager().getOverlord(),
            packageId, repoId);

        if (versionToUse == null) {
            throw new IllegalArgumentException(
                "The package with id "
                    + packageId
                    + " either doesn't exist at all or doesn't have any version. Can't execute a CLI script without a script to run.");
        }

        PipedInputStream bits = new PipedInputStream();
        final PipedOutputStream out = new PipedOutputStream(bits);

        Thread reader = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    csm.outputPackageVersionBits(versionToUse, out);
                } catch (RuntimeException e) {
                    LOG.warn("The thread for reading the bits of package version [" + versionToUse
                        + "] failed with exception.", e);
                    throw e;
                } finally {
                    try {
                        out.close();
                    } catch (IOException e) {
                        //doesn't happen in piped output stream
                        LOG.error(
                            "Failed to close the piped output stream receiving the package bits of package version "
                                + versionToUse + ". This should never happen.", e);
                    }
                }
            }
        });
        reader.setName("CLI Alert download thread for package version " + versionToUse);
        reader.setDaemon(true);
        reader.start();

        BitsAndFileExtension ret = new BitsAndFileExtension();
        ret.packageBits = bits;
        String fileName = versionToUse.getFileName();
        String extension = "";

        if (fileName != null) {
            int dotIdx = fileName.lastIndexOf('.');
            if (dotIdx >= 0) {
View Full Code Here

            ret = ret.replace("$userName", config.subject.getName());

            //now get the package and repo info
            Subject overlord = LookupUtil.getSubjectManager().getOverlord();
            RepoManagerLocal rm = LookupUtil.getRepoManagerLocal();
            PackageVersion versionToUse = rm.getLatestPackageVersion(overlord, config.packageId, config.repoId);

            if (versionToUse != null) {
                ret = ret.replace("$packageName", versionToUse.getDisplayName());
                ret = ret.replace(
                    "$packageVersion",
                    versionToUse.getDisplayVersion() == null ? versionToUse.getVersion() : versionToUse
                        .getDisplayVersion());
            } else {
                ret = ret.replace("$packageName", "unknown script with package id " + config.packageId);
                ret = ret.replace("$packageVersion", "no version");
            }
View Full Code Here

        when(mockContentManager.persistPackage(isNotNull(Package.class))).thenReturn(mockPackage);
       
        when(mockEntityManager.find(eq(Package.class), any())).thenReturn(mockPackage);
        when(mockPackage.getPackageType()).thenReturn(mockPackageType);

        PackageVersion mockPackageVersion = mock(PackageVersion.class);
        when(mockContentManager.persistPackageVersion(isNotNull(PackageVersion.class)))
            .thenReturn(mockPackageVersion);

        when(mockEntityManager.find(eq(PackageVersion.class), anyInt())).thenReturn(mockPackageVersion);
        when(mockPackageVersion.getGeneralPackage()).thenReturn(mockPackage);
        when(mockPackageVersion.getArchitecture()).thenReturn(mockArchitecture);

        PackageBitsBlob mockPackageBitsBlob = mock(PackageBitsBlob.class);
        when(mockEntityManager.find(eq(PackageBitsBlob.class), anyInt())).thenReturn(mockPackageBitsBlob);

        PackageBits mockBits = mock(PackageBits.class);
        when(mockEntityManager.find(eq(PackageBits.class), anyInt())).thenReturn(mockBits);

        DataSource mockDataSource = mock(DataSource.class);
        Connection mockConnection = mock(Connection.class);
        when(mockDataSource.getConnection()).thenReturn(mockConnection);
        PreparedStatement mockPreparedStatement1 = mock(PreparedStatement.class);
        when(mockConnection.prepareStatement(anyString())).thenReturn(mockPreparedStatement1);
        ResultSet mockResultSet = mock(ResultSet.class);
        when(mockPreparedStatement1.executeQuery()).thenReturn(mockResultSet);
        when(mockResultSet.next()).thenReturn(true, false);
        Blob mockBlob = mock(Blob.class);
        when(mockResultSet.getBlob(anyInt())).thenReturn(mockBlob);
        OutputStream mockOutputStream = mock(OutputStream.class);
        when(mockBlob.setBinaryStream(anyLong())).thenReturn(mockOutputStream);

        //create object to test and inject required dependencies
        ContentManagerBean objectUnderTest = new ContentManagerBean();
        Field[] fields = ContentManagerBean.class.getDeclaredFields();

        for (Field field : fields) {
            if (field.getName().equals("entityManager")) {
                field.setAccessible(true);
                field.set(objectUnderTest, mockEntityManager);
                field.setAccessible(false);
            }
            else if (field.getName().equals("contentManager")) {
                field.setAccessible(true);
                field.set(objectUnderTest, mockContentManager);
                field.setAccessible(false);
            }
            else if (field.getName().equals("dataSource")) {
                field.setAccessible(true);
                field.set(objectUnderTest, mockDataSource);
                field.setAccessible(false);
            }
        }

        //run the code to be tested
        PackageVersion result = objectUnderTest.createPackageVersionWithDisplayVersion(mockSubject, packageName,
            packageTypeID, version, displayVersion, architectureId, packageBitStream);

        //verify the results (Assert and Mock Verification)
        verify(mockList, times(2)).size();
        verify(mockList, never()).get(anyInt());
View Full Code Here

        when(mockEntityManager.createNamedQuery(eq(PackageVersion.QUERY_FIND_BY_PACKAGE_VER_ARCH))).thenReturn(
            mockQuery);
        List mockList = mock(List.class);
        when(mockQuery.getResultList()).thenReturn(mockList);
        when(mockList.size()).thenReturn(1);
        PackageVersion mockPackageVersion = mock(PackageVersion.class);
        when(mockList.get(eq(0))).thenReturn(mockPackageVersion);

        //create object to test and inject required dependencies
        ContentManagerBean objectUnderTest = new ContentManagerBean();
        Field[] fields = ContentManagerBean.class.getDeclaredFields();

        for (Field field : fields) {
            if (field.getName().equals("entityManager")) {
                field.setAccessible(true);
                field.set(objectUnderTest, mockEntityManager);
                field.setAccessible(false);
            }
        }

        //run the code to be tested
        PackageVersion result = objectUnderTest.createPackageVersionWithDisplayVersion(mockSubject, packageName,
            packageTypeID, version, displayVersion, architectureId, packageBitStream);

        //verify the results (Assert and Mock Verification)
        verify(mockList, times(1)).size();
        verify(mockList, times(1)).get(eq(0));
View Full Code Here

        when(mockEntityManager.createNamedQuery(eq(PackageVersion.QUERY_FIND_BY_PACKAGE_VER_ARCH))).thenReturn(
            mockQuery);
        List mockList = mock(List.class);
        when(mockQuery.getResultList()).thenReturn(mockList);
        when(mockList.size()).thenReturn(1);
        PackageVersion mockPackageVersion = mock(PackageVersion.class);
        when(mockList.get(eq(0))).thenReturn(mockPackageVersion);

        //create object to test and inject required dependencies
        ContentManagerBean objectUnderTest = new ContentManagerBean();
        Field[] fields = ContentManagerBean.class.getDeclaredFields();

        for (Field field : fields) {
            if (field.getName().equals("entityManager")) {
                field.setAccessible(true);
                field.set(objectUnderTest, mockEntityManager);
                field.setAccessible(false);
            }
        }

        //run the code to be tested
        PackageVersion result = objectUnderTest.createPackageVersionWithDisplayVersion(mockSubject, packageName,
            packageTypeID, version, displayVersion, architectureId, packageBitStream);

        //verify the results (Assert and Mock Verification)
        verify(mockList, times(1)).size();
        verify(mockList, times(1)).get(eq(0));
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.content.PackageVersion

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.