Fix CLOUDSTACK-936: fix nonoss build due to CloudException IdentityProxy

removal.
This commit is contained in:
Min Chen 2013-01-09 13:46:54 -08:00
parent 3dfd81fd6b
commit dcbb0ecef5
2 changed files with 48 additions and 54 deletions

View File

@ -56,14 +56,6 @@ public class CloudException extends Exception {
return; return;
} }
public void addProxyObject(Object voObj, Long id, String idFieldName) {
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(voObj);
if (tablename != null) {
addProxyObject(tablename, id, idFieldName);
}
return;
}
public ArrayList<String> getIdProxyList() { public ArrayList<String> getIdProxyList() {
return idList; return idList;

View File

@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing, // Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an // software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.network; package com.cloud.network;
@ -48,7 +48,7 @@ import com.cloud.utils.cisco.n1kv.vsm.NetconfHelper;
public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
@Inject @Inject
CiscoNexusVSMDeviceDao _ciscoNexusVSMDeviceDao; CiscoNexusVSMDeviceDao _ciscoNexusVSMDeviceDao;
@Inject @Inject
ClusterDao _clusterDao; ClusterDao _clusterDao;
@Inject @Inject
@ -65,9 +65,9 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
PortProfileDao _ppDao; PortProfileDao _ppDao;
@Inject @Inject
ConfigurationDao _configDao; ConfigurationDao _configDao;
private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalLoadBalancerDeviceManagerImpl.class); private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalLoadBalancerDeviceManagerImpl.class);
@DB @DB
//public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, ServerResource resource, String vsmName) { //public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, ServerResource resource, String vsmName) {
public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, String vCenterIpaddr, String vCenterDcName) { public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, String vCenterIpaddr, String vCenterDcName) {
@ -77,7 +77,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
// First check if the cluster is of type vmware. If not, // First check if the cluster is of type vmware. If not,
// throw an exception. VSMs are tightly integrated with vmware clusters. // throw an exception. VSMs are tightly integrated with vmware clusters.
ClusterVO cluster = _clusterDao.findById(clusterId); ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null) { if (cluster == null) {
throw new InvalidParameterValueException("Cluster with specified ID not found!"); throw new InvalidParameterValueException("Cluster with specified ID not found!");
@ -90,21 +90,21 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
// Next, check if the cluster already has a VSM associated with it. // Next, check if the cluster already has a VSM associated with it.
// If so, throw an exception disallowing this operation. The user must first // If so, throw an exception disallowing this operation. The user must first
// delete the current VSM and then only attempt to add the new one. // delete the current VSM and then only attempt to add the new one.
if (_clusterVSMDao.findByClusterId(clusterId) != null) { if (_clusterVSMDao.findByClusterId(clusterId) != null) {
// We can't have two VSMs for the same cluster. Throw exception. // We can't have two VSMs for the same cluster. Throw exception.
throw new InvalidParameterValueException("Cluster with specified id already has a VSM tied to it. Please remove that first and retry the operation."); throw new InvalidParameterValueException("Cluster with specified id already has a VSM tied to it. Please remove that first and retry the operation.");
} }
// TODO: Confirm whether we should be checking for VSM reachability here. // TODO: Confirm whether we should be checking for VSM reachability here.
// Next, check if this VSM is reachable. Use the XML-RPC VSM API Java bindings to talk to // Next, check if this VSM is reachable. Use the XML-RPC VSM API Java bindings to talk to
// the VSM. // the VSM.
//NetconfHelper (String ip, String username, String password) //NetconfHelper (String ip, String username, String password)
NetconfHelper netconfClient; NetconfHelper netconfClient;
try { try {
netconfClient = new NetconfHelper(ipaddress, username, password); netconfClient = new NetconfHelper(ipaddress, username, password);
} catch(CloudRuntimeException e) { } catch(CloudRuntimeException e) {
String msg = "Failed to connect to Nexus VSM " + ipaddress + " with credentials of user " + username; String msg = "Failed to connect to Nexus VSM " + ipaddress + " with credentials of user " + username;
s_logger.error(msg); s_logger.error(msg);
@ -118,7 +118,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
// First, check if VSM already exists in the table "virtual_supervisor_module". // First, check if VSM already exists in the table "virtual_supervisor_module".
// If it's not there already, create it. // If it's not there already, create it.
// If it's there already, return success. // If it's there already, return success.
// TODO - Right now, we only check if the ipaddress matches for both requests. // TODO - Right now, we only check if the ipaddress matches for both requests.
// We must really check whether every field of the VSM matches. Anyway, the // We must really check whether every field of the VSM matches. Anyway, the
// advantage of our approach for now is that existing infrastructure using // advantage of our approach for now is that existing infrastructure using
@ -131,7 +131,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
throw new CloudRuntimeException(e.getMessage()); throw new CloudRuntimeException(e.getMessage());
} }
if (VSMObj == null) { if (VSMObj == null) {
// Create the VSM record. For now, we aren't using the vsmName field. // Create the VSM record. For now, we aren't using the vsmName field.
VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password); VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password);
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
@ -144,7 +144,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
throw new CloudRuntimeException(e.getMessage()); throw new CloudRuntimeException(e.getMessage());
} }
} }
// At this stage, we have a VSM record for sure. Connect the VSM to the cluster Id. // At this stage, we have a VSM record for sure. Connect the VSM to the cluster Id.
long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId(); long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId();
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsmId); ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsmId);
@ -157,22 +157,22 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
txn.rollback(); txn.rollback();
throw new CloudRuntimeException(e.getMessage()); throw new CloudRuntimeException(e.getMessage());
} }
// Now, get a list of all the ESXi servers in this cluster. // Now, get a list of all the ESXi servers in this cluster.
// This is effectively a select * from host where cluster_id=clusterId; // This is effectively a select * from host where cluster_id=clusterId;
// All ESXi servers are stored in the host table, and their resource // All ESXi servers are stored in the host table, and their resource
// type is vmwareresource. // type is vmwareresource.
//List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId); //List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
//TODO: Activate the code below if we make the Nexus VSM a separate resource. //TODO: Activate the code below if we make the Nexus VSM a separate resource.
// Iterate through each of the hosts in this list. Each host has a host id. // Iterate through each of the hosts in this list. Each host has a host id.
// Given this host id, we can reconfigure the in-memory resource representing // Given this host id, we can reconfigure the in-memory resource representing
// the host via the agent manager. Thus we inject VSM related information // the host via the agent manager. Thus we inject VSM related information
// into each host's resource. Also, we first configure each resource's // into each host's resource. Also, we first configure each resource's
// entries in the database to contain this VSM information before the injection. // entries in the database to contain this VSM information before the injection.
//for (HostVO host : hosts) { //for (HostVO host : hosts) {
// Create a host details VO object and write it out for this hostid. // Create a host details VO object and write it out for this hostid.
//Long hostid = new Long(vsmId); //Long hostid = new Long(vsmId);
//DetailVO vsmDetail = new DetailVO(host.getId(), "vsmId", hostid.toString()); //DetailVO vsmDetail = new DetailVO(host.getId(), "vsmId", hostid.toString());
@ -193,28 +193,28 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
//hostDetails.put(ApiConstants.USERNAME, username); //hostDetails.put(ApiConstants.USERNAME, username);
//hostDetails.put(ApiConstants.PASSWORD, password); //hostDetails.put(ApiConstants.PASSWORD, password);
//_agentMrg.send(host.getId(), ) //_agentMrg.send(host.getId(), )
return VSMObj; return VSMObj;
} }
@DB @DB
public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException { public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException {
CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId); CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
if (cisconexusvsm == null) { if (cisconexusvsm == null) {
// This entry is already not present. Return success. // This entry is already not present. Return success.
return true; return true;
} }
// First, check whether this VSM is part of any non-empty cluster. // First, check whether this VSM is part of any non-empty cluster.
// Search ClusterVSMMap's table for a list of clusters using this vsmId. // Search ClusterVSMMap's table for a list of clusters using this vsmId.
List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsmId); List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsmId);
if (clusterList != null) { if (clusterList != null) {
for (ClusterVSMMapVO record : clusterList) { for (ClusterVSMMapVO record : clusterList) {
// If this cluster id has any hosts in it, fail this operation. // If this cluster id has any hosts in it, fail this operation.
Long clusterId = record.getClusterId(); Long clusterId = record.getClusterId();
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId); List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
if (hosts != null && hosts.size() > 0) { if (hosts != null && hosts.size() > 0) {
for (Host host: hosts) { for (Host host: hosts) {
@ -222,26 +222,26 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
s_logger.info("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first"); s_logger.info("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first"); throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
} }
} }
} }
} }
} }
// Iterate through the cluster list again, this time, delete the VSM. // Iterate through the cluster list again, this time, delete the VSM.
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
try { try {
txn.start(); txn.start();
// Remove the VSM entry in CiscoNexusVSMDeviceVO's table. // Remove the VSM entry in CiscoNexusVSMDeviceVO's table.
_ciscoNexusVSMDeviceDao.remove(vsmId); _ciscoNexusVSMDeviceDao.remove(vsmId);
// Remove the current record as well from ClusterVSMMapVO's table. // Remove the current record as well from ClusterVSMMapVO's table.
_clusterVSMDao.removeByVsmId(vsmId); _clusterVSMDao.removeByVsmId(vsmId);
// There are no hosts at this stage in the cluster, so we don't need // There are no hosts at this stage in the cluster, so we don't need
// to notify any resources or remove host details. // to notify any resources or remove host details.
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
s_logger.info("Caught exception when trying to delete VSM record.." + e.getMessage()); s_logger.info("Caught exception when trying to delete VSM record.." + e.getMessage());
throw new CloudRuntimeException("Failed to delete VSM"); throw new CloudRuntimeException("Failed to delete VSM");
} }
return true; return true;
} }
@ -249,10 +249,10 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
public CiscoNexusVSMDeviceVO enableCiscoNexusVSM(long vsmId) { public CiscoNexusVSMDeviceVO enableCiscoNexusVSM(long vsmId) {
CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId); CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
if (cisconexusvsm == null) { if (cisconexusvsm == null) {
throw new InvalidParameterValueException("Invalid vsm Id specified"); throw new InvalidParameterValueException("Invalid vsm Id specified");
} }
// Else, check if this db record shows that this VSM is enabled or not. // Else, check if this db record shows that this VSM is enabled or not.
if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled) { if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled) {
// it's currently disabled. So change it to enabled and write it out to the db. // it's currently disabled. So change it to enabled and write it out to the db.
cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled); cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled);
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
@ -265,18 +265,18 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
throw new CloudRuntimeException(e.getMessage()); throw new CloudRuntimeException(e.getMessage());
} }
} }
return cisconexusvsm; return cisconexusvsm;
} }
@DB @DB
public CiscoNexusVSMDeviceVO disableCiscoNexusVSM(long vsmId) { public CiscoNexusVSMDeviceVO disableCiscoNexusVSM(long vsmId) {
CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId); CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
if (cisconexusvsm == null) { if (cisconexusvsm == null) {
throw new InvalidParameterValueException("Invalid vsm Id specified"); throw new InvalidParameterValueException("Invalid vsm Id specified");
} }
// Else, check if this db record shows that this VSM is enabled or not. // Else, check if this db record shows that this VSM is enabled or not.
if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled) { if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled) {
// it's currently disabled. So change it to enabled and write it out to the db. // it's currently disabled. So change it to enabled and write it out to the db.
cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled); cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled);
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
@ -289,15 +289,15 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
throw new CloudRuntimeException(e.getMessage()); throw new CloudRuntimeException(e.getMessage());
} }
} }
return cisconexusvsm; return cisconexusvsm;
} }
@DB @DB
public CiscoNexusVSMDeviceVO getCiscoVSMbyVSMId(long vsmId) { public CiscoNexusVSMDeviceVO getCiscoVSMbyVSMId(long vsmId) {
return _ciscoNexusVSMDeviceDao.findById(vsmId); return _ciscoNexusVSMDeviceDao.findById(vsmId);
} }
@DB @DB
public CiscoNexusVSMDeviceVO getCiscoVSMbyClusId(long clusterId) { public CiscoNexusVSMDeviceVO getCiscoVSMbyClusId(long clusterId) {
ClusterVSMMapVO mapVO = _clusterVSMDao.findByClusterId(clusterId); ClusterVSMMapVO mapVO = _clusterVSMDao.findByClusterId(clusterId);
@ -309,12 +309,12 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
CiscoNexusVSMDeviceVO result = _ciscoNexusVSMDeviceDao.findById(mapVO.getVsmId()); CiscoNexusVSMDeviceVO result = _ciscoNexusVSMDeviceDao.findById(mapVO.getVsmId());
return result; return result;
} }
public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@DB @DB
public boolean vliadateVsmCluster(String vsmIp, String vsmUser, String vsmPassword, long clusterId, String clusterName) throws ResourceInUseException { public boolean vliadateVsmCluster(String vsmIp, String vsmUser, String vsmPassword, long clusterId, String clusterName) throws ResourceInUseException {
// Check if we're associating a Cisco Nexus VSM with a vmware cluster. // Check if we're associating a Cisco Nexus VSM with a vmware cluster.
@ -342,7 +342,9 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster"); s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster");
_clusterDao.remove(clusterId); _clusterDao.remove(clusterId);
ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id"); ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id");
ex.addProxyObject("cluster", clusterList.get(0).getClusterId(), "clusterId"); // get clusterUuid to report error
ClusterVO cluster = _clusterDao.findById(clusterList.get(0).getClusterId());
ex.addProxyObject(cluster.getUuid());
throw ex; throw ex;
} }
} }