~ubuntu-branches/ubuntu/natty/eucalyptus/natty-updates

« back to all changes in this revision

Viewing changes to clc/modules/walrus/src/main/java/edu/ucsb/eucalyptus/cloud/ws/WalrusManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-12-17 18:22:02 UTC
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: james.westby@ubuntu.com-20091217182202-0v2v09ry3cxrvh84
Tags: upstream-1.6.2~bzr1103
ImportĀ upstreamĀ versionĀ 1.6.2~bzr1103

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
import java.io.File;
68
68
import java.io.IOException;
69
69
import java.net.InetAddress;
 
70
import java.net.URI;
 
71
import java.net.URISyntaxException;
70
72
import java.net.URL;
71
73
import java.security.MessageDigest;
72
74
import java.util.ArrayList;
99
101
import edu.ucsb.eucalyptus.cloud.BucketNotEmptyException;
100
102
import edu.ucsb.eucalyptus.cloud.EntityTooLargeException;
101
103
import edu.ucsb.eucalyptus.cloud.InvalidRangeException;
 
104
import edu.ucsb.eucalyptus.cloud.InvalidTargetBucketForLoggingException;
102
105
import edu.ucsb.eucalyptus.cloud.NoSuchBucketException;
103
106
import edu.ucsb.eucalyptus.cloud.NoSuchEntityException;
104
107
import edu.ucsb.eucalyptus.cloud.NotModifiedException;
113
116
import edu.ucsb.eucalyptus.cloud.entities.WalrusSnapshotInfo;
114
117
import edu.ucsb.eucalyptus.msgs.AccessControlListType;
115
118
import edu.ucsb.eucalyptus.msgs.AccessControlPolicyType;
 
119
import edu.ucsb.eucalyptus.msgs.AddObjectResponseType;
 
120
import edu.ucsb.eucalyptus.msgs.AddObjectType;
116
121
import edu.ucsb.eucalyptus.msgs.BucketListEntry;
117
122
import edu.ucsb.eucalyptus.msgs.CanonicalUserType;
118
123
import edu.ucsb.eucalyptus.msgs.CopyObjectResponseType;
127
132
import edu.ucsb.eucalyptus.msgs.GetBucketAccessControlPolicyType;
128
133
import edu.ucsb.eucalyptus.msgs.GetBucketLocationResponseType;
129
134
import edu.ucsb.eucalyptus.msgs.GetBucketLocationType;
 
135
import edu.ucsb.eucalyptus.msgs.GetBucketLoggingStatusType;
 
136
import edu.ucsb.eucalyptus.msgs.GetBucketLoggingStatusResponseType;
130
137
import edu.ucsb.eucalyptus.msgs.GetObjectAccessControlPolicyResponseType;
131
138
import edu.ucsb.eucalyptus.msgs.GetObjectAccessControlPolicyType;
132
139
import edu.ucsb.eucalyptus.msgs.GetObjectExtendedResponseType;
135
142
import edu.ucsb.eucalyptus.msgs.GetObjectType;
136
143
import edu.ucsb.eucalyptus.msgs.Grant;
137
144
import edu.ucsb.eucalyptus.msgs.Grantee;
 
145
import edu.ucsb.eucalyptus.msgs.Group;
138
146
import edu.ucsb.eucalyptus.msgs.ListAllMyBucketsList;
139
147
import edu.ucsb.eucalyptus.msgs.ListAllMyBucketsResponseType;
140
148
import edu.ucsb.eucalyptus.msgs.ListAllMyBucketsType;
152
160
import edu.ucsb.eucalyptus.msgs.RemoveARecordType;
153
161
import edu.ucsb.eucalyptus.msgs.SetBucketAccessControlPolicyResponseType;
154
162
import edu.ucsb.eucalyptus.msgs.SetBucketAccessControlPolicyType;
 
163
import edu.ucsb.eucalyptus.msgs.SetBucketLoggingStatusResponseType;
 
164
import edu.ucsb.eucalyptus.msgs.SetBucketLoggingStatusType;
155
165
import edu.ucsb.eucalyptus.msgs.SetObjectAccessControlPolicyResponseType;
156
166
import edu.ucsb.eucalyptus.msgs.SetObjectAccessControlPolicyType;
157
167
import edu.ucsb.eucalyptus.msgs.SetRESTBucketAccessControlPolicyResponseType;
159
169
import edu.ucsb.eucalyptus.msgs.SetRESTObjectAccessControlPolicyResponseType;
160
170
import edu.ucsb.eucalyptus.msgs.SetRESTObjectAccessControlPolicyType;
161
171
import edu.ucsb.eucalyptus.msgs.Status;
 
172
import edu.ucsb.eucalyptus.msgs.TargetGrants;
162
173
import edu.ucsb.eucalyptus.msgs.UpdateARecordType;
163
174
import edu.ucsb.eucalyptus.storage.StorageManager;
164
175
import edu.ucsb.eucalyptus.storage.fs.FileIO;
166
177
import edu.ucsb.eucalyptus.util.WalrusDataMessage;
167
178
import edu.ucsb.eucalyptus.util.WalrusDataMessenger;
168
179
import edu.ucsb.eucalyptus.util.WalrusMonitor;
 
180
import edu.ucsb.eucalyptus.cloud.BucketLogData;
169
181
 
170
182
public class WalrusManager {
171
183
        private static Logger LOG = Logger.getLogger( WalrusManager.class );
172
184
 
173
185
        private StorageManager storageManager;
174
186
        private WalrusImageManager walrusImageManager;
175
 
        private static WalrusStatistics walrusStatistics = new WalrusStatistics();
 
187
        private static WalrusStatistics walrusStatistics = null;
 
188
        public static void deferedInitializer() {
 
189
                walrusStatistics = new WalrusStatistics();
 
190
        }
176
191
 
177
192
        public WalrusManager(StorageManager storageManager, WalrusImageManager walrusImageManager) {
178
193
                this.storageManager = storageManager;
248
263
                return reply;
249
264
        }
250
265
 
251
 
 
252
 
