OW2 Consortium elastic-grid

Rev

Rev 425 | Rev 472 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 425 Rev 455
Line 16... Line 16...
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
17
 */
18

18

19
package com.elasticgrid.utils.amazon;
19
package com.elasticgrid.utils.amazon;
20

20

-
 
21
import org.jets3t.service.security.AWSCredentials;
-
 
22
import org.jets3t.service.S3Service;
-
 
23
import org.jets3t.service.S3ServiceException;
-
 
24
import org.jets3t.service.impl.rest.httpclient.RestS3Service;
21
import java.io.File;
25
import java.io.File;
22
import java.io.FileInputStream;
26
import java.io.FileInputStream;
23
import java.io.IOException;
27
import java.io.IOException;
24
import java.io.InputStream;
28
import java.io.InputStream;
25
import java.util.Properties;
29
import java.util.Properties;
26
import java.util.logging.Level;
30
import java.util.logging.Level;
27
import java.util.logging.Logger;
31
import java.util.logging.Logger;
28

32

29
public class AWSUtils {
33
public class AWSUtils {
-
 
34
    private static S3Service s3;
30
    private static final Logger logger = Logger.getLogger(AWSUtils.class.getName());
35
    private static final Logger logger = Logger.getLogger(AWSUtils.class.getName());
-
 
36

-
 
37
    static {
-
 
38
        try {
-
 
39
            Properties config = loadEC2Configuration();
-
 
40
            String awsAccessID = config.getProperty("aws.accessId");
-
 
41
            String awsSecretKey = config.getProperty("aws.secretKey");
-
 
42
            s3 = new RestS3Service(new AWSCredentials(awsAccessID, awsSecretKey));
-
 
43
        } catch (Exception e) {
-
 
44
            logger.log(Level.SEVERE, "Can't initialize S3 environment", e);
-
 
45
        }
-
 
46
    }
31

47

32
    public static boolean isEnvironmentProperlySet() {
48
    public static boolean isEnvironmentProperlySet() {
33
        return new File(System.getProperty("user.home") + File.separatorChar + ".eg", "eg.properties").exists()
49
        return new File(System.getProperty("user.home") + File.separatorChar + ".eg", "eg.properties").exists()
34
                || new File(System.getenv("EG_HOME") + File.separatorChar + "config", "eg.properties").exists();
50
                || new File(System.getenv("EG_HOME") + File.separatorChar + "config", "eg.properties").exists();
35
    }
51
    }
Line 75... Line 91...
75

91

76
        return awsProperties;
92
        return awsProperties;
77
    }
93
    }
78

94

79
    public static String getDropBucket() throws IOException {
95
    public static String getDropBucket() throws IOException {
80
        return (String) loadEC2Configuration().get("eg.s3.dropBucket");
-
 
-
 
96
        return (String) loadEC2Configuration().getProperty("eg.s3.dropBucket");
-
 
97
    }
-
 
98

-
 
99
    public static S3Service getS3Service() {
-
 
100
        return s3;
81
    }
101
    }
82
}
102
}