Package com.cloud.utils.db

Examples of com.cloud.utils.db.TransactionLegacy


    @Override
    @DB
    public StorageNetworkIpAddressVO takeIpAddress(long rangeId) {
        SearchCriteria<StorageNetworkIpAddressVO> sc = untakenIp.create();
        sc.setParameters("rangeId", rangeId);
        TransactionLegacy txn = TransactionLegacy.currentTxn();
        txn.start();
        StorageNetworkIpAddressVO ip = lockOneRandomRow(sc, true);
        if (ip == null) {
            txn.rollback();
            return null;
        }
        ip.setTakenAt(new Date());
        update(ip.getId(), ip);
        txn.commit();
        return ip;
    }
View Full Code Here


        return listBy(sc);
    }

    @Override
    public boolean remove(Long id) {
        TransactionLegacy txn = TransactionLegacy.currentTxn();
        txn.start();
        ClusterVSMMapVO cluster = createForUpdate();
        //cluster.setClusterId(null);
        //cluster.setVsmId(null);

        update(id, cluster);

        boolean result = super.remove(id);
        txn.commit();
        return result;
    }
View Full Code Here

        }
    }

    @Override
    public void persist(long clusterId, Map<String, String> details) {
        TransactionLegacy txn = TransactionLegacy.currentTxn();
        txn.start();
        SearchCriteria<ClusterDetailsVO> sc = ClusterSearch.create();
        sc.setParameters("clusterId", clusterId);
        expunge(sc);

        for (Map.Entry<String, String> detail : details.entrySet()) {
            String value = detail.getValue();
            if ("password".equals(detail.getKey())) {
                value = DBEncryptionUtil.encrypt(value);
            }
            ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), value);
            persist(vo);
        }
        txn.commit();
    }
View Full Code Here

        txn.commit();
    }

    @Override
    public void persist(long clusterId, String name, String value) {
        TransactionLegacy txn = TransactionLegacy.currentTxn();
        txn.start();
        SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
        sc.setParameters("clusterId", clusterId);
        sc.setParameters("name", name);
        expunge(sc);

        ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, name, value);
        persist(vo);
        txn.commit();
    }
View Full Code Here

    // -> cache Bucket Policies here so we don't have to load from db on every access
    private final Map<String, S3BucketPolicy> policyMap = new HashMap<String, S3BucketPolicy>();

    protected ServiceProvider() throws IOException {
        // register service implementation object
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
        txn.close();
    }
View Full Code Here

        return properties;
    }

    public UserInfo getUserInfo(String accessKey) {
        UserInfo info = new UserInfo();
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
        try {
            txn.start();
            UserCredentialsVO cloudKeys = ucDao.getByAccessKey(accessKey);
            if (null == cloudKeys) {
                logger.debug(accessKey + " is not defined in the S3 service - call SetUserKeys");
                return null;
            } else {
                info.setAccessKey(accessKey);
                info.setSecretKey(cloudKeys.getSecretKey());
                info.setCanonicalUserId(accessKey);
                info.setDescription("S3 REST request");
                return info;
            }
        } finally {
            txn.commit();
        }
    }
View Full Code Here

            }
        }

        multipartDir = properties.getProperty("storage.multipartDir");

        TransactionLegacy txn1 = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
        timer.schedule(getHeartbeatTask(), HEARTBEAT_INTERVAL, HEARTBEAT_INTERVAL);
        txn1.close();

        if (logger.isInfoEnabled())
            logger.info("ServiceProvider initialized");
    }
View Full Code Here

    public S3CreateBucketResponse handleRequest(S3CreateBucketRequest request) {
        S3CreateBucketResponse response = new S3CreateBucketResponse();
        String cannedAccessPolicy = request.getCannedAccess();
        String bucketName = request.getBucketName();
        response.setBucketName(bucketName);
        TransactionLegacy txn = null;
        verifyBucketName(bucketName, false);

        S3PolicyContext context = new S3PolicyContext(PolicyActions.CreateBucket, bucketName);
        context.setEvalParam(ConditionKeys.Acl, cannedAccessPolicy);
        if (PolicyAccess.DENY == verifyPolicy(context))
            throw new PermissionDeniedException("Access Denied - bucket policy DENY result");
        OrderedPair<SHostVO, String> shost_storagelocation_pair = null;
        boolean success = false;
        try {
            txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);

            if (bucketDao.getByName(request.getBucketName()) != null)
                throw new ObjectAlreadyExistsException("Bucket already exists");

            shost_storagelocation_pair = allocBucketStorageHost(request.getBucketName(), null);
            SBucketVO sbucket =
                new SBucketVO(request.getBucketName(), DateHelper.currentGMTTime(), UserContext.current().getCanonicalUserId(), shost_storagelocation_pair.getFirst());

            shost_storagelocation_pair.getFirst().getBuckets().add(sbucket);
            // bucketDao.save(sbucket);
            sbucket = bucketDao.persist(sbucket);
            S3AccessControlList acl = request.getAcl();

            if (null != cannedAccessPolicy)
                setCannedAccessControls(cannedAccessPolicy, "SBucket", sbucket.getId(), sbucket);
            else if (null != acl)
                aclDao.save("SBucket", sbucket.getId(), acl);
            else
                setSingleAcl("SBucket", sbucket.getId(), SAcl.PERMISSION_FULL);

            success = true;
        } finally {
            if (!success && shost_storagelocation_pair != null) {
                S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(shost_storagelocation_pair.getFirst());
                bucketAdapter.deleteContainer(shost_storagelocation_pair.getSecond(), request.getBucketName());
            }
            txn.rollback();
            txn.close();
        }
        return response;
    }