        private void makeBucket(String userId, String bucketName, String locationConstraint, AccessControlListType accessControlList, boolean isAdministrator) throws EucalyptusCloudException {
 
266
        public CreateBucketResponseType createBucket(CreateBucketType request) throws EucalyptusCloudException {
 
267
                CreateBucketResponseType reply = (CreateBucketResponseType) request.getReply();
 
268
                String userId = request.getUserId();
 
269
 
 
270
                String bucketName = request.getBucket();
 
271
                String locationConstraint = request.getLocationConstraint();
 
272
 
253
273
                if(userId == null) {
254
274
                        throw new AccessDeniedException("Bucket", bucketName);
255
275
                }
256
276
 
 
277
                AccessControlListType accessControlList = request.getAccessControlList();
257
278
                if (accessControlList == null) {
258
279
                        accessControlList = new AccessControlListType();
259
280
                }
260
281
 
261
282
                EntityWrapper<BucketInfo> db = WalrusControl.getEntityWrapper();
262
283
 
263
 
                if(WalrusProperties.shouldEnforceUsageLimits && !isAdministrator) {
 
284
                if(WalrusProperties.shouldEnforceUsageLimits && !request.isAdministrator()) {
264
285
                        BucketInfo searchBucket = new BucketInfo();
265
286
                        searchBucket.setOwnerId(userId);
266
287
                        List<BucketInfo> bucketList = db.query(searchBucket);
289
310
                        bucket.addGrants(userId, grantInfos, accessControlList);
290
311
                        bucket.setGrants(grantInfos);
291
312
                        bucket.setBucketSize(0L);
 
313
                        bucket.setLoggingEnabled(false);
292
314
                        bucket.setHidden(false);
293
315
                        if(locationConstraint != null)
294
316
                                bucket.setLocation(locationConstraint);
295
317
                        else
296
318
                                bucket.setLocation("US");
297
319
                        db.add(bucket);
 
320
                        //call the storage manager to save the bucket to disk
 
321
                        try {
 
322
                                storageManager.createBucket(bucketName);
 
323
                                if(WalrusProperties.trackUsageStatistics) 
 
324
                                        walrusStatistics.incrementBucketCount();
 
325
                        } catch (IOException ex) {
 
326
                                LOG.error(ex);
 
327
                                db.rollback();
 
328
                                throw new EucalyptusCloudException("Unable to create bucket: " + bucketName);
 
329
                        }
298
330
                }
299
331
                db.commit();
300
 
        }
301
 
 
302
 
        public CreateBucketResponseType createBucket(CreateBucketType request) throws EucalyptusCloudException {
303
 
                CreateBucketResponseType reply = (CreateBucketResponseType) request.getReply();
304
 
                String userId = request.getUserId();
305
 
 
306
 
                String bucketName = request.getBucket();
307
 
                String locationConstraint = request.getLocationConstraint();
308
 
 
309
 
                if(userId == null) {
310
 
                        throw new AccessDeniedException("Bucket", bucketName);
311
 
                }
312
 
 
313
 
                AccessControlListType accessControlList = request.getAccessControlList();
314
 
                if (accessControlList == null) {
315
 
                        accessControlList = new AccessControlListType();
316
 
                }
317
 
 
318
 
                makeBucket(userId, bucketName, locationConstraint, accessControlList, request.isAdministrator());
319
 
 
320
 
                //call the storage manager to save the bucket to disk
321
 
                try {
322
 
                        storageManager.createBucket(bucketName);
323
 
                        if(WalrusProperties.trackUsageStatistics) 
324
 
                                walrusStatistics.incrementBucketCount();
325
 
                } catch (IOException ex) {
326
 
                        LOG.error(ex);
327
 
                        throw new EucalyptusCloudException(bucketName);
328
 
                }
329
332
 
330
333
                if(WalrusProperties.enableVirtualHosting) {
331
334
                        UpdateARecordType updateARecord = new UpdateARecordType();
332
335
                        updateARecord.setUserId(userId);
333
 
                        String address = WalrusProperties.WALRUS_IP;
 
336
                        URI walrusUri;
 
337
                        String address = null;
 
338
                        try {
 
339
                                walrusUri = new URI(EucalyptusProperties.getWalrusUrl());
 
340
                                address = walrusUri.getHost();
 
341
                        } catch (URISyntaxException e) {
 
342
                                throw new EucalyptusCloudException("Could not get Walrus URL");
 
343
                        }
334
344
                        String zone = WalrusProperties.WALRUS_SUBDOMAIN + ".";
335
345
                        updateARecord.setAddress(address);
336
346
                        updateARecord.setName(bucketName + "." + zone);
356
366
                BucketInfo searchBucket = new BucketInfo(bucketName);
357
367
                List<BucketInfo> bucketList = db.query(searchBucket);
358
368
 
359
 
 
360
369
                if(bucketList.size() > 0) {
361
370
                        BucketInfo bucketFound = bucketList.get(0);
 
371
                        BucketLogData logData = bucketFound.getLoggingEnabled() ? request.getLogData() : null;
362
372
                        if (bucketFound.canWrite(userId)) {
363
373
                                EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
364
374
                                ObjectInfo searchObject = new ObjectInfo();
405
415
                                        status.setCode(204);
406
416
                                        status.setDescription("No Content");
407
417
                                        reply.setStatus(status);
 
418
                                        if(logData != null) {
 
419
                                                updateLogData(bucketFound, logData);
 
420
                                                reply.setLogData(logData);
 
421
                                        }
408
422
                                } else {
409
423
                                        db.rollback();
410
 
                                        throw new BucketNotEmptyException(bucketName);
 
424
                                        throw new BucketNotEmptyException(bucketName, logData);
411
425
                                }
412
426
                        } else {
413
427
                                db.rollback();
414
 
                                throw new AccessDeniedException("Bucket", bucketName);
 
428
                                throw new AccessDeniedException("Bucket", bucketName, logData);
415
429
                        }
416
430
                } else {
417
431
                        db.rollback();
434
448
                List<BucketInfo> bucketList = db.query(bucketInfo);
435
449
 
436
450
                AccessControlListType accessControlList = new AccessControlListType();
 
451
                BucketLogData logData;
437
452
 
438
453
                if (bucketList.size() > 0) {
439
454
                        //construct access control policy from grant infos
440
455
                        BucketInfo bucket = bucketList.get(0);
 
456
                        logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
441
457
                        List<GrantInfo> grantInfos = bucket.getGrants();
442
458
                        if (bucket.canReadACP(userId)) {
 
459
                                if(logData != null) {
 
460
                                        updateLogData(bucket, logData);
 
461
                                        reply.setLogData(logData);
 
462
                                }                               
443
463
                                ownerId = bucket.getOwnerId();
444
464
                                ArrayList<Grant> grants = new ArrayList<Grant>();
 
465
                                bucket.readPermissions(grants);
445
466
                                for (GrantInfo grantInfo: grantInfos) {
446
467
                                        String uId = grantInfo.getUserId();
447
468
                                        try {
448
 
                                                User grantUserInfo = CredentialProvider.getUser( uId );
449
 
                                                bucket.readPermissions(grants);
450
 
                                                addPermission(grants, grantUserInfo, grantInfo);
 
469
                                                if(uId != null) {
 
470
                                                        User grantUserInfo = CredentialProvider.getUser( uId );
 
471
                                                        addPermission(grants, grantUserInfo, grantInfo);
 
472
                                                } else {
 
473
                                                        addPermission(grants, grantInfo);
 
474
                                                }
451
475
                                        } catch ( NoSuchUserException e ) {
452
476
                                                db.rollback( );
453
 
                                                throw new AccessDeniedException("Bucket", bucketName);
 
477
                                                throw new AccessDeniedException("Bucket", bucketName, logData);
454
478
                                        }
455
479
                                }
456
480
                                accessControlList.setGrants(grants);
467
491
                        accessControlPolicy.setAccessControlList(accessControlList);
468
492
                } catch ( NoSuchUserException e ) {
469
493
                        db.rollback( );
470
 
                        throw new AccessDeniedException("Bucket", bucketName);
 
494
                        throw new AccessDeniedException("Bucket", bucketName, logData);
471
495
                }
472
496
                reply.setAccessControlPolicy(accessControlPolicy);
473
497
                db.commit();
500
524
                }
501
525
        }
502
526
 
 
527
        private static void addPermission(ArrayList<Grant>grants, GrantInfo grantInfo) {
 
528
                if(grantInfo.getGrantGroup() != null) {
 
529
                        Group group = new Group(grantInfo.getGrantGroup());
 
530
 
 
531
                        if (grantInfo.canRead() && grantInfo.canWrite() && grantInfo.canReadACP() && grantInfo.isWriteACP()) {
 
532
                                grants.add(new Grant(new Grantee(group), "FULL_CONTROL"));
 
533
                                return;
 
534
                        }
 
535
 
 
536
                        if (grantInfo.canRead()) {
 
537
                                grants.add(new Grant(new Grantee(group), "READ"));
 
538
                        }
 
539
 
 
540
                        if (grantInfo.canWrite()) {
 
541
                                grants.add(new Grant(new Grantee(group), "WRITE"));
 
542
                        }
 
543
 
 
544
                        if (grantInfo.canReadACP()) {
 
545
                                grants.add(new Grant(new Grantee(group), "READ_ACP"));
 
546
                        }
 
547
 
 
548
                        if (grantInfo.isWriteACP()) {
 
549
                                grants.add(new Grant(new Grantee(group), "WRITE_ACP"));
 
550
                        }
 
551
                }
 
552
        }
 
553
 
503
554
        public PutObjectResponseType putObject(PutObjectType request) throws EucalyptusCloudException {
504
555
                PutObjectResponseType reply = (PutObjectResponseType) request.getReply();
505
556
                String userId = request.getUserId();
527
578
 
528
579
                if(bucketList.size() > 0) {
529
580
                        BucketInfo bucket = bucketList.get(0);
 
581
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
530
582
                        if (bucket.canWrite(userId)) {
 
583
                                if(logData != null)
 
584
                                        reply.setLogData(logData);
531
585
 
532
586
                                ObjectInfo foundObject = null;
533
587
                                EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
540
594
                                                if (!objectInfo.canWrite(userId)) {
541
595
                                                        db.rollback();
542
596
                                                        messenger.removeQueue(key, randomKey);
543
 
                                                        throw new AccessDeniedException("Key", objectKey);
 
597
                                                        throw new AccessDeniedException("Key", objectKey, logData);
544
598
                                                }
545
599
                                                foundObject = objectInfo;
546
600
                                                oldBucketSize = -foundObject.getSize();
644
698
                                                                        walrusStatistics.updateBytesIn(size);
645
699
                                                                        walrusStatistics.updateSpaceUsed(size);
646
700
                                                                }
 
701
                                                                if(logData != null) {
 
702
                                                                        logData.setObjectSize(size);
 
703
                                                                        updateLogData(bucket, logData);
 
704
                                                                }
647
705
                                                                dbObject.commit();
 
706
                                                                if(logData != null) {
 
707
                                                                        logData.setTurnAroundTime(Long.parseLong(new String(dataMessage.getPayload())));
 
708
                                                                }
648
709
                                                        } else {
649
710
                                                                dbObject.rollback();
650
 
                                                                throw new NoSuchEntityException("Could not find object: " + bucketName + "/" + objectKey);
 
711
                                                                throw new NoSuchEntityException("Could not find object: " + bucketName + "/" + objectKey, logData);
651
712
                                                        }
652
713
                                                        //restart all interrupted puts
653
714
                                                        WalrusMonitor monitor = messenger.getMonitor(key);
697
758
                                } catch (InterruptedException ex) {
698
759
                                        LOG.error(ex, ex);
699
760
                                        messenger.removeQueue(key, randomKey);
700
 
                                        throw new EucalyptusCloudException();
 
761
                                        throw new EucalyptusCloudException("Transfer interrupted: " + key + "." + randomKey);
701
762
                                }
702
763
                        } else {
703
764
                                db.rollback();
704
765
                                messenger.removeQueue(key, randomKey);
705
 
                                throw new AccessDeniedException("Bucket", bucketName);
 
766
                                throw new AccessDeniedException("Bucket", bucketName, logData);
706
767
                        }
707
768
                }   else {
708
769
                        db.rollback();
744
805
                reply.setMetaData(putObjectResponse.getMetaData());
745
806
                reply.setErrorCode(putObjectResponse.getErrorCode());
746
807
                reply.setStatusMessage(putObjectResponse.getStatusMessage());
 
808
                reply.setLogData(putObjectResponse.getLogData());
747
809
 
748
810
                String successActionRedirect = request.getSuccessActionRedirect();
749
811
                if(successActionRedirect != null) {
799
861
 
800
862
                if(bucketList.size() > 0) {
801
863
                        BucketInfo bucket = bucketList.get(0);
 
864
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
802
865
                        if (bucket.canWrite(userId)) {
803
866
                                EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
804
867
                                ObjectInfo searchObjectInfo = new ObjectInfo();
811
874
                                                //key (object) exists. check perms
812
875
                                                if (!objectInfo.canWrite(userId)) {
813
876
                                                        db.rollback();
814
 
                                                        throw new AccessDeniedException("Key", objectKey);
 
877
                                                        throw new AccessDeniedException("Key", objectKey, logData);
815
878
                                                }
816
879
                                                foundObject = objectInfo;
817
880
                                                oldBucketSize = -foundObject.getSize();
854
917
                                        }
855
918
                                        md5 = Hashes.getHexString(Hashes.Digest.MD5.get().digest(base64Data));
856
919
                                        foundObject.setEtag(md5);
857
 
                                        Long size = Long.parseLong(request.getContentLength());
 
920
                                        Long size = (long)base64Data.length;
858
921
                                        foundObject.setSize(size);
859
922
                                        if(WalrusProperties.shouldEnforceUsageLimits && !request.isAdministrator()) {
860
923
                                                Long bucketSize = bucket.getBucketSize();
861
924
                                                long newSize = bucketSize + oldBucketSize + size;
862
925
                                                if(newSize > WalrusProperties.MAX_BUCKET_SIZE) {
863
926
                                                        db.rollback();
864
 
                                                        throw new EntityTooLargeException("Key", objectKey);
 
927
                                                        throw new EntityTooLargeException("Key", objectKey, logData);
865
928
                                                }
866
929
                                                bucket.setBucketSize(newSize);
867
930
                                        }
877
940
                                        foundObject.setStorageClass("STANDARD");
878
941
                                        lastModified = new Date();
879
942
                                        foundObject.setLastModified(lastModified);
880
 
                                } catch (/*TODO: NEIL, check if it is IOException*/Exception ex) {
 
943
                                        if(logData != null) {
 
944
                                                updateLogData(bucket, logData);
 
945
                                                logData.setObjectSize(size);
 
946
                                                reply.setLogData(logData);
 
947
                                        }                                       
 
948
                                } catch (Exception ex) {
881
949
                                        LOG.error(ex);
882
950
                                        db.rollback();
883
951
                                        throw new EucalyptusCloudException(bucketName);
884
952
                                }
885
953
                        } else {
886
954
                                db.rollback();
887
 
                                throw new AccessDeniedException("Bucket", bucketName);
 
955
                                throw new AccessDeniedException("Bucket", bucketName, logData);
888
956
                        }
889
 
 
890
957
                }   else {
891
958
                        db.rollback();
892
959
                        throw new NoSuchBucketException(bucketName);
899
966
                return reply;
900
967
        }
901
968
 
902
 
        public void addObject(String userId, String bucketName, String key) throws EucalyptusCloudException {
903
 
 
904
 
                AccessControlListType accessControlList = new AccessControlListType();
 
969
        public AddObjectResponseType addObject(AddObjectType request) throws EucalyptusCloudException {
 
970
 
 
971
                AddObjectResponseType reply = (AddObjectResponseType) request.getReply();
 
972
                String bucketName = request.getBucket();
 
973
                String key = request.getKey();
 
974
                String userId = request.getUserId();
 
975
                String objectName = request.getObjectName();
 
976
 
 
977
                AccessControlListType accessControlList = request.getAccessControlList();
905
978
                if (accessControlList == null) {
906
979
                        accessControlList = new AccessControlListType();
907
980
                }
926
999
                                }
927
1000
                                //write object to bucket
928
1001
                                ObjectInfo objectInfo = new ObjectInfo(bucketName, key);
 
1002
                                objectInfo.setObjectName(objectName);
929
1003
                                List<GrantInfo> grantInfos = new ArrayList<GrantInfo>();
930
1004
                                objectInfo.addGrants(userId, grantInfos, accessControlList);
931
1005
                                objectInfo.setGrants(grantInfos);
933
1007
 
934
1008
                                objectInfo.setObjectKey(key);
935
1009
                                objectInfo.setOwnerId(userId);
936
 
                                objectInfo.setSize(storageManager.getSize(bucketName, key));
937
 
                                objectInfo.setEtag("");
 
1010
                                objectInfo.setSize(storageManager.getSize(bucketName, objectName));
 
1011
                                objectInfo.setEtag(request.getEtag());
938
1012
                                objectInfo.setLastModified(new Date());
 
1013
                                objectInfo.setStorageClass("STANDARD");
939
1014
                        } else {
940
1015
                                db.rollback();
941
1016
                                throw new AccessDeniedException("Bucket", bucketName);
945
1020
                        throw new NoSuchBucketException(bucketName);
946
1021
                }
947
1022
                db.commit();
 
1023
                return reply;
948
1024
        }
949
1025
 
950
1026
        public DeleteObjectResponseType deleteObject(DeleteObjectType request) throws EucalyptusCloudException {
959
1035
 
960
1036
                if (bucketList.size() > 0) {
961
1037
                        BucketInfo bucketInfo = bucketList.get(0);
 
1038
                        BucketLogData logData = bucketInfo.getLoggingEnabled() ? request.getLogData() : null;
962
1039
                        ObjectInfo foundObject = null;
963
1040
                        EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
964
1041
                        ObjectInfo searchObjectInfo = new ObjectInfo(bucketName, objectKey);
980
1057
                                        objectDeleter.start();
981
1058
                                        reply.setCode("200");
982
1059
                                        reply.setDescription("OK");
 
1060
                                        if(logData != null) {
 
1061
                                                updateLogData(bucketInfo, logData);
 
1062
                                                reply.setLogData(logData);
 
1063
                                        }                                       
983
1064
                                } else {
984
1065
                                        db.rollback();
985
 
                                        throw new AccessDeniedException("Key", objectKey);
 
1066
                                        throw new AccessDeniedException("Key", objectKey, logData);
986
1067
                                }
987
1068
                        } else {
988
1069
                                db.rollback();
989
 
                                throw new NoSuchEntityException(objectKey);
 
1070
                                throw new NoSuchEntityException(objectKey, logData);
990
1071
                        }
991
1072
                } else {
992
1073
                        db.rollback();
1044
1125
 
1045
1126
                if(bucketList.size() > 0) {
1046
1127
                        BucketInfo bucket = bucketList.get(0);
 
1128
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
1047
1129
                        if(bucket.canRead(userId)) {
 
1130
                                if(logData != null) {
 
1131
                                        updateLogData(bucket, logData);
 
1132
                                        reply.setLogData(logData);
 
1133
                                }                               
1048
1134
                                if(request.isAdministrator()) {
1049
1135
                                        EntityWrapper<WalrusSnapshotInfo> dbSnap = db.recast(WalrusSnapshotInfo.class);
1050
1136
                                        WalrusSnapshotInfo walrusSnapInfo = new WalrusSnapshotInfo();
1124
1210
                                                        listEntry.setOwner(new CanonicalUserType(userInfo.getQueryId(), displayName));
1125
1211
                                                } catch ( NoSuchUserException e ) {
1126
1212
                                                        db.rollback( );
1127
 
                                                        throw new AccessDeniedException("Bucket", bucketName);
 
1213
                                                        throw new AccessDeniedException("Bucket", bucketName, logData);
1128
1214
                                                }
1129
1215
                                                ArrayList<MetaDataEntry> metaData = new ArrayList<MetaDataEntry>();
1130
1216
                                                objectInfo.returnMetaData(metaData);
1140
1226
                                }
1141
1227
                        } else {
1142
1228
                                db.rollback();
1143
 
                                throw new AccessDeniedException("Bucket", bucketName);
 
1229
                                throw new AccessDeniedException("Bucket", bucketName, logData);
1144
1230
                        }
1145
1231
                } else {
1146
1232
                        db.rollback();
1162
1248
                EntityWrapper<BucketInfo> db = WalrusControl.getEntityWrapper();
1163
1249
                BucketInfo bucketInfo = new BucketInfo(bucketName);
1164
1250
                List<BucketInfo> bucketList = db.query(bucketInfo);
 
1251
                BucketLogData logData;
1165
1252
 
1166
1253
                AccessControlListType accessControlList = new AccessControlListType();
1167
1254
                if (bucketList.size() > 0) {
1168
1255
                        //construct access control policy from grant infos
 
1256
                        logData = bucketList.get(0).getLoggingEnabled() ? request.getLogData() : null;
1169
1257
                        EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
1170
1258
                        ObjectInfo searchObjectInfo = new ObjectInfo(bucketName, objectKey);
1171
1259
                        List<ObjectInfo> objectInfos = dbObject.query(searchObjectInfo);
1172
1260
                        if(objectInfos.size() > 0) {
1173
1261
                                ObjectInfo objectInfo = objectInfos.get(0);
1174
1262
                                if(objectInfo.canReadACP(userId)) {
 
1263
                                        BucketInfo bucket = bucketList.get(0);
 
1264
                                        if(logData != null) {
 
1265
                                                updateLogData(bucket, logData);
 
1266
                                                logData.setObjectSize(objectInfo.getSize());
 
1267
                                                reply.setLogData(logData);
 
1268
                                        }
 
1269
 
1175
1270
                                        ownerId = objectInfo.getOwnerId();
1176
1271
                                        ArrayList<Grant> grants = new ArrayList<Grant>();
1177
1272
                                        List<GrantInfo> grantInfos = objectInfo.getGrants();
1182
1277
                                                        objectInfo.readPermissions(grants);
1183
1278
                                                        addPermission(grants, userInfo, grantInfo);
1184
1279
                                                } catch ( NoSuchUserException e ) {
1185
 
                                                        throw new AccessDeniedException("Key", objectKey);              
 
1280
                                                        throw new AccessDeniedException("Key", objectKey, logData);              
1186
1281
                                                }
1187
1282
                                        }
1188
1283
                                        accessControlList.setGrants(grants);
1189
1284
                                } else {
1190
1285
                                        db.rollback();
1191
 
                                        throw new AccessDeniedException("Key", objectKey);
 
1286
                                        throw new AccessDeniedException("Key", objectKey, logData);
1192
1287
                                }
1193
1288
                        } else {
1194
1289
                                db.rollback();
1195
 
                                throw new NoSuchEntityException(objectKey);
 
1290
                                throw new NoSuchEntityException(objectKey, logData);
1196
1291
                        }
