use of com.netflix.ice.reader.ApplicationGroup in project ice by Netflix.
the class BasicWeeklyCostEmailService method trigger.
public synchronized void trigger(boolean test) {
try {
headerNote = getHeaderNote();
throughputMetrics = getThroughputMetrics();
AmazonSimpleEmailServiceClient emailService = AwsUtils.getAmazonSimpleEmailServiceClient();
Map<String, ApplicationGroup> appgroups = applicationGroupService.getApplicationGroups();
Map<String, List<ApplicationGroup>> appgroupsByEmail = collectEmails(appgroups);
for (String email : appgroupsByEmail.keySet()) {
try {
if (!StringUtils.isEmpty(email))
sendEmail(test, emailService, email, appgroupsByEmail.get(email));
} catch (Exception e) {
logger.error("error in sending email to " + email, e);
}
}
} catch (Exception e) {
logger.error("error sending cost emails", e);
}
}
use of com.netflix.ice.reader.ApplicationGroup in project ice by Netflix.
the class BasicS3ApplicationGroupService method getJson.
private String getJson(Map<String, ApplicationGroup> appgroups) throws JSONException {
JSONObject json = new JSONObject();
for (String name : appgroups.keySet()) {
ApplicationGroup appgroup = appgroups.get(name);
json.put(name, appgroup.getJSON());
}
return json.toString();
}
use of com.netflix.ice.reader.ApplicationGroup in project ice by Netflix.
the class BasicS3ApplicationGroupService method saveApplicationGroup.
public boolean saveApplicationGroup(ApplicationGroup appgroup) {
Map<String, ApplicationGroup> appgroups = getApplicationGroups();
appgroups.put(appgroup.name, appgroup);
try {
String json = getJson(appgroups);
s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups", IOUtils.toInputStream(json), new ObjectMetadata());
s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "copy_appgroups", IOUtils.toInputStream(json), new ObjectMetadata());
BasicS3ApplicationGroupService.logger.info("saved appgroup " + appgroup);
return true;
} catch (JSONException e) {
logger.error("Error saving appgroup " + appgroup, e);
return false;
}
}
use of com.netflix.ice.reader.ApplicationGroup in project ice by Netflix.
the class BasicS3ApplicationGroupService method getApplicationGroups.
public Map<String, ApplicationGroup> getApplicationGroups() {
String jsonStr;
try {
InputStream in = s3Client.getObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups").getObjectContent();
jsonStr = IOUtils.toString(in);
in.close();
} catch (Exception e) {
logger.error("Error reading from appgroups file", e);
try {
InputStream in = s3Client.getObject(config.workS3BucketName, config.workS3BucketPrefix + "copy_appgroups").getObjectContent();
jsonStr = IOUtils.toString(in);
in.close();
} catch (Exception r) {
logger.error("Error reading from copy_appgroups file", r);
return Maps.newHashMap();
}
}
try {
JSONObject json = new JSONObject(new JSONTokener(jsonStr));
Map<String, ApplicationGroup> appgroups = Maps.newHashMap();
Iterator<String> keys = json.keys();
while (keys.hasNext()) {
String key = keys.next();
String str = json.getString(key);
appgroups.put(key, new ApplicationGroup(str));
}
return appgroups;
} catch (JSONException e) {
logger.error("Error reading appgroups from json...", e);
return Maps.newHashMap();
}
}
use of com.netflix.ice.reader.ApplicationGroup in project ice by Netflix.
the class BasicS3ApplicationGroupService method deleteApplicationGroup.
public boolean deleteApplicationGroup(String name) {
Map<String, ApplicationGroup> appgroups = getApplicationGroups();
ApplicationGroup appgroup = appgroups.remove(name);
try {
String json = getJson(appgroups);
s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups", new ByteArrayInputStream(json.getBytes()), new ObjectMetadata());
BasicS3ApplicationGroupService.logger.info("delete appgroup " + name + " " + appgroup);
return true;
} catch (JSONException e) {
logger.error("Error deleting appgroup " + appgroup, e);
return false;
}
}
Aggregations