fixed ibmdev to compile again

This commit is contained in:
Adrian Cole 2010-11-15 10:44:21 +01:00
parent 5b27c07eaf
commit a8c24236ab
22 changed files with 436 additions and 359 deletions

View File

@ -0,0 +1,76 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ibmdev.compute.config;
import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
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.ibmdev.compute.strategy.IBMDeveloperCloudAddNodeWithTagStrategy;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudDestroyNodeStrategy;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudGetNodeMetadataStrategy;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudLifeCycleStrategy;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudListNodesStrategy;
/**
* @author Adrian Cole
*/
public class IBMDeveloperCloudBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
@Override
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
return IBMDeveloperCloudAddNodeWithTagStrategy.class;
}
@Override
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
return IBMDeveloperCloudDestroyNodeStrategy.class;
}
@Override
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
return IBMDeveloperCloudGetNodeMetadataStrategy.class;
}
@Override
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
return IBMDeveloperCloudListNodesStrategy.class;
}
@Override
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
return IBMDeveloperCloudLifeCycleStrategy.class;
}
@Override
protected Class<? extends ResumeNodeStrategy> defineStartNodeStrategy() {
return IBMDeveloperCloudLifeCycleStrategy.class;
}
@Override
protected Class<? extends SuspendNodeStrategy> defineStopNodeStrategy() {
return IBMDeveloperCloudLifeCycleStrategy.class;
}
}

View File

@ -0,0 +1,51 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ibmdev.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.ibmdev.compute.suppliers.IBMDeveloperCloudHardwareSupplier;
import org.jclouds.ibmdev.compute.suppliers.IBMDeveloperCloudImageSupplier;
import org.jclouds.ibmdev.compute.suppliers.IBMDeveloperCloudLocationSupplier;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
public class IBMDeveloperCloudBindComputeSuppliersByClass extends BindComputeSuppliersByClass {
@Override
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
return IBMDeveloperCloudHardwareSupplier.class;
}
@Override
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
return IBMDeveloperCloudImageSupplier.class;
}
@Override
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return IBMDeveloperCloudLocationSupplier.class;
}
}

View File

@ -21,76 +21,26 @@ package org.jclouds.ibmdev.compute.config;
import static org.jclouds.compute.domain.OsFamily.SUSE; import static org.jclouds.compute.domain.OsFamily.SUSE;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.LoadBalancerService;
import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
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.domain.Location;
import org.jclouds.ibmdev.IBMDeveloperCloudAsyncClient;
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
import org.jclouds.ibmdev.compute.functions.InstanceToNodeMetadata;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudAddNodeWithTagStrategy;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudDestroyNodeStrategy;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudGetNodeMetadataStrategy;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudListNodesStrategy;
import org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudRebootNodeStrategy;
import org.jclouds.ibmdev.compute.suppliers.IBMDeveloperCloudImageSupplier;
import org.jclouds.ibmdev.compute.suppliers.IBMDeveloperCloudLocationSupplier;
import org.jclouds.ibmdev.compute.suppliers.IBMDeveloperCloudSizeSupplier;
import org.jclouds.ibmdev.domain.Instance;
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.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.util.Providers;
/** /**
* Configures the {@link IBMDeveloperCloudComputeServiceContext}; requires
* {@link BaseComputeService} bound.
*
* @author Adrian Cole * @author Adrian Cole
*/ */
public class IBMDeveloperCloudComputeServiceContextModule extends BaseComputeServiceContextModule { public class IBMDeveloperCloudComputeServiceContextModule extends BaseComputeServiceContextModule {
@Override @Override
protected void configure() { protected void configure() {
install(new ComputeServiceTimeoutsModule()); install(new IBMDeveloperCloudComputeServiceDependenciesModule());
bind(new TypeLiteral<Function<Instance, NodeMetadata>>() { install(new IBMDeveloperCloudBindComputeStrategiesByClass());
}).to(InstanceToNodeMetadata.class); install(new IBMDeveloperCloudBindComputeSuppliersByClass());
bind(new TypeLiteral<ComputeServiceContext>() { super.configure();
}).to(new TypeLiteral<ComputeServiceContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<RestContext<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}).to(new TypeLiteral<RestContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(IBMDeveloperCloudAddNodeWithTagStrategy.class);
bind(ListNodesStrategy.class).to(IBMDeveloperCloudListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(IBMDeveloperCloudGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(IBMDeveloperCloudRebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(IBMDeveloperCloudDestroyNodeStrategy.class);
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
} }
/** /**
@ -100,48 +50,4 @@ public class IBMDeveloperCloudComputeServiceContextModule extends BaseComputeSer
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
return template.osFamily(SUSE); return template.osFamily(SUSE);
} }
@Provides
@Singleton
@Named("CREDENTIALS")
Map<String, String> credentialsMap() {
return new ConcurrentHashMap<String, String>();
}
@VisibleForTesting
static final Map<Instance.Status, NodeState> instanceStatusToNodeState = ImmutableMap
.<Instance.Status, NodeState> builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)//
.put(Instance.Status.STOPPED, NodeState.SUSPENDED)//
.put(Instance.Status.REMOVED, NodeState.TERMINATED)//
.put(Instance.Status.DEPROVISIONING, NodeState.PENDING)//
.put(Instance.Status.FAILED, NodeState.ERROR)//
.put(Instance.Status.NEW, NodeState.PENDING)//
.put(Instance.Status.PROVISIONING, NodeState.PENDING)//
.put(Instance.Status.REJECTED, NodeState.ERROR)//
.put(Instance.Status.RESTARTING, NodeState.PENDING)//
.put(Instance.Status.STARTING, NodeState.PENDING)//
.put(Instance.Status.STOPPING, NodeState.PENDING)//
.put(Instance.Status.DEPROVISION_PENDING, NodeState.PENDING)//
.put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build();
@Singleton
@Provides
Map<Instance.Status, NodeState> provideServerToNodeState() {
return instanceStatusToNodeState;
}
@Override
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
return injector.getInstance(IBMDeveloperCloudImageSupplier.class);
}
@Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(IBMDeveloperCloudSizeSupplier.class);
}
@Override
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
return injector.getInstance(IBMDeveloperCloudLocationSupplier.class);
}
} }

View File

@ -0,0 +1,92 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ibmdev.compute.config;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.ibmdev.IBMDeveloperCloudAsyncClient;
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
import org.jclouds.ibmdev.compute.functions.InstanceToNodeMetadata;
import org.jclouds.ibmdev.domain.Instance;
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 Adrian Cole
*/
public class IBMDeveloperCloudComputeServiceDependenciesModule extends AbstractModule {
@Override
protected void configure() {
bind(new TypeLiteral<Function<Instance, NodeMetadata>>() {
}).to(InstanceToNodeMetadata.class);
bind(new TypeLiteral<ComputeServiceContext>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<RestContext<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}).to(new TypeLiteral<RestContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
}
@Provides
@Singleton
@Named("CREDENTIALS")
Map<String, String> credentialsMap() {
return new ConcurrentHashMap<String, String>();
}
@VisibleForTesting
static final Map<Instance.Status, NodeState> instanceStatusToNodeState = ImmutableMap
.<Instance.Status, NodeState> builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)//
.put(Instance.Status.STOPPED, NodeState.SUSPENDED)//
.put(Instance.Status.REMOVED, NodeState.TERMINATED)//
.put(Instance.Status.DEPROVISIONING, NodeState.PENDING)//
.put(Instance.Status.FAILED, NodeState.ERROR)//
.put(Instance.Status.NEW, NodeState.PENDING)//
.put(Instance.Status.PROVISIONING, NodeState.PENDING)//
.put(Instance.Status.REJECTED, NodeState.ERROR)//
.put(Instance.Status.RESTARTING, NodeState.PENDING)//
.put(Instance.Status.STARTING, NodeState.PENDING)//
.put(Instance.Status.STOPPING, NodeState.PENDING)//
.put(Instance.Status.DEPROVISION_PENDING, NodeState.PENDING)//
.put(Instance.Status.UNKNOWN, NodeState.UNRECOGNIZED).build();
@Singleton
@Provides
Map<Instance.Status, NodeState> provideServerToNodeState() {
return instanceStatusToNodeState;
}
}

View File

@ -1,58 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ibmdev.compute.domain;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import com.google.common.collect.ImmutableMap;
/**
* @author Adrian Cole
*/
public class IBMImage extends ImageImpl {
/** The serialVersionUID */
private static final long serialVersionUID = -8520373150950058296L;
private final org.jclouds.ibmdev.domain.Image rawImage;
public IBMImage(org.jclouds.ibmdev.domain.Image in, Location location) {
// TODO parse correct OS
// TODO manifest fails to parse due to encoding issues in the path
// TODO get correct default credentials
// http://www-180.ibm.com/cloud/enterprise/beta/ram/community/_rlvid.jsp.faces?_rap=pc_DiscussionForum.doDiscussionTopic&_rvip=/community/discussionForum.jsp&guid={DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&submission=false&fid=1068&tid=1527
super(in.getId(), in.getName(), in.getId(), location, null, ImmutableMap.<String, String> of(),
new OperatingSystem((in.getPlatform().indexOf("Red Hat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, null,
null, null, in.getPlatform(), (in.getPlatform().indexOf("32") == -1)), in.getDescription(), in
.getCreatedTime().getTime()
+ "", new Credentials("idcuser", null));
this.rawImage = in;
}
public org.jclouds.ibmdev.domain.Image getRawImage() {
return rawImage;
}
}

View File

@ -1,74 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ibmdev.compute.domain;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.ibmdev.domain.InstanceType;
import com.google.common.collect.ImmutableMap;
/**
* @author Adrian Cole
*/
public class IBMSize extends SizeImpl {
/** The serialVersionUID */
private static final long serialVersionUID = -8520373150950058296L;
private final IBMImage image;
private final InstanceType instanceType;
// until we can lookup cores by id, we are multiplying price *100 to get a positive integer we
// can compare against.
public IBMSize(IBMImage in, InstanceType instanceType) {
super(instanceType.getId(), instanceType.getLabel(), in.getId() + "/" + instanceType.getId(), in.getLocation(),
in.getRawImage().getManifest(), ImmutableMap.<String, String> of(), (int) (instanceType.getPrice()
.getRate() * 100), (int) (instanceType.getPrice().getRate() * 1024d), (int) (instanceType
.getPrice().getRate() * 100d), null);
this.image = in;
this.instanceType = instanceType;
}
public IBMImage getImage() {
return image;
}
public InstanceType getInstanceType() {
return instanceType;
}
/**
* {@inheritDoc}
*/
@Override
public boolean supportsImage(Image input) {
return image.getId().equals(input.getId());
}
@Override
public String toString() {
return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() + ", cores=" + getCores()
+ ", ram=" + getRam() + ", disk=" + getDisk() + ", supportsImage=" + image.getId() + ", rate="
+ instanceType.getPrice().getRate() + "]";
}
}

View File

@ -32,16 +32,16 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.ibmdev.domain.Instance; import org.jclouds.ibmdev.domain.Instance;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -51,6 +51,21 @@ import com.google.common.collect.ImmutableSet;
@Singleton @Singleton
public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata> { public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata> {
@VisibleForTesting
public static final Map<Instance.Status, NodeState> instanceStatusToNodeState = ImmutableMap
.<Instance.Status, NodeState> builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)//
.put(Instance.Status.STOPPED, NodeState.SUSPENDED)//
.put(Instance.Status.REMOVED, NodeState.TERMINATED)//
.put(Instance.Status.DEPROVISIONING, NodeState.PENDING)//
.put(Instance.Status.FAILED, NodeState.ERROR)//
.put(Instance.Status.NEW, NodeState.PENDING)//
.put(Instance.Status.PROVISIONING, NodeState.PENDING)//
.put(Instance.Status.REJECTED, NodeState.ERROR)//
.put(Instance.Status.RESTARTING, NodeState.PENDING)//
.put(Instance.Status.STARTING, NodeState.PENDING)//
.put(Instance.Status.STOPPING, NodeState.PENDING)//
.put(Instance.Status.DEPROVISION_PENDING, NodeState.PENDING)//
.put(Instance.Status.UNKNOWN, NodeState.UNRECOGNIZED).build();
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final Map<Instance.Status, NodeState> instanceStateToNodeState; private final Map<Instance.Status, NodeState> instanceStateToNodeState;
@ -70,14 +85,15 @@ public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata>
@Override @Override
public NodeMetadata apply(Instance from) { public NodeMetadata apply(Instance from) {
//TODO hardware
String tag = parseTagFromName(from.getName()); String tag = parseTagFromName(from.getName());
Set<String> ipSet = from.getIp() != null ? ImmutableSet.of(from.getIp()) : ImmutableSet.<String> of(); Set<String> ipSet = from.getIp() != null ? ImmutableSet.of(from.getIp()) : ImmutableSet.<String> of();
NodeState state = instanceStateToNodeState.get(from.getStatus());
Image image = images.get().get(from.getImageId()); Image image = images.get().get(from.getImageId());
String key = tag != null ? credentialsMap.get(tag) : null; String key = tag != null ? credentialsMap.get(tag) : null;
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get().get( return new NodeMetadataBuilder().ids(from.getId() + "").name(from.getName())
image.getLocation()), null, ImmutableMap.<String, String> of(), tag, from.getImageId(), .location(locations.get().get(image.getLocation())).tag(tag).imageId(from.getImageId())
image != null ? image.getOperatingSystem() : null, state, ipSet, ImmutableList.<String> of(), .state(instanceStateToNodeState.get(from.getStatus()))
ImmutableMap.<String, String> of(), new Credentials(image.getDefaultCredentials().identity, key)); .operatingSystem(image != null ? image.getOperatingSystem() : null).publicAddresses(ipSet)
.credentials(new Credentials(image.getDefaultCredentials().identity, key)).build();
} }
} }

View File

@ -21,7 +21,6 @@ package org.jclouds.ibmdev.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -39,8 +38,6 @@ import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.compute.util.ComputeUtils; import org.jclouds.compute.util.ComputeUtils;
import org.jclouds.ibmdev.IBMDeveloperCloudClient; import org.jclouds.ibmdev.IBMDeveloperCloudClient;
import org.jclouds.io.Payload;
import org.jclouds.util.Utils;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -63,14 +60,8 @@ public class CreateKeyPairEncodeTagIntoNameRunNodesAndAddToSet extends EncodeTag
@Override @Override
public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> nodes, public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> nodes,
Map<NodeMetadata, Exception> badNodes) { Map<NodeMetadata, Exception> badNodes) {
Payload key = template.getOptions().getPublicKey(); String keyAsText = template.getOptions().getPublicKey();
if (key != null) { if (keyAsText != null) {
String keyAsText;
try {
keyAsText = Utils.toStringAndClose(key.getInput());
} catch (IOException e1) {
throw new RuntimeException(e1);
}
template.getOptions().dontAuthorizePublicKey(); template.getOptions().dontAuthorizePublicKey();
try { try {
client.addPublicKey(tag, keyAsText); client.addPublicKey(tag, keyAsText);

View File

@ -29,8 +29,6 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.ibmdev.IBMDeveloperCloudClient; import org.jclouds.ibmdev.IBMDeveloperCloudClient;
import org.jclouds.ibmdev.compute.domain.IBMImage;
import org.jclouds.ibmdev.compute.domain.IBMSize;
import org.jclouds.ibmdev.domain.Instance; import org.jclouds.ibmdev.domain.Instance;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -52,10 +50,9 @@ public class IBMDeveloperCloudAddNodeWithTagStrategy implements AddNodeWithTagSt
} }
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata addNodeWithTag(String tag, String name, Template template) {
Instance instance = client.createInstanceInLocation(template.getLocation().getId(), name, IBMImage.class.cast( Instance instance = client.createInstanceInLocation(template.getLocation().getId(), name, template.getImage()
template.getImage()).getRawImage().getId(), IBMSize.class.cast(template.getSize()).getInstanceType() .getProviderId(), template.getHardware().getProviderId(), authorizePublicKey(tag));
.getId(), authorizePublicKey(tag));
return instanceToNodeMetadata.apply(client.getInstance(instance.getId())); return instanceToNodeMetadata.apply(client.getInstance(instance.getId()));
} }
} }

View File

@ -44,8 +44,8 @@ public class IBMDeveloperCloudDestroyNodeStrategy implements DestroyNodeStrategy
} }
@Override @Override
public NodeMetadata execute(String id) { public NodeMetadata destroyNode(String id) {
client.deleteInstance(id); client.deleteInstance(id);
return getNode.execute(id); return getNode.getNode(id);
} }
} }

