Package com.cloud.utils.db

Examples of com.cloud.utils.db.TransactionLegacy$StackElement


        OrderedPair<SHostVO, String> host_storagelocation_pair = getBucketStorageHost(bucket);

        S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(host_storagelocation_pair.getFirst());
        String itemFileName = object_objectitem_pair.getSecond().getStoredPath();
        InputStream is = null;
        TransactionLegacy txn = null;
        try {
            // explicit transaction control to avoid holding transaction during file-copy process

            txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
            txn.start();
            is = request.getDataInputStream();
            String md5Checksum = bucketAdapter.saveObject(is, host_storagelocation_pair.getSecond(), bucket.getName(), itemFileName);
            response.setETag(md5Checksum);
            response.setLastModified(DateHelper.toCalendar(object_objectitem_pair.getSecond().getLastModifiedTime()));
            response.setVersion(object_objectitem_pair.getSecond().getVersion());

            //SObjectItemDaoImpl itemDao = new SObjectItemDaoImpl();
            SObjectItemVO item = itemDao.findById(object_objectitem_pair.getSecond().getId());
            item.setMd5(md5Checksum);
            item.setStoredSize(contentLength);
            itemDao.update(item.getId(), item);
            txn.commit();
        } catch (IOException e) {
            logger.error("PutObjectInline failed due to " + e.getMessage(), e);
        } catch (OutOfStorageException e) {
            logger.error("PutObjectInline failed due to " + e.getMessage(), e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    logger.error("PutObjectInline unable to close stream from data handler.", e);
                }
            }
            txn.close();
        }

        return response;
    }
View Full Code Here


     * As with all REST calls HTTPS should be used to ensure their security.
     */
    private void setUserKeys(HttpServletRequest request, HttpServletResponse response) {
        String[] accessKey = null;
        String[] secretKey = null;
        TransactionLegacy txn = null;
        try {
            // -> all these parameters are required
            accessKey = request.getParameterValues("accesskey");
            if (null == accessKey || 0 == accessKey.length) {
                response.sendError(530, "Missing accesskey parameter");
                return;
            }

            secretKey = request.getParameterValues("secretkey");
            if (null == secretKey || 0 == secretKey.length) {
                response.sendError(530, "Missing secretkey parameter");
                return;
            }
        } catch (Exception e) {
            logger.error("SetUserKeys exception " + e.getMessage(), e);
            response.setStatus(500);
            endResponse(response, "SetUserKeys exception " + e.getMessage());
            return;
        }
        try {
            txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
            txn.start();
            // -> use the keys to see if the account actually exists
            ServiceProvider.getInstance().getEC2Engine().validateAccount(accessKey[0], secretKey[0]);
            UserCredentialsVO user = new UserCredentialsVO(accessKey[0], secretKey[0]);
            ucDao.persist(user);
            txn.commit();
        } catch (Exception e) {
            logger.error("SetUserKeys " + e.getMessage(), e);
            response.setStatus(401);
            endResponse(response, e.toString());
            txn.close();
            return;
        }
        response.setStatus(200);
        endResponse(response, "User keys set successfully");
    }
View Full Code Here

        OrderedPair<SHostVO, String> host_storagelocation_pair = getBucketStorageHost(bucket);

        S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(host_storagelocation_pair.getFirst());
        String itemFileName = object_objectitem_pair.getSecond().getStoredPath();
        InputStream is = null;
        TransactionLegacy txn = null;
        try {
            // explicit transaction control to avoid holding transaction during file-copy process

            txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
            txn.start();

            is = request.getInputStream();
            String md5Checksum = bucketAdapter.saveObject(is, host_storagelocation_pair.getSecond(), bucket.getName(), itemFileName);
            response.setETag(md5Checksum);
            response.setLastModified(DateHelper.toCalendar(object_objectitem_pair.getSecond().getLastModifiedTime()));

            SObjectItemVO item = itemDao.findById(object_objectitem_pair.getSecond().getId());
            item.setMd5(md5Checksum);
            item.setStoredSize(contentLength);
            itemDao.update(item.getId(), item);
            txn.commit();

        } catch (OutOfStorageException e) {
            logger.error("PutObject failed due to " + e.getMessage(), e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    logger.error("Unable to close stream from data handler.", e);
                }
            }
            txn.close();
        }

        return response;
    }
View Full Code Here

     *
     * A user can call this REST function any number of times, on each call the X509 certificate
     * simply over writes any previously stored value.
     */
    private void setCertificate(HttpServletRequest request, HttpServletResponse response) throws Exception {
        TransactionLegacy txn = null;
        try {
            // [A] Pull the cert and cloud AccessKey from the request
            String[] certificate = request.getParameterValues("cert");
            if (null == certificate || 0 == certificate.length) {
                response.sendError(530, "Missing cert parameter");
                return;
            }
            // logger.debug( "SetCertificate cert: [" + certificate[0] + "]" );

            String[] accessKey = request.getParameterValues("AWSAccessKeyId");
            if (null == accessKey || 0 == accessKey.length) {
                response.sendError(530, "Missing AWSAccessKeyId parameter");
                return;
            }

            // [B] Open our keystore
            FileInputStream fsIn = new FileInputStream(pathToKeystore);
            KeyStore certStore = KeyStore.getInstance("JKS");
            certStore.load(fsIn, keystorePassword.toCharArray());

            // -> use the Cloud API key to save the cert in the keystore
            // -> write the cert into the keystore on disk
            Certificate userCert = null;
            CertificateFactory cf = CertificateFactory.getInstance("X.509");

            ByteArrayInputStream bs = new ByteArrayInputStream(certificate[0].getBytes());
            while (bs.available() > 0)
                userCert = cf.generateCertificate(bs);
            certStore.setCertificateEntry(accessKey[0], userCert);

            FileOutputStream fsOut = new FileOutputStream(pathToKeystore);
            certStore.store(fsOut, keystorePassword.toCharArray());

            // [C] Associate the cert's uniqueId with the Cloud API keys
            String uniqueId = AuthenticationUtils.X509CertUniqueId(userCert);
            logger.debug("SetCertificate, uniqueId: " + uniqueId);
            txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
            txn.start();
            UserCredentialsVO user = ucDao.getByAccessKey(accessKey[0]);
            user.setCertUniqueId(uniqueId);
            ucDao.update(user.getId(), user);
            response.setStatus(200);
            endResponse(response, "User certificate set successfully");
            txn.commit();

        } catch (NoSuchObjectException e) {
            logger.error("SetCertificate exception " + e.getMessage(), e);
            response.sendError(404, "SetCertificate exception " + e.getMessage());

        } catch (Exception e) {
            logger.error("SetCertificate exception " + e.getMessage(), e);
            response.sendError(500, "SetCertificate exception " + e.getMessage());
        } finally {
            txn.close();
        }

    }
View Full Code Here

        S3PolicyContext context = new S3PolicyContext(PolicyActions.PutObject, bucket.getName());
        context.setKeyName(nameKey);
        context.setEvalParam(ConditionKeys.Acl, cannedAccessPolicy);

        verifyAccess(context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE)// TODO - check this validates plain POSTs
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
        txn.start();

        // [B] If versioning is off them we over write a null object item
        SObjectVO object = objectDao.getByNameKey(bucket, nameKey);
        if (object != null) {
            // -> if versioning is on create new object items
            if (SBucket.VERSIONING_ENABLED == versioningStatus) {

                versionSeq = object.getNextSequence();
                object.setNextSequence(versionSeq + 1);
                objectDao.update(object.getId(), object);

                item = new SObjectItemVO();
                item.setTheObject(object);
                object.getItems().add(item);
                item.setsObjectID(object.getId());
                item.setVersion(String.valueOf(versionSeq));
                Date ts = DateHelper.currentGMTTime();
                item.setCreateTime(ts);
                item.setLastAccessTime(ts);
                item.setLastModifiedTime(ts);
                item = itemDao.persist(item);
                txn.commit();
                //session.save(item);
            } else {    // -> find an object item with a null version, can be null
                     //    if bucket started out with versioning enabled and was then suspended
                item = itemDao.getByObjectIdNullVersion(object.getId());
                if (item == null) {
                    item = new SObjectItemVO();
                    item.setTheObject(object);
                    item.setsObjectID(object.getId());
                    object.getItems().add(item);
                    Date ts = DateHelper.currentGMTTime();
                    item.setCreateTime(ts);
                    item.setLastAccessTime(ts);
                    item.setLastModifiedTime(ts);
                    item = itemDao.persist(item);
                    txn.commit();
                }
            }
        } else {
            TransactionLegacy txn1 = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
            txn1.start();
            // -> there is no object nor an object item
            object = new SObjectVO();
            object.setBucket(bucket);
            object.setNameKey(nameKey);
            object.setNextSequence(2);
View Full Code Here

                break;
            case DENY:
                response.setStatus(403);
                return;
        }
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
        // [B] Place the policy into the database over writting an existing policy
        try {
            // -> first make sure that the policy is valid by parsing it
            PolicyParser parser = new PolicyParser();
            S3BucketPolicy sbp = parser.parse(policy, bucketName);
            bPolicyDao.deletePolicy(bucketName);

            if (null != policy && !policy.isEmpty()) {
                BucketPolicyVO bpolicy = new BucketPolicyVO(bucketName, client, policy);
                bpolicy = bPolicyDao.persist(bpolicy);
                //policyDao.addPolicy( bucketName, client, policy );
            }

            if (null != sbp)
                ServiceProvider.getInstance().setBucketPolicy(bucketName, sbp);
            response.setStatus(200);
            txn.commit();
            txn.close();
        } catch (PermissionDeniedException e) {
            logger.error("Put Bucket Policy failed due to " + e.getMessage(), e);
            throw e;
        } catch (ParseException e) {
            logger.error("Put Bucket Policy failed due to " + e.getMessage(), e);
View Full Code Here

     * including: Signature, Timestamp, Expires, etc.   The signature is calculated using the
     * Cloud.com account holder's API access and secret keys and the Amazon defined EC2 signature
     * algorithm.
     */
    private void deleteCertificate(HttpServletRequest request, HttpServletResponse response) throws Exception {
        TransactionLegacy txn = null;
        try {
            String[] accessKey = request.getParameterValues("AWSAccessKeyId");
            if (null == accessKey || 0 == accessKey.length) {
                response.sendError(530, "Missing AWSAccessKeyId parameter");
                return;
            }

            // -> delete the specified entry and save back to disk
            FileInputStream fsIn = new FileInputStream(pathToKeystore);
            KeyStore certStore = KeyStore.getInstance("JKS");
            certStore.load(fsIn, keystorePassword.toCharArray());

            if (certStore.containsAlias(accessKey[0])) {
                certStore.deleteEntry(accessKey[0]);
                FileOutputStream fsOut = new FileOutputStream(pathToKeystore);
                certStore.store(fsOut, keystorePassword.toCharArray());

                // -> dis-associate the cert's uniqueId with the Cloud API keys
                /*                  UserCredentialsDao credentialDao = new UserCredentialsDao();
                 credentialDao.setCertificateId( accessKey[0], null );

                 */txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
                UserCredentialsVO user = ucDao.getByAccessKey(accessKey[0]);
                user.setCertUniqueId(null);
                ucDao.update(user.getId(), user);
                response.setStatus(200);
                endResponse(response, "User certificate deleted successfully");
                txn.commit();
            } else
                response.setStatus(404);

        } catch (NoSuchObjectException e) {
            logger.error("SetCertificate exception " + e.getMessage(), e);
            response.sendError(404, "SetCertificate exception " + e.getMessage());

        } catch (Exception e) {
            logger.error("DeleteCertificate exception " + e.getMessage(), e);
            response.sendError(500, "DeleteCertificate exception " + e.getMessage());
        } finally {
            txn.close();
        }
    }
View Full Code Here

    public List<VmDiskStatisticsVO> listActiveAndRecentlyDeleted(Date minRemovedDate, int startIndex, int limit) {
        List<VmDiskStatisticsVO> vmDiskStats = new ArrayList<VmDiskStatisticsVO>();
        if (minRemovedDate == null)
            return vmDiskStats;

        TransactionLegacy txn = TransactionLegacy.currentTxn();
        try {
            String sql = ACTIVE_AND_RECENTLY_DELETED_SEARCH + " LIMIT " + startIndex + "," + limit;
            PreparedStatement pstmt = null;
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), minRemovedDate));
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                vmDiskStats.add(toEntityBean(rs, false));
            }
View Full Code Here

    @Override
    public List<VmDiskStatisticsVO> listUpdatedStats() {
        List<VmDiskStatisticsVO> vmDiskStats = new ArrayList<VmDiskStatisticsVO>();

        TransactionLegacy txn = TransactionLegacy.currentTxn();
        try {
            PreparedStatement pstmt = null;
            pstmt = txn.prepareAutoCloseStatement(UPDATED_VM_NETWORK_STATS_SEARCH);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                vmDiskStats.add(toEntityBean(rs, false));
            }
        } catch (Exception ex) {
View Full Code Here

    public List<UserStatisticsVO> listActiveAndRecentlyDeleted(Date minRemovedDate, int startIndex, int limit) {
        List<UserStatisticsVO> userStats = new ArrayList<UserStatisticsVO>();
        if (minRemovedDate == null)
            return userStats;

        TransactionLegacy txn = TransactionLegacy.currentTxn();
        try {
            String sql = ACTIVE_AND_RECENTLY_DELETED_SEARCH + " LIMIT " + startIndex + "," + limit;
            PreparedStatement pstmt = null;
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), minRemovedDate));
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                userStats.add(toEntityBean(rs, false));
            }
View Full Code Here

TOP

Related Classes of com.cloud.utils.db.TransactionLegacy$StackElement

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.