Search in sources :

Example 66 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class HypervDirectConnectResource method execute.

private PlugNicAnswer execute(final PlugNicCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource PlugNicCommand " + s_gson.toJson(cmd));
    }
    try {
        final String vmName = cmd.getVmName();
        final NicTO nic = cmd.getNic();
        final URI broadcastUri = nic.getBroadcastUri();
        if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
            throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + nic.getBroadcastUri());
        }
        final String vlanId = BroadcastDomainType.getValue(broadcastUri);
        int publicNicInfo = -1;
        publicNicInfo = getVmFreeNicIndex(vmName);
        if (publicNicInfo > 0) {
            modifyNicVlan(vmName, vlanId, publicNicInfo, true, cmd.getNic().getName());
            return new PlugNicAnswer(cmd, true, "success");
        }
        final String msg = " Plug Nic failed for the vm as it has reached max limit of NICs to be added";
        s_logger.warn(msg);
        return new PlugNicAnswer(cmd, false, msg);
    } catch (final Exception e) {
        s_logger.error("Unexpected exception: ", e);
        return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString());
    }
}
Also used : InternalErrorException(com.cloud.exception.InternalErrorException) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) URI(java.net.URI) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException) NicTO(com.cloud.agent.api.to.NicTO)

Example 67 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class IvsVifDriver method createVnet.

private void createVnet(String vnetId, String pif, String brName, String protocol) throws InternalErrorException {
    synchronized (_vnetBridgeMonitor) {
        String script = _modifyVlanPath;
        if (protocol.equals(Networks.BroadcastDomainType.Vxlan.scheme())) {
            script = _modifyVxlanPath;
        }
        final Script command = new Script(script, _timeout, s_logger);
        command.add("-v", vnetId);
        command.add("-p", pif);
        command.add("-b", brName);
        command.add("-o", "add");
        final String result = command.execute();
        if (result != null) {
            throw new InternalErrorException("Failed to create vnet " + vnetId + ": " + result);
        }
    }
}
Also used : Script(com.cloud.utils.script.Script) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 68 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class LibvirtStartCommandWrapper method execute.

@Override
public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final VirtualMachineTO vmSpec = command.getVirtualMachine();
    vmSpec.setVncAddr(command.getHostIp());
    final String vmName = vmSpec.getName();
    LibvirtVMDef vm = null;
    DomainState state = DomainState.VIR_DOMAIN_SHUTOFF;
    final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
    Connect conn = null;
    try {
        vm = libvirtComputingResource.createVMFromSpec(vmSpec);
        conn = libvirtUtilitiesHelper.getConnectionByType(vm.getHvsType());
        Long remainingMem = getFreeMemory(conn, libvirtComputingResource);
        if (remainingMem == null) {
            return new StartAnswer(command, "failed to get free memory");
        } else if (remainingMem < vmSpec.getMinRam()) {
            return new StartAnswer(command, "Not enough memory on the host, remaining: " + remainingMem + ", asking: " + vmSpec.getMinRam());
        }
        final NicTO[] nics = vmSpec.getNics();
        for (final NicTO nic : nics) {
            if (vmSpec.getType() != VirtualMachine.Type.User) {
                nic.setPxeDisable(true);
            }
        }
        libvirtComputingResource.createVbd(conn, vmSpec, vmName, vm);
        if (!storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)) {
            return new StartAnswer(command, "Failed to connect physical disks to host");
        }
        libvirtComputingResource.createVifs(vmSpec, vm);
        s_logger.debug("starting " + vmName + ": " + vm.toString());
        libvirtComputingResource.startVM(conn, vmName, vm.toString());
        for (final NicTO nic : nics) {
            if (nic.isSecurityGroupEnabled() || nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) {
                if (vmSpec.getType() != VirtualMachine.Type.User) {
                    libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, vmName);
                    break;
                } else {
                    final List<String> nicSecIps = nic.getNicSecIps();
                    String secIpsStr;
                    final StringBuilder sb = new StringBuilder();
                    if (nicSecIps != null) {
                        for (final String ip : nicSecIps) {
                            sb.append(ip).append(":");
                        }
                        secIpsStr = sb.toString();
                    } else {
                        secIpsStr = "0:";
                    }
                    libvirtComputingResource.defaultNetworkRules(conn, vmName, nic, vmSpec.getId(), secIpsStr);
                }
            }
        }
        // pass cmdline info to system vms
        if (vmSpec.getType() != VirtualMachine.Type.User) {
            //wait and try passCmdLine for 5 minutes at most for CLOUDSTACK-2823
            String controlIp = null;
            for (final NicTO nic : nics) {
                if (nic.getType() == TrafficType.Control) {
                    controlIp = nic.getIp();
                    break;
                }
            }
            for (int count = 0; count < 30; count++) {
                libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs());
                //check router is up?
                final VirtualRoutingResource virtRouterResource = libvirtComputingResource.getVirtRouterResource();
                final boolean result = virtRouterResource.connect(controlIp, 1, 5000);
                if (result) {
                    break;
                }
            }
        }
        state = DomainState.VIR_DOMAIN_RUNNING;
        return new StartAnswer(command);
    } catch (final LibvirtException e) {
        s_logger.warn("LibvirtException ", e);
        if (conn != null) {
            libvirtComputingResource.handleVmStartFailure(conn, vmName, vm);
        }
        return new StartAnswer(command, e.getMessage());
    } catch (final InternalErrorException e) {
        s_logger.warn("InternalErrorException ", e);
        if (conn != null) {
            libvirtComputingResource.handleVmStartFailure(conn, vmName, vm);
        }
        return new StartAnswer(command, e.getMessage());
    } catch (final URISyntaxException e) {
        s_logger.warn("URISyntaxException ", e);
        if (conn != null) {
            libvirtComputingResource.handleVmStartFailure(conn, vmName, vm);
        }
        return new StartAnswer(command, e.getMessage());
    } finally {
        if (state != DomainState.VIR_DOMAIN_RUNNING) {
            storagePoolMgr.disconnectPhysicalDisksViaVmSpec(vmSpec);
        }
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) StartAnswer(com.cloud.agent.api.StartAnswer) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) InternalErrorException(com.cloud.exception.InternalErrorException) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) LibvirtVMDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef) DomainState(org.libvirt.DomainInfo.DomainState) NicTO(com.cloud.agent.api.to.NicTO)

