Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 90E8AEC3F for ; Tue, 12 Feb 2013 23:10:30 +0000 (UTC) Received: (qmail 69349 invoked by uid 500); 12 Feb 2013 23:10:29 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 69285 invoked by uid 500); 12 Feb 2013 23:10:29 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 69044 invoked by uid 99); 12 Feb 2013 23:10:29 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Feb 2013 23:10:29 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id E73E3519D3; Tue, 12 Feb 2013 23:10:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: prachidamle@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [3/8] git commit: refs/heads/4.1 - CLOUDSTACK-1128: [EC2 Query API] DescribeAvailabilityZones, support for message filter Message-Id: <20130212231028.E73E3519D3@tyr.zones.apache.org> Date: Tue, 12 Feb 2013 23:10:28 +0000 (UTC) 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 Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/ee90ebfc Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/ee90ebfc Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/ee90ebfc Branch: refs/heads/4.1 Commit: ee90ebfc00dff37a2eb5be372d8aa955176f7025 Parents: 961c8ee Author: Prachi Damle Authored: Tue Feb 12 13:34:49 2013 -0800 Committer: Prachi Damle Committed: Tue Feb 12 13:45:29 2013 -0800 ---------------------------------------------------------------------- .../cloud/bridge/service/EC2SoapServiceImpl.java | 15 +++-- .../service/core/ec2/EC2AvailabilityZone.java | 55 +++++++++++++++ .../core/ec2/EC2AvailabilityZonesFilterSet.java | 21 ++++-- .../ec2/EC2DescribeAvailabilityZonesResponse.java | 36 +++------- .../cloud/bridge/service/core/ec2/EC2Engine.java | 43 ++++++----- 5 files changed, 113 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ee90ebfc/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java b/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java index bf3c13e..442b460 100644 --- a/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java +++ b/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java @@ -41,6 +41,7 @@ import com.cloud.bridge.service.core.ec2.EC2DescribeAvailabilityZones; import com.cloud.bridge.service.core.ec2.EC2DescribeAvailabilityZonesResponse; import com.cloud.bridge.service.core.ec2.EC2DescribeImageAttribute; +import com.cloud.bridge.service.core.ec2.EC2AvailabilityZone; import com.cloud.bridge.service.core.ec2.EC2DescribeImages; import com.cloud.bridge.service.core.ec2.EC2DescribeImagesResponse; import com.cloud.bridge.service.core.ec2.EC2DescribeInstances; @@ -1775,14 +1776,18 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface { DescribeAvailabilityZonesResponse response = new DescribeAvailabilityZonesResponse(); DescribeAvailabilityZonesResponseType param1 = new DescribeAvailabilityZonesResponseType(); AvailabilityZoneSetType param2 = new AvailabilityZoneSetType(); - - String[] zones = engineResponse.getZoneSet(); - for (String zone : zones) { + + EC2AvailabilityZone[] zones = engineResponse.getAvailabilityZoneSet(); + for (EC2AvailabilityZone zone : zones) { AvailabilityZoneItemType param3 = new AvailabilityZoneItemType(); - AvailabilityZoneMessageSetType param4 = new AvailabilityZoneMessageSetType(); - param3.setZoneName( zone ); + param3.setZoneName( zone.getName() ); param3.setZoneState( "available" ); param3.setRegionName( "" ); + + AvailabilityZoneMessageSetType param4 = new AvailabilityZoneMessageSetType(); + AvailabilityZoneMessageType param5 = new AvailabilityZoneMessageType(); + param5.setMessage(zone.getMessage()); + param4.addItem(param5); param3.setMessageSet( param4 ); param2.addItem( param3 ); } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ee90ebfc/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZone.java ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZone.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZone.java new file mode 100644 index 0000000..457c6ef --- /dev/null +++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZone.java @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.bridge.service.core.ec2; + +public class EC2AvailabilityZone { + + private String id; + private String name; + private String message; + + public EC2AvailabilityZone() { + id = null; + name = null; + message = null; + } + + public void setId( String id ) { + this.id = id; + } + + public String getId() { + return this.id; + } + + public void setName( String name ) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public void setMessage( String message ) { + this.message = message; + } + + public String getMessage() { + return this.message; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ee90ebfc/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZonesFilterSet.java ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZonesFilterSet.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZonesFilterSet.java index 994b721..aa3897a 100644 --- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZonesFilterSet.java +++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2AvailabilityZonesFilterSet.java @@ -36,6 +36,7 @@ public class EC2AvailabilityZonesFilterSet { public EC2AvailabilityZonesFilterSet() { // -> use these values to check that the proper filter is passed to this type of filter set filterTypes.put( "zone-name", "String" ); + filterTypes.put( "message", "String"); } public void addFilter( EC2Filter param ) { @@ -55,13 +56,14 @@ public class EC2AvailabilityZonesFilterSet { return filterSet.toArray(new EC2Filter[0]); } - public List evaluate( EC2DescribeAvailabilityZonesResponse availabilityZones) throws ParseException { - List resultList = new ArrayList(); + public EC2DescribeAvailabilityZonesResponse evaluate( EC2DescribeAvailabilityZonesResponse availabilityZones) + throws ParseException { + EC2DescribeAvailabilityZonesResponse resultList = new EC2DescribeAvailabilityZonesResponse(); boolean matched; EC2Filter[] filterSet = getFilterSet(); - for ( String availableZone : availabilityZones.getZoneSet() ) { + for ( EC2AvailabilityZone availableZone : availabilityZones.getAvailabilityZoneSet() ) { matched = true; if (filterSet != null) { for (EC2Filter filter : filterSet) { @@ -71,19 +73,22 @@ public class EC2AvailabilityZonesFilterSet { } } } - if (matched == true) - resultList.add(availableZone); + if (matched) + resultList.addAvailabilityZone(availableZone); } return resultList; } - private boolean filterMatched( String availableZone, EC2Filter filter ) throws ParseException { + private boolean filterMatched( EC2AvailabilityZone availableZone, EC2Filter filter ) throws ParseException { String filterName = filter.getName(); String[] valueSet = filter.getValueSet(); if ( filterName.equalsIgnoreCase("zone-name")) { - return containsString(availableZone, valueSet); - } + return containsString(availableZone.getName(), valueSet); + } + else if (filterName.equalsIgnoreCase("message")) { + return containsString(availableZone.getMessage(), valueSet); + } return false; } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ee90ebfc/awsapi/src/com/cloud/bridge/service/core/ec2/EC2DescribeAvailabilityZonesResponse.java ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2DescribeAvailabilityZonesResponse.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2DescribeAvailabilityZonesResponse.java index ae0c233..f9bc6b6 100644 --- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2DescribeAvailabilityZonesResponse.java +++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2DescribeAvailabilityZonesResponse.java @@ -20,31 +20,17 @@ import java.util.ArrayList; import java.util.List; public class EC2DescribeAvailabilityZonesResponse { + private List availabilityZoneSet = new ArrayList(); - private List zoneIds = new ArrayList(); - private List zoneNames = new ArrayList(); + public EC2DescribeAvailabilityZonesResponse() { + } + + public void addAvailabilityZone( EC2AvailabilityZone param ) { + availabilityZoneSet.add( param ); + } + + public EC2AvailabilityZone[] getAvailabilityZoneSet() { + return availabilityZoneSet.toArray(new EC2AvailabilityZone[0]); + } - public EC2DescribeAvailabilityZonesResponse() { - } - - public void addZone(String id, String name) { - zoneIds.add(id); - zoneNames.add(name); - } - - /** - * The Amazon API only cares about the names of zones not their ID value. - * - * @return an array containing a set of zone names - */ - public String[] getZoneSet() { - return zoneNames.toArray(new String[0]); - } - - public String getZoneIdAt(int index) { - if (zoneIds.isEmpty() || index >= zoneIds.size()) { - return null; - } - return zoneIds.get(index); - } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ee90ebfc/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java index b729f77..1d278a2 100644 --- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java +++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java @@ -1060,12 +1060,8 @@ public class EC2Engine extends ManagerBase { EC2AvailabilityZonesFilterSet azfs = request.getFilterSet(); if ( null == azfs ) return availableZones; - else { - List matchedAvailableZones = azfs.evaluate(availableZones); - if (matchedAvailableZones.isEmpty()) - return new EC2DescribeAvailabilityZonesResponse(); - return listZones(matchedAvailableZones.toArray(new String[0]), null); - } + else + return azfs.evaluate(availableZones); } catch( EC2ServiceException error ) { logger.error( "EC2 DescribeAvailabilityZones - ", error); throw error; @@ -1691,9 +1687,11 @@ public class EC2Engine extends ManagerBase { zones = listZones(interestedZones, domainId); - if (zones == null || zones.getZoneIdAt( 0 ) == null) + if (zones == null || zones.getAvailabilityZoneSet().length == 0) throw new EC2ServiceException(ClientError.InvalidParameterValue, "Unknown zoneName value - " + zoneName); - return zones.getZoneIdAt(0); + + EC2AvailabilityZone[] zoneSet = zones.getAvailabilityZoneSet(); + return zoneSet[0].getId(); } @@ -1768,24 +1766,31 @@ public class EC2Engine extends ManagerBase { * * @return EC2DescribeAvailabilityZonesResponse */ - private EC2DescribeAvailabilityZonesResponse listZones(String[] interestedZones, String domainId) throws Exception - { + private EC2DescribeAvailabilityZonesResponse listZones(String[] interestedZones, String domainId) + throws Exception { EC2DescribeAvailabilityZonesResponse zones = new EC2DescribeAvailabilityZonesResponse(); List cloudZones = getApi().listZones(true, domainId, null, null); - - if(cloudZones != null) { + if(cloudZones != null && cloudZones.size() > 0) { for(CloudStackZone cloudZone : cloudZones) { - if ( null != interestedZones && 0 < interestedZones.length ) { - for( int j=0; j < interestedZones.length; j++ ) { - if (interestedZones[j].equalsIgnoreCase( cloudZone.getName())) { - zones.addZone(cloudZone.getId().toString(), cloudZone.getName()); + boolean matched = false; + if (interestedZones.length > 0) { + for (String zoneName : interestedZones){ + if (zoneName.equalsIgnoreCase( cloudZone.getName())) { + matched = true; break; } } - } else { - zones.addZone(cloudZone.getId().toString(), cloudZone.getName()); + } else { + matched = true; } + if (!matched) continue; + EC2AvailabilityZone ec2Zone = new EC2AvailabilityZone(); + ec2Zone.setId(cloudZone.getId().toString()); + ec2Zone.setMessage(cloudZone.getAllocationState()); + ec2Zone.setName(cloudZone.getName()); + + zones.addAvailabilityZone(ec2Zone); } } return zones; @@ -1952,7 +1957,7 @@ public class EC2Engine extends ManagerBase { * @throws ParserConfigurationException * @throws ParseException */ - public EC2DescribeSecurityGroupsResponse listSecurityGroups( String[] interestedGroups ) throws Exception { + private EC2DescribeSecurityGroupsResponse listSecurityGroups( String[] interestedGroups ) throws Exception { try { EC2DescribeSecurityGroupsResponse groupSet = new EC2DescribeSecurityGroupsResponse();