Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial version

  • Loading branch information...
commit 7324ed426d437e77647f78b683b9305f1d55e799 0 parents
@electrum authored
17 .gitignore
@@ -0,0 +1,17 @@
+*.iml
+*.ipr
+*.iws
+target/
+/var
+pom.xml.versionsBackup
+test-output/
+/atlassian-ide-plugin.xml
+.idea
+.DS_Store
+.classpath
+.settings
+.project
+temp-testng-customsuite.xml
+test-output
+.externalToolBuilders
+*~
1  README.txt
@@ -0,0 +1 @@
+Automatically update AWS Elastic Load Balancers (ELB) from Discovery
2  etc/config.properties
@@ -0,0 +1,2 @@
+node.environment=testing
+discovery.uri=http://localhost:8411
2  etc/log.properties
@@ -0,0 +1,2 @@
+com.proofpoint=DEBUG
+com.amazonaws.request=WARN
13 license-header.txt
@@ -0,0 +1,13 @@
+Copyright 2011 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.
165 pom.xml
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>rest-server-base</artifactId>
+ <version>0.46</version>
+ </parent>
+
+ <properties>
+ <main-class>com.proofpoint.discovery.elb.Main</main-class>
+ </properties>
+
+ <groupId>com.proofpoint.discovery</groupId>
+ <artifactId>elb</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.amazonaws</groupId>
+ <artifactId>aws-java-sdk</artifactId>
+ <version>1.2.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <version>1.3.9</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.weakref</groupId>
+ <artifactId>jmxutils</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.inject</groupId>
+ <artifactId>guice</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>bootstrap</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>configuration</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>discovery-experimental</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>log</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>http-server</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>jaxrs</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>json</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>jmx</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>node</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>units</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>experimental</artifactId>
+ </dependency>
+
+ <!-- for packaging -->
+ <dependency>
+ <groupId>com.proofpoint.platform</groupId>
+ <artifactId>launcher</artifactId>
+ <classifier>bin</classifier>
+ <type>tar.gz</type>
+ </dependency>
+
+ <!-- for testing -->
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <!--
+ Do a license check by running: mvn license:check
+ Update the license by running: mvn license:format
+ -->
+ <plugin>
+ <groupId>com.mycila.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <configuration>
+ <header>license-header.txt</header>
+ <strictCheck>true</strictCheck>
+ <mapping>
+ <java>SLASHSTAR_STYLE</java>
+ </mapping>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ <excludes>
+ <exclude>**/README.txt</exclude>
+ <exclude>**/config.properties</exclude>
+ <exclude>**/log.properties</exclude>
+ <exclude>**/logback-test.xml</exclude>
+ <exclude>**/.gitignore</exclude>
+ <exclude>var/**</exclude>
+ </excludes>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>test</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
116 src/main/java/com/proofpoint/discovery/elb/Ec2Location.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2011 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.discovery.elb;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Objects;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
+
+import javax.annotation.concurrent.Immutable;
+import java.util.List;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * EC2 Galaxy location: {@code ec2/region/zone/instance/slot}
+ */
+@Immutable
+@SuppressWarnings("UnusedDeclaration")
+public class Ec2Location
+{
+ private final String region;
+ private final String availabilityZone;
+ private final String instanceId;
+ private final String slot;
+
+ public Ec2Location(String region, String availabilityZone, String instanceId, String slot)
+ {
+ this.region = checkNotNull(region, "region is null");
+ this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone is null");
+ this.instanceId = checkNotNull(instanceId, "instanceId is null");
+ this.slot = checkNotNull(slot, "slot is null");
+ }
+
+ public String getRegion()
+ {
+ return region;
+ }
+
+ public String getAvailabilityZone()
+ {
+ return availabilityZone;
+ }
+
+ public String getInstanceId()
+ {
+ return instanceId;
+ }
+
+ public String getSlot()
+ {
+ return slot;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Ec2Location)) {
+ return false;
+ }
+ Ec2Location x = (Ec2Location) o;
+ return equal(region, x.region) &&
+ equal(availabilityZone, x.availabilityZone) &&
+ equal(instanceId, x.instanceId) &&
+ equal(slot, x.slot);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hashCode(region, availabilityZone, instanceId, slot);
+ }
+
+ @Override
+ public String toString()
+ {
+ return Joiner.on('/').join("ec2", region, availabilityZone, instanceId, slot);
+ }
+
+ /**
+ * Parse an EC2 location string into an {@link Ec2Location}.
+ *
+ * @param location the location string
+ * @return the parsed location
+ * @throws IllegalArgumentException if the location string is invalid
+ */
+ public static Ec2Location valueOf(String location)
+ throws IllegalArgumentException
+ {
+ List<String> parts = ImmutableList.copyOf(Splitter.on('/').split(location).iterator());
+ if (parts.size() != 5) {
+ throw new IllegalArgumentException("wrong number of parts");
+ }
+ if (!parts.get(0).equals("ec2")) {
+ throw new IllegalArgumentException("not an EC2 location");
+ }
+ return new Ec2Location(parts.get(1), parts.get(2), parts.get(3), parts.get(4));
+ }
+}
241 src/main/java/com/proofpoint/discovery/elb/ElasticLoadBalancerUpdater.java
@@ -0,0 +1,241 @@
+/*
+ * Copyright 2011 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.discovery.elb;
+
+import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancing;
+import com.amazonaws.services.elasticloadbalancing.model.DeregisterInstancesFromLoadBalancerRequest;
+import com.amazonaws.services.elasticloadbalancing.model.Instance;
+import com.amazonaws.services.elasticloadbalancing.model.Listener;
+import com.amazonaws.services.elasticloadbalancing.model.ListenerDescription;
+import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription;
+import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest;
+import com.google.common.base.Function;
+import com.google.common.base.Splitter;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import com.proofpoint.discovery.client.DiscoveryClient;
+import com.proofpoint.discovery.client.ServiceDescriptor;
+import com.proofpoint.discovery.client.ServiceDescriptors;
+import com.proofpoint.log.Logger;
+import com.proofpoint.node.NodeInfo;
+import com.proofpoint.units.Duration;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.concurrent.Immutable;
+import javax.inject.Inject;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.ImmutableList.copyOf;
+import static com.google.common.collect.Iterables.transform;
+import static com.google.common.collect.Sets.difference;
+import static com.google.common.collect.Sets.newHashSet;
+
+@Immutable
+public class ElasticLoadBalancerUpdater
+{
+ private static final Logger log = Logger.get(ElasticLoadBalancerUpdater.class);
+
+ private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(
+ new ThreadFactoryBuilder().setNameFormat("ElasticLoadBalancerUpdater-%s").build());
+
+ private final AmazonElasticLoadBalancing elbClient;
+ private final NodeInfo nodeInfo;
+ private final DiscoveryClient discoveryClient;
+ private final Duration updateInterval;
+
+ @Inject
+ public ElasticLoadBalancerUpdater(AmazonElasticLoadBalancing elbClient, NodeInfo nodeInfo, DiscoveryClient discoveryClient, ServerConfig config)
+ {
+ this.elbClient = checkNotNull(elbClient, "elbClient is null");
+ this.nodeInfo = checkNotNull(nodeInfo, "nodeInfo is null");
+ this.discoveryClient = checkNotNull(discoveryClient, "discoveryClient is null");
+ checkNotNull(config, "config is null");
+ updateInterval = config.getUpdateInterval();
+ }
+
+ @PostConstruct
+ public void start()
+ {
+ Runnable updater = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try {
+ update();
+ }
+ catch (Exception e) {
+ log.error(e, "update failed");
+ }
+ }
+ };
+ executor.scheduleAtFixedRate(updater, 0, (long) updateInterval.toMillis(), TimeUnit.MILLISECONDS);
+ }
+
+ @PreDestroy
+ public void destroy()
+ throws IOException
+ {
+ executor.shutdown();
+ }
+
+ public void update()
+ throws Exception
+ {
+ for (LoadBalancerDescription loadBalancer : elbClient.describeLoadBalancers().getLoadBalancerDescriptions()) {
+ // split ELB name into parts
+ String elbName = loadBalancer.getLoadBalancerName();
+ List<String> parts = copyOf(Splitter.on('-').split(elbName).iterator());
+ if (parts.size() != 3) {
+ log.debug("ignoring load balancer: %s", elbName);
+ continue;
+ }
+ String environment = parts.get(0);
+ String type = parts.get(1);
+ String pool = parts.get(2);
+ log.debug("found load balancer: %s", elbName);
+
+ // check against environment
+ if (!environment.equals(nodeInfo.getEnvironment())) {
+ continue;
+ }
+
+ // look for services in discovery
+ ServiceDescriptors services = discoveryClient.getServices(type, pool).get(1, TimeUnit.SECONDS);
+
+ // map services to instances
+ Set<String> instances = newHashSet();
+ for (ServiceDescriptor descriptor : services.getServiceDescriptors()) {
+ String instanceId = extractEc2InstanceId(descriptor.getLocation());
+ if (instanceId == null) {
+ log.warn("invalid EC2 location: %s", descriptor.getLocation());
+ continue;
+ }
+
+ // verify load balancer listeners against the service announcement
+ boolean valid = true;
+ for (Listener listener : transform(loadBalancer.getListenerDescriptions(), GET_LISTENER)) {
+ if (!serviceExistsForListener(listener, descriptor.getProperties())) {
+ valid = false;
+ log.warn("load balancer %s listener %s does not match service %s", elbName, listener, descriptor);
+ }
+ }
+ if (valid) {
+ instances.add(instanceId);
+ }
+ }
+
+ // get registered instances
+ Set<String> registeredInstances = newHashSet(transform(loadBalancer.getInstances(), GET_INSTANCE_ID));
+
+ // add new instances to load balancer
+ Collection<String> addInstances = difference(instances, registeredInstances);
+ if (!addInstances.isEmpty()) {
+ registerInstances(elbName, addInstances);
+ }
+
+ // remove missing instances from load balancer
+ Collection<String> removeInstances = difference(registeredInstances, instances);
+ if (!removeInstances.isEmpty()) {
+ deregisterInstances(elbName, removeInstances);
+ }
+ }
+ }
+
+ private static boolean serviceExistsForListener(Listener listener, Map<String, String> properties)
+ {
+ // TODO: use instanceProtocol when supported by AWS library
+ String protocol = listener.getProtocol().toLowerCase();
+ if ((!protocol.equals("http")) && (!protocol.equals("https"))) {
+ return false;
+ }
+ URI uri = extractUri(properties.get(protocol));
+ return (uri != null) && (uri.getPort() == listener.getInstancePort());
+ }
+
+ private void registerInstances(String elbName, Collection<String> instanceIds)
+ {
+ List<Instance> instances = copyOf(transform(instanceIds, NEW_INSTANCE));
+ log.debug("adding instances to load balancer: %s: %s", elbName, instanceIds);
+ elbClient.registerInstancesWithLoadBalancer(new RegisterInstancesWithLoadBalancerRequest(elbName, instances));
+ log.info("added instances to load balancer: %s: %s", elbName, instanceIds);
+ }
+
+ private void deregisterInstances(String elbName, Collection<String> instanceIds)
+ {
+ List<Instance> instances = copyOf(transform(instanceIds, NEW_INSTANCE));
+ log.debug("removing instances from load balancer: %s: %s", elbName, instanceIds);
+ elbClient.deregisterInstancesFromLoadBalancer(new DeregisterInstancesFromLoadBalancerRequest(elbName, instances));
+ log.info("removed instances from load balancer: %s: %s", elbName, instanceIds);
+ }
+
+ private static String extractEc2InstanceId(String location)
+ {
+ try {
+ return Ec2Location.valueOf(location).getInstanceId();
+ }
+ catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
+ private static URI extractUri(String uri)
+ {
+ try {
+ return new URI(uri);
+ }
+ catch (Exception e) {
+ return null;
+ }
+ }
+
+ private static Function<ListenerDescription, Listener> GET_LISTENER = new Function<ListenerDescription, Listener>()
+ {
+ @Override
+ public Listener apply(ListenerDescription input)
+ {
+ return input.getListener();
+ }
+ };
+
+ private static Function<Instance, String> GET_INSTANCE_ID = new Function<Instance, String>()
+ {
+ @Override
+ public String apply(Instance input)
+ {
+ return input.getInstanceId();
+ }
+ };
+
+ private static Function<String, Instance> NEW_INSTANCE = new Function<String, Instance>()
+ {
+
+ @Override
+ public Instance apply(String input)
+ {
+ return new Instance(input);
+ }
+ };
+}
49 src/main/java/com/proofpoint/discovery/elb/Main.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2011 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.discovery.elb;
+
+import com.google.inject.Injector;
+import com.proofpoint.bootstrap.Bootstrap;
+import com.proofpoint.discovery.client.Announcer;
+import com.proofpoint.discovery.client.DiscoveryModule;
+import com.proofpoint.experimental.jmx.JmxHttpModule;
+import com.proofpoint.http.server.HttpServerModule;
+import com.proofpoint.jaxrs.JaxrsModule;
+import com.proofpoint.jmx.JmxModule;
+import com.proofpoint.json.JsonModule;
+import com.proofpoint.node.NodeModule;
+import org.weakref.jmx.guice.MBeanModule;
+
+public class Main
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ Bootstrap app = new Bootstrap(
+ new NodeModule(),
+ new DiscoveryModule(),
+ new HttpServerModule(),
+ new JsonModule(),
+ new JaxrsModule(),
+ new MBeanModule(),
+ new JmxModule(),
+ new JmxHttpModule(),
+ new MainModule());
+
+ Injector injector = app.strictConfig().initialize();
+ injector.getInstance(Announcer.class).start();
+ }
+}
53 src/main/java/com/proofpoint/discovery/elb/MainModule.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2011 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.discovery.elb;
+
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancing;
+import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClient;
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.Provides;
+import com.google.inject.Scopes;
+
+import static com.proofpoint.configuration.ConfigurationModule.bindConfig;
+
+public class MainModule
+ implements Module
+{
+ public void configure(Binder binder)
+ {
+ binder.requireExplicitBindings();
+ binder.disableCircularProxies();
+
+ binder.bind(ElasticLoadBalancerUpdater.class).in(Scopes.SINGLETON);
+
+ bindConfig(binder).to(ServerConfig.class);
+ }
+
+ @Provides
+ private AmazonElasticLoadBalancing provideAmazonElasticLoadBalancing(AWSCredentials awsCredentials)
+ {
+ return new AmazonElasticLoadBalancingClient(awsCredentials);
+ }
+
+ @Provides
+ private AWSCredentials provideAwsCredentials(ServerConfig config)
+ {
+ return new BasicAWSCredentials(config.getAwsAccessKey(), config.getAwsSecretKey());
+ }
+}
74 src/main/java/com/proofpoint/discovery/elb/ServerConfig.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2011 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.discovery.elb;
+
+import com.proofpoint.configuration.Config;
+import com.proofpoint.configuration.ConfigDescription;
+import com.proofpoint.units.Duration;
+import com.proofpoint.units.MinDuration;
+
+import javax.validation.constraints.NotNull;
+import java.util.concurrent.TimeUnit;
+
+public class ServerConfig
+{
+ private Duration updateInterval = new Duration(30, TimeUnit.SECONDS);
+ private String awsAccessKey;
+ private String awsSecretKey;
+
+ @Config("elb.update-interval")
+ @ConfigDescription("time between updates")
+ public ServerConfig setUpdateInterval(Duration updateInterval)
+ {
+ this.updateInterval = updateInterval;
+ return this;
+ }
+
+ @NotNull
+ @MinDuration("1s")
+ public Duration getUpdateInterval()
+ {
+ return updateInterval;
+ }
+
+ @Config("elb.aws-access-key")
+ @ConfigDescription("AWS access key")
+ public ServerConfig setAwsAccessKey(String awsAccessKey)
+ {
+ this.awsAccessKey = awsAccessKey;
+ return this;
+ }
+
+ @NotNull
+ public String getAwsAccessKey()
+ {
+ return awsAccessKey;
+ }
+
+ @Config("elb.aws-secret-key")
+ @ConfigDescription("AWS secret key")
+ public ServerConfig setAwsSecretKey(String awsSecretKey)
+ {
+ this.awsSecretKey = awsSecretKey;
+ return this;
+ }
+
+ @NotNull
+ public String getAwsSecretKey()
+ {
+ return awsSecretKey;
+ }
+}
60 src/test/java/com/proofpoint/discovery/elb/TestServer.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2011 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.discovery.elb;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.proofpoint.configuration.ConfigurationFactory;
+import com.proofpoint.configuration.ConfigurationModule;
+import com.proofpoint.discovery.client.testing.TestingDiscoveryModule;
+import com.proofpoint.http.server.testing.TestingHttpServerModule;
+import com.proofpoint.jaxrs.JaxrsModule;
+import com.proofpoint.json.JsonModule;
+import com.proofpoint.node.testing.TestingNodeModule;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class TestServer
+{
+ @BeforeMethod
+ public void setup()
+ throws Exception
+ {
+ ImmutableMap<String, String> config = ImmutableMap.<String, String>builder()
+ .put("elb.aws-access-key", "fake-aws-access-key")
+ .put("elb.aws-secret-key", "fake-aws-secret-key")
+ .build();
+
+ Injector injector = Guice.createInjector(
+ new TestingNodeModule(),
+ new TestingDiscoveryModule(),
+ new TestingHttpServerModule(),
+ new JsonModule(),
+ new JaxrsModule(),
+ new MainModule(),
+ new ConfigurationModule(new ConfigurationFactory(config)));
+
+ injector.getInstance(ElasticLoadBalancerUpdater.class);
+ }
+
+ @Test
+ public void testSuccess()
+ {
+ Assert.assertTrue(true);
+ }
+}
54 src/test/java/com/proofpoint/discovery/elb/TestServerConfig.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2011 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.discovery.elb;
+
+import com.google.common.collect.ImmutableMap;
+import com.proofpoint.configuration.testing.ConfigAssertions;
+import com.proofpoint.units.Duration;
+import org.testng.annotations.Test;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public class TestServerConfig
+{
+ @Test
+ public void testDefaults()
+ {
+ ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(ServerConfig.class)
+ .setUpdateInterval(new Duration(30, TimeUnit.SECONDS))
+ .setAwsAccessKey(null)
+ .setAwsSecretKey(null)
+ );
+ }
+
+ @Test
+ public void testExplicitPropertyMappings()
+ {
+ Map<String, String> properties = new ImmutableMap.Builder<String, String>()
+ .put("elb.update-interval", "2s")
+ .put("elb.aws-access-key", "my-access-key")
+ .put("elb.aws-secret-key", "my-secret-key")
+ .build();
+
+ ServerConfig expected = new ServerConfig()
+ .setUpdateInterval(new Duration(2, TimeUnit.SECONDS))
+ .setAwsAccessKey("my-access-key")
+ .setAwsSecretKey("my-secret-key");
+
+ ConfigAssertions.assertFullMapping(properties, expected);
+ }
+}
11 src/test/resources/logback-test.xml
@@ -0,0 +1,11 @@
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT"/>
+ </root>
+</configuration>
Please sign in to comment.
Something went wrong with that request. Please try again.