Example 69 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class LibvirtPrepareForMigrationCommandWrapper method execute.

@Override
public Answer execute(final PrepareForMigrationCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final VirtualMachineTO vm = command.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    final NicTO[] nics = vm.getNics();
    boolean skipDisconnect = false;
    final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vm.getName());
        for (final NicTO nic : nics) {
            libvirtComputingResource.getVifDriver(nic.getType()).plug(nic, null, "");
        }
        /* setup disks, e.g for iso */
        final DiskTO[] volumes = vm.getDisks();
        for (final DiskTO volume : volumes) {
            if (volume.getType() == Volume.Type.ISO) {
                libvirtComputingResource.getVolumePath(conn, volume);
            }
        }
        skipDisconnect = true;
        if (!storagePoolMgr.connectPhysicalDisksViaVmSpec(vm)) {
            return new PrepareForMigrationAnswer(command, "failed to connect physical disks to host");
        }
        return new PrepareForMigrationAnswer(command);
    } catch (final LibvirtException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } catch (final InternalErrorException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } catch (final URISyntaxException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } finally {
        if (!skipDisconnect) {
            storagePoolMgr.disconnectPhysicalDisksViaVmSpec(vm);
        }
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.exception.InternalErrorException) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) NicTO(com.cloud.agent.api.to.NicTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 70 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class CitrixResourceBase method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) {
    final Connection conn = getConnection();
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
    try {
        final IpAddressTO[] ips = cmd.getIpAddresses();
        for (final IpAddressTO ip : ips) {
            final VM router = getVM(conn, routerName);
            final NicTO nic = new NicTO();
            nic.setMac(ip.getVifMacAddress());
            nic.setType(ip.getTrafficType());
            if (ip.getBroadcastUri() == null) {
                nic.setBroadcastType(BroadcastDomainType.Native);
            } else {
                final URI uri = BroadcastDomainType.fromString(ip.getBroadcastUri());
                nic.setBroadcastType(BroadcastDomainType.getSchemeValue(uri));
                nic.setBroadcastUri(uri);
            }
            nic.setDeviceId(0);
            nic.setNetworkRateMbps(ip.getNetworkRate());
            nic.setName(ip.getNetworkName());
            final Network network = getNetwork(conn, nic);
            // Determine the correct VIF on DomR to associate/disassociate
            // the
            // IP address with
            VIF correctVif = getCorrectVif(conn, router, network);
            // If we are associating an IP address and DomR doesn't have a
            // VIF
            // for the specified vlan ID, we need to add a VIF
            // If we are disassociating the last IP address in the VLAN, we
            // need
            // to remove a VIF
            boolean addVif = false;
            if (ip.isAdd() && correctVif == null) {
                addVif = true;
            }
            if (addVif) {
                // Add a new VIF to DomR
                final String vifDeviceNum = getLowestAvailableVIFDeviceNum(conn, router);
                if (vifDeviceNum == null) {
                    throw new InternalErrorException("There were no more available slots for a new VIF on router: " + router.getNameLabel(conn));
                }
                nic.setDeviceId(Integer.parseInt(vifDeviceNum));
                correctVif = createVif(conn, routerName, router, null, nic);
                correctVif.plug(conn);
                // Add iptables rule for network usage
                networkUsage(conn, routerIp, "addVif", "eth" + correctVif.getDevice(conn));
            }
            if (ip.isAdd() && correctVif == null) {
                throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
            }
            if (correctVif != null) {
                ip.setNicDevId(Integer.valueOf(correctVif.getDevice(conn)));
                ip.setNewNic(addVif);
            }
        }
    } catch (final InternalErrorException e) {
        s_logger.error("Ip Assoc failure on applying one ip due to exception:  ", e);
        return new ExecutionResult(false, e.getMessage());
    } catch (final Exception e) {
        return new ExecutionResult(false, e.getMessage());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) ExecutionResult(com.cloud.utils.ExecutionResult) InternalErrorException(com.cloud.exception.InternalErrorException) URI(java.net.URI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) VIF(com.xensource.xenapi.VIF) VM(com.xensource.xenapi.VM) Network(com.xensource.xenapi.Network) NicTO(com.cloud.agent.api.to.NicTO)

Aggregations

InternalErrorException (com.cloud.exception.InternalErrorException)86 IOException (java.io.IOException)28 LibvirtException (org.libvirt.LibvirtException)27 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)25 Connect (org.libvirt.Connect)23 URISyntaxException (java.net.URISyntaxException)21 ConfigurationException (javax.naming.ConfigurationException)21 Answer (com.cloud.agent.api.Answer)17 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)16 NicTO (com.cloud.agent.api.to.NicTO)15 URI (java.net.URI)15 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)14 Script (com.cloud.utils.script.Script)14 Test (org.junit.Test)14 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)12 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)12 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)12 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)12 Processor (com.cloud.storage.template.Processor)11 TemplateLocation (com.cloud.storage.template.TemplateLocation)11