1197
1292
                }   else {
1198
1293
                        db.rollback();
1205
1300
                        accessControlPolicy.setOwner(new CanonicalUserType(ownerUserInfo.getQueryId(), ownerUserInfo.getUserName()));
1206
1301
                        accessControlPolicy.setAccessControlList(accessControlList);
1207
1302
                } catch ( NoSuchUserException e ) {
1208
 
                        throw new AccessDeniedException("Key", objectKey);
 
1303
                        throw new AccessDeniedException("Key", objectKey, logData);
1209
1304
                }
1210
1305
                reply.setAccessControlPolicy(accessControlPolicy);
1211
1306
                db.commit();
1228
1323
 
1229
1324
                if (bucketList.size() > 0) {
1230
1325
                        BucketInfo bucket = bucketList.get(0);
 
1326
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
1231
1327
                        if (bucket.canWriteACP(userId)) {
1232
1328
                                List<GrantInfo> grantInfos = new ArrayList<GrantInfo>();
1233
1329
                                bucket.resetGlobalGrants();
1235
1331
                                bucket.setGrants(grantInfos);
1236
1332
                                reply.setCode("204");
1237
1333
                                reply.setDescription("OK");
 
1334
                                if(logData != null) {
 
1335
                                        updateLogData(bucket, logData);
 
1336
                                        reply.setLogData(logData);
 
1337
                                }                               
1238
1338
                        } else {
1239
1339
                                db.rollback();
1240
 
                                throw new AccessDeniedException("Bucket", bucketName);
 
1340
                                throw new AccessDeniedException("Bucket", bucketName, logData);
1241
1341
                        }
1242
1342
                }   else {
1243
1343
                        db.rollback();
1264
1364
 
1265
1365
                if (bucketList.size() > 0) {
1266
1366
                        BucketInfo bucket = bucketList.get(0);
 
1367
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
1267
1368
                        if (bucket.canWriteACP(userId)) {
1268
1369
                                List<GrantInfo> grantInfos = new ArrayList<GrantInfo>();
1269
1370
                                bucket.resetGlobalGrants();
1271
1372
                                bucket.setGrants(grantInfos);
1272
1373
                                reply.setCode("204");
1273
1374
                                reply.setDescription("OK");
 
1375
                                if(logData != null) {
 
1376
                                        updateLogData(bucket, logData);
 
1377
                                        reply.setLogData(logData);
 
1378
                                }                       
1274
1379
                        } else {
1275
1380
                                db.rollback();
1276
 
                                throw new AccessDeniedException("Bucket", bucketName);
 
1381
                                throw new AccessDeniedException("Bucket", bucketName, logData);
1277
1382
                        }
1278
1383
                }   else {
1279
1384
                        db.rollback();
1297
1402
                List<BucketInfo> bucketList = db.query(bucketInfo);
1298
1403
 
1299
1404
                if (bucketList.size() > 0) {
 
1405
                        BucketInfo bucket = bucketList.get(0);
 
1406
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
1300
1407
                        EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
1301
1408
                        ObjectInfo searchObjectInfo = new ObjectInfo(bucketName, objectKey);
1302
1409
                        List<ObjectInfo> objectInfos = dbObject.query(searchObjectInfo);
1304
1411
                                ObjectInfo objectInfo = objectInfos.get(0);
1305
1412
                                if (!objectInfo.canWriteACP(userId)) {
1306
1413
                                        db.rollback();
1307
 
                                        throw new AccessDeniedException("Key", objectKey);
 
1414
                                        throw new AccessDeniedException("Key", objectKey, logData);
1308
1415
                                }
1309
1416
                                List<GrantInfo> grantInfos = new ArrayList<GrantInfo>();
1310
1417
                                objectInfo.resetGlobalGrants();
1330
1437
                                }
1331
1438
                                reply.setCode("204");
1332
1439
                                reply.setDescription("OK");
 
1440
                                if(logData != null) {
 
1441
                                        updateLogData(bucket, logData);
 
1442
                                        logData.setObjectSize(objectInfo.getSize());
 
1443
                                        reply.setLogData(logData);
 
1444
                                }                               
1333
1445
                        } else {
1334
1446
                                db.rollback();
1335
 
                                throw new NoSuchEntityException(objectKey);
 
1447
                                throw new NoSuchEntityException(objectKey, logData);
1336
1448
                        }
1337
1449
                }   else {
1338
1450
                        db.rollback();
1359
1471
                List<BucketInfo> bucketList = db.query(bucketInfo);
1360
1472
 
1361
1473
                if (bucketList.size() > 0) {
 
1474
                        BucketInfo bucket = bucketList.get(0);
 
1475
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
1362
1476
                        EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
1363
1477
                        ObjectInfo searchObjectInfo = new ObjectInfo(bucketName, objectKey);
1364
1478
                        List<ObjectInfo> objectInfos = dbObject.query(searchObjectInfo);
1366
1480
                                ObjectInfo objectInfo = objectInfos.get(0);
1367
1481
                                if (!objectInfo.canWriteACP(userId)) {
1368
1482
                                        db.rollback();
1369
 
                                        throw new AccessDeniedException("Key", objectKey);
 
1483
                                        throw new AccessDeniedException("Key", objectKey, logData);
1370
1484
                                }
1371
1485
                                List<GrantInfo> grantInfos = new ArrayList<GrantInfo>();
1372
1486
                                objectInfo.resetGlobalGrants();
1390
1504
                                } else {
1391
1505
                                        LOG.warn("Bittorrent support has been disabled. Please check pre-requisites");
1392
1506
                                }
 
1507
                                if(logData != null) {
 
1508
                                        updateLogData(bucket, logData);
 
1509
                                        logData.setObjectSize(objectInfo.getSize());
 
1510
                                        reply.setLogData(logData);
 
1511
                                }                               
1393
1512
                                reply.setCode("204");
1394
1513
                                reply.setDescription("OK");
1395
1514
                        } else {
1396
1515
                                db.rollback();
1397
 
                                throw new NoSuchEntityException(objectKey);
 
1516
                                throw new NoSuchEntityException(objectKey, logData);
1398
1517
                        }
1399
1518
                }   else {
1400
1519
                        db.rollback();
1426
1545
                List<BucketInfo> bucketList = db.query(bucketInfo);
1427
1546
 
1428
1547
                if (bucketList.size() > 0) {
 
1548
                        BucketInfo bucket = bucketList.get(0);
 
1549
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
1429
1550
                        EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
1430
1551
                        ObjectInfo searchObjectInfo = new ObjectInfo(bucketName, objectKey);
1431
1552
                        List<ObjectInfo> objectInfos = dbObject.query(searchObjectInfo);
1455
1576
                                                        } catch (EucalyptusCloudException ex) {
1456
1577
                                                                String torrentFile = objectName + ".torrent";
1457
1578
                                                                String torrentFilePath = storageManager.getObjectPath(bucketName, torrentFile);
1458
 
                                                                TorrentCreator torrentCreator = new TorrentCreator(absoluteObjectPath, objectKey, objectName, torrentFilePath, WalrusProperties.TRACKER_URL);
 
1579
                                                                TorrentCreator torrentCreator = new TorrentCreator(absoluteObjectPath, objectKey, objectName, torrentFilePath, WalrusProperties.getTrackerUrl());
1459
1580
                                                                try {
1460
1581
                                                                        torrentCreator.create();
1461
1582
                                                                } catch(Exception e) {
1482
1603
                                                                Date lastModified = objectInfo.getLastModified();
1483
1604
                                                                db.commit();
1484
1605
                                                                long torrentLength = torrent.length();
 
1606
                                                                if(logData != null) {
 
1607
                                                                        updateLogData(bucket, logData);
 
1608
                                                                        logData.setObjectSize(torrentLength);
 
1609
                                                                }                                                               
1485
1610
                                                                storageManager.sendObject(request.getChannel(), httpResponse, bucketName, torrentFile, torrentLength, null, 
1486
1611
                                                                                DateUtils.format(lastModified.getTime(), DateUtils.ISO8601_DATETIME_PATTERN) + ".000Z", 
1487
 
                                                                                "application/x-bittorrent", "attachment; filename=" + objectKey + ".torrent;", request.getIsCompressed());
 
1612
                                                                                "application/x-bittorrent", "attachment; filename=" + objectKey + ".torrent;", request.getIsCompressed(),
 
1613
                                                                                logData);
1488
1614
                                                                if(WalrusProperties.trackUsageStatistics) {
1489
1615
                                                                        walrusStatistics.updateBytesOut(torrentLength);
1490
1616
                                                                }
1497
1623
                                                        }
1498
1624
                                                } else {
1499
1625
                                                        db.rollback();
1500
 
                                                        throw new AccessDeniedException("Key", objectKey);
 
1626
                                                        throw new AccessDeniedException("Key", objectKey, logData);
1501
1627
                                                }
