mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 15:08:28 +00:00
Issue 191: updated to provide cookbook creation support
This commit is contained in:
parent
47a843dd24
commit
99e14159a0
@ -35,16 +35,19 @@ import javax.ws.rs.Path;
|
|||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.chef.binders.BindChecksumsToJsonPayload;
|
|
||||||
import org.jclouds.chef.binders.BindClientnameToJsonPayload;
|
import org.jclouds.chef.binders.BindClientnameToJsonPayload;
|
||||||
import org.jclouds.chef.binders.BindGenerateKeyForClientToJsonPayload;
|
import org.jclouds.chef.binders.BindGenerateKeyForClientToJsonPayload;
|
||||||
import org.jclouds.chef.domain.Cookbook;
|
import org.jclouds.chef.binders.BindIsCompletedToJsonPayload;
|
||||||
|
import org.jclouds.chef.binders.BindMD5sToJsonPayload;
|
||||||
|
import org.jclouds.chef.domain.CookbookVersion;
|
||||||
import org.jclouds.chef.domain.Sandbox;
|
import org.jclouds.chef.domain.Sandbox;
|
||||||
|
import org.jclouds.chef.domain.UploadSite;
|
||||||
import org.jclouds.chef.filters.SignedHeaderAuth;
|
import org.jclouds.chef.filters.SignedHeaderAuth;
|
||||||
import org.jclouds.chef.functions.ParseCookbookFromJson;
|
import org.jclouds.chef.functions.ParseCookbookVersionFromJson;
|
||||||
import org.jclouds.chef.functions.ParseKeyFromJson;
|
import org.jclouds.chef.functions.ParseKeyFromJson;
|
||||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||||
import org.jclouds.chef.functions.ParseSandboxFromJson;
|
import org.jclouds.chef.functions.ParseSandboxFromJson;
|
||||||
|
import org.jclouds.chef.functions.ParseUploadSiteFromJson;
|
||||||
import org.jclouds.chef.functions.ParseValueSetFromJson;
|
import org.jclouds.chef.functions.ParseValueSetFromJson;
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
import org.jclouds.rest.annotations.ExceptionParser;
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
@ -70,16 +73,25 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Headers(keys = "X-Chef-Version", values = ChefAsyncClient.VERSION)
|
@Headers(keys = "X-Chef-Version", values = ChefAsyncClient.VERSION)
|
||||||
public interface ChefAsyncClient {
|
public interface ChefAsyncClient {
|
||||||
public static final String VERSION = "0.9.0";
|
public static final String VERSION = "0.9.6";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefClient#getUploadUrisForContent
|
* @see ChefClient#getUploadUrisForChecksums
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("sandboxes")
|
@Path("sandboxes")
|
||||||
|
@ResponseParser(ParseUploadSiteFromJson.class)
|
||||||
|
ListenableFuture<UploadSite> getUploadSiteForChecksums(
|
||||||
|
@BinderParam(BindMD5sToJsonPayload.class) Set<byte[]> md5s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ChefClient#closeSandbox
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Path("sandboxes/{id}")
|
||||||
@ResponseParser(ParseSandboxFromJson.class)
|
@ResponseParser(ParseSandboxFromJson.class)
|
||||||
ListenableFuture<Sandbox> getUploadUrisForContent(
|
ListenableFuture<Sandbox> closeSandbox(@PathParam("id") String id,
|
||||||
@BinderParam(BindChecksumsToJsonPayload.class) Set<String> checksums);
|
@BinderParam(BindIsCompletedToJsonPayload.class) boolean isCompleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefCookbooks#listCookbooks
|
* @see ChefCookbooks#listCookbooks
|
||||||
@ -94,10 +106,9 @@ public interface ChefAsyncClient {
|
|||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path("cookbooks/{cookbookname}/{version}")
|
@Path("cookbooks/{cookbookname}/{version}")
|
||||||
ListenableFuture<Void> updateCookbook(
|
ListenableFuture<Void> updateCookbook(@PathParam("cookbookname") String cookbookName,
|
||||||
@PathParam("cookbookname") String cookbookName,
|
@PathParam("version") String version,
|
||||||
@PathParam("version") String version,
|
@BinderParam(BindToJsonPayload.class) CookbookVersion cookbook);
|
||||||
@BinderParam(BindToJsonPayload.class) Cookbook cookbook);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefCookbook#deleteCookbook(String)
|
* @see ChefCookbook#deleteCookbook(String)
|
||||||
@ -105,9 +116,8 @@ public interface ChefAsyncClient {
|
|||||||
@DELETE
|
@DELETE
|
||||||
@Path("cookbooks/{cookbookname}/{version}")
|
@Path("cookbooks/{cookbookname}/{version}")
|
||||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||||
ListenableFuture<Void> deleteCookbook(
|
ListenableFuture<Void> deleteCookbook(@PathParam("cookbookname") String cookbookName,
|
||||||
@PathParam("cookbookname") String cookbookName,
|
@PathParam("version") String version);
|
||||||
@PathParam("version") String version);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefCookbook#getVersionsOfCookbook
|
* @see ChefCookbook#getVersionsOfCookbook
|
||||||
@ -117,18 +127,17 @@ public interface ChefAsyncClient {
|
|||||||
@ResponseParser(ParseValueSetFromJson.class)
|
@ResponseParser(ParseValueSetFromJson.class)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Set<String>> getVersionsOfCookbook(
|
ListenableFuture<Set<String>> getVersionsOfCookbook(
|
||||||
@PathParam("cookbookname") String cookbookName);
|
@PathParam("cookbookname") String cookbookName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefCookbook#getCookbook
|
* @see ChefCookbook#getCookbook
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("cookbooks/{cookbookname}/{version}")
|
@Path("cookbooks/{cookbookname}/{version}")
|
||||||
@ResponseParser(ParseCookbookFromJson.class)
|
@ResponseParser(ParseCookbookVersionFromJson.class)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Cookbook> getCookbook(
|
ListenableFuture<CookbookVersion> getCookbook(@PathParam("cookbookname") String cookbookName,
|
||||||
@PathParam("cookbookname") String cookbookName,
|
@PathParam("version") String version);
|
||||||
@PathParam("version") String version);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefClient#createClient
|
* @see ChefClient#createClient
|
||||||
@ -137,7 +146,7 @@ public interface ChefAsyncClient {
|
|||||||
@Path("clients")
|
@Path("clients")
|
||||||
@ResponseParser(ParseKeyFromJson.class)
|
@ResponseParser(ParseKeyFromJson.class)
|
||||||
ListenableFuture<String> createClient(
|
ListenableFuture<String> createClient(
|
||||||
@BinderParam(BindClientnameToJsonPayload.class) String clientname);
|
@BinderParam(BindClientnameToJsonPayload.class) String clientname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefClient#generateKeyForClient
|
* @see ChefClient#generateKeyForClient
|
||||||
@ -146,7 +155,7 @@ public interface ChefAsyncClient {
|
|||||||
@Path("clients/{clientname}")
|
@Path("clients/{clientname}")
|
||||||
@ResponseParser(ParseKeyFromJson.class)
|
@ResponseParser(ParseKeyFromJson.class)
|
||||||
ListenableFuture<String> generateKeyForClient(
|
ListenableFuture<String> generateKeyForClient(
|
||||||
@PathParam("clientname") @BinderParam(BindGenerateKeyForClientToJsonPayload.class) String clientname);
|
@PathParam("clientname") @BinderParam(BindGenerateKeyForClientToJsonPayload.class) String clientname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefClient#clientExists
|
* @see ChefClient#clientExists
|
||||||
@ -154,8 +163,7 @@ public interface ChefAsyncClient {
|
|||||||
@HEAD
|
@HEAD
|
||||||
@Path("clients/{clientname}")
|
@Path("clients/{clientname}")
|
||||||
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
|
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
|
||||||
ListenableFuture<Boolean> clientExists(
|
ListenableFuture<Boolean> clientExists(@PathParam("clientname") String clientname);
|
||||||
@PathParam("clientname") String clientname);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefClient#getClient
|
* @see ChefClient#getClient
|
||||||
@ -163,8 +171,7 @@ public interface ChefAsyncClient {
|
|||||||
@GET
|
@GET
|
||||||
@Path("clients/{clientname}")
|
@Path("clients/{clientname}")
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Boolean> getClient(
|
ListenableFuture<Boolean> getClient(@PathParam("clientname") String clientname);
|
||||||
@PathParam("clientname") String clientname);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefClient#deleteClient
|
* @see ChefClient#deleteClient
|
||||||
@ -172,8 +179,7 @@ public interface ChefAsyncClient {
|
|||||||
@DELETE
|
@DELETE
|
||||||
@Path("clients/{clientname}")
|
@Path("clients/{clientname}")
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<String> deleteClient(
|
ListenableFuture<String> deleteClient(@PathParam("clientname") String clientname);
|
||||||
@PathParam("clientname") String clientname);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefClient#listClients
|
* @see ChefClient#listClients
|
||||||
|
@ -44,8 +44,9 @@ package org.jclouds.chef;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.chef.domain.Cookbook;
|
import org.jclouds.chef.domain.CookbookVersion;
|
||||||
import org.jclouds.chef.domain.Sandbox;
|
import org.jclouds.chef.domain.Sandbox;
|
||||||
|
import org.jclouds.chef.domain.UploadSite;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
@ -60,7 +61,9 @@ import org.jclouds.rest.AuthorizationException;
|
|||||||
*/
|
*/
|
||||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
public interface ChefClient {
|
public interface ChefClient {
|
||||||
Sandbox getUploadUrisForContent(Set<String> checksums);
|
UploadSite getUploadSiteForChecksums(Set<byte[]> md5s);
|
||||||
|
|
||||||
|
Sandbox closeSandbox(String id, boolean isCompleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -69,14 +72,12 @@ public interface ChefClient {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* "401 Unauthorized" if the caller is not a recognized user.
|
* "401 Unauthorized" if the caller is not a recognized user.
|
||||||
* <p/>
|
* <p/>
|
||||||
* "403 Forbidden" if you do not have permission to see the
|
* "403 Forbidden" if you do not have permission to see the cookbook list.
|
||||||
* cookbook list.
|
|
||||||
*/
|
*/
|
||||||
Set<String> listCookbooks();
|
Set<String> listCookbooks();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates or updates (uploads) a cookbook with the name present from the
|
* Creates or updates (uploads) a cookbook with the name present from the tar/gz file.
|
||||||
* tar/gz file.
|
|
||||||
*
|
*
|
||||||
* @param cookbookName
|
* @param cookbookName
|
||||||
* matches the root directory path of the archive
|
* matches the root directory path of the archive
|
||||||
@ -85,13 +86,12 @@ public interface ChefClient {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* "401 Unauthorized" if the caller is not a recognized user.
|
* "401 Unauthorized" if the caller is not a recognized user.
|
||||||
* <p/>
|
* <p/>
|
||||||
* "403 Forbidden" if you do not have permission to create
|
* "403 Forbidden" if you do not have permission to create cookbooks.
|
||||||
* cookbooks.
|
|
||||||
* @throws HttpResponseException
|
* @throws HttpResponseException
|
||||||
* "409 Conflict" if the cookbook already exists
|
* "409 Conflict" if the cookbook already exists
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 10, timeUnit = TimeUnit.MINUTES)
|
@Timeout(duration = 10, timeUnit = TimeUnit.MINUTES)
|
||||||
void updateCookbook(String cookbookName, String version, Cookbook cookbook);
|
void updateCookbook(String cookbookName, String version, CookbookVersion cookbook);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes an existing cookbook.
|
* deletes an existing cookbook.
|
||||||
@ -101,8 +101,7 @@ public interface ChefClient {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* "401 Unauthorized" if you are not a recognized user.
|
* "401 Unauthorized" if you are not a recognized user.
|
||||||
* <p/>
|
* <p/>
|
||||||
* "403 Forbidden" if you do not have Delete rights on the
|
* "403 Forbidden" if you do not have Delete rights on the cookbook.
|
||||||
* cookbook.
|
|
||||||
*/
|
*/
|
||||||
String deleteCookbook(String cookbookName, String version);
|
String deleteCookbook(String cookbookName, String version);
|
||||||
|
|
||||||
@ -114,14 +113,13 @@ public interface ChefClient {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* "401 Unauthorized" if the caller is not a recognized user.
|
* "401 Unauthorized" if the caller is not a recognized user.
|
||||||
* <p/>
|
* <p/>
|
||||||
* "403 Forbidden" if the caller is not authorized to view the
|
* "403 Forbidden" if the caller is not authorized to view the cookbook.
|
||||||
* cookbook.
|
|
||||||
*/
|
*/
|
||||||
Set<String> getVersionsOfCookbook(String cookbookName);
|
Set<String> getVersionsOfCookbook(String cookbookName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a description of the cookbook, with links to all of its component
|
* Returns a description of the cookbook, with links to all of its component parts, and the
|
||||||
* parts, and the metadata.
|
* metadata.
|
||||||
*
|
*
|
||||||
* @return the cookbook or null, if not found
|
* @return the cookbook or null, if not found
|
||||||
*
|
*
|
||||||
@ -129,22 +127,20 @@ public interface ChefClient {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* "401 Unauthorized" if the caller is not a recognized user.
|
* "401 Unauthorized" if the caller is not a recognized user.
|
||||||
* <p/>
|
* <p/>
|
||||||
* "403 Forbidden" if the caller is not authorized to view the
|
* "403 Forbidden" if the caller is not authorized to view the cookbook.
|
||||||
* cookbook.
|
|
||||||
*/
|
*/
|
||||||
Cookbook getCookbook(String cookbookName, String version);
|
CookbookVersion getCookbook(String cookbookName, String version);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new client
|
* creates a new client
|
||||||
*
|
*
|
||||||
* @return the private key of the client. You can then use this client name
|
* @return the private key of the client. You can then use this client name and private key to
|
||||||
* and private key to access the Opscode API.
|
* access the Opscode API.
|
||||||
* @throws AuthorizationException
|
* @throws AuthorizationException
|
||||||
* <p/>
|
* <p/>
|
||||||
* "401 Unauthorized" if the caller is not a recognized user.
|
* "401 Unauthorized" if the caller is not a recognized user.
|
||||||
* <p/>
|
* <p/>
|
||||||
* "403 Forbidden" if the caller is not authorized to create a
|
* "403 Forbidden" if the caller is not authorized to create a client.
|
||||||
* client.
|
|
||||||
* @throws HttpResponseException
|
* @throws HttpResponseException
|
||||||
* "409 Conflict" if the client already exists
|
* "409 Conflict" if the client already exists
|
||||||
*/
|
*/
|
||||||
@ -152,8 +148,7 @@ public interface ChefClient {
|
|||||||
String createClient(String name);
|
String createClient(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a new key-pair for this client, and return the new private key in
|
* generate a new key-pair for this client, and return the new private key in the response body.
|
||||||
* the response body.
|
|
||||||
*
|
*
|
||||||
* @return the new private key
|
* @return the new private key
|
||||||
*
|
*
|
||||||
@ -161,8 +156,7 @@ public interface ChefClient {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* "401 Unauthorized" if the caller is not a recognized user.
|
* "401 Unauthorized" if the caller is not a recognized user.
|
||||||
* <p/>
|
* <p/>
|
||||||
* "403 Forbidden" if the caller is not authorized to modify the
|
* "403 Forbidden" if the caller is not authorized to modify the client.
|
||||||
* client.
|
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 120, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 120, timeUnit = TimeUnit.SECONDS)
|
||||||
String generateKeyForClient(String name);
|
String generateKeyForClient(String name);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.chef.binders;
|
package org.jclouds.chef.binders;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class BindClientnameToJsonPayload extends BindToStringPayload {
|
public class BindClientnameToJsonPayload extends BindToStringPayload {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.chef.binders;
|
package org.jclouds.chef.binders;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class BindGenerateKeyForClientToJsonPayload extends BindToStringPayload {
|
public class BindGenerateKeyForClientToJsonPayload extends BindToStringPayload {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.chef.binders;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class BindIsCompletedToJsonPayload extends BindToStringPayload {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindToRequest(HttpRequest request, Object value) {
|
||||||
|
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
||||||
|
ImmutableSet.of(MediaType.APPLICATION_JSON));
|
||||||
|
super.bindToRequest(request, String.format("{\"is_completed\":\"%s\"}", value));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -28,10 +28,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
|
||||||
@ -43,24 +45,30 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class BindChecksumsToJsonPayload extends BindToStringPayload {
|
public class BindMD5sToJsonPayload extends BindToStringPayload {
|
||||||
|
private final EncryptionService encryptionService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BindMD5sToJsonPayload(EncryptionService encryptionService) {
|
||||||
|
this.encryptionService = encryptionService;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void bindToRequest(HttpRequest request, Object input) {
|
public void bindToRequest(HttpRequest request, Object input) {
|
||||||
checkArgument(checkNotNull(input, "input") instanceof Set,
|
checkArgument(checkNotNull(input, "input") instanceof Set,
|
||||||
"this binder is only valid for Set!");
|
"this binder is only valid for Set!");
|
||||||
|
|
||||||
Set<String> sums = (Set<String>) input;
|
Set<byte[]> md5s = (Set<byte[]>) input;
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("{\"checksums\":{");
|
builder.append("{\"checksums\":{");
|
||||||
|
|
||||||
for (String sum : sums)
|
for (byte[] md5 : md5s)
|
||||||
builder.append(String.format("\"%s\":null,", sum));
|
builder.append(String.format("\"%s\":null,", encryptionService.hex(md5)));
|
||||||
builder.deleteCharAt(builder.length() - 1);
|
builder.deleteCharAt(builder.length() - 1);
|
||||||
builder.append("}}");
|
builder.append("}}");
|
||||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
||||||
ImmutableSet.of(MediaType.APPLICATION_JSON));
|
ImmutableSet.of(MediaType.APPLICATION_JSON));
|
||||||
super.bindToRequest(request, builder.toString());
|
super.bindToRequest(request, builder.toString());
|
||||||
}
|
}
|
||||||
|
|
@ -66,6 +66,8 @@ import org.jclouds.http.RequiresHttp;
|
|||||||
import org.jclouds.http.annotation.ClientError;
|
import org.jclouds.http.annotation.ClientError;
|
||||||
import org.jclouds.http.annotation.Redirection;
|
import org.jclouds.http.annotation.Redirection;
|
||||||
import org.jclouds.http.annotation.ServerError;
|
import org.jclouds.http.annotation.ServerError;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
@ -126,4 +128,10 @@ public class BaseChefRestClientModule<S, A> extends RestClientModule<S, A> {
|
|||||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ChefErrorHandler.class);
|
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ChefErrorHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||||
|
super.configure();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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 org.jclouds.chef.domain;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class ChecksumStatus {
|
||||||
|
private URI url;
|
||||||
|
@SerializedName("needs_upload")
|
||||||
|
private boolean needsUpload;
|
||||||
|
|
||||||
|
public ChecksumStatus(URI url, boolean needsUpload) {
|
||||||
|
this.url = url;
|
||||||
|
this.needsUpload = needsUpload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChecksumStatus() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean needsUpload() {
|
||||||
|
return needsUpload;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ChecksumStatus [needsUpload=" + needsUpload + ", url=" + url + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + (needsUpload ? 1231 : 1237);
|
||||||
|
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
ChecksumStatus other = (ChecksumStatus) obj;
|
||||||
|
if (needsUpload != other.needsUpload)
|
||||||
|
return false;
|
||||||
|
if (url == null) {
|
||||||
|
if (other.url != null)
|
||||||
|
return false;
|
||||||
|
} else if (!url.equals(other.url))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -29,12 +29,10 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Cookbook {
|
public class CookbookVersion {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private Set<Resource> definitions = Sets.newLinkedHashSet();
|
private Set<Resource> definitions = Sets.newLinkedHashSet();
|
||||||
@SerializedName("json_class")
|
|
||||||
private String jsonClass;
|
|
||||||
private Set<Resource> attributes = Sets.newLinkedHashSet();
|
private Set<Resource> attributes = Sets.newLinkedHashSet();
|
||||||
private Set<Resource> files = Sets.newLinkedHashSet();
|
private Set<Resource> files = Sets.newLinkedHashSet();
|
||||||
private Metadata metadata;
|
private Metadata metadata;
|
||||||
@ -48,17 +46,28 @@ public class Cookbook {
|
|||||||
private Set<Resource> recipes = Sets.newLinkedHashSet();
|
private Set<Resource> recipes = Sets.newLinkedHashSet();
|
||||||
@SerializedName("root_files")
|
@SerializedName("root_files")
|
||||||
private Set<Resource> rootFiles = Sets.newLinkedHashSet();
|
private Set<Resource> rootFiles = Sets.newLinkedHashSet();
|
||||||
@SerializedName("chef_type")
|
|
||||||
private String chefType;
|
|
||||||
|
|
||||||
public Cookbook(String name, Set<Resource> definitions, String jsonClass,
|
|
||||||
Set<Resource> attributes, Set<Resource> files, Metadata metadata,
|
// internal
|
||||||
Set<Resource> providers, String cookbookName, Set<Resource> resources,
|
@SuppressWarnings("unused")
|
||||||
Set<Resource> templates, Set<Resource> libraries, String version,
|
@SerializedName("json_class")
|
||||||
Set<Resource> recipes, Set<Resource> rootFiles, String chefType) {
|
private String _jsonClass = "Chef::CookbookVersion";
|
||||||
|
@SerializedName("chef_type")
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private String _chefType = "cookbook_version";
|
||||||
|
|
||||||
|
public CookbookVersion(String cookbookName, String version) {
|
||||||
|
this.cookbookName = cookbookName;
|
||||||
|
this.version = version;
|
||||||
|
this.name = cookbookName + "-" + version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CookbookVersion(String name, Set<Resource> definitions, Set<Resource> attributes,
|
||||||
|
Set<Resource> files, Metadata metadata, Set<Resource> providers, String cookbookName,
|
||||||
|
Set<Resource> resources, Set<Resource> templates, Set<Resource> libraries,
|
||||||
|
String version, Set<Resource> recipes, Set<Resource> rootFiles) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
Iterables.addAll(this.definitions, definitions);
|
Iterables.addAll(this.definitions, definitions);
|
||||||
this.jsonClass = jsonClass;
|
|
||||||
Iterables.addAll(this.attributes, attributes);
|
Iterables.addAll(this.attributes, attributes);
|
||||||
Iterables.addAll(this.files, files);
|
Iterables.addAll(this.files, files);
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
@ -70,10 +79,9 @@ public class Cookbook {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
Iterables.addAll(this.recipes, recipes);
|
Iterables.addAll(this.recipes, recipes);
|
||||||
Iterables.addAll(this.rootFiles, rootFiles);
|
Iterables.addAll(this.rootFiles, rootFiles);
|
||||||
this.chefType = chefType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cookbook() {
|
public CookbookVersion() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,10 +93,6 @@ public class Cookbook {
|
|||||||
return definitions;
|
return definitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJsonClass() {
|
|
||||||
return jsonClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Resource> getAttributes() {
|
public Set<Resource> getAttributes() {
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
@ -133,37 +137,22 @@ public class Cookbook {
|
|||||||
return rootFiles;
|
return rootFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChefType() {
|
|
||||||
return chefType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result
|
result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
|
||||||
+ ((attributes == null) ? 0 : attributes.hashCode());
|
result = prime * result + ((cookbookName == null) ? 0 : cookbookName.hashCode());
|
||||||
result = prime * result + ((chefType == null) ? 0 : chefType.hashCode());
|
result = prime * result + ((definitions == null) ? 0 : definitions.hashCode());
|
||||||
result = prime * result
|
|
||||||
+ ((cookbookName == null) ? 0 : cookbookName.hashCode());
|
|
||||||
result = prime * result
|
|
||||||
+ ((definitions == null) ? 0 : definitions.hashCode());
|
|
||||||
result = prime * result + ((files == null) ? 0 : files.hashCode());
|
result = prime * result + ((files == null) ? 0 : files.hashCode());
|
||||||
result = prime * result
|
result = prime * result + ((libraries == null) ? 0 : libraries.hashCode());
|
||||||
+ ((jsonClass == null) ? 0 : jsonClass.hashCode());
|
|
||||||
result = prime * result
|
|
||||||
+ ((libraries == null) ? 0 : libraries.hashCode());
|
|
||||||
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
result = prime * result
|
result = prime * result + ((providers == null) ? 0 : providers.hashCode());
|
||||||
+ ((providers == null) ? 0 : providers.hashCode());
|
|
||||||
result = prime * result + ((recipes == null) ? 0 : recipes.hashCode());
|
result = prime * result + ((recipes == null) ? 0 : recipes.hashCode());
|
||||||
result = prime * result
|
result = prime * result + ((resources == null) ? 0 : resources.hashCode());
|
||||||
+ ((resources == null) ? 0 : resources.hashCode());
|
result = prime * result + ((rootFiles == null) ? 0 : rootFiles.hashCode());
|
||||||
result = prime * result
|
result = prime * result + ((templates == null) ? 0 : templates.hashCode());
|
||||||
+ ((rootFiles == null) ? 0 : rootFiles.hashCode());
|
|
||||||
result = prime * result
|
|
||||||
+ ((templates == null) ? 0 : templates.hashCode());
|
|
||||||
result = prime * result + ((version == null) ? 0 : version.hashCode());
|
result = prime * result + ((version == null) ? 0 : version.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -176,17 +165,12 @@ public class Cookbook {
|
|||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
Cookbook other = (Cookbook) obj;
|
CookbookVersion other = (CookbookVersion) obj;
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
if (other.attributes != null)
|
if (other.attributes != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!attributes.equals(other.attributes))
|
} else if (!attributes.equals(other.attributes))
|
||||||
return false;
|
return false;
|
||||||
if (chefType == null) {
|
|
||||||
if (other.chefType != null)
|
|
||||||
return false;
|
|
||||||
} else if (!chefType.equals(other.chefType))
|
|
||||||
return false;
|
|
||||||
if (cookbookName == null) {
|
if (cookbookName == null) {
|
||||||
if (other.cookbookName != null)
|
if (other.cookbookName != null)
|
||||||
return false;
|
return false;
|
||||||
@ -202,11 +186,6 @@ public class Cookbook {
|
|||||||
return false;
|
return false;
|
||||||
} else if (!files.equals(other.files))
|
} else if (!files.equals(other.files))
|
||||||
return false;
|
return false;
|
||||||
if (jsonClass == null) {
|
|
||||||
if (other.jsonClass != null)
|
|
||||||
return false;
|
|
||||||
} else if (!jsonClass.equals(other.jsonClass))
|
|
||||||
return false;
|
|
||||||
if (libraries == null) {
|
if (libraries == null) {
|
||||||
if (other.libraries != null)
|
if (other.libraries != null)
|
||||||
return false;
|
return false;
|
||||||
@ -257,13 +236,11 @@ public class Cookbook {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Cookbook [attributes=" + attributes + ", chefType=" + chefType
|
return "Cookbook [attributes=" + attributes + ", cookbookName=" + cookbookName
|
||||||
+ ", cookbookName=" + cookbookName + ", definitions=" + definitions
|
+ ", definitions=" + definitions + ", files=" + files + ", libraries=" + libraries
|
||||||
+ ", files=" + files + ", jsonClass=" + jsonClass + ", libraries="
|
+ ", metadata=" + metadata + ", name=" + name + ", providers=" + providers
|
||||||
+ libraries + ", metadata=" + metadata + ", name=" + name
|
+ ", recipes=" + recipes + ", resources=" + resources + ", rootFiles=" + rootFiles
|
||||||
+ ", providers=" + providers + ", recipes=" + recipes
|
+ ", templates=" + templates + ", version=" + version + "]";
|
||||||
+ ", resources=" + resources + ", rootFiles=" + rootFiles
|
|
||||||
+ ", templates=" + templates + ", version=" + version + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -33,8 +33,11 @@ public class Resource {
|
|||||||
private String path;
|
private String path;
|
||||||
private String specificity;
|
private String specificity;
|
||||||
|
|
||||||
public Resource(String name, URI url, String checksum, String path,
|
public Resource(String name, String checksum, String path) {
|
||||||
String specificity) {
|
this(name, null, checksum, path, "default");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Resource(String name, URI url, String checksum, String path, String specificity) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.checksum = checksum;
|
this.checksum = checksum;
|
||||||
@ -52,6 +55,7 @@ public class Resource {
|
|||||||
public URI getUrl() {
|
public URI getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChecksum() {
|
public String getChecksum() {
|
||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
@ -71,8 +75,7 @@ public class Resource {
|
|||||||
result = prime * result + ((checksum == null) ? 0 : checksum.hashCode());
|
result = prime * result + ((checksum == null) ? 0 : checksum.hashCode());
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
result = prime * result + ((path == null) ? 0 : path.hashCode());
|
result = prime * result + ((path == null) ? 0 : path.hashCode());
|
||||||
result = prime * result
|
result = prime * result + ((specificity == null) ? 0 : specificity.hashCode());
|
||||||
+ ((specificity == null) ? 0 : specificity.hashCode());
|
|
||||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -116,8 +119,8 @@ public class Resource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Resource [checksum=" + checksum + ", name=" + name + ", path="
|
return "Resource [checksum=" + checksum + ", name=" + name + ", path=" + path
|
||||||
+ path + ", specificity=" + specificity + ", url=" + url + "]";
|
+ ", specificity=" + specificity + ", url=" + url + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -18,53 +18,86 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.chef.domain;
|
package org.jclouds.chef.domain;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cookbook object.
|
* Sandbox object.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Sandbox {
|
public class Sandbox {
|
||||||
private URI uri;
|
|
||||||
private Map<String, ChecksumStatus> checksums = Maps.newLinkedHashMap();
|
|
||||||
@SerializedName("sandbox_id")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
public Sandbox(URI uri, Map<String, ChecksumStatus> checksums, String id) {
|
@SerializedName("_rev")
|
||||||
this.uri = uri;
|
private String rev;
|
||||||
this.checksums.putAll(checksums);
|
@SerializedName("is_completed")
|
||||||
this.id = id;
|
private boolean isCompleted;
|
||||||
|
@SerializedName("create_time")
|
||||||
|
private Date createTime;
|
||||||
|
private Set<String> checksums = Sets.newLinkedHashSet();
|
||||||
|
private String name;
|
||||||
|
private String guid;
|
||||||
|
|
||||||
|
// internal
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@SerializedName("json_class")
|
||||||
|
private String _jsonClass = "Chef::Sandbox";
|
||||||
|
@SerializedName("chef_type")
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private String _chefType = "sandbox";
|
||||||
|
|
||||||
|
public Sandbox(String rev, boolean isCompleted, Date createTime, Iterable<String> checksums,
|
||||||
|
String name, String guid) {
|
||||||
|
this.rev = rev;
|
||||||
|
this.isCompleted = isCompleted;
|
||||||
|
this.createTime = createTime;
|
||||||
|
Iterables.addAll(this.checksums, checksums);
|
||||||
|
this.name = name;
|
||||||
|
this.guid = guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sandbox() {
|
public Sandbox() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getUri() {
|
public String getRev() {
|
||||||
return uri;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, ChecksumStatus> getChecksums() {
|
public boolean isCompleted() {
|
||||||
|
return isCompleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getChecksums() {
|
||||||
return checksums;
|
return checksums;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getName() {
|
||||||
return id;
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGuid() {
|
||||||
|
return guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result
|
result = prime * result + ((checksums == null) ? 0 : checksums.hashCode());
|
||||||
+ ((checksums == null) ? 0 : checksums.hashCode());
|
result = prime * result + ((createTime == null) ? 0 : createTime.hashCode());
|
||||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
result = prime * result + ((guid == null) ? 0 : guid.hashCode());
|
||||||
result = prime * result + ((uri == null) ? 0 : uri.hashCode());
|
result = prime * result + (isCompleted ? 1231 : 1237);
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
result = prime * result + ((rev == null) ? 0 : rev.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,80 +115,34 @@ public class Sandbox {
|
|||||||
return false;
|
return false;
|
||||||
} else if (!checksums.equals(other.checksums))
|
} else if (!checksums.equals(other.checksums))
|
||||||
return false;
|
return false;
|
||||||
if (id == null) {
|
if (createTime == null) {
|
||||||
if (other.id != null)
|
if (other.createTime != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!id.equals(other.id))
|
} else if (!createTime.equals(other.createTime))
|
||||||
return false;
|
return false;
|
||||||
if (uri == null) {
|
if (guid == null) {
|
||||||
if (other.uri != null)
|
if (other.guid != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!uri.equals(other.uri))
|
} else if (!guid.equals(other.guid))
|
||||||
|
return false;
|
||||||
|
if (isCompleted != other.isCompleted)
|
||||||
|
return false;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null)
|
||||||
|
return false;
|
||||||
|
} else if (!name.equals(other.name))
|
||||||
|
return false;
|
||||||
|
if (rev == null) {
|
||||||
|
if (other.rev != null)
|
||||||
|
return false;
|
||||||
|
} else if (!rev.equals(other.rev))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ChecksumStatus {
|
|
||||||
private URI url;
|
|
||||||
@SerializedName("needs_upload")
|
|
||||||
private boolean needsUpload;
|
|
||||||
|
|
||||||
public ChecksumStatus(URI url, boolean needsUpload) {
|
|
||||||
this.url = url;
|
|
||||||
this.needsUpload = needsUpload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChecksumStatus() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean needsUpload() {
|
|
||||||
return needsUpload;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ChecksumStatus [needsUpload=" + needsUpload + ", url=" + url
|
|
||||||
+ "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (needsUpload ? 1231 : 1237);
|
|
||||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
ChecksumStatus other = (ChecksumStatus) obj;
|
|
||||||
if (needsUpload != other.needsUpload)
|
|
||||||
return false;
|
|
||||||
if (url == null) {
|
|
||||||
if (other.url != null)
|
|
||||||
return false;
|
|
||||||
} else if (!url.equals(other.url))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Sandbox [checksums=" + checksums + ", id=" + id + ", uri=" + uri
|
return "Sandbox [checksums=" + checksums + ", createTime=" + createTime + ", guid=" + guid
|
||||||
+ "]";
|
+ ", isCompleted=" + isCompleted + ", name=" + name + ", rev=" + rev + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
103
chef/src/main/java/org/jclouds/chef/domain/UploadSite.java
Normal file
103
chef/src/main/java/org/jclouds/chef/domain/UploadSite.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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 org.jclouds.chef.domain;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class UploadSite {
|
||||||
|
private URI uri;
|
||||||
|
private Map<String, ChecksumStatus> checksums = Maps.newLinkedHashMap();
|
||||||
|
@SerializedName("sandbox_id")
|
||||||
|
private String sandboxId;
|
||||||
|
|
||||||
|
public UploadSite(URI uri, Map<String, ChecksumStatus> checksums, String sandboxId) {
|
||||||
|
this.uri = uri;
|
||||||
|
this.checksums.putAll(checksums);
|
||||||
|
this.sandboxId = sandboxId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UploadSite() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI getUri() {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ChecksumStatus> getChecksums() {
|
||||||
|
return checksums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSandboxId() {
|
||||||
|
return sandboxId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result
|
||||||
|
+ ((checksums == null) ? 0 : checksums.hashCode());
|
||||||
|
result = prime * result + ((sandboxId == null) ? 0 : sandboxId.hashCode());
|
||||||
|
result = prime * result + ((uri == null) ? 0 : uri.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
UploadSite other = (UploadSite) obj;
|
||||||
|
if (checksums == null) {
|
||||||
|
if (other.checksums != null)
|
||||||
|
return false;
|
||||||
|
} else if (!checksums.equals(other.checksums))
|
||||||
|
return false;
|
||||||
|
if (sandboxId == null) {
|
||||||
|
if (other.sandboxId != null)
|
||||||
|
return false;
|
||||||
|
} else if (!sandboxId.equals(other.sandboxId))
|
||||||
|
return false;
|
||||||
|
if (uri == null) {
|
||||||
|
if (other.uri != null)
|
||||||
|
return false;
|
||||||
|
} else if (!uri.equals(other.uri))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "UploadSite [checksums=" + checksums + ", id=" + sandboxId + ", uri=" + uri
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.chef.functions;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.chef.domain.CookbookVersion;
|
||||||
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class ParseCookbookVersionFromJson extends ParseJson<CookbookVersion> {
|
||||||
|
@Inject
|
||||||
|
public ParseCookbookVersionFromJson(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CookbookVersion apply(InputStream stream) {
|
||||||
|
try {
|
||||||
|
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||||
|
CookbookVersion.class);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -50,8 +50,7 @@ public class ParseSandboxFromJson extends ParseJson<Sandbox> {
|
|||||||
@Override
|
@Override
|
||||||
protected Sandbox apply(InputStream stream) {
|
protected Sandbox apply(InputStream stream) {
|
||||||
try {
|
try {
|
||||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), Sandbox.class);
|
||||||
Sandbox.class);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.chef.domain.Cookbook;
|
import org.jclouds.chef.domain.UploadSite;
|
||||||
import org.jclouds.http.functions.ParseJson;
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@ -41,17 +41,17 @@ import com.google.gson.Gson;
|
|||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ParseCookbookFromJson extends ParseJson<Cookbook> {
|
public class ParseUploadSiteFromJson extends ParseJson<UploadSite> {
|
||||||
@Inject
|
@Inject
|
||||||
public ParseCookbookFromJson(Gson gson) {
|
public ParseUploadSiteFromJson(Gson gson) {
|
||||||
super(gson);
|
super(gson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Cookbook apply(InputStream stream) {
|
protected UploadSite apply(InputStream stream) {
|
||||||
try {
|
try {
|
||||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||||
Cookbook.class);
|
UploadSite.class);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||||
}
|
}
|
@ -31,14 +31,16 @@ import java.util.Properties;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.chef.config.ChefRestClientModule;
|
import org.jclouds.chef.config.ChefRestClientModule;
|
||||||
import org.jclouds.chef.domain.Cookbook;
|
import org.jclouds.chef.domain.CookbookVersion;
|
||||||
import org.jclouds.chef.filters.SignedHeaderAuth;
|
import org.jclouds.chef.filters.SignedHeaderAuth;
|
||||||
import org.jclouds.chef.filters.SignedHeaderAuthTest;
|
import org.jclouds.chef.filters.SignedHeaderAuthTest;
|
||||||
import org.jclouds.chef.functions.ParseCookbookFromJson;
|
import org.jclouds.chef.functions.ParseCookbookVersionFromJson;
|
||||||
import org.jclouds.chef.functions.ParseKeyFromJson;
|
import org.jclouds.chef.functions.ParseKeyFromJson;
|
||||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||||
import org.jclouds.chef.functions.ParseSandboxFromJson;
|
import org.jclouds.chef.functions.ParseSandboxFromJson;
|
||||||
|
import org.jclouds.chef.functions.ParseUploadSiteFromJson;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||||
@ -68,22 +70,44 @@ import com.google.inject.TypeLiteral;
|
|||||||
@Test(groups = "unit", testName = "chef.ChefAsyncClientTest")
|
@Test(groups = "unit", testName = "chef.ChefAsyncClientTest")
|
||||||
public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
|
|
||||||
public void testGetUploadUrisForContent() throws SecurityException, NoSuchMethodException,
|
public void testCloseSandbox() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
IOException {
|
|
||||||
Method method = ChefAsyncClient.class.getMethod("getUploadUrisForContent", Set.class);
|
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
|
||||||
ImmutableSet.of("0189e76ccc476701d6b374e5a1a27347",
|
|
||||||
"0c5ecd7788cf4f6c7de2a57193897a6c", "1dda05ed139664f1f89b9dec482b77c0"));
|
|
||||||
|
|
||||||
|
Method method = ChefAsyncClient.class.getMethod("closeSandbox", String.class, boolean.class);
|
||||||
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"0189e76ccc476701d6b374e5a1a27347", true);
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
|
||||||
|
assertHeadersEqual(
|
||||||
|
httpRequest,
|
||||||
|
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
|
assertPayloadEquals(httpRequest, "{\"is_completed\":\"true\"}");
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseSandboxFromJson.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetUploadSiteForChecksums() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
|
EncryptionService encservice = injector.getInstance(EncryptionService.class);
|
||||||
|
|
||||||
|
Method method = ChefAsyncClient.class.getMethod("getUploadSiteForChecksums", Set.class);
|
||||||
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
ImmutableSet.of(encservice.fromHex("0189e76ccc476701d6b374e5a1a27347"), encservice
|
||||||
|
.fromHex("0c5ecd7788cf4f6c7de2a57193897a6c"), encservice
|
||||||
|
.fromHex("1dda05ed139664f1f89b9dec482b77c0")));
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
|
"Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}");
|
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}");
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseSandboxFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseUploadSiteFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
@ -97,10 +121,10 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
"cookbook", "1.0.0");
|
"cookbook", "1.0.0");
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
"GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseCookbookFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
@ -114,7 +138,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
"cookbook", "1.0.0");
|
"cookbook", "1.0.0");
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
"DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
||||||
@ -127,18 +151,18 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
|
|
||||||
public void testUpdateCookbook() throws SecurityException, NoSuchMethodException, IOException {
|
public void testUpdateCookbook() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = ChefAsyncClient.class.getMethod("updateCookbook", String.class, String.class,
|
Method method = ChefAsyncClient.class.getMethod("updateCookbook", String.class, String.class,
|
||||||
Cookbook.class);
|
CookbookVersion.class);
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
"cookbook", "1.0.1", new Cookbook());
|
"cookbook", "1.0.1", new CookbookVersion());
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
|
"PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 134\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
|
"Accept: application/json\nContent-Length: 202\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"{\"definitions\":[],\"attributes\":[],\"files\":[],\"providers\":[],\"resources\":[],\"templates\":[],\"libraries\":[],\"recipes\":[],\"root_files\":[]}");
|
"{\"definitions\":[],\"attributes\":[],\"files\":[],\"providers\":[],\"resources\":[],\"templates\":[],\"libraries\":[],\"recipes\":[],\"root_files\":[],\"json_class\":\"Chef::CookbookVersion\",\"chef_type\":\"cookbook_version\"}");
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
@ -153,7 +177,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||||
@ -168,7 +192,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
Method method = ChefAsyncClient.class.getMethod("clientExists", String.class);
|
Method method = ChefAsyncClient.class.getMethod("clientExists", String.class);
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||||
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/client HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
|
||||||
@ -183,7 +207,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
Method method = ChefAsyncClient.class.getMethod("deleteClient", String.class);
|
Method method = ChefAsyncClient.class.getMethod("deleteClient", String.class);
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||||
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
||||||
@ -201,7 +225,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
|
"Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}");
|
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}");
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||||
@ -219,7 +243,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
|
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}");
|
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}");
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||||
@ -235,7 +259,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||||
|
@ -32,8 +32,15 @@ import java.io.InputStream;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.chef.domain.Cookbook;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
|
import org.jclouds.chef.domain.ChecksumStatus;
|
||||||
|
import org.jclouds.chef.domain.CookbookVersion;
|
||||||
import org.jclouds.chef.domain.Resource;
|
import org.jclouds.chef.domain.Resource;
|
||||||
|
import org.jclouds.chef.domain.UploadSite;
|
||||||
|
import org.jclouds.http.Payload;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
@ -109,6 +116,43 @@ public class ChefClientLiveTest {
|
|||||||
clientConnection.getApi().clientExists(PREFIX);
|
clientConnection.getApi().clientExists(PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testCreateClient")
|
||||||
|
public void testCreateNewCookbook() throws Exception {
|
||||||
|
Payload pom = Payloads.newFilePayload(new File(System.getProperty("user.dir"), "pom.xml"));
|
||||||
|
byte[] md5 = adminConnection.utils().encryption().md5(pom.getInput());
|
||||||
|
UploadSite site = adminConnection.getApi().getUploadSiteForChecksums(ImmutableSet.of(md5));
|
||||||
|
|
||||||
|
String md5Hex = adminConnection.utils().encryption().hex(md5);
|
||||||
|
try {
|
||||||
|
assert site.getChecksums().containsKey(md5Hex) : md5Hex + " not in " + site.getChecksums();
|
||||||
|
ChecksumStatus status = site.getChecksums().get(md5Hex);
|
||||||
|
if (status.needsUpload()) {
|
||||||
|
adminConnection.utils().http().put(status.getUrl(), pom,
|
||||||
|
new PutContentOptions(adminConnection.utils().encryption().base64(md5)));
|
||||||
|
}
|
||||||
|
adminConnection.getApi().closeSandbox(site.getSandboxId(), true);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
adminConnection.getApi().closeSandbox(site.getSandboxId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
CookbookVersion cookbook = new CookbookVersion("test", "0.0.0");
|
||||||
|
cookbook.getRootFiles().add(new Resource("pom.xml", md5Hex, "pom.xml"));
|
||||||
|
adminConnection.getApi().updateCookbook("test", "0.0.0", cookbook);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class PutContentOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
|
public PutContentOptions(String md5Base64) {
|
||||||
|
super();
|
||||||
|
this.headers.replaceValues(HttpHeaders.ACCEPT, ImmutableSet.of("application/json"));
|
||||||
|
this.headers.replaceValues(HttpHeaders.CONTENT_TYPE, ImmutableSet
|
||||||
|
.of("application/x-binary"));
|
||||||
|
this.headers.replaceValues("Content-MD5", ImmutableSet.of(md5Base64));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateClient")
|
@Test(dependsOnMethods = "testCreateClient")
|
||||||
public void testGenerateKeyForClient() throws Exception {
|
public void testGenerateKeyForClient() throws Exception {
|
||||||
clientKey = validatorConnection.getApi().generateKeyForClient(PREFIX);
|
clientKey = validatorConnection.getApi().generateKeyForClient(PREFIX);
|
||||||
@ -123,19 +167,18 @@ public class ChefClientLiveTest {
|
|||||||
assertNotNull(validatorConnection.getApi().clientExists(PREFIX));
|
assertNotNull(validatorConnection.getApi().clientExists(PREFIX));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(dependsOnMethods = "testCreateNewCookbook")
|
||||||
public void testListCookbooks() throws Exception {
|
public void testListCookbooks() throws Exception {
|
||||||
for (String cookbook : adminConnection.getApi().listCookbooks())
|
for (String cookbook : adminConnection.getApi().listCookbooks())
|
||||||
for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
|
for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
|
||||||
System.err.printf("%s/%s:%n", cookbook, version);
|
System.err.printf("%s/%s:%n", cookbook, version);
|
||||||
Cookbook cookbookO = adminConnection.getApi().getCookbook(cookbook, version);
|
CookbookVersion cookbookO = adminConnection.getApi().getCookbook(cookbook, version);
|
||||||
for (Resource resource : ImmutableList.<Resource> builder().addAll(
|
for (Resource resource : ImmutableList.<Resource> builder().addAll(
|
||||||
cookbookO.getDefinitions()).addAll(cookbookO.getFiles()).addAll(
|
cookbookO.getDefinitions()).addAll(cookbookO.getFiles()).addAll(
|
||||||
cookbookO.getLibraries()).addAll(cookbookO.getProviders()).addAll(
|
cookbookO.getLibraries()).addAll(cookbookO.getProviders()).addAll(
|
||||||
cookbookO.getRecipes()).addAll(cookbookO.getResources()).addAll(
|
cookbookO.getRecipes()).addAll(cookbookO.getResources()).addAll(
|
||||||
cookbookO.getRootFiles()).addAll(cookbookO.getTemplates()).build()) {
|
cookbookO.getRootFiles()).addAll(cookbookO.getTemplates()).build()) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
InputStream stream = adminConnection.utils().http().get(resource.getUrl());
|
InputStream stream = adminConnection.utils().http().get(resource.getUrl());
|
||||||
byte[] md5 = adminConnection.utils().encryption().md5(stream);
|
byte[] md5 = adminConnection.utils().encryption().md5(stream);
|
||||||
String md5Hex = adminConnection.utils().encryption().hex(md5);
|
String md5Hex = adminConnection.utils().encryption().hex(md5);
|
||||||
@ -155,10 +198,9 @@ public class ChefClientLiveTest {
|
|||||||
for (String cookbook : adminConnection.getApi().listCookbooks())
|
for (String cookbook : adminConnection.getApi().listCookbooks())
|
||||||
for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
|
for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
|
||||||
System.err.printf("%s/%s:%n", cookbook, version);
|
System.err.printf("%s/%s:%n", cookbook, version);
|
||||||
Cookbook cook = adminConnection.getApi().getCookbook(cookbook, version);
|
CookbookVersion cook = adminConnection.getApi().getCookbook(cookbook, version);
|
||||||
adminConnection.getApi().updateCookbook(cookbook, version, cook);
|
adminConnection.getApi().updateCookbook(cookbook, version, cook);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testUpdateCookbook")
|
@Test(dependsOnMethods = "testUpdateCookbook")
|
||||||
@ -166,7 +208,7 @@ public class ChefClientLiveTest {
|
|||||||
for (String cookbook : adminConnection.getApi().listCookbooks())
|
for (String cookbook : adminConnection.getApi().listCookbooks())
|
||||||
for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
|
for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
|
||||||
System.err.printf("%s/%s:%n", cookbook, version);
|
System.err.printf("%s/%s:%n", cookbook, version);
|
||||||
Cookbook cook = adminConnection.getApi().getCookbook(cookbook, version);
|
CookbookVersion cook = adminConnection.getApi().getCookbook(cookbook, version);
|
||||||
adminConnection.getApi().deleteCookbook(cookbook, version);
|
adminConnection.getApi().deleteCookbook(cookbook, version);
|
||||||
assert adminConnection.getApi().getCookbook(cookbook, version) == null : cookbook
|
assert adminConnection.getApi().getCookbook(cookbook, version) == null : cookbook
|
||||||
+ version;
|
+ version;
|
||||||
|
@ -30,6 +30,7 @@ import java.net.URI;
|
|||||||
|
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
|
||||||
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
@ -41,14 +42,15 @@ import com.google.inject.Injector;
|
|||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "chef.BindChecksumsToJsonPayloadTest")
|
@Test(groups = "unit", testName = "chef.BindMD5sToJsonPayloadTest")
|
||||||
public class BindChecksumsToJsonPayloadTest {
|
public class BindMD5sToJsonPayloadTest {
|
||||||
|
|
||||||
Injector injector = Guice.createInjector(new ParserModule());
|
Injector injector = Guice.createInjector(new ParserModule());
|
||||||
|
EncryptionService encservice = injector.getInstance(EncryptionService.class);
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testMustBeIterable() {
|
public void testMustBeIterable() {
|
||||||
BindChecksumsToJsonPayload binder = new BindChecksumsToJsonPayload();
|
BindMD5sToJsonPayload binder = new BindMD5sToJsonPayload(encservice);
|
||||||
injector.injectMembers(binder);
|
injector.injectMembers(binder);
|
||||||
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
|
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
|
||||||
.create("http://localhost"));
|
.create("http://localhost"));
|
||||||
@ -57,19 +59,19 @@ public class BindChecksumsToJsonPayloadTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCorrect() {
|
public void testCorrect() {
|
||||||
BindChecksumsToJsonPayload binder = new BindChecksumsToJsonPayload();
|
BindMD5sToJsonPayload binder = new BindMD5sToJsonPayload(encservice);
|
||||||
injector.injectMembers(binder);
|
injector.injectMembers(binder);
|
||||||
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
|
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
|
||||||
.create("http://localhost"));
|
.create("http://localhost"));
|
||||||
binder.bindToRequest(request, ImmutableSet.of("abddef", "12345"));
|
binder.bindToRequest(request, ImmutableSet.of(encservice.fromHex("abddef"), encservice.fromHex("1234")));
|
||||||
assertEquals(request.getPayload().getRawContent(),
|
assertEquals(request.getPayload().getRawContent(),
|
||||||
"{\"checksums\":{\"abddef\":null,\"12345\":null}}");
|
"{\"checksums\":{\"abddef\":null,\"1234\":null}}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = { NullPointerException.class,
|
@Test(expectedExceptions = { NullPointerException.class,
|
||||||
IllegalStateException.class })
|
IllegalStateException.class })
|
||||||
public void testNullIsBad() {
|
public void testNullIsBad() {
|
||||||
BindChecksumsToJsonPayload binder = new BindChecksumsToJsonPayload();
|
BindMD5sToJsonPayload binder = new BindMD5sToJsonPayload(encservice);
|
||||||
injector.injectMembers(binder);
|
injector.injectMembers(binder);
|
||||||
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
|
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
|
||||||
.create("http://localhost"));
|
.create("http://localhost"));
|
@ -1,113 +0,0 @@
|
|||||||
package org.jclouds.chef.functions;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jclouds.chef.domain.Attribute;
|
|
||||||
import org.jclouds.chef.domain.Cookbook;
|
|
||||||
import org.jclouds.chef.domain.Metadata;
|
|
||||||
import org.jclouds.chef.domain.Resource;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
|
||||||
import org.jclouds.util.Utils;
|
|
||||||
import org.testng.annotations.BeforeTest;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.inject.Guice;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code ParseCookbookFromJson}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", sequential = true, testName = "chef.ParseCookbookFromJsonTest")
|
|
||||||
public class ParseCookbookFromJsonTest {
|
|
||||||
|
|
||||||
private ParseCookbookFromJson handler;
|
|
||||||
|
|
||||||
@BeforeTest
|
|
||||||
protected void setUpInjector() throws IOException {
|
|
||||||
Injector injector = Guice.createInjector(new ParserModule());
|
|
||||||
handler = injector.getInstance(ParseCookbookFromJson.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBrew() throws IOException {
|
|
||||||
Cookbook cookbook = handler.apply(new HttpResponse(
|
|
||||||
ParseCookbookFromJsonTest.class
|
|
||||||
.getResourceAsStream("/brew-cookbook.json")));
|
|
||||||
|
|
||||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils
|
|
||||||
.toInputStream(new Gson().toJson(cookbook)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testTomcat() {
|
|
||||||
Cookbook cookbook = handler.apply(new HttpResponse(
|
|
||||||
ParseCookbookFromJsonTest.class
|
|
||||||
.getResourceAsStream("/tomcat-cookbook.json")));
|
|
||||||
|
|
||||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils
|
|
||||||
.toInputStream(new Gson().toJson(cookbook)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testMysql() throws IOException {
|
|
||||||
Cookbook cookbook = handler.apply(new HttpResponse(
|
|
||||||
ParseCookbookFromJsonTest.class
|
|
||||||
.getResourceAsStream("/mysql-cookbook.json")));
|
|
||||||
|
|
||||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils
|
|
||||||
.toInputStream(new Gson().toJson(cookbook)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testApache() {
|
|
||||||
assertEquals(
|
|
||||||
handler.apply(new HttpResponse(ParseCookbookFromJsonTest.class
|
|
||||||
.getResourceAsStream("/apache-chef-demo-cookbook.json"))),
|
|
||||||
new Cookbook(
|
|
||||||
"apache-chef-demo-0.0.0",
|
|
||||||
ImmutableSet.<Resource> of(),
|
|
||||||
"Chef::CookbookVersion",
|
|
||||||
ImmutableSet.<Resource> of(),
|
|
||||||
ImmutableSet.<Resource> of(),
|
|
||||||
new Metadata("Apache v2.0", "Your Name", ImmutableMap
|
|
||||||
.<String, String> of(), ImmutableMap
|
|
||||||
.<String, Set<String>> of(), "youremail@example.com",
|
|
||||||
ImmutableMap.<String, Set<String>> of(),
|
|
||||||
"A fabulous new cookbook", ImmutableMap
|
|
||||||
.<String, Set<String>> of(), ImmutableMap
|
|
||||||
.<String, Set<String>> of(), "0.0.0",
|
|
||||||
ImmutableMap.<String, String> of(), ImmutableMap
|
|
||||||
.<String, Set<String>> of(), "apache-chef-demo",
|
|
||||||
ImmutableMap.<String, String> of(), "", ImmutableMap
|
|
||||||
.<String, Attribute> of(), ImmutableMap
|
|
||||||
.<String, String> of()),
|
|
||||||
ImmutableSet.<Resource> of(),
|
|
||||||
"apache-chef-demo",
|
|
||||||
ImmutableSet.<Resource> of(),
|
|
||||||
ImmutableSet.<Resource> of(),
|
|
||||||
ImmutableSet.<Resource> of(),
|
|
||||||
"0.0.0",
|
|
||||||
ImmutableSet.<Resource> of(),
|
|
||||||
ImmutableSet
|
|
||||||
.<Resource> of(
|
|
||||||
new Resource(
|
|
||||||
"README",
|
|
||||||
URI
|
|
||||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-11637f98942eafbf49c71b7f2f048b78?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=zgpNl6wSxjTNovqZu2nJq0JztU8%3D"),
|
|
||||||
"11637f98942eafbf49c71b7f2f048b78",
|
|
||||||
"README", "default"),
|
|
||||||
new Resource(
|
|
||||||
"Rakefile",
|
|
||||||
URI
|
|
||||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-ebcf925a1651b4e04b9cd8aac2bc54eb?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=EFzzDSKKytTl7b%2FxrCeNLh05zj4%3D"),
|
|
||||||
"ebcf925a1651b4e04b9cd8aac2bc54eb",
|
|
||||||
"Rakefile", "default")), "cookbook_version"));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,110 @@
|
|||||||
|
package org.jclouds.chef.functions;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.chef.domain.Attribute;
|
||||||
|
import org.jclouds.chef.domain.CookbookVersion;
|
||||||
|
import org.jclouds.chef.domain.Metadata;
|
||||||
|
import org.jclouds.chef.domain.Resource;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
import org.testng.annotations.BeforeTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code ParseCookbookVersionFromJson}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", sequential = true, testName = "chef.ParseCookbookVersionFromJsonTest")
|
||||||
|
public class ParseCookbookVersionFromJsonTest {
|
||||||
|
|
||||||
|
private ParseCookbookVersionFromJson handler;
|
||||||
|
|
||||||
|
@BeforeTest
|
||||||
|
protected void setUpInjector() throws IOException {
|
||||||
|
Injector injector = Guice.createInjector(new ParserModule());
|
||||||
|
handler = injector.getInstance(ParseCookbookVersionFromJson.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBrew() throws IOException {
|
||||||
|
CookbookVersion cookbook = handler.apply(new HttpResponse(
|
||||||
|
ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/brew-cookbook.json")));
|
||||||
|
|
||||||
|
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
||||||
|
.toJson(cookbook)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTomcat() {
|
||||||
|
CookbookVersion cookbook = handler
|
||||||
|
.apply(new HttpResponse(ParseCookbookVersionFromJsonTest.class
|
||||||
|
.getResourceAsStream("/tomcat-cookbook.json")));
|
||||||
|
|
||||||
|
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
||||||
|
.toJson(cookbook)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMysql() throws IOException {
|
||||||
|
CookbookVersion cookbook = handler.apply(new HttpResponse(
|
||||||
|
ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/mysql-cookbook.json")));
|
||||||
|
|
||||||
|
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
||||||
|
.toJson(cookbook)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testApache() {
|
||||||
|
assertEquals(
|
||||||
|
handler.apply(new HttpResponse(ParseCookbookVersionFromJsonTest.class
|
||||||
|
.getResourceAsStream("/apache-chef-demo-cookbook.json"))),
|
||||||
|
new CookbookVersion(
|
||||||
|
"apache-chef-demo-0.0.0",
|
||||||
|
ImmutableSet.<Resource> of(),
|
||||||
|
ImmutableSet.<Resource> of(),
|
||||||
|
ImmutableSet.<Resource> of(),
|
||||||
|
new Metadata("Apache v2.0", "Your Name",
|
||||||
|
ImmutableMap.<String, String> of(), ImmutableMap
|
||||||
|
.<String, Set<String>> of(), "youremail@example.com",
|
||||||
|
ImmutableMap.<String, Set<String>> of(),
|
||||||
|
"A fabulous new cookbook",
|
||||||
|
ImmutableMap.<String, Set<String>> of(), ImmutableMap
|
||||||
|
.<String, Set<String>> of(), "0.0.0", ImmutableMap
|
||||||
|
.<String, String> of(), ImmutableMap
|
||||||
|
.<String, Set<String>> of(), "apache-chef-demo",
|
||||||
|
ImmutableMap.<String, String> of(), "", ImmutableMap
|
||||||
|
.<String, Attribute> of(), ImmutableMap
|
||||||
|
.<String, String> of()),
|
||||||
|
ImmutableSet.<Resource> of(),
|
||||||
|
"apache-chef-demo",
|
||||||
|
ImmutableSet.<Resource> of(),
|
||||||
|
ImmutableSet.<Resource> of(),
|
||||||
|
ImmutableSet.<Resource> of(),
|
||||||
|
"0.0.0",
|
||||||
|
ImmutableSet.<Resource> of(),
|
||||||
|
ImmutableSet
|
||||||
|
.<Resource> of(
|
||||||
|
new Resource(
|
||||||
|
"README",
|
||||||
|
URI
|
||||||
|
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-11637f98942eafbf49c71b7f2f048b78?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=zgpNl6wSxjTNovqZu2nJq0JztU8%3D"),
|
||||||
|
"11637f98942eafbf49c71b7f2f048b78", "README",
|
||||||
|
"default"),
|
||||||
|
new Resource(
|
||||||
|
"Rakefile",
|
||||||
|
URI
|
||||||
|
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-ebcf925a1651b4e04b9cd8aac2bc54eb?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=EFzzDSKKytTl7b%2FxrCeNLh05zj4%3D"),
|
||||||
|
"ebcf925a1651b4e04b9cd8aac2bc54eb", "Rakefile",
|
||||||
|
"default"))));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -3,16 +3,18 @@ package org.jclouds.chef.functions;
|
|||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.chef.domain.Sandbox;
|
import org.jclouds.chef.domain.Sandbox;
|
||||||
import org.jclouds.chef.domain.Sandbox.ChecksumStatus;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
@ -25,30 +27,28 @@ import com.google.inject.Injector;
|
|||||||
public class ParseSandboxFromJsonTest {
|
public class ParseSandboxFromJsonTest {
|
||||||
|
|
||||||
private ParseSandboxFromJson handler;
|
private ParseSandboxFromJson handler;
|
||||||
|
private DateService dateService;
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
protected void setUpInjector() throws IOException {
|
protected void setUpInjector() throws IOException {
|
||||||
Injector injector = Guice.createInjector(new ParserModule());
|
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
handler = injector.getInstance(ParseSandboxFromJson.class);
|
handler = injector.getInstance(ParseSandboxFromJson.class);
|
||||||
|
dateService = injector.getInstance(DateService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
assertEquals(
|
assertEquals(handler.apply(new HttpResponse(ParseSandboxFromJsonTest.class
|
||||||
handler.apply(new HttpResponse(ParseSandboxFromJsonTest.class
|
.getResourceAsStream("/sandbox.json"))), new Sandbox(
|
||||||
.getResourceAsStream("/sandbox.json"))),
|
"1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
|
||||||
new Sandbox(
|
.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"), ImmutableSet
|
||||||
URI
|
.<String> of(), "f9d6d9b72bae465890aae87969f98a9c",
|
||||||
.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"),
|
"f9d6d9b72bae465890aae87969f98a9c"));
|
||||||
ImmutableMap
|
|
||||||
.<String, ChecksumStatus> of(
|
|
||||||
"0c5ecd7788cf4f6c7de2a57193897a6c",
|
|
||||||
new ChecksumStatus(
|
|
||||||
URI
|
|
||||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D"),
|
|
||||||
true), "0189e76ccc476701d6b374e5a1a27347",
|
|
||||||
new ChecksumStatus(),
|
|
||||||
"1dda05ed139664f1f89b9dec482b77c0",
|
|
||||||
new ChecksumStatus()),
|
|
||||||
"d454f71e2a5f400c808d0c5d04c2c88c"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package org.jclouds.chef.functions;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.chef.domain.ChecksumStatus;
|
||||||
|
import org.jclouds.chef.domain.UploadSite;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
|
import org.testng.annotations.BeforeTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code ParseUploadSiteFromJson}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", sequential = true, testName = "chef.ParseUploadSiteFromJsonTest")
|
||||||
|
public class ParseUploadSiteFromJsonTest {
|
||||||
|
|
||||||
|
private ParseUploadSiteFromJson handler;
|
||||||
|
|
||||||
|
@BeforeTest
|
||||||
|
protected void setUpInjector() throws IOException {
|
||||||
|
Injector injector = Guice.createInjector(new ParserModule());
|
||||||
|
handler = injector.getInstance(ParseUploadSiteFromJson.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
assertEquals(
|
||||||
|
handler.apply(new HttpResponse(ParseUploadSiteFromJsonTest.class
|
||||||
|
.getResourceAsStream("/upload-site.json"))),
|
||||||
|
new UploadSite(
|
||||||
|
URI
|
||||||
|
.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"),
|
||||||
|
ImmutableMap
|
||||||
|
.<String, ChecksumStatus> of(
|
||||||
|
"0c5ecd7788cf4f6c7de2a57193897a6c",
|
||||||
|
new ChecksumStatus(
|
||||||
|
URI
|
||||||
|
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D"),
|
||||||
|
true), "0189e76ccc476701d6b374e5a1a27347",
|
||||||
|
new ChecksumStatus(), "1dda05ed139664f1f89b9dec482b77c0",
|
||||||
|
new ChecksumStatus()), "d454f71e2a5f400c808d0c5d04c2c88c"));
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,12 @@
|
|||||||
{
|
{
|
||||||
"uri": "https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c",
|
"_rev": "1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2",
|
||||||
"checksums": {
|
"json_class": "Chef::Sandbox",
|
||||||
"0c5ecd7788cf4f6c7de2a57193897a6c": {
|
"is_completed": false,
|
||||||
"url": "https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D",
|
"create_time": "2010-07-07T03:36:00+00:00",
|
||||||
"needs_upload": true
|
"chef_type": "sandbox",
|
||||||
}, "0189e76ccc476701d6b374e5a1a27347": {
|
"checksums": [],
|
||||||
"needs_upload": false
|
"name": "f9d6d9b72bae465890aae87969f98a9c",
|
||||||
}, "1dda05ed139664f1f89b9dec482b77c0": {
|
"guid": "f9d6d9b72bae465890aae87969f98a9c"
|
||||||
"needs_upload": false
|
}
|
||||||
}
|
|
||||||
}, "sandbox_id": "d454f71e2a5f400c808d0c5d04c2c88c"
|
|
||||||
}
|
|
||||||
|
13
chef/src/test/resources/upload-site.json
Normal file
13
chef/src/test/resources/upload-site.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"uri": "https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c",
|
||||||
|
"checksums": {
|
||||||
|
"0c5ecd7788cf4f6c7de2a57193897a6c": {
|
||||||
|
"url": "https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D",
|
||||||
|
"needs_upload": true
|
||||||
|
}, "0189e76ccc476701d6b374e5a1a27347": {
|
||||||
|
"needs_upload": false
|
||||||
|
}, "1dda05ed139664f1f89b9dec482b77c0": {
|
||||||
|
"needs_upload": false
|
||||||
|
}
|
||||||
|
}, "sandbox_id": "d454f71e2a5f400c808d0c5d04c2c88c"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user