use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VpcVirtualRouterElement method implement.
@Override
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
final Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.trace("Network " + network + " is not associated with any VPC");
return false;
}
final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
if (vpc == null) {
s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
return false;
}
final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
if (network.isRollingRestart()) {
params.put(VirtualMachineProfile.Param.RollingRestart, true);
vpc.setRollingRestart(true);
}
final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
}
configureGuestNetwork(network, routers);
return true;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VpcVirtualRouterElement method getRouters.
@Override
protected List<DomainRouterVO> getRouters(final Network network, final DeployDestination dest) {
// 1st time it runs the domain router of the VM shall be returned
List<DomainRouterVO> routers = super.getRouters(network, dest);
if (CollectionUtils.isNotEmpty(routers)) {
return routers;
}
// For the 2nd time it returns the VPC routers.
final Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.error("Network " + network + " is not associated with any VPC");
return routers;
}
final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
if (vpc == null) {
s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
return routers;
}
final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).build();
try {
routers = routerDeploymentDefinition.deployVirtualRouter();
} catch (final ConcurrentOperationException e) {
s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
} catch (final InsufficientCapacityException e) {
s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
} catch (final ResourceUnavailableException e) {
s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
}
return routers;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VpcVirtualRouterElement method startSite2SiteVpn.
@Override
public boolean startSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException {
final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId());
final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId());
final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn);
if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) {
s_logger.error("try to start site 2 site vpn on unsupported network element?");
return false;
}
final Long vpcId = ip.getVpcId();
final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId());
}
final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
if (routers == null) {
throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId());
}
boolean result = true;
for (final DomainRouterVO domainRouterVO : routers) {
result = result && _vpcRouterMgr.startSite2SiteVpn(conn, domainRouterVO);
}
return result;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class ConfigDriveNetworkElement method createConfigDriveIsoOnHostCache.
private boolean createConfigDriveIsoOnHostCache(VirtualMachineProfile profile, Long hostId) throws ResourceUnavailableException {
if (hostId == null) {
throw new ResourceUnavailableException("Config drive iso creation failed, dest host not available", ConfigDriveNetworkElement.class, 0L);
}
LOG.debug("Creating config drive ISO for vm: " + profile.getInstanceName() + " on host: " + hostId);
final String isoFileName = ConfigDrive.configIsoFileName(profile.getInstanceName());
final String isoPath = ConfigDrive.createConfigDrivePath(profile.getInstanceName());
final String isoData = ConfigDriveBuilder.buildConfigDrive(profile.getVmData(), isoFileName, profile.getConfigDriveLabel());
final HandleConfigDriveIsoCommand configDriveIsoCommand = new HandleConfigDriveIsoCommand(isoPath, isoData, null, false, true, true);
final HandleConfigDriveIsoAnswer answer = (HandleConfigDriveIsoAnswer) agentManager.easySend(hostId, configDriveIsoCommand);
if (answer == null) {
throw new CloudRuntimeException("Unable to get an answer to handle config drive creation for vm: " + profile.getInstanceName() + " on host: " + hostId);
}
if (!answer.getResult()) {
throw new ResourceUnavailableException(String.format("Config drive iso creation failed, details: %s", answer.getDetails()), ConfigDriveNetworkElement.class, 0L);
}
profile.setConfigDriveLocation(answer.getConfigDriveLocation());
_userVmDetailsDao.addDetail(profile.getId(), VmDetailConstants.CONFIG_DRIVE_LOCATION, answer.getConfigDriveLocation().toString(), false);
addConfigDriveDisk(profile, null);
return true;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class ConfigDriveNetworkElement method createConfigDriveIso.
private boolean createConfigDriveIso(VirtualMachineProfile profile, DeployDestination dest, DiskTO disk) throws ResourceUnavailableException {
DataStore dataStore = getDatastoreForConfigDriveIso(disk, profile, dest);
final Long agentId = findAgentId(profile, dest, dataStore);
if (agentId == null || dataStore == null) {
throw new ResourceUnavailableException("Config drive iso creation failed, agent or datastore not available", ConfigDriveNetworkElement.class, 0L);
}
LOG.debug("Creating config drive ISO for vm: " + profile.getInstanceName());
final String isoFileName = ConfigDrive.configIsoFileName(profile.getInstanceName());
final String isoPath = ConfigDrive.createConfigDrivePath(profile.getInstanceName());
final String isoData = ConfigDriveBuilder.buildConfigDrive(profile.getVmData(), isoFileName, profile.getConfigDriveLabel());
boolean useHostCacheOnUnsupportedPool = VirtualMachineManager.VmConfigDriveUseHostCacheOnUnsupportedPool.valueIn(dest.getDataCenter().getId());
boolean preferHostCache = VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId());
final HandleConfigDriveIsoCommand configDriveIsoCommand = new HandleConfigDriveIsoCommand(isoPath, isoData, dataStore.getTO(), useHostCacheOnUnsupportedPool, preferHostCache, true);
final HandleConfigDriveIsoAnswer answer = (HandleConfigDriveIsoAnswer) agentManager.easySend(agentId, configDriveIsoCommand);
if (!answer.getResult()) {
throw new ResourceUnavailableException(String.format("Config drive iso creation failed, details: %s", answer.getDetails()), ConfigDriveNetworkElement.class, 0L);
}
profile.setConfigDriveLocation(answer.getConfigDriveLocation());
_userVmDetailsDao.addDetail(profile.getId(), VmDetailConstants.CONFIG_DRIVE_LOCATION, answer.getConfigDriveLocation().toString(), false);
addConfigDriveDisk(profile, dataStore);
return true;
}
Aggregations