Adding tags support to the 4 EC2 Describe* API's(DescribeImages, DescribeInstances, DescribeVolumes, DescribeSnapshots) in AWSAPI.

Reviewed by: Prachi
This commit is contained in:
Likitha Shetty 2012-07-10 18:45:48 +05:30
parent 1bcb9afa89
commit 2bf8026ea8
10 changed files with 179 additions and 39 deletions

View File

@ -955,7 +955,11 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
param7.addItem( param8 );
param3.setBlockDeviceMapping( param7 );
param2.addItem( param3 );
EC2TagKeyValue[] tags = images[i].getResourceTags();
param3.setTagSet(setResourceTags(tags));
param2.addItem( param3 );
}
param1.setImagesSet( param2 );
@ -1262,14 +1266,9 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
}
param3.setAttachmentSet( param4 );
// -> try to generate an empty tag does not seem to work
ResourceTagSetType param6 = new ResourceTagSetType();
ResourceTagSetItemType param7 = new ResourceTagSetItemType();
param7.setKey("");
param7.setValue("");
param6.addItem( param7 );
param3.setTagSet( param6 );
EC2TagKeyValue[] tags = vol.getResourceTags();
param3.setTagSet( setResourceTags(tags) );
param2.addItem( param3 );
}
param1.setVolumeSet( param2 );
@ -1397,6 +1396,9 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
param7.setSpotInstanceRequestId( "" );
param7.setHypervisor(inst.getHypervisor());
EC2TagKeyValue[] tags = inst.getResourceTags();
param7.setTagSet(setResourceTags(tags));
param6.addItem( param7 );
param3.setInstancesSet( param6 );
param2.addItem( param3 );
@ -1879,12 +1881,9 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
param3.setDescription( snap.getName());
param3.setOwnerAlias( snap.getAccountName() );
ResourceTagSetType param18 = new ResourceTagSetType();
ResourceTagSetItemType param19 = new ResourceTagSetItemType();
param19.setKey("");
param19.setValue("");
param18.addItem( param19 );
param3.setTagSet( param18 );
EC2TagKeyValue[] tags = snap.getResourceTags();
param3.setTagSet(setResourceTags(tags));
param2.addItem( param3 );
}
@ -2208,7 +2207,29 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
public GetPasswordDataResponse getPasswordData(GetPasswordData getPasswordData) {
return toGetPasswordData(engine.getPasswordData(getPasswordData.getGetPasswordData().getInstanceId()));
}
public static ResourceTagSetType setResourceTags(EC2TagKeyValue[] tags){
ResourceTagSetType param1 = new ResourceTagSetType();
if (null == tags || 0 == tags.length) {
ResourceTagSetItemType param2 = new ResourceTagSetItemType();
param2.setKey("");
param2.setValue("");
param1.addItem( param2 );
}
else {
for(EC2TagKeyValue tag : tags) {
ResourceTagSetItemType param2 = new ResourceTagSetItemType();
param2.setKey(tag.getKey());
if (tag.getValue() != null)
param2.setValue(tag.getValue());
else
param2.setValue("");
param1.addItem(param2);
}
}
return param1;
}
@SuppressWarnings("serial")
public static GetPasswordDataResponse toGetPasswordData(final EC2PasswordData passwdData) {
return new GetPasswordDataResponse() {{

View File

@ -659,6 +659,15 @@ public class EC2Engine {
shot.setAccountName(cloudSnapshot.getAccountName());
shot.setDomainId(cloudSnapshot.getDomainId());
List<CloudStackKeyValue> resourceTags = cloudSnapshot.getTags();
for(CloudStackKeyValue resourceTag : resourceTags) {
EC2TagKeyValue param = new EC2TagKeyValue();
param.setKey(resourceTag.getKey());
if (resourceTag.getValue() != null)
param.setValue(resourceTag.getValue());
shot.addResourceTag(param);
}
snapshots.addSnapshot(shot);
}
return snapshots;
@ -1709,6 +1718,15 @@ public class EC2Engine {
ec2Vol.setVMState(vol.getVirtualMachineState());
ec2Vol.setZoneName(vol.getZoneName());
List<CloudStackKeyValue> resourceTags = vol.getTags();
for(CloudStackKeyValue resourceTag : resourceTags) {
EC2TagKeyValue param = new EC2TagKeyValue();
param.setKey(resourceTag.getKey());
if (resourceTag.getValue() != null)
param.setValue(resourceTag.getValue());
ec2Vol.addResourceTag(param);
}
volumes.addVolume(ec2Vol);
}
}
@ -1886,7 +1904,16 @@ public class EC2Engine {
break;
}
}
List<CloudStackKeyValue> resourceTags = cloudVm.getTags();
for(CloudStackKeyValue resourceTag : resourceTags) {
EC2TagKeyValue param = new EC2TagKeyValue();
param.setKey(resourceTag.getKey());
if (resourceTag.getValue() != null)
param.setValue(resourceTag.getValue());
ec2Vm.addResourceTag(param);
}
if (cloudVm.getSecurityGroupList() != null && cloudVm.getSecurityGroupList().size() > 0) {
// TODO, we have a list of security groups, just return the first one?
List<CloudStackSecurityGroup> securityGroupList = cloudVm.getSecurityGroupList();
@ -1959,6 +1986,14 @@ public class EC2Engine {
ec2Image.setIsPublic(temp.getIsPublic());
ec2Image.setIsReady(temp.getIsReady());
ec2Image.setDomainId(temp.getDomainId());
List<CloudStackKeyValue> resourceTags = temp.getTags();
for(CloudStackKeyValue resourceTag : resourceTags) {
EC2TagKeyValue param = new EC2TagKeyValue();
param.setKey(resourceTag.getKey());
if (resourceTag.getValue() != null)
param.setValue(resourceTag.getValue());
ec2Image.addResourceTag(param);
}
images.addImage(ec2Image);
}
}

View File

@ -15,6 +15,9 @@
*/
package com.cloud.bridge.service.core.ec2;
import java.util.ArrayList;
import java.util.List;
/**
* An EC2 Image is a Cloud template.
*/
@ -27,7 +30,8 @@ public class EC2Image {
private boolean isPublic;
private boolean isReady;
private String accountName;
private String domainId;
private String domainId;
private List<EC2TagKeyValue> tagsSet;
public EC2Image() {
id = null;
@ -37,7 +41,8 @@ public class EC2Image {
isPublic = false;
isReady = false;
accountName = null;
domainId = null;
domainId = null;
tagsSet = new ArrayList<EC2TagKeyValue>();
}
public void setId( String id ) {
@ -102,6 +107,14 @@ public class EC2Image {
public void setDomainId(String domainId) {
this.domainId = domainId;
}
}
public void addResourceTag( EC2TagKeyValue param ) {
tagsSet.add( param );
}
public EC2TagKeyValue[] getResourceTags() {
return tagsSet.toArray(new EC2TagKeyValue[0]);
}
}
}

View File

@ -39,7 +39,8 @@ public class EC2Instance {
private String hypervisor;
private String rootDeviceType;
private String rootDeviceId;
private List<String> groupSet;
private List<String> groupSet;
private List<EC2TagKeyValue> tagsSet;
public EC2Instance() {
id = null;
@ -58,7 +59,8 @@ public class EC2Instance {
hypervisor = null;
rootDeviceType = null;
rootDeviceId = null;
groupSet = new ArrayList<String>();
groupSet = new ArrayList<String>();
tagsSet = new ArrayList<EC2TagKeyValue>();
}
public void setId( String id ) {
@ -195,6 +197,13 @@ public class EC2Instance {
public String[] getGroupSet() {
return groupSet.toArray(new String[0]);
}
}
}
public void addResourceTag( EC2TagKeyValue param ) {
tagsSet.add( param );
}
public EC2TagKeyValue[] getResourceTags() {
return tagsSet.toArray(new EC2TagKeyValue[0]);
}
}

View File

@ -15,7 +15,9 @@
*/
package com.cloud.bridge.service.core.ec2;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import com.cloud.bridge.util.EC2RestAuth;
@ -29,7 +31,8 @@ public class EC2Snapshot {
private String state;
private Calendar created;
private String accountName;
private String domainId;
private String domainId;
private List<EC2TagKeyValue> tagsSet;
public EC2Snapshot() {
id = null;
@ -40,7 +43,8 @@ public class EC2Snapshot {
state = null;
created = null;
accountName = null;
domainId = null;
domainId = null;
tagsSet = new ArrayList<EC2TagKeyValue>();
}
public void setId(String id ) {
@ -114,5 +118,13 @@ public class EC2Snapshot {
public void setState(String state) {
this.state = state;
}
}
public void addResourceTag( EC2TagKeyValue param ) {
tagsSet.add( param );
}
public EC2TagKeyValue[] getResourceTags() {
return tagsSet.toArray(new EC2TagKeyValue[0]);
}
}

View File

@ -15,6 +15,9 @@
*/
package com.cloud.bridge.service.core.ec2;
import java.util.ArrayList;
import java.util.List;
public class EC2Volume {
@ -30,7 +33,8 @@ public class EC2Volume {
private String VMState;
private String hypervisor;
private String created;
private String attached;
private String attached;
private List<EC2TagKeyValue> tagsSet;
public EC2Volume() {
id = null;
@ -44,7 +48,8 @@ public class EC2Volume {
VMState = null;
hypervisor = null;
created = null;
attached = null;
attached = null;
tagsSet = new ArrayList<EC2TagKeyValue>();
}
public void setSize(Long size) {
@ -228,6 +233,14 @@ public class EC2Volume {
*/
public void setAttached(String attached) {
this.attached = attached;
}
}
public void addResourceTag( EC2TagKeyValue param ) {
tagsSet.add( param );
}
public EC2TagKeyValue[] getResourceTags() {
return tagsSet.toArray(new EC2TagKeyValue[0]);
}
}

View File

@ -15,6 +15,8 @@
*/
package com.cloud.stack.models;
import java.util.List;
import com.google.gson.annotations.SerializedName;
public class CloudStackSnapshot {
@ -45,7 +47,9 @@ public class CloudStackSnapshot {
@SerializedName(ApiConstants.VOLUME_NAME)
private String volumeName;
@SerializedName(ApiConstants.VOLUME_TYPE)
private String volumeType;
private String volumeType;
@SerializedName(ApiConstants.TAGS)
private List<CloudStackKeyValue> tags;
public CloudStackSnapshot() {
}
@ -104,5 +108,9 @@ public class CloudStackSnapshot {
public String getState() {
return state;
}
}
public List<CloudStackKeyValue> getTags() {
return tags;
}
}

View File

@ -16,6 +16,8 @@
package com.cloud.stack.models;
import java.util.List;
import com.google.gson.annotations.SerializedName;
/**
@ -85,6 +87,8 @@ public class CloudStackTemplate {
private String zoneId;
@SerializedName(ApiConstants.ZONE_NAME)
private String zoneName;
@SerializedName(ApiConstants.TAGS)
private List<CloudStackKeyValue> tags;
/**
*
@ -309,4 +313,10 @@ public class CloudStackTemplate {
return zoneName;
}
/**
* @return all tags
*/
public List<CloudStackKeyValue> getTags() {
return tags;
}
}

View File

@ -101,7 +101,9 @@ public class CloudStackUserVm {
@SerializedName(ApiConstants.NIC)
private List<CloudStackNic> nics;
@SerializedName(ApiConstants.SECURITY_GROUP)
private List<CloudStackSecurityGroup> securityGroupList;
private List<CloudStackSecurityGroup> securityGroupList;
@SerializedName(ApiConstants.TAGS)
private List<CloudStackKeyValue> tags;
public CloudStackUserVm() {
}
@ -391,7 +393,13 @@ public class CloudStackUserVm {
*/
public List<CloudStackSecurityGroup> getSecurityGroupList() {
return securityGroupList;
}
}
/**
* @return all tags
*/
public List<CloudStackKeyValue> getTags() {
return tags;
}
}

View File

@ -15,6 +15,8 @@
*/
package com.cloud.stack.models;
import java.util.List;
import com.google.gson.annotations.SerializedName;
public class CloudStackVolume {
@ -79,7 +81,9 @@ public class CloudStackVolume {
@SerializedName(ApiConstants.ZONE_ID)
private String zoneId;
@SerializedName(ApiConstants.ZONE_NAME)
private String zoneName;
private String zoneName;
@SerializedName(ApiConstants.TAGS)
private List<CloudStackKeyValue> tags;
public CloudStackVolume() {
@ -331,6 +335,13 @@ public class CloudStackVolume {
*/
public String getZoneName() {
return zoneName;
}
}
/**
* @return all tags
*/
public List<CloudStackKeyValue> getTags() {
return tags;
}
}