Examples of PackageBits


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

                    assert composite.getPackageBitsId() == null;
                    assert !composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // pretend we loaded the bits, but we stored them somewhere other then the DB
                    PackageBits packageBits = createPackageBits();
                    pkgVer.setPackageBits(packageBits);
                    pkgVer = em.merge(pkgVer);
                    em.flush();

                    // test that the bits are available, but are not stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // let's make sure there really is no data in the DB
                    packageBits = em.find(PackageBits.class, packageBits.getId());
                    assert packageBits != null;
                    assert packageBits.getBlob().getBits() == null;

                    // now lets store some bits in the DB
                    final String DATA = "testPackageBits data";
                    PackageBitsBlob packageBitsBlob = em.find(PackageBitsBlob.class, packageBits.getId());
                    packageBitsBlob.setBits(DATA.getBytes());
                    em.merge(packageBitsBlob);
                    em.flush();

                    // test that the bits are available and stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // let's make sure the data really is in the DB
                    packageBits = em.find(PackageBits.class, packageBits.getId());
                    assert packageBits != null;
                    assert DATA.equals(new String(packageBits.getBlob().getBits()));

                    ////////////////////////////////////////////////////
                    // create another package version and test with that
                    ////////////////////////////////////////////////////
                    PackageVersion pkgVer2 = new PackageVersion(pkg, "2", arch);
                    em.persist(pkgVer2);
                    em.flush();

                    // first make sure the query still gets the right answer for the first pkgVer
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // test that no bits are available right now
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer2.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer2.getId();
                    assert composite.getPackageBitsId() == null;
                    assert !composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // pretend we loaded the bits, but we stored them somewhere other then the DB
                    PackageBits packageBits2 = createPackageBits();
                    pkgVer2.setPackageBits(packageBits2);
                    pkgVer2 = em.merge(pkgVer2);
                    em.flush();

                    // make sure the query still gets the right answer for the first pkgVer
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // test that the bits are available, but are not stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer2.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer2.getId();
                    assert composite.getPackageBitsId() == packageBits2.getId();
                    assert composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // let's make sure there really is no data in the DB
                    packageBits2 = em.find(PackageBits.class, packageBits2.getId());
                    assert packageBits2 != null;
                    assert packageBits2.getBlob().getBits() == null;

                    // now lets store some bits in the DB
                    final String DATA2 = "testPackageBits more data";
                    packageBits2.getBlob().setBits(DATA2.getBytes());
                    em.merge(packageBits2.getBlob());
                    em.flush();

                    // make sure the query still gets the right answer for the first pkgVer
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // test that the bits are available and stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer2.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer2.getId();
                    assert composite.getPackageBitsId() == packageBits2.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // let's make sure the data really is in the DB
                    packageBits2 = em.find(PackageBits.class, packageBits2.getId());
                    assert packageBits2 != null;
                    assert DATA2.equals(new String(packageBits2.getBlob().getBits()));

                } catch (Throwable t) {
                    t.printStackTrace();
                    throw new RuntimeException(t);
                }
View Full Code Here

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

                    assert composite.getPackageBitsId() == null;
                    assert !composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // pretend we loaded the bits, but we stored them somewhere other then the DB
                    PackageBits packageBits = createPackageBits();
                    pkgVer.setPackageBits(packageBits);
                    pkgVer = em.merge(pkgVer);
                    em.flush();

                    // test that the bits are available, but are not stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // let's make sure there really is no data in the DB
                    packageBits = em.find(PackageBits.class, packageBits.getId());
                    assert packageBits != null;
                    assert packageBits.getBlob().getBits() == null;

                    // now lets store some bits in the DB using PreparedStatements and BLOB mechanism
                    // to simulate large file transfers where streaming is used instead of reading entire
                    // contents into memory every time.

                    // destination once pulled from db
                    File tempDir = getTempDir();
                    if (!tempDir.exists()) {
                        assertTrue("Unable to mkdirs " + tempDir + " for test.", tempDir.mkdirs());
                    }
                    File retrieved = new File(tempDir, "pulled.jar");
                    if (retrieved.exists()) {
                        assertTrue("Unable to delete " + retrieved.getPath() + " for test cleanup.", retrieved.delete());
                    }

                    //any jar should be fine. Use canned jar
                    InputStream originalBinaryStream = this.getClass().getClassLoader()
                        .getResourceAsStream("binary-blob-sample.jar");
                    String originalDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256)
                        .calcDigestString(originalBinaryStream);
                    originalBinaryStream.close();
                    originalBinaryStream = this.getClass().getClassLoader()
                        .getResourceAsStream("binary-blob-sample.jar");
                    contentManager.updateBlobStream(originalBinaryStream, packageBits, null);
                    packageBits = em.find(PackageBits.class, packageBits.getId());

                    // test that the bits are available and stored in the DB: Reading the Blob
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    FileOutputStream outputStream = new FileOutputStream(retrieved);
                    contentManager.writeBlobOutToStream(outputStream, packageBits, false);
View Full Code Here

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

            }
        });
    }

    private PackageBits createPackageBits() {
        PackageBits bits = null;
        PackageBitsBlob blob = null;

        // We have to work backwards to avoid constraint violations. PackageBits requires a PackageBitsBlob,
        // so create and persist that first, getting the ID
        blob = new PackageBitsBlob();
        em.persist(blob);

        // Now create the PackageBits entity and assign the Id and blob.  Note, do not persist the
        // entity, the row already exists. Just perform and flush the update.
        bits = new PackageBits();
        bits.setId(blob.getId());
        bits.setBlob(blob);
        em.flush();

        // return the new PackageBits and associated PackageBitsBlob
        return bits;
    }
View Full Code Here

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

            throw new IllegalStateException(" Unknown download mode - this is a bug, please report it: " + pvcs);
        }
        }

        InputStream bitsStream = null;
        PackageBits packageBits = null;

        try {
            ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer();
            bitsStream = pc.getAdapterManager().loadPackageBits(contentSourceId, packageVersionLocation);

            Connection conn = null;
            PreparedStatement ps = null;
            PreparedStatement ps2 = null;
            try {
                packageBits = createPackageBits(pk.getContentSource().getDownloadMode() == DownloadMode.DATABASE);

                PackageVersion pv = entityManager.find(PackageVersion.class, packageVersionId);
                pv.setPackageBits(packageBits); // associate the entities
                entityManager.flush(); // may not be necessary

                if (pk.getContentSource().getDownloadMode() == DownloadMode.DATABASE) {
                    conn = dataSource.getConnection();
                    // The blob has been initialized to EMPTY_BLOB already by createPackageBits...
                    // we need to lock the row which will be updated so we are using FOR UPDATE
                    ps = conn.prepareStatement("SELECT BITS FROM " + PackageBits.TABLE_NAME
                        + " WHERE ID = ? FOR UPDATE");
                    ps.setInt(1, packageBits.getId());
                    ResultSet rs = ps.executeQuery();
                    try {
                        while (rs.next()) {
                            //We can not create a blob directly because BlobImpl from Hibernate is not acceptable
                            //for oracle and Connection.createBlob is not working on postgres.
                            //This blob will be not empty because we saved there a bytes from String("a").
                            Blob blb = rs.getBlob(1);

                            StreamUtil.copy(bitsStream, blb.setBinaryStream(1), true);
                            ps2 = conn.prepareStatement("UPDATE " + PackageBits.TABLE_NAME
                                + " SET bits = ? where id = ?");
                            ps2.setBlob(1, blb);
                            ps2.setInt(2, packageBits.getId());
                            if (ps2.execute()) {
                                throw new Exception("Did not download the package bits to the DB for ");
                            }
                            ps2.close();
                        }
View Full Code Here

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

     * classes to the Agent and Remote clients.
     *
     * @return
     */
    private PackageBits createPackageBits(boolean initialize) {
        PackageBits bits = null;
        PackageBitsBlob blob = null;

        // We have to work backwards to avoid constraint violations. PackageBits requires a PackageBitsBlob,
        // so create and persist that first, getting the ID
        blob = new PackageBitsBlob();
        if (initialize) {
            blob.setBits(PackageBits.EMPTY_BLOB.getBytes());
        }
        entityManager.persist(blob);

        // Now create the PackageBits entity and assign the Id and blob.  Note, do not persist the
        // entity, the row already exists. Just perform and flush the update.
        bits = new PackageBits();
        bits.setId(blob.getId());
        bits.setBlob(blob);
        entityManager.flush();

        // return the new PackageBits and associated PackageBitsBlob
        return bits;
    }
View Full Code Here

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

        PackageVersionContentSourcePK pk = pvcs.getPackageVersionContentSourcePK();
        int contentSourceId = pk.getContentSource().getId();
        int packageVersionId = pk.getPackageVersion().getId();
        String packageVersionLocation = pvcs.getLocation();

        PackageBits packageBits = null;

        try {

            Connection conn = null;
            PreparedStatement ps = null;
            PreparedStatement ps2 = null;
            try {
                packageBits = createPackageBits(pk.getContentSource().getDownloadMode() == DownloadMode.DATABASE);

                PackageVersion pv = entityManager.find(PackageVersion.class, packageVersionId);
                pv.setPackageBits(packageBits); // associate entities
                entityManager.flush(); // not sure this is necessary

                if (pk.getContentSource().getDownloadMode() == DownloadMode.DATABASE) {
                    packageBits = entityManager.find(PackageBits.class, packageBits.getId());

                    conn = dataSource.getConnection();
                    //we are loading the PackageBits saved in the previous step
                    //we need to lock the row which will be updated so we are using FOR UPDATE
                    ps = conn.prepareStatement("SELECT BITS FROM " + PackageBits.TABLE_NAME
                        + " WHERE ID = ? FOR UPDATE");
                    ps.setInt(1, packageBits.getId());
                    ResultSet rs = ps.executeQuery();
                    try {
                        while (rs.next()) {

                            //We can not create a blob directly because BlobImpl from Hibernate is not acceptable
                            //for oracle and Connection.createBlob is not working on postgres.
                            //This blob will be not empty because we saved there a bytes from String("a").
                            Blob blb = rs.getBlob(1);

                            StreamUtil.copy(bitsStream, blb.setBinaryStream(1), false);
                            bitsStream.close();
                            ps2 = conn.prepareStatement("UPDATE " + PackageBits.TABLE_NAME
                                + " SET bits = ? where id = ?");
                            ps2.setBlob(1, blb);
                            ps2.setInt(2, packageBits.getId());
                            if (ps2.execute()) {
                                throw new Exception("Did not download the package bits to the DB for ");
                            }
                            ps2.close();
                        }
View Full Code Here

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

                // This way, we start with a fresh tx timeout when downloading and this
                // won't affect the time we are in in this method's tx (I hope that's how it works).
                // This is because this method itself may take a long time to send the data to the output stream
                // and we don't want out tx timing out due to the time it takes downloading.
                InputStream stream = preloadPackageBits(pvcs);
                PackageBits bits = null;
                bits = preparePackageBits(subjectManager.getOverlord(), stream, pvcs);
            } catch (Exception e) {
                return false;
            }
        }
View Full Code Here

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

            // Make it a true EJB call so we suspend our tx and get a new tx.
            // This way, we start with a fresh tx timeout when downloading and this
            // won't affect the time we are in in this method's tx (I hope that's how it works).
            // This is because this method itself may take a long time to send the data to the output stream
            // and we don't want out tx timing out due to the time it takes downloading.
            PackageBits bits = null;
            bits = contentSourceManager.downloadPackageBits(subjectManager.getOverlord(), pvcs);

            if (bits != null) {
                // rerun the query just to make sure we really downloaded it successfully
                query.setParameter("id", pvcs.getPackageVersionContentSourcePK().getPackageVersion().getId());
View Full Code Here

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

                + "] does not have permission to obtain package content for installed package id ["
                + installedPackageId + "] for resource ID [" + resourceId + "]");
        }
        try {
            InstalledPackage installedPackage = entityManager.find(InstalledPackage.class, installedPackageId);
            PackageBits bits = installedPackage.getPackageVersion().getPackageBits();
            if (bits == null || bits.getBlob().getBits().length == 0) {
                long start = System.currentTimeMillis();
                retrieveBitsFromResource(user, resourceId, installedPackageId);

                bits = installedPackage.getPackageVersion().getPackageBits();
                while ((bits == null || bits.getBlob().getBits() == null)
                    && (System.currentTimeMillis() - start < 30000)) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                    }
                    entityManager.clear();
                    installedPackage = entityManager.find(InstalledPackage.class, installedPackageId);
                    bits = installedPackage.getPackageVersion().getPackageBits();
                }

                if (bits == null) {
                    throw new RuntimeException("Unable to retrieve package bits for resource: " + resourceId
                        + " and package: " + installedPackageId + " before timeout.");
                }

            }

            return bits.getBlob().getBits();
        } catch (Exception e) {
            throw new RuntimeException("Unable to retrieve package bits for resource: " + resourceId + " and package: "
                + installedPackageId + ".", e);

        }
View Full Code Here

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

            try {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Saving content for response: " + response);
                }

                PackageBits packageBits = initializePackageBits(null);

                // Could use the following, but only on jdk6 as builds
                // @since 1.6
                // void setBinaryStream(int parameterIndex, java.io.InputStream x) throws SQLException;

                Long length = packageVersion.getFileSize();
                if (length == null) {
                    File tmpFile = File.createTempFile("rhq", ".stream");
                    FileOutputStream fos = new FileOutputStream(tmpFile);
                    length = StreamUtil.copy(bitStream, fos, true);

                    bitStream = new FileInputStream(tmpFile);
                }
                Connection conn = null;
                PreparedStatement ps = null;

                try {
                    PackageBits bits = entityManager.find(PackageBits.class, packageBits.getId());
                    String pkgName = "(set packageName)";
                    if ((packageVersion != null) && (packageVersion.getGeneralPackage() != null)) {
                        //update it to whatever package name is if we can get to it.
                        pkgName = packageVersion.getGeneralPackage().getName();
                    }
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.