Skip to content
Browse files

Added keys property, AwsInjectable test.

  • Loading branch information...
1 parent 0b4243c commit 7c253ba03c122a1b5271134e73781be6c6ce21c6 @gorzell gorzell committed
View
2 NOTICE.txt
@@ -1,4 +1,4 @@
-Curator
+Servo
Copyright 2011 Netlix, Inc.
This product includes software developed by The Apache Software
View
0 servo-cloudwatch/doc/ec2Metadata.txt
No changes.
View
49 servo-cloudwatch/src/main/java/com/netflix/servo/aws/AwsInjectableTag.java
@@ -19,11 +19,17 @@
*/
package com.netflix.servo.aws;
+import com.amazonaws.AmazonClientException;
+import com.amazonaws.auth.PropertiesCredentials;
+import com.amazonaws.services.autoscaling.AmazonAutoScaling;
+import com.amazonaws.services.autoscaling.AmazonAutoScalingClient;
+import com.amazonaws.services.autoscaling.model.DescribeAutoScalingInstancesRequest;
import com.netflix.servo.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
+import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
@@ -34,7 +40,12 @@
*/
public enum AwsInjectableTag implements Tag {
AUTOSCALE_GROUP("autoScalingGroup", getAutoScaleGroup()),
- INSTANCE_ID("instanceId", getInstanceId());
+ INSTANCE_ID("instanceId", getInstanceId()),
+ EC2_ZONE("zone", getZone());
+
+ private static final String metaDataUrl = "http://169.254.169.254/latest/meta-data";
+ private static final String undefined = "undefined";
+ private static final Logger log = LoggerFactory.getLogger(AwsInjectableTag.class);
private final String key;
private final String value;
@@ -44,10 +55,6 @@ private AwsInjectableTag(String key, String val) {
this.value = val;
}
- private static final Logger log = LoggerFactory.getLogger(AwsInjectableTag.class);
-
- private static final String metaDataUrl = "http://169.254.169.254/latest/meta-data";
-
public String getKey() {
return key;
}
@@ -56,30 +63,44 @@ public String getValue() {
return value;
}
- private static String getAutoScaleGroup() {
- return "";
+ static String getAutoScaleGroup() {
+ try {
+ File credFile = new File(System.getProperties().getProperty(AwsPropertyKeys.awsCredentialsFile));
+ AmazonAutoScaling autoScalingClient = new AmazonAutoScalingClient(new PropertiesCredentials(credFile));
+
+ return autoScalingClient.describeAutoScalingInstances(
+ new DescribeAutoScalingInstancesRequest().withInstanceIds(getInstanceId()))
+ .getAutoScalingInstances().get(0).getAutoScalingGroupName();
+ } catch (Exception e) {
+ log.error("Unable to get ASG name.", e);
+ return undefined;
+ }
}
- private static String getInstanceId() {
+ static String getInstanceId() {
return getUrlValue("/instance-id");
}
- private static String getUrlValue(String path) {
+ static String getUrlValue(String path) {
try {
URL url = new URL(metaDataUrl + path);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
- String line = null;
+ String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
- while( ( line = reader.readLine() ) != null ) {
- stringBuilder.append( line );
- stringBuilder.append( ls );
+ while ((line = reader.readLine()) != null) {
+ stringBuilder.append(line);
+ stringBuilder.append(ls);
}
return stringBuilder.toString();
} catch (Exception e) {
log.warn("", e);
- return "uknown";
+ return undefined;
}
}
+
+ static String getZone(){
+ return undefined;
+ }
}
View
2 servo-cloudwatch/src/main/java/com/netflix/servo/aws/AwsPropertyKeys.java
@@ -23,5 +23,5 @@
*/
public class AwsPropertyKeys {
- public static final String
+ public static final String awsCredentialsFile = "com.netflix.servo.aws.credentialsFile";
}
View
16 servo-cloudwatch/src/test/java/com/netflix/servo/aws/AwsInjectableTagTest.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2012. Netflix, 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.netflix.servo.aws;
import org.testng.annotations.Test;

0 comments on commit 7c253ba

Please sign in to comment.
Something went wrong with that request. Please try again.