use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class Site2SiteVpnManagerImpl method startVpnConnection.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "starting s2s vpn connection", async = true)
public Site2SiteVpnConnection startVpnConnection(final long id) throws ResourceUnavailableException {
final Site2SiteVpnConnectionVO conn = _vpnConnectionDao.acquireInLockTable(id);
if (conn == null) {
throw new CloudRuntimeException("Unable to acquire lock on " + conn);
}
try {
if (conn.getState() != State.Pending && conn.getState() != State.Disconnected) {
throw new InvalidParameterValueException("Site to site VPN connection with specified connectionId not in correct state(pending or disconnected) to process!");
}
conn.setState(State.Pending);
_vpnConnectionDao.persist(conn);
boolean result = true;
for (final Site2SiteVpnServiceProvider element : _s2sProviders) {
result = result & element.startSite2SiteVpn(conn);
}
if (result) {
if (conn.isPassive()) {
conn.setState(State.Disconnected);
} else {
conn.setState(State.Connected);
}
_vpnConnectionDao.persist(conn);
return conn;
}
conn.setState(State.Error);
_vpnConnectionDao.persist(conn);
throw new ResourceUnavailableException("Failed to apply site-to-site VPN", Site2SiteVpnConnection.class, id);
} finally {
_vpnConnectionDao.releaseFromLockTable(conn.getId());
}
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method upgradeSystemVM.
@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_UPGRADE, eventDescription = "Upgrading system VM", async = true)
public VirtualMachine upgradeSystemVM(final ScaleSystemVMCmd cmd) throws ResourceUnavailableException, ManagementServerException, VirtualMachineMigrationException, ConcurrentOperationException {
final VMInstanceVO vmInstance = _vmInstanceDao.findById(cmd.getId());
if (vmInstance.getHypervisorType() == HypervisorType.XenServer && vmInstance.getState().equals(State.Running)) {
throw new InvalidParameterValueException("Dynamic Scaling operation is not permitted for this hypervisor on system vm");
}
final boolean result = _userVmMgr.upgradeVirtualMachine(cmd.getId(), cmd.getServiceOfferingId(), cmd.getDetails());
if (result) {
final VirtualMachine vm = _vmInstanceDao.findById(cmd.getId());
return vm;
} else {
throw new CloudRuntimeException("Failed to upgrade System VM");
}
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method upgradeStoppedSystemVm.
private VirtualMachine upgradeStoppedSystemVm(final Long systemVmId, final Long serviceOfferingId, final Map<String, String> customparameters) {
final Account caller = getCaller();
final VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(systemVmId, VirtualMachineType.ConsoleProxy, VirtualMachineType.SecondaryStorageVm);
if (systemVm == null) {
throw new InvalidParameterValueException("Unable to find SystemVm with id " + systemVmId);
}
_accountMgr.checkAccess(caller, null, true, systemVm);
// Check that the specified service offering ID is valid
ServiceOfferingVO newServiceOffering = _offeringDao.findById(serviceOfferingId);
final ServiceOfferingVO currentServiceOffering = _offeringDao.findById(systemVmId, systemVm.getServiceOfferingId());
_itMgr.checkIfCanUpgrade(systemVm, newServiceOffering);
final boolean result = _itMgr.upgradeVmDb(systemVmId, serviceOfferingId);
if (result) {
return _vmInstanceDao.findById(systemVmId);
} else {
throw new CloudRuntimeException("Unable to upgrade system vm " + systemVm);
}
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class SHA256SaltedUserAuthenticator method authenticate.
/* (non-Javadoc)
* @see com.cloud.server.auth.UserAuthenticator#authenticate(java.lang.String, java.lang.String, java.lang.Long, java.util.Map)
*/
@Override
public Pair<Boolean, ActionOnFailedAuthentication> authenticate(final String username, final String password, final Long domainId, final Map<String, Object[]> requestParameters) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Retrieving user: " + username);
}
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
s_logger.debug("Username or Password cannot be empty");
return new Pair<>(false, null);
}
boolean realUser = true;
final UserAccount user = _userAccountDao.getUserAccount(username, domainId);
if (user == null) {
s_logger.debug("Unable to find user with " + username + " in domain " + domainId);
realUser = false;
}
/* Fake Data */
String realPassword = new String(s_defaultPassword);
byte[] salt = new String(s_defaultSalt).getBytes();
if (realUser) {
final String[] storedPassword = user.getPassword().split(":");
if (storedPassword.length != 2) {
s_logger.warn("The stored password for " + username + " isn't in the right format for this authenticator");
realUser = false;
} else {
realPassword = storedPassword[1];
salt = Base64.decode(storedPassword[0]);
}
}
try {
final String hashedPassword = encode(password, salt);
/* constantTimeEquals comes first in boolean since we need to thwart timing attacks */
final boolean result = constantTimeEquals(realPassword, hashedPassword) && realUser;
ActionOnFailedAuthentication action = null;
if (!result && realUser) {
action = ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT;
}
return new Pair<>(result, action);
} catch (final NoSuchAlgorithmException e) {
throw new CloudRuntimeException("Unable to hash password", e);
} catch (final UnsupportedEncodingException e) {
throw new CloudRuntimeException("Unable to hash password", e);
}
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class ResourceManagerImpl method getOrCreateCluster.
private Long getOrCreateCluster(final DataCenterVO zone, final HostPodVO pod, Long clusterId, final String clusterName, final String hypervisorType) {
final Long dcId = zone.getId();
final Long podId = pod.getId();
if (clusterName != null) {
ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
cluster.setHypervisorType(hypervisorType);
try {
cluster = this._clusterDao.persist(cluster);
} catch (final Exception e) {
cluster = this._clusterDao.findBy(clusterName, podId);
if (cluster == null) {
final CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod with specified podId and data center with specified dcID", e);
ex.addProxyObject(pod.getUuid(), "podId");
ex.addProxyObject(zone.getUuid(), "dcId");
throw ex;
}
}
clusterId = cluster.getId();
if (this._clusterDetailsDao.findDetail(clusterId, "cpuOvercommitRatio") == null) {
final ClusterDetailsVO cluster_cpu_detail = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", "1");
final ClusterDetailsVO cluster_memory_detail = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", "1");
this._clusterDetailsDao.persist(cluster_cpu_detail);
this._clusterDetailsDao.persist(cluster_memory_detail);
}
}
return clusterId;
}
Aggregations