| 55 |
jeje |
1 |
/**
|
| 182 |
jeje |
2 |
* Elastic Grid
|
| 2 |
jeje |
3 |
* Copyright (C) 2007-2008 Elastic Grid, LLC.
|
|
|
4 |
*
|
| 182 |
jeje |
5 |
* This program is free software: you can redistribute it and/or modify
|
|
|
6 |
* it under the terms of the GNU Affero General Public License as
|
| 55 |
jeje |
7 |
* published by the Free Software Foundation, either version 3 of the
|
| 182 |
jeje |
8 |
* License, or (at your option) any later version.
|
| 2 |
jeje |
9 |
*
|
| 182 |
jeje |
10 |
* This program is distributed in the hope that it will be useful,
|
| 55 |
jeje |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 182 |
jeje |
13 |
* GNU Affero General Public License for more details.
|
| 55 |
jeje |
14 |
*
|
| 182 |
jeje |
15 |
* You should have received a copy of the GNU Affero General Public License
|
|
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 55 |
jeje |
17 |
*/
|
|
|
18 |
|
| 2 |
jeje |
19 |
package com.elasticgrid;
|
|
|
20 |
|
|
|
21 |
import com.xerox.amazonws.ec2.EC2Exception;
|
|
|
22 |
import com.xerox.amazonws.ec2.ImageDescription;
|
|
|
23 |
import com.xerox.amazonws.ec2.Jec2;
|
|
|
24 |
import org.testng.annotations.BeforeClass;
|
|
|
25 |
import org.testng.annotations.Test;
|
| 43 |
jeje |
26 |
import java.io.File;
|
|
|
27 |
import java.io.FileInputStream;
|
|
|
28 |
import java.io.IOException;
|
|
|
29 |
import java.io.InputStream;
|
| 2 |
jeje |
30 |
import java.util.Arrays;
|
|
|
31 |
import java.util.List;
|
|
|
32 |
import java.util.Properties;
|
|
|
33 |
|
|
|
34 |
public class EC2Test {
|
|
|
35 |
private Jec2 ec2;
|
|
|
36 |
|
|
|
37 |
@Test
|
|
|
38 |
public void testDescribeImages() throws EC2Exception {
|
|
|
39 |
List<ImageDescription> imagesDescriptions = ec2.describeImages(Arrays.asList("ami-999174f0"));
|
|
|
40 |
assert imagesDescriptions != null;
|
|
|
41 |
assert imagesDescriptions.size() == 1;
|
|
|
42 |
ImageDescription description = imagesDescriptions.get(0);
|
|
|
43 |
assert description != null;
|
|
|
44 |
System.out.printf("Description: %s %s %s %s\n",
|
|
|
45 |
description.getImageLocation(),
|
|
|
46 |
description.getImageOwnerId(),
|
|
|
47 |
description.getImageState(),
|
|
|
48 |
description.getProductCodes()
|
|
|
49 |
);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
@Test
|
|
|
53 |
public void testDescribeImagesByOwner() throws EC2Exception {
|
|
|
54 |
List<ImageDescription> imagesDescriptions = ec2.describeImagesByOwner(Arrays.asList("amazon"));
|
|
|
55 |
assert imagesDescriptions != null;
|
|
|
56 |
assert imagesDescriptions.size() > 1;
|
|
|
57 |
for (ImageDescription description : imagesDescriptions) {
|
|
|
58 |
assert description != null;
|
|
|
59 |
System.out.printf("Description: %s %s %s %s\n",
|
|
|
60 |
description.getImageLocation(),
|
|
|
61 |
description.getImageOwnerId(),
|
|
|
62 |
description.getImageState(),
|
|
|
63 |
description.getProductCodes()
|
|
|
64 |
);
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
@BeforeClass
|
|
|
69 |
public void setupEC2() throws IOException {
|
|
|
70 |
String userHome = System.getProperty("user.home");
|
|
|
71 |
File egUserDirectory = new File(userHome, ".eg");
|
|
|
72 |
assert egUserDirectory.exists() : "The '$HOME/.eg' directory does not exists!";
|
|
|
73 |
assert egUserDirectory.isDirectory() : "'$HOME/.eg' is not a directory!";
|
|
|
74 |
Properties props = new Properties();
|
|
|
75 |
InputStream propsStream = new FileInputStream(new File(egUserDirectory, "aws.properties"));
|
|
|
76 |
try {
|
|
|
77 |
props.load(propsStream);
|
|
|
78 |
String accessId = (String) props.get("aws.accessId");
|
|
|
79 |
assert accessId != null : "Empty AWS access ID!";
|
|
|
80 |
String secretKey = (String) props.get("aws.secretKey");
|
|
|
81 |
assert secretKey != null : "Empty AWS secret key!";
|
|
|
82 |
ec2 = new Jec2(accessId, secretKey);
|
|
|
83 |
} finally {
|
|
|
84 |
propsStream.close();
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
/*
|
|
|
89 |
@BeforeClass
|
|
|
90 |
public void setupEC2() throws Exception {
|
|
|
91 |
service = new QueueServiceJSB();
|
|
|
92 |
ServiceBeanContext context = new FakeServiceBeanContext();
|
|
|
93 |
((QueueServiceJSB) service).setServiceBeanContext(context);
|
|
|
94 |
((QueueServiceJSB) service).createProxy(service);
|
|
|
95 |
((QueueServiceJSB) service).postInitialize();
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
class FakeServiceBeanContext implements ServiceBeanContext {
|
|
|
99 |
public Configuration getConfiguration() throws ConfigurationException {
|
|
|
100 |
return new AbstractConfiguration() {
|
|
|
101 |
protected Object getEntryInternal(String component, String name, Class type, Object data) throws ConfigurationException {
|
|
|
102 |
if ("awsAccessKeyId".equals(name))
|
|
|
103 |
return "0ZFE2GWP55PY92GD0A02";
|
|
|
104 |
else if ("awsSecretKey".equals(name))
|
|
|
105 |
return "Xj3hJngb3nJD5c3ti/O1MqW/A2v5gnd9ST6rns4h";
|
|
|
106 |
else if ("secured".equals(name))
|
|
|
107 |
return false;
|
|
|
108 |
else
|
|
|
109 |
return null;
|
|
|
110 |
}
|
|
|
111 |
};
|
|
|
112 |
}
|
|
|
113 |
public String getExportCodebase() { return null; }
|
|
|
114 |
public ServiceBeanManager getServiceBeanManager() { return null; }
|
|
|
115 |
public ComputeResourceManager getComputeResourceManager() { return null; }
|
|
|
116 |
public Object getInitParameter(String s) { return null; }
|
|
|
117 |
public Iterator<String> getInitParameterNames() { return null; }
|
|
|
118 |
public ServiceElement getServiceElement() { return null; }
|
|
|
119 |
public ServiceBeanConfig getServiceBeanConfig() { return null; }
|
|
|
120 |
public DiscoveryManagement getDiscoveryManagement() throws IOException { return null; }
|
|
|
121 |
public ComponentLoader getComponentLoader() { return null; }
|
|
|
122 |
public AssociationManagement getAssociationManagement() { return null; }
|
|
|
123 |
public WatchRegistry getWatchRegistry() { return null; }
|
|
|
124 |
}
|
|
|
125 |
*/
|
|
|
126 |
}
|