Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
Add support for multiple providers, ensure ec2-aws jclouds provider i…
Browse files Browse the repository at this point in the history
…s fully functional, isolate inventory dependency
mattstep committed Jun 7, 2012
1 parent 07d1079 commit 02b91a9
Showing 50 changed files with 2,355 additions and 587 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -87,7 +87,6 @@ For failed requests, the response will contain a JSON body of the following form

It can be difficult to code to all potential failures, but the following errors are known to potentially occur, all of which will have a 400 response code :

- Capacity Unavailable - The instance could not be created because capacity is unavailable to support the request.
- Size Unavailable - The instance size requested is not supported by the provider at that location.
- Location Unavailable - The location is unavailable for that provider.
- Provider Unavailable - There is no provider available to support this request.
@@ -268,3 +267,35 @@ The response will be 200 OK with the following body.
}
]
}



Configuration
=============

Provider Listing
----------------
A single configuration property is used to define the providers to allocate.

cloud-management.providers=devstack,hpcloud,aws,softlayer,rackspace

Individual Providers
--------------------
Each provider is then allocated with a collection of configuration properties.

cloud-management.devstack.api=openstack-nova
cloud-management.devstack.name=DevStack edition of OpenStack
cloud-management.devstack.location=http://192.168.56.2:5000
cloud-management.devstack.user=admin:admin
cloud-management.devstack.secret=admin
cloud-management.devstack.default-image-id=005dbf05-9e1c-4773-9fbc-48f7eea99aca

The following properties are supported for each provider you specify. All are required unless otherwise stated.

- api : The jclouds api or provider to use for this provider (see http://www.jclouds.org/documentation/reference/supported-providers).
- name : A meaningful name for this provider.
- location : A symantically required endpoint to connect to this provider with. For some jclouds providers this is not required. Refer to http://jclouds.org for more information on which cloud providers and apis require this to be specified.
- user : The user to connect to the specified provider with.
- secret : The password or shared secret to use when connecting with the provider.
- default-image-id : The default image to be used when starting instances.
- aws-vpc-subnet-id : An optionally specified property for ec2 providers that will specify which vpc subnet to create new instances in.
25 changes: 17 additions & 8 deletions etc/config.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
node.environment=test
discovery.uri=http://localhost:8080
http-server.http.port=8888

cloud-management.manager=InMemory

cloud-management.providers=devstack,aws
#Configured with a locally running devstack
jclouds.location=http://localhost:5000
jclouds.user=admin:admin
jclouds.secret=admin
jclouds.default-image-id=cirros-0.3.0-x86_64-uec
jclouds.default-location-id=RegionOne
inventory.base-uri=http://localhost/inv_api/v1/
inventory.user=user
inventory.password=pass
cloud-management.devstack.api=openstack-nova
cloud-management.devstack.name=DevStack edition of OpenStack
cloud-management.devstack.location=http://192.168.56.2:5000
cloud-management.devstack.user=admin:admin
cloud-management.devstack.secret=admin
cloud-management.devstack.default-image-id=005dbf05-9e1c-4773-9fbc-48f7eea99aca

cloud-management.aws.api=aws-ec2
cloud-management.aws.name=Amazon Web Services
cloud-management.aws.user=
cloud-management.aws.secret=
cloud-management.aws.default-image-id=ami-a29943cb
cloud-management.aws.aws-vpc-subnet-id=subnet-e9ac9581
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -139,12 +139,11 @@
</dependency>

<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>openstack-nova</artifactId>
<version>1.5.0-alpha.6</version>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-allcompute</artifactId>
<version>1.5.0-beta.1</version>
</dependency>


<!-- for packaging -->
<dependency>
<groupId>com.proofpoint.platform</groupId>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2010 Proofpoint, Inc.
*
* 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 com.proofpoint.cloudmanagement.service;

import com.google.common.base.Preconditions;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.proofpoint.configuration.ConfigurationAwareModule;
import com.proofpoint.configuration.ConfigurationFactory;

public class ConditionalModule implements ConfigurationAwareModule
{
public static ConfigurationAwareModule installIfPropertyEquals(Module module, String property, String expectedValue)
{
return new ConditionalModule(module, property, expectedValue);
}

private final Module module;
private final String property;
private final String expectedValue;
private ConfigurationFactory configurationFactory;

private ConditionalModule(Module module, String property, String expectedValue)
{
Preconditions.checkNotNull(module, "module is null");
Preconditions.checkNotNull(property, "property is null");

this.module = module;
this.property = property;
this.expectedValue = expectedValue;
}

@Override
public void setConfigurationFactory(ConfigurationFactory configurationFactory)
{
this.configurationFactory = configurationFactory;
configurationFactory.consumeProperty(property);

// consume properties if we are not going to install the module
if (!shouldInstall()) {
configurationFactory.registerConfigurationClasses(module);
}
}

@Override
public void configure(Binder binder)
{
Preconditions.checkNotNull(configurationFactory, "configurationFactory is null");
if (shouldInstall()) {
binder.install(module);
}
}

private boolean shouldInstall()
{
if (expectedValue != null) {
return expectedValue.equals(configurationFactory.getProperties().get(property));
}
else {
return configurationFactory.getProperties().containsKey(property);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2010 Proofpoint, Inc.
*
* 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 com.proofpoint.cloudmanagement.service;

public interface DnsManager
{
public String getFullyQualifiedDomainName(Instance instance);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2010 Proofpoint, Inc.
*
* 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 com.proofpoint.cloudmanagement.service;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Scopes;
import org.eclipse.jetty.util.ConcurrentHashSet;

import java.util.Set;

public class InMemoryManagerModule
implements Module
{
public void configure(Binder binder)
{
binder.requireExplicitBindings();
binder.disableCircularProxies();

binder.bind(DnsManager.class).to(NoOpDnsManager.class).in(Scopes.SINGLETON);
binder.bind(TagManager.class).to(InMemoryTagManager.class).in(Scopes.SINGLETON);
}

public static class NoOpDnsManager implements DnsManager
{
@Override
public String getFullyQualifiedDomainName(Instance instance)
{
return instance.getHostname();
}
}

public static class InMemoryTagManager implements TagManager
{
private final LoadingCache<String, Set<String>> tagCache =
CacheBuilder.newBuilder()
.build(new CacheLoader<String, Set<String>>()
{

@Override
public Set<String> load(String key)
throws Exception
{
return new ConcurrentHashSet<String>();
}
});

@Override
public TagUpdateStatus addTag(Instance instance, String tag)
{
tagCache.getUnchecked(instance.getId()).add(tag);
return TagUpdateStatus.UPDATED;
}

@Override
public TagUpdateStatus deleteTag(Instance instance, String tag)
{
tagCache.getUnchecked(instance.getId()).remove(tag);
return TagUpdateStatus.UPDATED;
}

@Override
public Iterable<String> getTags(Instance instance)
{
return tagCache.getUnchecked(instance.getId());
}
}
}
Loading

0 comments on commit 02b91a9

Please sign in to comment.