Removed obsolete TransientChefApi

This commit is contained in:
Ignasi Barrera 2014-10-10 11:29:45 +02:00
parent c9dfb07d02
commit 2caf6ea86e
6 changed files with 0 additions and 679 deletions

View File

@ -1,387 +0,0 @@
/*
* 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.test;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Sets.newLinkedHashSet;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.blobstore.config.LocalBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.chef.ChefApi;
import org.jclouds.chef.domain.Client;
import org.jclouds.chef.domain.CookbookDefinition;
import org.jclouds.chef.domain.CookbookVersion;
import org.jclouds.chef.domain.DatabagItem;
import org.jclouds.chef.domain.Environment;
import org.jclouds.chef.domain.Node;
import org.jclouds.chef.domain.Resource;
import org.jclouds.chef.domain.Role;
import org.jclouds.chef.domain.Sandbox;
import org.jclouds.chef.domain.SearchResult;
import org.jclouds.chef.domain.UploadSandbox;
import org.jclouds.chef.options.CreateClientOptions;
import org.jclouds.chef.options.SearchOptions;
import org.jclouds.io.Payload;
import org.jclouds.lifecycle.Closer;
import org.jclouds.util.Strings2;
import com.google.common.base.Function;
/**
* In-memory chef simulator.
*/
public class TransientChefApi implements ChefApi {
@Singleton
private static class StorageMetadataToName implements Function<PageSet<? extends StorageMetadata>, Set<String>> {
@Override
public Set<String> apply(PageSet<? extends StorageMetadata> from) {
return newLinkedHashSet(transform(from, new Function<StorageMetadata, String>() {
@Override
public String apply(StorageMetadata from) {
return from.getName();
}
}));
}
}
@Singleton
private static class BlobToDatabagItem implements Function<Blob, DatabagItem> {
@Override
public DatabagItem apply(Blob from) {
try {
return from == null ? null : new DatabagItem(from.getMetadata().getName(), Strings2.toStringAndClose(from
.getPayload().getInput()));
} catch (IOException e) {
propagate(e);
return null;
}
}
}
private final LocalBlobStore databags;
private final BlobToDatabagItem blobToDatabagItem;
private final StorageMetadataToName storageMetadataToName;
private final Closer closer;
@Inject
TransientChefApi(@Named("databags") LocalBlobStore databags, StorageMetadataToName storageMetadataToName,
BlobToDatabagItem blobToDatabagItem, Closer closer) {
this.databags = checkNotNull(databags, "databags");
this.storageMetadataToName = checkNotNull(storageMetadataToName, "storageMetadataToName");
this.blobToDatabagItem = checkNotNull(blobToDatabagItem, "blobToDatabagItem");
this.closer = checkNotNull(closer, "closer");
}
@Override
public Sandbox commitSandbox(String id, boolean isCompleted) {
throw new UnsupportedOperationException();
}
@Override
public Client createClient(String clientName) {
throw new UnsupportedOperationException();
}
@Override
public Client createClient(String clientName, CreateClientOptions options) {
throw new UnsupportedOperationException();
}
@Override
public void createDatabag(String databagName) {
databags.createContainerInLocation(null, databagName);
}
@Override
public DatabagItem createDatabagItem(String databagName, DatabagItem databagItem) {
Blob blob = databags.blobBuilder(databagItem.getId()).payload(databagItem.toString()).build();
databags.putBlob(databagName, blob);
return databagItem;
}
@Override
public void createNode(Node node) {
throw new UnsupportedOperationException();
}
@Override
public void createRole(Role role) {
throw new UnsupportedOperationException();
}
@Override
public Client deleteClient(String clientName) {
throw new UnsupportedOperationException();
}
@Override
public CookbookVersion deleteCookbook(String cookbookName, String version) {
throw new UnsupportedOperationException();
}
@Override
public void deleteDatabag(String databagName) {
databags.deleteContainer(databagName);
}
@Override
public DatabagItem deleteDatabagItem(String databagName, String databagItemId) {
DatabagItem item = blobToDatabagItem.apply(databags.getBlob(databagName, databagItemId));
databags.removeBlob(databagName, databagItemId);
return item;
}
@Override
public Node deleteNode(String nodeName) {
throw new UnsupportedOperationException();
}
@Override
public Role deleteRole(String rolename) {
throw new UnsupportedOperationException();
}
@Override
public Client generateKeyForClient(String clientName) {
throw new UnsupportedOperationException();
}
@Override
public Client getClient(String clientName) {
throw new UnsupportedOperationException();
}
@Override
public CookbookVersion getCookbook(String cookbookName, String version) {
throw new UnsupportedOperationException();
}
@Override
public DatabagItem getDatabagItem(String databagName, String databagItemId) {
return blobToDatabagItem.apply(databags.getBlob(databagName, databagItemId));
}
@Override
public Node getNode(String nodeName) {
throw new UnsupportedOperationException();
}
@Override
public Role getRole(String roleName) {
throw new UnsupportedOperationException();
}
@Override
public UploadSandbox createUploadSandboxForChecksums(Set<List<Byte>> md5s) {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listVersionsOfCookbook(String cookbookName) {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listClients() {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listCookbooks() {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listDatabagItems(String databagName) {
return storageMetadataToName.apply(databags.list(databagName));
}
@Override
public Set<String> listDatabags() {
return storageMetadataToName.apply(databags.list());
}
@Override
public Set<String> listNodes() {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listRoles() {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listSearchIndexes() {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends Client> searchClients() {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends Client> searchClients(SearchOptions options) {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends DatabagItem> searchDatabagItems(String databagName) {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends DatabagItem> searchDatabagItems(String databagName, SearchOptions options) {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends Node> searchNodes() {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends Node> searchNodes(SearchOptions options) {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends Role> searchRoles() {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends Role> searchRoles(SearchOptions options) {
throw new UnsupportedOperationException();
}
@Override
public CookbookVersion updateCookbook(String cookbookName, String version, CookbookVersion cookbook) {
throw new UnsupportedOperationException();
}
@Override
public DatabagItem updateDatabagItem(String databagName, DatabagItem item) {
return createDatabagItem(databagName, item);
}
@Override
public Node updateNode(Node node) {
throw new UnsupportedOperationException();
}
@Override
public Role updateRole(Role role) {
throw new UnsupportedOperationException();
}
@Override
public void uploadContent(URI location, Payload content) {
throw new UnsupportedOperationException();
}
@Override
public InputStream getResourceContents(Resource resource) {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listEnvironments() {
throw new UnsupportedOperationException();
}
@Override
public void createEnvironment(Environment environment) {
throw new UnsupportedOperationException();
}
@Override
public Environment deleteEnvironment(String environmentName) {
throw new UnsupportedOperationException();
}
@Override
public Environment getEnvironment(String environmentName) {
throw new UnsupportedOperationException();
}
@Override
public Environment updateEnvironment(Environment environment) {
throw new UnsupportedOperationException();
}
@Override
public Set<CookbookDefinition> listCookbooksInEnvironment(String environmentName) {
throw new UnsupportedOperationException();
}
@Override
public Set<CookbookDefinition> listCookbooksInEnvironment(String environmentName, String numVersions) {
throw new UnsupportedOperationException();
}
@Override
public CookbookDefinition getCookbookInEnvironment(String environmentName, String cookbookName) {
throw new UnsupportedOperationException();
}
@Override
public CookbookDefinition getCookbookInEnvironment(String environmentName, String cookbookName, String numVersions) {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends Environment> searchEnvironments() {
throw new UnsupportedOperationException();
}
@Override
public SearchResult<? extends Environment> searchEnvironments(SearchOptions options) {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listRecipesInEnvironment(String environmentName) {
throw new UnsupportedOperationException();
}
@Override
public Set<String> listNodesInEnvironment(String environmentName) {
throw new UnsupportedOperationException();
}
@Override
public void close() throws IOException {
closer.close();
}
}

View File

@ -1,75 +0,0 @@
/*
* 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.test;
import java.net.URI;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.chef.config.ChefBootstrapModule;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.chef.test.config.TransientChefApiModule;
import org.jclouds.ohai.config.JMXOhaiModule;
import org.jclouds.rest.internal.BaseHttpApiMetadata;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for the Amazon-specific Chef API
*/
public class TransientChefApiMetadata extends BaseHttpApiMetadata<TransientChefApi> {
@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}
public TransientChefApiMetadata() {
this(new Builder());
}
protected TransientChefApiMetadata(Builder builder) {
super(builder);
}
public static class Builder extends BaseHttpApiMetadata.Builder<TransientChefApi, Builder> {
protected Builder() {
id("transientchef")
.name("In-memory Chef API")
.identityName("unused")
.defaultIdentity("api")
.documentation(URI.create("http://localhost"))
.defaultCredential(
"-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEAyb2ZJJqGm0KKR+8nfQJNsSd+F9tXNMV7CfOcW6jsqs8EZgiV\nR09hD1IYOj4YqM0qJONlgyg4xRWewdSG7QTPj1lJpVAida9sXy2+kzyagZA1Am0O\nZcbqb5hoeID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iUUCOa8bQPXNR\n+34OTsW6TUna4CSZAycLfhffAoGBAIggVsefBCvuQkF0NeUhmDCRZfhnd8y55RHR\n1HCvqKIlpv+rhcX/zmyBLuteopYyRJRsOiE2FW00i8+rIPRu4Z3Q5nybx7w3PzV9\noHN5R5baE9OyI4KpZWztpYYitZF67NcnAvVULHHOvVJQGnKYfLHJYmrJF7GA1ojM\nAuMdFbjFAoGAPxUhxwFy8gaqBahKUEZn4F81HFP5ihGhkT4QL6AFPO2e+JhIGjuR\n27+85hcFqQ+HHVtFsm81b/a+R7P4UuCRgc8eCjxQMoJ1Xl4n7VbjPbHMnIN0Ryvd\nO4ZpWDWYnCO021JTOUUOJ4J/y0416Bvkw0z59y7sNX7wDBBHHbK/XCc=\n-----END RSA PRIVATE KEY-----\n")
.defaultEndpoint("transientchef")
.defaultProperties(ChefApiMetadata.defaultProperties())
.defaultModules(
ImmutableSet.<Class<? extends Module>> of(TransientChefApiModule.class, ChefParserModule.class,
ChefBootstrapModule.class, JMXOhaiModule.class));
}
@Override
public TransientChefApiMetadata build() {
return new TransientChefApiMetadata(this);
}
@Override
protected Builder self() {
return this;
}
}
}

View File

@ -1,114 +0,0 @@
/*
* 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.test.config;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import java.io.IOException;
import java.security.PrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.util.List;
import javax.inject.Singleton;
import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.TransientApiMetadata;
import org.jclouds.blobstore.config.LocalBlobStore;
import org.jclouds.chef.ChefApi;
import org.jclouds.chef.config.Validator;
import org.jclouds.chef.domain.Client;
import org.jclouds.chef.functions.BootstrapConfigForGroup;
import org.jclouds.chef.functions.ClientForGroup;
import org.jclouds.chef.functions.RunListForGroup;
import org.jclouds.chef.test.TransientChefApi;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.crypto.Crypto;
import org.jclouds.domain.JsonBall;
import org.jclouds.rest.ConfiguresHttpApi;
import org.jclouds.rest.config.RestModule;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.name.Names;
@ConfiguresHttpApi
public class TransientChefApiModule extends AbstractModule {
@Override
protected void configure() {
install(new RestModule());
bind(ChefApi.class).to(TransientChefApi.class);
bind(LocalBlobStore.class).annotatedWith(Names.named("databags"))
.toInstance(
ContextBuilder
.newBuilder(new TransientApiMetadata())
.modules(
ImmutableSet.<Module> of(new ExecutorServiceModule(sameThreadExecutor(),
sameThreadExecutor()))).buildInjector().getInstance(LocalBlobStore.class));
}
@Provides
@Singleton
public Supplier<PrivateKey> supplyKey() {
return new Supplier<PrivateKey>() {
@Override
public PrivateKey get() {
return null;
}
};
}
@Provides
@Singleton
CacheLoader<String, List<String>> runListForGroup(RunListForGroup runListForGroup) {
return CacheLoader.from(runListForGroup);
}
@Provides
@Singleton
CacheLoader<String, ? extends JsonBall> bootstrapConfigForGroup(BootstrapConfigForGroup bootstrapConfigForGroup) {
return CacheLoader.from(bootstrapConfigForGroup);
}
@Provides
@Singleton
CacheLoader<String, Client> groupToClient(ClientForGroup clientForGroup) {
return CacheLoader.from(clientForGroup);
}
@Provides
@Singleton
@Validator
public Optional<String> provideValidatorName(Injector injector) {
return Optional.absent();
}
@Provides
@Singleton
@Validator
public Optional<PrivateKey> provideValidatorCredential(Crypto crypto, Injector injector)
throws InvalidKeySpecException, IOException {
return Optional.absent();
}
}

View File

@ -1,2 +1 @@
org.jclouds.chef.test.TransientChefApiMetadata
org.jclouds.chef.ChefApiMetadata

View File

@ -1,69 +0,0 @@
/*
* 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.test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Properties;
import org.jclouds.chef.ChefApi;
import org.jclouds.chef.domain.DatabagItem;
import org.jclouds.chef.internal.BaseChefLiveTest;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code TransientChefApi}
*/
@Test(groups = { "integration" })
public class TransientChefApiIntegrationTest extends BaseChefLiveTest<ChefApi> {
public static final String PREFIX = System.getProperty("user.name") + "-jcloudstest";
private DatabagItem databagItem;
public TransientChefApiIntegrationTest() {
provider = "transientchef";
}
@Override
protected Properties setupProperties() {
return new Properties();
}
public void testCreateDatabag() {
api.deleteDatabag(PREFIX);
api.createDatabag(PREFIX);
}
@Test(dependsOnMethods = { "testCreateDatabag" })
public void testCreateDatabagItem() {
Properties config = new Properties();
config.setProperty("foo", "bar");
databagItem = api.createDatabagItem(PREFIX, new DatabagItem("config", json.toJson(config)));
assertNotNull(databagItem);
assertEquals(databagItem.getId(), "config");
assertEquals(config, json.fromJson(databagItem.toString(), Properties.class));
}
@Test(dependsOnMethods = "testCreateDatabagItem")
public void testUpdateDatabagItem() {
for (String databagItemId : api.listDatabagItems(PREFIX)) {
DatabagItem databagItem = api.getDatabagItem(PREFIX, databagItemId);
api.updateDatabagItem(PREFIX, databagItem);
}
}
}

View File

@ -1,33 +0,0 @@
/*
* 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.test;
import org.jclouds.View;
import org.jclouds.rest.internal.BaseHttpApiMetadataTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
@Test(groups = "unit", testName = "TransientChefApiMetadataTest")
public class TransientChefApiMetadataTest extends BaseHttpApiMetadataTest {
// no config management abstraction, yet
public TransientChefApiMetadataTest() {
super(new TransientChefApiMetadata(), ImmutableSet.<TypeToken<? extends View>> of());
}
}