mirror of https://github.com/apache/jclouds.git
updated slicehost to compute service adapter
This commit is contained in:
parent
a80e1b07e6
commit
e9360fc938
|
@ -1,76 +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.slicehost.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.slicehost.compute.strategy.SlicehostCreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.slicehost.compute.strategy.SlicehostDestroyNodeStrategy;
|
||||
import org.jclouds.slicehost.compute.strategy.SlicehostGetNodeMetadataStrategy;
|
||||
import org.jclouds.slicehost.compute.strategy.SlicehostListNodesStrategy;
|
||||
import org.jclouds.slicehost.compute.strategy.SlicehostLifeCycleStrategy;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class SlicehostBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
|
||||
|
||||
@Override
|
||||
protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
|
||||
return SlicehostCreateNodeWithGroupEncodedIntoName.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||
return SlicehostDestroyNodeStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||
return SlicehostGetNodeMetadataStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||
return SlicehostListNodesStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||
return SlicehostLifeCycleStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends ResumeNodeStrategy> defineStartNodeStrategy() {
|
||||
return SlicehostLifeCycleStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends SuspendNodeStrategy> defineStopNodeStrategy() {
|
||||
return SlicehostLifeCycleStrategy.class;
|
||||
}
|
||||
}
|
|
@ -1,54 +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.slicehost.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.location.suppliers.JustProvider;
|
||||
import org.jclouds.slicehost.compute.suppliers.SlicehostHardwareSupplier;
|
||||
import org.jclouds.slicehost.compute.suppliers.SlicehostImageSupplier;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class SlicehostBindComputeSuppliersByClass extends BindComputeSuppliersByClass {
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||
return SlicehostHardwareSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||
return SlicehostImageSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||
return JustProvider.class;
|
||||
}
|
||||
}
|
|
@ -20,29 +20,99 @@ package org.jclouds.slicehost.compute.config;
|
|||
|
||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||
|
||||
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.OperatingSystem;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.internal.BaseComputeService;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
|
||||
import org.jclouds.slicehost.SlicehostAsyncClient;
|
||||
import org.jclouds.slicehost.SlicehostClient;
|
||||
import org.jclouds.slicehost.compute.functions.FlavorToHardware;
|
||||
import org.jclouds.slicehost.compute.functions.SliceToNodeMetadata;
|
||||
import org.jclouds.slicehost.compute.functions.SlicehostImageToImage;
|
||||
import org.jclouds.slicehost.compute.functions.SlicehostImageToOperatingSystem;
|
||||
import org.jclouds.slicehost.compute.strategy.SlicehostComputeServiceAdapter;
|
||||
import org.jclouds.slicehost.domain.Flavor;
|
||||
import org.jclouds.slicehost.domain.Slice;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Configures the {@link SlicehostComputeServiceContext}; requires {@link BaseComputeService} bound.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SlicehostComputeServiceContextModule extends BaseComputeServiceContextModule {
|
||||
@Override
|
||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||
return template.osFamily(UBUNTU).osVersionMatches("1[10].[10][04]").osDescriptionMatches("^((?!MGC).)*$").os64Bit(true);
|
||||
public class SlicehostComputeServiceContextModule
|
||||
extends
|
||||
ComputeServiceAdapterContextModule<SlicehostClient, SlicehostAsyncClient, Slice, Flavor, org.jclouds.slicehost.domain.Image, Location> {
|
||||
public SlicehostComputeServiceContextModule() {
|
||||
super(SlicehostClient.class, SlicehostAsyncClient.class);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new SlicehostComputeServiceDependenciesModule());
|
||||
install(new SlicehostBindComputeStrategiesByClass());
|
||||
install(new SlicehostBindComputeSuppliersByClass());
|
||||
super.configure();
|
||||
bind(new TypeLiteral<ComputeServiceAdapter<Slice, Flavor, org.jclouds.slicehost.domain.Image, Location>>() {
|
||||
}).to(SlicehostComputeServiceAdapter.class);
|
||||
|
||||
bind(new TypeLiteral<Function<Slice, NodeMetadata>>() {
|
||||
}).to(SliceToNodeMetadata.class);
|
||||
|
||||
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, Image>>() {
|
||||
}).to(SlicehostImageToImage.class);
|
||||
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, OperatingSystem>>() {
|
||||
}).to(SlicehostImageToOperatingSystem.class);
|
||||
|
||||
bind(new TypeLiteral<Function<Flavor, Hardware>>() {
|
||||
}).to(FlavorToHardware.class);
|
||||
|
||||
// we aren't converting location from a provider-specific type
|
||||
bind(new TypeLiteral<Function<Location, Location>>() {
|
||||
}).to((Class) IdentityFunction.class);
|
||||
|
||||
// there are no locations except the provider
|
||||
bind(new TypeLiteral<Supplier<Location>>() {
|
||||
}).to(OnlyLocationOrFirstZone.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||
return template.osFamily(UBUNTU).osVersionMatches("1[10].[10][04]").osDescriptionMatches("^((?!MGC).)*$")
|
||||
.os64Bit(true);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static final Map<Slice.Status, NodeState> sliceStatusToNodeState = ImmutableMap
|
||||
.<Slice.Status, NodeState> builder().put(Slice.Status.ACTIVE, NodeState.RUNNING)//
|
||||
.put(Slice.Status.BUILD, NodeState.PENDING)//
|
||||
.put(Slice.Status.REBOOT, NodeState.PENDING)//
|
||||
.put(Slice.Status.HARD_REBOOT, NodeState.PENDING)//
|
||||
.put(Slice.Status.TERMINATED, NodeState.TERMINATED)//
|
||||
.put(Slice.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
||||
.build();
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<Slice.Status, NodeState> provideSliceToNodeState() {
|
||||
return sliceStatusToNodeState;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,96 +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.slicehost.compute.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.NodeState;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.internal.BaseComputeService;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.jclouds.slicehost.SlicehostAsyncClient;
|
||||
import org.jclouds.slicehost.SlicehostClient;
|
||||
import org.jclouds.slicehost.compute.functions.FlavorToHardware;
|
||||
import org.jclouds.slicehost.compute.functions.SliceToNodeMetadata;
|
||||
import org.jclouds.slicehost.compute.functions.SlicehostImageToImage;
|
||||
import org.jclouds.slicehost.compute.functions.SlicehostImageToOperatingSystem;
|
||||
import org.jclouds.slicehost.domain.Flavor;
|
||||
import org.jclouds.slicehost.domain.Slice;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Configures the {@link SlicehostComputeServiceContext}; requires {@link BaseComputeService} bound.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SlicehostComputeServiceDependenciesModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<Slice, NodeMetadata>>() {
|
||||
}).to(SliceToNodeMetadata.class);
|
||||
|
||||
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, Image>>() {
|
||||
}).to(SlicehostImageToImage.class);
|
||||
|
||||
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, OperatingSystem>>() {
|
||||
}).to(SlicehostImageToOperatingSystem.class);
|
||||
bind(new TypeLiteral<Function<Flavor, Hardware>>() {
|
||||
}).to(FlavorToHardware.class);
|
||||
|
||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||
}).to(new TypeLiteral<ComputeServiceContextImpl<SlicehostClient, SlicehostAsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(new TypeLiteral<RestContext<SlicehostClient, SlicehostAsyncClient>>() {
|
||||
}).to(new TypeLiteral<RestContextImpl<SlicehostClient, SlicehostAsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static final Map<Slice.Status, NodeState> sliceStatusToNodeState = ImmutableMap
|
||||
.<Slice.Status, NodeState> builder().put(Slice.Status.ACTIVE, NodeState.RUNNING)//
|
||||
.put(Slice.Status.BUILD, NodeState.PENDING)//
|
||||
.put(Slice.Status.REBOOT, NodeState.PENDING)//
|
||||
.put(Slice.Status.HARD_REBOOT, NodeState.PENDING)//
|
||||
.put(Slice.Status.TERMINATED, NodeState.TERMINATED)//
|
||||
.put(Slice.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
||||
.build();
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<Slice.Status, NodeState> provideSliceToNodeState() {
|
||||
return sliceStatusToNodeState;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package org.jclouds.slicehost.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.location.suppliers.JustProvider;
|
||||
import org.jclouds.slicehost.SlicehostClient;
|
||||
import org.jclouds.slicehost.domain.Flavor;
|
||||
import org.jclouds.slicehost.domain.Image;
|
||||
import org.jclouds.slicehost.domain.Slice;
|
||||
|
||||
/**
|
||||
* defines the connection between the {@link SlicehostClient} implementation and the jclouds
|
||||
* {@link ComputeService}
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class SlicehostComputeServiceAdapter implements ComputeServiceAdapter<Slice, Flavor, Image, Location> {
|
||||
|
||||
protected final SlicehostClient client;
|
||||
protected final JustProvider locationSupplier;
|
||||
|
||||
@Inject
|
||||
protected SlicehostComputeServiceAdapter(SlicehostClient client, JustProvider locationSupplier) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeAndInitialCredentials<Slice> createNodeWithGroupEncodedIntoName(String group, String name,
|
||||
Template template) {
|
||||
Slice server = client
|
||||
.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template
|
||||
.getHardware().getProviderId()));
|
||||
|
||||
return new NodeAndInitialCredentials<Slice>(server, server.getId() + "", LoginCredentials.builder().password(
|
||||
server.getRootPassword()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Flavor> listHardwareProfiles() {
|
||||
return client.listFlavors();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Image> listImages() {
|
||||
return client.listImages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Slice> listNodes() {
|
||||
return client.listSlices();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Iterable<Location> listLocations() {
|
||||
return (Iterable<Location>) locationSupplier.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice getNode(String id) {
|
||||
int serverId = Integer.parseInt(id);
|
||||
return client.getSlice(serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyNode(String id) {
|
||||
int serverId = Integer.parseInt(id);
|
||||
// if false server wasn't around in the first place
|
||||
client.destroySlice(serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebootNode(String id) {
|
||||
int sliceId = Integer.parseInt(id);
|
||||
client.hardRebootSlice(sliceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeNode(String id) {
|
||||
throw new UnsupportedOperationException("suspend not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suspendNode(String id) {
|
||||
throw new UnsupportedOperationException("suspend not supported");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,84 +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.slicehost.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.slicehost.SlicehostClient;
|
||||
import org.jclouds.slicehost.domain.Slice;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SlicehostCreateNodeWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName {
|
||||
|
||||
protected final SlicehostClient client;
|
||||
protected final Map<String, Credentials> credentialStore;
|
||||
protected final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
|
||||
protected final Function<Slice, NodeMetadata> sliceToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected SlicehostCreateNodeWithGroupEncodedIntoName(SlicehostClient client,
|
||||
Map<String, Credentials> credentialStore,
|
||||
PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate,
|
||||
Function<Slice, NodeMetadata> sliceToNodeMetadata) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||
this.sliceToNodeMetadata = checkNotNull(sliceToNodeMetadata, "sliceToNodeMetadata");
|
||||
this.prioritizeCredentialsFromTemplate = checkNotNull(prioritizeCredentialsFromTemplate,
|
||||
"prioritizeCredentialsFromTemplate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
|
||||
checkState(group != null, "group (that which groups identical nodes together) must be specified");
|
||||
checkState(name != null && name.indexOf(group) != -1, "name should have %s encoded into it", group);
|
||||
checkState(template != null, "template must be specified");
|
||||
|
||||
Slice slice = client.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Integer
|
||||
.parseInt(template.getHardware().getProviderId()));
|
||||
|
||||
NodeAndInitialCredentials<Slice> from = new NodeAndInitialCredentials<Slice>(slice, slice.getId() + "",
|
||||
LoginCredentials.builder().password(slice.getRootPassword()).build());
|
||||
|
||||
LoginCredentials fromNode = from.getCredentials();
|
||||
LoginCredentials creds = prioritizeCredentialsFromTemplate.apply(template, fromNode);
|
||||
if (creds != null)
|
||||
credentialStore.put("node#" + from.getNodeId(), creds);
|
||||
NodeMetadata node = sliceToNodeMetadata.apply(from.getNode());
|
||||
return node;
|
||||
}
|
||||
}
|
|
@ -1,52 +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.slicehost.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.slicehost.SlicehostClient;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SlicehostDestroyNodeStrategy implements DestroyNodeStrategy {
|
||||
private final SlicehostClient client;
|
||||
private final GetNodeMetadataStrategy getNode;
|
||||
|
||||
@Inject
|
||||
protected SlicehostDestroyNodeStrategy(SlicehostClient client, GetNodeMetadataStrategy getNode) {
|
||||
this.client = client;
|
||||
this.getNode = getNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata destroyNode(String id) {
|
||||
int sliceId = Integer.parseInt(id);
|
||||
// if false slice wasn't around in the first place
|
||||
client.destroySlice(sliceId);
|
||||
return getNode.getNode(id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,80 +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.slicehost.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.slicehost.SlicehostClient;
|
||||
import org.jclouds.slicehost.domain.Slice;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SlicehostGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
|
||||
|
||||
private final SlicehostClient client;
|
||||
private final Map<String, Credentials> credentialStore;
|
||||
private final Function<Slice, NodeMetadata> nodeMetadataAdapter;
|
||||
|
||||
@Inject
|
||||
protected SlicehostGetNodeMetadataStrategy(SlicehostClient client, Map<String, Credentials> credentialStore,
|
||||
Function<Slice, NodeMetadata> nodeMetadataAdapter) {
|
||||
this.client = client;
|
||||
this.credentialStore = credentialStore;
|
||||
this.nodeMetadataAdapter = Functions.compose(addLoginCredentials, checkNotNull(nodeMetadataAdapter,
|
||||
"nodeMetadataAdapter"));
|
||||
}
|
||||
|
||||
private final Function<NodeMetadata, NodeMetadata> addLoginCredentials = new Function<NodeMetadata, NodeMetadata>() {
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(NodeMetadata arg0) {
|
||||
return credentialStore.containsKey("node#" + arg0.getId()) ? NodeMetadataBuilder.fromNodeMetadata(arg0)
|
||||
.credentials(LoginCredentials.fromCredentials(credentialStore.get("node#" + arg0.getId()))).build()
|
||||
: arg0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "addLoginCredentialsFromCredentialStore()";
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public NodeMetadata getNode(String id) {
|
||||
int sliceId = Integer.parseInt(id);
|
||||
Slice slice = client.getSlice(sliceId);
|
||||
return slice == null ? null : nodeMetadataAdapter.apply(slice);
|
||||
}
|
||||
}
|
|
@ -1,63 +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.slicehost.compute.strategy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
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.slicehost.SlicehostClient;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SlicehostLifeCycleStrategy implements RebootNodeStrategy, SuspendNodeStrategy, ResumeNodeStrategy {
|
||||
private final SlicehostClient client;
|
||||
private final GetNodeMetadataStrategy getNode;
|
||||
|
||||
@Inject
|
||||
protected SlicehostLifeCycleStrategy(SlicehostClient client, GetNodeMetadataStrategy getNode) {
|
||||
this.client = client;
|
||||
this.getNode = getNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata rebootNode(String id) {
|
||||
int sliceId = Integer.parseInt(id);
|
||||
client.hardRebootSlice(sliceId);
|
||||
return getNode.getNode(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata suspendNode(String id) {
|
||||
throw new UnsupportedOperationException("suspend not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata resumeNode(String id) {
|
||||
throw new UnsupportedOperationException("resume not supported");
|
||||
}
|
||||
|
||||
}
|
|
@ -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.slicehost.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.slicehost.SlicehostClient;
|
||||
import org.jclouds.slicehost.domain.Slice;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SlicehostListNodesStrategy implements ListNodesStrategy {
|
||||
private final SlicehostClient client;
|
||||
private final Function<Slice, NodeMetadata> sliceToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected SlicehostListNodesStrategy(SlicehostClient client, Function<Slice, NodeMetadata> sliceToNodeMetadata) {
|
||||
this.client = client;
|
||||
this.sliceToNodeMetadata = sliceToNodeMetadata;
|
||||
}
|
||||
|
||||
@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.listSlices(), sliceToNodeMetadata), filter);
|
||||
}
|
||||
}
|
|
@ -1,66 +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.slicehost.compute.suppliers;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.slicehost.SlicehostClient;
|
||||
import org.jclouds.slicehost.domain.Flavor;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SlicehostHardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final SlicehostClient sync;
|
||||
private final Function<Flavor, Hardware> flavorToHardware;
|
||||
|
||||
@Inject
|
||||
SlicehostHardwareSupplier(SlicehostClient sync, Function<Flavor, Hardware> flavorToHardware) {
|
||||
this.sync = sync;
|
||||
this.flavorToHardware = flavorToHardware;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Hardware> get() {
|
||||
final Set<Hardware> hardware;
|
||||
logger.debug(">> providing hardware");
|
||||
hardware = Sets.newLinkedHashSet(Iterables.transform(sync.listFlavors(), flavorToHardware));
|
||||
logger.debug("<< hardware(%d)", hardware.size());
|
||||
return hardware;
|
||||
}
|
||||
}
|
|
@ -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.slicehost.compute.suppliers;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule.AddDefaultCredentialsToImage;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.slicehost.SlicehostClient;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SlicehostImageSupplier implements Supplier<Set<? extends Image>> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected final SlicehostClient sync;
|
||||
protected final Function<org.jclouds.slicehost.domain.Image, Image> cloudServersImageToImage;
|
||||
protected final AddDefaultCredentialsToImage addDefaultCredentialsToImage;
|
||||
|
||||
@Inject
|
||||
SlicehostImageSupplier(SlicehostClient sync,
|
||||
Function<org.jclouds.slicehost.domain.Image, Image> cloudServersImageToImage,
|
||||
AddDefaultCredentialsToImage addDefaultCredentialsToImage) {
|
||||
this.sync = sync;
|
||||
this.cloudServersImageToImage = cloudServersImageToImage;
|
||||
this.addDefaultCredentialsToImage = addDefaultCredentialsToImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Image> get() {
|
||||
Set<Image> images;
|
||||
logger.debug(">> providing images");
|
||||
images = Sets.<Image> newLinkedHashSet(Iterables.transform(sync.listImages(), Functions.compose(
|
||||
addDefaultCredentialsToImage, cloudServersImageToImage)));
|
||||
logger.debug("<< images(%d)", images.size());
|
||||
return images;
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ public class SlicehostComputeServiceContextModuleTest {
|
|||
public void testAllStatusCovered() {
|
||||
|
||||
for (Slice.Status state : Slice.Status.values()) {
|
||||
assert SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState.containsKey(state) : state;
|
||||
assert SlicehostComputeServiceContextModule.sliceStatusToNodeState.containsKey(state) : state;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.slicehost.compute.functions;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -38,7 +37,7 @@ import org.jclouds.compute.domain.VolumeBuilder;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.slicehost.compute.config.SlicehostComputeServiceDependenciesModule;
|
||||
import org.jclouds.slicehost.compute.config.SlicehostComputeServiceContextModule;
|
||||
import org.jclouds.slicehost.domain.Slice;
|
||||
import org.jclouds.slicehost.xml.SliceHandlerTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -56,8 +55,8 @@ public class SliceToNodeMetadataTest {
|
|||
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
|
||||
|
||||
@Test
|
||||
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException {
|
||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState;
|
||||
public void testApplyWhereImageAndHardwareNotFound() {
|
||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceContextModule.sliceStatusToNodeState;
|
||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||
Slice slice = SliceHandlerTest.parseSlice();
|
||||
|
@ -75,8 +74,8 @@ public class SliceToNodeMetadataTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException {
|
||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState;
|
||||
public void testApplyWhereImageFoundAndHardwareNotFound() {
|
||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceContextModule.sliceStatusToNodeState;
|
||||
org.jclouds.compute.domain.Image jcImage = SlicehostImageToImageTest.convertImage();
|
||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
|
||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||
|
@ -97,8 +96,8 @@ public class SliceToNodeMetadataTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException {
|
||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState;
|
||||
public void testApplyWhereImageAndHardwareFound() {
|
||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceContextModule.sliceStatusToNodeState;
|
||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(SlicehostImageToImageTest.convertImage());
|
||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
|
||||
Slice slice = SliceHandlerTest.parseSlice();
|
||||
|
|
Loading…
Reference in New Issue