Skip to content
Permalink
Browse files
JCLOUDS-457: Added initiateJob
Now the Glacier client supports the initiateJob operation.
  • Loading branch information
rcoedo authored and gaul committed Jun 26, 2014
1 parent bce335a commit 5cf26f6f7a418c83b93ea1ee2c8495101cdb3a26
Showing 10 changed files with 544 additions and 0 deletions.
@@ -36,15 +36,18 @@
import org.jclouds.glacier.binders.BindContentRangeToHeaders;
import org.jclouds.glacier.binders.BindDescriptionToHeaders;
import org.jclouds.glacier.binders.BindHashesToHeaders;
import org.jclouds.glacier.binders.BindJobRequestToJsonPayload;
import org.jclouds.glacier.binders.BindMultipartTreeHashToHeaders;
import org.jclouds.glacier.binders.BindPartSizeToHeaders;
import org.jclouds.glacier.domain.JobRequest;
import org.jclouds.glacier.domain.MultipartUploadMetadata;
import org.jclouds.glacier.domain.PaginatedMultipartUploadCollection;
import org.jclouds.glacier.domain.PaginatedVaultCollection;
import org.jclouds.glacier.domain.VaultMetadata;
import org.jclouds.glacier.fallbacks.FalseOnIllegalArgumentException;
import org.jclouds.glacier.filters.RequestAuthorizeSignature;
import org.jclouds.glacier.functions.ParseArchiveIdHeader;
import org.jclouds.glacier.functions.ParseJobIdHeader;
import org.jclouds.glacier.functions.ParseMultipartUploadIdHeader;
import org.jclouds.glacier.functions.ParseMultipartUploadListFromHttpContent;
import org.jclouds.glacier.functions.ParseMultipartUploadPartListFromHttpContent;
@@ -262,4 +265,15 @@ ListenableFuture<PaginatedMultipartUploadCollection> listMultipartUploads(
@ResponseParser(ParseMultipartUploadListFromHttpContent.class)
ListenableFuture<PaginatedMultipartUploadCollection> listMultipartUploads(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName);

/**
* @see GlacierClient#initiateJob
*/
@Named("InitiateJob")
@POST
@Path("/-/vaults/{vault}/jobs")
@ResponseParser(ParseJobIdHeader.class)
ListenableFuture<String> initiateJob(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName,
@BinderParam(BindJobRequestToJsonPayload.class) JobRequest job);
}
@@ -20,6 +20,7 @@
import java.net.URI;
import java.util.Map;

import org.jclouds.glacier.domain.JobRequest;
import org.jclouds.glacier.domain.MultipartUploadMetadata;
import org.jclouds.glacier.domain.PaginatedMultipartUploadCollection;
import org.jclouds.glacier.domain.PaginatedVaultCollection;
@@ -218,4 +219,16 @@ public interface GlacierClient extends Closeable {
* Lists the multipart uploads in a vault.
*/
PaginatedMultipartUploadCollection listMultipartUploads(String vaultName);

/**
* Initiates a job.
*
* @param vaultName
* Name of the target Vault for the job.
* @param job
* JobRequest instance with the concrete request.
* @return The job identifier.
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-initiate-job-post.html" />
*/
String initiateJob(String vaultName, JobRequest job);
}
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.glacier.binders;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import org.jclouds.glacier.domain.JobRequest;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.Binder;

import com.google.inject.Inject;

public class BindJobRequestToJsonPayload implements Binder {
@Inject
private Json json;

@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof JobRequest,
"This binder is only valid for JobRequest");
checkNotNull(request, "request");
request.setPayload(json.toJson(input));
return request;
}
}
@@ -0,0 +1,117 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.glacier.domain;

import static com.google.common.base.Preconditions.checkNotNull;

import java.beans.ConstructorProperties;

import org.jclouds.glacier.util.ContentRange;
import org.jclouds.javax.annotation.Nullable;

import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;

public class ArchiveRetrievalJobRequest extends JobRequest {
private static final String TYPE = "archive-retrieval";

@SerializedName("ArchiveId")
private final String archiveId;
@SerializedName("Description")
private final String description;
@SerializedName("RetrievalByteRange")
private final ContentRange range;

private ArchiveRetrievalJobRequest(String archiveId, @Nullable String description, @Nullable ContentRange range) {
super(TYPE);
this.archiveId = checkNotNull(archiveId, "archiveId");
this.description = description;
this.range = range;
}

@ConstructorProperties({ "ArchiveId", "Description", "RetrievalByteRange" })
private ArchiveRetrievalJobRequest(String archiveId, @Nullable String description, @Nullable String range) {
this(archiveId, description, range == null ? null : ContentRange.fromString(range));
}

public String getDescription() {
return description;
}

public ContentRange getRange() {
return range;
}

public String getArchiveId() {
return archiveId;
}

@Override
public int hashCode() {
return Objects.hashCode(this.archiveId, this.description, this.range);
}

@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ArchiveRetrievalJobRequest other = (ArchiveRetrievalJobRequest) obj;

return Objects.equal(this.archiveId, other.archiveId) && Objects.equal(this.description, other.description)
&& Objects.equal(this.range, other.range);
}

@Override
public String toString() {
return "InventoryRetrievalParameters [archiveId=" + archiveId + ", description=" + description + ", range="
+ range + "]";
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private String archiveId;
private String description;
private ContentRange range;

Builder() {
}

public Builder archiveId(String archiveId) {
this.archiveId = archiveId;
return this;
}

public Builder description(String description) {
this.description = description;
return this;
}

public Builder range(ContentRange range) {
this.range = range;
return this;
}

public ArchiveRetrievalJobRequest build() {
return new ArchiveRetrievalJobRequest(archiveId, description, range);
}
}
}
@@ -0,0 +1,133 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.glacier.domain;

import java.beans.ConstructorProperties;

import org.jclouds.javax.annotation.Nullable;

import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;

public class InventoryRetrievalJobRequest extends JobRequest {
private static final String TYPE = "inventory-retrieval";

@SerializedName("Description")
private final String description;
@SerializedName("Format")
private final String format;
@SerializedName("InventoryRetrievalParameters")
private final InventoryRetrievalParameters parameters;

@ConstructorProperties({ "Description", "Format" })
private InventoryRetrievalJobRequest(@Nullable String description, @Nullable String format) {
super(TYPE);
this.description = description;
this.format = format;
this.parameters = new InventoryRetrievalParameters();
}

public String getDescription() {
return description;
}

public String getFormat() {
return format;
}

public InventoryRetrievalParameters getParameters() {
return this.parameters;
}

@Override
public int hashCode() {
return Objects.hashCode(this.description, this.format, this.parameters);
}

@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
InventoryRetrievalJobRequest other = (InventoryRetrievalJobRequest) obj;

return Objects.equal(this.description, other.description) && Objects.equal(this.format, other.format)
&& Objects.equal(this.parameters, other.parameters);
}

@Override
public String toString() {
return "InventoryRetrievalJobRequest [description=" + description + ", format=" + format + "," +
"parameters=" + parameters + "]";
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private String description;
private String format;
private String startDate;
private String endDate;
private Integer limit;
private String marker;

Builder() {
}

public Builder description(String description) {
this.description = description;
return this;
}

public Builder format(String format) {
this.format = format;
return this;
}

public Builder startDate(String startDate) {
this.startDate = startDate;
return this;
}

public Builder endDate(String endDate) {
this.endDate = endDate;
return this;
}

public Builder limit(Integer limit) {
this.limit = limit;
return this;
}

public Builder marker(String marker) {
this.marker = marker;
return this;
}

public InventoryRetrievalJobRequest build() {
InventoryRetrievalJobRequest request = new InventoryRetrievalJobRequest(description, format);
request.getParameters().setEndDate(endDate);
request.getParameters().setStartDate(startDate);
request.getParameters().setLimit(limit);
request.getParameters().setMarker(marker);
return request;
}
}
}

0 comments on commit 5cf26f6

Please sign in to comment.