Issue 191: started update to chef v0.9

This commit is contained in:
Adrian Cole 2010-06-25 10:46:29 -07:00
parent 055c56dc08
commit fcfb3739aa
10 changed files with 1287 additions and 0 deletions

View File

@ -0,0 +1,67 @@
/**
*
* 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 static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
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 BindChecksumsToJsonPayload extends BindToStringPayload {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof Set,
"this binder is only valid for Set!");
Set<String> sums = (Set<String>) input;
StringBuilder builder = new StringBuilder();
builder.append("{\"checksums\":{");
for (String sum : sums)
builder.append(String.format("\"%s\":null,", sum));
builder.deleteCharAt(builder.length() - 1);
builder.append("}}");
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
ImmutableSet.of(MediaType.APPLICATION_JSON));
super.bindToRequest(request, builder.toString());
}
}

View File

@ -0,0 +1,174 @@
/**
*
* 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.domain;
import java.util.List;
import java.util.Set;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.gson.annotations.SerializedName;
/**
* Cookbook object.
*
* @author Adrian Cole
*/
public class Attribute {
private String required;
private boolean calculated;
private Set<String> choice;
@SerializedName("default")
private String defaultValue;
private String type;
private List<String> recipes = Lists.newArrayList();
@SerializedName("display_name")
private String displayName;
private String description;
public Attribute(String required, boolean calculated, Set<String> choice,
String defaultValue, String type, List<String> recipes,
String displayName, String description) {
this.required = required;
this.calculated = calculated;
Iterables.addAll(this.choice, choice);
this.defaultValue = defaultValue;
this.type = type;
Iterables.addAll(this.recipes, recipes);
this.displayName = displayName;
this.description = description;
}
public Attribute() {
}
public String getRequired() {
return required;
}
public boolean isCalculated() {
return calculated;
}
public Set<String> getChoice() {
return choice;
}
public String getDefaultValue() {
return defaultValue;
}
public String getType() {
return type;
}
public List<String> getRecipes() {
return recipes;
}
public String getDisplayName() {
return displayName;
}
public String getDescription() {
return description;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (calculated ? 1231 : 1237);
result = prime * result + ((choice == null) ? 0 : choice.hashCode());
result = prime * result
+ ((defaultValue == null) ? 0 : defaultValue.hashCode());
result = prime * result
+ ((description == null) ? 0 : description.hashCode());
result = prime * result
+ ((displayName == null) ? 0 : displayName.hashCode());
result = prime * result + ((recipes == null) ? 0 : recipes.hashCode());
result = prime * result + ((required == null) ? 0 : required.hashCode());
result = prime * result + ((type == null) ? 0 : type.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;
Attribute other = (Attribute) obj;
if (calculated != other.calculated)
return false;
if (choice == null) {
if (other.choice != null)
return false;
} else if (!choice.equals(other.choice))
return false;
if (defaultValue == null) {
if (other.defaultValue != null)
return false;
} else if (!defaultValue.equals(other.defaultValue))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (displayName == null) {
if (other.displayName != null)
return false;
} else if (!displayName.equals(other.displayName))
return false;
if (recipes == null) {
if (other.recipes != null)
return false;
} else if (!recipes.equals(other.recipes))
return false;
if (required == null) {
if (other.required != null)
return false;
} else if (!required.equals(other.required))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
@Override
public String toString() {
return "Attribute [calculated=" + calculated + ", choice=" + choice
+ ", defaultValue=" + defaultValue + ", description=" + description
+ ", displayName=" + displayName + ", recipes=" + recipes
+ ", required=" + required + ", type=" + type + "]";
}
}

View File

@ -0,0 +1,269 @@
/**
*
* 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.util.Set;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName;
/**
* Cookbook object.
*
* @author Adrian Cole
*/
public class Cookbook {
private String name;
private Set<Resource> definitions = Sets.newLinkedHashSet();
@SerializedName("json_class")
private String jsonClass;
private Set<Resource> attributes = Sets.newLinkedHashSet();
private Set<Resource> files = Sets.newLinkedHashSet();
private Metadata metadata;
private Set<Resource> providers = Sets.newLinkedHashSet();
@SerializedName("cookbook_name")
private String cookbookName;
private Set<Resource> resources = Sets.newLinkedHashSet();
private Set<Resource> templates = Sets.newLinkedHashSet();
private Set<Resource> libraries = Sets.newLinkedHashSet();
private String version;
private Set<Resource> recipes = Sets.newLinkedHashSet();
@SerializedName("root_files")
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,
Set<Resource> providers, String cookbookName, Set<Resource> resources,
Set<Resource> templates, Set<Resource> libraries, String version,
Set<Resource> recipes, Set<Resource> rootFiles, String chefType) {
this.name = name;
Iterables.addAll(this.definitions, definitions);
this.jsonClass = jsonClass;
Iterables.addAll(this.attributes, attributes);
Iterables.addAll(this.files, files);
this.metadata = metadata;
Iterables.addAll(this.providers, providers);
this.cookbookName = cookbookName;
Iterables.addAll(this.resources, resources);
Iterables.addAll(this.templates, templates);
Iterables.addAll(this.libraries, libraries);
this.version = version;
Iterables.addAll(this.recipes, recipes);
Iterables.addAll(this.rootFiles, rootFiles);
this.chefType = chefType;
}
public Cookbook() {
}
public String getName() {
return name;
}
public Set<Resource> getDefinitions() {
return definitions;
}
public String getJsonClass() {
return jsonClass;
}
public Set<Resource> getAttributes() {
return attributes;
}
public Set<Resource> getFiles() {
return files;
}
public Metadata getMetadata() {
return metadata;
}
public Set<Resource> getProviders() {
return providers;
}
public String getCookbookName() {
return cookbookName;
}
public Set<Resource> getResources() {
return resources;
}
public Set<Resource> getTemplates() {
return templates;
}
public Set<Resource> getLibraries() {
return libraries;
}
public String getVersion() {
return version;
}
public Set<Resource> getRecipes() {
return recipes;
}
public Set<Resource> getRootFiles() {
return rootFiles;
}
public String getChefType() {
return chefType;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((attributes == null) ? 0 : attributes.hashCode());
result = prime * result + ((chefType == null) ? 0 : chefType.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
+ ((jsonClass == null) ? 0 : jsonClass.hashCode());
result = prime * result
+ ((libraries == null) ? 0 : libraries.hashCode());
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result
+ ((providers == null) ? 0 : providers.hashCode());
result = prime * result + ((recipes == null) ? 0 : recipes.hashCode());
result = prime * result
+ ((resources == null) ? 0 : resources.hashCode());
result = prime * result
+ ((rootFiles == null) ? 0 : rootFiles.hashCode());
result = prime * result
+ ((templates == null) ? 0 : templates.hashCode());
result = prime * result + ((version == null) ? 0 : version.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;
Cookbook other = (Cookbook) obj;
if (attributes == null) {
if (other.attributes != null)
return false;
} else if (!attributes.equals(other.attributes))
return false;
if (chefType == null) {
if (other.chefType != null)
return false;
} else if (!chefType.equals(other.chefType))
return false;
if (cookbookName == null) {
if (other.cookbookName != null)
return false;
} else if (!cookbookName.equals(other.cookbookName))
return false;
if (definitions == null) {
if (other.definitions != null)
return false;
} else if (!definitions.equals(other.definitions))
return false;
if (files == null) {
if (other.files != null)
return false;
} else if (!files.equals(other.files))
return false;
if (jsonClass == null) {
if (other.jsonClass != null)
return false;
} else if (!jsonClass.equals(other.jsonClass))
return false;
if (libraries == null) {
if (other.libraries != null)
return false;
} else if (!libraries.equals(other.libraries))
return false;
if (metadata == null) {
if (other.metadata != null)
return false;
} else if (!metadata.equals(other.metadata))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (providers == null) {
if (other.providers != null)
return false;
} else if (!providers.equals(other.providers))
return false;
if (recipes == null) {
if (other.recipes != null)
return false;
} else if (!recipes.equals(other.recipes))
return false;
if (resources == null) {
if (other.resources != null)
return false;
} else if (!resources.equals(other.resources))
return false;
if (rootFiles == null) {
if (other.rootFiles != null)
return false;
} else if (!rootFiles.equals(other.rootFiles))
return false;
if (templates == null) {
if (other.templates != null)
return false;
} else if (!templates.equals(other.templates))
return false;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
return true;
}
@Override
public String toString() {
return "Cookbook [attributes=" + attributes + ", chefType=" + chefType
+ ", cookbookName=" + cookbookName + ", definitions=" + definitions
+ ", files=" + files + ", jsonClass=" + jsonClass + ", libraries="
+ libraries + ", metadata=" + metadata + ", name=" + name
+ ", providers=" + providers + ", recipes=" + recipes
+ ", resources=" + resources + ", rootFiles=" + rootFiles
+ ", templates=" + templates + ", version=" + version + "]";
}
}

View File

@ -0,0 +1,301 @@
/**
*
* 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.util.Map;
import java.util.Set;
import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
/**
* Cookbook object.
*
* @author Adrian Cole
*/
public class Metadata {
private String license;
private String maintainer;
private Map<String, String> suggestions = Maps.newLinkedHashMap();
private Map<String, String> dependencies = Maps.newLinkedHashMap();
@SerializedName("maintainer_email")
private String maintainerEmail;
private Map<String, String> conflicting = Maps.newLinkedHashMap();
private String description;
private Map<String, String> providing = Maps.newLinkedHashMap();
private Map<String, Map<String, Set<String>>> platforms = Maps
.newLinkedHashMap();
private String version;
private Map<String, Map<String, String>> recipes = Maps.newLinkedHashMap();
private Map<String, String> replacing = Maps.newLinkedHashMap();
private String name;
private Map<String, String> groupings = Maps.newLinkedHashMap();
@SerializedName("long_description")
private String longDescription;
private Map<String, Attribute> attributes = Maps.newLinkedHashMap();
private Map<String, String> recommendations = Maps.newLinkedHashMap();
public Metadata(String license, String maintainer,
Map<String, String> suggestions, Map<String, String> dependencies,
String maintainerEmail, Map<String, String> conflicting,
String description, Map<String, String> providing,
Map<String, Map<String, Set<String>>> platforms, String version,
Map<String, Map<String, String>> recipes,
Map<String, String> replacing, String name,
Map<String, String> groupings, String longDescription,
Map<String, Attribute> attributes, Map<String, String> recommendations) {
this.license = license;
this.maintainer = maintainer;
this.suggestions.putAll(suggestions);
this.dependencies.putAll(dependencies);
this.maintainerEmail = maintainerEmail;
this.conflicting.putAll(conflicting);
this.description = description;
this.providing.putAll(providing);
this.platforms.putAll(platforms);
this.version = version;
this.recipes.putAll(recipes);
this.replacing.putAll(replacing);
this.name = name;
this.groupings.putAll(groupings);
this.longDescription = longDescription;
this.attributes.putAll(attributes);
this.recommendations.putAll(recommendations);
}
public Metadata() {
}
public String getLicense() {
return license;
}
public String getMaintainer() {
return maintainer;
}
public Map<String, String> getSuggestions() {
return suggestions;
}
public Map<String, String> getDependencies() {
return dependencies;
}
public String getMaintainerEmail() {
return maintainerEmail;
}
public Map<String, String> getConflicting() {
return conflicting;
}
public String getDescription() {
return description;
}
public Map<String, String> getProviding() {
return providing;
}
public Map<String, Map<String, Set<String>>> getPlatforms() {
return platforms;
}
public String getVersion() {
return version;
}
public Map<String, Map<String, String>> getRecipes() {
return recipes;
}
public Map<String, String> getReplacing() {
return replacing;
}
public String getName() {
return name;
}
public Map<String, String> getGroupings() {
return groupings;
}
public String getLongDescription() {
return longDescription;
}
public Map<String, Attribute> getAttributes() {
return attributes;
}
public Map<String, String> getRecommendations() {
return recommendations;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((attributes == null) ? 0 : attributes.hashCode());
result = prime * result
+ ((conflicting == null) ? 0 : conflicting.hashCode());
result = prime * result
+ ((dependencies == null) ? 0 : dependencies.hashCode());
result = prime * result
+ ((description == null) ? 0 : description.hashCode());
result = prime * result
+ ((groupings == null) ? 0 : groupings.hashCode());
result = prime * result + ((license == null) ? 0 : license.hashCode());
result = prime * result
+ ((longDescription == null) ? 0 : longDescription.hashCode());
result = prime * result
+ ((maintainer == null) ? 0 : maintainer.hashCode());
result = prime * result
+ ((maintainerEmail == null) ? 0 : maintainerEmail.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result
+ ((platforms == null) ? 0 : platforms.hashCode());
result = prime * result
+ ((providing == null) ? 0 : providing.hashCode());
result = prime * result + ((recipes == null) ? 0 : recipes.hashCode());
result = prime * result
+ ((recommendations == null) ? 0 : recommendations.hashCode());
result = prime * result
+ ((replacing == null) ? 0 : replacing.hashCode());
result = prime * result
+ ((suggestions == null) ? 0 : suggestions.hashCode());
result = prime * result + ((version == null) ? 0 : version.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;
Metadata other = (Metadata) obj;
if (attributes == null) {
if (other.attributes != null)
return false;
} else if (!attributes.equals(other.attributes))
return false;
if (conflicting == null) {
if (other.conflicting != null)
return false;
} else if (!conflicting.equals(other.conflicting))
return false;
if (dependencies == null) {
if (other.dependencies != null)
return false;
} else if (!dependencies.equals(other.dependencies))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (groupings == null) {
if (other.groupings != null)
return false;
} else if (!groupings.equals(other.groupings))
return false;
if (license == null) {
if (other.license != null)
return false;
} else if (!license.equals(other.license))
return false;
if (longDescription == null) {
if (other.longDescription != null)
return false;
} else if (!longDescription.equals(other.longDescription))
return false;
if (maintainer == null) {
if (other.maintainer != null)
return false;
} else if (!maintainer.equals(other.maintainer))
return false;
if (maintainerEmail == null) {
if (other.maintainerEmail != null)
return false;
} else if (!maintainerEmail.equals(other.maintainerEmail))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (platforms == null) {
if (other.platforms != null)
return false;
} else if (!platforms.equals(other.platforms))
return false;
if (providing == null) {
if (other.providing != null)
return false;
} else if (!providing.equals(other.providing))
return false;
if (recipes == null) {
if (other.recipes != null)
return false;
} else if (!recipes.equals(other.recipes))
return false;
if (recommendations == null) {
if (other.recommendations != null)
return false;
} else if (!recommendations.equals(other.recommendations))
return false;
if (replacing == null) {
if (other.replacing != null)
return false;
} else if (!replacing.equals(other.replacing))
return false;
if (suggestions == null) {
if (other.suggestions != null)
return false;
} else if (!suggestions.equals(other.suggestions))
return false;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
return true;
}
@Override
public String toString() {
return "Metadata [attributes=" + attributes + ", conflicting="
+ conflicting + ", dependencies=" + dependencies + ", description="
+ description + ", groupings=" + groupings + ", license=" + license
+ ", longDescription=" + longDescription + ", maintainer="
+ maintainer + ", maintainerEmail=" + maintainerEmail + ", name="
+ name + ", platforms=" + platforms + ", providing=" + providing
+ ", recipes=" + recipes + ", recommendations=" + recommendations
+ ", replacing=" + replacing + ", suggestions=" + suggestions
+ ", version=" + version + "]";
}
}

View File

@ -0,0 +1,110 @@
/**
*
* 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;
/**
* Cookbook object.
*
* @author Adrian Cole
*/
public class Resource {
private String name;
private String checksum;
private String path;
private String specificity;
public Resource(String name, String checksum, String path, String specificity) {
this.name = name;
this.checksum = checksum;
this.path = path;
this.specificity = specificity;
}
public Resource() {
}
public String getName() {
return name;
}
public String getChecksum() {
return checksum;
}
public String getPath() {
return path;
}
public String getSpecificity() {
return specificity;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((checksum == null) ? 0 : checksum.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result
+ ((specificity == null) ? 0 : specificity.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;
Resource other = (Resource) obj;
if (checksum == null) {
if (other.checksum != null)
return false;
} else if (!checksum.equals(other.checksum))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (path == null) {
if (other.path != null)
return false;
} else if (!path.equals(other.path))
return false;
if (specificity == null) {
if (other.specificity != null)
return false;
} else if (!specificity.equals(other.specificity))
return false;
return true;
}
@Override
public String toString() {
return "Resource [checksum=" + checksum + ", name=" + name + ", path="
+ path + ", specificity=" + specificity + "]";
}
}

View File

@ -0,0 +1,161 @@
/**
*
* 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;
/**
* Cookbook object.
*
* @author Adrian Cole
*/
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) {
this.uri = uri;
this.checksums.putAll(checksums);
this.id = id;
}
public Sandbox() {
}
public URI getUri() {
return uri;
}
public Map<String, ChecksumStatus> getChecksums() {
return checksums;
}
public String getId() {
return id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((checksums == null) ? 0 : checksums.hashCode());
result = prime * result + ((id == null) ? 0 : id.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;
Sandbox other = (Sandbox) obj;
if (checksums == null) {
if (other.checksums != null)
return false;
} else if (!checksums.equals(other.checksums))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (uri == null) {
if (other.uri != null)
return false;
} else if (!uri.equals(other.uri))
return false;
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
public String toString() {
return "Sandbox [checksums=" + checksums + ", id=" + id + ", uri=" + uri
+ "]";
}
}

View File

@ -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.Sandbox;
import org.jclouds.http.functions.ParseJson;
import com.google.gson.Gson;
/**
*
*
* @author Adrian Cole
*/
@Singleton
public class ParseSandboxFromJson extends ParseJson<Sandbox> {
@Inject
public ParseSandboxFromJson(Gson gson) {
super(gson);
}
@Override
protected Sandbox apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
Sandbox.class);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,79 @@
/**
*
* 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 static org.testng.Assert.assertEquals;
import java.io.File;
import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "chef.BindChecksumsToJsonPayloadTest")
public class BindChecksumsToJsonPayloadTest {
Injector injector = Guice.createInjector(new ParserModule());
@Test(expectedExceptions = IllegalArgumentException.class)
public void testMustBeIterable() {
BindChecksumsToJsonPayload binder = new BindChecksumsToJsonPayload();
injector.injectMembers(binder);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
.create("http://localhost"));
binder.bindToRequest(request, new File("foo"));
}
@Test
public void testCorrect() {
BindChecksumsToJsonPayload binder = new BindChecksumsToJsonPayload();
injector.injectMembers(binder);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
.create("http://localhost"));
binder.bindToRequest(request, ImmutableSet.of("abddef", "12345"));
assertEquals(request.getPayload().getRawContent(),
"{\"checksums\":{\"abddef\":null,\"12345\":null}}");
}
@Test(expectedExceptions = { NullPointerException.class,
IllegalStateException.class })
public void testNullIsBad() {
BindChecksumsToJsonPayload binder = new BindChecksumsToJsonPayload();
injector.injectMembers(binder);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI
.create("http://localhost"));
binder.bindToRequest(request, null);
}
}

View File

@ -0,0 +1,54 @@
package org.jclouds.chef.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import org.jclouds.chef.domain.Sandbox;
import org.jclouds.chef.domain.Sandbox.ChecksumStatus;
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 ParseSandboxFromJson}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "chef.ParseSandboxFromJsonTest")
public class ParseSandboxFromJsonTest {
private ParseSandboxFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule());
handler = injector.getInstance(ParseSandboxFromJson.class);
}
public void test() {
assertEquals(
handler.apply(new HttpResponse(ParseSandboxFromJsonTest.class
.getResourceAsStream("/sandbox.json"))),
new Sandbox(
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"));
}
}

View 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"
}