Skip to content

Conversation

@frankyn
Copy link
Contributor

@frankyn frankyn commented Jun 2, 2022

Introducing more support for BucketInfo conversions

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: storage Issues related to the googleapis/java-storage API. labels Jun 2, 2022
@frankyn frankyn force-pushed the bucket-info-feat branch 2 times, most recently from daa1619 to de73884 Compare June 3, 2022 16:39
@frankyn frankyn force-pushed the bucket-info-feat branch from de73884 to df3df98 Compare June 3, 2022 17:03
}

/**
* Returns the date in RFC 3339 format with only the date part (for instance, "2013-01-15").
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OffesetDateTime isn't exactly an RFC 3339 date.

I think we'll want to change the comment here to be a bit more explicit. Something like:

Returns the date and offset from UTC for this condition.
If a time other than 00:00:00.000 is present in the value, GCS will truncate to 00:00:00.000.

import net.jqwik.api.Property;

final class BucketPropertyTest {
final class BucketInfoPropertyTest extends BaseConvertablePropertyTest<BucketInfo, Bucket> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

.offsetBetween(ZoneOffset.UTC, ZoneOffset.UTC)
.map(
odt -> {
OffsetDateTime utc = odt.withOffsetSameInstant(ZoneOffset.UTC);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this transform here, the input has previously been constrained to UTC.

return rule()
.list()
.ofMinSize(0)
.ofMaxSize(100)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an actual limit on the gcs side for how many rules can be present? If so it might make sense to use a similar value here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was 100 but i can't seem to find a limit. I can remove the upperbound but 100 feels okay to me. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100's probably fine in that case. We probably won't want to somehow end up slowing down tests because the generator needs to construct like 700k of these things.

Comment on lines 634 to 636
if (createdBefore == null) return this;
return setCreateBeforeOffsetDateTime(
millisOffsetDateTimeCodec.encode(createdBefore.getValue()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the getter, I think this can be simplified to

Suggested change
if (createdBefore == null) return this;
return setCreateBeforeOffsetDateTime(
millisOffsetDateTimeCodec.encode(createdBefore.getValue()));
return setCustomTimeBeforeOffsetDateTime(
Utils.dateTimeCodec.nullable().decode(customTimeBefore));

Comment on lines 700 to 702
if (noncurrentTimeBefore == null) return this;
return setNoncurrentTimeBeforeOffsetDateTime(
millisOffsetDateTimeCodec.encode(noncurrentTimeBefore.getValue()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #setCustomDateTime

Comment on lines 726 to 728
if (customTimeBefore == null) return this;
return setCustomTimeBeforeOffsetDateTime(
millisOffsetDateTimeCodec.encode(customTimeBefore.getValue()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #setCustomDateTime

if (createdBefore == null) return this;
return setCreateBeforeOffsetDateTime(
millisOffsetDateTimeCodec.encode(createdBefore.getValue()));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, when using the Utils.dateTimeCodec.nullable() you'll want to put that in a variable so it doesn't construct a new codec instance each time.

Comment on lines 198 to 203
if (from.getWebsite() != null
|| from.getWebsite().getMainPageSuffix() != null
|| from.getWebsite().getNotFoundPage() != null) {
to.setIndexPage(from.getWebsite().getMainPageSuffix());
to.setNotFoundPage(from.getWebsite().getNotFoundPage());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the proto definition, both of these properties are non-optional.

message Website {
// If the requested object path is missing, the service will ensure the path
// has a trailing '/', append this suffix, and attempt to retrieve the
// resulting object. This allows the creation of `index.html`
// objects to represent directory pages.
string main_page_suffix = 1;
// If the requested object path is missing, and any
// `mainPageSuffix` object is missing, if applicable, the service
// will return the named object from this bucket as the content for a
// [https://tools.ietf.org/html/rfc7231#section-6.5.4][404 Not Found]
// result.
string not_found_page = 2;
}

This if condition can be simplified to:

if (from.hasWebsite())

actionBuilder.setStorageClass(s);
}
return actionBuilder.build();
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the previous version easier to read, but if you feel this is easier feel free to keep it.

Copy link
Collaborator

@BenWhitehead BenWhitehead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor requests to update some of the javadocs. I'll approve so you can merge after updating those items.

* truncated. This condition is satisfied when the custom time on an object is before this
* date in UTC.
*
* @deprecated {@link #setCustomTimeBeforeOffsetDateTime(OffsetDateTime)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the Use on this statement like the others

/**
* Returns the date in RFC 3339 format with only the date part (for instance, "2013-01-15").
*
* @deprecated {@link #getNoncurrentTimeBeforeOffsetDateTime()}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the Use on this statement like the others

Comment on lines 704 to 709
/**
* Sets the date in RFC 3339 format with only the date part (for instance, "2013-01-15").
* Note that only date part will be considered, if the time is specified it will be
* truncated. This condition is satisfied when the noncurrent time on an object is before
* this date. This condition is relevant only for versioned objects.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop the RFC 3339 part of this statement?

}

/**
* Sets the date in RFC 3339 format with only the date part (for instance, "2013-01-15").
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop the RFC 3339 part of this statement.

@frankyn frankyn marked this pull request as ready for review June 6, 2022 17:55
@frankyn frankyn requested review from a team as code owners June 6, 2022 17:55
Utils.toImmutableListOf(lifecycleRule()::encode),
lifecycleBuilder::addAllRule);
/*
// Corruption occurs by having deleteRule() values added
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenWhitehead deleteRule() corrupts the policy and I commented it out. I can do a follow-up PR to better handle this case as this PR is long. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@frankyn frankyn merged commit 500b73f into feat/grpc-storage Jun 6, 2022
@frankyn frankyn deleted the bucket-info-feat branch June 6, 2022 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/java-storage API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants