mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 15:08:28 +00:00
Issue 230: completed coding ibmdev support
This commit is contained in:
parent
b87fcd4ee2
commit
003c29e4b5
@ -0,0 +1,85 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.ibmdev.compute.functions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
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.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
|
||||||
|
import org.jclouds.domain.Credentials;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.ibmdev.domain.Instance;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata> {
|
||||||
|
public static final Pattern ALL_BEFORE_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
private final Map<Instance.Status, NodeState> instanceStateToNodeState;
|
||||||
|
private final Map<String, ? extends Image> images;
|
||||||
|
private final Map<String, String> credentialsMap;
|
||||||
|
private final Map<String, ? extends Location> locations;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
InstanceToNodeMetadata(Map<Instance.Status, NodeState> instanceStateToNodeState,
|
||||||
|
Map<String, ? extends Image> images,
|
||||||
|
@Named("CREDENTIALS") Map<String, String> credentialsMap,
|
||||||
|
Map<String, ? extends Location> locations) {
|
||||||
|
this.instanceStateToNodeState = checkNotNull(instanceStateToNodeState,
|
||||||
|
"instanceStateToNodeState");
|
||||||
|
this.images = checkNotNull(images, "images");
|
||||||
|
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
|
||||||
|
this.locations = checkNotNull(locations, "locations");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMetadata apply(Instance from) {
|
||||||
|
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
|
||||||
|
final String tag = matcher.find() ? matcher.group(1) : null;
|
||||||
|
Set<String> ipSet = ImmutableSet.of(from.getIp());
|
||||||
|
NodeState state = instanceStateToNodeState.get(from.getStatus());
|
||||||
|
Image image = images.get(from.getImageId());
|
||||||
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations
|
||||||
|
.get(image.getLocation()), null, ImmutableMap.<String, String> of(), tag, image,
|
||||||
|
state, ipSet, ImmutableList.<String> of(), ImmutableMap.<String, String> of(),
|
||||||
|
new Credentials(image.getDefaultCredentials().account, credentialsMap.get(tag)));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.ibmdev.functions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ParseLongFromDate implements Function<Object, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(Object from) {
|
||||||
|
checkArgument(from instanceof Date, "this binder is only valid for Date!");
|
||||||
|
return Date.class.cast(from).getTime()+"";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.ibmdev.functions;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.ibmdev.domain.Address;
|
||||||
|
import org.jclouds.ibmdev.domain.Image;
|
||||||
|
import org.jclouds.ibmdev.domain.Instance;
|
||||||
|
import org.jclouds.ibmdev.domain.Volume;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class ParseUtils {
|
||||||
|
|
||||||
|
public static final Predicate<Address> CLEAN_ADDRESS = new Predicate<Address>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Address input) {
|
||||||
|
if ("".equals(input.getIp()))
|
||||||
|
input.setIp(null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Set<String> emptyString = ImmutableSet.of("");
|
||||||
|
|
||||||
|
public static final Predicate<Volume> CLEAN_VOLUME = new Predicate<Volume>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Volume input) {
|
||||||
|
if (new Long(0).equals(input.getInstanceId()))
|
||||||
|
input.setInstanceId(null);
|
||||||
|
if (emptyString.equals(input.getProductCodes()))
|
||||||
|
input.getProductCodes().clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Predicate<Image> CLEAN_IMAGE = new Predicate<Image>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Image input) {
|
||||||
|
if (emptyString.equals(input.getProductCodes()))
|
||||||
|
input.getProductCodes().clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Predicate<Instance> CLEAN_INSTANCE = new Predicate<Instance>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Instance input) {
|
||||||
|
if (emptyString.equals(input.getProductCodes()))
|
||||||
|
input.getProductCodes().clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static <T> Set<T> clean(Iterable<T> elements, Predicate<T> cleaner) {
|
||||||
|
return Sets.newLinkedHashSet(Iterables.filter(elements, cleaner));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.ibmdev.predicates;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
|
||||||
|
import org.jclouds.ibmdev.domain.Address;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class AddressFree implements Predicate<Address> {
|
||||||
|
|
||||||
|
private final IBMDeveloperCloudClient client;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public AddressFree(IBMDeveloperCloudClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean apply(Address address) {
|
||||||
|
logger.trace("looking for state on address %s", address);
|
||||||
|
final String id = address.getId();
|
||||||
|
try {
|
||||||
|
address = Iterables.find(client.listAddresses(), new Predicate<Address>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Address input) {
|
||||||
|
return input.getId().equals(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
logger.trace("%s: looking for address state %s: currently: %s", address.getId(),
|
||||||
|
Address.State.FREE, address.getState());
|
||||||
|
return address.getState() == Address.State.FREE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.ibmdev.predicates;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
|
||||||
|
import org.jclouds.ibmdev.domain.Instance;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests to see if a task succeeds.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class InstanceActive implements Predicate<Instance> {
|
||||||
|
|
||||||
|
private final IBMDeveloperCloudClient client;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public InstanceActive(IBMDeveloperCloudClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean apply(Instance instance) {
|
||||||
|
logger.trace("looking for state on instance %s", instance);
|
||||||
|
instance = client.getInstance(instance.getId());
|
||||||
|
if (instance == null)
|
||||||
|
return false;
|
||||||
|
logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(),
|
||||||
|
Instance.Status.ACTIVE, instance.getStatus());
|
||||||
|
return instance.getStatus() == Instance.Status.ACTIVE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.ibmdev.predicates;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
|
||||||
|
import org.jclouds.ibmdev.domain.Instance;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class InstanceRemovedOrNotFound implements Predicate<Instance> {
|
||||||
|
|
||||||
|
private final IBMDeveloperCloudClient client;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public InstanceRemovedOrNotFound(IBMDeveloperCloudClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean apply(Instance instance) {
|
||||||
|
logger.trace("looking for state on instance %s", instance);
|
||||||
|
instance = client.getInstance(instance.getId());
|
||||||
|
if (instance == null)
|
||||||
|
return true;
|
||||||
|
logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(),
|
||||||
|
Instance.Status.REMOVED, instance.getStatus());
|
||||||
|
return instance.getStatus() == Instance.Status.REMOVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.ibmdev.predicates;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
|
||||||
|
import org.jclouds.ibmdev.domain.Volume;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class VolumeUnmounted implements Predicate<Volume> {
|
||||||
|
|
||||||
|
private final IBMDeveloperCloudClient client;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public VolumeUnmounted(IBMDeveloperCloudClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean apply(Volume volume) {
|
||||||
|
logger.trace("looking for state on volume %s", volume);
|
||||||
|
volume = client.getVolume(volume.getId());
|
||||||
|
if (volume == null)
|
||||||
|
return false;
|
||||||
|
logger.trace("%s: looking for volume state %s: currently: %s", volume.getId(),
|
||||||
|
Volume.State.UNMOUNTED, volume.getState());
|
||||||
|
return volume.getState() == Volume.State.UNMOUNTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user