Skip to content

Commit b72cf81

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 1477 b: refs/heads/master c: 12a10b5 h: refs/heads/master i: 1475: 7d91e7b
1 parent e4c22fe commit b72cf81

26 files changed

Lines changed: 212 additions & 186 deletions

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 5b1c443e0f0918e543fe9a2a737d7ccb4ce30cf8
2+
refs/heads/master: 12a10b575b00e1d51347f545414e35f3b64fe26e
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: d1b373c30c176edc08692348167bec3a244bb823
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3

trunk/TESTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ Currently, there isn't an emulator for Google Cloud Storage, so an alternative i
5555
3. Create a `RemoteGcsHelper` object using your project ID and JSON key.
5656
Here is an example that uses the `RemoteGcsHelper` to create a bucket.
5757
```java
58-
RemoteGcsHelper gcsHelper =
59-
RemoteGcsHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
58+
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/my/JSON/key.json");
6059
Storage storage = gcsHelper.options().service();
6160
String bucket = RemoteGcsHelper.generateBucketName();
6261
storage.create(BucketInfo.of(bucket));

trunk/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/testing/LocalResourceManagerHelper.java

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ String body() {
9595
private enum Error {
9696
ALREADY_EXISTS(409, "global", "alreadyExists", "ALREADY_EXISTS"),
9797
PERMISSION_DENIED(403, "global", "forbidden", "PERMISSION_DENIED"),
98-
// change failed precondition error code to 412 when #440 is fixed
9998
FAILED_PRECONDITION(400, "global", "failedPrecondition", "FAILED_PRECONDITION"),
100-
// change invalid argument error code to 412 when #440 is fixed
10199
INVALID_ARGUMENT(400, "global", "badRequest", "INVALID_ARGUMENT"),
102100
BAD_REQUEST(400, "global", "badRequest", "BAD_REQUEST"),
103101
INTERNAL_ERROR(500, "global", "internalError", "INTERNAL_ERROR");
@@ -324,12 +322,9 @@ Response create(Project project) {
324322
}
325323
}
326324

327-
Response delete(String projectId) {
325+
synchronized Response delete(String projectId) {
328326
Project project = projects.get(projectId);
329327
if (project == null) {
330-
// Currently the service returns 403 Permission Denied when trying to delete a project that
331-
// doesn't exist. Here we mimic this behavior, but this line should be changed to throw a
332-
// 404 Not Found error when the service fixes this (#440).
333328
return Error.PERMISSION_DENIED.response(
334329
"Error when deleting " + projectId + " because the project was not found.");
335330
}
@@ -343,18 +338,16 @@ Response delete(String projectId) {
343338
}
344339

345340
Response get(String projectId, String[] fields) {
346-
if (!projects.containsKey(projectId)) {
347-
// Currently the service returns 403 Permission Denied when trying to get a project that
348-
// doesn't exist. Here we mimic this behavior, but this line should be changed to throw a
349-
// 404 Not Found error when the service fixes this (#440).
350-
return Error.PERMISSION_DENIED.response("Project " + projectId + " not found.");
351-
}
352341
Project project = projects.get(projectId);
353-
try {
354-
return new Response(HTTP_OK, jsonFactory.toString(extractFields(project, fields)));
355-
} catch (IOException e) {
356-
return Error.INTERNAL_ERROR.response(
357-
"Error when serializing project " + project.getProjectId());
342+
if (project != null) {
343+
try {
344+
return new Response(HTTP_OK, jsonFactory.toString(extractFields(project, fields)));
345+
} catch (IOException e) {
346+
return Error.INTERNAL_ERROR.response(
347+
"Error when serializing project " + project.getProjectId());
348+
}
349+
} else {
350+
return Error.PERMISSION_DENIED.response("Project " + projectId + " not found.");
358351
}
359352
}
360353

@@ -462,12 +455,9 @@ private static Project extractFields(Project fullProject, String[] fields) {
462455
return project;
463456
}
464457

465-
Response replace(String projectId, Project project) {
458+
synchronized Response replace(String projectId, Project project) {
466459
Project originalProject = projects.get(projectId);
467460
if (originalProject == null) {
468-
// Currently the service returns 403 Permission Denied when trying to replace a project that
469-
// doesn't exist. Here we mimic this behavior, but this line should be changed to throw a
470-
// 404 Not Found error when the service fixes this (#440).
471461
return Error.PERMISSION_DENIED.response(
472462
"Error when replacing " + projectId + " because the project was not found.");
473463
} else if (!originalProject.getLifecycleState().equals("ACTIVE")) {
@@ -478,23 +468,23 @@ Response replace(String projectId, Project project) {
478468
"The server currently only supports setting the parent once "
479469
+ "and does not allow unsetting it.");
480470
}
481-
originalProject.setName(project.getName());
482-
originalProject.setLabels(project.getLabels());
483-
originalProject.setParent(project.getParent());
471+
project.setProjectId(projectId);
472+
project.setLifecycleState(originalProject.getLifecycleState());
473+
project.setCreateTime(originalProject.getCreateTime());
474+
project.setProjectNumber(originalProject.getProjectNumber());
475+
// replace cannot fail because both this method and removeProject are synchronized
476+
projects.replace(projectId, project);
484477
try {
485-
return new Response(HTTP_OK, jsonFactory.toString(originalProject));
478+
return new Response(HTTP_OK, jsonFactory.toString(project));
486479
} catch (IOException e) {
487480
return Error.INTERNAL_ERROR.response("Error when serializing project " + projectId);
488481
}
489482
}
490483

491-
Response undelete(String projectId) {
484+
synchronized Response undelete(String projectId) {
492485
Project project = projects.get(projectId);
493486
Response response;
494487
if (project == null) {
495-
// Currently the service returns 403 Permission Denied when trying to undelete a project that
496-
// doesn't exist. Here we mimic this behavior, but this line should be changed to throw a
497-
// 404 Not Found error when the service fixes this (#440).
498488
response = Error.PERMISSION_DENIED.response(
499489
"Error when undeleting " + projectId + " because the project was not found.");
500490
} else if (!project.getLifecycleState().equals("DELETE_REQUESTED")) {
@@ -550,7 +540,7 @@ public void stop() {
550540
*
551541
* @return true if the lifecycle state was successfully updated, false otherwise.
552542
*/
553-
public boolean changeLifecycleState(String projectId, String lifecycleState) {
543+
public synchronized boolean changeLifecycleState(String projectId, String lifecycleState) {
554544
checkArgument(
555545
"ACTIVE".equals(lifecycleState) || "DELETE_REQUESTED".equals(lifecycleState)
556546
|| "DELETE_IN_PROGRESS".equals(lifecycleState),
@@ -571,7 +561,9 @@ public boolean changeLifecycleState(String projectId, String lifecycleState) {
571561
*
572562
* @return true if the project was successfully deleted, false if the project didn't exist.
573563
*/
574-
public boolean removeProject(String projectId) {
564+
public synchronized boolean removeProject(String projectId) {
565+
// Because this method is synchronized, any code that relies on non-atomic read/write operations
566+
// should not fail if that code is also synchronized.
575567
return projects.remove(checkNotNull(projectId)) != null;
576568
}
577569
}

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ public Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, lo
479479
}
480480

481481
@Override
482-
public void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length,
483-
boolean last) throws StorageException {
482+
public void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest,
483+
long destOffset, int length, boolean last) throws StorageException {
484484
try {
485485
GenericUrl url = new GenericUrl(uploadId);
486486
HttpRequest httpRequest = storage.getRequestFactory().buildPutRequest(url,
@@ -571,7 +571,7 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage
571571
try {
572572
Long maxBytesRewrittenPerCall = req.megabytesRewrittenPerCall != null
573573
? req.megabytesRewrittenPerCall * MEGABYTE : null;
574-
com.google.api.services.storage.model.RewriteResponse rewriteResponse = storage.objects()
574+
com.google.api.services.storage.model.RewriteResponse rewriteReponse = storage.objects()
575575
.rewrite(req.source.getBucket(), req.source.getName(), req.target.getBucket(),
576576
req.target.getName(), req.target.getContentType() != null ? req.target : null)
577577
.setSourceGeneration(req.source.getGeneration())
@@ -590,11 +590,11 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage
590590
.execute();
591591
return new RewriteResponse(
592592
req,
593-
rewriteResponse.getResource(),
594-
rewriteResponse.getObjectSize().longValue(),
595-
rewriteResponse.getDone(),
596-
rewriteResponse.getRewriteToken(),
597-
rewriteResponse.getTotalBytesRewritten().longValue());
593+
rewriteReponse.getResource(),
594+
rewriteReponse.getObjectSize().longValue(),
595+
rewriteReponse.getDone(),
596+
rewriteReponse.getRewriteToken(),
597+
rewriteReponse.getTotalBytesRewritten().longValue());
598598
} catch (IOException ex) {
599599
throw translate(ex);
600600
}

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, long posi
264264

265265
String open(StorageObject object, Map<Option, ?> options) throws StorageException;
266266

267-
void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length,
268-
boolean last) throws StorageException;
267+
void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest,
268+
long destOffset, int length, boolean last) throws StorageException;
269269

270270
RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws StorageException;
271271

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ protected String value() {
7373
}
7474

7575
@Override
76-
public boolean equals(Object obj) {
77-
if (this == obj) {
76+
public boolean equals(Object o) {
77+
if (this == o) {
7878
return true;
7979
}
80-
if (obj == null || getClass() != obj.getClass()) {
80+
if (o == null || getClass() != o.getClass()) {
8181
return false;
8282
}
83-
Entity entity = (Entity) obj;
83+
Entity entity = (Entity) o;
8484
return Objects.equals(type, entity.type) && Objects.equals(value, entity.value);
8585
}
8686

@@ -226,7 +226,7 @@ public static final class Project extends Entity {
226226

227227
private static final long serialVersionUID = 7933776866530023027L;
228228

229-
private final ProjectRole projectRole;
229+
private final ProjectRole pRole;
230230
private final String projectId;
231231

232232
public enum ProjectRole {
@@ -236,20 +236,20 @@ public enum ProjectRole {
236236
/**
237237
* Creates a project entity.
238238
*
239-
* @param projectRole a role in the project, used to select project's teams
239+
* @param pRole a role in the project, used to select project's teams
240240
* @param projectId id of the project
241241
*/
242-
public Project(ProjectRole projectRole, String projectId) {
243-
super(Type.PROJECT, projectRole.name().toLowerCase() + "-" + projectId);
244-
this.projectRole = projectRole;
242+
public Project(ProjectRole pRole, String projectId) {
243+
super(Type.PROJECT, pRole.name().toLowerCase() + "-" + projectId);
244+
this.pRole = pRole;
245245
this.projectId = projectId;
246246
}
247247

248248
/**
249249
* Returns the role in the project for this entity.
250250
*/
251251
public ProjectRole projectRole() {
252-
return projectRole;
252+
return pRole;
253253
}
254254

255255
/**
@@ -275,7 +275,7 @@ String toPb() {
275275
}
276276

277277
/**
278-
* Creates an ACL object.
278+
* Creats an ACL object.
279279
*
280280
* @param entity the entity for this ACL object
281281
* @param role the role to associate to the {@code entity} object

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static <T extends Serializable> Result<T> empty() {
113113
}
114114
}
115115

116-
BatchResponse(List<Result<Boolean>> deleteResult, List<Result<BlobInfo>> updateResult,
116+
public BatchResponse(List<Result<Boolean>> deleteResult, List<Result<BlobInfo>> updateResult,
117117
List<Result<BlobInfo>> getResult) {
118118
this.deleteResult = ImmutableList.copyOf(deleteResult);
119119
this.updateResult = ImmutableList.copyOf(updateResult);

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
/**
4040
* A Google cloud storage object.
4141
*
42-
* <p>Objects of this class are immutable. Operations that modify the blob like {@link #update} and
42+
* <p>
43+
* Objects of this class are immutable. Operations that modify the blob like {@link #update} and
4344
* {@link #copyTo} return a new object. To get a {@code Blob} object with the most recent
4445
* information use {@link #reload}.
4546
* </p>
@@ -238,13 +239,13 @@ public Blob reload(BlobSourceOption... options) {
238239
* made on the metadata generation of the current blob. If you want to update the information only
239240
* if the current blob metadata are at their latest version use the {@code metagenerationMatch}
240241
* option: {@code blob.update(newInfo, BlobTargetOption.metagenerationMatch())}.
241-
*
242-
* <p>Original metadata are merged with metadata in the provided {@code blobInfo}. To replace
242+
* <p>
243+
* Original metadata are merged with metadata in the provided {@code blobInfo}. To replace
243244
* metadata instead you first have to unset them. Unsetting metadata can be done by setting the
244245
* provided {@code blobInfo}'s metadata to {@code null}.
245246
* </p>
246-
*
247-
* <p>Example usage of replacing blob's metadata:
247+
* <p>
248+
* Example usage of replacing blob's metadata:
248249
* <pre> {@code blob.update(blob.info().toBuilder().metadata(null).build());}
249250
* {@code blob.update(blob.info().toBuilder().metadata(newMetadata).build());}
250251
* </pre>
@@ -260,17 +261,6 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
260261
return new Blob(storage, storage.update(blobInfo, options));
261262
}
262263

263-
/**
264-
* Deletes this blob.
265-
*
266-
* @param options blob delete options
267-
* @return {@code true} if blob was deleted, {@code false} if it was not found
268-
* @throws StorageException upon failure
269-
*/
270-
public boolean delete(BlobSourceOption... options) {
271-
return storage.delete(info.blobId(), toSourceOptions(info, options));
272-
}
273-
274264
/**
275265
* Sends a copy request for the current blob to the target blob. Possibly also some of the
276266
* metadata are copied (e.g. content-type).
@@ -287,6 +277,17 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
287277
return storage.copy(copyRequest);
288278
}
289279

280+
/**
281+
* Deletes this blob.
282+
*
283+
* @param options blob delete options
284+
* @return {@code true} if blob was deleted, {@code false} if it was not found
285+
* @throws StorageException upon failure
286+
*/
287+
public boolean delete(BlobSourceOption... options) {
288+
return storage.delete(info.blobId(), toSourceOptions(info, options));
289+
}
290+
290291
/**
291292
* Sends a copy request for the current blob to the target bucket, preserving its name. Possibly
292293
* copying also some of the metadata (e.g. content-type).
@@ -380,8 +381,8 @@ public static List<Blob> get(final Storage storage, BlobId... blobs) {
380381
return Collections.unmodifiableList(Lists.transform(storage.get(blobs),
381382
new Function<BlobInfo, Blob>() {
382383
@Override
383-
public Blob apply(BlobInfo blobInfo) {
384-
return blobInfo != null ? new Blob(storage, blobInfo) : null;
384+
public Blob apply(BlobInfo f) {
385+
return f != null ? new Blob(storage, f) : null;
385386
}
386387
}));
387388
}
@@ -409,8 +410,8 @@ public static List<Blob> update(final Storage storage, BlobInfo... infos) {
409410
return Collections.unmodifiableList(Lists.transform(storage.update(infos),
410411
new Function<BlobInfo, Blob>() {
411412
@Override
412-
public Blob apply(BlobInfo blobInfo) {
413-
return blobInfo != null ? new Blob(storage, blobInfo) : null;
413+
public Blob apply(BlobInfo f) {
414+
return f != null ? new Blob(storage, f) : null;
414415
}
415416
}));
416417
}

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ Builder mediaLink(String mediaLink) {
277277
*/
278278
public Builder metadata(Map<String, String> metadata) {
279279
this.metadata = metadata != null
280-
? new HashMap<>(metadata) : Data.<Map<String, String>>nullOf(ImmutableEmptyMap.class);
280+
? new HashMap(metadata) : Data.<Map>nullOf(ImmutableEmptyMap.class);
281281
return this;
282282
}
283283

@@ -576,9 +576,8 @@ public ObjectAccessControl apply(Acl acl) {
576576
Map<String, String> pbMetadata = metadata;
577577
if (metadata != null && !Data.isNull(metadata)) {
578578
pbMetadata = Maps.newHashMapWithExpectedSize(metadata.size());
579-
for (Map.Entry<String, String> entry : metadata.entrySet()) {
580-
pbMetadata.put(entry.getKey(),
581-
firstNonNull(entry.getValue(), Data.<String>nullOf(String.class)));
579+
for (String key : metadata.keySet()) {
580+
pbMetadata.put(key, firstNonNull(metadata.get(key), Data.<String>nullOf(String.class)));
582581
}
583582
}
584583
storageObject.setMetadata(pbMetadata);

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
/**
2727
* A channel for reading data from a Google Cloud Storage object.
2828
*
29-
* <p>Implementations of this class may buffer data internally to reduce remote calls. This
30-
* interface implements {@link Restorable} to allow saving the reader's state to continue reading
31-
* afterwards.
32-
* </p>
29+
* Implementations of this class may buffer data internally to reduce remote calls. This interface
30+
* implements {@link Restorable} to allow saving the reader's state to continue reading afterwards.
3331
*/
3432
public interface BlobReadChannel extends ReadableByteChannel, Closeable,
3533
Restorable<BlobReadChannel> {

0 commit comments

Comments
 (0)