Search in sources :

Example 1 with ApplicationGroup

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);
    }
}
Also used : ApplicationGroup(com.netflix.ice.reader.ApplicationGroup) AmazonSimpleEmailServiceClient(com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException)

Example 2 with ApplicationGroup

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();
}
Also used : ApplicationGroup(com.netflix.ice.reader.ApplicationGroup) JSONObject(org.json.JSONObject)

Example 3 with ApplicationGroup

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;
    }
}
Also used : ApplicationGroup(com.netflix.ice.reader.ApplicationGroup) JSONException(org.json.JSONException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 4 with ApplicationGroup

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();
    }
}
Also used : JSONTokener(org.json.JSONTokener) ApplicationGroup(com.netflix.ice.reader.ApplicationGroup) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JSONException(org.json.JSONException) JSONException(org.json.JSONException)

Example 5 with ApplicationGroup

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;
    }
}
Also used : ApplicationGroup(com.netflix.ice.reader.ApplicationGroup) ByteArrayInputStream(java.io.ByteArrayInputStream) JSONException(org.json.JSONException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ApplicationGroup (com.netflix.ice.reader.ApplicationGroup)7 JSONException (org.json.JSONException)3 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 MessagingException (javax.mail.MessagingException)2 JSONObject (org.json.JSONObject)2 AmazonSimpleEmailServiceClient (com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient)1 RawMessage (com.amazonaws.services.simpleemail.model.RawMessage)1 SendRawEmailRequest (com.amazonaws.services.simpleemail.model.SendRawEmailRequest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 BodyPart (javax.mail.BodyPart)1 Session (javax.mail.Session)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 DateTime (org.joda.time.DateTime)1 JSONTokener (org.json.JSONTokener)1