Search in sources :

Example 31 with CloudRuntimeException

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());
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Site2SiteVpnServiceProvider(com.cloud.network.element.Site2SiteVpnServiceProvider) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 32 with CloudRuntimeException

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");
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) ActionEvent(com.cloud.event.ActionEvent)

Example 33 with CloudRuntimeException

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);
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 34 with CloudRuntimeException

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);
    }
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UserAccount(com.cloud.legacymodel.user.UserAccount) Pair(com.cloud.legacymodel.utils.Pair)

Example 35 with CloudRuntimeException

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;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) ResourceInUseException(com.cloud.legacymodel.exceptions.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) SshException(com.cloud.utils.ssh.SshException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.legacymodel.exceptions.UnableDeleteHostException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DiscoveryException(com.cloud.legacymodel.exceptions.DiscoveryException)

Aggregations

CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)587 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)159 ArrayList (java.util.ArrayList)110 DB (com.cloud.utils.db.DB)90 Account (com.cloud.legacymodel.user.Account)84 SQLException (java.sql.SQLException)84 ActionEvent (com.cloud.event.ActionEvent)73 ConfigurationException (javax.naming.ConfigurationException)73 PreparedStatement (java.sql.PreparedStatement)68 HashMap (java.util.HashMap)68 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)62 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)52 HostVO (com.cloud.host.HostVO)50 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)50 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)50 XenAPIException (com.xensource.xenapi.Types.XenAPIException)47 Answer (com.cloud.legacymodel.communication.answer.Answer)45 XmlRpcException (org.apache.xmlrpc.XmlRpcException)45 TransactionStatus (com.cloud.utils.db.TransactionStatus)44 IOException (java.io.IOException)44