View File

@ -47,7 +47,7 @@ public class IBMDeveloperCloudGetNodeMetadataStrategy implements GetNodeMetadata
} }
@Override @Override
public NodeMetadata execute(String id) { public NodeMetadata getNode(String id) {
Instance instance = client.getInstance(checkNotNull(id, "id")); Instance instance = client.getInstance(checkNotNull(id, "id"));
return instance == null ? null : instanceToNodeMetadata.apply(instance); return instance == null ? null : instanceToNodeMetadata.apply(instance);
} }

View File

@ -27,26 +27,38 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.ibmdev.IBMDeveloperCloudClient; import org.jclouds.ibmdev.IBMDeveloperCloudClient;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class IBMDeveloperCloudRebootNodeStrategy implements RebootNodeStrategy { public class IBMDeveloperCloudLifeCycleStrategy implements RebootNodeStrategy, SuspendNodeStrategy, ResumeNodeStrategy {
private final IBMDeveloperCloudClient client; private final IBMDeveloperCloudClient client;
private final GetNodeMetadataStrategy getNode; private final GetNodeMetadataStrategy getNode;
@Inject @Inject
protected IBMDeveloperCloudRebootNodeStrategy(IBMDeveloperCloudClient client, GetNodeMetadataStrategy getNode) { protected IBMDeveloperCloudLifeCycleStrategy(IBMDeveloperCloudClient client, GetNodeMetadataStrategy getNode) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.getNode = checkNotNull(getNode, "getNode"); this.getNode = checkNotNull(getNode, "getNode");
} }
@Override @Override
public NodeMetadata execute(String id) { public NodeMetadata rebootNode(String id) {
client.restartInstance(id); client.restartInstance(id);
return getNode.execute(id); 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");
} }
} }

View File

@ -49,7 +49,7 @@ public class IBMDeveloperCloudListNodesStrategy implements ListNodesStrategy {
} }
@Override @Override
public Iterable<? extends ComputeMetadata> list() { public Iterable<? extends ComputeMetadata> listNodes() {
return listDetailsOnNodesMatching(NodePredicates.all()); return listDetailsOnNodesMatching(NodePredicates.all());
} }

View File

@ -0,0 +1,86 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ibmdev.compute.suppliers;
import java.util.Map;
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.domain.HardwareBuilder;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
import org.jclouds.ibmdev.domain.InstanceType;
import org.jclouds.logging.Logger;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
@Singleton
public class IBMDeveloperCloudHardwareSupplier implements Supplier<Set<? extends Hardware>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final IBMDeveloperCloudClient sync;
private final Supplier<Map<String, ? extends Location>> locations;
@Inject
IBMDeveloperCloudHardwareSupplier(IBMDeveloperCloudClient sync, Supplier<Map<String, ? extends Location>> locations) {
this.sync = sync;
this.locations = locations;
}
@Override
public Set<? extends Hardware> get() {
final Set<Hardware> hardware = Sets.newHashSet();
logger.debug(">> providing hardware");
for (org.jclouds.ibmdev.domain.Image image : sync.listImages()) {
for (InstanceType instanceType : image.getSupportedInstanceTypes()) {
hardware.add(new HardwareBuilder()
.id(image.getId() + "/" + instanceType.getId())
.providerId(image.getId())
.name(instanceType.getLabel())
.location(locations.get().get(image.getLocation()))
.uri(image.getManifest())
.processors(ImmutableList.of(new Processor((instanceType.getPrice().getRate() * 100), 1.0)))
.ram((int) instanceType.getPrice().getRate() * 1024)
.volumes(
ImmutableList.<Volume> of(new VolumeImpl((float) (instanceType.getPrice().getRate() * 100d),
true, true))).build());
}
}
logger.debug("<< hardware(%d)", hardware.size());
return hardware;
}
}

View File

@ -28,10 +28,13 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.ibmdev.IBMDeveloperCloudClient; import org.jclouds.ibmdev.IBMDeveloperCloudClient;
import org.jclouds.ibmdev.compute.domain.IBMImage;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -61,11 +64,24 @@ public class IBMDeveloperCloudImageSupplier implements Supplier<Set<? extends Im
final Set<Image> images = Sets.newHashSet(); final Set<Image> images = Sets.newHashSet();
logger.debug(">> providing images"); logger.debug(">> providing images");
for (org.jclouds.ibmdev.domain.Image image : sync.listImages()) for (org.jclouds.ibmdev.domain.Image image : sync.listImages()) {
images.add(new IBMImage(image, locations.get().get(image.getLocation()))); // TODO parse correct OS
// TODO manifest fails to parse due to encoding issues in the path
// TODO get correct default credentials
// http://www-180.ibm.com/cloud/enterprise/beta/ram/community/_rlvid.jsp.faces?_rap=pc_DiscussionForum.doDiscussionTopic&_rvip=/community/discussionForum.jsp&guid={DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&submission=false&fid=1068&tid=1527
images.add(new ImageBuilder()
.ids(image.getId())
.name(image.getName())
.location(locations.get().get(image.getLocation()))
.operatingSystem(
new OperatingSystemBuilder()
.family((image.getPlatform().indexOf("Red Hat") != -1) ? OsFamily.RHEL : OsFamily.SUSE)
.arch(image.getPlatform()).is64Bit(image.getPlatform().indexOf("32") == -1).build())
.description(image.getDescription()).version(image.getCreatedTime().getTime() + "")
.defaultCredentials(new Credentials("idcuser", null)).build());
}
logger.debug("<< images(%d)", images.size()); logger.debug("<< images(%d)", images.size());
return images; return images;
} }
} }

