Skip to content

Commit ee90ebf

Browse files
author
Prachi Damle
committed
CLOUDSTACK-1128: [EC2 Query API] DescribeAvailabilityZones, support for message filter
Add message in the response element of EC2DesrcibeAvailibilityZones. Add support for filter 'message'. The value of 'message' should be set to the allocation_state of the zone Code cleanup
1 parent 961c8ee commit ee90ebf

5 files changed

Lines changed: 113 additions & 57 deletions

File tree

‎awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.cloud.bridge.service.core.ec2.EC2DescribeAvailabilityZonesResponse;
4242
import com.cloud.bridge.service.core.ec2.EC2DescribeImageAttribute;
4343

44+
import com.cloud.bridge.service.core.ec2.EC2AvailabilityZone;
4445
import com.cloud.bridge.service.core.ec2.EC2DescribeImages;
4546
import com.cloud.bridge.service.core.ec2.EC2DescribeImagesResponse;
4647
import com.cloud.bridge.service.core.ec2.EC2DescribeInstances;
@@ -1775,14 +1776,18 @@ public static DescribeAvailabilityZonesResponse toDescribeAvailabilityZonesRespo
17751776
DescribeAvailabilityZonesResponse response = new DescribeAvailabilityZonesResponse();
17761777
DescribeAvailabilityZonesResponseType param1 = new DescribeAvailabilityZonesResponseType();
17771778
AvailabilityZoneSetType param2 = new AvailabilityZoneSetType();
1778-
1779-
String[] zones = engineResponse.getZoneSet();
1780-
for (String zone : zones) {
1779+
1780+
EC2AvailabilityZone[] zones = engineResponse.getAvailabilityZoneSet();
1781+
for (EC2AvailabilityZone zone : zones) {
17811782
AvailabilityZoneItemType param3 = new AvailabilityZoneItemType();
1782-
AvailabilityZoneMessageSetType param4 = new AvailabilityZoneMessageSetType();
1783-
param3.setZoneName( zone );
1783+
param3.setZoneName( zone.getName() );
17841784
param3.setZoneState( "available" );
17851785
param3.setRegionName( "" );
1786+
1787+
AvailabilityZoneMessageSetType param4 = new AvailabilityZoneMessageSetType();
1788+
AvailabilityZoneMessageType param5 = new AvailabilityZoneMessageType();
1789+
param5.setMessage(zone.getMessage());
1790+
param4.addItem(param5);
17861791
param3.setMessageSet( param4 );
17871792
param2.addItem( param3 );
17881793
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.bridge.service.core.ec2;
18+
19+
public class EC2AvailabilityZone {
20+
21+
private String id;
22+
private String name;
23+
private String message;
24+
25+
public EC2AvailabilityZone() {
26+
id = null;
27+
name = null;
28+
message = null;
29+
}
30+
31+
public void setId( String id ) {
32+
this.id = id;
33+
}
34+
35+
public String getId() {
36+
return this.id;
37+
}
38+
39+
public void setName( String name ) {
40+
this.name = name;
41+
}
42+
43+
public String getName() {
44+
return this.name;
45+
}
46+
47+
public void setMessage( String message ) {
48+
this.message = message;
49+
}
50+
51+
public String getMessage() {
52+
return this.message;
53+
}
54+
55+
}

‎awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZonesFilterSet.java‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class EC2AvailabilityZonesFilterSet {
3636
public EC2AvailabilityZonesFilterSet() {
3737
// -> use these values to check that the proper filter is passed to this type of filter set
3838
filterTypes.put( "zone-name", "String" );
39+
filterTypes.put( "message", "String");
3940
}
4041

4142
public void addFilter( EC2Filter param ) {
@@ -55,13 +56,14 @@ public EC2Filter[] getFilterSet() {
5556
return filterSet.toArray(new EC2Filter[0]);
5657
}
5758

58-
public List<String> evaluate( EC2DescribeAvailabilityZonesResponse availabilityZones) throws ParseException {
59-
List<String> resultList = new ArrayList<String>();
59+
public EC2DescribeAvailabilityZonesResponse evaluate( EC2DescribeAvailabilityZonesResponse availabilityZones)
60+
throws ParseException {
61+
EC2DescribeAvailabilityZonesResponse resultList = new EC2DescribeAvailabilityZonesResponse();
6062

6163
boolean matched;
6264

6365
EC2Filter[] filterSet = getFilterSet();
64-
for ( String availableZone : availabilityZones.getZoneSet() ) {
66+
for ( EC2AvailabilityZone availableZone : availabilityZones.getAvailabilityZoneSet() ) {
6567
matched = true;
6668
if (filterSet != null) {
6769
for (EC2Filter filter : filterSet) {
@@ -71,19 +73,22 @@ public List<String> evaluate( EC2DescribeAvailabilityZonesResponse availabilityZ
7173
}
7274
}
7375
}
74-
if (matched == true)
75-
resultList.add(availableZone);
76+
if (matched)
77+
resultList.addAvailabilityZone(availableZone);
7678
}
7779
return resultList;
7880
}
7981

80-
private boolean filterMatched( String availableZone, EC2Filter filter ) throws ParseException {
82+
private boolean filterMatched( EC2AvailabilityZone availableZone, EC2Filter filter ) throws ParseException {
8183
String filterName = filter.getName();
8284
String[] valueSet = filter.getValueSet();
8385

8486
if ( filterName.equalsIgnoreCase("zone-name")) {
85-
return containsString(availableZone, valueSet);
86-
}
87+
return containsString(availableZone.getName(), valueSet);
88+
}
89+
else if (filterName.equalsIgnoreCase("message")) {
90+
return containsString(availableZone.getMessage(), valueSet);
91+
}
8792
return false;
8893
}
8994

‎awsapi/src/com/cloud/bridge/service/core/ec2/EC2DescribeAvailabilityZonesResponse.java‎

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,17 @@
2020
import java.util.List;
2121

2222
public class EC2DescribeAvailabilityZonesResponse {
23+
private List<EC2AvailabilityZone> availabilityZoneSet = new ArrayList<EC2AvailabilityZone>();
2324

24-
private List<String> zoneIds = new ArrayList<String>();
25-
private List<String> zoneNames = new ArrayList<String>();
25+
public EC2DescribeAvailabilityZonesResponse() {
26+
}
27+
28+
public void addAvailabilityZone( EC2AvailabilityZone param ) {
29+
availabilityZoneSet.add( param );
30+
}
31+
32+
public EC2AvailabilityZone[] getAvailabilityZoneSet() {
33+
return availabilityZoneSet.toArray(new EC2AvailabilityZone[0]);
34+
}
2635

27-
public EC2DescribeAvailabilityZonesResponse() {
28-
}
29-
30-
public void addZone(String id, String name) {
31-
zoneIds.add(id);
32-
zoneNames.add(name);
33-
}
34-
35-
/**
36-
* The Amazon API only cares about the names of zones not their ID value.
37-
*
38-
* @return an array containing a set of zone names
39-
*/
40-
public String[] getZoneSet() {
41-
return zoneNames.toArray(new String[0]);
42-
}
43-
44-
public String getZoneIdAt(int index) {
45-
if (zoneIds.isEmpty() || index >= zoneIds.size()) {
46-
return null;
47-
}
48-
return zoneIds.get(index);
49-
}
5036
}

‎awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,12 +1060,8 @@ public EC2DescribeAvailabilityZonesResponse handleRequest(EC2DescribeAvailabilit
10601060
EC2AvailabilityZonesFilterSet azfs = request.getFilterSet();
10611061
if ( null == azfs )
10621062
return availableZones;
1063-
else {
1064-
List<String> matchedAvailableZones = azfs.evaluate(availableZones);
1065-
if (matchedAvailableZones.isEmpty())
1066-
return new EC2DescribeAvailabilityZonesResponse();
1067-
return listZones(matchedAvailableZones.toArray(new String[0]), null);
1068-
}
1063+
else
1064+
return azfs.evaluate(availableZones);
10691065
} catch( EC2ServiceException error ) {
10701066
logger.error( "EC2 DescribeAvailabilityZones - ", error);
10711067
throw error;
@@ -1691,9 +1687,11 @@ private String toZoneId(String zoneName, String domainId) throws Exception {
16911687

16921688
zones = listZones(interestedZones, domainId);
16931689

1694-
if (zones == null || zones.getZoneIdAt( 0 ) == null)
1690+
if (zones == null || zones.getAvailabilityZoneSet().length == 0)
16951691
throw new EC2ServiceException(ClientError.InvalidParameterValue, "Unknown zoneName value - " + zoneName);
1696-
return zones.getZoneIdAt(0);
1692+
1693+
EC2AvailabilityZone[] zoneSet = zones.getAvailabilityZoneSet();
1694+
return zoneSet[0].getId();
16971695
}
16981696

16991697

@@ -1768,24 +1766,31 @@ private String toOSTypeId( String osTypeName ) throws Exception {
17681766
*
17691767
* @return EC2DescribeAvailabilityZonesResponse
17701768
*/
1771-
private EC2DescribeAvailabilityZonesResponse listZones(String[] interestedZones, String domainId) throws Exception
1772-
{
1769+
private EC2DescribeAvailabilityZonesResponse listZones(String[] interestedZones, String domainId)
1770+
throws Exception {
17731771
EC2DescribeAvailabilityZonesResponse zones = new EC2DescribeAvailabilityZonesResponse();
17741772

17751773
List<CloudStackZone> cloudZones = getApi().listZones(true, domainId, null, null);
1776-
1777-
if(cloudZones != null) {
1774+
if(cloudZones != null && cloudZones.size() > 0) {
17781775
for(CloudStackZone cloudZone : cloudZones) {
1779-
if ( null != interestedZones && 0 < interestedZones.length ) {
1780-
for( int j=0; j < interestedZones.length; j++ ) {
1781-
if (interestedZones[j].equalsIgnoreCase( cloudZone.getName())) {
1782-
zones.addZone(cloudZone.getId().toString(), cloudZone.getName());
1776+
boolean matched = false;
1777+
if (interestedZones.length > 0) {
1778+
for (String zoneName : interestedZones){
1779+
if (zoneName.equalsIgnoreCase( cloudZone.getName())) {
1780+
matched = true;
17831781
break;
17841782
}
17851783
}
1786-
} else {
1787-
zones.addZone(cloudZone.getId().toString(), cloudZone.getName());
1784+
} else {
1785+
matched = true;
17881786
}
1787+
if (!matched) continue;
1788+
EC2AvailabilityZone ec2Zone = new EC2AvailabilityZone();
1789+
ec2Zone.setId(cloudZone.getId().toString());
1790+
ec2Zone.setMessage(cloudZone.getAllocationState());
1791+
ec2Zone.setName(cloudZone.getName());
1792+
1793+
zones.addAvailabilityZone(ec2Zone);
17891794
}
17901795
}
17911796
return zones;
@@ -1952,7 +1957,7 @@ private EC2DescribeImagesResponse listTemplates( String templateId, EC2DescribeI
19521957
* @throws ParserConfigurationException
19531958
* @throws ParseException
19541959
*/
1955-
public EC2DescribeSecurityGroupsResponse listSecurityGroups( String[] interestedGroups ) throws Exception {
1960+
private EC2DescribeSecurityGroupsResponse listSecurityGroups( String[] interestedGroups ) throws Exception {
19561961
try {
19571962
EC2DescribeSecurityGroupsResponse groupSet = new EC2DescribeSecurityGroupsResponse();
19581963

0 commit comments

Comments
 (0)