1502
1628
                                        }
1503
1629
                                        Date lastModified = objectInfo.getLastModified();
1506
1632
                                        String contentType = objectInfo.getContentType();
1507
1633
                                        String contentDisposition = objectInfo.getContentDisposition();
1508
1634
                                        db.commit();
 
1635
                                        if(logData != null) {
 
1636
                                                updateLogData(bucket, logData);
 
1637
                                                logData.setObjectSize(size);
 
1638
                                        }                                                               
1509
1639
                                        if(request.getGetData()) {
1510
1640
                                                if(request.getInlineData()) {
1511
1641
                                                        try {
1519
1649
                                                        } catch (IOException ex) {
1520
1650
                                                                db.rollback();
1521
1651
                                                                LOG.error(ex);
1522
 
                                                                //set error code
1523
 
                                                                return null;
 
1652
                                                                throw new EucalyptusCloudException("Unable to read object: " + bucketName + "/" + objectName);
1524
1653
                                                        }
1525
1654
                                                } else {
1526
1655
                                                        //support for large objects
1529
1658
                                                        }
1530
1659
                                                        storageManager.sendObject(request.getChannel(), httpResponse, bucketName, objectName, size, etag, 
1531
1660
                                                                        DateUtils.format(lastModified.getTime(), DateUtils.ISO8601_DATETIME_PATTERN) + ".000Z", 
1532
 
                                                                        contentType, contentDisposition, request.getIsCompressed());           
1533
 
                                                        return null;                 
 
1661
                                                                        contentType, contentDisposition, request.getIsCompressed(), logData);  
 
