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

Added ProjectInfo. #590

Merged
merged 4 commits into from
Jan 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 286 additions & 0 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/ProjectInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gcloud.dns;

import static com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.MoreObjects;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Objects;

/**
* The class provides the Google Cloud DNS information associated with this project. A project is a
* top level container for resources including {@code ManagedZone}s. Projects can be created only in
* the APIs console.
*
* @see <a href="https://cloud.google.com/dns/api/v1/projects">Google Cloud DNS documentation</a>
*/
public class ProjectInfo implements Serializable {

private static final long serialVersionUID = 8696578863323485036L;
private final String id;
private final BigInteger number;
private final Quota quota;

/**
* This class represents quotas assigned to the {@code ProjectInfo}.
*
* @see <a href="https://cloud.google.com/dns/api/v1/projects#quota">Google Cloud DNS
* documentation</a>
*/
public static class Quota {

private final int zones;
private final int resourceRecordsPerRrset;
private final int rrsetAdditionsPerChange;
private final int rrsetDeletionsPerChange;
private final int rrsetsPerManagedZone;
private final int totalRrdataSizePerChange;

/**
* Creates an instance of {@code Quota}.
*
* <p>This is the only way of creating an instance of {@code Quota}. As the service does not
* allow for specifying options, quota is an "all-or-nothing object" and we do not need a
* builder.
*/
Quota(int zones,
int resourceRecordsPerRrset,
int rrsetAdditionsPerChange,
int rrsetDeletionsPerChange,
int rrsetsPerManagedZone,
int totalRrdataSizePerChange) {
this.zones = zones;
this.resourceRecordsPerRrset = resourceRecordsPerRrset;
this.rrsetAdditionsPerChange = rrsetAdditionsPerChange;
this.rrsetDeletionsPerChange = rrsetDeletionsPerChange;
this.rrsetsPerManagedZone = rrsetsPerManagedZone;
this.totalRrdataSizePerChange = totalRrdataSizePerChange;
}

/**
* Returns the maximum allowed number of managed zones in the project.
*/
public int zones() {
return zones;
}

/**
* Returns the maximum allowed number of records per {@link DnsRecord}.
*/
public int resourceRecordsPerRrset() {
return resourceRecordsPerRrset;
}

/**
* Returns the maximum allowed number of {@link DnsRecord}s to add per {@link ChangeRequest}.
*/
public int rrsetAdditionsPerChange() {
return rrsetAdditionsPerChange;
}

/**
* Returns the maximum allowed number of {@link DnsRecord}s to delete per {@link
* ChangeRequest}.
*/
public int rrsetDeletionsPerChange() {
return rrsetDeletionsPerChange;
}

/**
* Returns the maximum allowed number of {@link DnsRecord}s per {@link ManagedZoneInfo} in the
* project.
*/
public int rrsetsPerManagedZone() {
return rrsetsPerManagedZone;
}

/**
* Returns the maximum allowed size for total records in one ChangesRequest in bytes.
*/
public int totalRrdataSizePerChange() {
return totalRrdataSizePerChange;
}

@Override
public boolean equals(Object other) {
return (other instanceof Quota) && this.toPb().equals(((Quota) other).toPb());

This comment was marked as spam.

This comment was marked as spam.

}

@Override
public int hashCode() {
return Objects.hash(zones, resourceRecordsPerRrset, rrsetAdditionsPerChange,
rrsetDeletionsPerChange, rrsetsPerManagedZone, totalRrdataSizePerChange);
}

com.google.api.services.dns.model.Quota toPb() {
com.google.api.services.dns.model.Quota pb = new com.google.api.services.dns.model.Quota();
pb.setManagedZones(zones);
pb.setResourceRecordsPerRrset(resourceRecordsPerRrset);
pb.setRrsetAdditionsPerChange(rrsetAdditionsPerChange);
pb.setRrsetDeletionsPerChange(rrsetDeletionsPerChange);
pb.setRrsetsPerManagedZone(rrsetsPerManagedZone);
pb.setTotalRrdataSizePerChange(totalRrdataSizePerChange);
return pb;
}

static Quota fromPb(com.google.api.services.dns.model.Quota pb) {
Quota quota = new Quota(pb.getManagedZones(),
pb.getResourceRecordsPerRrset(),
pb.getRrsetAdditionsPerChange(),
pb.getRrsetDeletionsPerChange(),
pb.getRrsetsPerManagedZone(),
pb.getTotalRrdataSizePerChange()
);
return quota;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("zones", zones)
.add("resourceRecordsPerRrset", resourceRecordsPerRrset)
.add("rrsetAdditionsPerChange", rrsetAdditionsPerChange)
.add("rrsetDeletionsPerChange", rrsetDeletionsPerChange)
.add("rrsetsPerManagedZone", rrsetsPerManagedZone)
.add("totalRrdataSizePerChange", totalRrdataSizePerChange)
.toString();
}
}

/**
* A builder for {@code ProjectInfo}.
*/
static class Builder {
private String id;
private BigInteger number;
private Quota quota;

private Builder() {
}

/**
* Sets an id of the project.
*/
Builder id(String id) {
this.id = checkNotNull(id);

This comment was marked as spam.

This comment was marked as spam.

return this;
}

/**
* Sets a number of the project.
*/
Builder number(BigInteger number) {
this.number = checkNotNull(number);

This comment was marked as spam.

This comment was marked as spam.

return this;
}

/**
* Sets quotas assigned to the project.
*/
Builder quota(Quota quota) {
this.quota = checkNotNull(quota);
return this;
}

/**
* Builds an instance of the {@code ProjectInfo}.
*/
ProjectInfo build() {
return new ProjectInfo(this);
}
}

private ProjectInfo(Builder builder) {
this.id = builder.id;
this.number = builder.number;
this.quota = builder.quota;
}

/**
* Returns a builder for {@code ProjectInfo}.
*/
static Builder builder() {
return new Builder();
}

/**
* Returns the {@code Quota} object which contains quotas assigned to this project.
*/
public Quota quota() {
return quota;
}

/**
* Returns project number. For internal use only.
*/
BigInteger number() {
return number;
}

/**
* Returns project id. For internal use only.
*/
String id() {
return id;
}

com.google.api.services.dns.model.Project toPb() {
com.google.api.services.dns.model.Project pb = new com.google.api.services.dns.model.Project();
pb.setId(id);
pb.setNumber(number);
if (this.quota != null) {
pb.setQuota(quota.toPb());
}
return pb;
}

static ProjectInfo fromPb(com.google.api.services.dns.model.Project pb) {
Builder builder = builder();
if (pb.getId() != null) {
builder.id(pb.getId());
}
if (pb.getNumber() != null) {
builder.number(pb.getNumber());
}
if (pb.getQuota() != null) {
builder.quota(Quota.fromPb(pb.getQuota()));
}
return builder.build();
}

@Override
public boolean equals(Object other) {
return (other instanceof ProjectInfo) && toPb().equals(((ProjectInfo) other).toPb());
}

@Override
public int hashCode() {
return Objects.hash(id, number, quota);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.add("number", number)
.add("quota", quota)
.toString();
}
}
Loading