Search in sources :

Example 1 with ResourceInUseException

use of com.cloud.exception.ResourceInUseException in project CloudStack-archive by CloudStack-extras.

the class DeleteSecurityGroupCmd method execute.

@Override
public void execute() {
    try {
        boolean result = _securityGroupService.deleteSecurityGroup(this);
        if (result) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete security group");
        }
    } catch (ResourceInUseException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, ex.getMessage());
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException) ResourceInUseException(com.cloud.exception.ResourceInUseException)

Example 2 with ResourceInUseException

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

the class AddVmwareDcCmd method execute.

@Override
public void execute() {
    try {
        VmwareDatacenterResponse response = new VmwareDatacenterResponse();
        VmwareDatacenterVO result = _vmwareDatacenterService.addVmwareDatacenter(this);
        if (result != null) {
            response.setId(result.getUuid());
            response.setName(result.getVmwareDatacenterName());
            response.setResponseName(getCommandName());
            response.setObjectName("vmwaredc");
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add VMware Datacenter to zone.");
        }
        this.setResponseObject(response);
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceInUseException ex) {
        s_logger.warn("Exception: ", ex);
        ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
        for (String proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj);
        }
        throw e;
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException(ex.getMessage());
    } catch (CloudRuntimeException runtimeEx) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeEx.getMessage());
    }
}
Also used : VmwareDatacenterResponse(org.apache.cloudstack.api.response.VmwareDatacenterResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 3 with ResourceInUseException

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

the class RemoveVmwareDcCmd method execute.

@Override
public void execute() {
    SuccessResponse response = new SuccessResponse();
    try {
        boolean result = _vmwareDatacenterService.removeVmwareDatacenter(this);
        if (result) {
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove VMware datacenter from zone");
        }
    } catch (ResourceInUseException ex) {
        s_logger.warn("The zone has one or more resources (like cluster), hence not able to remove VMware datacenter from zone." + " Please remove all resource from zone, and retry. Exception: ", ex);
        ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
        for (String proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj);
        }
        throw e;
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException(ex.getMessage());
    } catch (CloudRuntimeException runtimeEx) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeEx.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException)

Example 4 with ResourceInUseException

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

the class CiscoNexusVSMElement method validateAndAddVsm.

@Override
@DB
public Pair<Boolean, Long> validateAndAddVsm(final String vsmIp, final String vsmUser, final String vsmPassword, final long clusterId, String clusterName) throws ResourceInUseException {
    CiscoNexusVSMDeviceVO vsm = null;
    boolean vsmAdded = false;
    Long vsmId = 0L;
    if (vsmIp != null && vsmUser != null && vsmPassword != null) {
        NetconfHelper netconfClient;
        try {
            netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
            netconfClient.disconnect();
        } catch (CloudRuntimeException e) {
            String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
            s_logger.error(msg);
            _clusterDao.remove(clusterId);
            throw new CloudRuntimeException(msg);
        }
        // If VSM already exists and is mapped to a cluster, fail this operation.
        vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
        if (vsm != null) {
            List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsm.getId());
            if (clusterList != null && !clusterList.isEmpty()) {
                s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster");
                ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id");
                // get clusterUuid to report error
                ClusterVO cluster = _clusterDao.findById(clusterList.get(0).getClusterId());
                ex.addProxyObject(cluster.getUuid());
                _clusterDao.remove(clusterId);
                throw ex;
            }
        }
        // persist credentials to database if the VSM entry is not already in the db.
        vsm = Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>() {

            @Override
            public CiscoNexusVSMDeviceVO doInTransaction(TransactionStatus status) {
                CiscoNexusVSMDeviceVO vsm = null;
                if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
                    vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
                    _vsmDao.persist(vsm);
                }
                // Create a mapping between the cluster and the vsm.
                vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
                if (vsm != null) {
                    ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
                    _clusterVSMDao.persist(connectorObj);
                }
                return vsm;
            }
        });
    } else {
        String msg;
        msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() + " is set to \"true\". Following mandatory parameters are not specified. ";
        if (vsmIp == null) {
            msg += "vsmipaddress: Management IP address of Cisco Nexus 1000v dvSwitch. ";
        }
        if (vsmUser == null) {
            msg += "vsmusername: Name of a user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
        }
        if (vsmPassword == null) {
            if (vsmUser != null) {
                msg += "vsmpassword: Password of user account " + vsmUser + ". ";
            } else {
                msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
            }
        }
        s_logger.error(msg);
        // Cleaning up the cluster record as addCluster operation failed because of invalid credentials of Nexus dvSwitch.
        _clusterDao.remove(clusterId);
        throw new CloudRuntimeException(msg);
    }
    if (vsm != null) {
        vsmAdded = true;
        vsmId = vsm.getId();
    }
    return new Pair<Boolean, Long>(vsmAdded, vsmId);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallback(com.cloud.utils.db.TransactionCallback) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) NetconfHelper(com.cloud.utils.cisco.n1kv.vsm.NetconfHelper) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Example 5 with ResourceInUseException

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

the class CreateStoragePoolCmd method execute.

@Override
public void execute() {
    try {
        StoragePool result = _storageService.createPool(this);
        if (result != null) {
            StoragePoolResponse response = _responseGenerator.createStoragePoolResponse(result);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add storage pool");
        }
    } catch (ResourceUnavailableException ex1) {
        s_logger.warn("Exception: ", ex1);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex1.getMessage());
    } catch (ResourceInUseException ex2) {
        s_logger.warn("Exception: ", ex2);
        throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex2.getMessage());
    } catch (UnknownHostException ex3) {
        s_logger.warn("Exception: ", ex3);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex3.getMessage());
    } catch (Exception ex4) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex4.getMessage());
    }
}
Also used : StoragePoolResponse(org.apache.cloudstack.api.response.StoragePoolResponse) StoragePool(com.cloud.storage.StoragePool) ServerApiException(org.apache.cloudstack.api.ServerApiException) UnknownHostException(java.net.UnknownHostException) ResourceInUseException(com.cloud.exception.ResourceInUseException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnknownHostException(java.net.UnknownHostException) ResourceInUseException(com.cloud.exception.ResourceInUseException)

Aggregations

ResourceInUseException (com.cloud.exception.ResourceInUseException)22 ServerApiException (org.apache.cloudstack.api.ServerApiException)10 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 DiscoveryException (com.cloud.exception.DiscoveryException)8 DB (com.cloud.utils.db.DB)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 ArrayList (java.util.ArrayList)4 ConfigurationException (javax.naming.ConfigurationException)4 ServerApiException (com.cloud.api.ServerApiException)3 ClusterVO (com.cloud.dc.ClusterVO)3 DataCenterVO (com.cloud.dc.DataCenterVO)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 HostVO (com.cloud.host.HostVO)3 VmwareDatacenterVO (com.cloud.hypervisor.vmware.VmwareDatacenterVO)3 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)3 Cluster (com.cloud.org.Cluster)3 TransactionStatus (com.cloud.utils.db.TransactionStatus)3 UnknownHostException (java.net.UnknownHostException)3 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)3 ClusterVSMMapVO (com.cloud.dc.ClusterVSMMapVO)2