Search in sources :

Example 26 with InternalErrorException

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

the class ExtractTemplateCmd method execute.

@Override
public void execute() {
    try {
        CallContext.current().setEventDetails(getEventDescription());
        String uploadUrl = _templateService.extract(this);
        if (uploadUrl != null) {
            ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract template");
        }
    } catch (InternalErrorException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ExtractResponse(org.apache.cloudstack.api.response.ExtractResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 27 with InternalErrorException

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

the class HypervDirectConnectResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) {
    try {
        final IpAddressTO[] ips = cmd.getIpAddresses();
        final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
        final String controlIp = getRouterSshControlIp(cmd);
        for (final IpAddressTO ip : ips) {
            /**
                 * TODO support other networks
                 */
            final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
            if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + ip.getBroadcastUri());
            }
            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
            int publicNicInfo = -1;
            publicNicInfo = getVmNics(routerName, vlanId);
            boolean addVif = false;
            if (ip.isAdd() && publicNicInfo == -1) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp());
                }
                addVif = true;
            }
            if (addVif) {
                final Pair<Integer, String> nicdevice = findRouterFreeEthDeviceIndex(controlIp);
                publicNicInfo = nicdevice.first();
                if (publicNicInfo > 0) {
                    modifyNicVlan(routerName, vlanId, nicdevice.second());
                    // After modifying the vnic on VR, check the VR VNics config in the host and get the device position
                    publicNicInfo = getVmNics(routerName, vlanId);
                    // As a new nic got activated in the VR. add the entry in the NIC's table.
                    networkUsage(controlIp, "addVif", "eth" + publicNicInfo);
                } else {
                    // we didn't find any eth device available in VR to configure the ip range with new VLAN
                    final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with.";
                    s_logger.error(msg);
                    throw new InternalErrorException(msg);
                }
                ip.setNicDevId(publicNicInfo);
                ip.setNewNic(addVif);
            } else {
                ip.setNicDevId(publicNicInfo);
            }
        }
    } catch (final Throwable e) {
        s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e);
        return new ExecutionResult(false, e.toString());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult) InternalErrorException(com.cloud.exception.InternalErrorException) URI(java.net.URI)

Example 28 with InternalErrorException

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

the class HypervDirectConnectResource method execute.

private UnPlugNicAnswer execute(final UnPlugNicCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource UnPlugNicCommand " + 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 unassign a public IP to a VIF on network " + nic.getBroadcastUri());
        }
        final String vlanId = BroadcastDomainType.getValue(broadcastUri);
        int publicNicInfo = -1;
        publicNicInfo = getVmNics(vmName, vlanId);
        if (publicNicInfo > 0) {
            modifyNicVlan(vmName, "2", publicNicInfo, false, "");
        }
        return new UnPlugNicAnswer(cmd, true, "success");
    } catch (final Exception e) {
        s_logger.error("Unexpected exception: ", e);
        return new UnPlugNicAnswer(cmd, false, "Unable to execute unPlugNicCommand due to " + e.toString());
    }
}
Also used : UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) InternalErrorException(com.cloud.exception.InternalErrorException) 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 29 with InternalErrorException

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

the class HypervDirectConnectResource method assignPublicIpAddress.

protected void assignPublicIpAddress(final String vmName, final String privateIpAddress, final String publicIpAddress, final boolean add, final boolean firstIP, final boolean sourceNat, final String broadcastId, final String vlanGateway, final String vlanNetmask, final String vifMacAddress) throws Exception {
    final URI broadcastUri = BroadcastDomainType.fromString(broadcastId);
    if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
        throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + broadcastId);
    }
    final String vlanId = BroadcastDomainType.getValue(broadcastUri);
    int publicNicInfo = -1;
    publicNicInfo = getVmNics(vmName, vlanId);
    boolean addVif = false;
    if (add && publicNicInfo == -1) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Plug new NIC to associate" + privateIpAddress + " to " + publicIpAddress);
        }
        addVif = true;
    } else if (!add && firstIP) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Unplug NIC " + publicNicInfo);
        }
    }
    if (addVif) {
        final Pair<Integer, String> nicdevice = findRouterFreeEthDeviceIndex(privateIpAddress);
        publicNicInfo = nicdevice.first();
        if (publicNicInfo > 0) {
            modifyNicVlan(vmName, vlanId, nicdevice.second());
            // After modifying the vnic on VR, check the VR VNics config in the host and get the device position
            publicNicInfo = getVmNics(vmName, vlanId);
            // As a new nic got activated in the VR. add the entry in the NIC's table.
            networkUsage(privateIpAddress, "addVif", "eth" + publicNicInfo);
        } else {
            // we didn't find any eth device available in VR to configure the ip range with new VLAN
            final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with.";
            s_logger.error(msg);
            throw new InternalErrorException(msg);
        }
    }
    String args = null;
    if (add) {
        args = " -A ";
    } else {
        args = " -D ";
    }
    if (sourceNat) {
        args += " -s ";
    }
    if (firstIP) {
        args += " -f ";
    }
    final String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask));
    args += " -l ";
    args += publicIpAddress + "/" + cidrSize;
    args += " -c ";
    args += "eth" + publicNicInfo;
    args += " -g ";
    args += vlanGateway;
    if (addVif) {
        args += " -n ";
    }
    final String command = String.format("%s%s %s", "/opt/cloud/bin/", VRScripts.IPASSOC, args);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Run command on domain router " + privateIpAddress + command);
    }
    final Pair<Boolean, String> result = SshHelper.sshExecute(privateIpAddress, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command);
    if (!result.first()) {
        s_logger.error("ipassoc command on domain router " + privateIpAddress + " failed. message: " + result.second());
        throw new Exception("ipassoc failed due to " + result.second());
    }
    if (s_logger.isInfoEnabled()) {
        s_logger.info("ipassoc command on domain router " + privateIpAddress + " completed");
    }
}
Also used : InternalErrorException(com.cloud.exception.InternalErrorException) 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)

Example 30 with InternalErrorException

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

the class HypervDirectConnectResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) {
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        final IpAddressTO[] ips = cmd.getIpAddresses();
        for (final IpAddressTO ip : ips) {
            final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
            if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                throw new InternalErrorException("Invalid Broadcast URI " + ip.getBroadcastUri());
            }
            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
            int publicNicInfo = -1;
            publicNicInfo = getVmNics(routerName, vlanId);
            if (publicNicInfo < 0) {
                if (ip.isAdd()) {
                    throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
                } else {
                    s_logger.debug("VIF to deassociate IP with does not exist, return success");
                    continue;
                }
            }
            ip.setNicDevId(publicNicInfo);
        }
    } catch (final Exception e) {
        s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception:  ", e);
        return new ExecutionResult(false, e.toString());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult) InternalErrorException(com.cloud.exception.InternalErrorException) 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)

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