use of com.cloud.exception.ResourceInUseException in project cloudstack by apache.
the class CiscoNexusVSMElement method validateAndAddVsm.
@Override
@DB
public Pair<Boolean, Long> validateAndAddVsm(final String vsmIp, final String vsmUser, final String vsmPassword, final long clusterId, String clusterName) throws ResourceInUseException {
CiscoNexusVSMDeviceVO vsm = null;
boolean vsmAdded = false;
Long vsmId = 0L;
if (vsmIp != null && vsmUser != null && vsmPassword != null) {
NetconfHelper netconfClient;
try {
netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
netconfClient.disconnect();
} catch (CloudRuntimeException e) {
String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
s_logger.error(msg);
_clusterDao.remove(clusterId);
throw new CloudRuntimeException(msg);
}
// If VSM already exists and is mapped to a cluster, fail this operation.
vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
if (vsm != null) {
List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsm.getId());
if (clusterList != null && !clusterList.isEmpty()) {
s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster");
ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id");
// get clusterUuid to report error
ClusterVO cluster = _clusterDao.findById(clusterList.get(0).getClusterId());
ex.addProxyObject(cluster.getUuid());
_clusterDao.remove(clusterId);
throw ex;
}
}
// persist credentials to database if the VSM entry is not already in the db.
vsm = Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>() {
@Override
public CiscoNexusVSMDeviceVO doInTransaction(TransactionStatus status) {
CiscoNexusVSMDeviceVO vsm = null;
if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
_vsmDao.persist(vsm);
}
// Create a mapping between the cluster and the vsm.
vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
if (vsm != null) {
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
_clusterVSMDao.persist(connectorObj);
}
return vsm;
}
});
} else {
String msg;
msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() + " is set to \"true\". Following mandatory parameters are not specified. ";
if (vsmIp == null) {
msg += "vsmipaddress: Management IP address of Cisco Nexus 1000v dvSwitch. ";
}
if (vsmUser == null) {
msg += "vsmusername: Name of a user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
}
if (vsmPassword == null) {
if (vsmUser != null) {
msg += "vsmpassword: Password of user account " + vsmUser + ". ";
} else {
msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
}
}
s_logger.error(msg);
// Cleaning up the cluster record as addCluster operation failed because of invalid credentials of Nexus dvSwitch.
_clusterDao.remove(clusterId);
throw new CloudRuntimeException(msg);
}
if (vsm != null) {
vsmAdded = true;
vsmId = vsm.getId();
}
return new Pair<Boolean, Long>(vsmAdded, vsmId);
}
use of com.cloud.exception.ResourceInUseException in project cloudstack by apache.
the class SecurityGroupManagerImpl method deleteSecurityGroup.
@DB
@Override
@ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_DELETE, eventDescription = "deleting security group")
public boolean deleteSecurityGroup(DeleteSecurityGroupCmd cmd) throws ResourceInUseException {
final Long groupId = cmd.getId();
Account caller = CallContext.current().getCallingAccount();
SecurityGroupVO group = _securityGroupDao.findById(groupId);
if (group == null) {
throw new InvalidParameterValueException("Unable to find network group: " + groupId + "; failed to delete group.");
}
// check permissions
_accountMgr.checkAccess(caller, null, true, group);
return Transaction.execute(new TransactionCallbackWithException<Boolean, ResourceInUseException>() {
@Override
public Boolean doInTransaction(TransactionStatus status) throws ResourceInUseException {
SecurityGroupVO group = _securityGroupDao.lockRow(groupId, true);
if (group == null) {
throw new InvalidParameterValueException("Unable to find security group by id " + groupId);
}
if (group.getName().equalsIgnoreCase(SecurityGroupManager.DEFAULT_GROUP_NAME)) {
throw new InvalidParameterValueException("The network group default is reserved");
}
List<SecurityGroupRuleVO> allowingRules = _securityGroupRuleDao.listByAllowedSecurityGroupId(groupId);
List<SecurityGroupVMMapVO> securityGroupVmMap = _securityGroupVMMapDao.listBySecurityGroup(groupId);
if (!allowingRules.isEmpty()) {
throw new ResourceInUseException("Cannot delete group when there are security rules that allow this group");
} else if (!securityGroupVmMap.isEmpty()) {
throw new ResourceInUseException("Cannot delete group when it's in use by virtual machines");
}
_securityGroupDao.expunge(groupId);
s_logger.debug("Deleted security group id=" + groupId);
return true;
}
});
}
use of com.cloud.exception.ResourceInUseException in project cloudstack by apache.
the class DeleteVolumePoolCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
netappMgr.deletePool(poolName);
DeleteVolumePoolCmdResponse response = new DeleteVolumePoolCmdResponse();
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString());
} catch (ResourceInUseException e) {
throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, e.toString());
}
}
use of com.cloud.exception.ResourceInUseException in project cloudstack by apache.
the class DestroyVolumeOnFilerCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
netappMgr.destroyVolumeOnFiler(ipAddr, aggrName, volumeName);
DeleteVolumeOnFilerCmdResponse response = new DeleteVolumeOnFilerCmdResponse();
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString());
} catch (ResourceInUseException e) {
throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, e.toString());
} catch (ServerException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
}
}
use of com.cloud.exception.ResourceInUseException in project CloudStack-archive by CloudStack-extras.
the class AddClusterCmd method execute.
@Override
public void execute() {
try {
List<? extends Cluster> result = _resourceService.discoverCluster(this);
ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
if (result != null) {
for (Cluster cluster : result) {
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
clusterResponses.add(clusterResponse);
}
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add cluster");
}
response.setResponses(clusterResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (DiscoveryException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
} catch (ResourceInUseException ex) {
s_logger.warn("Exception: ", ex);
ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
for (IdentityProxy proxyObj : ex.getIdProxyList()) {
e.addProxyObject(proxyObj.getTableName(), proxyObj.getValue(), proxyObj.getidFieldName());
}
throw e;
}
}
Aggregations