Search in sources :

Example 41 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method doCancelMaintenance.

private boolean doCancelMaintenance(final long hostId) {
    final HostVO host;
    host = this._hostDao.findById(hostId);
    if (host == null || host.getRemoved() != null) {
        s_logger.warn("Unable to find host " + hostId);
        return true;
    }
    /*
         * TODO: think twice about returning true or throwing out exception, I
         * really prefer to exception that always exposes bugs
         */
    if (host.getResourceState() != ResourceState.PrepareForMaintenance && host.getResourceState() != ResourceState.Maintenance && host.getResourceState() != ResourceState.ErrorInMaintenance) {
        throw new CloudRuntimeException("Cannot perform cancelMaintenance when resource state is " + host.getResourceState() + ", hostId = " + hostId);
    }
    /* TODO: move to listener */
    this._haMgr.cancelScheduledMigrations(host);
    boolean vms_migrating = false;
    final List<VMInstanceVO> vms = this._haMgr.findTakenMigrationWork();
    for (final VMInstanceVO vm : vms) {
        if (vm.getHostId() != null && vm.getHostId() == hostId) {
            s_logger.warn("Unable to cancel migration because the vm is being migrated: " + vm + ", hostId = " + hostId);
            vms_migrating = true;
        }
    }
    try {
        resourceStateTransitTo(host, ResourceState.Event.AdminCancelMaintenance, this._nodeId);
        this._agentMgr.pullAgentOutMaintenance(hostId);
        // for kvm, need to log into kvm host, restart cosmic-agent
        if ((host.getHypervisorType() == HypervisorType.KVM && !vms_migrating)) {
            final boolean sshToAgent = Boolean.parseBoolean(this._configDao.getValue(Config.KvmSshToAgentEnabled.key()));
            if (!sshToAgent) {
                s_logger.info("Configuration tells us not to SSH into Agents. Please restart the Agent (" + hostId + ")  manually");
                return true;
            }
            this._hostDao.loadDetails(host);
            final String password = host.getDetail("password");
            final String username = host.getDetail("username");
            if (password == null || username == null) {
                s_logger.debug("Can't find password/username");
                return false;
            }
            final com.trilead.ssh2.Connection connection = SSHCmdHelper.acquireAuthorizedConnection(host.getPrivateIpAddress(), 22, username, password);
            if (connection == null) {
                s_logger.debug("Failed to connect to host: " + host.getPrivateIpAddress());
                return false;
            }
            try {
                SSHCmdHelper.sshExecuteCmdOneShot(connection, "systemctl restart cosmic-agent");
            } catch (final SshException e) {
                s_logger.info("Tried to restart agent but it failed. Please restart the Agent (" + hostId + ")  manually");
                // No need to send an error.
                return true;
            }
        }
        return true;
    } catch (final NoTransitionException e) {
        s_logger.debug("Cannot transmit host " + host.getId() + "to Enabled state", e);
        return false;
    }
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) VMInstanceVO(com.cloud.vm.VMInstanceVO) SshException(com.cloud.utils.ssh.SshException) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Example 42 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class NetworkACLManagerImpl method createNetworkACLItem.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_ITEM_CREATE, eventDescription = "creating network ACL Item", create = true)
public NetworkACLItem createNetworkACLItem(final Integer portStart, final Integer portEnd, final String protocol, final List<String> sourceCidrList, final Integer icmpCode, final Integer icmpType, final NetworkACLItem.TrafficType trafficType, final Long aclId, final String action, Integer number, final Boolean forDisplay) {
    // If number is null, set it to currentMax + 1 (for backward compatibility)
    if (number == null) {
        number = _networkACLItemDao.getMaxNumberByACL(aclId) + 1;
    }
    final Integer numberFinal = number;
    final NetworkACLItemVO newRule = Transaction.execute(new TransactionCallback<NetworkACLItemVO>() {

        @Override
        public NetworkACLItemVO doInTransaction(final TransactionStatus status) {
            NetworkACLItem.Action ruleAction = NetworkACLItem.Action.Allow;
            if ("deny".equalsIgnoreCase(action)) {
                ruleAction = NetworkACLItem.Action.Deny;
            }
            NetworkACLItemVO newRule = new NetworkACLItemVO(portStart, portEnd, protocol.toLowerCase(), aclId, sourceCidrList, icmpCode, icmpType, trafficType, ruleAction, numberFinal);
            if (forDisplay != null) {
                newRule.setDisplay(forDisplay);
            }
            newRule = _networkACLItemDao.persist(newRule);
            if (!_networkACLItemDao.setStateToAdd(newRule)) {
                throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
            }
            CallContext.current().setEventDetails("ACL Item Id: " + newRule.getId());
            return newRule;
        }
    });
    return getNetworkACLItem(newRule.getId());
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) TransactionStatus(com.cloud.utils.db.TransactionStatus) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 43 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class NetworkACLManagerImpl method replaceNetworkACL.

