Add Snapshot View and DescribeSnapshots.
@@ -92,6 +92,8 @@ | ||
92 | 92 | import com.amazonaws.ec2.model.DescribeKeyPairsResponse; |
93 | 93 | import com.amazonaws.ec2.model.DescribeSecurityGroupsRequest; |
94 | 94 | import com.amazonaws.ec2.model.DescribeSecurityGroupsResponse; |
95 | +import com.amazonaws.ec2.model.DescribeSnapshotsRequest; | |
96 | +import com.amazonaws.ec2.model.DescribeSnapshotsResponse; | |
95 | 97 | import com.amazonaws.ec2.model.DescribeVolumesRequest; |
96 | 98 | import com.amazonaws.ec2.model.DescribeVolumesResponse; |
97 | 99 | import com.amazonaws.ec2.model.DisassociateAddressRequest; |
@@ -105,6 +107,7 @@ | ||
105 | 107 | import com.amazonaws.ec2.model.RunInstancesRequest; |
106 | 108 | import com.amazonaws.ec2.model.RunningInstance; |
107 | 109 | import com.amazonaws.ec2.model.SecurityGroup; |
110 | +import com.amazonaws.ec2.model.Snapshot; | |
108 | 111 | import com.amazonaws.ec2.model.TerminateInstancesRequest; |
109 | 112 | import com.amazonaws.ec2.model.UserIdGroupPair; |
110 | 113 | import com.amazonaws.ec2.model.Volume; |
@@ -480,10 +483,39 @@ | ||
480 | 483 | |
481 | 484 | @Override |
482 | 485 | public List<EC2Snapshot> describeSnapshot(EC2DescribeSnapshotRequest request) { |
483 | - // TODO Auto-generated method stub | |
484 | - return null; | |
486 | + DescribeSnapshotsRequest req = new DescribeSnapshotsRequest(); | |
487 | + req.setOwner(request.getOwner()); | |
488 | + req.setRestorableBy(request.getRestoableBy()); | |
489 | + req.setSnapshotId(request.getSnapshotId()); | |
490 | + List<EC2Snapshot> ret = null; | |
491 | + try { | |
492 | + DescribeSnapshotsResponse response = client.describeSnapshots(req); | |
493 | + ret = createSnapshotList(response.getDescribeSnapshotsResult().getSnapshot()); | |
494 | + } catch (AmazonEC2Exception e) { | |
495 | + // TODO handle exception. | |
496 | + e.printStackTrace(); | |
497 | + } | |
498 | + return ret; | |
485 | 499 | } |
486 | 500 | |
501 | + private List<EC2Snapshot> createSnapshotList(List<Snapshot> snapshots) { | |
502 | + List<EC2Snapshot> ret = new ArrayList<EC2Snapshot>(); | |
503 | + for (Snapshot s : snapshots) { | |
504 | + EC2Snapshot snap = new EC2Snapshot(); | |
505 | + snap.setDescription(s.getDescription()); | |
506 | + snap.setOwnerAlias(s.getOwnerAlias()); | |
507 | + snap.setOwnerId(s.getOwnerId()); | |
508 | + snap.setProgress(s.getProgress()); | |
509 | + snap.setSnapshotId(s.getSnapshotId()); | |
510 | + snap.setStartTime(s.getStartTime()); | |
511 | + snap.setStatus(s.getStatus()); | |
512 | + snap.setVolumeId(s.getVolumeId()); | |
513 | + snap.setVolumeSize(s.getVolumeSize()); | |
514 | + ret.add(snap); | |
515 | + } | |
516 | + return ret; | |
517 | + } | |
518 | + | |
487 | 519 | @Override |
488 | 520 | public List<EC2Volume> describeVolumes(EC2DescribeVolumesRequest request) { |
489 | 521 | DescribeVolumesRequest req = new DescribeVolumesRequest(); |
@@ -497,7 +529,7 @@ | ||
497 | 529 | } |
498 | 530 | return ret; |
499 | 531 | } |
500 | - | |
532 | + | |
501 | 533 | private List<EC2Volume> createEC2VolumeList(DescribeVolumesResponse response) { |
502 | 534 | List<EC2Volume> ret = new ArrayList<EC2Volume>(); |
503 | 535 | for (Volume volume : response.getDescribeVolumesResult().getVolume()) { |
@@ -0,0 +1,62 @@ | ||
1 | +/** | |
2 | + * | |
3 | + */ | |
4 | +package jp.co.intellilink.aws.ui.model; | |
5 | + | |
6 | +/** | |
7 | + * @author tanacasino | |
8 | + * | |
9 | + */ | |
10 | +public class SnapshotModel { | |
11 | + | |
12 | + private String snapshotId; | |
13 | + | |
14 | + private String status; | |
15 | + | |
16 | + private String progress; | |
17 | + | |
18 | + private String volumeId; | |
19 | + | |
20 | + private String volumeSize; | |
21 | + | |
22 | + public String getSnapshotId() { | |
23 | + return snapshotId; | |
24 | + } | |
25 | + | |
26 | + public void setSnapshotId(String snapshotId) { | |
27 | + this.snapshotId = snapshotId; | |
28 | + } | |
29 | + | |
30 | + public String getStatus() { | |
31 | + return status; | |
32 | + } | |
33 | + | |
34 | + public void setStatus(String status) { | |
35 | + this.status = status; | |
36 | + } | |
37 | + | |
38 | + public String getProgress() { | |
39 | + return progress; | |
40 | + } | |
41 | + | |
42 | + public void setProgress(String progress) { | |
43 | + this.progress = progress; | |
44 | + } | |
45 | + | |
46 | + public String getVolumeId() { | |
47 | + return volumeId; | |
48 | + } | |
49 | + | |
50 | + public void setVolumeId(String volumeId) { | |
51 | + this.volumeId = volumeId; | |
52 | + } | |
53 | + | |
54 | + public String getVolumeSize() { | |
55 | + return volumeSize; | |
56 | + } | |
57 | + | |
58 | + public void setVolumeSize(String volumeSize) { | |
59 | + this.volumeSize = volumeSize; | |
60 | + } | |
61 | + | |
62 | +} |
@@ -1,5 +1,37 @@ | ||
1 | 1 | package jp.co.intellilink.aws.api.transport; |
2 | 2 | |
3 | +import java.util.List; | |
4 | + | |
3 | 5 | public class EC2DescribeSnapshotRequest { |
4 | 6 | |
7 | + private List<String> snapshotId; | |
8 | + | |
9 | + private String owner; | |
10 | + | |
11 | + private String restoableBy; | |
12 | + | |
13 | + public List<String> getSnapshotId() { | |
14 | + return snapshotId; | |
15 | + } | |
16 | + | |
17 | + public void setSnapshotId(List<String> snapshotId) { | |
18 | + this.snapshotId = snapshotId; | |
19 | + } | |
20 | + | |
21 | + public String getOwner() { | |
22 | + return owner; | |
23 | + } | |
24 | + | |
25 | + public void setOwner(String owner) { | |
26 | + this.owner = owner; | |
27 | + } | |
28 | + | |
29 | + public String getRestoableBy() { | |
30 | + return restoableBy; | |
31 | + } | |
32 | + | |
33 | + public void setRestoableBy(String restoableBy) { | |
34 | + this.restoableBy = restoableBy; | |
35 | + } | |
36 | + | |
5 | 37 | } |
@@ -2,4 +2,94 @@ | ||
2 | 2 | |
3 | 3 | public class EC2Snapshot { |
4 | 4 | |
5 | + private String snapshotId; | |
6 | + | |
7 | + private String status; | |
8 | + | |
9 | + private String progress; | |
10 | + | |
11 | + private String volumeId; | |
12 | + | |
13 | + private String volumeSize; | |
14 | + | |
15 | + private String description; | |
16 | + | |
17 | + private String startTime; | |
18 | + | |
19 | + private String ownerId; | |
20 | + | |
21 | + private String ownerAlias; | |
22 | + | |
23 | + public String getSnapshotId() { | |
24 | + return snapshotId; | |
25 | + } | |
26 | + | |
27 | + public void setSnapshotId(String snapshotId) { | |
28 | + this.snapshotId = snapshotId; | |
29 | + } | |
30 | + | |
31 | + public String getStatus() { | |
32 | + return status; | |
33 | + } | |
34 | + | |
35 | + public void setStatus(String status) { | |
36 | + this.status = status; | |
37 | + } | |
38 | + | |
39 | + public String getProgress() { | |
40 | + return progress; | |
41 | + } | |
42 | + | |
43 | + public void setProgress(String progress) { | |
44 | + this.progress = progress; | |
45 | + } | |
46 | + | |
47 | + public String getVolumeId() { | |
48 | + return volumeId; | |
49 | + } | |
50 | + | |
51 | + public void setVolumeId(String volumeId) { | |
52 | + this.volumeId = volumeId; | |
53 | + } | |
54 | + | |
55 | + public String getVolumeSize() { | |
56 | + return volumeSize; | |
57 | + } | |
58 | + | |
59 | + public void setVolumeSize(String volumeSize) { | |
60 | + this.volumeSize = volumeSize; | |
61 | + } | |
62 | + | |
63 | + public String getDescription() { | |
64 | + return description; | |
65 | + } | |
66 | + | |
67 | + public void setDescription(String description) { | |
68 | + this.description = description; | |
69 | + } | |
70 | + | |
71 | + public String getStartTime() { | |
72 | + return startTime; | |
73 | + } | |
74 | + | |
75 | + public void setStartTime(String startTime) { | |
76 | + this.startTime = startTime; | |
77 | + } | |
78 | + | |
79 | + public String getOwnerId() { | |
80 | + return ownerId; | |
81 | + } | |
82 | + | |
83 | + public void setOwnerId(String ownerId) { | |
84 | + this.ownerId = ownerId; | |
85 | + } | |
86 | + | |
87 | + public String getOwnerAlias() { | |
88 | + return ownerAlias; | |
89 | + } | |
90 | + | |
91 | + public void setOwnerAlias(String ownerAlias) { | |
92 | + this.ownerAlias = ownerAlias; | |
93 | + } | |
94 | + | |
5 | 95 | } |
@@ -0,0 +1,51 @@ | ||
1 | +/** | |
2 | + * | |
3 | + */ | |
4 | +package jp.co.intellilink.aws.ui.view; | |
5 | + | |
6 | +import jp.co.intellilink.aws.ui.model.SnapshotModel; | |
7 | + | |
8 | +import org.eclipse.jface.viewers.ITableLabelProvider; | |
9 | +import org.eclipse.jface.viewers.LabelProvider; | |
10 | +import org.eclipse.swt.graphics.Image; | |
11 | + | |
12 | +/** | |
13 | + * @author tanacasino | |
14 | + * | |
15 | + */ | |
16 | +public class SnapshotLabelProvider extends LabelProvider implements ITableLabelProvider { | |
17 | + | |
18 | + /* | |
19 | + * (non-Javadoc) | |
20 | + * | |
21 | + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) | |
22 | + */ | |
23 | + @Override | |
24 | + public Image getColumnImage(Object element, int columnIndex) { | |
25 | + // TODO add snapshot image icon. | |
26 | + return null; | |
27 | + } | |
28 | + | |
29 | + /* | |
30 | + * (non-Javadoc) | |
31 | + * | |
32 | + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) | |
33 | + */ | |
34 | + @Override | |
35 | + public String getColumnText(Object element, int columnIndex) { | |
36 | + if (element instanceof SnapshotModel) { | |
37 | + SnapshotModel model = (SnapshotModel) element; | |
38 | + switch (columnIndex) { | |
39 | + case 0: return model.getSnapshotId(); | |
40 | + case 1: return model.getStatus(); | |
41 | + case 2: return model.getProgress(); | |
42 | + case 3: return model.getVolumeId(); | |
43 | + case 4: return model.getVolumeSize(); | |
44 | + default: | |
45 | + break; | |
46 | + } | |
47 | + } | |
48 | + return null; | |
49 | + } | |
50 | + | |
51 | +} |
@@ -0,0 +1,73 @@ | ||
1 | +/** | |
2 | + * | |
3 | + */ | |
4 | +package jp.co.intellilink.aws.ui.view; | |
5 | + | |
6 | +import java.util.List; | |
7 | + | |
8 | +import jp.co.intellilink.aws.api.ElasticComputingCloudInterface; | |
9 | +import jp.co.intellilink.aws.api.transport.EC2DescribeSnapshotRequest; | |
10 | +import jp.co.intellilink.aws.api.transport.EC2Snapshot; | |
11 | +import jp.co.intellilink.aws.core.CoreException; | |
12 | +import jp.co.intellilink.aws.core.EC2ServiceProvider; | |
13 | +import jp.co.intellilink.aws.ui.Activator; | |
14 | + | |
15 | +import org.eclipse.core.runtime.IProgressMonitor; | |
16 | +import org.eclipse.core.runtime.IStatus; | |
17 | +import org.eclipse.core.runtime.Status; | |
18 | +import org.eclipse.core.runtime.jobs.Job; | |
19 | +import org.eclipse.swt.widgets.Display; | |
20 | + | |
21 | +/** | |
22 | + * @author tanacasino | |
23 | + * | |
24 | + */ | |
25 | +public class DescribeSnapshotsJob extends Job { | |
26 | + | |
27 | + private ActionCallbackHandler handler; | |
28 | + | |
29 | + private List<String> snapshotIds; | |
30 | + | |
31 | + public DescribeSnapshotsJob(String name, ActionCallbackHandler handler, List<String> snapshotIds) { | |
32 | + super(name); | |
33 | + this.handler = handler; | |
34 | + this.snapshotIds = snapshotIds; | |
35 | + } | |
36 | + | |
37 | + /* | |
38 | + * (non-Javadoc) | |
39 | + * | |
40 | + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) | |
41 | + */ | |
42 | + @Override | |
43 | + protected IStatus run(IProgressMonitor monitor) { | |
44 | + monitor.beginTask("DescribeSnapshots", 0); | |
45 | + monitor.setTaskName("Resolve EC2 Client..."); | |
46 | + EC2ServiceProvider provider = Activator.getDefault().getProvider(); | |
47 | + monitor.worked(10); | |
48 | + monitor.setTaskName("Describe Snapshots..."); | |
49 | + final List<EC2Snapshot> snapshots; | |
50 | + try { | |
51 | + ElasticComputingCloudInterface client = provider.getEC2(); | |
52 | + EC2DescribeSnapshotRequest request = new EC2DescribeSnapshotRequest(); | |
53 | + request.setSnapshotId(snapshotIds); | |
54 | + snapshots = client.describeSnapshot(request); | |
55 | + monitor.worked(80); | |
56 | + } catch (CoreException e) { | |
57 | + // TODO Auto-generated catch block | |
58 | + e.printStackTrace(); | |
59 | + return Status.CANCEL_STATUS; | |
60 | + } | |
61 | + if (handler != null && snapshots != null) { | |
62 | + Display.getDefault().syncExec(new Runnable() { | |
63 | + @Override | |
64 | + public void run() { | |
65 | + handler.onDescribeSnapshots(snapshots); | |
66 | + } | |
67 | + }); | |
68 | + } | |
69 | + monitor.done(); | |
70 | + return Status.OK_STATUS; | |
71 | + } | |
72 | + | |
73 | +} |
@@ -0,0 +1,28 @@ | ||
1 | +/** | |
2 | + * | |
3 | + */ | |
4 | +package jp.co.intellilink.aws.ui.view; | |
5 | + | |
6 | +import java.util.ArrayList; | |
7 | + | |
8 | +import jp.co.intellilink.aws.ui.Activator; | |
9 | + | |
10 | +/** | |
11 | + * @author tanacasino | |
12 | + * | |
13 | + */ | |
14 | +public class DescribeSnapshotsAction extends CallbackAction { | |
15 | + | |
16 | + public DescribeSnapshotsAction(ActionCallbackHandler handler) { | |
17 | + super(handler, "DescribeSnapshots"); | |
18 | + setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/refresh.png")); | |
19 | + } | |
20 | + | |
21 | + @Override | |
22 | + public void run() { | |
23 | + super.run(); | |
24 | + DescribeSnapshotsJob job = new DescribeSnapshotsJob("DescribeSnapshots", getHandler(), new ArrayList<String>()); | |
25 | + job.schedule(); | |
26 | + } | |
27 | + | |
28 | +} |
@@ -12,6 +12,7 @@ | ||
12 | 12 | import jp.co.intellilink.aws.api.transport.EC2Permission; |
13 | 13 | import jp.co.intellilink.aws.api.transport.EC2Permission.EC2UserGroupPair; |
14 | 14 | import jp.co.intellilink.aws.api.transport.EC2SecurityGroup; |
15 | +import jp.co.intellilink.aws.api.transport.EC2Snapshot; | |
15 | 16 | import jp.co.intellilink.aws.api.transport.EC2Volume; |
16 | 17 | import jp.co.intellilink.aws.ui.model.ElasticIPModel; |
17 | 18 | import jp.co.intellilink.aws.ui.model.GroupModel; |
@@ -22,6 +23,7 @@ | ||
22 | 23 | import jp.co.intellilink.aws.ui.model.KeyPairModel; |
23 | 24 | import jp.co.intellilink.aws.ui.model.NetworkRule; |
24 | 25 | import jp.co.intellilink.aws.ui.model.SecurityGroupModel; |
26 | +import jp.co.intellilink.aws.ui.model.SnapshotModel; | |
25 | 27 | import jp.co.intellilink.aws.ui.model.VolumeModel; |
26 | 28 | |
27 | 29 | import org.eclipse.jface.viewers.TreeViewer; |
@@ -190,4 +192,18 @@ | ||
190 | 192 | viewer.setInput(input); |
191 | 193 | } |
192 | 194 | |
195 | + public void onDescribeSnapshots(List<EC2Snapshot> items) { | |
196 | + List<SnapshotModel> input = new ArrayList<SnapshotModel>(); | |
197 | + for (EC2Snapshot snap : items) { | |
198 | + SnapshotModel model = new SnapshotModel(); | |
199 | + model.setSnapshotId(snap.getSnapshotId()); | |
200 | + model.setStatus(snap.getStatus()); | |
201 | + model.setProgress(snap.getProgress()); | |
202 | + model.setVolumeId(snap.getVolumeId()); | |
203 | + model.setVolumeSize(snap.getVolumeSize()); | |
204 | + input.add(model); | |
205 | + } | |
206 | + viewer.setInput(input); | |
207 | + } | |
208 | + | |
193 | 209 | } |
@@ -0,0 +1,96 @@ | ||
1 | +/** | |
2 | + * | |
3 | + */ | |
4 | +package jp.co.intellilink.aws.ui.view; | |
5 | + | |
6 | +import org.eclipse.jface.action.IMenuListener; | |
7 | +import org.eclipse.jface.action.IMenuManager; | |
8 | +import org.eclipse.jface.action.IToolBarManager; | |
9 | +import org.eclipse.jface.action.MenuManager; | |
10 | +import org.eclipse.jface.viewers.ArrayContentProvider; | |
11 | +import org.eclipse.jface.viewers.TableViewer; | |
12 | +import org.eclipse.swt.SWT; | |
13 | +import org.eclipse.swt.widgets.Composite; | |
14 | +import org.eclipse.swt.widgets.Menu; | |
15 | +import org.eclipse.swt.widgets.Table; | |
16 | +import org.eclipse.swt.widgets.TableColumn; | |
17 | +import org.eclipse.ui.IViewSite; | |
18 | +import org.eclipse.ui.PartInitException; | |
19 | +import org.eclipse.ui.part.ViewPart; | |
20 | + | |
21 | +/** | |
22 | + * @author tanacasino | |
23 | + * | |
24 | + */ | |
25 | +public class SnapshotView extends ViewPart { | |
26 | + | |
27 | + private ActionCallbackHandler handler; | |
28 | + | |
29 | + private DescribeSnapshotsAction describeSnapshotsAction; | |
30 | + | |
31 | + @Override | |
32 | + public void init(IViewSite site) throws PartInitException { | |
33 | + super.init(site); | |
34 | + } | |
35 | + | |
36 | + /* | |
37 | + * (non-Javadoc) | |
38 | + * | |
39 | + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) | |
40 | + */ | |
41 | + @Override | |
42 | + public void createPartControl(Composite parent) { | |
43 | + TableViewer viewer = new TableViewer(parent); | |
44 | + Table tree = viewer.getTable(); | |
45 | + | |
46 | + TableColumn snapshotId = new TableColumn(tree, SWT.NONE); | |
47 | + snapshotId.setText("Snapshot ID"); | |
48 | + snapshotId.setWidth(100); | |
49 | + | |
50 | + TableColumn status = new TableColumn(tree, SWT.NONE); | |
51 | + status.setText("Status"); | |
52 | + status.setWidth(90); | |
53 | + | |
54 | + TableColumn progress = new TableColumn(tree, SWT.NONE); | |
55 | + progress.setText("Progress"); | |
56 | + progress.setWidth(70); | |
57 | + | |
58 | + TableColumn volumeId = new TableColumn(tree, SWT.NONE); | |
59 | + volumeId.setText("Volume ID"); | |
60 | + volumeId.setWidth(100); | |
61 | + | |
62 | + TableColumn volumeSize = new TableColumn(tree, SWT.NONE); | |
63 | + volumeSize.setText("Volume Size"); | |
64 | + volumeSize.setWidth(100); | |
65 | + | |
66 | + tree.setHeaderVisible(true); | |
67 | + tree.pack(false); | |
68 | + viewer.setContentProvider(new ArrayContentProvider()); | |
69 | + viewer.setLabelProvider(new SnapshotLabelProvider()); | |
70 | + this.handler = new ActionCallbackHandler(viewer); | |
71 | + IToolBarManager manager = getViewSite().getActionBars().getToolBarManager(); | |
72 | + describeSnapshotsAction = new DescribeSnapshotsAction(handler); | |
73 | + manager.add(describeSnapshotsAction); | |
74 | + MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ | |
75 | + menuMgr.setRemoveAllWhenShown(true); | |
76 | + menuMgr.addMenuListener(new IMenuListener() { | |
77 | + public void menuAboutToShow(IMenuManager manager) { | |
78 | + manager.add(describeSnapshotsAction); | |
79 | + } | |
80 | + }); | |
81 | + Menu menu = menuMgr.createContextMenu(viewer.getControl()); | |
82 | + viewer.getControl().setMenu(menu); | |
83 | + getSite().registerContextMenu(menuMgr, viewer); | |
84 | + } | |
85 | + | |
86 | + /* | |
87 | + * (non-Javadoc) | |
88 | + * | |
89 | + * @see org.eclipse.ui.part.WorkbenchPart#setFocus() | |
90 | + */ | |
91 | + @Override | |
92 | + public void setFocus() { | |
93 | + // TODO Auto-generated method stub | |
94 | + } | |
95 | + | |
96 | +} |
@@ -73,6 +73,13 @@ | ||
73 | 73 | name="%aws.view.volume" |
74 | 74 | restorable="true"> |
75 | 75 | </view> |
76 | + <view | |
77 | + category="jp.co.intellilink.aws.ui.view" | |
78 | + class="jp.co.intellilink.aws.ui.view.SnapshotView" | |
79 | + id="jp.co.intellilink.aws.ui.view.snapshot" | |
80 | + name="%aws.view.snapshot" | |
81 | + restorable="true"> | |
82 | + </view> | |
76 | 83 | </extension> |
77 | 84 | <extension |
78 | 85 | point="org.eclipse.help.contexts"> |
@@ -16,6 +16,7 @@ | ||
16 | 16 | IFolderLayout folder2 = layout.createFolder("jp.co.intellilink.aws.ui.bottom", IPageLayout.BOTTOM, 0.3f, IPageLayout.ID_EDITOR_AREA); |
17 | 17 | folder2.addView("jp.co.intellilink.aws.ui.view.images"); |
18 | 18 | folder2.addView("jp.co.intellilink.aws.ui.view.volume"); |
19 | + folder2.addView("jp.co.intellilink.aws.ui.view.snapshot"); | |
19 | 20 | layout.addView("jp.co.intellilink.aws.app.view", IPageLayout.BOTTOM, 0.8f, "jp.co.intellilink.aws.ui.view.images"); |
20 | 21 | } |
21 | 22 |