diff --git a/server/src/com/cloud/api/commands/ListPreallocatedLunsCmd.java b/server/src/com/cloud/api/commands/ListPreallocatedLunsCmd.java index 34c56e62ebc..fd7808de7f9 100644 --- a/server/src/com/cloud/api/commands/ListPreallocatedLunsCmd.java +++ b/server/src/com/cloud/api/commands/ListPreallocatedLunsCmd.java @@ -20,30 +20,21 @@ package com.cloud.api.commands; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; -import com.cloud.api.BaseCmd; +import com.cloud.api.BaseListCmd; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.server.Criteria; +import com.cloud.api.response.PreallocatedLunResponse; +import com.cloud.serializer.SerializerHelper; import com.cloud.storage.preallocatedlun.PreallocatedLunVO; -import com.cloud.utils.Pair; -public class ListPreallocatedLunsCmd extends BaseCmd { +@Implementation(method="getPreAllocatedLuns") +public class ListPreallocatedLunsCmd extends BaseListCmd { public static final Logger s_logger = Logger.getLogger(ListPreallocatedLunsCmd.class.getName()); private static final String s_name = "listpreallocatedlunsresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.TARGET_IQN, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.SCOPE, Boolean.FALSE)); - - s_properties.add(new Pair(BaseCmd.Properties.PAGE, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.PAGESIZE, Boolean.FALSE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -71,68 +62,30 @@ public class ListPreallocatedLunsCmd extends BaseCmd { /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + @Override public String getName() { return s_name; } - public List> getProperties() { - return s_properties; + + @Override @SuppressWarnings("unchecked") + public String getResponse() { + List preallocatedLuns = (List)getResponseObject(); + + List response = new ArrayList(); + for (PreallocatedLunVO preallocatedLun : preallocatedLuns) { + PreallocatedLunResponse preallocLunResponse = new PreallocatedLunResponse(); + preallocLunResponse.setId(preallocatedLun.getId()); + preallocLunResponse.setVolumeId(preallocatedLun.getVolumeId()); + preallocLunResponse.setZoneId(preallocatedLun.getDataCenterId()); + preallocLunResponse.setLun(preallocatedLun.getLun()); + preallocLunResponse.setPortal(preallocatedLun.getPortal()); + preallocLunResponse.setSize(preallocatedLun.getSize()); + preallocLunResponse.setTaken(preallocatedLun.getTaken()); + preallocLunResponse.setTargetIqn(preallocatedLun.getTargetIqn()); + + response.add(preallocLunResponse); + } + + return SerializerHelper.toSerializedString(response); } - - @Override - public List> execute(Map params) { - String targetIqn = (String)params.get(BaseCmd.Properties.TARGET_IQN.getName()); - String scope = (String)params.get(BaseCmd.Properties.SCOPE.getName()); - Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName()); - Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName()); - - Long startIndex = Long.valueOf(0); - int pageSizeNum = 50; - if (pageSize != null) { - pageSizeNum = pageSize.intValue(); - } - if (page != null) { - int pageNum = page.intValue(); - if (pageNum > 0) { - startIndex = Long.valueOf(pageSizeNum * (pageNum-1)); - } - } - Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum)); - if (targetIqn != null) { - c.addCriteria(Criteria.TARGET_IQN, targetIqn); - } - if(scope != null){ - c.addCriteria(Criteria.SCOPE, scope); - } - - List preAllocatedLuns = getManagementServer().getPreAllocatedLuns(c); - - if(preAllocatedLuns == null) - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find pre allocated luns"); - - List> preAllocatedLunTags = new ArrayList>(); - Object[] sTag = new Object[preAllocatedLuns.size()]; - int i = 0; - for (PreallocatedLunVO lun : preAllocatedLuns) - { - List> lunData = new ArrayList>(); - - lunData.add(new Pair(BaseCmd.Properties.ID.getName(), lun.getId())); - lunData.add(new Pair(BaseCmd.Properties.VOLUME_ID.getName(), lun.getVolumeId())); - lunData.add(new Pair(BaseCmd.Properties.ZONE_ID.getName(), lun.getDataCenterId())); - lunData.add(new Pair(BaseCmd.Properties.LUN.getName(), lun.getLun())); - lunData.add(new Pair(BaseCmd.Properties.PORTAL.getName(), lun.getPortal())); - lunData.add(new Pair(BaseCmd.Properties.SIZE.getName(), lun.getSize())); - lunData.add(new Pair(BaseCmd.Properties.TAKEN.getName(), lun.getTaken())); - lunData.add(new Pair(BaseCmd.Properties.TARGET_IQN.getName(), lun.getTargetIqn())); - - sTag[i++] = lunData; - } - Pair lunTag = new Pair("preallocatedlun", sTag); - preAllocatedLunTags.add(lunTag); - return preAllocatedLunTags; - - - } - - } \ No newline at end of file diff --git a/server/src/com/cloud/api/response/PreallocatedLunResponse.java b/server/src/com/cloud/api/response/PreallocatedLunResponse.java new file mode 100644 index 00000000000..018c03768cd --- /dev/null +++ b/server/src/com/cloud/api/response/PreallocatedLunResponse.java @@ -0,0 +1,96 @@ +package com.cloud.api.response; + +import java.util.Date; + +import com.cloud.api.ResponseObject; +import com.cloud.serializer.Param; + +public class PreallocatedLunResponse implements ResponseObject { + @Param(name="id") + private Long id; + + @Param(name="volumeid") + private Long volumeId; + + @Param(name="zoneid") + private Long zoneId; + + @Param(name="lun") + private Integer lun; + + @Param(name="portal") + private String portal; + + @Param(name="size") + private Long size; + + @Param(name="taken") + private Date taken; + + @Param(name="targetiqn") + private String targetIqn; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getVolumeId() { + return volumeId; + } + + public void setVolumeId(Long volumeId) { + this.volumeId = volumeId; + } + + public Long getZoneId() { + return zoneId; + } + + public void setZoneId(Long zoneId) { + this.zoneId = zoneId; + } + + public Integer getLun() { + return lun; + } + + public void setLun(Integer lun) { + this.lun = lun; + } + + public String getPortal() { + return portal; + } + + public void setPortal(String portal) { + this.portal = portal; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public Date getTaken() { + return taken; + } + + public void setTaken(Date taken) { + this.taken = taken; + } + + public String getTargetIqn() { + return targetIqn; + } + + public void setTargetIqn(String targetIqn) { + this.targetIqn = targetIqn; + } +} diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 6d86c021b7e..f3603b64f66 100644 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -50,6 +50,7 @@ import com.cloud.api.commands.ListPodsByCmd; import com.cloud.api.commands.ListPortForwardingServiceRulesCmd; import com.cloud.api.commands.ListPortForwardingServicesByVmCmd; import com.cloud.api.commands.ListPortForwardingServicesCmd; +import com.cloud.api.commands.ListPreallocatedLunsCmd; import com.cloud.api.commands.ListTemplatesCmd; import com.cloud.api.commands.LockAccountCmd; import com.cloud.api.commands.LockUserCmd; @@ -1931,7 +1932,7 @@ public interface ManagementServer { */ boolean isLocalStorageActiveOnHost(HostVO host); - public List getPreAllocatedLuns(Criteria c); + public List getPreAllocatedLuns(ListPreallocatedLunsCmd cmd); public String getNetworkGroupsNamesForVm(long vmId); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 6705d537b40..617ee15040a 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -88,6 +88,7 @@ import com.cloud.api.commands.ListPodsByCmd; import com.cloud.api.commands.ListPortForwardingServiceRulesCmd; import com.cloud.api.commands.ListPortForwardingServicesByVmCmd; import com.cloud.api.commands.ListPortForwardingServicesCmd; +import com.cloud.api.commands.ListPreallocatedLunsCmd; import com.cloud.api.commands.ListTemplatesCmd; import com.cloud.api.commands.LockAccountCmd; import com.cloud.api.commands.LockUserCmd; @@ -8357,13 +8358,12 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public List getPreAllocatedLuns(Criteria c) - { - Filter searchFilter = new Filter(PreallocatedLunVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit()); + public List getPreAllocatedLuns(ListPreallocatedLunsCmd cmd) { + Filter searchFilter = new Filter(PreallocatedLunVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchCriteria sc = _lunDao.createSearchCriteria(); - Object targetIqn = c.getCriteria(Criteria.TARGET_IQN); - Object scope = c.getCriteria(Criteria.SCOPE); + Object targetIqn = cmd.getTargetIqn(); + Object scope = cmd.getScope(); if (targetIqn != null) { sc.addAnd("targetIqn", SearchCriteria.Op.EQ, targetIqn); @@ -8371,24 +8371,19 @@ public class ManagementServerImpl implements ManagementServer { if (scope == null || scope.toString().equalsIgnoreCase("ALL")) { return _lunDao.search(sc, searchFilter); - } - else if(scope.toString().equalsIgnoreCase("ALLOCATED")) - { + } else if(scope.toString().equalsIgnoreCase("ALLOCATED")) { sc.addAnd("volumeId", SearchCriteria.Op.NNULL); sc.addAnd("taken", SearchCriteria.Op.NNULL); return _lunDao.search(sc, searchFilter); - } - else if(scope.toString().equalsIgnoreCase("FREE")) - { + } else if(scope.toString().equalsIgnoreCase("FREE")) { sc.addAnd("volumeId", SearchCriteria.Op.NULL); sc.addAnd("taken", SearchCriteria.Op.NULL); return _lunDao.search(sc, searchFilter); } - - return null; + return null; } @Override