mirror of https://github.com/apache/jclouds.git
modernized gogrid
This commit is contained in:
parent
e9360fc938
commit
aef44b26b9
|
@ -1,73 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.config;
|
||||
|
||||
import org.jclouds.compute.config.BindComputeStrategiesByClass;
|
||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
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.gogrid.compute.strategy.FindIpThenCreateNodeInGroup;
|
||||
import org.jclouds.gogrid.compute.strategy.GoGridDestroyNodeStrategy;
|
||||
import org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy;
|
||||
import org.jclouds.gogrid.compute.strategy.GoGridLifeCycleStrategy;
|
||||
import org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class GoGridBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
|
||||
@Override
|
||||
protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
|
||||
return FindIpThenCreateNodeInGroup.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||
return GoGridDestroyNodeStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||
return GoGridGetNodeMetadataStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||
return GoGridListNodesStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||
return GoGridLifeCycleStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends ResumeNodeStrategy> defineStartNodeStrategy() {
|
||||
return GoGridLifeCycleStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends SuspendNodeStrategy> defineStopNodeStrategy() {
|
||||
return GoGridLifeCycleStrategy.class;
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.config;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.config.BindComputeSuppliersByClass;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.gogrid.compute.suppliers.GoGridDefaultLocationSupplier;
|
||||
import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier;
|
||||
import org.jclouds.gogrid.compute.suppliers.GoGridImageSupplier;
|
||||
import org.jclouds.gogrid.compute.suppliers.GoGridLocationSupplier;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class GoGridBindComputeSuppliersByClass extends BindComputeSuppliersByClass {
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||
return GoGridHardwareSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||
return GoGridImageSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
|
||||
return GoGridDefaultLocationSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||
return GoGridLocationSupplier.class;
|
||||
}
|
||||
}
|
|
@ -19,28 +19,130 @@
|
|||
package org.jclouds.gogrid.compute.config;
|
||||
|
||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
|
||||
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.gogrid.GoGridAsyncClient;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.compute.functions.OptionToLocation;
|
||||
import org.jclouds.gogrid.compute.functions.ServerImageToImage;
|
||||
import org.jclouds.gogrid.compute.functions.ServerToNodeMetadata;
|
||||
import org.jclouds.gogrid.compute.options.GoGridTemplateOptions;
|
||||
import org.jclouds.gogrid.compute.strategy.GoGridComputeServiceAdapter;
|
||||
import org.jclouds.gogrid.compute.suppliers.GoGridDefaultLocationSupplier;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.gogrid.domain.ServerState;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
* @author Adrian Cole
|
||||
* @author Andrew Kennedy
|
||||
*/
|
||||
public class GoGridComputeServiceContextModule extends BaseComputeServiceContextModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new GoGridComputeServiceDependenciesModule());
|
||||
install(new GoGridBindComputeStrategiesByClass());
|
||||
install(new GoGridBindComputeSuppliersByClass());
|
||||
super.configure();
|
||||
public class GoGridComputeServiceContextModule extends
|
||||
ComputeServiceAdapterContextModule<GoGridClient, GoGridAsyncClient, Server, Hardware, ServerImage, Option> {
|
||||
public GoGridComputeServiceContextModule() {
|
||||
super(GoGridClient.class, GoGridAsyncClient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||
return template.osFamily(UBUNTU).osVersionMatches("1[10].[10][04]").imageNameMatches(".*w/ None.*");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(new TypeLiteral<ComputeServiceAdapter<Server, Hardware, ServerImage, Option>>() {
|
||||
}).to(GoGridComputeServiceAdapter.class);
|
||||
|
||||
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
||||
}).to(ServerToNodeMetadata.class);
|
||||
|
||||
bind(new TypeLiteral<Function<ServerImage, Image>>() {
|
||||
}).to(ServerImageToImage.class);
|
||||
|
||||
bind(new TypeLiteral<Function<Option, Location>>() {
|
||||
}).to(OptionToLocation.class);
|
||||
|
||||
// we aren't converting hardware from a provider-specific type
|
||||
bind(new TypeLiteral<Function<Hardware, Hardware>>() {
|
||||
}).to((Class) IdentityFunction.class);
|
||||
|
||||
// there are no locations except the provider
|
||||
bind(new TypeLiteral<Supplier<Location>>() {
|
||||
}).to(GoGridDefaultLocationSupplier.class);
|
||||
|
||||
bind(TemplateOptions.class).to(GoGridTemplateOptions.class);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static final Map<ServerState, NodeState> serverStateToNodeState = ImmutableMap.<ServerState, NodeState> builder()
|
||||
.put(ServerState.ON, NodeState.RUNNING)//
|
||||
.put(ServerState.STARTING, NodeState.PENDING)//
|
||||
.put(ServerState.OFF, NodeState.SUSPENDED)//
|
||||
.put(ServerState.STOPPING, NodeState.PENDING)//
|
||||
.put(ServerState.RESTARTING, NodeState.PENDING)//
|
||||
.put(ServerState.SAVING, NodeState.PENDING)//
|
||||
.put(ServerState.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
||||
.put(ServerState.RESTORING, NodeState.PENDING)//
|
||||
.put(ServerState.UPDATING, NodeState.PENDING).build();
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<ServerState, NodeState> provideServerToNodeState() {
|
||||
return serverStateToNodeState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds matches to required configurations. GoGrid's documentation only specifies how much RAM
|
||||
* one can get with different instance types. The # of cores and disk sizes are purely empyrical
|
||||
* and aren't guaranteed. However, these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28
|
||||
* GB Ram: 1GB, CPU: 1 core, HDD: 57 GB Ram: 2GB, CPU: 1 core, HDD: 113 GB Ram: 4GB, CPU: 3
|
||||
* cores, HDD: 233 GB Ram: 8GB, CPU: 6 cores, HDD: 462 GB (as of March 2010)
|
||||
*
|
||||
* @return matched size
|
||||
*/
|
||||
@Singleton
|
||||
@Provides
|
||||
Function<Hardware, String> provideSizeToRam() {
|
||||
return new Function<Hardware, String>() {
|
||||
@Override
|
||||
public String apply(Hardware hardware) {
|
||||
if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || getSpace(hardware) >= 450)
|
||||
return "8GB";
|
||||
if (hardware.getRam() >= 4 * 1024 || getCores(hardware) >= 3 || getSpace(hardware) >= 230)
|
||||
return "4GB";
|
||||
if (hardware.getRam() >= 2 * 1024 || getSpace(hardware) >= 110)
|
||||
return "2GB";
|
||||
if (hardware.getRam() >= 1024 || getSpace(hardware) >= 55)
|
||||
return "1GB";
|
||||
return "512MB"; /* smallest */
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.config;
|
||||
|
||||
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;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
* @author Adrian Cole
|
||||
* @author Andrew Kennedy
|
||||
*/
|
||||
public class GoGridComputeServiceDependenciesModule extends AbstractModule {
|
||||
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>() {
|
||||
}).to(new TypeLiteral<ComputeServiceContextImpl<GoGridClient, GoGridAsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(new TypeLiteral<RestContext<GoGridClient, GoGridAsyncClient>>() {
|
||||
}).to(new TypeLiteral<RestContextImpl<GoGridClient, GoGridAsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static final Map<ServerState, NodeState> serverStateToNodeState = ImmutableMap.<ServerState, NodeState> builder()
|
||||
.put(ServerState.ON, NodeState.RUNNING)//
|
||||
.put(ServerState.STARTING, NodeState.PENDING)//
|
||||
.put(ServerState.OFF, NodeState.SUSPENDED)//
|
||||
.put(ServerState.STOPPING, NodeState.PENDING)//
|
||||
.put(ServerState.RESTARTING, NodeState.PENDING)//
|
||||
.put(ServerState.SAVING, NodeState.PENDING)//
|
||||
.put(ServerState.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
||||
.put(ServerState.RESTORING, NodeState.PENDING)//
|
||||
.put(ServerState.UPDATING, NodeState.PENDING).build();
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<ServerState, NodeState> provideServerToNodeState() {
|
||||
return serverStateToNodeState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds matches to required configurations. GoGrid's documentation only specifies how much RAM
|
||||
* one can get with different instance types. The # of cores and disk sizes are purely empyrical
|
||||
* and aren't guaranteed. However, these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28
|
||||
* GB Ram: 1GB, CPU: 1 core, HDD: 57 GB Ram: 2GB, CPU: 1 core, HDD: 113 GB Ram: 4GB, CPU: 3
|
||||
* cores, HDD: 233 GB Ram: 8GB, CPU: 6 cores, HDD: 462 GB (as of March 2010)
|
||||
*
|
||||
* @return matched size
|
||||
*/
|
||||
@Singleton
|
||||
@Provides
|
||||
Function<Hardware, String> provideSizeToRam() {
|
||||
return new Function<Hardware, String>() {
|
||||
@Override
|
||||
public String apply(Hardware hardware) {
|
||||
if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || getSpace(hardware) >= 450)
|
||||
return "8GB";
|
||||
if (hardware.getRam() >= 4 * 1024 || getCores(hardware) >= 3 || getSpace(hardware) >= 230)
|
||||
return "4GB";
|
||||
if (hardware.getRam() >= 2 * 1024 || getSpace(hardware) >= 110)
|
||||
return "2GB";
|
||||
if (hardware.getRam() >= 1024 || getSpace(hardware) >= 55)
|
||||
return "1GB";
|
||||
return "512MB"; /* smallest */
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.suppliers;
|
||||
package org.jclouds.gogrid.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
@ -30,49 +30,38 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.location.Iso3166;
|
||||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.location.suppliers.JustProvider;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class GoGridLocationSupplier extends JustProvider {
|
||||
public class OptionToLocation extends JustProvider implements Function<Option, Location> {
|
||||
|
||||
private final GoGridClient sync;
|
||||
private final Map<String, Set<String>> isoCodesById;
|
||||
private final Location provider;
|
||||
|
||||
@Inject
|
||||
GoGridLocationSupplier(@Iso3166 Set<String> isoCodes, @Provider String providerName, @Provider URI endpoint,
|
||||
GoGridClient sync, @Iso3166 Map<String, Set<String>> isoCodesById) {
|
||||
OptionToLocation(@Iso3166 Set<String> isoCodes, @Provider String providerName, @Provider URI endpoint,
|
||||
@Iso3166 Map<String, Set<String>> isoCodesById) {
|
||||
super(providerName, endpoint, isoCodes);
|
||||
this.sync = checkNotNull(sync, "sync");
|
||||
this.provider = Iterables.getOnlyElement(super.get());
|
||||
this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Location> get() {
|
||||
Builder<Location> locations = ImmutableSet.builder();
|
||||
Set<Option> list = sync.getServerServices().getDatacenters();
|
||||
Location provider = Iterables.getOnlyElement(super.get());
|
||||
if (list.size() == 0)
|
||||
locations.add(provider);
|
||||
else
|
||||
for (Option from : list) {
|
||||
LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(from.getId() + "")
|
||||
.description(from.getDescription()).parent(provider);
|
||||
if (isoCodesById.containsKey(from.getId() + ""))
|
||||
builder.iso3166Codes(isoCodesById.get(from.getId() + ""));
|
||||
locations.add(builder.build());
|
||||
}
|
||||
return locations.build();
|
||||
public Location apply(Option from) {
|
||||
LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(from.getId() + "").description(
|
||||
from.getDescription()).parent(provider);
|
||||
if (isoCodesById.containsKey(from.getId() + ""))
|
||||
builder.iso3166Codes(isoCodesById.get(from.getId() + ""));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -16,10 +16,9 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.suppliers;
|
||||
package org.jclouds.gogrid.compute.functions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -35,19 +34,17 @@ import org.jclouds.compute.domain.OsFamily;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||
import org.jclouds.compute.util.ComputeServiceUtils;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class GoGridImageSupplier implements Supplier<Set<? extends Image>> {
|
||||
public class ServerImageToImage implements Function<ServerImage, Image> {
|
||||
public static final Pattern GOGRID_OS_PATTERN = Pattern.compile("([a-zA-Z]*).*");
|
||||
public static final Pattern GOGRID_VERSION_PATTERN = Pattern.compile(".* ([0-9.]+) .*");
|
||||
|
||||
|
@ -55,34 +52,12 @@ public class GoGridImageSupplier implements Supplier<Set<? extends Image>> {
|
|||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final GoGridClient sync;
|
||||
private final PopulateDefaultLoginCredentialsForImageStrategy authenticator;
|
||||
private final Map<OsFamily, Map<String, String>> osVersionMap;
|
||||
|
||||
@Inject
|
||||
GoGridImageSupplier(GoGridClient sync, PopulateDefaultLoginCredentialsForImageStrategy authenticator,
|
||||
Map<OsFamily, Map<String, String>> osVersionMap) {
|
||||
ServerImageToImage(PopulateDefaultLoginCredentialsForImageStrategy authenticator,
|
||||
Map<OsFamily, Map<String, String>> osVersionMap) {
|
||||
this.osVersionMap = osVersionMap;
|
||||
this.sync = sync;
|
||||
this.authenticator = authenticator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Image> get() {
|
||||
final Set<Image> images = Sets.newHashSet();
|
||||
logger.debug(">> providing images");
|
||||
Set<ServerImage> allImages = sync.getImageServices().getImageList();
|
||||
for (ServerImage from : allImages) {
|
||||
ImageBuilder builder = new ImageBuilder();
|
||||
builder.ids(from.getId() + "");
|
||||
builder.name(from.getFriendlyName());
|
||||
builder.description(from.getDescription());
|
||||
builder.defaultCredentials(authenticator.apply(from));
|
||||
builder.operatingSystem(parseOs(from));
|
||||
images.add(builder.build());
|
||||
}
|
||||
logger.debug("<< images(%d)", images.size());
|
||||
return images;
|
||||
}
|
||||
|
||||
protected OperatingSystem parseOs(ServerImage from) {
|
||||
|
@ -113,4 +88,14 @@ public class GoGridImageSupplier implements Supplier<Set<? extends Image>> {
|
|||
return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image apply(ServerImage from) {
|
||||
ImageBuilder builder = new ImageBuilder();
|
||||
builder.ids(from.getId() + "");
|
||||
builder.name(from.getFriendlyName());
|
||||
builder.description(from.getDescription());
|
||||
builder.operatingSystem(parseOs(from));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -18,27 +18,30 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.IpType;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.domain.PowerCommand;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.gogrid.options.GetIpListOptions;
|
||||
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
@ -49,46 +52,39 @@ import com.google.common.base.Throwables;
|
|||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
* defines the connection between the {@link GoGridClient} implementation and the jclouds
|
||||
* {@link ComputeService}
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class FindIpThenCreateNodeInGroup implements CreateNodeWithGroupEncodedIntoName {
|
||||
public class GoGridComputeServiceAdapter implements ComputeServiceAdapter<Server, Hardware, ServerImage, Option> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final GoGridClient client;
|
||||
private final Function<Hardware, String> sizeToRam;
|
||||
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
||||
private final RetryablePredicate<Server> serverLatestJobCompleted;
|
||||
private final RetryablePredicate<Server> serverLatestJobCompletedShort;
|
||||
private final Map<String, Credentials> credentialStore;
|
||||
|
||||
|
||||
@Inject
|
||||
protected FindIpThenCreateNodeInGroup(GoGridClient client, Map<String, Credentials> credentialStore,
|
||||
Function<Server, NodeMetadata> serverToNodeMetadata, Function<Hardware, String> sizeToRam,
|
||||
Timeouts timeouts) {
|
||||
protected GoGridComputeServiceAdapter(GoGridClient client, Function<Hardware, String> sizeToRam, Timeouts timeouts) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||
this.serverToNodeMetadata = checkNotNull(serverToNodeMetadata, "serverToNodeMetadata");
|
||||
this.sizeToRam = checkNotNull(sizeToRam, "sizeToRam");
|
||||
this.serverLatestJobCompleted = new RetryablePredicate<Server>(
|
||||
new ServerLatestJobCompleted(client.getJobServices()),
|
||||
timeouts.nodeRunning * 9l / 10l);
|
||||
this.serverLatestJobCompletedShort = new RetryablePredicate<Server>(
|
||||
new ServerLatestJobCompleted(client.getJobServices()),
|
||||
timeouts.nodeRunning * 1l / 10l);
|
||||
this.serverLatestJobCompleted = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
|
||||
.getJobServices()), timeouts.nodeRunning * 9l / 10l);
|
||||
this.serverLatestJobCompletedShort = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
|
||||
.getJobServices()), timeouts.nodeRunning * 1l / 10l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
|
||||
public NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String group, String name,
|
||||
Template template) {
|
||||
Server addedServer = null;
|
||||
boolean notStarted = true;
|
||||
int numOfRetries = 20;
|
||||
GetIpListOptions unassignedIps = new GetIpListOptions()
|
||||
.onlyUnassigned()
|
||||
.inDatacenter(template.getLocation().getId())
|
||||
.onlyWithType(IpType.PUBLIC);
|
||||
GetIpListOptions unassignedIps = new GetIpListOptions().onlyUnassigned().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
|
||||
|
@ -110,21 +106,77 @@ public class FindIpThenCreateNodeInGroup implements CreateNodeWithGroupEncodedIn
|
|||
serverLatestJobCompleted.apply(addedServer);
|
||||
client.getServerServices().power(addedServer.getName(), PowerCommand.START);
|
||||
serverLatestJobCompletedShort.apply(addedServer);
|
||||
addedServer = Iterables.getOnlyElement(client.getServerServices().getServersByName(
|
||||
addedServer.getName()));
|
||||
addedServer = Iterables.getOnlyElement(client.getServerServices().getServersByName(addedServer.getName()));
|
||||
}
|
||||
Credentials credentials = client.getServerServices().getServerCredentialsList().get(addedServer.getName());
|
||||
if (credentials != null)
|
||||
credentialStore.put("node#" + addedServer.getId(), credentials);
|
||||
else
|
||||
logger.warn("couldn't get credentials for server %s", addedServer.getName());
|
||||
return serverToNodeMetadata.apply(addedServer);
|
||||
LoginCredentials credentials = LoginCredentials.fromCredentials(client.getServerServices()
|
||||
.getServerCredentialsList().get(addedServer.getName()));
|
||||
return new NodeAndInitialCredentials<Server>(addedServer, addedServer.getName() + "", credentials);
|
||||
}
|
||||
|
||||
private Server addServer(String name, Template template, Ip availableIp) {
|
||||
Server addedServer = client.getServerServices().addServer(name,
|
||||
checkNotNull(template.getImage().getProviderId()),
|
||||
sizeToRam.apply(template.getHardware()), availableIp.getIp());
|
||||
checkNotNull(template.getImage().getProviderId()), sizeToRam.apply(template.getHardware()),
|
||||
availableIp.getIp());
|
||||
return addedServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Hardware> listHardwareProfiles() {
|
||||
return GoGridHardwareSupplier.H_ALL;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ServerImage> listImages() {
|
||||
return client.getImageServices().getImageList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Server> listNodes() {
|
||||
return client.getServerServices().getServerList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Option> listLocations() {
|
||||
return client.getServerServices().getDatacenters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getNode(String id) {
|
||||
try {
|
||||
return Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(checkNotNull(id, "id"))));
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyNode(String id) {
|
||||
client.getServerServices().deleteById(new Long(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebootNode(String id) {
|
||||
executeCommandOnServer(PowerCommand.RESTART, id);
|
||||
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id)));
|
||||
client.getServerServices().power(server.getName(), PowerCommand.START);
|
||||
serverLatestJobCompletedShort.apply(server);
|
||||
}
|
||||
|
||||
private boolean executeCommandOnServer(PowerCommand command, String id) {
|
||||
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id)));
|
||||
client.getServerServices().power(server.getName(), command);
|
||||
return serverLatestJobCompleted.apply(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeNode(String id) {
|
||||
executeCommandOnServer(PowerCommand.START, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suspendNode(String id) {
|
||||
executeCommandOnServer(PowerCommand.STOP, id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.strategy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class GoGridDestroyNodeStrategy implements DestroyNodeStrategy {
|
||||
private final GoGridClient client;
|
||||
private final GetNodeMetadataStrategy getNode;
|
||||
|
||||
@Inject
|
||||
protected GoGridDestroyNodeStrategy(GoGridClient client, GetNodeMetadataStrategy getNode) {
|
||||
this.client = client;
|
||||
this.getNode = getNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata destroyNode(String id) {
|
||||
client.getServerServices().deleteById(new Long(id));
|
||||
return getNode.getNode(id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class GoGridGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
|
||||
private final GoGridClient client;
|
||||
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected GoGridGetNodeMetadataStrategy(GoGridClient client, Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||
this.client = client;
|
||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata getNode(String id) {
|
||||
try {
|
||||
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(
|
||||
new Long(checkNotNull(id, "id"))));
|
||||
return server == null ? null : serverToNodeMetadata.apply(server);
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.strategy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.domain.PowerCommand;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class GoGridLifeCycleStrategy implements RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy {
|
||||
private final GoGridClient client;
|
||||
private final RetryablePredicate<Server> serverLatestJobCompleted;
|
||||
private final RetryablePredicate<Server> serverLatestJobCompletedShort;
|
||||
private final GetNodeMetadataStrategy getNode;
|
||||
|
||||
@Inject
|
||||
protected GoGridLifeCycleStrategy(GoGridClient client, GetNodeMetadataStrategy getNode, Timeouts timeouts) {
|
||||
this.client = client;
|
||||
this.serverLatestJobCompleted = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
|
||||
.getJobServices()), timeouts.nodeRunning * 9l / 10l);
|
||||
this.serverLatestJobCompletedShort = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
|
||||
.getJobServices()), timeouts.nodeRunning * 1l / 10l);
|
||||
this.getNode = getNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata rebootNode(String id) {
|
||||
executeCommandOnServer(PowerCommand.RESTART, id);
|
||||
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id)));
|
||||
client.getServerServices().power(server.getName(), PowerCommand.START);
|
||||
serverLatestJobCompletedShort.apply(server);
|
||||
return getNode.getNode(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata resumeNode(String id) {
|
||||
executeCommandOnServer(PowerCommand.START, id);
|
||||
return getNode.getNode(id);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata suspendNode(String id) {
|
||||
executeCommandOnServer(PowerCommand.STOP, id);
|
||||
return getNode.getNode(id);
|
||||
|
||||
}
|
||||
|
||||
private boolean executeCommandOnServer(PowerCommand command, String id) {
|
||||
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id)));
|
||||
client.getServerServices().power(server.getName(), command);
|
||||
return serverLatestJobCompleted.apply(server);
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.strategy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.predicates.NodePredicates;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class GoGridListNodesStrategy implements ListNodesStrategy {
|
||||
private final GoGridClient client;
|
||||
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected GoGridListNodesStrategy(GoGridClient client, Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||
this.client = client;
|
||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends ComputeMetadata> listNodes() {
|
||||
return listDetailsOnNodesMatching(NodePredicates.all());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
return Iterables.filter(Iterables.transform(client.getServerServices().getServerList(), serverToNodeMetadata),
|
||||
filter);
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ public class GoGridComputeServiceContextModuleTest {
|
|||
public void testAllStatusCovered() {
|
||||
|
||||
for (ServerState state : ServerState.values()) {
|
||||
assert GoGridComputeServiceDependenciesModule.serverStateToNodeState.containsKey(state) : state;
|
||||
assert GoGridComputeServiceContextModule.serverStateToNodeState.containsKey(state) : state;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue