Skip to content

Commit

Permalink
Parse services with '/'. Fixes #100
Browse files Browse the repository at this point in the history
  • Loading branch information
AMeng committed Aug 25, 2015
1 parent 5c76154 commit 0c21b05
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/java/com/netflix/ice/basic/BasicDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ReadOnlyData load(DateTime monthDate) throws Exception {
public BasicDataManager(Product product, ConsolidateType consolidateType, boolean isCost) {
this.product = product;
this.consolidateType = consolidateType;
this.dbName = (isCost ? "cost_" : "usage_") + consolidateType + "_" + (product == null ? "all" : product.name);
this.dbName = (isCost ? "cost_" : "usage_") + consolidateType + "_" + (product == null ? "all" : product.s3Name);

start(300);
}
Expand Down
2 changes: 2 additions & 0 deletions src/java/com/netflix/ice/basic/BasicManagers.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.netflix.ice.processor.TagGroupWriter;
import com.netflix.ice.reader.*;
import com.netflix.ice.tag.Product;
import com.netflix.ice.tag.Tag;

import java.util.Collection;
import java.util.Map;
Expand Down Expand Up @@ -99,6 +100,7 @@ private void doWork() {
}
else {
String name = key.substring((config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX).length());
name = Tag.fromS3(name);
product = config.productService.getProductByName(name);
}
if (!products.contains(product)) {
Expand Down
2 changes: 1 addition & 1 deletion src/java/com/netflix/ice/basic/BasicTagGroupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class BasicTagGroupManager extends Poller implements TagGroupManager {
private Interval totalInterval;

BasicTagGroupManager(Product product) {
this.dbName = TagGroupWriter.DB_PREFIX + (product == null ? "all" : product.name);
this.dbName = TagGroupWriter.DB_PREFIX + (product == null ? "all" : product.s3Name);
file = new File(config.localDir, dbName);
try {
poll();
Expand Down
5 changes: 2 additions & 3 deletions src/java/com/netflix/ice/processor/BillingFileProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private void archive() throws Exception {
private void archiveHourly(Map<Product, ReadWriteData> dataMap, String prefix) throws Exception {
DateTime monthDateTime = new DateTime(startMilli, DateTimeZone.UTC);
for (Product product: dataMap.keySet()) {
String prodName = product == null ? "all" : product.name;
String prodName = product == null ? "all" : product.s3Name;
DataWriter writer = new DataWriter(prefix + "hourly_" + prodName + "_" + AwsUtils.monthDateFormat.print(monthDateTime), false);
writer.archive(dataMap.get(product));
}
Expand All @@ -447,7 +447,7 @@ private void archiveSummary(Map<Product, ReadWriteData> dataMap, String prefix)

for (Product product: dataMap.keySet()) {

String prodName = product == null ? "all" : product.name;
String prodName = product == null ? "all" : product.s3Name;
ReadWriteData data = dataMap.get(product);
Collection<TagGroup> tagGroups = data.getTagGroups();

Expand Down Expand Up @@ -755,4 +755,3 @@ private class BillingFile {
}
}
}

3 changes: 2 additions & 1 deletion src/java/com/netflix/ice/processor/DataWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.netflix.ice.common.AwsUtils;
import com.netflix.ice.common.TagGroup;
import com.netflix.ice.tag.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,6 +39,7 @@ public class DataWriter {

DataWriter(String name, boolean loadData) throws Exception {

name = Tag.toS3(name);
dbName = name;
file = new File(config.localDir, dbName);
if (loadData) {
Expand Down Expand Up @@ -81,4 +83,3 @@ void archive(ReadWriteData data) throws IOException {
logger.info(this.dbName + " uploading done.");
}
}

3 changes: 2 additions & 1 deletion src/java/com/netflix/ice/processor/TagGroupWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.Maps;
import com.netflix.ice.common.AwsUtils;
import com.netflix.ice.common.TagGroup;
import com.netflix.ice.tag.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,6 +39,7 @@ public class TagGroupWriter {

TagGroupWriter(String name) throws Exception {

name = Tag.toS3(name);
dbName = DB_PREFIX + name;
file = new File(config.localDir, dbName);
logger.info("creating TagGroupWriter for " + file);
Expand Down Expand Up @@ -74,4 +76,3 @@ void archive(Long monthMilli,Collection<TagGroup> tagGroups) throws IOException
logger.info(dbName + " uploading done.");
}
}

18 changes: 18 additions & 0 deletions src/java/com/netflix/ice/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public int compareTo(Tag t) {
};

public final String name;
public final String s3Name;
Tag(String name) {
this.name = name;
this.s3Name = Tag.toS3(name);
}

@Override
Expand All @@ -40,6 +42,22 @@ public boolean equals(Object o) {
return false;
}

/**
* Normalize a tagname suitable to be an S3 Filename
*/
public static String toS3(String name) {
name = name.replaceAll("/","--");
return name;
}

/**
* Normalize a tagname from an S3 Filename
*/
public static String fromS3(String name) {
name = name.replaceAll("--","/");
return name;
}

@Override
public String toString() {
return this.name;
Expand Down

0 comments on commit 0c21b05

Please sign in to comment.