mirror of https://github.com/apache/cloudstack.git
Refactoring listPreallocatedLuns to new API framework.
This commit is contained in:
parent
2cd9a44267
commit
1d1e10d2d3
|
|
@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TARGET_IQN, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.SCOPE, Boolean.FALSE));
|
||||
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(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<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public String getResponse() {
|
||||
List<PreallocatedLunVO> preallocatedLuns = (List<PreallocatedLunVO>)getResponseObject();
|
||||
|
||||
List<PreallocatedLunResponse> response = new ArrayList<PreallocatedLunResponse>();
|
||||
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<Pair<String, Object>> execute(Map<String, Object> 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<PreallocatedLunVO> preAllocatedLuns = getManagementServer().getPreAllocatedLuns(c);
|
||||
|
||||
if(preAllocatedLuns == null)
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find pre allocated luns");
|
||||
|
||||
List<Pair<String, Object>> preAllocatedLunTags = new ArrayList<Pair<String, Object>>();
|
||||
Object[] sTag = new Object[preAllocatedLuns.size()];
|
||||
int i = 0;
|
||||
for (PreallocatedLunVO lun : preAllocatedLuns)
|
||||
{
|
||||
List<Pair<String, Object>> lunData = new ArrayList<Pair<String, Object>>();
|
||||
|
||||
lunData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), lun.getId()));
|
||||
lunData.add(new Pair<String, Object>(BaseCmd.Properties.VOLUME_ID.getName(), lun.getVolumeId()));
|
||||
lunData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), lun.getDataCenterId()));
|
||||
lunData.add(new Pair<String, Object>(BaseCmd.Properties.LUN.getName(), lun.getLun()));
|
||||
lunData.add(new Pair<String, Object>(BaseCmd.Properties.PORTAL.getName(), lun.getPortal()));
|
||||
lunData.add(new Pair<String, Object>(BaseCmd.Properties.SIZE.getName(), lun.getSize()));
|
||||
lunData.add(new Pair<String, Object>(BaseCmd.Properties.TAKEN.getName(), lun.getTaken()));
|
||||
lunData.add(new Pair<String, Object>(BaseCmd.Properties.TARGET_IQN.getName(), lun.getTargetIqn()));
|
||||
|
||||
sTag[i++] = lunData;
|
||||
}
|
||||
Pair<String, Object> lunTag = new Pair<String, Object>("preallocatedlun", sTag);
|
||||
preAllocatedLunTags.add(lunTag);
|
||||
return preAllocatedLunTags;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<PreallocatedLunVO> getPreAllocatedLuns(Criteria c);
|
||||
public List<PreallocatedLunVO> getPreAllocatedLuns(ListPreallocatedLunsCmd cmd);
|
||||
|
||||
public String getNetworkGroupsNamesForVm(long vmId);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<PreallocatedLunVO> getPreAllocatedLuns(Criteria c)
|
||||
{
|
||||
Filter searchFilter = new Filter(PreallocatedLunVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
|
||||
public List<PreallocatedLunVO> getPreAllocatedLuns(ListPreallocatedLunsCmd cmd) {
|
||||
Filter searchFilter = new Filter(PreallocatedLunVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
SearchCriteria<PreallocatedLunVO> 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue