Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functional methods for disks and Disk class #870

Merged
merged 2 commits into from Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcloud-java-compute/pom.xml
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-compute</artifactId>
<version>v1-rev97-1.21.0</version>
<version>v1-rev103-1.21.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Expand Up @@ -161,7 +161,6 @@ enum ZoneField {
CREATION_TIMESTAMP("creationTimestamp"),
DESCRIPTION("description"),
ID("id"),
MAINTENANCE_WINDOWS("maintenanceWindows"),
NAME("name"),
REGION("region"),
SELF_LINK("selfLink"),
Expand Down Expand Up @@ -917,6 +916,54 @@ public static ImageFilter notEquals(ImageField field, long value) {
}
}

/**
* Class for filtering disk lists.
*/
class DiskFilter extends ListFilter {

private static final long serialVersionUID = 5856790665396877913L;

private DiskFilter(DiskField field, ComparisonOperator operator, Object value) {
super(field.selector(), operator, value);
}

/**
* Returns an equals filter for the given field and string value. For string fields,
* {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
* match the entire field.
*
* @see <a href="https://github.com/google/re2/wiki/Syntax">RE2</a>
*/
public static DiskFilter equals(DiskField field, String value) {
return new DiskFilter(checkNotNull(field), ComparisonOperator.EQ, checkNotNull(value));
}

/**
* Returns a not-equals filter for the given field and string value. For string fields,
* {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
* match the entire field.
*
* @see <a href="https://github.com/google/re2/wiki/Syntax">RE2</a>
*/
public static DiskFilter notEquals(DiskField field, String value) {
return new DiskFilter(checkNotNull(field), ComparisonOperator.NE, checkNotNull(value));
}

/**
* Returns an equals filter for the given field and long value.
*/
public static DiskFilter equals(DiskField field, long value) {
return new DiskFilter(checkNotNull(field), ComparisonOperator.EQ, value);
}

/**
* Returns a not-equals filter for the given field and long value.
*/
public static DiskFilter notEquals(DiskField field, long value) {
return new DiskFilter(checkNotNull(field), ComparisonOperator.NE, value);
}
}

/**
* Class for specifying disk type get options.
*/
Expand Down Expand Up @@ -1585,6 +1632,112 @@ public static ImageListOption fields(ImageField... fields) {
}
}

/**
* Class for specifying disk get options.
*/
class DiskOption extends Option {

private static final long serialVersionUID = -4354796876226661667L;

private DiskOption(ComputeRpc.Option option, Object value) {
super(option, value);
}

/**
* Returns an option to specify the disk's fields to be returned by the RPC call. If this option
* is not provided, all disk's fields are returned. {@code DiskOption.fields} can be used to

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* specify only the fields of interest. {@link Disk#diskId()},
* {@link DiskConfiguration#diskType()} and either
* {@link SnapshotDiskConfiguration#sourceSnapshot()} or
* {@link ImageDiskConfiguration#sourceImage()} are always returned, even if not specified.
*/
public static DiskOption fields(DiskField... fields) {
return new DiskOption(ComputeRpc.Option.FIELDS, DiskField.selector(fields));
}
}

/**
* Class for specifying disk list options.
*/
class DiskListOption extends Option {

private static final long serialVersionUID = -5148497888688645905L;

private DiskListOption(ComputeRpc.Option option, Object value) {
super(option, value);
}

/**
* Returns an option to specify a filter on the disks being listed.
*/
public static DiskListOption filter(DiskFilter filter) {
return new DiskListOption(ComputeRpc.Option.FILTER, filter.toPb());
}

/**
* Returns an option to specify the maximum number of disks returned per page. {@code pageSize}
* must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static DiskListOption pageSize(long pageSize) {
return new DiskListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
}

/**
* Returns an option to specify the page token from which to start listing disks.
*/
public static DiskListOption pageToken(String pageToken) {
return new DiskListOption(ComputeRpc.Option.PAGE_TOKEN, pageToken);
}

/**
* Returns an option to specify the disk's fields to be returned by the RPC call. If this option
* is not provided, all disk's fields are returned. {@code DiskListOption.fields} can be used to

This comment was marked as spam.

* specify only the fields of interest. {@link Disk#diskId()},
* {@link DiskConfiguration#diskType()} and either
* {@link SnapshotDiskConfiguration#sourceSnapshot()} or
* {@link ImageDiskConfiguration#sourceImage()} are always returned, even if not specified.
*/
public static DiskListOption fields(DiskField... fields) {
StringBuilder builder = new StringBuilder();
builder.append("items(").append(DiskField.selector(fields)).append("),nextPageToken");
return new DiskListOption(ComputeRpc.Option.FIELDS, builder.toString());
}
}

/**
* Class for specifying disk aggregated list options.
*/
class DiskAggregatedListOption extends Option {

private static final long serialVersionUID = 1163784797870242766L;

private DiskAggregatedListOption(ComputeRpc.Option option, Object value) {
super(option, value);
}

/**
* Returns an option to specify a filter on the disks being listed.
*/
public static DiskAggregatedListOption filter(DiskFilter filter) {
return new DiskAggregatedListOption(ComputeRpc.Option.FILTER, filter.toPb());
}

/**
* Returns an option to specify the maximum number of disks returned per page. {@code pageSize}
* must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static DiskAggregatedListOption pageSize(long pageSize) {
return new DiskAggregatedListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
}

/**
* Returns an option to specify the page token from which to start listing disks.
*/
public static DiskAggregatedListOption pageToken(String pageToken) {
return new DiskAggregatedListOption(ComputeRpc.Option.PAGE_TOKEN, pageToken);
}
}

/**
* Returns the requested disk type or {@code null} if not found.
*
Expand Down Expand Up @@ -1770,8 +1923,7 @@ public static ImageListOption fields(ImageField... fields) {
/**
* Creates a new snapshot.
*
* @return a zone operation if the create request was issued correctly, {@code null} if
* {@code snapshot.sourceDisk} was not found
* @return a zone operation for snapshot creation
* @throws ComputeException upon failure
*/
Operation create(SnapshotInfo snapshot, OperationOption... options);
Expand Down Expand Up @@ -1868,4 +2020,51 @@ public static ImageListOption fields(ImageField... fields) {
*/
Operation deprecate(ImageId image, DeprecationStatus<ImageId> deprecationStatus,
OperationOption... options);

/**
* Returns the requested disk or {@code null} if not found.
*
* @throws ComputeException upon failure
*/
Disk get(DiskId diskId, DiskOption... options);

/**
* Creates a new disk.
*
* @return a zone operation for disk's creation
* @throws ComputeException upon failure
*/
Operation create(DiskInfo disk, OperationOption... options);

/**
* Lists disks for the provided zone.
*
* @throws ComputeException upon failure
*/
Page<Disk> listDisks(String zone, DiskListOption... options);

/**
* Lists disks for all zones.
*
* @throws ComputeException upon failure
*/
Page<Disk> listDisks(DiskAggregatedListOption... options);

/**
* Deletes the requested disk.
*
* @return a zone operation if the request was issued correctly, {@code null} if the disk was not
* found
* @throws ComputeException upon failure
*/
Operation delete(DiskId disk, OperationOption... options);

/**
* Resizes the disk to the requested size. The new size must be larger than the previous one.
*
* @return a zone operation if the request was issued correctly, {@code null} if the disk was not
* found
* @throws ComputeException upon failure or if the new disk size is smaller than the previous one
*/
Operation resize(DiskId disk, long sizeGb, OperationOption... options);
}