View File

@ -1,68 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ibmdev.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.Image;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.ibmdev.compute.domain.IBMImage;
import org.jclouds.ibmdev.compute.domain.IBMSize;
import org.jclouds.ibmdev.domain.InstanceType;
import org.jclouds.logging.Logger;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
@Singleton
public class IBMDeveloperCloudSizeSupplier implements Supplier<Set<? extends Size>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final Supplier<Set<? extends Image>> images;
@Inject
IBMDeveloperCloudSizeSupplier(Supplier<Set<? extends Image>> images) {
this.images = images;
}
@Override
public Set<? extends Size> get() {
final Set<Size> sizes = Sets.newHashSet();
logger.debug(">> providing sizes");
for (Image in : images.get()) {
IBMImage image = IBMImage.class.cast(in);
for (InstanceType instanceType : image.getRawImage().getSupportedInstanceTypes())
sizes.add(new IBMSize(image, instanceType));
}
logger.debug("<< sizes(%d)", sizes.size());
return sizes;
}
}

View File

@ -56,8 +56,7 @@ public class IBMDeveloperCloudErrorHandler implements HttpErrorHandler {
response.getStatusLine()); response.getStatusLine());
switch (response.getStatusCode()) { switch (response.getStatusCode()) {
case 401: case 401:
exception = new AuthorizationException(command.getRequest(), message != null ? message : response exception = new AuthorizationException(exception.getMessage(), exception);
.getStatusLine());
break; break;
case 402: case 402:
case 403: case 403:

View File

@ -50,7 +50,7 @@ import org.jclouds.ibmdev.xml.LocationHandler;
import org.jclouds.ibmdev.xml.LocationsHandler; import org.jclouds.ibmdev.xml.LocationsHandler;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
@ -660,7 +660,7 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
} }
@Override @Override
public ContextSpec<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient> createContextSpec() { public RestContextSpec<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient> createContextSpec() {
return new RestContextFactory().createContextSpec("ibmdev", "identity", "credential", new Properties()); return new RestContextFactory().createContextSpec("ibmdev", "identity", "credential", new Properties());
} }
} }

View File

