mirror of https://github.com/apache/jclouds.git
JCLOUDS-776: Map chef cookbook attribute files with Resource instead of Attribute
This commit is contained in:
parent
494f35ddae
commit
68f3bdc264
|
@ -38,7 +38,7 @@ public class CookbookVersion {
|
|||
public static class Builder {
|
||||
private String cookbookName;
|
||||
private ImmutableSet.Builder<Resource> definitions = ImmutableSet.builder();
|
||||
private ImmutableSet.Builder<Attribute> attributes = ImmutableSet.builder();
|
||||
private ImmutableSet.Builder<Resource> attributes = ImmutableSet.builder();
|
||||
private ImmutableSet.Builder<Resource> files = ImmutableSet.builder();
|
||||
private Metadata metadata = Metadata.builder().build();
|
||||
private ImmutableSet.Builder<Resource> providers = ImmutableSet.builder();
|
||||
|
@ -69,12 +69,12 @@ public class CookbookVersion {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder attribute(Attribute attribute) {
|
||||
public Builder attribute(Resource attribute) {
|
||||
this.attributes.add(checkNotNull(attribute, "attribute"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder attributes(Iterable<Attribute> attributes) {
|
||||
public Builder attributes(Iterable<Resource> attributes) {
|
||||
this.attributes.addAll(checkNotNull(attributes, "attributes"));
|
||||
return this;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ public class CookbookVersion {
|
|||
|
||||
private final String name;
|
||||
private final Set<Resource> definitions;
|
||||
private final Set<Attribute> attributes;
|
||||
private final Set<Resource> attributes;
|
||||
private final Set<Resource> files;
|
||||
private final Metadata metadata;
|
||||
private final Set<Resource> providers;
|
||||
|
@ -190,7 +190,7 @@ public class CookbookVersion {
|
|||
|
||||
@ConstructorProperties({ "name", "definitions", "attributes", "files", "metadata", "providers", "cookbook_name",
|
||||
"resources", "templates", "libraries", "version", "recipes", "root_files" })
|
||||
protected CookbookVersion(String name, @Nullable Set<Resource> definitions, @Nullable Set<Attribute> attributes,
|
||||
protected CookbookVersion(String name, @Nullable Set<Resource> definitions, @Nullable Set<Resource> attributes,
|
||||
@Nullable Set<Resource> files, Metadata metadata, @Nullable Set<Resource> providers, String cookbookName,
|
||||
@Nullable Set<Resource> resources, @Nullable Set<Resource> templates, @Nullable Set<Resource> libraries,
|
||||
String version, @Nullable Set<Resource> recipes, @Nullable Set<Resource> rootFiles) {
|
||||
|
@ -217,7 +217,7 @@ public class CookbookVersion {
|
|||
return definitions;
|
||||
}
|
||||
|
||||
public Set<Attribute> getAttributes() {
|
||||
public Set<Resource> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import static org.testng.Assert.assertTrue;
|
|||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -85,6 +86,30 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
|
|||
public void testCreateNewCookbook() throws Exception {
|
||||
// Define the file you want in the cookbook
|
||||
File file = new File(System.getProperty("user.dir"), "pom.xml");
|
||||
FilePayload content = uploadAndGetFilePayload(file);
|
||||
|
||||
// Create the metadata of the cookbook
|
||||
Metadata metadata = Metadata.builder() //
|
||||
.name(PREFIX) //
|
||||
.version("0.0.0") //
|
||||
.description("Jclouds test uploaded cookbook") //
|
||||
.maintainer("jclouds") //
|
||||
.maintainerEmail("someone@jclouds.org") //
|
||||
.license("Apache 2.0") //
|
||||
.build();
|
||||
|
||||
// Create a new cookbook
|
||||
CookbookVersion cookbook = CookbookVersion.builder(PREFIX, "0.0.0") //
|
||||
.metadata(metadata) //
|
||||
.rootFile(Resource.builder().fromPayload(content).build()) //
|
||||
.attribute(Resource.builder().fromPayload(content).name("default.rb").build())
|
||||
.build();
|
||||
|
||||
// upload the cookbook to the remote server
|
||||
api.updateCookbook(PREFIX, "0.0.0", cookbook);
|
||||
}
|
||||
|
||||
private FilePayload uploadAndGetFilePayload(File file) throws IOException {
|
||||
FilePayload content = Payloads.newFilePayload(file);
|
||||
content.getContentMetadata().setContentType("application/x-binary");
|
||||
|
||||
|
@ -111,25 +136,7 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
|
|||
api.commitSandbox(site.getSandboxId(), false);
|
||||
fail("Could not upload content");
|
||||
}
|
||||
|
||||
// Create the metadata of the cookbook
|
||||
Metadata metadata = Metadata.builder() //
|
||||
.name(PREFIX) //
|
||||
.version("0.0.0") //
|
||||
.description("Jclouds test uploaded cookbook") //
|
||||
.maintainer("jclouds") //
|
||||
.maintainerEmail("someone@jclouds.org") //
|
||||
.license("Apache 2.0") //
|
||||
.build();
|
||||
|
||||
// Create a new cookbook
|
||||
CookbookVersion cookbook = CookbookVersion.builder(PREFIX, "0.0.0") //
|
||||
.metadata(metadata) //
|
||||
.rootFile(Resource.builder().fromPayload(content).build()) //
|
||||
.build();
|
||||
|
||||
// upload the cookbook to the remote server
|
||||
api.updateCookbook(PREFIX, "0.0.0", cookbook);
|
||||
return content;
|
||||
}
|
||||
|
||||
public void testListCookbooks() throws Exception {
|
||||
|
@ -160,7 +167,7 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
|
|||
for (Resource resource : ImmutableList.<Resource> builder().addAll(cookbook.getDefinitions())
|
||||
.addAll(cookbook.getFiles()).addAll(cookbook.getLibraries()).addAll(cookbook.getSuppliers())
|
||||
.addAll(cookbook.getRecipes()).addAll(cookbook.getResources()).addAll(cookbook.getRootFiles())
|
||||
.addAll(cookbook.getTemplates()).build()) {
|
||||
.addAll(cookbook.getTemplates()).addAll(cookbook.getAttributes()).build()) {
|
||||
|
||||
InputStream stream = api.getResourceContents(resource);
|
||||
assertNotNull(stream, "Resource contents are null for resource: " + resource.getName());
|
||||
|
|
Loading…
Reference in New Issue