mirror of https://github.com/apache/jclouds.git
Implement create/list/deleteSnapshot in the Cloudstack API
This commit is contained in:
parent
e9cff5e17c
commit
16771961e1
|
@ -0,0 +1,401 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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 org.jclouds.cloudstack.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class Snapshot implements Comparable<Snapshot> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private long id;
|
||||
private String account;
|
||||
private Date created;
|
||||
private String domain;
|
||||
private long domainId;
|
||||
private SnapshotIntervalType intervalType;
|
||||
private long jobId;
|
||||
private String jobStatus;
|
||||
private String name;
|
||||
private SnapshotType snapshotType;
|
||||
private SnapshotState state;
|
||||
private long volumeId;
|
||||
private String volumeName;
|
||||
private String volumeType;
|
||||
|
||||
/**
|
||||
* @param id ID of the snapshot
|
||||
*/
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param account the account associated with the snapshot
|
||||
*/
|
||||
public Builder account(String account) {
|
||||
this.account = account;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param created the date the snapshot was created
|
||||
*/
|
||||
public Builder created(Date created) {
|
||||
this.created = created;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domain the domain name of the snapshot's account
|
||||
*/
|
||||
public Builder domain(String domain) {
|
||||
this.domain = domain;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId the domain ID of the snapshot's account
|
||||
*/
|
||||
public Builder domainId(long domainId) {
|
||||
this.domainId = domainId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param intervalType valid types are hourly, daily, weekly, monthy, template, and none.
|
||||
*/
|
||||
public Builder intervalType(SnapshotIntervalType intervalType) {
|
||||
this.intervalType = intervalType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jobId the job ID associated with the snapshot. This is only displayed if the snapshot listed is part of a currently running asynchronous job.
|
||||
*/
|
||||
public Builder jobId(long jobId) {
|
||||
this.jobId = jobId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jobStatus the job status associated with the snapshot. This is only displayed if the snapshot listed is part of a currently running asynchronous job.
|
||||
*/
|
||||
public Builder jobStatus(String jobStatus) {
|
||||
this.jobStatus = jobStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name name of the snapshot
|
||||
*/
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param snapshotType the type of the snapshot
|
||||
*/
|
||||
public Builder snapshotType(SnapshotType snapshotType) {
|
||||
this.snapshotType = snapshotType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state the state of the snapshot. BackedUp means that snapshot is ready to be used; Creating - the snapshot is being allocated on the primary storage; BackingUp - the snapshot is being backed up on secondary storage
|
||||
*/
|
||||
public Builder state(SnapshotState state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param volumeId ID of the disk volume
|
||||
*/
|
||||
public Builder volumeId(long volumeId) {
|
||||
this.volumeId = volumeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param volumeName name of the disk volume
|
||||
*/
|
||||
public Builder volumeName(String volumeName) {
|
||||
this.volumeName = volumeName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param volumeType type of the disk volume
|
||||
*/
|
||||
public Builder volumeType(String volumeType) {
|
||||
this.volumeType = volumeType;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum SnapshotState {
|
||||
|
||||
BackedUp, Creating, BackingUp, UNRECOGNIZED;
|
||||
|
||||
public static SnapshotState fromValue(String type) {
|
||||
try {
|
||||
return valueOf(checkNotNull(type, "type"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SnapshotType {
|
||||
|
||||
MANUAL, RECURRING, UNRECOGNIZED;
|
||||
|
||||
public static SnapshotType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(checkNotNull(type, "type"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SnapshotIntervalType {
|
||||
|
||||
HOURLY, DAILY, WEEKLY, MONTHLY, template, none, UNRECOGNIZED;
|
||||
|
||||
public static SnapshotIntervalType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(checkNotNull(type, "type"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long id;
|
||||
private String account;
|
||||
private Date created;
|
||||
private String domain;
|
||||
@SerializedName("domainid")
|
||||
private long domainId;
|
||||
@SerializedName("intervaltype")
|
||||
private SnapshotIntervalType intervalType;
|
||||
@SerializedName("jobid")
|
||||
private long jobId;
|
||||
@SerializedName("jobstatus")
|
||||
private String jobStatus;
|
||||
private String name;
|
||||
@SerializedName("snapshottype")
|
||||
private SnapshotType snapshotType;
|
||||
private SnapshotState state;
|
||||
@SerializedName("volumeid")
|
||||
private long volumeId;
|
||||
@SerializedName("volumename")
|
||||
private String volumeName;
|
||||
@SerializedName("volumetype")
|
||||
private String volumeType; // FIXME: replace this with a proper enumerated type (blocked until volume API implemented)
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*/
|
||||
Snapshot() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ID of the snapshot
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the account associated with the snapshot
|
||||
*/
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the date the snapshot was created
|
||||
*/
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the domain name of the snapshot's account
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the domain ID of the snapshot's account
|
||||
*/
|
||||
public long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return valid types are hourly, daily, weekly, monthy, template, and none.
|
||||
*/
|
||||
public SnapshotIntervalType getIntervalType() {
|
||||
return intervalType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the job ID associated with the snapshot. This is only displayed if the snapshot listed is part of a currently running asynchronous job.
|
||||
*/
|
||||
public long getJobId() {
|
||||
return jobId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the job status associated with the snapshot. This is only displayed if the snapshot listed is part of a currently running asynchronous job.
|
||||
*/
|
||||
public String getJobStatus() {
|
||||
return jobStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of the snapshot
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type of the snapshot
|
||||
*/
|
||||
public SnapshotType getSnapshotType() {
|
||||
return snapshotType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the state of the snapshot. BackedUp means that snapshot is ready to be used; Creating - the snapshot is being allocated on the primary storage; BackingUp - the snapshot is being backed up on secondary storage
|
||||
*/
|
||||
public SnapshotState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ID of the disk volume
|
||||
*/
|
||||
public long getVolumeId() {
|
||||
return volumeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of the disk volume
|
||||
*/
|
||||
public String getVolumeName() {
|
||||
return volumeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return type of the disk volume
|
||||
*/
|
||||
public String getVolumeType() {
|
||||
return volumeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Snapshot snapshot = (Snapshot) o;
|
||||
|
||||
if (domainId != snapshot.domainId) return false;
|
||||
if (id != snapshot.id) return false;
|
||||
if (jobId != snapshot.jobId) return false;
|
||||
if (volumeId != snapshot.volumeId) return false;
|
||||
if (account != null ? !account.equals(snapshot.account) : snapshot.account != null) return false;
|
||||
if (created != null ? !created.equals(snapshot.created) : snapshot.created != null) return false;
|
||||
if (domain != null ? !domain.equals(snapshot.domain) : snapshot.domain != null) return false;
|
||||
if (intervalType != snapshot.intervalType) return false;
|
||||
if (jobStatus != null ? !jobStatus.equals(snapshot.jobStatus) : snapshot.jobStatus != null) return false;
|
||||
if (name != null ? !name.equals(snapshot.name) : snapshot.name != null) return false;
|
||||
if (snapshotType != snapshot.snapshotType) return false;
|
||||
if (state != snapshot.state) return false;
|
||||
if (volumeName != null ? !volumeName.equals(snapshot.volumeName) : snapshot.volumeName != null) return false;
|
||||
if (volumeType != null ? !volumeType.equals(snapshot.volumeType) : snapshot.volumeType != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (id ^ (id >>> 32));
|
||||
result = 31 * result + (account != null ? account.hashCode() : 0);
|
||||
result = 31 * result + (created != null ? created.hashCode() : 0);
|
||||
result = 31 * result + (domain != null ? domain.hashCode() : 0);
|
||||
result = 31 * result + (int) (domainId ^ (domainId >>> 32));
|
||||
result = 31 * result + (intervalType != null ? intervalType.hashCode() : 0);
|
||||
result = 31 * result + (int) (jobId ^ (jobId >>> 32));
|
||||
result = 31 * result + (jobStatus != null ? jobStatus.hashCode() : 0);
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (snapshotType != null ? snapshotType.hashCode() : 0);
|
||||
result = 31 * result + (state != null ? state.hashCode() : 0);
|
||||
result = 31 * result + (int) (volumeId ^ (volumeId >>> 32));
|
||||
result = 31 * result + (volumeName != null ? volumeName.hashCode() : 0);
|
||||
result = 31 * result + (volumeType != null ? volumeType.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Snapshot[" +
|
||||
"id=" + id +
|
||||
", account='" + account + '\'' +
|
||||
", created=" + created +
|
||||
", domain='" + domain + '\'' +
|
||||
", domainId=" + domainId +
|
||||
", intervalType=" + intervalType +
|
||||
", jobId=" + jobId +
|
||||
", jobStatus='" + jobStatus + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", snapshotType=" + snapshotType +
|
||||
", state=" + state +
|
||||
", volumeId=" + volumeId +
|
||||
", volumeName='" + volumeName + '\'' +
|
||||
", volumeType='" + volumeType + '\'' +
|
||||
']';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Snapshot other) {
|
||||
return new Long(this.id).compareTo(other.getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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 org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.Snapshot;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.CreateSnapshotOptions;
|
||||
import org.jclouds.cloudstack.options.ListSnapshotsOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack Snapshot features.
|
||||
* <p/>
|
||||
*
|
||||
* @see SnapshotClient
|
||||
* @see http://download.cloud.com/releases/2.2.0/api/TOC_User.html
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface SnapshotAsyncClient {
|
||||
|
||||
/**
|
||||
* Creates an instant snapshot of a volume.
|
||||
*
|
||||
* @param volumeId The ID of the disk volume
|
||||
* @param options optional arguments
|
||||
* @return an asynchronous job structure
|
||||
*/
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@QueryParams(keys = "command", values = "createSnapshot")
|
||||
@Unwrap
|
||||
ListenableFuture<AsyncCreateResponse> createSnapshot(@QueryParam("volumeid") long volumeId, CreateSnapshotOptions... options);
|
||||
|
||||
/**
|
||||
* Lists all available snapshots for the account, matching the query described by the options.
|
||||
*
|
||||
* @param options optional arguments
|
||||
* @return the snapshots matching the query
|
||||
*/
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@QueryParams(keys = "command", values = "listSnapshots")
|
||||
@Unwrap
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Snapshot>> listSnapshots(ListSnapshotsOptions... options);
|
||||
|
||||
/**
|
||||
* Deletes a snapshot of a disk volume.
|
||||
*
|
||||
* @param id The ID of the snapshot
|
||||
* @return an asynchronous job structure
|
||||
*/
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@QueryParams(keys = "command", values = "deleteSnapshot")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteSnapshot(@QueryParam("id") long id);
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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 org.jclouds.cloudstack.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.Snapshot;
|
||||
import org.jclouds.cloudstack.options.CreateSnapshotOptions;
|
||||
import org.jclouds.cloudstack.options.ListSnapshotsOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack Snapshot features.
|
||||
* <p/>
|
||||
*
|
||||
* @see SnapshotAsyncClient
|
||||
* @see http://download.cloud.com/releases/2.2.0/api/TOC_User.html
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface SnapshotClient {
|
||||
|
||||
/**
|
||||
* Creates an instant snapshot of a volume.
|
||||
*
|
||||
* @param volumeId The ID of the disk volume
|
||||
* @param options optional arguments
|
||||
* @return an asynchronous job structure
|
||||
*/
|
||||
AsyncCreateResponse createSnapshot(long volumeId, CreateSnapshotOptions... options);
|
||||
|
||||
/**
|
||||
* Lists all available snapshots for the account, matching the query described by the options.
|
||||
*
|
||||
* @param options optional arguments
|
||||
* @return the snapshots matching the query
|
||||
*/
|
||||
Set<Snapshot> listSnapshots(ListSnapshotsOptions... options);
|
||||
|
||||
/**
|
||||
* Deletes a snapshot of a disk volume.
|
||||
*
|
||||
* @param id The ID of the snapshot
|
||||
* @return an asynchronous job structure
|
||||
*/
|
||||
void deleteSnapshot(long id);
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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 org.jclouds.cloudstack.options;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options for the Snapshot createSnapshot method.
|
||||
*
|
||||
* @see org.jclouds.cloudstack.features.SnapshotClient#createSnapshot
|
||||
* @see org.jclouds.cloudstack.features.SnapshotAsyncClient#createSnapshot
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class CreateSnapshotOptions extends AccountInDomainOptions {
|
||||
|
||||
public static final CreateSnapshotOptions NONE = new CreateSnapshotOptions();
|
||||
|
||||
/**
|
||||
* @param policyId policy id of the snapshot, if this is null, then use MANUAL_POLICY.
|
||||
*/
|
||||
public CreateSnapshotOptions policyId(long policyId) {
|
||||
this.queryParameters.replaceValues("policyid", ImmutableSet.of(policyId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @param account The account of the snapshot.
|
||||
* @param domainId The domain ID of the snapshot.
|
||||
*/
|
||||
public static CreateSnapshotOptions accountInDomain(String account, long domainId) {
|
||||
return (CreateSnapshotOptions) new CreateSnapshotOptions().accountInDomain(account, domainId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId The domain ID of the snapshot.
|
||||
*/
|
||||
public static CreateSnapshotOptions domainId(long domainId) {
|
||||
return (CreateSnapshotOptions) new CreateSnapshotOptions().domainId(domainId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param policyId policy id of the snapshot, if this is null, then use MANUAL_POLICY.
|
||||
*/
|
||||
public static CreateSnapshotOptions policyId(long policyId) {
|
||||
return new CreateSnapshotOptions().policyId(policyId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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 org.jclouds.cloudstack.options;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.cloudstack.domain.Snapshot;
|
||||
|
||||
/**
|
||||
* Options for the Snapshot listSnapshots method.
|
||||
*
|
||||
* @see org.jclouds.cloudstack.features.SnapshotClient#listSnapshots
|
||||
* @see org.jclouds.cloudstack.features.SnapshotAsyncClient#listSnapshots
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class ListSnapshotsOptions extends AccountInDomainOptions {
|
||||
|
||||
public static final ListSnapshotsOptions NONE = new ListSnapshotsOptions();
|
||||
|
||||
/**
|
||||
* @param id lists snapshot by snapshot ID
|
||||
*/
|
||||
public ListSnapshotsOptions id(long id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param intervalType valid values are HOURLY, DAILY, WEEKLY, and MONTHLY.
|
||||
*/
|
||||
public ListSnapshotsOptions intervalType(Snapshot.SnapshotIntervalType intervalType) {
|
||||
this.queryParameters.replaceValues("intervaltype", ImmutableSet.of(intervalType + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isRecursive defaults to false, but if true, lists all snapshots from the parent specified by the domain id till leaves.
|
||||
*/
|
||||
public ListSnapshotsOptions isRecursive(boolean isRecursive) {
|
||||
this.queryParameters.replaceValues("isrecursive", ImmutableSet.of(isRecursive + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param keyword List by keyword
|
||||
*/
|
||||
public ListSnapshotsOptions keyword(String keyword) {
|
||||
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name lists snapshot by snapshot name
|
||||
*/
|
||||
public ListSnapshotsOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param snapshotType valid values are MANUAL or RECURRING.
|
||||
*/
|
||||
public ListSnapshotsOptions snapshotType(Snapshot.SnapshotType snapshotType) {
|
||||
this.queryParameters.replaceValues("snapshottype", ImmutableSet.of(snapshotType + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param volumeId the ID of the disk volume
|
||||
*/
|
||||
public ListSnapshotsOptions volumeId(long volumeId) {
|
||||
this.queryParameters.replaceValues("volumeid", ImmutableSet.of(volumeId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @param account lists snapshot belonging to the specified account.
|
||||
* @param domainId The domain ID.
|
||||
*/
|
||||
public static ListSnapshotsOptions accountInDomain(String account, long domainId) {
|
||||
return (ListSnapshotsOptions) new ListSnapshotsOptions().accountInDomain(account, domainId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId the domain ID.
|
||||
*/
|
||||
public static ListSnapshotsOptions domainId(long domainId) {
|
||||
return (ListSnapshotsOptions) new ListSnapshotsOptions().domainId(domainId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id lists snapshot by snapshot ID
|
||||
*/
|
||||
public static ListSnapshotsOptions id(long id) {
|
||||
return new ListSnapshotsOptions().id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param intervalType valid values are HOURLY, DAILY, WEEKLY, and MONTHLY.
|
||||
*/
|
||||
public static ListSnapshotsOptions intervalType(Snapshot.SnapshotIntervalType intervalType) {
|
||||
return new ListSnapshotsOptions().intervalType(intervalType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isRecursive defaults to false, but if true, lists all snapshots from the parent specified by the domain id till leaves.
|
||||
*/
|
||||
public static ListSnapshotsOptions isRecursive(boolean isRecursive) {
|
||||
return new ListSnapshotsOptions().isRecursive(isRecursive);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param keyword List by keyword
|
||||
*/
|
||||
public static ListSnapshotsOptions keyword(String keyword) {
|
||||
return new ListSnapshotsOptions().keyword(keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name lists snapshot by snapshot name
|
||||
*/
|
||||
public static ListSnapshotsOptions name(String name) {
|
||||
return new ListSnapshotsOptions().name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param snapshotType valid values are MANUAL or RECURRING.
|
||||
*/
|
||||
public static ListSnapshotsOptions snapshotType(Snapshot.SnapshotType snapshotType) {
|
||||
return new ListSnapshotsOptions().snapshotType(snapshotType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param volumeId the ID of the disk volume
|
||||
*/
|
||||
public static ListSnapshotsOptions volumeId(long volumeId) {
|
||||
return new ListSnapshotsOptions().volumeId(volumeId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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 org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.cloudstack.domain.Snapshot;
|
||||
import org.jclouds.cloudstack.options.CreateSnapshotOptions;
|
||||
import org.jclouds.cloudstack.options.ListSnapshotsOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Tests the behaviour of SnapshotAsyncClient.
|
||||
*
|
||||
* @see SnapshotAsyncClient
|
||||
* @author Richard Downer
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during
|
||||
// surefire
|
||||
@Test(groups = "unit", testName = "SnapshotAsyncClientTest")
|
||||
public class SnapshotAsyncClientTest extends BaseCloudStackAsyncClientTest<SnapshotAsyncClient> {
|
||||
|
||||
public void testCreateSnapshot() throws NoSuchMethodException {
|
||||
Method method = SnapshotAsyncClient.class.getMethod("createSnapshot", long.class, CreateSnapshotOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=createSnapshot&volumeid=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testCreateSnapshotOptions() throws NoSuchMethodException {
|
||||
Method method = SnapshotAsyncClient.class.getMethod("createSnapshot", long.class, CreateSnapshotOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5, CreateSnapshotOptions.Builder.accountInDomain("acc", 7).policyId(9));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=createSnapshot&volumeid=5&account=acc&domainid=7&policyid=9 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testListSnapshots() throws NoSuchMethodException {
|
||||
Method method = SnapshotAsyncClient.class.getMethod("listSnapshots", ListSnapshotsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listSnapshots HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testListSnapshotsOptions() throws NoSuchMethodException {
|
||||
Method method = SnapshotAsyncClient.class.getMethod("listSnapshots", ListSnapshotsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListSnapshotsOptions.Builder.accountInDomain("acc", 7).id(5).intervalType(Snapshot.SnapshotIntervalType.MONTHLY).isRecursive(true).keyword("fred").name("fred's snapshot").snapshotType(Snapshot.SnapshotType.RECURRING).volumeId(11));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listSnapshots&account=acc&domainid=7&id=5&intervaltype=MONTHLY&isrecursive=true&keyword=fred&name=fred%27s%20snapshot&snapshottype=RECURRING&volumeid=11 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testDeleteSnapshot() throws NoSuchMethodException {
|
||||
Method method = SnapshotAsyncClient.class.getMethod("deleteSnapshot", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 14);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=deleteSnapshot&id=14 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<SnapshotAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<SnapshotAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue