use of com.cloud.exception.CloudException in project cloudstack by apache.
the class UsageIPAddressDaoImpl method update.
@Override
public void update(UsageIPAddressVO usage) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
try {
txn.start();
if (usage.getReleased() != null) {
try (PreparedStatement pstmt = txn.prepareStatement(UPDATE_RELEASED)) {
if (pstmt != null) {
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getReleased()));
pstmt.setLong(2, usage.getAccountId());
pstmt.setString(3, usage.getAddress());
pstmt.executeUpdate();
}
} catch (SQLException e) {
throw new CloudException("update:Exception:" + e.getMessage(), e);
}
}
txn.commit();
} catch (Exception e) {
txn.rollback();
s_logger.error("Error updating usageIPAddressVO:" + e.getMessage(), e);
} finally {
txn.close();
}
}
use of com.cloud.exception.CloudException in project cloudstack by apache.
the class DatastoreMO method searchFileInSubFolders.
public String searchFileInSubFolders(String fileName, boolean caseInsensitive) throws Exception {
String datastorePath = "[" + getName() + "]";
String rootDirectoryFilePath = String.format("%s %s", datastorePath, fileName);
if (fileExists(rootDirectoryFilePath)) {
return rootDirectoryFilePath;
}
String parentFolderPath = null;
String absoluteFileName = null;
s_logger.info("Searching file " + fileName + " in " + datastorePath);
HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
ArrayList<HostDatastoreBrowserSearchResults> results = browserMo.searchDatastoreSubFolders("[" + getName() + "]", fileName, caseInsensitive);
if (results != null && results.size() > 1) {
s_logger.warn("Multiple files with name " + fileName + " exists in datastore " + datastorePath + ". Trying to choose first file found in search attempt.");
} else if (results == null) {
String msg = "No file found with name " + fileName + " found in datastore " + datastorePath;
s_logger.error(msg);
throw new CloudException(msg);
}
for (HostDatastoreBrowserSearchResults result : results) {
List<FileInfo> info = result.getFile();
if (info != null && info.size() > 0) {
for (FileInfo fi : info) {
absoluteFileName = parentFolderPath = result.getFolderPath();
s_logger.info("Found file " + fileName + " in datastore at " + absoluteFileName);
if (parentFolderPath.endsWith("]"))
absoluteFileName += " ";
absoluteFileName += fi.getPath();
break;
}
}
}
return absoluteFileName;
}
use of com.cloud.exception.CloudException in project cloudstack by apache.
the class UserVmManagerImpl method stopVirtualMachine.
@Override
public boolean stopVirtualMachine(long userId, long vmId) {
boolean status = false;
if (s_logger.isDebugEnabled()) {
s_logger.debug("Stopping vm=" + vmId);
}
UserVmVO vm = _vmDao.findById(vmId);
if (vm == null || vm.getRemoved() != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("VM is either removed or deleted.");
}
return true;
}
_userDao.findById(userId);
try {
VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
status = vmEntity.stop(Long.toString(userId));
} catch (ResourceUnavailableException e) {
s_logger.debug("Unable to stop due to ", e);
status = false;
} catch (CloudException e) {
throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e);
}
return status;
}
use of com.cloud.exception.CloudException in project cloudstack by apache.
the class UserVmManagerImpl method stopVirtualMachine.
@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_STOP, eventDescription = "stopping Vm", async = true)
public UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException {
// Input validation
Account caller = CallContext.current().getCallingAccount();
Long userId = CallContext.current().getCallingUserId();
// if account is removed, return error
if (caller != null && caller.getRemoved() != null) {
throw new PermissionDeniedException("The account " + caller.getUuid() + " is removed");
}
UserVmVO vm = _vmDao.findById(vmId);
if (vm == null) {
throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
}
_userDao.findById(userId);
boolean status = false;
try {
VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
if (forced) {
status = vmEntity.stopForced(Long.toString(userId));
} else {
status = vmEntity.stop(Long.toString(userId));
}
if (status) {
return _vmDao.findById(vmId);
} else {
return null;
}
} catch (ResourceUnavailableException e) {
throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e);
} catch (CloudException e) {
throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e);
}
}
use of com.cloud.exception.CloudException in project cloudstack by apache.
the class NetworkProviderTest method createTestNetwork.
private Network createTestNetwork(String name) {
CreateNetworkCmd cmd = new CreateNetworkCmd();
ComponentContext.inject(cmd);
Account system = _accountMgr.getSystemAccount();
DataCenter zone = _server.getZone();
ManagementServerMock.setParameter(cmd, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
ManagementServerMock.setParameter(cmd, ApiConstants.NAME, BaseCmd.CommandType.STRING, name);
ManagementServerMock.setParameter(cmd, "displayText", BaseCmd.CommandType.STRING, "test network");
ManagementServerMock.setParameter(cmd, "networkOfferingId", BaseCmd.CommandType.LONG, _contrailMgr.getRouterOffering().getId());
ManagementServerMock.setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, zone.getId());
ManagementServerMock.setParameter(cmd, ApiConstants.GATEWAY, BaseCmd.CommandType.STRING, "10.0.1.254");
ManagementServerMock.setParameter(cmd, ApiConstants.NETMASK, BaseCmd.CommandType.STRING, "255.255.255.0");
// Physical network id can't be specified for Guest traffic type.
// SetParameter(cmd, "physicalNetworkId", BaseCmd.CommandType.LONG, _znet.getId());
Network result = null;
try {
result = _networkService.createGuestNetwork(cmd);
} catch (CloudException e) {
e.printStackTrace();
return null;
}
return result;
}
Aggregations