View Full Code Here

        S3Response response = new S3Response();
        //
        String bucketName = request.getBucketName();
        SBucketVO sbucket = bucketDao.getByName(bucketName);

        TransactionLegacy txn = null;
        if (sbucket != null) {
            txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
            txn.start();
            S3PolicyContext context = new S3PolicyContext(PolicyActions.DeleteBucket, bucketName);
            switch (verifyPolicy(context)) {
                case ALLOW:
                    // The bucket policy can give users permission to delete a
                    // bucket whereas ACLs cannot
                    break;

                case DENY:
                    throw new PermissionDeniedException("Access Denied - bucket policy DENY result");

                case DEFAULT_DENY:
                default:
                    // Irrespective of what the ACLs say, only the owner can delete
                    // a bucket
                    String client = UserContext.current().getCanonicalUserId();
                    if (!client.equals(sbucket.getOwnerCanonicalId())) {
                        throw new PermissionDeniedException("Access Denied - only the owner can delete a bucket");
                    }
                    break;
            }

            // Delete the file from its storage location
            OrderedPair<SHostVO, String> host_storagelocation_pair = getBucketStorageHost(sbucket);
            S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(host_storagelocation_pair.getFirst());
            bucketAdapter.deleteContainer(host_storagelocation_pair.getSecond(), request.getBucketName());

            // Cascade-deleting can delete related SObject/SObjectItem objects, but not SAcl, SMeta and policy objects.
            // To delete SMeta & SAcl objects:
            // (1)Get all the objects in the bucket,
            // (2)then all the items in each object,
            // (3) then all meta & acl data for each item
            Set<SObjectVO> objectsInBucket = sbucket.getObjectsInBucket();
            Iterator<SObjectVO> it = objectsInBucket.iterator();
            while (it.hasNext()) {
                SObjectVO oneObject = it.next();
                Set<SObjectItemVO> itemsInObject = oneObject.getItems();
                Iterator<SObjectItemVO> is = itemsInObject.iterator();
                while (is.hasNext()) {
                    SObjectItemVO oneItem = is.next();
                    deleteMetaData(oneItem.getId());
                    deleteObjectAcls("SObjectItem", oneItem.getId());
                }
            }

            // Delete all the policy state associated with the bucket
            try {
                ServiceProvider.getInstance().deleteBucketPolicy(bucketName);
                bPolicyDao.deletePolicy(bucketName);
            } catch (Exception e) {
                logger.error("When deleting a bucket we must try to delete its policy: ", e);
            }

            deleteBucketAcls(sbucket.getId());
            bucketDao.remove(sbucket.getId());

            response.setResultCode(204);
            response.setResultDescription("OK");

            txn.close();
        } else {
            response.setResultCode(404);
            response.setResultDescription("Bucket does not exist");
        }
        return response;
View Full Code Here

        httpResp.setContentType("text/xml; charset=UTF-8");
        String version = object_objectitem_pair.getSecond().getVersion();
        if (null != version)
            httpResp.addHeader("x-amz-version-id", version);
        httpResp.flushBuffer();
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
        // [C] Re-assemble the object from its uploaded file parts
        try {
            // explicit transaction control to avoid holding transaction during
            // long file concatenation process
            txn.start();
            OrderedPair<String, Long> result =
                bucketAdapter.concatentateObjects(host_storagelocation_pair.getSecond(), bucket.getName(), itemFileName, ServiceProvider.getInstance().getMultipartDir(),
                    parts, outputStream);

            response.setETag(result.getFirst());
            response.setLastModified(DateHelper.toCalendar(object_objectitem_pair.getSecond().getLastModifiedTime()));
            SObjectItemVO item = itemDao.findById(object_objectitem_pair.getSecond().getId());
            item.setMd5(result.getFirst());
            item.setStoredSize(result.getSecond().longValue());
            itemDao.update(item.getId(), item);
            response.setResultCode(200);
        } catch (Exception e) {
            logger.error("completeMultipartUpload failed due to " + e.getMessage(), e);
            txn.close();
        }
        return response;
    }
View Full Code Here

TOP

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

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.