这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/com/netflix/simianarmy/EventType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright 2013 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.simianarmy;

/**
* Marker interface for all event type enumerations.
*/
public interface EventType extends NamedType {

}
25 changes: 25 additions & 0 deletions src/main/java/com/netflix/simianarmy/GroupType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright 2013 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.simianarmy;

/**
* Marker interface for all group type enumerations.
*/
public interface GroupType extends NamedType {

}
2 changes: 1 addition & 1 deletion src/main/java/com/netflix/simianarmy/Monkey.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Monkey(Context ctx) {
*
* @return the monkey type enum
*/
public abstract Enum type();
public abstract MonkeyType type();

/**
* Do monkey business.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/netflix/simianarmy/MonkeyRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public interface Event {
*
* @return the monkey type enum
*/
Enum monkeyType();
MonkeyType monkeyType();

/**
* Event type.
*
* @return the event type enum
*/
Enum eventType();
EventType eventType();

/**
* Region.
Expand Down Expand Up @@ -108,7 +108,7 @@ public interface Event {
* the id
* @return the event
*/
Event newEvent(Enum monkeyType, Enum eventType, String region, String id);
Event newEvent(MonkeyType monkeyType, EventType eventType, String region, String id);

/**
* Record event.
Expand Down Expand Up @@ -140,7 +140,7 @@ public interface Event {
* the after
* @return the list of events
*/
List<Event> findEvents(Enum monkeyType, Map<String, String> query, Date after);
List<Event> findEvents(MonkeyType monkeyType, Map<String, String> query, Date after);

/**
* Find events.
Expand All @@ -155,5 +155,5 @@ public interface Event {
* the after
* @return the list
*/
List<Event> findEvents(Enum monkeyType, Enum eventType, Map<String, String> query, Date after);
List<Event> findEvents(MonkeyType monkeyType, EventType eventType, Map<String, String> query, Date after);
}
25 changes: 25 additions & 0 deletions src/main/java/com/netflix/simianarmy/MonkeyType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright 2013 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.simianarmy;

/**
* Marker interface for all monkey type enumerations.
*/
public interface MonkeyType extends NamedType {

}
30 changes: 30 additions & 0 deletions src/main/java/com/netflix/simianarmy/NamedType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
*
* Copyright 2013 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.simianarmy;

/**
* Interface requiring a name() method.
*/
public interface NamedType {

/**
* Name of this instance.
*/
String name();

}
6 changes: 3 additions & 3 deletions src/main/java/com/netflix/simianarmy/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ public enum CleanupState {
*
* @return the resource type enum
*/
Enum getResourceType();
ResourceType getResourceType();

/**
* Sets the resource type.
*
* @param type the resource type enum
*/
void setResourceType(Enum type);
void setResourceType(ResourceType type);

/**
* Sets the resource type and returns the resource.
*
* @param type resource type enum
* @return the resource object
*/
Resource withResourceType(Enum type);
Resource withResourceType(ResourceType type);

/**
* Gets the region the resource is in.
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/netflix/simianarmy/ResourceType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright 2013 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.simianarmy;

/**
* Marker interface for all resource type enumerations.
*/
public interface ResourceType extends NamedType {

}
20 changes: 15 additions & 5 deletions src/main/java/com/netflix/simianarmy/aws/AWSResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.netflix.simianarmy.NamedType;
import com.netflix.simianarmy.Resource;
import com.netflix.simianarmy.ResourceType;

/**
* The class represents general AWS resources that are managed by janitor monkey.
*/
public class AWSResource implements Resource {
private String id;
private Enum resourceType;
private ResourceType resourceType;
private String region;
private String ownerEmail;
private String description;
Expand Down Expand Up @@ -189,19 +191,19 @@ public Resource withId(String resourceId) {

/** {@inheritDoc} */
@Override
public Enum getResourceType() {
public ResourceType getResourceType() {
return resourceType;
}

/** {@inheritDoc} */
@Override
public void setResourceType(Enum resourceType) {
public void setResourceType(ResourceType resourceType) {
this.resourceType = resourceType;
}

/** {@inheritDoc} */
@Override
public Resource withResourceType(Enum type) {
public Resource withResourceType(ResourceType type) {
setResourceType(type);
return this;
}
Expand Down Expand Up @@ -430,7 +432,15 @@ private static void putToMapIfNotNull(Map<String, String> map, String key, Strin
}
}

private static void putToMapIfNotNull(Map<String, String> map, String key, Enum value) {
private static void putToMapIfNotNull(Map<String, String> map, String key, Enum<?> value) {
Validate.notNull(map);
Validate.notNull(key);
if (value != null) {
map.put(key, value.name());
}
}

private static void putToMapIfNotNull(Map<String, String> map, String key, NamedType value) {
Validate.notNull(map);
Validate.notNull(key);
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

package com.netflix.simianarmy.aws;

import com.netflix.simianarmy.ResourceType;

/**
* The enum of resource types of AWS.
*/
public enum AWSResourceType {
public enum AWSResourceType implements ResourceType {
/** AWS instance. */
INSTANCE,
/** AWS EBS volume. */
Expand Down
36 changes: 23 additions & 13 deletions src/main/java/com/netflix/simianarmy/aws/SimpleDBRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
import com.amazonaws.services.simpledb.model.ReplaceableAttribute;
import com.amazonaws.services.simpledb.model.SelectRequest;
import com.amazonaws.services.simpledb.model.SelectResult;
import com.netflix.simianarmy.EventType;
import com.netflix.simianarmy.MonkeyRecorder;
import com.netflix.simianarmy.MonkeyType;
import com.netflix.simianarmy.NamedType;
import com.netflix.simianarmy.basic.BasicRecorderEvent;
import com.netflix.simianarmy.client.aws.AWSClient;

Expand Down Expand Up @@ -120,7 +123,7 @@ protected AmazonSimpleDB sdbClient() {
* the e
* @return the string
*/
private static String enumToValue(Enum e) {
private static String enumToValue(NamedType e) {
return String.format("%s|%s", e.name(), e.getClass().getName());
}

Expand All @@ -131,30 +134,37 @@ private static String enumToValue(Enum e) {
* the value
* @return the enum
*/
@SuppressWarnings("unchecked")
private static Enum valueToEnum(String value) {
private static <T extends NamedType> T valueToEnum(
Class<T> type, String value) {
// parts = [enum value, enum class type]
String[] parts = value.split("\\|", 2);
if (parts.length < 2) {
throw new RuntimeException("value " + value + " does not appear to be an internal enum format");
}

Class enumClass;
Class<?> enumClass;
try {
enumClass = Class.forName(parts[1]);
} catch (ClassNotFoundException e) {
throw new RuntimeException("class for enum value " + value + " not found");
}
if (enumClass.isEnum()) {
final Class<? extends Enum> enumSubClass = enumClass.asSubclass(Enum.class);
return Enum.valueOf(enumSubClass, parts[0]);
if (!enumClass.isEnum()) {
throw new RuntimeException("value " + value + " does not appear to be of an enum type");
}
throw new RuntimeException("value " + value + " does not appear to be an enum type");
if (!type.isAssignableFrom(enumClass)) {
throw new RuntimeException("value " + value + " cannot be assigned to a variable of this type: "
+ type.getCanonicalName());
}
@SuppressWarnings("rawtypes")
Class<? extends Enum> enumType = enumClass.asSubclass(Enum.class);
@SuppressWarnings("unchecked")
T enumValue = (T) Enum.valueOf(enumType, parts[0]);
return enumValue;
}

/** {@inheritDoc} */
@Override
public Event newEvent(Enum monkeyType, Enum eventType, String reg, String id) {
public Event newEvent(MonkeyType monkeyType, EventType eventType, String reg, String id) {
return new BasicRecorderEvent(monkeyType, eventType, reg, id);
}

Expand Down Expand Up @@ -220,8 +230,8 @@ protected List<Event> findEvents(Map<String, String> queryMap, long after) {
}
String eid = res.get(Keys.id.name());
String ereg = res.get(Keys.region.name());
Enum monkeyType = valueToEnum(res.get(Keys.monkeyType.name()));
Enum eventType = valueToEnum(res.get(Keys.eventType.name()));
MonkeyType monkeyType = valueToEnum(MonkeyType.class, res.get(Keys.monkeyType.name()));
EventType eventType = valueToEnum(EventType.class, res.get(Keys.eventType.name()));
long eventTime = Long.parseLong(res.get(Keys.eventTime.name()));
list.add(new BasicRecorderEvent(monkeyType, eventType, ereg, eid, eventTime).addFields(fields));
}
Expand All @@ -237,15 +247,15 @@ public List<Event> findEvents(Map<String, String> query, Date after) {

/** {@inheritDoc} */
@Override
public List<Event> findEvents(Enum monkeyType, Map<String, String> query, Date after) {
public List<Event> findEvents(MonkeyType monkeyType, Map<String, String> query, Date after) {
Map<String, String> copy = new LinkedHashMap<String, String>(query);
copy.put(Keys.monkeyType.name(), enumToValue(monkeyType));
return findEvents(copy, after);
}

/** {@inheritDoc} */
@Override
public List<Event> findEvents(Enum monkeyType, Enum eventType, Map<String, String> query, Date after) {
public List<Event> findEvents(MonkeyType monkeyType, EventType eventType, Map<String, String> query, Date after) {
Map<String, String> copy = new LinkedHashMap<String, String>(query);
copy.put(Keys.monkeyType.name(), enumToValue(monkeyType));
copy.put(Keys.eventType.name(), enumToValue(eventType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.amazonaws.services.simpledb.model.SelectResult;
import com.netflix.simianarmy.Resource;
import com.netflix.simianarmy.Resource.CleanupState;
import com.netflix.simianarmy.ResourceType;
import com.netflix.simianarmy.aws.AWSResource;
import com.netflix.simianarmy.client.aws.AWSClient;
import com.netflix.simianarmy.janitor.JanitorResourceTracker;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void addOrUpdate(Resource resource) {
* the SimpleDB.
*/
@Override
public List<Resource> getResources(Enum resourceType, CleanupState state, String resourceRegion) {
public List<Resource> getResources(ResourceType resourceType, CleanupState state, String resourceRegion) {
Validate.notEmpty(resourceRegion);
List<Resource> resources = new ArrayList<Resource>();
StringBuilder query = new StringBuilder();
Expand Down
Loading