Search in sources :

Example 31 with StorageUnavailableException

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

the class StartVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
    try {
        UserContext.current().setEventDetails("Vm Id: " + getId());
        UserVm result;
        if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
            result = _bareMetalVmService.startVirtualMachine(this);
        } else {
            result = _userVmService.startVirtualMachine(this);
        }
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) ExecutionException(com.cloud.utils.exception.ExecutionException) UserVmResponse(com.cloud.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 32 with StorageUnavailableException

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

the class CopyTemplateCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        UserContext.current().setEventDetails(getEventDescription());
        VirtualMachineTemplate template = _templateService.copyTemplate(this);
        if (template != null) {
            List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template.getId(), getDestinationZoneId(), false);
            TemplateResponse response = new TemplateResponse();
            if (listResponse != null && !listResponse.isEmpty()) {
                response = listResponse.get(0);
            }
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to copy template");
        }
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 33 with StorageUnavailableException

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

the class VirtualMachineManagerImpl method orchestrateStorageMigration.

private void orchestrateStorageMigration(final String vmUuid, final StoragePool destPool) {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (destPool == null) {
        throw new CloudRuntimeException("Unable to migrate vm: missing destination storage pool");
    }
    try {
        stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
    } catch (final NoTransitionException e) {
        s_logger.debug("Unable to migrate vm: " + e.toString());
        throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    boolean migrationResult = false;
    try {
        migrationResult = volumeMgr.storageMigration(profile, destPool);
        if (migrationResult) {
            if (destPool.getPodId() != null && !destPool.getPodId().equals(vm.getPodIdToDeployIn())) {
                final DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null);
                final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null);
                _networkMgr.reallocate(vmProfile, plan);
            }
            //when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
            vm.setLastHostId(null);
            vm.setPodIdToDeployIn(destPool.getPodId());
            // unregister the VM from the source host and cleanup the associated VM files.
            if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
                Long srcClusterId = null;
                Long srcHostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
                if (srcHostId != null) {
                    HostVO srcHost = _hostDao.findById(srcHostId);
                    srcClusterId = srcHost.getClusterId();
                }
                final Long destClusterId = destPool.getClusterId();
                if (srcClusterId != null && destClusterId != null && !srcClusterId.equals(destClusterId)) {
                    final String srcDcName = _clusterDetailsDao.getVmwareDcName(srcClusterId);
                    final String destDcName = _clusterDetailsDao.getVmwareDcName(destClusterId);
                    if (srcDcName != null && destDcName != null && !srcDcName.equals(destDcName)) {
                        s_logger.debug("Since VM's storage was successfully migrated across VMware Datacenters, unregistering VM: " + vm.getInstanceName() + " from source host: " + srcHostId);
                        final UnregisterVMCommand uvc = new UnregisterVMCommand(vm.getInstanceName());
                        uvc.setCleanupVmFiles(true);
                        try {
                            _agentMgr.send(srcHostId, uvc);
                        } catch (final AgentUnavailableException | OperationTimedoutException e) {
                            throw new CloudRuntimeException("Failed to unregister VM: " + vm.getInstanceName() + " from source host: " + srcHostId + " after successfully migrating VM's storage across VMware Datacenters");
                        }
                    }
                }
            }
        } else {
            s_logger.debug("Storage migration failed");
        }
    } catch (final ConcurrentOperationException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientVirtualNetworkCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientAddressCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final StorageUnavailableException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } finally {
        try {
            stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to change vm state: " + e.toString());
            throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) UnregisterVMCommand(com.cloud.agent.api.UnregisterVMCommand) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HostVO(com.cloud.host.HostVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 34 with StorageUnavailableException

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

the class StartVMCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    try {
        CallContext.current().setEventDetails("Vm Id: " + getId());
        UserVm result;
        result = _userVmService.startVirtualMachine(this);
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        StringBuilder message = new StringBuilder(ex.getMessage());
        if (ex instanceof InsufficientServerCapacityException) {
            if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
                message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
            }
        }
        s_logger.info(ex);
        s_logger.info(message.toString(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ExecutionException(com.cloud.utils.exception.ExecutionException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 35 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method migrateVolume.

@Override
@DB
public Volume migrateVolume(final Volume volume, final StoragePool destPool) throws StorageUnavailableException {
    final VolumeInfo vol = volFactory.getVolume(volume.getId());
    final AsyncCallFuture<VolumeService.VolumeApiResult> future = volService.copyVolume(vol, (DataStore) destPool);
    try {
        final VolumeService.VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.error("Migrate volume failed. Error received from hypervisor:" + result.getResult());
            throw new StorageUnavailableException("Migrate volume failed. Error received from hypervisor: " + result.getResult(), destPool.getId());
        } else {
            // update the volumeId for snapshots on secondary
            if (!_snapshotDao.listByVolumeId(vol.getId()).isEmpty()) {
                _snapshotDao.updateVolumeIds(vol.getId(), result.getVolume().getId());
                _snapshotDataStoreDao.updateVolumeIds(vol.getId(), result.getVolume().getId());
            }
        }
        return result.getVolume();
    } catch (final InterruptedException e) {
        s_logger.debug("migrate volume failed", e);
        throw new CloudRuntimeException(e.getMessage());
    } catch (final ExecutionException e) {
        s_logger.debug("migrate volume failed", e);
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : StorageUnavailableException(com.cloud.exception.StorageUnavailableException) VolumeService(com.cloud.engine.subsystem.api.storage.VolumeService) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) ExecutionException(java.util.concurrent.ExecutionException) DB(com.cloud.utils.db.DB)

Aggregations

StorageUnavailableException (com.cloud.exception.StorageUnavailableException)52 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)21 DB (com.cloud.utils.db.DB)16 ExecutionException (java.util.concurrent.ExecutionException)15 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)14 ArrayList (java.util.ArrayList)13 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 StoragePool (com.cloud.storage.StoragePool)12 Pair (com.cloud.utils.Pair)11 Answer (com.cloud.agent.api.Answer)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)10 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)9 ConfigurationException (javax.naming.ConfigurationException)9 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)8 DiskOffering (com.cloud.offering.DiskOffering)8 VolumeVO (com.cloud.storage.VolumeVO)8 ExecutionException (com.cloud.utils.exception.ExecutionException)8 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)8 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)7