@ -41,14 +41,14 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.ibmdev.domain.Address; import org.jclouds.ibmdev.domain.Address;
import org.jclouds.ibmdev.domain.Image; import org.jclouds.ibmdev.domain.Image;
import org.jclouds.ibmdev.domain.Instance; import org.jclouds.ibmdev.domain.Instance;
import org.jclouds.ibmdev.domain.Instance.Software;
import org.jclouds.ibmdev.domain.InstanceType; import org.jclouds.ibmdev.domain.InstanceType;
import org.jclouds.ibmdev.domain.Key; import org.jclouds.ibmdev.domain.Key;
import org.jclouds.ibmdev.domain.Location; import org.jclouds.ibmdev.domain.Location;
import org.jclouds.ibmdev.domain.Offering; import org.jclouds.ibmdev.domain.Offering;
import org.jclouds.ibmdev.domain.StorageOffering; import org.jclouds.ibmdev.domain.StorageOffering;
import org.jclouds.ibmdev.domain.Volume;
import org.jclouds.ibmdev.domain.Instance.Software;
import org.jclouds.ibmdev.domain.StorageOffering.Format; import org.jclouds.ibmdev.domain.StorageOffering.Format;
import org.jclouds.ibmdev.domain.Volume;
import org.jclouds.ibmdev.predicates.AddressFree; import org.jclouds.ibmdev.predicates.AddressFree;
import org.jclouds.ibmdev.predicates.InstanceActive; import org.jclouds.ibmdev.predicates.InstanceActive;
import org.jclouds.ibmdev.predicates.InstanceActiveOrFailed; import org.jclouds.ibmdev.predicates.InstanceActiveOrFailed;
@ -56,6 +56,7 @@ import org.jclouds.ibmdev.predicates.InstanceRemovedOrNotFound;
import org.jclouds.ibmdev.predicates.VolumeUnmounted; import org.jclouds.ibmdev.predicates.VolumeUnmounted;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
@ -63,7 +64,6 @@ import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshException;
import org.jclouds.ssh.jsch.JschSshClient; import org.jclouds.ssh.jsch.JschSshClient;
import org.jclouds.ssh.jsch.predicates.InetSocketAddressConnect;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -19,6 +19,7 @@
package org.jclouds.ibmdev.compute; package org.jclouds.ibmdev.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.BaseComputeServiceLiveTest;
@ -52,7 +53,7 @@ public class IBMDeveloperCloudComputeServiceLiveTestDisabled extends BaseCompute
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.SUSE); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.SUSE);
assertEquals(defaultTemplate.getLocation().getId(), "1"); assertEquals(defaultTemplate.getLocation().getId(), "1");
assertEquals(defaultTemplate.getSize().getCores(), 2.0d); assertEquals(getCores(defaultTemplate.getHardware()), 2.0d);
} }
@Override @Override

View File

@ -0,0 +1,34 @@
package org.jclouds.ibmdev.compute;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.OsFamily;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "ibmdev.IBMDeveloperCloudTemplateBuilderLiveTest")
public class IBMDeveloperCloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public IBMDeveloperCloudTemplateBuilderLiveTest() {
provider = "ibmdev";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
return input.family != OsFamily.RHEL && //
input.family != OsFamily.SUSE && //
input.family != OsFamily.WINDOWS;
}
};
}
}

View File

@ -25,13 +25,13 @@ import org.testng.annotations.Test;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "ibmdev.IBMDeveloperCloudComputeServiceContextModuleTest") @Test(groups = "unit", testName = "ibmdev.IBMDeveloperCloudComputeServiceDependenciesModuleTest")
public class IBMDeveloperCloudComputeServiceContextModuleTest { public class IBMDeveloperCloudComputeServiceDependenciesModuleTest {
public void testAllStatusCovered() { public void testAllStatusCovered() {
for (Instance.Status state : Instance.Status.values()) { for (Instance.Status state : Instance.Status.values()) {
assert IBMDeveloperCloudComputeServiceContextModule.instanceStatusToNodeState.containsKey(state) : state; assert IBMDeveloperCloudComputeServiceDependenciesModule.instanceStatusToNodeState.containsKey(state) : state;
} }
} }