mirror of https://github.com/apache/jclouds.git
fixed compute and basic archetype
This commit is contained in:
parent
f05e68869d
commit
e4e47748d4
|
@ -2,7 +2,7 @@
|
|||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -19,18 +19,21 @@
|
|||
====================================================================
|
||||
|
||||
-->
|
||||
<archetype-descriptor name="jclouds-compute-service-archetype">
|
||||
<archetype-descriptor name="jclouds-compute-service-archetype" partial="true">
|
||||
<requiredProperties>
|
||||
<requiredProperty key="groupId">
|
||||
<defaultValue>org.jclouds</defaultValue>
|
||||
</requiredProperty>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="package" >
|
||||
<defaultValue>${groupId}.${artifactId}</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="author">
|
||||
<defaultValue>Adrian Cole</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="providerName" />
|
||||
<requiredProperty key="providerEndpoint" />
|
||||
<requiredProperty key="providerUser" />
|
||||
<requiredProperty key="providerPassword" />
|
||||
<requiredProperty key="providerAccount" />
|
||||
<requiredProperty key="providerKey" />
|
||||
</requiredProperties>
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
|
@ -45,16 +48,10 @@
|
|||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory>src/test/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet encoding="UTF-8">
|
||||
<directory>src/test/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.json</include>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
|
@ -62,6 +59,6 @@
|
|||
<includes>
|
||||
<include>.gitignore</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</archetype-descriptor>
|
|
@ -1,9 +0,0 @@
|
|||
# use glob syntax.
|
||||
syntax: glob
|
||||
target
|
||||
.settings
|
||||
.classpath
|
||||
.project
|
||||
jclouds-${artifactId}.iml
|
||||
jclouds-${artifactId}.ipr
|
||||
jclouds-${artifactId}.iws
|
|
@ -1,47 +0,0 @@
|
|||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
/**
|
||||
*
|
||||
* 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 ${package};
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Related to a ${providerName} resource.
|
||||
*
|
||||
* @author ${author}
|
||||
*
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface ${providerName} {
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
/**
|
||||
*
|
||||
* 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 ${package};
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
import ${package}.internal.${providerName}AsyncClientImpl;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
*/
|
||||
@ImplementedBy(${providerName}AsyncClientImpl.class)
|
||||
public interface ${providerName}AsyncClient {
|
||||
/*
|
||||
* TODO: define interface methods for ${providerName}
|
||||
*/
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
/**
|
||||
*
|
||||
* 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 ${package};
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
public interface ${providerName}Client {
|
||||
/*
|
||||
* TODO: define synchronous versions of methods in ${providerName}AsyncClient
|
||||
*/
|
||||
}
|
|
@ -34,7 +34,7 @@ import com.google.inject.Key;
|
|||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextBuilder;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import ${package}.config.${providerName}ComputeServiceContextModule;
|
||||
import ${package}.compute.config.${providerName}ComputeServiceContextModule;
|
||||
import ${package}.config.${providerName}RestClientModule;
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
@ -45,8 +45,8 @@ import com.google.inject.TypeLiteral;
|
|||
*/
|
||||
public class ${providerName}ContextBuilder extends ComputeServiceContextBuilder<${providerName}AsyncClient, ${providerName}Client> {
|
||||
|
||||
public ${providerName}ContextBuilder(Properties props) {
|
||||
super(new TypeLiteral<${providerName}AsyncClient>() {},
|
||||
public ${providerName}ContextBuilder(String providerName, Properties props) {
|
||||
super(providerName, new TypeLiteral<${providerName}AsyncClient>() {},
|
||||
new TypeLiteral<${providerName}Client>() {},
|
||||
props);
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ public class ${providerName}ContextBuilder extends ComputeServiceContextBuilder<
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void addContextModule(List<Module> modules) {
|
||||
modules.add(new ${providerName}ComputeServiceContextModule());
|
||||
protected void addContextModule(String providerName, List<Module> modules) {
|
||||
modules.add(new ${providerName}ComputeServiceContextModule(providerName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,22 +45,29 @@ import com.google.inject.Module;
|
|||
*/
|
||||
public class ${providerName}ContextFactory {
|
||||
public static ComputeServiceContext createContext(Properties properties, Module... modules) {
|
||||
return new ${providerName}ContextBuilder(
|
||||
return new ${providerName}ContextBuilder("${artifactId}",
|
||||
new ${providerName}PropertiesBuilder(properties).build()).withModules(modules)
|
||||
.buildComputeServiceContext();
|
||||
}
|
||||
|
||||
public static ComputeServiceContext createContext(String user, String key,
|
||||
Module... modules) {
|
||||
return new ${providerName}ContextBuilder("${artifactId}",
|
||||
new ${providerName}PropertiesBuilder(user, key).build())
|
||||
.withModules(modules).buildComputeServiceContext();
|
||||
}
|
||||
|
||||
public static ComputeServiceContext createContext(Properties properties, String user,
|
||||
String key, Module... modules) {
|
||||
return new ${providerName}ContextBuilder(
|
||||
return new ${providerName}ContextBuilder("${artifactId}",
|
||||
new ${providerName}PropertiesBuilder(properties).withCredentials(user, key)
|
||||
.build()).withModules(modules).buildComputeServiceContext();
|
||||
}
|
||||
|
||||
public static ComputeServiceContext createContext(URI endpoint, String user, String key,
|
||||
Module... modules) {
|
||||
return new ${providerName}ContextBuilder(
|
||||
new ${providerName}PropertiesBuilder(endpoint, user, key).withEndpoint(endpoint).build())
|
||||
return new ${providerName}ContextBuilder("${artifactId}",
|
||||
new ${providerName}PropertiesBuilder(user, key).withEndpoint(endpoint).build())
|
||||
.withModules(modules).buildComputeServiceContext();
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
/**
|
||||
*
|
||||
* 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 ${package};
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static ${package}.reference.${providerName}Constants.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Builds properties used in ${providerName} Clients
|
||||
*
|
||||
* @author ${author}
|
||||
*
|
||||
*/
|
||||
public class ${providerName}PropertiesBuilder extends PropertiesBuilder {
|
||||
@Override
|
||||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_ENDPOINT, "${providerEndpoint}");
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_SESSIONINTERVAL, 8 * 60 + "");
|
||||
return properties;
|
||||
}
|
||||
|
||||
public ${providerName}PropertiesBuilder(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
public ${providerName}PropertiesBuilder(URI endpoint, String id, String secret) {
|
||||
super();
|
||||
withCredentials(id, secret);
|
||||
withEndpoint(endpoint);
|
||||
}
|
||||
|
||||
public ${providerName}PropertiesBuilder withTokenExpiration(long seconds) {
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_SESSIONINTERVAL, seconds + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
public ${providerName}PropertiesBuilder withCredentials(String id, String secret) {
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_USER, checkNotNull(id, "user"));
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_KEY, checkNotNull(secret, "key"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ${providerName}PropertiesBuilder withEndpoint(URI endpoint) {
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_ENDPOINT,
|
||||
checkNotNull(endpoint, "endpoint").toString());
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -16,28 +16,30 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package ${package}.config;
|
||||
package ${package}.compute.config;
|
||||
|
||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import ${package}.${providerName}Client;
|
||||
import ${package}.config.${providerName}ContextModule;
|
||||
|
||||
import org.jclouds.compute.LoadBalancerService;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Size;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.compute.predicates.RunScriptRunning;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
|
@ -49,23 +51,25 @@ import org.jclouds.domain.LocationScope;
|
|||
import org.jclouds.domain.internal.LocationImpl;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import ${package}.${providerName}AsyncClient;
|
||||
import ${package}.${providerName}Client;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
*/
|
||||
public class ${providerName}ComputeServiceContextModule extends ${providerName}ContextModule {
|
||||
|
||||
private final String providerName;
|
||||
|
||||
public ${providerName}ComputeServiceContextModule(String providerName){
|
||||
super(providerName);
|
||||
this.providerName=providerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
|
@ -74,8 +78,18 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
|
|||
bind(GetNodeMetadataStrategy.class).to(${providerName}GetNodeMetadataStrategy.class);
|
||||
bind(RebootNodeStrategy.class).to(${providerName}RebootNodeStrategy.class);
|
||||
bind(DestroyNodeStrategy.class).to(${providerName}DestroyNodeStrategy.class);
|
||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* tested known configuration
|
||||
*/
|
||||
@Provides
|
||||
@Named("DEFAULT")
|
||||
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||
return template.osFamily(UBUNTU);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("NAMING_CONVENTION")
|
||||
@Singleton
|
||||
|
@ -107,7 +121,7 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(ComputeMetadata node) {
|
||||
public boolean execute(String id) {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
|
@ -123,11 +137,19 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends ComputeMetadata> execute() {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
return null;
|
||||
public Iterable<? extends ComputeMetadata> list() {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(
|
||||
Predicate<ComputeMetadata> filter) {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -140,7 +162,7 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
|
|||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata execute(ComputeMetadata node) {
|
||||
public NodeMetadata execute(String id) {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
|
@ -156,7 +178,7 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(ComputeMetadata node) {
|
||||
public boolean execute(String id) {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
|
@ -165,62 +187,44 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
|
|||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ComputeServiceContext provideContext(ComputeService computeService,
|
||||
RestContext<${providerName}AsyncClient, ${providerName}Client> context) {
|
||||
return new ComputeServiceContextImpl<${providerName}AsyncClient, ${providerName}Client>(computeService, context);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("NOT_RUNNING")
|
||||
protected Predicate<SshClient> runScriptRunning(RunScriptRunning stateRunning) {
|
||||
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3,
|
||||
protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
|
||||
return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Location getDefaultLocation(Map<String, ? extends Location> locations) {
|
||||
return locations.get("SANFRANCISCO");
|
||||
Location getDefaultLocation(Set<? extends Location> locations) {
|
||||
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Map<String, ? extends Location> getDefaultLocations(${providerName}Client sync, LogHolder holder,
|
||||
Function<ComputeMetadata, String> indexer) {
|
||||
final Set<Location> locations = Sets.newHashSet();
|
||||
Set<? extends Location> getAssignableLocations(${providerName}Client sync, LogHolder holder ) {
|
||||
final Set<Location> assignableLocations = Sets.newHashSet();
|
||||
holder.logger.debug(">> providing locations");
|
||||
locations.add(new LocationImpl(LocationScope.ZONE, "SANFRANCISCO", "San Francisco, CA", null,
|
||||
true));
|
||||
holder.logger.debug("<< locations(%d)", locations.size());
|
||||
return Maps.uniqueIndex(locations, new Function<Location, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Location from) {
|
||||
return from.getId();
|
||||
}
|
||||
});
|
||||
Location parent = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
||||
/*
|
||||
* TODO: add children with parent to locations. Note do not add parent to assignablelocations
|
||||
* directly
|
||||
*/
|
||||
|
||||
holder.logger.debug("<< locations(%d)", assignableLocations.size());
|
||||
return assignableLocations;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Function<ComputeMetadata, String> indexer() {
|
||||
return new Function<ComputeMetadata, String>() {
|
||||
@Override
|
||||
public String apply(ComputeMetadata from) {
|
||||
return from.getId();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Map<String, ? extends Size> provideSizes(${providerName}Client sync,
|
||||
Map<String, ? extends Image> images, LogHolder holder,
|
||||
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
||||
TimeoutException, ExecutionException {
|
||||
protected Set<? extends Size> provideSizes(${providerName}Client sync,
|
||||
Set<? extends Image> images, LogHolder holder) {
|
||||
final Set<Size> sizes = Sets.newHashSet();
|
||||
holder.logger.debug(">> providing sizes");
|
||||
|
||||
|
@ -229,20 +233,13 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
|
|||
*/
|
||||
|
||||
holder.logger.debug("<< sizes(%d)", sizes.size());
|
||||
return Maps.uniqueIndex(sizes, indexer);
|
||||
}
|
||||
|
||||
private static class LogHolder {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
return sizes;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Map<String, ? extends Image> provideImages(final ${providerName}Client sync, LogHolder holder,
|
||||
Function<ComputeMetadata, String> indexer, Location location)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
protected Set<? extends Image> provideImages(final ${providerName}Client sync, LogHolder holder,
|
||||
Location location) {
|
||||
final Set<Image> images = Sets.newHashSet();
|
||||
holder.logger.debug(">> providing images");
|
||||
|
||||
|
@ -251,6 +248,13 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
|
|||
*/
|
||||
|
||||
holder.logger.debug("<< images(%d)", images.size());
|
||||
return Maps.uniqueIndex(images, indexer);
|
||||
return images;
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
private static class LogHolder {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
/**
|
||||
*
|
||||
* 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 ${package}.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.gson.*;
|
||||
import ${package}.${providerName}AsyncClient;
|
||||
import ${package}.${providerName}Client;
|
||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import ${package}.${providerName};
|
||||
import ${package}.reference.${providerName}Constants;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Configures the ${providerName} connection, including logging and http transport.
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
public class ${providerName}ContextModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(DateSecondsAdapter.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
RestContext<${providerName}AsyncClient, ${providerName}Client> provideContext(Closer closer, ${providerName}AsyncClient asyncApi,
|
||||
${providerName}Client syncApi, @${providerName} URI endPoint, @Named(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER) String account) {
|
||||
return new RestContextImpl<${providerName}AsyncClient, ${providerName}Client>(closer, asyncApi, syncApi, endPoint, account);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class DateSecondsAdapter implements DateAdapter {
|
||||
|
||||
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getTime());
|
||||
}
|
||||
|
||||
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String toParse = json.getAsJsonPrimitive().getAsString();
|
||||
return new Date(Long.valueOf(toParse));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
/**
|
||||
*
|
||||
* 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 ${package}.config;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.GridO;
|
||||
import org.jclouds.concurrent.ExpirableSupplier;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.reference.GridOConstants;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import static ${package}.reference.${providerName}Constants.*;
|
||||
|
||||
/**
|
||||
* Configures the ${providerName} connection.
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class ${providerName}RestClientModule extends AbstractModule {
|
||||
/*
|
||||
* TODO: modify configuration for ${providerName}Client
|
||||
*/
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
requestInjection(this);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@${providerName}
|
||||
protected URI provideURI(@Named(${providerName}Constants.PROPERTY_${ucaseProviderName}_ENDPOINT) String endpoint) {
|
||||
return URI.create(endpoint);
|
||||
}
|
||||
|
||||
// borrowing concurrency code to ensure that caching takes place properly
|
||||
@Provides
|
||||
@TimeStamp
|
||||
Supplier<Long> provideTimeStampCache(
|
||||
@Named(PROPERTY_${ucaseProviderName}_SESSIONINTERVAL) long seconds) {
|
||||
return new ExpirableSupplier<Long>(new Supplier<Long>() {
|
||||
public Long get() {
|
||||
return System.currentTimeMillis() / 1000;
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
/**
|
||||
*
|
||||
* 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 ${package}.internal;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import ${package}.${providerName}AsyncClient;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
*/
|
||||
@Singleton
|
||||
public class ${providerName}AsyncClientImpl implements ${providerName}AsyncClient {
|
||||
|
||||
@Inject
|
||||
public ${providerName}AsyncClientImpl() {
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: implement ${providerName}AsyncClient
|
||||
*/
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
|
||||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
/**
|
||||
*
|
||||
* 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 ${package}.reference;
|
||||
|
||||
/**
|
||||
* Configuration properties and constants used in ${providerName} connections.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface ${providerName}Constants {
|
||||
public static final String PROPERTY_${ucaseProviderName}_ENDPOINT = "jclouds.${lcaseProviderName}.endpoint";
|
||||
public static final String PROPERTY_${ucaseProviderName}_USER = "jclouds.${lcaseProviderName}.user";
|
||||
public static final String PROPERTY_${ucaseProviderName}_KEY = "jclouds.${lcaseProviderName}.key";
|
||||
/**
|
||||
* how long do we wait before obtaining a new timestamp for requests.
|
||||
*/
|
||||
public static final String PROPERTY_${ucaseProviderName}_SESSIONINTERVAL = "jclouds.${lcaseProviderName}.sessioninterval";
|
||||
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
|
||||
#set( $camelCaseProviderName = "${providerName.substring(0, 1).toLowerCase()}${providerName.substring(1)}" )
|
||||
/**
|
||||
*
|
||||
* 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 ${package};
|
||||
|
||||
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.BaseComputeServiceLiveTest;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
*/
|
||||
@Test(groups = "live", enabled = true, sequential = true, testName = "${lcaseProviderName}.${providerName}ComputeServiceLiveTest")
|
||||
public class ${providerName}ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void setServiceDefaults() {
|
||||
service = "${lcaseProviderName}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildScript() {
|
||||
return new StringBuilder()
|
||||
.append("TODO: define build script")
|
||||
.toString();
|
||||
}
|
||||
|
||||
protected Template buildTemplate(TemplateBuilder templateBuilder) {
|
||||
return templateBuilder.osFamily(CENTOS).imageDescriptionMatches("TODO: insert image description").smallest()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JschSshClientModule getSshModule() {
|
||||
return new JschSshClientModule();
|
||||
}
|
||||
|
||||
public void testAssignability() throws Exception {
|
||||
@SuppressWarnings("unused")
|
||||
RestContext<${providerName}AsyncClient, ${providerName}Client> ${camelCaseProviderName}Context =
|
||||
new ComputeServiceContextFactory().createContext(service, user, password).getProviderSpecificContext();
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void endToEndComputeServiceTest() {
|
||||
/*
|
||||
* TODO: adapt the following sample test for ${providerName}
|
||||
*/
|
||||
ComputeService service = context.getComputeService();
|
||||
Template t = service.templateBuilder().minRam(1024).imageId("1532").build();
|
||||
|
||||
assertEquals(t.getImage().getId(), "1532");
|
||||
service.runNodesWithTag(this.service, 1, t);
|
||||
|
||||
Map<String, ? extends ComputeMetadata> nodes = service.getNodes();
|
||||
|
||||
ComputeMetadata node = Iterables.find(nodes.values(), new Predicate<ComputeMetadata>() {
|
||||
@Override
|
||||
public boolean apply(ComputeMetadata computeMetadata) {
|
||||
return computeMetadata.getName().startsWith(${providerName}ComputeServiceLiveTest.this.service);
|
||||
}
|
||||
});
|
||||
|
||||
NodeMetadata nodeMetadata = service.getNodeMetadata(node);
|
||||
assertEquals(nodeMetadata.getPublicAddresses().size(), 1,
|
||||
"There must be 1 public address for the node");
|
||||
assertTrue(nodeMetadata.getName().startsWith(this.service));
|
||||
service.rebootNode(nodeMetadata); // blocks until finished
|
||||
|
||||
assertEquals(service.getNodeMetadata(nodeMetadata).getState(), NodeState.RUNNING);
|
||||
service.destroyNode(nodeMetadata);
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
/**
|
||||
*
|
||||
* 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 ${package};
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* End to end live test for ${providerName}
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
@Test(groups = "live", testName = "${lcaseProviderName}.${providerName}LiveTest")
|
||||
public class ${providerName}LiveTest {
|
||||
private ${providerName}Client client;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
|
||||
"jclouds.test.endpoint");
|
||||
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||
|
||||
client = new ${providerName}ContextBuilder(
|
||||
new ${providerName}PropertiesBuilder(URI.create(endpoint), user, password).build())
|
||||
.withModules(new Log4JLoggingModule()).buildContext().getApi();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests server start, reboot and deletion.
|
||||
* TODO: describe additional services tested
|
||||
*/
|
||||
@Test(enabled=true)
|
||||
public void testServerLifecycle() {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests common server image operations.
|
||||
*/
|
||||
@Test(enabled=true)
|
||||
public void testImageLifecycle() {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
}
|
||||
|
||||
@Test(enabled=true)
|
||||
public void testShellAccess() throws IOException {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* In case anything went wrong during the tests, removes the objects
|
||||
* created in the tests.
|
||||
*/
|
||||
@AfterTest
|
||||
public void cleanup() {
|
||||
/*
|
||||
* TODO: implement
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
|
@ -18,16 +18,19 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package ${package};
|
||||
package ${package}.compute;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import ${package}.${providerName}ContextBuilder;
|
||||
import ${package}.${providerName}PropertiesBuilder;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
|
@ -0,0 +1,70 @@
|
|||
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
|
||||
#set( $camelCaseProviderName = "${providerName.substring(0, 1).toLowerCase()}${providerName.substring(1)}" )
|
||||
/**
|
||||
*
|
||||
* 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 ${package}.compute;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import ${package}.${providerName}AsyncClient;
|
||||
import ${package}.${providerName}Client;
|
||||
import org.jclouds.compute.BaseComputeServiceLiveTest;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.domain.Architecture;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
*/
|
||||
@Test(groups = "live", enabled = true, sequential = true, testName = "${lcaseProviderName}.${providerName}ComputeServiceLiveTest")
|
||||
public class ${providerName}ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void setServiceDefaults() {
|
||||
service = "${lcaseProviderName}";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateBuilder() {
|
||||
Template defaultTemplate = client.templateBuilder().build();
|
||||
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
|
||||
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(defaultTemplate.getLocation().getId(), "DFW1");
|
||||
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JschSshClientModule getSshModule() {
|
||||
return new JschSshClientModule();
|
||||
}
|
||||
|
||||
public void testAssignability() throws Exception {
|
||||
@SuppressWarnings("unused")
|
||||
RestContext<${providerName}AsyncClient, ${providerName}Client> tmContext = new ComputeServiceContextFactory()
|
||||
.createContext(service, user, password).getProviderSpecificContext();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
|
||||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
/**
|
||||
*
|
||||
* 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 ${package}.config;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import org.jboss.resteasy.specimpl.UriBuilderImpl;
|
||||
import org.jclouds.${providerName}PropertiesBuilder;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.HttpRetryHandler;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||
import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler;
|
||||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.http.handlers.RedirectionRetryHandler;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
*/
|
||||
@Test(groups = "unit", testName = "${lcaseProviderName}.${providerName}ContextModule")
|
||||
public class ${providerName}ContextModuleTest {
|
||||
|
||||
Injector createInjector() {
|
||||
return Guice.createInjector(new ${providerName}RestClientModule(), new ${providerName}ContextModule("${artifactId}") {
|
||||
@Override
|
||||
protected void configure() {
|
||||
Jsr330.bindProperties(this.binder(), new ${providerName}PropertiesBuilder("user", "pass")
|
||||
.build());
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
bind(UriBuilder.class).to(UriBuilderImpl.class);
|
||||
super.configure();
|
||||
}
|
||||
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),
|
||||
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServerErrorHandler() {
|
||||
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
|
||||
assertEquals(handler.getServerErrorHandler().getClass(),
|
||||
"TODO: insert expected error handler class");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClientErrorHandler() {
|
||||
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
|
||||
assertEquals(handler.getClientErrorHandler().getClass(),
|
||||
"TODO: insert expected error handler class");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClientRetryHandler() {
|
||||
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
|
||||
assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedirectionRetryHandler() {
|
||||
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
|
||||
assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -30,7 +30,7 @@
|
|||
</parent>
|
||||
<artifactId>jclouds-json-client-archetype</artifactId>
|
||||
<name>jclouds JSON client archetype</name>
|
||||
<description>Maven archetype for a client of a JSON-speaking service</description>
|
||||
<description>Maven archetype for a provider of a JSON-speaking service</description>
|
||||
<packaging>maven-archetype</packaging>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -30,10 +30,10 @@
|
|||
<requiredProperty key="author">
|
||||
<defaultValue>Adrian Cole</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="clientName" />
|
||||
<requiredProperty key="clientEndpoint" />
|
||||
<requiredProperty key="clientUser" />
|
||||
<requiredProperty key="clientPassword" />
|
||||
<requiredProperty key="providerName" />
|
||||
<requiredProperty key="providerEndpoint" />
|
||||
<requiredProperty key="providerAccount" />
|
||||
<requiredProperty key="providerKey" />
|
||||
</requiredProperties>
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#set( $lcaseClientName = ${clientName.toLowerCase()} )
|
||||
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
|
||||
#set( $symbol_dollar = '$' )
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
@ -37,13 +37,13 @@
|
|||
</parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>jclouds-${artifactId}</artifactId>
|
||||
<name>jclouds ${clientName} core</name>
|
||||
<description>jclouds components to access ${clientName}</description>
|
||||
<name>jclouds ${providerName} core</name>
|
||||
<description>jclouds components to access ${providerName}</description>
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/${lcaseClientName}</connection>
|
||||
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/${lcaseClientName}</developerConnection>
|
||||
<url>http://jclouds.googlecode.com/svn/trunk/${lcaseClientName}</url>
|
||||
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/${lcaseProviderName}</connection>
|
||||
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/${lcaseProviderName}</developerConnection>
|
||||
<url>http://jclouds.googlecode.com/svn/trunk/${lcaseProviderName}</url>
|
||||
</scm>
|
||||
|
||||
<!-- bootstrapping: need to fetch the project POM -->
|
||||
|
@ -62,8 +62,8 @@
|
|||
</repositories>
|
||||
|
||||
<properties>
|
||||
<jclouds.test.user>${clientUser}</jclouds.test.user>
|
||||
<jclouds.test.key>${clientPassword}</jclouds.test.key>
|
||||
<jclouds.test.user>${providerAccount}</jclouds.test.user>
|
||||
<jclouds.test.key>${providerKey}</jclouds.test.key>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
#set( $ucaseClientName = ${clientName.toUpperCase()} )
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 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 ${package};
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import ${package}.config.${clientName}ContextModule;
|
||||
import ${package}.config.${clientName}RestClientModule;
|
||||
import ${package}.reference.${clientName}Constants;
|
||||
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
public class ${clientName}ContextBuilder extends RestContextBuilder<${clientName}AsyncClient, ${clientName}Client> {
|
||||
|
||||
public ${clientName}ContextBuilder(String providerName, Properties props) {
|
||||
super(providerName, new TypeLiteral<${clientName}AsyncClient>() {
|
||||
}, new TypeLiteral<${clientName}Client>() {
|
||||
}, props);
|
||||
checkNotNull(properties.getProperty(${clientName}Constants.PROPERTY_${ucaseClientName}_USER));
|
||||
checkNotNull(properties.getProperty(${clientName}Constants.PROPERTY_${ucaseClientName}_PASSWORD));
|
||||
}
|
||||
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new ${clientName}RestClientModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addContextModule(String providerName, List<Module> modules) {
|
||||
modules.add(new ${clientName}ContextModule(providerName));
|
||||
}
|
||||
|
||||
}
|
|
@ -52,7 +52,7 @@ import java.lang.annotation.Target;
|
|||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Related to a ${clientName} resource.
|
||||
* Related to a ${providerName} resource.
|
||||
*
|
||||
* @author ${author}
|
||||
*
|
||||
|
@ -60,6 +60,6 @@ import javax.inject.Qualifier;
|
|||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface ${clientName} {
|
||||
public @interface ${providerName} {
|
||||
|
||||
}
|
|
@ -39,29 +39,29 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
|||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to ${clientName} via their REST API.
|
||||
* Provides asynchronous access to ${providerName} via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see ${clientName}Client
|
||||
* @see <a href="TODO: insert URL of client documentation" />
|
||||
* @see ${providerName}Client
|
||||
* @see <a href="TODO: insert URL of provider documentation" />
|
||||
* @author ${author}
|
||||
*/
|
||||
@Endpoint(${clientName}.class)
|
||||
@Endpoint(${providerName}.class)
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
public interface ${clientName}AsyncClient {
|
||||
public interface ${providerName}AsyncClient {
|
||||
/*
|
||||
* TODO: define interface methods for ${clientName}
|
||||
* TODO: define interface methods for ${providerName}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see ${clientName}AsyncClient#list()
|
||||
* @see ${providerName}AsyncClient#list()
|
||||
*/
|
||||
@GET
|
||||
@Path("/item")
|
||||
ListenableFuture<String> list();
|
||||
|
||||
/**
|
||||
* @see ${clientName}AsyncClient#get(String)
|
||||
* @see ${providerName}AsyncClient#get(String)
|
||||
*/
|
||||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
|
@ -49,18 +49,18 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to ${clientName}.
|
||||
* Provides synchronous access to ${providerName}.
|
||||
* <p/>
|
||||
*
|
||||
* @see ${clientName}AsyncClient
|
||||
* @see <a href="TODO: insert URL of ${clientName} documentation" />
|
||||
* @see ${providerName}AsyncClient
|
||||
* @see <a href="TODO: insert URL of ${providerName} documentation" />
|
||||
* @author ${author}
|
||||
*/
|
||||
@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS)
|
||||
public interface ${clientName}Client {
|
||||
public interface ${providerName}Client {
|
||||
/*
|
||||
* Note all these delegate to methods in ${clientName}AsyncClient with a specified or inherited timeout.
|
||||
* The singatures should match those of ${clientName}AsyncClient, except the returnvals should not be
|
||||
* Note all these delegate to methods in ${providerName}AsyncClient with a specified or inherited timeout.
|
||||
* The singatures should match those of ${providerName}AsyncClient, except the returnvals should not be
|
||||
* wrapped in a ListenableFuture
|
||||
*/
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
/**
|
||||
*
|
||||
* 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 ${package};
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import ${package}.${providerName}AsyncClient;
|
||||
import ${package}.${providerName}Client;
|
||||
|
||||
import ${package}.config.${providerName}ContextModule;
|
||||
import ${package}.config.${providerName}RestClientModule;
|
||||
import ${package}.reference.${providerName}Constants;
|
||||
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
public class ${providerName}ContextBuilder extends RestContextBuilder<${providerName}AsyncClient, ${providerName}Client> {
|
||||
|
||||
public ${providerName}ContextBuilder(String providerName, Properties props) {
|
||||
super(providerName, new TypeLiteral<${providerName}AsyncClient>() {
|
||||
}, new TypeLiteral<${providerName}Client>() {
|
||||
}, props);
|
||||
checkNotNull(properties.getProperty(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER));
|
||||
checkNotNull(properties.getProperty(${providerName}Constants.PROPERTY_${ucaseProviderName}_PASSWORD));
|
||||
}
|
||||
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new ${providerName}RestClientModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addContextModule(String providerName, List<Module> modules) {
|
||||
modules.add(new ${providerName}ContextModule(providerName));
|
||||
}
|
||||
|
||||
}
|
|
@ -53,7 +53,7 @@ import org.jclouds.rest.RestContext;
|
|||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Creates {@link RestContext} for {@link ${clientName}Client} instances based on the most commonly
|
||||
* Creates {@link RestContext} for {@link ${providerName}Client} instances based on the most commonly
|
||||
* requested arguments.
|
||||
* <p/>
|
||||
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
|
||||
|
@ -64,19 +64,19 @@ import com.google.inject.Module;
|
|||
*
|
||||
* @author ${author}
|
||||
* @see RestContext
|
||||
* @see ${clientName}Client
|
||||
* @see ${clientName}AsyncClient
|
||||
* @see ${providerName}Client
|
||||
* @see ${providerName}AsyncClient
|
||||
*/
|
||||
public class ${clientName}ContextFactory {
|
||||
public class ${providerName}ContextFactory {
|
||||
|
||||
public static RestContext<${clientName}AsyncClient, ${clientName}Client> createContext(String user, String password,
|
||||
public static RestContext<${providerName}AsyncClient, ${providerName}Client> createContext(String user, String password,
|
||||
Module... modules) {
|
||||
return new ${clientName}ContextBuilder("${artifactId}", new ${clientName}PropertiesBuilder(user, password).build())
|
||||
return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(user, password).build())
|
||||
.withModules(modules).buildContext();
|
||||
}
|
||||
|
||||
public static RestContext<${clientName}AsyncClient, ${clientName}Client> createContext(Properties properties, Module... modules) {
|
||||
return new ${clientName}ContextBuilder("${artifactId}", new ${clientName}PropertiesBuilder(properties).build())
|
||||
public static RestContext<${providerName}AsyncClient, ${providerName}Client> createContext(Properties properties, Module... modules) {
|
||||
return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(properties).build())
|
||||
.withModules(modules).buildContext();
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#set( $ucaseClientName = ${clientName.toUpperCase()} )
|
||||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
|
@ -28,9 +28,9 @@
|
|||
package ${package};
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static ${package}.reference.${clientName}Constants.PROPERTY_${ucaseClientName}_ENDPOINT;
|
||||
import static ${package}.reference.${clientName}Constants.PROPERTY_${ucaseClientName}_PASSWORD;
|
||||
import static ${package}.reference.${clientName}Constants.PROPERTY_${ucaseClientName}_USER;
|
||||
import static ${package}.reference.${providerName}Constants.PROPERTY_${ucaseProviderName}_ENDPOINT;
|
||||
import static ${package}.reference.${providerName}Constants.PROPERTY_${ucaseProviderName}_PASSWORD;
|
||||
import static ${package}.reference.${providerName}Constants.PROPERTY_${ucaseProviderName}_USER;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
@ -38,35 +38,35 @@ import java.util.Properties;
|
|||
import org.jclouds.PropertiesBuilder;
|
||||
|
||||
/**
|
||||
* Builds properties used in ${clientName} Clients
|
||||
* Builds properties used in ${providerName} Clients
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
public class ${clientName}PropertiesBuilder extends PropertiesBuilder {
|
||||
public class ${providerName}PropertiesBuilder extends PropertiesBuilder {
|
||||
@Override
|
||||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_${ucaseClientName}_ENDPOINT, "${clientEndpoint}");
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_ENDPOINT, "${providerEndpoint}");
|
||||
return properties;
|
||||
}
|
||||
|
||||
public ${clientName}PropertiesBuilder(Properties properties) {
|
||||
public ${providerName}PropertiesBuilder(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
public ${clientName}PropertiesBuilder(String id, String secret) {
|
||||
public ${providerName}PropertiesBuilder(String id, String secret) {
|
||||
super();
|
||||
withCredentials(id, secret);
|
||||
}
|
||||
|
||||
public ${clientName}PropertiesBuilder withCredentials(String id, String secret) {
|
||||
properties.setProperty(PROPERTY_${ucaseClientName}_USER, checkNotNull(id, "user"));
|
||||
properties.setProperty(PROPERTY_${ucaseClientName}_PASSWORD, checkNotNull(secret, "password"));
|
||||
public ${providerName}PropertiesBuilder withCredentials(String id, String secret) {
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_USER, checkNotNull(id, "user"));
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_PASSWORD, checkNotNull(secret, "password"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ${clientName}PropertiesBuilder withEndpoint(URI endpoint) {
|
||||
properties.setProperty(PROPERTY_${ucaseClientName}_ENDPOINT, checkNotNull(endpoint, "endpoint")
|
||||
public ${providerName}PropertiesBuilder withEndpoint(URI endpoint) {
|
||||
properties.setProperty(PROPERTY_${ucaseProviderName}_ENDPOINT, checkNotNull(endpoint, "endpoint")
|
||||
.toString());
|
||||
return this;
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
#set( $ucaseClientName = ${clientName.toUpperCase()} )
|
||||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
@ -50,22 +50,22 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.lifecycle.Closer;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import ${package}.${clientName};
|
||||
import ${package}.${clientName}AsyncClient;
|
||||
import ${package}.${clientName}Client;
|
||||
import ${package}.reference.${clientName}Constants;
|
||||
import ${package}.${providerName};
|
||||
import ${package}.${providerName}AsyncClient;
|
||||
import ${package}.${providerName}Client;
|
||||
import ${package}.reference.${providerName}Constants;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Configures the ${clientName} connection, including logging and http transport.
|
||||
* Configures the ${providerName} connection, including logging and http transport.
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
public class ${clientName}ContextModule extends AbstractModule {
|
||||
public class ${providerName}ContextModule extends AbstractModule {
|
||||
|
||||
public ${clientName}ContextModule(String providerName) {
|
||||
public ${providerName}ContextModule(String providerName) {
|
||||
// providerName ignored right now
|
||||
}
|
||||
|
||||
|
@ -77,9 +77,9 @@ public class ${clientName}ContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
RestContext<${clientName}AsyncClient, ${clientName}Client> provideContext(Closer closer, ${clientName}AsyncClient asyncApi,
|
||||
${clientName}Client syncApi, @${clientName} URI endPoint, @Named(${clientName}Constants.PROPERTY_${ucaseClientName}_USER) String account) {
|
||||
return new RestContextImpl<${clientName}AsyncClient, ${clientName}Client>(closer, asyncApi, syncApi, endPoint, account);
|
||||
RestContext<${providerName}AsyncClient, ${providerName}Client> provideContext(Closer closer, ${providerName}AsyncClient asyncApi,
|
||||
${providerName}Client syncApi, @${providerName} URI endPoint, @Named(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER) String account) {
|
||||
return new RestContextImpl<${providerName}AsyncClient, ${providerName}Client>(closer, asyncApi, syncApi, endPoint, account);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
#set( $ucaseClientName = ${clientName.toUpperCase()} )
|
||||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
@ -55,22 +55,22 @@ import org.jclouds.rest.ConfiguresRestClient;
|
|||
import org.jclouds.rest.RestClientFactory;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
|
||||
import ${package}.${clientName};
|
||||
import ${package}.${clientName}Client;
|
||||
import ${package}.${clientName}AsyncClient;
|
||||
import ${package}.reference.${clientName}Constants;
|
||||
import ${package}.${providerName};
|
||||
import ${package}.${providerName}Client;
|
||||
import ${package}.${providerName}AsyncClient;
|
||||
import ${package}.reference.${providerName}Constants;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Configures the ${clientName} connection.
|
||||
* Configures the ${providerName} connection.
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class ${clientName}RestClientModule extends AbstractModule {
|
||||
public class ${providerName}RestClientModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
@ -81,8 +81,8 @@ public class ${clientName}RestClientModule extends AbstractModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
public BasicAuthentication provideBasicAuthentication(
|
||||
@Named(${clientName}Constants.PROPERTY_${ucaseClientName}_USER) String user,
|
||||
@Named(${clientName}Constants.PROPERTY_${ucaseClientName}_PASSWORD) String password,
|
||||
@Named(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER) String user,
|
||||
@Named(${providerName}Constants.PROPERTY_${ucaseProviderName}_PASSWORD) String password,
|
||||
EncryptionService encryptionService)
|
||||
throws UnsupportedEncodingException {
|
||||
return new BasicAuthentication(user, password, encryptionService);
|
||||
|
@ -90,21 +90,21 @@ public class ${clientName}RestClientModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected ${clientName}AsyncClient provideClient(RestClientFactory factory) {
|
||||
return factory.create(${clientName}AsyncClient.class);
|
||||
protected ${providerName}AsyncClient provideClient(RestClientFactory factory) {
|
||||
return factory.create(${providerName}AsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public ${clientName}Client provideClient(${clientName}AsyncClient client) throws IllegalArgumentException,
|
||||
public ${providerName}Client provideClient(${providerName}AsyncClient provider) throws IllegalArgumentException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(${clientName}Client.class, client);
|
||||
return SyncProxy.create(${providerName}Client.class, provider);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@${clientName}
|
||||
protected URI provideURI(@Named(${clientName}Constants.PROPERTY_${ucaseClientName}_ENDPOINT) String endpoint) {
|
||||
@${providerName}
|
||||
protected URI provideURI(@Named(${providerName}Constants.PROPERTY_${ucaseProviderName}_ENDPOINT) String endpoint) {
|
||||
return URI.create(endpoint);
|
||||
}
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
#set( $lcaseClientName = ${clientName.toLowerCase()} )
|
||||
#set( $ucaseClientName = ${clientName.toUpperCase()} )
|
||||
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
|
||||
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
@ -44,12 +44,12 @@
|
|||
package ${package}.reference;
|
||||
|
||||
/**
|
||||
* Configuration properties and constants used in ${clientName} connections.
|
||||
* Configuration properties and constants used in ${providerName} connections.
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
public interface ${clientName}Constants {
|
||||
public static final String PROPERTY_${ucaseClientName}_ENDPOINT = "jclouds.${lcaseClientName}.endpoint";
|
||||
public static final String PROPERTY_${ucaseClientName}_USER = "jclouds.${lcaseClientName}.user";
|
||||
public static final String PROPERTY_${ucaseClientName}_PASSWORD = "jclouds.${lcaseClientName}.password";
|
||||
public interface ${providerName}Constants {
|
||||
public static final String PROPERTY_${ucaseProviderName}_ENDPOINT = "jclouds.${lcaseProviderName}.endpoint";
|
||||
public static final String PROPERTY_${ucaseProviderName}_USER = "jclouds.${lcaseProviderName}.user";
|
||||
public static final String PROPERTY_${ucaseProviderName}_PASSWORD = "jclouds.${lcaseProviderName}.password";
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#set( $lcaseClientName = ${clientName.toLowerCase()} )
|
||||
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
|
@ -57,19 +57,19 @@ import com.google.inject.Provides;
|
|||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ${clientName}AsyncClient}
|
||||
* Tests annotation parsing of {@code ${providerName}AsyncClient}
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
@Test(groups = "unit", testName = "${lcaseClientName}.${clientName}AsyncClientTest")
|
||||
public class ${clientName}AsyncClientTest extends RestClientTest<${clientName}AsyncClient> {
|
||||
@Test(groups = "unit", testName = "${lcaseProviderName}.${providerName}AsyncClientTest")
|
||||
public class ${providerName}AsyncClientTest extends RestClientTest<${providerName}AsyncClient> {
|
||||
|
||||
|
||||
public void testList() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ${clientName}AsyncClient.class.getMethod("list");
|
||||
GeneratedHttpRequest<${clientName}AsyncClient> httpRequest = processor.createRequest(method);
|
||||
Method method = ${providerName}AsyncClient.class.getMethod("list");
|
||||
GeneratedHttpRequest<${providerName}AsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET ${clientEndpoint}/item HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class ${clientName}AsyncClientTest extends RestClientTest<${clientName}As
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET ${clientEndpoint}/item HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one" header
|
||||
assertHeadersEqual(httpRequest, "Authorization: Basic Zm9vOmJhcg==\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
@ -92,10 +92,10 @@ public class ${clientName}AsyncClientTest extends RestClientTest<${clientName}As
|
|||
}
|
||||
|
||||
public void testGet() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ${clientName}AsyncClient.class.getMethod("get", long.class);
|
||||
GeneratedHttpRequest<${clientName}AsyncClient> httpRequest = processor.createRequest(method, 1);
|
||||
Method method = ${providerName}AsyncClient.class.getMethod("get", long.class);
|
||||
GeneratedHttpRequest<${providerName}AsyncClient> httpRequest = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET ${clientEndpoint}/item/1 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item/1 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
|
@ -110,14 +110,14 @@ public class ${clientName}AsyncClientTest extends RestClientTest<${clientName}As
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<${clientName}AsyncClient> httpRequest) {
|
||||
protected void checkFilters(GeneratedHttpRequest<${providerName}AsyncClient> httpRequest) {
|
||||
assertEquals(httpRequest.getFilters().size(), 1);
|
||||
assertEquals(httpRequest.getFilters().get(0).getClass(), BasicAuthentication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<${clientName}AsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<${clientName}AsyncClient>>() {
|
||||
protected TypeLiteral<RestAnnotationProcessor<${providerName}AsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<${providerName}AsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -126,10 +126,10 @@ public class ${clientName}AsyncClientTest extends RestClientTest<${clientName}As
|
|||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
Jsr330.bindProperties(binder(), new ${clientName}PropertiesBuilder(
|
||||
Jsr330.bindProperties(binder(), new ${providerName}PropertiesBuilder(
|
||||
new Properties()).build());
|
||||
bind(URI.class).annotatedWith(${clientName}.class).toInstance(
|
||||
URI.create("${clientEndpoint}"));
|
||||
bind(URI.class).annotatedWith(${providerName}.class).toInstance(
|
||||
URI.create("${providerEndpoint}"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
|
@ -1,4 +1,4 @@
|
|||
#set( $lcaseClientName = ${clientName.toLowerCase()} )
|
||||
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
|
||||
#set( $symbol_pound = '#' )
|
||||
#set( $symbol_dollar = '$' )
|
||||
#set( $symbol_escape = '\' )
|
||||
|
@ -35,21 +35,21 @@ import org.testng.annotations.BeforeGroups;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ${clientName}Client}
|
||||
* Tests behavior of {@code ${providerName}Client}
|
||||
*
|
||||
* @author ${author}
|
||||
*/
|
||||
@Test(groups = "live", testName = "${lcaseClientName}.${clientName}ClientLiveTest")
|
||||
public class ${clientName}ClientLiveTest {
|
||||
@Test(groups = "live", testName = "${lcaseProviderName}.${providerName}ClientLiveTest")
|
||||
public class ${providerName}ClientLiveTest {
|
||||
|
||||
private ${clientName}Client connection;
|
||||
private ${providerName}Client connection;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||
|
||||
connection = ${clientName}ContextFactory.createContext(user, password, new Log4JLoggingModule())
|
||||
connection = ${providerName}ContextFactory.createContext(user, password, new Log4JLoggingModule())
|
||||
.getApi();
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,6 @@ public class ${clientName}ClientLiveTest {
|
|||
}
|
||||
|
||||
/*
|
||||
* TODO: add tests for ${clientName} interface methods
|
||||
* TODO: add tests for ${providerName} interface methods
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue