Moved EC2 launching FactoryBean to test support.
Now using typica from mvn repo. Added some svn ignores.
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
package org.springframework.ldap;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.xerox.amazonws.ec2.Jec2;
|
||||
import com.xerox.amazonws.ec2.LaunchConfiguration;
|
||||
import com.xerox.amazonws.ec2.ReservationDescription;
|
||||
import com.xerox.amazonws.ec2.ReservationDescription.Instance;
|
||||
|
||||
public abstract class AbstractEc2InstanceLaunchingFactoryBean extends AbstractFactoryBean {
|
||||
private static final int SLEEP_TIME = 1000;
|
||||
|
||||
private static final Log log = LogFactory.getLog(AbstractEc2InstanceLaunchingFactoryBean.class);
|
||||
|
||||
private String imageName;
|
||||
|
||||
private String awsKey;
|
||||
|
||||
private String awsSecretKey;
|
||||
|
||||
private String keyName;
|
||||
|
||||
private String groupName;
|
||||
|
||||
private Instance instance;
|
||||
|
||||
public void setImageName(String imageName) {
|
||||
this.imageName = imageName;
|
||||
}
|
||||
|
||||
public void setAwsKey(String awsKey) {
|
||||
this.awsKey = awsKey;
|
||||
}
|
||||
|
||||
public void setAwsSecretKey(String awsSecretKey) {
|
||||
this.awsSecretKey = awsSecretKey;
|
||||
}
|
||||
|
||||
public void setKeyName(String keyName) {
|
||||
this.keyName = keyName;
|
||||
}
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Object createInstance() throws Exception {
|
||||
Assert.hasLength(imageName, "ImageName must be set");
|
||||
Assert.hasLength(awsKey, "AwsKey must be set");
|
||||
Assert.hasLength(awsSecretKey, "AwsSecretKey must be set");
|
||||
Assert.hasLength(keyName, "KeyName must be set");
|
||||
Assert.hasLength(groupName, "GroupName must be set");
|
||||
|
||||
log.info("Launching EC2 instance for image: " + imageName);
|
||||
|
||||
Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
|
||||
LaunchConfiguration launchConfiguration = new LaunchConfiguration(imageName);
|
||||
launchConfiguration.setKeyName(keyName);
|
||||
launchConfiguration.setSecurityGroup(Collections.singletonList(groupName));
|
||||
|
||||
ReservationDescription reservationDescription = jec2.runInstances(launchConfiguration);
|
||||
instance = reservationDescription.getInstances().get(0);
|
||||
while (!instance.isRunning() && !instance.isTerminated()) {
|
||||
log.info("Instance still starting up; sleeping " + SLEEP_TIME + "ms");
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
reservationDescription = jec2.describeInstances(Collections.singletonList(instance.getInstanceId())).get(0);
|
||||
instance = reservationDescription.getInstances().get(0);
|
||||
}
|
||||
|
||||
if (instance.isRunning()) {
|
||||
log.info("EC2 instance is now running");
|
||||
return doCreateInstance(instance.getDnsName());
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Failed to start a new instance");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract Object doCreateInstance(String dnsName) throws Exception;
|
||||
|
||||
@Override
|
||||
protected void destroyInstance(Object ignored) throws Exception {
|
||||
if (this.instance != null) {
|
||||
log.info("Shutting down instance");
|
||||
Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
|
||||
jec2.terminateInstances(Collections.singletonList(this.instance.getInstanceId()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,28 @@
|
||||
/*
|
||||
* Copyright 2005-2008 the original author or authors.
|
||||
*
|
||||
* 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.springframework.ldap;
|
||||
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.support.LdapContextSource;
|
||||
import org.springframework.ldap.test.AbstractEc2InstanceLaunchingFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* FactoryBean to create a ContextSource using the EC2 instance created by superclass.
|
||||
*/
|
||||
public class ContextSourceEc2InstanceLaunchingFactoryBean extends AbstractEc2InstanceLaunchingFactoryBean {
|
||||
|
||||
private String base;
|
||||
@@ -18,6 +38,7 @@ public class ContextSourceEc2InstanceLaunchingFactoryBean extends AbstractEc2Ins
|
||||
|
||||
@Override
|
||||
protected final Object doCreateInstance(final String dnsName) throws Exception {
|
||||
Assert.hasText(userDn);
|
||||
LdapContextSource instance = new LdapContextSource();
|
||||
instance.setUrl("ldap://" + dnsName);
|
||||
instance.setUserDn(userDn);
|
||||
@@ -36,7 +57,7 @@ public class ContextSourceEc2InstanceLaunchingFactoryBean extends AbstractEc2Ins
|
||||
* @param dnsName The dns name of the created Ec2 instance.
|
||||
*/
|
||||
protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) {
|
||||
|
||||
//Nothing to do here
|
||||
}
|
||||
|
||||
public void setBase(String base) {
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2005-2008 the original author or authors.
|
||||
*
|
||||
* 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.springframework.ldap;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
@@ -6,6 +21,9 @@ import javax.net.ssl.SSLSession;
|
||||
import org.springframework.ldap.core.support.DefaultTlsDirContextAuthenticationStrategy;
|
||||
import org.springframework.ldap.core.support.LdapContextSource;
|
||||
|
||||
/**
|
||||
* FactoryBean for testing LDAP TLS connections on an Amazon EC2 image launched by superclass.
|
||||
*/
|
||||
public class TlsContextSourceEc2InstanceLaunchingFactoryBean extends ContextSourceEc2InstanceLaunchingFactoryBean {
|
||||
|
||||
protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<property name="awsSecretKey" value="${aws.secret.key}" />
|
||||
<property name="imageName" value="${aws.ami}" />
|
||||
<property name="groupName" value="${aws.security.group}" />
|
||||
<property name="keyName" value="${aws.keypair}" />
|
||||
<property name="keypairName" value="${aws.keypair}" />
|
||||
<property name="base" value="dc=jayway,dc=se" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<property name="awsSecretKey" value="${aws.secret.key}" />
|
||||
<property name="imageName" value="${aws.ami}" />
|
||||
<property name="groupName" value="${aws.security.group}" />
|
||||
<property name="keyName" value="${aws.keypair}" />
|
||||
<property name="keypairName" value="${aws.keypair}" />
|
||||
<property name="base" value="dc=jayway,dc=se" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
|
||||
Reference in New Issue
Block a user