1662
                                                        return null;
1534
1663
                                                }
1535
1664
                                        } else {
1536
1665
                                                storageManager.sendHeaders(request.getChannel(), httpResponse, size, etag, 
1537
1666
                                                                DateUtils.format(lastModified.getTime(), DateUtils.ISO8601_DATETIME_PATTERN) + ".000Z", 
1538
 
                                                                contentType, contentDisposition);                            
 
1667
                                                                contentType, contentDisposition, logData);
1539
1668
                                                return null;
1540
1669
 
1541
1670
                                        }
1551
1680
                                        return reply;
1552
1681
                                } else {
1553
1682
                                        db.rollback();
1554
 
                                        throw new AccessDeniedException("Key", objectKey);
 
1683
                                        throw new AccessDeniedException("Key", objectKey, logData);
1555
1684
                                }
1556
1685
                        } else {
1557
1686
                                db.rollback();
1558
 
                                throw new NoSuchEntityException(objectKey);
 
1687
                                throw new NoSuchEntityException(objectKey, logData);
1559
1688
                        }
1560
1689
                } else {
1561
1690
                        db.rollback();
1590
1719
 
1591
1720
 
1592
1721
                if (bucketList.size() > 0) {
 
1722
                        BucketInfo bucket = bucketList.get(0);
 
1723
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
1593
1724
                        EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class);
1594
1725
                        ObjectInfo searchObjectInfo = new ObjectInfo(bucketName, objectKey);
1595
1726
                        List<ObjectInfo> objectInfos = dbObject.query(searchObjectInfo);
1644
1775
                                        String contentType = objectInfo.getContentType();
1645
1776
                                        String contentDisposition = objectInfo.getContentDisposition();
1646
1777
                                        db.commit();
 
1778
                                        if(logData != null) {
 
1779
                                                updateLogData(bucket, logData);
 
1780
                                                logData.setObjectSize(size);
 
1781
                                        }                                                                               
1647
1782
                                        if(request.getGetData()) {
1648
1783
                                                if(WalrusProperties.trackUsageStatistics) {
1649
1784
                                                        walrusStatistics.updateBytesOut(size);
1650
1785
                                                }
1651
1786
                                                storageManager.sendObject(request.getChannel(), httpResponse, bucketName, objectName, byteRangeStart, byteRangeEnd, size, etag, 
1652
1787
                                                                DateUtils.format(lastModified.getTime(), DateUtils.ISO8601_DATETIME_PATTERN + ".000Z"), 
1653
 
                                                                contentType, contentDisposition, request.getIsCompressed());                            
 
1788
                                                                contentType, contentDisposition, request.getIsCompressed(), logData);  
 
1789
                                                return null;
1654
1790
                                        } else {
1655
1791
                                                storageManager.sendHeaders(request.getChannel(), httpResponse, size, etag, 
1656
1792
                                                                DateUtils.format(lastModified.getTime(), DateUtils.ISO8601_DATETIME_PATTERN + ".000Z"), 
1657
 
                                                                contentType, contentDisposition);                            
1658
 
                                        }
1659
 
                                        reply.setEtag(etag);
1660
 
                                        reply.setLastModified(DateUtils.format(lastModified.getTime(), DateUtils.ISO8601_DATETIME_PATTERN) + ".000Z");
1661
 
                                        if(byteRangeEnd > -1) {
1662
 
                                                if(byteRangeEnd <= size && ((byteRangeEnd - byteRangeStart) > 0))
1663
 
                                                        reply.setSize(byteRangeEnd - byteRangeStart);
1664
 
                                                else
1665
 
                                                        reply.setSize(0L);
1666
 
                                        } else {
1667
 
                                                reply.setSize(size);
1668
 
                                        }
1669
 
                                        status.setCode(200);
1670
 
                                        status.setDescription("OK");
1671
 
                                        reply.setContentType("binary/octet-stream");                    
1672
 
                                        reply.setStatus(status);
 
1793
                                                                contentType, contentDisposition, logData);
 
1794
                                                return null;
 
1795
                                        }
1673
1796
                                } else {
1674
1797
                                        db.rollback();
1675
1798
                                        throw new AccessDeniedException("Key", objectKey);
1682
1805
                        db.rollback();
1683
1806
                        throw new NoSuchBucketException(bucketName);
1684
1807
                }
1685
 
                db.commit();
1686
 
                return null;
1687
1808
        }
1688
1809
 
