use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class ConfigDriveNetworkElement method deleteConfigDriveIso.
private boolean deleteConfigDriveIso(final VirtualMachine vm) throws ResourceUnavailableException {
Long hostId = (vm.getHostId() != null) ? vm.getHostId() : vm.getLastHostId();
Location location = getConfigDriveLocation(vm.getId());
if (location == Location.HOST) {
return deleteConfigDriveIsoOnHostCache(vm, hostId);
}
Long agentId = null;
DataStore dataStore = null;
if (location == Location.SECONDARY) {
dataStore = _dataStoreMgr.getImageStoreWithFreeCapacity(vm.getDataCenterId());
agentId = findAgentIdForImageStore(dataStore);
} else if (location == Location.PRIMARY) {
List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
if (volumes != null && volumes.size() > 0) {
dataStore = _dataStoreMgr.getDataStore(volumes.get(0).getPoolId(), DataStoreRole.Primary);
}
agentId = hostId;
}
if (agentId == null || dataStore == null) {
throw new ResourceUnavailableException("Config drive iso deletion failed, agent or datastore not available", ConfigDriveNetworkElement.class, 0L);
}
LOG.debug("Deleting config drive ISO for vm: " + vm.getInstanceName());
final String isoPath = ConfigDrive.createConfigDrivePath(vm.getInstanceName());
final HandleConfigDriveIsoCommand configDriveIsoCommand = new HandleConfigDriveIsoCommand(isoPath, null, dataStore.getTO(), false, false, false);
final HandleConfigDriveIsoAnswer answer = (HandleConfigDriveIsoAnswer) agentManager.easySend(agentId, configDriveIsoCommand);
if (!answer.getResult()) {
LOG.error("Failed to remove config drive for instance: " + vm.getInstanceName());
return false;
}
return true;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualRouterElement method commitMigration.
@Override
public void commitMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
return;
}
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
assert vm instanceof DomainRouterVO;
final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
try {
networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nic);
} catch (final ResourceUnavailableException e) {
s_logger.warn("Timed Out", e);
}
} else if (vm.getType() == VirtualMachine.Type.User) {
assert vm instanceof UserVmVO;
_userVmMgr.setupVmForPvlan(true, vm.getVirtualMachine().getHostId(), nic);
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class CreateStorageNetworkIpRangeCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
StorageNetworkIpRange result = _storageNetworkService.createIpRange(this);
StorageNetworkIpRangeResponse response = _responseGenerator.createStorageNetworkIpRangeResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (Exception e) {
s_logger.warn("Create storage network IP range failed", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class DeleteManagementNetworkIpRangeCmd method execute.
@Override
public void execute() {
try {
_configService.deletePodIpRange(this);
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (Exception e) {
s_logger.warn("Failed to delete management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId(), e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class ListStorageNetworkIpRangeCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
List<StorageNetworkIpRange> results = _storageNetworkService.listIpRange(this);
ListResponse<StorageNetworkIpRangeResponse> response = new ListResponse<StorageNetworkIpRangeResponse>();
List<StorageNetworkIpRangeResponse> resList = new ArrayList<StorageNetworkIpRangeResponse>(results.size());
for (StorageNetworkIpRange r : results) {
StorageNetworkIpRangeResponse resp = _responseGenerator.createStorageNetworkIpRangeResponse(r);
resList.add(resp);
}
response.setResponses(resList);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (Exception e) {
s_logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId());
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
Aggregations