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

- List* APIs in CloudStack have tags support. Adding the corresponding support to EC2Decsribe* APIs in the AWSAPI component.
This commit is contained in:
Likitha Shetty 2012-07-23 15:11:09 -07:00 committed by prachi
parent 88f7872b81
commit aef09e1b20
10 changed files with 162 additions and 20 deletions

View File

@ -956,7 +956,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 );
@ -1263,14 +1267,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 );
@ -1398,6 +1397,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 );
@ -1880,12 +1882,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 );
}
@ -2209,7 +2208,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

@ -660,6 +660,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;
@ -1710,6 +1719,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);
}
}
@ -1887,7 +1905,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();
@ -1960,6 +1987,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

@ -16,6 +16,9 @@
// under the License.
package com.cloud.bridge.service.core.ec2;
import java.util.ArrayList;
import java.util.List;
/**
* An EC2 Image is a Cloud template.
*/
@ -29,6 +32,7 @@ public class EC2Image {
private boolean isReady;
private String accountName;
private String domainId;
private List<EC2TagKeyValue> tagsSet;
public EC2Image() {
id = null;
@ -39,6 +43,7 @@ public class EC2Image {
isReady = false;
accountName = null;
domainId = null;
tagsSet = new ArrayList<EC2TagKeyValue>();
}
public void setId( String id ) {
@ -104,5 +109,13 @@ 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

@ -41,6 +41,7 @@ public class EC2Instance {
private String rootDeviceType;
private String rootDeviceId;
private List<String> groupSet;
private List<EC2TagKeyValue> tagsSet;
public EC2Instance() {
id = null;
@ -60,6 +61,7 @@ public class EC2Instance {
rootDeviceType = null;
rootDeviceId = null;
groupSet = new ArrayList<String>();
tagsSet = new ArrayList<EC2TagKeyValue>();
}
public void setId( String id ) {
@ -197,5 +199,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

@ -16,7 +16,9 @@
// under the License.
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;
@ -31,6 +33,7 @@ public class EC2Snapshot {
private Calendar created;
private String accountName;
private String domainId;
private List<EC2TagKeyValue> tagsSet;
public EC2Snapshot() {
id = null;
@ -42,6 +45,7 @@ public class EC2Snapshot {
created = null;
accountName = null;
domainId = null;
tagsSet = new ArrayList<EC2TagKeyValue>();
}
public void setId(String id ) {
@ -116,4 +120,12 @@ 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

@ -16,6 +16,9 @@
// under the License.
package com.cloud.bridge.service.core.ec2;
import java.util.ArrayList;
import java.util.List;
public class EC2Volume {
@ -32,6 +35,7 @@ public class EC2Volume {
private String hypervisor;
private String created;
private String attached;
private List<EC2TagKeyValue> tagsSet;
public EC2Volume() {
id = null;
@ -46,6 +50,7 @@ public class EC2Volume {
hypervisor = null;
created = null;
attached = null;
tagsSet = new ArrayList<EC2TagKeyValue>();
}
public void setSize(Long size) {
@ -230,5 +235,13 @@ 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

@ -16,6 +16,8 @@
// under the License.
package com.cloud.stack.models;
import java.util.List;
import com.google.gson.annotations.SerializedName;
public class CloudStackSnapshot {
@ -47,6 +49,8 @@ public class CloudStackSnapshot {
private String volumeName;
@SerializedName(ApiConstants.VOLUME_TYPE)
private String volumeType;
@SerializedName(ApiConstants.TAGS)
private List<CloudStackKeyValue> tags;
public CloudStackSnapshot() {
}
@ -106,4 +110,9 @@ public class CloudStackSnapshot {
public String getState() {
return state;
}
public List<CloudStackKeyValue> getTags() {
return tags;
}
}

View File

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

View File

@ -103,6 +103,8 @@ public class CloudStackUserVm {
private List<CloudStackNic> nics;
@SerializedName(ApiConstants.SECURITY_GROUP)
private List<CloudStackSecurityGroup> securityGroupList;
@SerializedName(ApiConstants.TAGS)
private List<CloudStackKeyValue> tags;
public CloudStackUserVm() {
}
@ -394,5 +396,12 @@ public class CloudStackUserVm {
return securityGroupList;
}
/**
* @return all tags
*/
public List<CloudStackKeyValue> getTags() {
return tags;
}
}

View File

@ -16,6 +16,8 @@
// under the License.
package com.cloud.stack.models;
import java.util.List;
import com.google.gson.annotations.SerializedName;
public class CloudStackVolume {
@ -81,6 +83,8 @@ public class CloudStackVolume {
private String zoneId;
@SerializedName(ApiConstants.ZONE_NAME)
private String zoneName;
@SerializedName(ApiConstants.TAGS)
private List<CloudStackKeyValue> tags;
public CloudStackVolume() {
@ -334,4 +338,10 @@ public class CloudStackVolume {
return zoneName;
}
/**
* @return all tags
*/
public List<CloudStackKeyValue> getTags() {
return tags;
}
}