Search in sources :

Example 36 with ConcurrentOperationException

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

the class HighAvailabilityManagerImpl method scheduleRestart.

@Override
public void scheduleRestart(VMInstanceVO vm, boolean investigate) {
    Long hostId = vm.getHostId();
    if (hostId == null) {
        try {
            s_logger.debug("Found a vm that is scheduled to be restarted but has no host id: " + vm);
            _itMgr.advanceStop(vm.getUuid(), true);
        } catch (ResourceUnavailableException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        } catch (OperationTimedoutException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        } catch (ConcurrentOperationException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        }
    }
    if (vm.getHypervisorType() == HypervisorType.VMware || vm.getHypervisorType() == HypervisorType.Hyperv) {
        s_logger.info("Skip HA for VMware VM or Hyperv VM" + vm.getInstanceName());
        return;
    }
    if (!investigate) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("VM does not require investigation so I'm marking it as Stopped: " + vm.toString());
        }
        AlertManager.AlertType alertType = AlertManager.AlertType.ALERT_TYPE_USERVM;
        if (VirtualMachine.Type.DomainRouter.equals(vm.getType())) {
            alertType = AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER;
        } else if (VirtualMachine.Type.ConsoleProxy.equals(vm.getType())) {
            alertType = AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY;
        } else if (VirtualMachine.Type.SecondaryStorageVm.equals(vm.getType())) {
            alertType = AlertManager.AlertType.ALERT_TYPE_SSVM;
        }
        if (!(_forceHA || vm.isHaEnabled())) {
            String hostDesc = "id:" + vm.getHostId() + ", availability zone id:" + vm.getDataCenterId() + ", pod id:" + vm.getPodIdToDeployIn();
            _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodIdToDeployIn(), "VM (name: " + vm.getHostName() + ", id: " + vm.getId() + ") stopped unexpectedly on host " + hostDesc, "Virtual Machine " + vm.getHostName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() + "] stopped unexpectedly.");
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("VM is not HA enabled so we're done.");
            }
        }
        try {
            _itMgr.advanceStop(vm.getUuid(), true);
            vm = _instanceDao.findByUuid(vm.getUuid());
        } catch (ResourceUnavailableException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        } catch (OperationTimedoutException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        } catch (ConcurrentOperationException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        }
    }
    if (vm.getHypervisorType() == HypervisorType.VMware) {
        s_logger.info("Skip HA for VMware VM " + vm.getInstanceName());
        return;
    }
    List<HaWorkVO> items = _haDao.findPreviousHA(vm.getId());
    int timesTried = 0;
    for (HaWorkVO item : items) {
        if (timesTried < item.getTimesTried() && !item.canScheduleNew(_timeBetweenFailures)) {
            timesTried = item.getTimesTried();
            break;
        }
    }
    if (hostId == null) {
        hostId = vm.getLastHostId();
    }
    HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.HA, investigate ? Step.Investigating : Step.Scheduled, hostId != null ? hostId : 0L, vm.getState(), timesTried, vm.getUpdated());
    _haDao.persist(work);
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Schedule vm for HA:  " + vm);
    }
    wakeupWorkers();
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AlertManager(com.cloud.alert.AlertManager) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 37 with ConcurrentOperationException

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

the class VirtualNetworkApplianceManagerImpl method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    final List<DomainRouterVO> routers = _routerDao.listIsolatedByHostId(host.getId());
    for (DomainRouterVO router : routers) {
        if (router.isStopPending()) {
            s_logger.info("Stopping router " + router.getInstanceName() + " due to stop pending flag found!");
            final VirtualMachine.State state = router.getState();
            if (state != VirtualMachine.State.Stopped && state != VirtualMachine.State.Destroyed) {
                try {
                    stopRouter(router.getId(), false);
                } catch (final ResourceUnavailableException e) {
                    s_logger.warn("Fail to stop router " + router.getInstanceName(), e);
                    throw new ConnectionException(false, "Fail to stop router " + router.getInstanceName());
                } catch (final ConcurrentOperationException e) {
                    s_logger.warn("Fail to stop router " + router.getInstanceName(), e);
                    throw new ConnectionException(false, "Fail to stop router " + router.getInstanceName());
                }
            }
            router.setStopPending(false);
            router = _routerDao.persist(router);
        }
    }
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) DomainRouterVO(com.cloud.vm.DomainRouterVO) ConnectionException(com.cloud.exception.ConnectionException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 38 with ConcurrentOperationException

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

the class VirtualNetworkApplianceManagerImpl method recoverRedundantNetwork.

// Ensure router status is update to date before execute this function. The
// function would try best to recover all routers except MASTER
protected void recoverRedundantNetwork(final DomainRouterVO masterRouter, final DomainRouterVO backupRouter) {
    if (masterRouter.getState() == VirtualMachine.State.Running && backupRouter.getState() == VirtualMachine.State.Running) {
        final HostVO masterHost = _hostDao.findById(masterRouter.getHostId());
        final HostVO backupHost = _hostDao.findById(backupRouter.getHostId());
        if (masterHost.getState() == Status.Up && backupHost.getState() == Status.Up) {
            final String title = "Reboot " + backupRouter.getInstanceName() + " to ensure redundant virtual routers work";
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(title);
            }
            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, backupRouter.getDataCenterId(), backupRouter.getPodIdToDeployIn(), title, title);
            try {
                rebootRouter(backupRouter.getId(), true);
            } catch (final ConcurrentOperationException e) {
                s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
            } catch (final ResourceUnavailableException e) {
                s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
            } catch (final InsufficientCapacityException e) {
                s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
            }
        }
    }
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO)

Example 39 with ConcurrentOperationException

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

the class UploadSslCertCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        SslCertResponse response = _certService.uploadSslCert(this);
        setResponseObject(response);
        response.setResponseName(getCommandName());
    } catch (Exception e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) SslCertResponse(org.apache.cloudstack.api.response.SslCertResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 40 with ConcurrentOperationException

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

the class VolumeApiServiceImpl method extractVolume.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_EXTRACT, eventDescription = "extracting volume", async = true)
public String extractVolume(ExtractVolumeCmd cmd) {
    Long volumeId = cmd.getId();
    Long zoneId = cmd.getZoneId();
    String mode = cmd.getMode();
    Account account = CallContext.current().getCallingAccount();
    if (!_accountMgr.isRootAdmin(account.getId()) && ApiDBUtils.isExtractionDisabled()) {
        throw new PermissionDeniedException("Extraction has been disabled by admin");
    }
    VolumeVO volume = _volsDao.findById(volumeId);
    if (volume == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find volume with specified volumeId");
        ex.addProxyObject(volumeId.toString(), "volumeId");
        throw ex;
    }
    // perform permission check
    _accountMgr.checkAccess(account, null, true, volume);
    if (_dcDao.findById(zoneId) == null) {
        throw new InvalidParameterValueException("Please specify a valid zone.");
    }
    if (volume.getPoolId() == null) {
        throw new InvalidParameterValueException("The volume doesnt belong to a storage pool so cant extract it");
    }
    // instance is stopped
    if (volume.getInstanceId() != null && ApiDBUtils.findVMInstanceById(volume.getInstanceId()).getState() != State.Stopped) {
        s_logger.debug("Invalid state of the volume with ID: " + volumeId + ". It should be either detached or the VM should be in stopped state.");
        PermissionDeniedException ex = new PermissionDeniedException("Invalid state of the volume with specified ID. It should be either detached or the VM should be in stopped state.");
        ex.addProxyObject(volume.getUuid(), "volumeId");
        throw ex;
    }
    if (volume.getVolumeType() != Volume.Type.DATADISK) {
        // Datadisk dont have any template dependence.
        VMTemplateVO template = ApiDBUtils.findTemplateById(volume.getTemplateId());
        if (template != null) {
            // For ISO based volumes template = null and
            // we allow extraction of all ISO based
            // volumes
            boolean isExtractable = template.isExtractable() && template.getTemplateType() != Storage.TemplateType.SYSTEM;
            if (!isExtractable && account != null && !_accountMgr.isRootAdmin(account.getId())) {
                // Global admins are always allowed to extract
                PermissionDeniedException ex = new PermissionDeniedException("The volume with specified volumeId is not allowed to be extracted");
                ex.addProxyObject(volume.getUuid(), "volumeId");
                throw ex;
            }
        }
    }
    if (mode == null || (!mode.equals(Upload.Mode.FTP_UPLOAD.toString()) && !mode.equals(Upload.Mode.HTTP_DOWNLOAD.toString()))) {
        throw new InvalidParameterValueException("Please specify a valid extract Mode ");
    }
    // Check if the url already exists
    VolumeDataStoreVO volumeStoreRef = _volumeStoreDao.findByVolume(volumeId);
    if (volumeStoreRef != null && volumeStoreRef.getExtractUrl() != null) {
        return volumeStoreRef.getExtractUrl();
    }
    VMInstanceVO vm = null;
    if (volume.getInstanceId() != null) {
        vm = _vmInstanceDao.findById(volume.getInstanceId());
    }
    if (vm != null) {
        // serialize VM operation
        AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
        if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
            // avoid re-entrance
            VmWorkJobVO placeHolder = null;
            placeHolder = createPlaceHolderWork(vm.getId());
            try {
                return orchestrateExtractVolume(volume.getId(), zoneId);
            } finally {
                _workJobDao.expunge(placeHolder.getId());
            }
        } else {
            Outcome<String> outcome = extractVolumeThroughJobQueue(vm.getId(), volume.getId(), zoneId);
            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 RuntimeException)
                    throw (RuntimeException) jobResult;
                else if (jobResult instanceof Throwable)
                    throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
            }
            // retrieve the entity url from job result
            if (jobResult != null && jobResult instanceof String) {
                return (String) jobResult;
            }
            return null;
        }
    }
    return orchestrateExtractVolume(volume.getId(), zoneId);
}
Also used : Account(com.cloud.user.Account) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) VMInstanceVO(com.cloud.vm.VMInstanceVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) ExecutionException(java.util.concurrent.ExecutionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) 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