1689
1810
        public GetBucketLocationResponseType getBucketLocation(GetBucketLocationType request) throws EucalyptusCloudException {
1697
1818
 
1698
1819
                if(bucketList.size() > 0) {
1699
1820
                        BucketInfo bucket = bucketList.get(0);
 
1821
                        BucketLogData logData = bucket.getLoggingEnabled() ? request.getLogData() : null;
1700
1822
                        if(bucket.canRead(userId)) {
 
1823
                                if(logData != null) {
 
1824
                                        updateLogData(bucket, logData);
 
1825
                                        reply.setLogData(logData);
 
1826
                                }                               
1701
1827
                                String location = bucket.getLocation();
1702
1828
                                if(location == null) {
1703
1829
                                        location = "NotSupported";
1705
1831
                                reply.setLocationConstraint(location);
1706
1832
                        } else {
1707
1833
                                db.rollback();
1708
 
                                throw new AccessDeniedException("Bucket", bucketName);
 
1834
                                throw new AccessDeniedException("Bucket", bucketName, logData);
1709
1835
                        }
1710
1836
                } else {
1711
1837
                        db.rollback();
1861
1987
                        throw new NoSuchBucketException(sourceBucket);
1862
1988
                }
1863
1989
        }
 
1990
 
 
1991
        public SetBucketLoggingStatusResponseType setBucketLoggingStatus(SetBucketLoggingStatusType request) throws EucalyptusCloudException {
 
1992
                SetBucketLoggingStatusResponseType reply = (SetBucketLoggingStatusResponseType) request.getReply();
 
1993
                String bucket = request.getBucket();
 
1994
                String targetBucket = request.getLoggingEnabled().getTargetBucket();
 
1995
                String targetPrefix = request.getLoggingEnabled().getTargetPrefix();
 
1996
                List<Grant> targetGrantsList = null;
 
1997
                TargetGrants targetGrants = request.getLoggingEnabled().getTargetGrants();
 
1998
                if(targetGrants != null)
 
1999
                        targetGrantsList = targetGrants.getGrants();
 
2000
                if(targetPrefix == null)
 
2001
                        targetPrefix = "";
 
2002
 
 
2003
                EntityWrapper<BucketInfo> db = WalrusControl.getEntityWrapper();
 
2004
                BucketInfo bucketInfo, targetBucketInfo;
 
2005
                try {
 
2006
                        bucketInfo = db.getUnique(new BucketInfo(bucket));
 
2007
                } catch(EucalyptusCloudException ex) {
 
2008
                        db.rollback();
 
2009
                        throw new NoSuchBucketException(bucket);
 
2010
                } 
 
2011
                try {
 
2012
                        targetBucketInfo = db.getUnique(new BucketInfo(targetBucket));
 
2013
                } catch(EucalyptusCloudException ex) {
 
2014
                        db.rollback();
 
2015
                        throw new NoSuchBucketException(bucket);
 
2016
                } 
 
2017
                if(!targetBucketInfo.hasLoggingPerms()) {
 
2018
                        db.rollback();
 
2019
                        throw new InvalidTargetBucketForLoggingException(targetBucket); 
 
2020
                }
 
2021
                bucketInfo.setTargetBucket(targetBucket);
 
2022
                bucketInfo.setTargetPrefix(targetPrefix);
 
2023
                bucketInfo.setLoggingEnabled(true);
 
2024
                if(targetGrantsList != null) {
 
2025
                        targetBucketInfo.addGrants(targetGrantsList);
 
2026
                }
 
2027
                db.commit();            
 
2028
                return reply;
 
2029
        }
 
2030
 
 
2031
        public GetBucketLoggingStatusResponseType getBucketLoggingStatus(GetBucketLoggingStatusType request) throws EucalyptusCloudException {
 
2032
                GetBucketLoggingStatusResponseType reply = (GetBucketLoggingStatusResponseType) request.getReply();
 
2033
                String bucket = request.getBucket();
 
2034
 
 
2035
                EntityWrapper<BucketInfo> db = WalrusControl.getEntityWrapper();
 
2036
                try {
 
2037
                        BucketInfo bucketInfo = db.getUnique(new BucketInfo(bucket));
 
2038
                        if(bucketInfo.getLoggingEnabled()) {
 
2039
                                String targetBucket = bucketInfo.getTargetBucket();
 
2040
                                ArrayList<Grant> grants = new ArrayList<Grant>();
 
2041
                                try {
 
2042
                                        BucketInfo targetBucketInfo = db.getUnique(new BucketInfo(targetBucket));
 
2043
                                        List<GrantInfo> grantInfos = targetBucketInfo.getGrants();
 
2044
                                        for (GrantInfo grantInfo: grantInfos) {
 
2045
                                                String uId = grantInfo.getUserId();
 
2046
                                                try {
 
2047
                                                        if(uId != null) {
 
2048
                                                                User grantUserInfo = CredentialProvider.getUser( uId );
 
2049
                                                                addPermission(grants, grantUserInfo, grantInfo);
 
2050
                                                        } else {
 
2051
                                                                addPermission(grants, grantInfo);
 
2052
                                                        }
 
2053
                                                } catch ( NoSuchUserException e ) {
 
2054
                                                        db.rollback( );
 
2055
                                                        throw new AccessDeniedException("Bucket", targetBucket);
 
2056
                                                }
 
2057
                                        }
 
2058
                                } catch(EucalyptusCloudException ex) {
 
2059
                                        db.rollback();
 
2060
                                        throw new InvalidTargetBucketForLoggingException(targetBucket);
 
2061
                                }
 
2062
                                reply.getLoggingEnabled().setTargetBucket(bucketInfo.getTargetBucket());
 
2063
                                reply.getLoggingEnabled().setTargetPrefix(bucketInfo.getTargetPrefix());
 
2064
 
 
2065
                                TargetGrants targetGrants = new TargetGrants();
 
2066
                                targetGrants.setGrants(grants);
 
2067
                                reply.getLoggingEnabled().setTargetGrants(targetGrants);
 
2068
                        }
 
2069
                } catch(EucalyptusCloudException ex) {
 
2070
                        db.rollback();
 
2071
                        throw new NoSuchBucketException(bucket);
 
2072
                } 
 
2073
                db.commit();            
 
2074
                return reply;
 
2075
        }
 
2076
 
 
2077
        private void updateLogData(BucketInfo bucket, BucketLogData logData) {
 
2078
                logData.setOwnerId(bucket.getOwnerId());
 
2079
                logData.setTargetBucket(bucket.getTargetBucket());
 
2080
                logData.setTargetPrefix(bucket.getTargetPrefix());
 
2081
        }
1864
2082
}