Search in sources :

Example 56 with ConcurrentOperationException

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

the class AsyncJobExecutionContext method disjoinJob.

//
// check failure exception before we disjoin the worker job, work job usually fails with exception
// this will help propogate exception between jobs
// TODO : it is ugly and this will become unnecessary after we switch to full-async mode
//
public void disjoinJob(long joinedJobId) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    assert (_job != null);
    AsyncJobJoinMapVO record = s_joinMapDao.getJoinRecord(_job.getId(), joinedJobId);
    s_jobMgr.disjoinJob(_job.getId(), joinedJobId);
    if (record.getJoinStatus() == JobInfo.Status.FAILED) {
        if (record.getJoinResult() != null) {
            Object exception = JobSerializerHelper.fromObjectSerializedString(record.getJoinResult());
            if (exception != null && exception instanceof Exception) {
                if (exception instanceof InsufficientCapacityException) {
                    s_logger.error("Job " + joinedJobId + " failed with InsufficientCapacityException");
                    throw (InsufficientCapacityException) exception;
                } else if (exception instanceof ConcurrentOperationException) {
                    s_logger.error("Job " + joinedJobId + " failed with ConcurrentOperationException");
                    throw (ConcurrentOperationException) exception;
                } else if (exception instanceof ResourceUnavailableException) {
                    s_logger.error("Job " + joinedJobId + " failed with ResourceUnavailableException");
                    throw (ResourceUnavailableException) exception;
                } else {
                    s_logger.error("Job " + joinedJobId + " failed with exception");
                    throw new RuntimeException((Exception) exception);
                }
            }
        } else {
            s_logger.error("Job " + joinedJobId + " failed without providing an error object");
            throw new RuntimeException("Job " + joinedJobId + " failed without providing an error object");
        }
    }
}
Also used : AsyncJobJoinMapVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 57 with ConcurrentOperationException

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

the class CiscoVnmcElement method implement.

@Override
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
    if (zone.getNetworkType() == NetworkType.Basic) {
        s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic);
        return false;
    }
    if (!canHandle(network)) {
        return false;
    }
    final List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No Cisco Vnmc device on network " + network.getName());
        return false;
    }
    List<CiscoAsa1000vDeviceVO> asaList = _ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (asaList.isEmpty()) {
        s_logger.debug("No Cisco ASA 1000v device on network " + network.getName());
        return false;
    }
    NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId());
    if (asaForNetwork != null) {
        s_logger.debug("Cisco ASA 1000v device already associated with network " + network.getName());
        return true;
    }
    if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.CiscoVnmc)) {
        s_logger.error("SourceNat service is not provided by Cisco Vnmc device on network " + network.getName());
        return false;
    }
    try {
        // ensure that there is an ASA 1000v assigned to this network
        CiscoAsa1000vDevice assignedAsa = assignAsa1000vToNetwork(network);
        if (assignedAsa == null) {
            s_logger.error("Unable to assign ASA 1000v device to network " + network.getName());
            throw new CloudRuntimeException("Unable to assign ASA 1000v device to network " + network.getName());
        }
        ClusterVO asaCluster = _clusterDao.findById(assignedAsa.getClusterId());
        ClusterVSMMapVO clusterVsmMap = _clusterVsmMapDao.findByClusterId(assignedAsa.getClusterId());
        if (clusterVsmMap == null) {
            s_logger.error("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it");
            throw new CloudRuntimeException("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it");
        }
        CiscoNexusVSMDeviceVO vsmDevice = _vsmDeviceDao.findById(clusterVsmMap.getVsmId());
        if (vsmDevice == null) {
            s_logger.error("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName());
            throw new CloudRuntimeException("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName());
        }
        CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
        HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
        _hostDao.loadDetails(ciscoVnmcHost);
        Account owner = context.getAccount();
        PublicIp sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
        long vlanId = Long.parseLong(BroadcastDomainType.getValue(network.getBroadcastUri()));
        List<VlanVO> vlanVOList = _vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId());
        List<String> publicGateways = new ArrayList<String>();
        for (VlanVO vlanVO : vlanVOList) {
            publicGateways.add(vlanVO.getVlanGateway());
        }
        // due to VNMC limitation of not allowing source NAT ip as the outside ip of firewall,
        // an additional public ip needs to acquired for assigning as firewall outside ip.
        // In case there are already additional ip addresses available (network restart) use one
        // of them such that it is not the source NAT ip
        IpAddress outsideIp = null;
        List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
        for (IPAddressVO ip : publicIps) {
            if (!ip.isSourceNat()) {
                outsideIp = ip;
                break;
            }
        }
        if (outsideIp == null) {
            // none available, acquire one
            try {
                Account caller = CallContext.current().getCallingAccount();
                long callerUserId = CallContext.current().getCallingUserId();
                outsideIp = _ipAddrMgr.allocateIp(owner, false, caller, callerUserId, zone, true);
            } catch (ResourceAllocationException e) {
                s_logger.error("Unable to allocate additional public Ip address. Exception details " + e);
                throw new CloudRuntimeException("Unable to allocate additional public Ip address. Exception details " + e);
            }
            try {
                outsideIp = _ipAddrMgr.associateIPToGuestNetwork(outsideIp.getId(), network.getId(), true);
            } catch (ResourceAllocationException e) {
                s_logger.error("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details " + e);
                throw new CloudRuntimeException("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details " + e);
            }
        }
        // create logical edge firewall in VNMC
        String gatewayNetmask = NetUtils.getCidrNetmask(network.getCidr());
        // all public ip addresses must be from same subnet, this essentially means single public subnet in zone
        if (!createLogicalEdgeFirewall(vlanId, network.getGateway(), gatewayNetmask, outsideIp.getAddress().addr(), sourceNatIp.getNetmask(), publicGateways, ciscoVnmcHost.getId())) {
            s_logger.error("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName());
            throw new CloudRuntimeException("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName());
        }
        // create stuff in VSM for ASA device
        if (!configureNexusVsmForAsa(vlanId, network.getGateway(), vsmDevice.getUserName(), vsmDevice.getPassword(), vsmDevice.getipaddr(), assignedAsa.getInPortProfile(), ciscoVnmcHost.getId())) {
            s_logger.error("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() + " for ASA device for network " + network.getName());
            throw new CloudRuntimeException("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() + " for ASA device for network " + network.getName());
        }
        // configure source NAT
        if (!configureSourceNat(vlanId, network.getCidr(), sourceNatIp, ciscoVnmcHost.getId())) {
            s_logger.error("Failed to configure source NAT in Cisco VNMC device for network " + network.getName());
            throw new CloudRuntimeException("Failed to configure source NAT in Cisco VNMC device for network " + network.getName());
        }
        // associate Asa 1000v instance with logical edge firewall
        if (!associateAsaWithLogicalEdgeFirewall(vlanId, assignedAsa.getManagementIp(), ciscoVnmcHost.getId())) {
            s_logger.error("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() + ") with logical edge firewall in VNMC for network " + network.getName());
            throw new CloudRuntimeException("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() + ") with logical edge firewall in VNMC for network " + network.getName());
        }
    } catch (CloudRuntimeException e) {
        unassignAsa1000vFromNetwork(network);
        s_logger.error("CiscoVnmcElement failed", e);
        return false;
    } catch (Exception e) {
        unassignAsa1000vFromNetwork(network);
        ExceptionUtil.rethrowRuntime(e);
        ExceptionUtil.rethrow(e, InsufficientAddressCapacityException.class);
        ExceptionUtil.rethrow(e, ResourceUnavailableException.class);
        throw new IllegalStateException(e);
    }
    return true;
}
Also used : Account(com.cloud.user.Account) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ArrayList(java.util.ArrayList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) CiscoAsa1000vDevice(com.cloud.network.cisco.CiscoAsa1000vDevice) VlanVO(com.cloud.dc.VlanVO) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ClusterVO(com.cloud.dc.ClusterVO) CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) PublicIp(com.cloud.network.addr.PublicIp) HostVO(com.cloud.host.HostVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) EntityExistsException(javax.persistence.EntityExistsException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) DataCenter(com.cloud.dc.DataCenter) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 58 with ConcurrentOperationException

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

the class VMSnapshotManagerImpl method createVMSnapshot.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_SNAPSHOT_CREATE, eventDescription = "creating VM snapshot", async = true)
public VMSnapshot createVMSnapshot(Long vmId, Long vmSnapshotId, Boolean quiescevm) {
    UserVmVO userVm = _userVMDao.findById(vmId);
    if (userVm == null) {
        throw new InvalidParameterValueException("Create vm to snapshot failed due to vm: " + vmId + " is not found");
    }
    VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(vmSnapshotId);
    if (vmSnapshot == null) {
        throw new CloudRuntimeException("VM snapshot id: " + vmSnapshotId + " can not be found");
    }
    // serialize VM operation
    AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
    if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
        // avoid re-entrance
        VmWorkJobVO placeHolder = null;
        placeHolder = createPlaceHolderWork(vmId);
        try {
            return orchestrateCreateVMSnapshot(vmId, vmSnapshotId, quiescevm);
        } finally {
            _workJobDao.expunge(placeHolder.getId());
        }
    } else {
        Outcome<VMSnapshot> outcome = createVMSnapshotThroughJobQueue(vmId, vmSnapshotId, quiescevm);
        VMSnapshot result = null;
        try {
            result = outcome.get();
        } catch (InterruptedException e) {
            throw new RuntimeException("Operation is interrupted", e);
        } catch (java.util.concurrent.ExecutionException e) {
            throw new RuntimeException("Execution excetion", e);
        }
        Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
        if (jobResult != null) {
            if (jobResult instanceof ConcurrentOperationException)
                throw (ConcurrentOperationException) jobResult;
            else if (jobResult instanceof Throwable)
                throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
        }
        return result;
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ActionEvent(com.cloud.event.ActionEvent)

Example 59 with ConcurrentOperationException

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

the class VMSnapshotManagerImpl method deleteAllVMSnapshots.

@Override
public boolean deleteAllVMSnapshots(long vmId, VMSnapshot.Type type) {
    // serialize VM operation
    AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
    if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
        // avoid re-entrance
        VmWorkJobVO placeHolder = null;
        placeHolder = createPlaceHolderWork(vmId);
        try {
            return orchestrateDeleteAllVMSnapshots(vmId, type);
        } finally {
            if (placeHolder != null)
                _workJobDao.expunge(placeHolder.getId());
        }
    } else {
        Outcome<VirtualMachine> outcome = deleteAllVMSnapshotsThroughJobQueue(vmId, type);
        try {
            outcome.get();
        } catch (InterruptedException e) {
            throw new RuntimeException("Operation is interrupted", e);
        } catch (java.util.concurrent.ExecutionException e) {
            throw new RuntimeException("Execution excetion", e);
        }
        Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
        if (jobResult != null) {
            if (jobResult instanceof ConcurrentOperationException)
                throw (ConcurrentOperationException) jobResult;
            else if (jobResult instanceof InvalidParameterValueException)
                throw (InvalidParameterValueException) jobResult;
            else if (jobResult instanceof Throwable)
                throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
        }
        if (jobResult instanceof Boolean)
            return (Boolean) jobResult;
        return false;
    }
}
Also used : AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 60 with ConcurrentOperationException

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

the class VMSnapshotManagerImpl method deleteVMSnapshot.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_SNAPSHOT_DELETE, eventDescription = "delete vm snapshots", async = true)
public boolean deleteVMSnapshot(Long vmSnapshotId) {
    Account caller = getCaller();
    VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(vmSnapshotId);
    if (vmSnapshot == null) {
        throw new InvalidParameterValueException("unable to find the vm snapshot with id " + vmSnapshotId);
    }
    _accountMgr.checkAccess(caller, null, true, vmSnapshot);
    // check VM snapshot states, only allow to delete vm snapshots in created and error state
    if (VMSnapshot.State.Ready != vmSnapshot.getState() && VMSnapshot.State.Expunging != vmSnapshot.getState() && VMSnapshot.State.Error != vmSnapshot.getState()) {
        throw new InvalidParameterValueException("Can't delete the vm snapshotshot " + vmSnapshotId + " due to it is not in Created or Error, or Expunging State");
    }
    // check if there are other active VM snapshot tasks
    if (hasActiveVMSnapshotTasks(vmSnapshot.getVmId())) {
        List<VMSnapshotVO> expungingSnapshots = _vmSnapshotDao.listByInstanceId(vmSnapshot.getVmId(), VMSnapshot.State.Expunging);
        if (expungingSnapshots.size() > 0 && expungingSnapshots.get(0).getId() == vmSnapshot.getId())
            s_logger.debug("Target VM snapshot already in expunging state, go on deleting it: " + vmSnapshot.getDisplayName());
        else
            throw new InvalidParameterValueException("There is other active vm snapshot tasks on the instance, please try again later");
    }
    // serialize VM operation
    AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
    if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
        // avoid re-entrance
        VmWorkJobVO placeHolder = null;
        placeHolder = createPlaceHolderWork(vmSnapshot.getVmId());
        try {
            return orchestrateDeleteVMSnapshot(vmSnapshotId);
        } finally {
            _workJobDao.expunge(placeHolder.getId());
        }
    } else {
        Outcome<VMSnapshot> outcome = deleteVMSnapshotThroughJobQueue(vmSnapshot.getVmId(), vmSnapshotId);
        VMSnapshot result = null;
        try {
            result = outcome.get();
        } catch (InterruptedException e) {
            throw new RuntimeException("Operation is interrupted", e);
        } catch (java.util.concurrent.ExecutionException e) {
            throw new RuntimeException("Execution excetion", e);
        }
        Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
        if (jobResult != null) {
            if (jobResult instanceof ConcurrentOperationException)
                throw (ConcurrentOperationException) jobResult;
            else if (jobResult instanceof Throwable)
                throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
        }
        if (jobResult instanceof Boolean)
            return ((Boolean) jobResult).booleanValue();
        return false;
    }
}
Also used : Account(com.cloud.user.Account) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)153 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)96 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)80 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)71 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)43 ServerApiException (org.apache.cloudstack.api.ServerApiException)32 Account (com.cloud.user.Account)24 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)23 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)21 DB (com.cloud.utils.db.DB)21 AsyncJobExecutionContext (org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext)20 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)20 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)17 ConfigurationException (javax.naming.ConfigurationException)17 ArrayList (java.util.ArrayList)16 ActionEvent (com.cloud.event.ActionEvent)14 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)14 UserVm (com.cloud.uservm.UserVm)14 ManagementServerException (com.cloud.exception.ManagementServerException)13