Merge branch '2.1.refactor' of ssh://git.cloud.com/var/lib/git/cloudstack-oss into 2.1.refactor

This commit is contained in:
abhishek 2010-08-18 16:15:09 -07:00
commit 2c670609b1
14 changed files with 407 additions and 334 deletions

View File

@ -17,13 +17,14 @@
*/
package com.cloud.agent.manager;
import java.net.URI;
import java.util.List;
import java.util.Set;
import com.cloud.agent.Listener;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.api.commands.AddHostCmd;
import com.cloud.api.commands.AddHostOrStorageCmd;
import com.cloud.api.commands.DeleteHostCmd;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
@ -220,5 +221,5 @@ public interface AgentManager extends Manager {
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException;
public boolean reconnect(final long hostId) throws AgentUnavailableException;
public List<HostVO> discoverHosts(long dcId, Long podId, Long clusterId, URI url, String username, String password) throws DiscoveryException;
public List<HostVO> discoverHosts(AddHostOrStorageCmd cmd) throws DiscoveryException, InvalidParameterValueException;
}

View File

@ -20,6 +20,7 @@ package com.cloud.agent.manager;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.ClosedChannelException;
import java.util.ArrayList;
import java.util.Enumeration;
@ -69,8 +70,8 @@ import com.cloud.agent.transport.Request;
import com.cloud.agent.transport.Response;
import com.cloud.agent.transport.UpgradeResponse;
import com.cloud.alert.AlertManager;
import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException;
import com.cloud.api.commands.AddHostCmd;
import com.cloud.api.commands.AddHostOrStorageCmd;
import com.cloud.api.commands.DeleteHostCmd;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
@ -95,10 +96,10 @@ import com.cloud.exception.UnsupportedVersionException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.host.DetailVO;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.host.HostStats;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.Host.Type;
import com.cloud.host.Status.Event;
import com.cloud.host.dao.DetailsDao;
import com.cloud.host.dao.HostDao;
@ -472,13 +473,85 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
}
@Override
public List<HostVO> discoverHosts(long dcId, Long podId, Long clusterId, URI url, String username, String password) throws IllegalArgumentException, DiscoveryException {
public List<HostVO> discoverHosts(AddHostOrStorageCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
Long dcId = cmd.getZoneId();
Long podId = cmd.getPodId();
Long clusterId = cmd.getClusterId();
String clusterName = cmd.getName();
String url = cmd.getUrl();
String username = cmd.getUsername();
String password = cmd.getPassword();
URI uri = null;
//Check if the zone exists in the system
if (_dcDao.findById(dcId) == null ){
throw new InvalidParameterValueException("Can't find zone by id " + dcId);
}
//Check if the pod exists in the system
if (podId != null) {
if (_podDao.findById(podId) == null ){
throw new InvalidParameterValueException("Can't find pod by id " + podId);
}
//check if pod belongs to the zone
HostPodVO pod = _podDao.findById(podId);
if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) {
throw new InvalidParameterValueException("Pod " + podId + " doesn't belong to the zone " + dcId);
}
}
// Deny to add a secondary storage multiple times for the same zone
if ((username == null) && (_hostDao.findSecondaryStorageHost(dcId) != null)) {
throw new InvalidParameterValueException("A secondary storage host already exists in the specified zone");
}
//Verify cluster information and create a new cluster if needed
if (clusterName != null && clusterId != null) {
throw new InvalidParameterValueException("Can't specify cluster by both id and name");
}
if ((clusterName != null || clusterId != null) && podId == null) {
throw new InvalidParameterValueException("Can't specify cluster without specifying the pod");
}
if (clusterId != null) {
if (_clusterDao.findById(clusterId) == null) {
throw new InvalidParameterValueException("Can't find cluster by id " + clusterId);
}
}
if (clusterName != null) {
ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
try {
cluster = _clusterDao.persist(cluster);
} catch (Exception e) {
cluster = _clusterDao.findBy(clusterName, podId);
if (cluster == null) {
throw new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod " + podId + " and data center " + dcId, e);
}
}
clusterId = cluster.getId();
}
try {
uri = new URI(url);
if (uri.getScheme() == null)
throw new InvalidParameterValueException("uri.scheme is null " + url + ", add nfs:// as a prefix");
else if (uri.getScheme().equalsIgnoreCase("nfs")) {
if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
throw new InvalidParameterValueException("Your host and/or path is wrong. Make sure it's of the format nfs://hostname/path");
}
}
} catch (URISyntaxException e) {
throw new InvalidParameterValueException(url + " is not a valid uri");
}
List<HostVO> hosts = new ArrayList<HostVO>();
s_logger.info("Trying to add a new host at " + url + " in data center " + dcId);
Enumeration<Discoverer> en = _discoverers.enumeration();
while (en.hasMoreElements()) {
Discoverer discoverer = en.nextElement();
Map<? extends ServerResource, Map<String, String>> resources = discoverer.find(dcId, podId, clusterId, url, username, password);
Map<? extends ServerResource, Map<String, String>> resources = discoverer.find(dcId, podId, clusterId, uri, username, password);
if (resources != null) {
for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
ServerResource resource = entry.getKey();

View File

@ -25,79 +25,12 @@ import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@Implementation(method="discoverHosts", manager=Manager.ManagementServer)
public class AddHostCmd extends BaseCmd {
@Implementation(method="discoverHosts", manager=Manager.AgentManager)
public class AddHostCmd extends AddHostOrStorageCmd {
public static final Logger s_logger = Logger.getLogger(AddHostCmd.class.getName());
private static final String s_name = "addhostresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name="clusterid", type=CommandType.LONG)
private Long clusterId;
@Parameter(name="clustername", type=CommandType.STRING)
private String clusterName;
@Parameter(name="password", type=CommandType.STRING, required=true)
private String password;
@Parameter(name="podid", type=CommandType.LONG)
private Long podId;
@Parameter(name="url", type=CommandType.STRING, required=true)
private String url;
@Parameter(name="username", type=CommandType.STRING, required=true)
private String username;
@Parameter(name="zoneid", type=CommandType.LONG, required=true)
private Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getClusterId() {
return clusterId;
}
public String getClusterName() {
return clusterName;
}
public String getPassword() {
return password;
}
public Long getPodId() {
return podId;
}
public String getUrl() {
return url;
}
public String getUsername() {
return username;
}
public Long getZoneId() {
return zoneId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
}
private static final String s_name = "addhostresponse";
/*
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params)

View File

@ -0,0 +1,102 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@Implementation(method="discoverHosts", manager=Manager.AgentManager)
public abstract class AddHostOrStorageCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddHostOrStorageCmd.class.getName());
private static final String s_name = "addhostorstorageresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name="clusterid", type=CommandType.LONG)
private Long clusterId;
@Parameter(name="clustername", type=CommandType.STRING)
private String clusterName;
@Parameter(name="password", type=CommandType.STRING, required=true)
private String password;
@Parameter(name="podid", type=CommandType.LONG)
private Long podId;
@Parameter(name="url", type=CommandType.STRING, required=true)
private String url;
@Parameter(name="username", type=CommandType.STRING, required=true)
private String username;
@Parameter(name="zoneid", type=CommandType.LONG, required=true)
private Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getClusterId() {
return clusterId;
}
public String getClusterName() {
return clusterName;
}
public String getPassword() {
return password;
}
public Long getPodId() {
return podId;
}
public String getUrl() {
return url;
}
public String getUsername() {
return username;
}
public Long getZoneId() {
return zoneId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
}
}

View File

@ -25,43 +25,35 @@ import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@Implementation(method="discoverHosts", manager=Manager.ManagementServer)
public class AddSecondaryStorageCmd extends BaseCmd {
@Implementation(method="discoverHosts", manager=Manager.AgentManager)
public class AddSecondaryStorageCmd extends AddHostOrStorageCmd {
public static final Logger s_logger = Logger.getLogger(AddSecondaryStorageCmd.class.getName());
private static final String s_name = "addsecondarystorageresponse";
private static final String s_name = "addsecondarystorageresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name="url", type=CommandType.STRING, required=true)
private String url;
@Parameter(name="zoneid", type=CommandType.LONG)
private Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getUrl() {
return url;
public Long getClusterId() {
return null;
}
public String getClusterName() {
return null;
}
public Long getZoneId() {
return zoneId;
public String getPassword() {
return null;
}
public Long getPodId() {
return null;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
}
public String getUsername() {
return null;
}
/*
@Override

View File

@ -1,28 +1,17 @@
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.BaseCmd.Manager;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.StoragePoolVO;
import com.cloud.utils.Pair;
@Implementation(method="deleteHost", manager=Manager.StorageManager)
public class DeletePoolCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(DeletePoolCmd.class.getName());
private static final String s_name = "deletepoolresponse";
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 /////////////////////
/////////////////////////////////////////////////////
@ -48,40 +37,36 @@ public class DeletePoolCmd extends BaseCmd {
public String getName() {
return s_name;
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Long poolId = (Long) params.get(BaseCmd.Properties.ID.getName());
//verify parameters
StoragePoolVO sPool = getManagementServer().findPoolById(poolId);
if (sPool == null) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find pool by id " + poolId);
}
if (sPool.getPoolType().equals(StoragePoolType.LVM)) {
throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "Unable to delete local storage id: " + poolId);
}
boolean deleted = true;
try {
deleted = getManagementServer().deletePool(poolId);
} catch (Exception ex) {
s_logger.error("Exception deleting pool", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
if (!deleted) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Volumes exist on primary storage, unable to delete");
}
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
return returnValues;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Long poolId = (Long) params.get(BaseCmd.Properties.ID.getName());
//
// //verify parameters
// StoragePoolVO sPool = getManagementServer().findPoolById(poolId);
// if (sPool == null) {
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find pool by id " + poolId);
// }
//
// if (sPool.getPoolType().equals(StoragePoolType.LVM)) {
// throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "Unable to delete local storage id: " + poolId);
// }
//
// boolean deleted = true;
// try {
// deleted = getManagementServer().deletePool(poolId);
//
// } catch (Exception ex) {
// s_logger.error("Exception deleting pool", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
// }
// if (!deleted) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Volumes exist on primary storage, unable to delete");
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
//
// return returnValues;
// }
}

View File

@ -58,10 +58,6 @@ public class EnableUserCmd extends BaseCmd {
return s_name;
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {

View File

@ -26,60 +26,20 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@Implementation(method="updateTemplate", manager=Manager.ManagementServer)
public class UpdateIsoCmd extends BaseCmd {
public class UpdateIsoCmd extends UpdateTemplateOrIsoCmd {
public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName());
private static final String s_name = "updateisoresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name="bootable", type=CommandType.BOOLEAN)
private Boolean bootable;
@Parameter(name="displaytext", type=CommandType.STRING)
private String displayText;
@Parameter(name="id", type=CommandType.LONG, required=true)
private Long id;
@Parameter(name="name", type=CommandType.STRING)
private String isoName;
@Parameter(name="ostypeid", type=CommandType.LONG)
private Long osTypeId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Boolean isBootable() {
return bootable;
public Boolean isPasswordEnabled() {
return null;
}
public String getDisplayText() {
return displayText;
}
public Long getId() {
return id;
}
public String isoName() {
return isoName;
}
public Long getOsTypeId() {
return osTypeId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
public String getFormat() {
return null;
}
// @Override

View File

@ -26,72 +26,18 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@Implementation(method="updateTemplate", manager=Manager.ManagementServer)
public class UpdateTemplateCmd extends BaseCmd {
public class UpdateTemplateCmd extends UpdateTemplateOrIsoCmd {
public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName());
private static final String s_name = "updatetemplateresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name="displaytext", type=CommandType.STRING)
private String displayText;
@Parameter(name="format", type=CommandType.STRING)
private String format;
@Parameter(name="id", type=CommandType.LONG, required=true)
private Long id;
@Parameter(name="name", type=CommandType.STRING)
private String templateName;
@Parameter(name="ostypeid", type=CommandType.LONG)
private Long osTypeId;
@Parameter(name="passwordenabled", type=CommandType.BOOLEAN)
private Boolean passwordEnabled;
private static final String s_name = "updatetemplateresponse";
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getDisplayText() {
return displayText;
}
public String getFormat() {
return format;
}
public Long getId() {
return id;
}
public String getTemplateName() {
return templateName;
}
public Long getOsTypeId() {
return osTypeId;
}
public Boolean isPasswordEnabled() {
return passwordEnabled;
}
public Boolean isBootable() {
return true;
return null;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {

View File

@ -0,0 +1,85 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@Implementation(method="updateTemplate", manager=Manager.ManagementServer)
public abstract class UpdateTemplateOrIsoCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName());
private static final String s_name = "updatetemplateorisoresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name="bootable", type=CommandType.BOOLEAN)
private Boolean bootable;
@Parameter(name="displaytext", type=CommandType.STRING)
private String displayText;
@Parameter(name="id", type=CommandType.LONG, required=true)
private Long id;
@Parameter(name="name", type=CommandType.STRING)
private String isoName;
@Parameter(name="ostypeid", type=CommandType.LONG)
private Long osTypeId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Boolean isBootable() {
return bootable;
}
public String getDisplayText() {
return displayText;
}
public Long getId() {
return id;
}
public String isoName() {
return isoName;
}
public Long getOsTypeId() {
return osTypeId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
}
}

View File

@ -34,6 +34,7 @@ import com.cloud.api.commands.StopSystemVmCmd;
import com.cloud.api.commands.UpdateAccountCmd;
import com.cloud.api.commands.UpdateDomainCmd;
import com.cloud.api.commands.UpdateTemplateCmd;
import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
import com.cloud.api.commands.UpdateTemplateOrIsoPermissionsCmd;
import com.cloud.api.commands.UpdateUserCmd;
import com.cloud.async.AsyncJobResult;
@ -137,7 +138,7 @@ public interface ManagementServer {
ClusterVO findClusterById(long clusterId);
List<ClusterVO> listClusterByPodId(long podId);
ClusterVO createCluster(long dcId, long podId, String name);
// ClusterVO createCluster(long dcId, long podId, String name);
/**
* Creates a new user, does not encrypt the password
@ -272,18 +273,18 @@ public interface ManagementServer {
boolean unregisterPreallocatedLun(long id) throws IllegalArgumentException;
/**
* Discovers new hosts given an url to locate the resource.
* @param dcId id of the data center
* @param podid id of the pod
* @param clusterId id of the cluster
* @param url url to use
* @param username username to use to login
* @param password password to use to login
* @return true if hosts were found; false if not.
* @throws IllegalArgumentException
*/
List<? extends Host> discoverHosts(long dcId, Long podId, Long clusterId, String url, String username, String password) throws IllegalArgumentException, DiscoveryException;
// /**
// * Discovers new hosts given an url to locate the resource.
// * @param dcId id of the data center
// * @param podid id of the pod
// * @param clusterId id of the cluster
// * @param url url to use
// * @param username username to use to login
// * @param password password to use to login
// * @return true if hosts were found; false if not.
// * @throws IllegalArgumentException
// */
// List<? extends Host> discoverHosts(long dcId, Long podId, Long clusterId, String url, String username, String password) throws IllegalArgumentException, DiscoveryException;
String updateAdminPassword(long userId, String oldPassword, String newPassword);
@ -1152,7 +1153,7 @@ public interface ManagementServer {
* @param cmd
* @return success/failure
*/
boolean updateTemplate(UpdateTemplateCmd cmd) throws InvalidParameterValueException;
boolean updateTemplate(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException;
/**
* Creates a template by downloading to all zones
@ -2001,13 +2002,6 @@ public interface ManagementServer {
List<SecondaryStorageVmVO> searchForSecondaryStorageVm(Criteria c);
/**
* Deletes a pool based on the pool id
* @param id -- pool id
* @return -- status of the operation
*/
boolean deletePool(Long id);
/**
* Returns back a SHA1 signed response

View File

@ -86,6 +86,7 @@ import com.cloud.api.commands.UpdateAccountCmd;
import com.cloud.api.commands.UpdateDomainCmd;
import com.cloud.api.commands.UpdateIsoPermissionsCmd;
import com.cloud.api.commands.UpdateTemplateCmd;
import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
import com.cloud.api.commands.UpdateTemplateOrIsoPermissionsCmd;
import com.cloud.api.commands.UpdateTemplatePermissionsCmd;
import com.cloud.api.commands.UpdateUserCmd;
@ -112,15 +113,15 @@ import com.cloud.async.executor.ResetVMPasswordParam;
import com.cloud.async.executor.SecurityGroupParam;
import com.cloud.async.executor.UpdateLoadBalancerParam;
import com.cloud.async.executor.VMOperationParam;
import com.cloud.async.executor.VolumeOperationParam;
import com.cloud.async.executor.VMOperationParam.VmOp;
import com.cloud.async.executor.VolumeOperationParam;
import com.cloud.async.executor.VolumeOperationParam.VolumeOp;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.ConfigurationVO;
import com.cloud.configuration.ResourceLimitVO;
import com.cloud.configuration.ResourceCount.ResourceType;
import com.cloud.configuration.ResourceLimitVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.configuration.dao.ResourceLimitDao;
import com.cloud.consoleproxy.ConsoleProxyManager;
@ -130,8 +131,8 @@ import com.cloud.dc.DataCenterIpAddressVO;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.PodVlanMapVO;
import com.cloud.dc.VlanVO;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.VlanVO;
import com.cloud.dc.dao.AccountVlanMapDao;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
@ -197,22 +198,22 @@ import com.cloud.storage.GuestOSCategoryVO;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.LaunchPermissionVO;
import com.cloud.storage.Snapshot;
import com.cloud.storage.Snapshot.SnapshotType;
import com.cloud.storage.SnapshotPolicyVO;
import com.cloud.storage.SnapshotScheduleVO;
import com.cloud.storage.SnapshotVO;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.FileSystem;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.StorageStats;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume.VolumeType;
import com.cloud.storage.VolumeStats;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.Snapshot.SnapshotType;
import com.cloud.storage.Storage.FileSystem;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Volume.VolumeType;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.DiskTemplateDao;
import com.cloud.storage.dao.GuestOSCategoryDao;
@ -222,9 +223,9 @@ import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.dao.SnapshotPolicyDao;
import com.cloud.storage.dao.StoragePoolDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateDao.TemplateFilter;
import com.cloud.storage.dao.VMTemplateHostDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.dao.VMTemplateDao.TemplateFilter;
import com.cloud.storage.preallocatedlun.PreallocatedLunVO;
import com.cloud.storage.preallocatedlun.dao.PreallocatedLunDao;
import com.cloud.storage.secondary.SecondaryStorageVmManager;
@ -246,12 +247,12 @@ import com.cloud.user.dao.UserDao;
import com.cloud.user.dao.UserStatisticsDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.DateUtil;
import com.cloud.utils.DateUtil.IntervalType;
import com.cloud.utils.EnumUtils;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.StringUtils;
import com.cloud.utils.DateUtil.IntervalType;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.concurrency.NamedThreadFactory;
@ -506,17 +507,17 @@ public class ManagementServerImpl implements ManagementServer {
return _configs;
}
@Override
public List<? extends Host> discoverHosts(long dcId, Long podId, Long clusterId, String url, String username, String password) throws IllegalArgumentException, DiscoveryException {
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Unable to convert the url" + url, e);
}
// TODO: parameter checks.
return _agentMgr.discoverHosts(dcId, podId, clusterId, uri, username, password);
}
// @Override
// public List<? extends Host> discoverHosts(long dcId, Long podId, Long clusterId, String url, String username, String password) throws IllegalArgumentException, DiscoveryException {
// URI uri;
// try {
// uri = new URI(url);
// } catch (URISyntaxException e) {
// throw new IllegalArgumentException("Unable to convert the url" + url, e);
// }
// // TODO: parameter checks.
// return _agentMgr.discoverHosts(dcId, podId, clusterId, uri, username, password);
// }
@Override
public StorageStats getStorageStatistics(long hostId) {
@ -4639,7 +4640,7 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public boolean updateTemplate(UpdateTemplateCmd cmd) throws InvalidParameterValueException {
public boolean updateTemplate(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException {
Long id = cmd.getId();
String name = cmd.getName();
String displayText = cmd.getDisplayText();
@ -7607,25 +7608,19 @@ public class ManagementServerImpl implements ManagementServer {
return _clusterDao.listByPodId(podId);
}
@Override
public ClusterVO createCluster(long dcId, long podId, String name) {
ClusterVO cluster = new ClusterVO(dcId, podId, name);
try {
cluster = _clusterDao.persist(cluster);
} catch (Exception e) {
cluster = _clusterDao.findBy(name, podId);
if (cluster == null) {
throw new CloudRuntimeException("Unable to create cluster " + name + " in pod " + podId + " and data center " + dcId, e);
}
}
return cluster;
}
@Override
public boolean deletePool(Long id)
{
return _storageMgr.deletePool(id);
}
// @Override
// public ClusterVO createCluster(long dcId, long podId, String name) {
// ClusterVO cluster = new ClusterVO(dcId, podId, name);
// try {
// cluster = _clusterDao.persist(cluster);
// } catch (Exception e) {
// cluster = _clusterDao.findBy(name, podId);
// if (cluster == null) {
// throw new CloudRuntimeException("Unable to create cluster " + name + " in pod " + podId + " and data center " + dcId, e);
// }
// }
// return cluster;
// }
@Override
public List<? extends StoragePoolVO> searchForStoragePools(Criteria c) {

View File

@ -24,10 +24,12 @@ import java.util.Map;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.api.commands.DeletePoolCmd;
import com.cloud.api.commands.UpdateStoragePoolCmd;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.exception.InternalErrorException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceInUseException;
import com.cloud.exception.StorageUnavailableException;
@ -254,7 +256,7 @@ public interface StorageManager extends Manager {
* Delete the storage pool
* @param id -- id associated
*/
boolean deletePool(long id);
boolean deletePool(DeletePoolCmd cmd) throws InvalidParameterValueException;
/**
* Updates a storage pool.

View File

@ -59,6 +59,8 @@ import com.cloud.agent.api.to.VolumeTO;
import com.cloud.agent.manager.AgentManager;
import com.cloud.alert.AlertManager;
import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException;
import com.cloud.api.commands.DeletePoolCmd;
import com.cloud.api.commands.StopVMCmd;
import com.cloud.api.commands.UpdateStoragePoolCmd;
import com.cloud.async.AsyncInstanceCreateStatus;
@ -1336,14 +1338,21 @@ public class StorageManagerImpl implements StorageManager {
}
@DB
public boolean deletePool(long id) {
public boolean deletePool(DeletePoolCmd command) throws InvalidParameterValueException{
Long id = command.getId();
boolean deleteFlag = false;
//verify parameters
StoragePoolVO sPool = _storagePoolDao.findById(id);
if (sPool == null) {
throw new InvalidParameterValueException("Unable to find pool by id " + id);
}
if (sPool.getPoolType().equals(StoragePoolType.LVM)) {
throw new InvalidParameterValueException("Unable to delete local storage id: " + id);
}
// get the pool to delete
StoragePoolVO sPool = _storagePoolDao.findById(id);
if (sPool == null)
return false;
// for the given pool id, find all records in the storage_pool_host_ref
List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(id);