mirror of https://github.com/apache/jclouds.git
commit
93633a630d
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.gogrid.compute;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.internal.BaseComputeService;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.gogrid.compute.options.GoGridTemplateOptions;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* @author Andrew Kennedy
|
||||
*/
|
||||
@Singleton
|
||||
public class GoGridComputeService extends BaseComputeService {
|
||||
@Inject
|
||||
protected GoGridComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||
@Memoized Supplier<Set<? extends Image>> images,
|
||||
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||
GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
|
||||
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||
Provider<TemplateOptions> templateOptionsProvider,
|
||||
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
|
||||
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
|
||||
@Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended,
|
||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, Timeouts timeouts,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getNodeMetadataStrategy,
|
||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy, suspendNodeStrategy,
|
||||
templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, nodeSuspended,
|
||||
initScriptRunnerFactory, timeouts, executor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns template options, except of type {@link GoGridTemplateOptions}.
|
||||
*/
|
||||
@Override
|
||||
public GoGridTemplateOptions templateOptions() {
|
||||
return GoGridTemplateOptions.class.cast(super.templateOptions());
|
||||
}
|
||||
}
|
|
@ -18,21 +18,24 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.compute.config;
|
||||
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.gogrid.GoGridAsyncClient;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.compute.GoGridComputeService;
|
||||
import org.jclouds.gogrid.compute.functions.ServerToNodeMetadata;
|
||||
import org.jclouds.gogrid.compute.options.GoGridTemplateOptions;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.ServerState;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
@ -49,11 +52,12 @@ import com.google.inject.TypeLiteral;
|
|||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
* @author Adrian Cole
|
||||
* @author Andrew Kennedy
|
||||
*/
|
||||
public class GoGridComputeServiceDependenciesModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(TemplateOptions.class).to(GoGridTemplateOptions.class);
|
||||
bind(ComputeService.class).to(GoGridComputeService.class);
|
||||
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
||||
}).to(ServerToNodeMetadata.class);
|
||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||
|
|
|
@ -18,27 +18,28 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.compute.options;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.gogrid.domain.IpType;
|
||||
import org.jclouds.io.Payload;
|
||||
|
||||
/**
|
||||
* Contains options supported in the {@code ComputeService#runNode} operation on the "gogrid"
|
||||
* provider.
|
||||
* Contains options supported by the {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)}
|
||||
* and {@link ComputeService#runNodesWithTag(String, int, TemplateOptions)} operations on
|
||||
* the <em>gogrid</em> provider.
|
||||
*
|
||||
* <h2>Usage</h2>
|
||||
* The recommended way to instantiate a {@link GoGridTemplateOptions} object is to statically
|
||||
* import {@code GoGridTemplateOptions.*} and invoke a static creation method followed by an
|
||||
* instance mutator (if needed):
|
||||
* <p>
|
||||
* <code>
|
||||
* <pre>
|
||||
* import static org.jclouds.compute.options.GoGridTemplateOptions.Builder.*;
|
||||
* ComputeService client = // get connection
|
||||
* templateBuilder.options(inboundPorts(22, 80, 8080, 443));
|
||||
* Set<? extends NodeMetadata> set = client.runNodesWithTag(tag, 2, templateBuilder.build());
|
||||
* <code>
|
||||
* Set<? extends NodeMetadata> set = client.runNodesWithTag(tag, 2, templateBuilder.build());
|
||||
* </pre>
|
||||
*
|
||||
* TODO add GoGrid specific options
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Andrew Kennedy
|
||||
|
@ -55,36 +56,18 @@ public class GoGridTemplateOptions extends TemplateOptions implements Cloneable
|
|||
public void copyTo(TemplateOptions to) {
|
||||
super.copyTo(to);
|
||||
if (to instanceof GoGridTemplateOptions) {
|
||||
@SuppressWarnings("unused")
|
||||
GoGridTemplateOptions eTo = GoGridTemplateOptions.class.cast(to);
|
||||
if (getIpType() != null)
|
||||
eTo.ipType(getIpType());
|
||||
}
|
||||
}
|
||||
|
||||
private IpType ipType = null;
|
||||
|
||||
public static final GoGridTemplateOptions NONE = new GoGridTemplateOptions();
|
||||
|
||||
/**
|
||||
* Specifies the ipType used for network interfaces on the VMs
|
||||
*/
|
||||
public GoGridTemplateOptions ipType(IpType ipType) {
|
||||
this.ipType = ipType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
/**
|
||||
* @see GoGridTemplateOptions#ipAddressAllocationMode
|
||||
*/
|
||||
public static GoGridTemplateOptions ipType(IpType ipType) {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
return GoGridTemplateOptions.class.cast(options.ipType(ipType));
|
||||
}
|
||||
|
||||
// methods that only facilitate returning the correct object type
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#inboundPorts
|
||||
* @see TemplateOptions#inboundPorts(int...)
|
||||
*/
|
||||
public static GoGridTemplateOptions inboundPorts(int... ports) {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
|
@ -92,7 +75,7 @@ public class GoGridTemplateOptions extends TemplateOptions implements Cloneable
|
|||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#port
|
||||
* @see TemplateOptions#blockOnPort(int, int)
|
||||
*/
|
||||
public static GoGridTemplateOptions blockOnPort(int port, int seconds) {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
|
@ -100,7 +83,7 @@ public class GoGridTemplateOptions extends TemplateOptions implements Cloneable
|
|||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#runScript
|
||||
* @see TemplateOptions#runScript(Payload)
|
||||
*/
|
||||
public static GoGridTemplateOptions runScript(Payload script) {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
|
@ -108,41 +91,36 @@ public class GoGridTemplateOptions extends TemplateOptions implements Cloneable
|
|||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#installPrivateKey
|
||||
* @see TemplateOptions#installPrivateKey(Payload)
|
||||
*/
|
||||
@Deprecated
|
||||
public static GoGridTemplateOptions installPrivateKey(Payload rsaKey) {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
return GoGridTemplateOptions.class.cast(options.installPrivateKey(rsaKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#authorizePublicKey
|
||||
* @see TemplateOptions#authorizePublicKey(Payload)
|
||||
*/
|
||||
@Deprecated
|
||||
public static GoGridTemplateOptions authorizePublicKey(Payload rsaKey) {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
return GoGridTemplateOptions.class.cast(options.authorizePublicKey(rsaKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#withDetails
|
||||
* @see TemplateOptions#withMetadata()
|
||||
*/
|
||||
public static GoGridTemplateOptions withDetails() {
|
||||
public static GoGridTemplateOptions withMetadata() {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
return GoGridTemplateOptions.class.cast(options.withMetadata());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ipType on the vms
|
||||
*/
|
||||
public IpType getIpType() {
|
||||
return ipType;
|
||||
}
|
||||
|
||||
// methods that only facilitate returning the correct object type
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#blockOnPort
|
||||
* @see TemplateOptions#blockOnPort(int, int)
|
||||
*/
|
||||
@Override
|
||||
public GoGridTemplateOptions blockOnPort(int port, int seconds) {
|
||||
|
@ -150,12 +128,7 @@ public class GoGridTemplateOptions extends TemplateOptions implements Cloneable
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* special thing is that we do assume if you are passing groups that you have everything you need
|
||||
* already defined. for example, our option inboundPorts normally creates ingress rules
|
||||
* accordingly but if we notice you've specified securityGroups, we do not mess with rules at all
|
||||
*
|
||||
* @see TemplateOptions#inboundPorts
|
||||
* @see TemplateOptions#inboundPorts(int...)
|
||||
*/
|
||||
@Override
|
||||
public GoGridTemplateOptions inboundPorts(int... ports) {
|
||||
|
@ -214,40 +187,10 @@ public class GoGridTemplateOptions extends TemplateOptions implements Cloneable
|
|||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#withMetadata
|
||||
* @see TemplateOptions#withMetadata()
|
||||
*/
|
||||
@Override
|
||||
public GoGridTemplateOptions withMetadata() {
|
||||
return GoGridTemplateOptions.class.cast(super.withMetadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((ipType == null) ? 0 : ipType.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
GoGridTemplateOptions other = (GoGridTemplateOptions) obj;
|
||||
if (ipType != other.ipType)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + (ipType != null ? "ipType=" + ipType : "") + ", inboundPorts=" + Arrays.toString(inboundPorts) + ", privateKey="
|
||||
+ (privateKey != null) + ", publicKey=" + (publicKey != null) + ", runScript=" + (script != null)
|
||||
+ ", port:seconds=" + port + ":" + seconds + ", metadata/details: " + includeMetadata + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.compute.domain.Template;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.compute.options.GoGridTemplateOptions;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.IpType;
|
||||
import org.jclouds.gogrid.domain.PowerCommand;
|
||||
|
@ -78,11 +77,8 @@ public class FindIpThenCreateNodeInGroup implements CreateNodeWithGroupEncodedIn
|
|||
int numOfRetries = 20;
|
||||
GetIpListOptions unassignedIps = new GetIpListOptions()
|
||||
.onlyUnassigned()
|
||||
.inDatacenter(template.getLocation().getId());
|
||||
if (template.getOptions() instanceof GoGridTemplateOptions) {
|
||||
IpType ipType = GoGridTemplateOptions.class.cast(template.getOptions()).getIpType();
|
||||
unassignedIps = unassignedIps.onlyWithType(ipType);
|
||||
}
|
||||
.inDatacenter(template.getLocation().getId())
|
||||
.onlyWithType(IpType.PUBLIC);
|
||||
// lock-free consumption of a shared resource: IP address pool
|
||||
while (notStarted) { // TODO: replace with Predicate-based thread
|
||||
// collision avoidance for simplicity
|
||||
|
|
|
@ -18,41 +18,20 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.compute.options;
|
||||
|
||||
import static org.jclouds.gogrid.compute.options.GoGridTemplateOptions.Builder.*;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.gogrid.domain.IpType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests possible uses of {@code GoGridTemplateOptions} and {@code GoGridTemplateOptions.Builder.*}
|
||||
* with {@link IpType} option.
|
||||
* Tests possible uses of {@code GoGridTemplateOptions} and {@code GoGridTemplateOptions.Builder.*}.
|
||||
*
|
||||
* @author Andrew Kennedy
|
||||
*/
|
||||
public class GoGridTemplateOptionsTest {
|
||||
@Test
|
||||
public void testipTypePrivate() {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
options.ipType(IpType.PRIVATE);
|
||||
assertEquals(options.getIpType(), IpType.PRIVATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testipTypePublic() {
|
||||
GoGridTemplateOptions options = ipType(IpType.PUBLIC);
|
||||
assertEquals(options.getIpType(), IpType.PUBLIC);
|
||||
}
|
||||
|
||||
public void testAs() {
|
||||
TemplateOptions options = new GoGridTemplateOptions();
|
||||
assertEquals(options.as(GoGridTemplateOptions.class), options);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullIpType() {
|
||||
GoGridTemplateOptions options = new GoGridTemplateOptions();
|
||||
assertEquals(options.getIpType(), null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue