Search in sources :

Example 11 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 12 with ResourceInUseException

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

the class SecurityGroupManagerImpl method deleteSecurityGroup.

@DB
@Override
@ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_DELETE, eventDescription = "deleting security group")
public boolean deleteSecurityGroup(DeleteSecurityGroupCmd cmd) throws ResourceInUseException {
    final Long groupId = cmd.getId();
    Account caller = CallContext.current().getCallingAccount();
    SecurityGroupVO group = _securityGroupDao.findById(groupId);
    if (group == null) {
        throw new InvalidParameterValueException("Unable to find network group: " + groupId + "; failed to delete group.");
    }
    // check permissions
    _accountMgr.checkAccess(caller, null, true, group);
    return Transaction.execute(new TransactionCallbackWithException<Boolean, ResourceInUseException>() {

        @Override
        public Boolean doInTransaction(TransactionStatus status) throws ResourceInUseException {
            SecurityGroupVO group = _securityGroupDao.lockRow(groupId, true);
            if (group == null) {
                throw new InvalidParameterValueException("Unable to find security group by id " + groupId);
            }
            if (group.getName().equalsIgnoreCase(SecurityGroupManager.DEFAULT_GROUP_NAME)) {
                throw new InvalidParameterValueException("The network group default is reserved");
            }
            List<SecurityGroupRuleVO> allowingRules = _securityGroupRuleDao.listByAllowedSecurityGroupId(groupId);
            List<SecurityGroupVMMapVO> securityGroupVmMap = _securityGroupVMMapDao.listBySecurityGroup(groupId);
            if (!allowingRules.isEmpty()) {
                throw new ResourceInUseException("Cannot delete group when there are security rules that allow this group");
            } else if (!securityGroupVmMap.isEmpty()) {
                throw new ResourceInUseException("Cannot delete group when it's in use by virtual machines");
            }
            _securityGroupDao.expunge(groupId);
            s_logger.debug("Deleted security group id=" + groupId);
            return true;
        }
    });
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceInUseException(com.cloud.exception.ResourceInUseException) TransactionStatus(com.cloud.utils.db.TransactionStatus) ArrayList(java.util.ArrayList) List(java.util.List) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 13 with ResourceInUseException

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

the class DeleteVolumePoolCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        netappMgr.deletePool(poolName);
        DeleteVolumePoolCmdResponse response = new DeleteVolumePoolCmdResponse();
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException e) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString());
    } catch (ResourceInUseException e) {
        throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, e.toString());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceInUseException(com.cloud.exception.ResourceInUseException) DeleteVolumePoolCmdResponse(com.cloud.server.api.response.netapp.DeleteVolumePoolCmdResponse)

Example 14 with ResourceInUseException

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

the class DestroyVolumeOnFilerCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        netappMgr.destroyVolumeOnFiler(ipAddr, aggrName, volumeName);
        DeleteVolumeOnFilerCmdResponse response = new DeleteVolumeOnFilerCmdResponse();
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException e) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString());
    } catch (ResourceInUseException e) {
        throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, e.toString());
    } catch (ServerException e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
    }
}
Also used : ServerException(java.rmi.ServerException) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DeleteVolumeOnFilerCmdResponse(com.cloud.server.api.response.netapp.DeleteVolumeOnFilerCmdResponse) ResourceInUseException(com.cloud.exception.ResourceInUseException)

Example 15 with ResourceInUseException

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

the class AddClusterCmd method execute.

@Override
public void execute() {
    try {
        List<? extends Cluster> result = _resourceService.discoverCluster(this);
        ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
        List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
        if (result != null) {
            for (Cluster cluster : result) {
                ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
                clusterResponses.add(clusterResponse);
            }
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add cluster");
        }
        response.setResponses(clusterResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceInUseException ex) {
        s_logger.warn("Exception: ", ex);
        ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
        for (IdentityProxy proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj.getTableName(), proxyObj.getValue(), proxyObj.getidFieldName());
        }
        throw e;
    }
}
Also used : IdentityProxy(com.cloud.utils.IdentityProxy) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) ResourceInUseException(com.cloud.exception.ResourceInUseException) ArrayList(java.util.ArrayList) ClusterResponse(com.cloud.api.response.ClusterResponse) Cluster(com.cloud.org.Cluster) DiscoveryException(com.cloud.exception.DiscoveryException)

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