mirror of https://github.com/apache/cloudstack.git
Refactoring deletePreallocatedLun and registerPreallocatedLun to new API framework.
This commit is contained in:
parent
1b8965c202
commit
dc6e07ad75
|
|
@ -17,28 +17,15 @@
|
|||
*/
|
||||
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.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.api.response.DeletePreallocatedLunResponse;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
|
||||
@Implementation(method="unregisterPreallocatedLun")
|
||||
public class DeletePreallocatedLunCmd extends BaseCmd {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(DeletePreallocatedLunCmd.class);
|
||||
|
||||
private static final String s_name = "deletePreallocatedLunsResponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
|
@ -47,7 +34,6 @@ public class DeletePreallocatedLunCmd extends BaseCmd {
|
|||
@Parameter(name="id", type=CommandType.LONG, required=true)
|
||||
private Long id;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -56,37 +42,22 @@ public class DeletePreallocatedLunCmd extends BaseCmd {
|
|||
return id;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long id = (Long) params.get(BaseCmd.Properties.ID.getName());
|
||||
|
||||
boolean success = false;
|
||||
ManagementServer ms = getManagementServer();
|
||||
try {
|
||||
success = ms.unregisterPreallocatedLun(id);
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unable to unregister lun ", e);
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Unable to unregister lun due to: " + e.getMessage());
|
||||
}
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.toString(success)));
|
||||
return returnValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
public String getResponse() {
|
||||
Boolean result = (Boolean)getResponseObject();
|
||||
|
||||
DeletePreallocatedLunResponse response = new DeletePreallocatedLunResponse();
|
||||
response.setSuccess(result);
|
||||
|
||||
return SerializerHelper.toSerializedString(response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,33 +17,16 @@
|
|||
*/
|
||||
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.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.api.response.PreallocatedLunResponse;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.storage.preallocatedlun.PreallocatedLunVO;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@Implementation(method="registerPreallocatedLun")
|
||||
public class RegisterPreallocatedLunCmd extends BaseCmd {
|
||||
private static final Logger s_logger = Logger.getLogger(RegisterPreallocatedLunCmd.class);
|
||||
|
||||
private static final String s_name = "registerPreallocatedLunsResponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISK_SIZE, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.LUN, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PORTAL, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TAGS, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TARGET_IQN, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.TRUE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
|
@ -99,52 +82,25 @@ public class RegisterPreallocatedLunCmd extends BaseCmd {
|
|||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
String targetIqn = (String)params.get(BaseCmd.Properties.TARGET_IQN.getName());
|
||||
String portal = (String)params.get(BaseCmd.Properties.PORTAL.getName());
|
||||
Long size = (Long)params.get(BaseCmd.Properties.DISK_SIZE.getName());
|
||||
Long dcId = (Long)params.get(BaseCmd.Properties.ZONE_ID.getName());
|
||||
Integer lun = (Integer)params.get(BaseCmd.Properties.LUN.getName());
|
||||
String t = (String)params.get(BaseCmd.Properties.TAGS.getName());
|
||||
|
||||
PreallocatedLunVO registeredLun = null;
|
||||
ManagementServer ms = getManagementServer();
|
||||
try {
|
||||
registeredLun = ms.registerPreallocatedLun(targetIqn, portal, lun, size, dcId, t);
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unable to register lun", e);
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Unable to register lun");
|
||||
}
|
||||
|
||||
List<Pair<String, Object>> embeddedObject = new ArrayList<Pair<String, Object>>();
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
if (registeredLun == null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to register LUN.");
|
||||
} else {
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), registeredLun.getId()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.VOLUME_ID.getName(), registeredLun.getVolumeId()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), registeredLun.getDataCenterId()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.LUN.getName(), registeredLun.getLun()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.PORTAL.getName(), registeredLun.getPortal()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SIZE.getName(), registeredLun.getSize()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAKEN.getName(), registeredLun.getTaken()));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TARGET_IQN.getName(), registeredLun.getTargetIqn()));
|
||||
|
||||
embeddedObject.add(new Pair<String, Object>("preallocatedlun", new Object[] { returnValues } ));
|
||||
}
|
||||
|
||||
return embeddedObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
public String getResponse() {
|
||||
PreallocatedLunVO preallocatedLun = (PreallocatedLunVO)getResponseObject();
|
||||
|
||||
PreallocatedLunResponse response = new PreallocatedLunResponse();
|
||||
response.setId(preallocatedLun.getId());
|
||||
response.setVolumeId(preallocatedLun.getVolumeId());
|
||||
response.setZoneId(preallocatedLun.getDataCenterId());
|
||||
response.setLun(preallocatedLun.getLun());
|
||||
response.setPortal(preallocatedLun.getPortal());
|
||||
response.setSize(preallocatedLun.getSize());
|
||||
response.setTaken(preallocatedLun.getTaken());
|
||||
response.setTargetIqn(preallocatedLun.getTargetIqn());
|
||||
|
||||
return SerializerHelper.toSerializedString(response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.cloud.api.response;
|
||||
|
||||
import com.cloud.api.ResponseObject;
|
||||
import com.cloud.serializer.Param;
|
||||
|
||||
public class DeletePreallocatedLunResponse implements ResponseObject {
|
||||
@Param(name="success")
|
||||
private Boolean success;
|
||||
|
||||
public Boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
}
|
||||
|
|
@ -30,6 +30,7 @@ import com.cloud.api.commands.CreatePortForwardingServiceRuleCmd;
|
|||
import com.cloud.api.commands.CreateUserCmd;
|
||||
import com.cloud.api.commands.DeleteDomainCmd;
|
||||
import com.cloud.api.commands.DeletePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.DeletePreallocatedLunCmd;
|
||||
import com.cloud.api.commands.DeleteUserCmd;
|
||||
import com.cloud.api.commands.DeployVMCmd;
|
||||
import com.cloud.api.commands.EnableAccountCmd;
|
||||
|
|
@ -75,6 +76,7 @@ import com.cloud.api.commands.LockUserCmd;
|
|||
import com.cloud.api.commands.QueryAsyncJobResultCmd;
|
||||
import com.cloud.api.commands.RebootSystemVmCmd;
|
||||
import com.cloud.api.commands.RegisterCmd;
|
||||
import com.cloud.api.commands.RegisterPreallocatedLunCmd;
|
||||
import com.cloud.api.commands.RemovePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.StartSystemVMCmd;
|
||||
import com.cloud.api.commands.StopSystemVmCmd;
|
||||
|
|
@ -256,23 +258,24 @@ public interface ManagementServer {
|
|||
/**
|
||||
* registerPreallocatedLun registers a preallocated lun in our database.
|
||||
*
|
||||
* @param targetIqn iqn for the storage server.
|
||||
* @param portal portal ip address for the storage server.
|
||||
* @param lun lun #
|
||||
* @param size size of the lun
|
||||
* @param dcId data center to attach to
|
||||
* @param tags tags to attach to the lun
|
||||
* @param cmd the API command wrapping the register parameters
|
||||
* - targetIqn iqn for the storage server.
|
||||
* - portal portal ip address for the storage server.
|
||||
* - lun lun #
|
||||
* - size size of the lun
|
||||
* - dcId data center to attach to
|
||||
* - tags tags to attach to the lun
|
||||
* @return the new PreAllocatedLun
|
||||
*/
|
||||
PreallocatedLunVO registerPreallocatedLun(String targetIqn, String portal, int lun, long size, long dcId, String tags);
|
||||
PreallocatedLunVO registerPreallocatedLun(RegisterPreallocatedLunCmd cmd);
|
||||
|
||||
/**
|
||||
* Unregisters a preallocated lun in our database
|
||||
* @param id id of the lun
|
||||
* @param cmd the api command wrapping the id of the lun
|
||||
* @return true if unregistered; false if not.
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
boolean unregisterPreallocatedLun(long id) throws IllegalArgumentException;
|
||||
boolean unregisterPreallocatedLun(DeletePreallocatedLunCmd cmd) throws IllegalArgumentException;
|
||||
|
||||
String updateAdminPassword(long userId, String oldPassword, String newPassword);
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ import com.cloud.api.commands.CreatePortForwardingServiceRuleCmd;
|
|||
import com.cloud.api.commands.CreateUserCmd;
|
||||
import com.cloud.api.commands.DeleteDomainCmd;
|
||||
import com.cloud.api.commands.DeletePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.DeletePreallocatedLunCmd;
|
||||
import com.cloud.api.commands.DeleteUserCmd;
|
||||
import com.cloud.api.commands.DeployVMCmd;
|
||||
import com.cloud.api.commands.EnableAccountCmd;
|
||||
|
|
@ -106,6 +107,7 @@ import com.cloud.api.commands.LockUserCmd;
|
|||
import com.cloud.api.commands.QueryAsyncJobResultCmd;
|
||||
import com.cloud.api.commands.RebootSystemVmCmd;
|
||||
import com.cloud.api.commands.RegisterCmd;
|
||||
import com.cloud.api.commands.RegisterPreallocatedLunCmd;
|
||||
import com.cloud.api.commands.RemovePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.StartSystemVMCmd;
|
||||
import com.cloud.api.commands.StopSystemVmCmd;
|
||||
|
|
@ -518,7 +520,14 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PreallocatedLunVO registerPreallocatedLun(String targetIqn, String portal, int lun, long size, long dcId, String t) {
|
||||
public PreallocatedLunVO registerPreallocatedLun(RegisterPreallocatedLunCmd cmd) {
|
||||
Long zoneId = cmd.getZoneId();
|
||||
String portal = cmd.getPortal();
|
||||
String targetIqn = cmd.getTargetIqn();
|
||||
Integer lun = cmd.getLun();
|
||||
Long size = cmd.getDiskSize();
|
||||
String t = cmd.getTags();
|
||||
|
||||
String[] tags = null;
|
||||
if (t != null) {
|
||||
tags = t.split(",");
|
||||
|
|
@ -529,12 +538,13 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
tags = new String[0];
|
||||
}
|
||||
|
||||
PreallocatedLunVO vo = new PreallocatedLunVO(dcId, portal, targetIqn, lun, size);
|
||||
PreallocatedLunVO vo = new PreallocatedLunVO(zoneId, portal, targetIqn, lun, size);
|
||||
return _lunDao.persist(vo, tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregisterPreallocatedLun(long id) throws IllegalArgumentException {
|
||||
public boolean unregisterPreallocatedLun(DeletePreallocatedLunCmd cmd) throws IllegalArgumentException {
|
||||
Long id = cmd.getId();
|
||||
PreallocatedLunVO lun = null;
|
||||
if ((lun = _lunDao.findById(id)) == null) {
|
||||
throw new IllegalArgumentException("Unable to find a LUN with ID " + id);
|
||||
|
|
|
|||
Loading…
Reference in New Issue