@Override
public boolean replaceNetworkACL(final NetworkACL acl, final NetworkVO network) throws ResourceUnavailableException {
    final NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
    if (guestNtwkOff == null) {
        throw new InvalidParameterValueException("Can't find network offering associated with network: " + network.getUuid());
    }
    // verify that ACLProvider is supported by network offering
    if (!_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.NetworkACL)) {
        throw new InvalidParameterValueException("Cannot apply NetworkACL. Network Offering does not support NetworkACL service");
    }
    if (network.getNetworkACLId() != null) {
        // Revoke ACL Items of the existing ACL if the new ACL is empty
        // Existing rules won't be removed otherwise
        final List<NetworkACLItemVO> aclItems = _networkACLItemDao.listByACL(acl.getId());
        if (aclItems == null || aclItems.isEmpty()) {
            s_logger.debug("New network ACL is empty. Revoke existing rules before applying ACL");
            if (!revokeACLItemsForNetwork(network.getId())) {
                throw new CloudRuntimeException("Failed to replace network ACL. Error while removing existing ACL items for network: " + network.getId());
            }
        }
    }
    network.setNetworkACLId(acl.getId());
    // Update Network ACL
    if (_networkDao.update(network.getId(), network)) {
        s_logger.debug("Updated network: " + network.getId() + " with Network ACL Id: " + acl.getId() + ", Applying ACL items");
        // Apply ACL to network
        final Boolean result = applyACLToNetwork(network.getId());
        if (result) {
            // public message on message bus, so that network elements implementing distributed routing capability
            // can act on the event
            _messageBus.publish(_name, "Network_ACL_Replaced", PublishScope.LOCAL, network);
        }
        return result;
    }
    return false;
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 44 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCopyVolumeCommandCloudRuntime2.

@Test
public void testCopyVolumeCommandCloudRuntime2() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long volumeId = 1l;
    final int wait = 0;
    final String volumePath = "/vol/path";
    final boolean toSecondaryStorage = false;
    final boolean executeInSequence = false;
    final CopyVolumeCommand command = new CopyVolumeCommand(volumeId, volumePath, storagePool, secondaryStoragePoolURL, toSecondaryStorage, wait, executeInSequence);
    final StorageFilerTO pool = command.getPool();
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenThrow(new CloudRuntimeException("error"));
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) CopyVolumeCommand(com.cloud.legacymodel.communication.command.CopyVolumeCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Example 45 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method umount.

protected void umount(final String localRootPath, final URI uri) {
    ensureLocalRootPathExists(localRootPath, uri);
    if (!mountExists(localRootPath, uri)) {
        return;
    }
    final Script command = new Script(!this._inSystemVM, "mount", this._timeout, s_logger);
    command.add(localRootPath);
    final String result = command.execute();
    if (result != null) {
        // Fedora Core 12 errors out with any -o option executed from java
        final String errMsg = "Unable to umount " + localRootPath + " due to " + result;
        s_logger.error(errMsg);
        final File file = new File(localRootPath);
        if (file.exists()) {
            file.delete();
        }
        throw new CloudRuntimeException(errMsg);
    }
    s_logger.debug("Successfully umounted " + localRootPath);
}
Also used : Script(com.cloud.utils.script.Script) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) File(java.io.File)

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