Search in sources :

Example 81 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method maintain.

@Override
public Host maintain(final PrepareForMaintenanceCmd cmd) {
    final Long hostId = cmd.getId();
    final HostVO host = this._hostDao.findById(hostId);
    if (host == null) {
        s_logger.debug("Unable to find host " + hostId);
        throw new InvalidParameterValueException("Unable to find host with ID: " + hostId + ". Please specify a valid host ID.");
    }
    if (this._hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance) > 0) {
        throw new InvalidParameterValueException("There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster " + host.getClusterId());
    }
    if (this._storageMgr.isLocalStorageActiveOnHost(host.getId())) {
        throw new InvalidParameterValueException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage.");
    }
    try {
        processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE, hostId);
        if (maintain(hostId)) {
            processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER, hostId);
            return this._hostDao.findById(hostId);
        } else {
            throw new CloudRuntimeException("Unable to prepare for maintenance host " + hostId);
        }
    } catch (final AgentUnavailableException e) {
        throw new CloudRuntimeException("Unable to prepare for maintenance host " + hostId);
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Example 82 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method doDeleteHost.

@DB
protected boolean doDeleteHost(final long hostId, final boolean isForced, final boolean isForceDeleteStorage) {
    this._accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    // Verify that host exists
    final HostVO host = this._hostDao.findById(hostId);
    if (host == null) {
        throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
    }
    this._accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId());
    if (!isForced && host.getResourceState() != ResourceState.Maintenance) {
        throw new CloudRuntimeException("Host " + host.getUuid() + " cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
    }
    // Get storage pool host mappings here because they can be removed as a
    // part of handleDisconnect later
    // TODO: find out the bad boy, what's a buggy logic!
    final List<StoragePoolHostVO> pools = this._storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
    final ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer) dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST, false, host, isForced, isForceDeleteStorage);
    if (answer == null) {
        throw new CloudRuntimeException("No resource adapter respond to DELETE_HOST event for " + host.getName() + " id = " + hostId + ", hypervisorType is " + host.getHypervisorType() + ", host type is " + host.getType());
    }
    if (answer.getIsException()) {
        return false;
    }
    if (!answer.getIsContinue()) {
        return true;
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            ResourceManagerImpl.this._dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
            ResourceManagerImpl.this._agentMgr.disconnectWithoutInvestigation(hostId, Event.Remove);
            // delete host details
            ResourceManagerImpl.this._hostDetailsDao.deleteDetails(hostId);
            // if host is GPU enabled, delete GPU entries
            ResourceManagerImpl.this._hostGpuGroupsDao.deleteGpuEntries(hostId);
            // delete host tags
            ResourceManagerImpl.this._hostTagsDao.deleteTags(hostId);
            host.setGuid(null);
            final Long clusterId = host.getClusterId();
            host.setClusterId(null);
            ResourceManagerImpl.this._hostDao.update(host.getId(), host);
            ResourceManagerImpl.this._hostDao.remove(hostId);
            if (clusterId != null) {
                final List<HostVO> hosts = listAllHostsInCluster(clusterId);
                if (hosts.size() == 0) {
                    final ClusterVO cluster = ResourceManagerImpl.this._clusterDao.findById(clusterId);
                    cluster.setGuid(null);
                    ResourceManagerImpl.this._clusterDao.update(clusterId, cluster);
                }
            }
            try {
                resourceStateTransitTo(host, ResourceState.Event.DeleteHost, ResourceManagerImpl.this._nodeId);
            } catch (final NoTransitionException e) {
                s_logger.debug("Cannot transmit host " + host.getId() + " to Enabled state", e);
            }
            // Delete the associated entries in host ref table
            ResourceManagerImpl.this._storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
            // Make sure any VMs that were marked as being on this host are cleaned up
            final List<VMInstanceVO> vms = ResourceManagerImpl.this._vmDao.listByHostId(hostId);
            for (final VMInstanceVO vm : vms) {
                // this is how VirtualMachineManagerImpl does it when it syncs VM states
                vm.setState(State.Stopped);
                vm.setHostId(null);
                ResourceManagerImpl.this._vmDao.persist(vm);
            }
            // where
            for (final StoragePoolHostVO pool : pools) {
                final Long poolId = pool.getPoolId();
                final StoragePoolVO storagePool = ResourceManagerImpl.this._storagePoolDao.findById(poolId);
                if (storagePool.isLocal() && isForceDeleteStorage) {
                    storagePool.setUuid(null);
                    storagePool.setClusterId(null);
                    ResourceManagerImpl.this._storagePoolDao.update(poolId, storagePool);
                    ResourceManagerImpl.this._storagePoolDao.remove(poolId);
                    s_logger.debug("Local storage id=" + poolId + " is removed as a part of host removal id=" + hostId);
                }
            }
            // delete the op_host_capacity entry
            final Object[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY };
            final SearchCriteria<CapacityVO> hostCapacitySC = ResourceManagerImpl.this._capacityDao.createSearchCriteria();
            hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
            hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
            ResourceManagerImpl.this._capacityDao.remove(hostCapacitySC);
            // remove from dedicated resources
            final DedicatedResourceVO dr = ResourceManagerImpl.this._dedicatedDao.findByHostId(hostId);
            if (dr != null) {
                ResourceManagerImpl.this._dedicatedDao.remove(dr.getId());
            }
        }
    });
    return true;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) SearchCriteria(com.cloud.utils.db.SearchCriteria) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) DB(com.cloud.utils.db.DB)

Example 83 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method updateHost.

@Override
public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
    final Long hostId = cmd.getId();
    final Long guestOSCategoryId = cmd.getOsCategoryId();
    // Verify that the host exists
    final HostVO host = this._hostDao.findById(hostId);
    if (host == null) {
        throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
    }
    if (cmd.getAllocationState() != null) {
        final ResourceState.Event resourceEvent = ResourceState.Event.toEvent(cmd.getAllocationState());
        if (resourceEvent != ResourceState.Event.Enable && resourceEvent != ResourceState.Event.Disable) {
            throw new CloudRuntimeException("Invalid allocation state:" + cmd.getAllocationState() + ", only Enable/Disable are allowed");
        }
        resourceStateTransitTo(host, resourceEvent, this._nodeId);
    }
    if (guestOSCategoryId != null) {
        // Verify that the guest OS Category exists
        if (!(guestOSCategoryId > 0) || this._guestOSCategoryDao.findById(guestOSCategoryId) == null) {
            throw new InvalidParameterValueException("Please specify a valid guest OS category.");
        }
        final GuestOSCategoryVO guestOSCategory = this._guestOSCategoryDao.findById(guestOSCategoryId);
        final DetailVO guestOSDetail = this._hostDetailsDao.findDetail(hostId, "guest.os.category.id");
        if (guestOSCategory != null && !GuestOSCategoryVO.CATEGORY_NONE.equalsIgnoreCase(guestOSCategory.getName())) {
            // Create/Update an entry for guest.os.category.id
            if (guestOSDetail != null) {
                guestOSDetail.setValue(String.valueOf(guestOSCategory.getId()));
                this._hostDetailsDao.update(guestOSDetail.getId(), guestOSDetail);
            } else {
                final Map<String, String> detail = new HashMap<>();
                detail.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
                this._hostDetailsDao.persist(hostId, detail);
            }
        } else {
            // Delete any existing entry for guest.os.category.id
            if (guestOSDetail != null) {
                this._hostDetailsDao.remove(guestOSDetail.getId());
            }
        }
    }
    final List<String> hostTags = cmd.getHostTags();
    if (hostTags != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Updating Host Tags to :" + hostTags);
        }
        this._hostTagsDao.persist(hostId, hostTags);
    }
    final String url = cmd.getUrl();
    if (url != null) {
        this._storageMgr.updateSecondaryStorage(cmd.getId(), cmd.getUrl());
    }
    final HostVO updatedHost = this._hostDao.findById(hostId);
    return updatedHost;
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResourceState(com.cloud.legacymodel.resource.ResourceState) GuestOSCategoryVO(com.cloud.storage.GuestOSCategoryVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Example 84 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ProjectManagerImpl method updateProject.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_UPDATE, eventDescription = "updating project", async = true)
public Project updateProject(final long projectId, final String displayText, final String newOwnerName) throws ResourceAllocationException {
    final Account caller = CallContext.current().getCallingAccount();
    // check that the project exists
    final ProjectVO project = getProject(projectId);
    if (project == null) {
        throw new InvalidParameterValueException("Unable to find the project id=" + projectId);
    }
    // verify permissions
    _accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
    Transaction.execute(new TransactionCallbackWithExceptionNoReturn<ResourceAllocationException>() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) throws ResourceAllocationException {
            if (displayText != null) {
                project.setDisplayText(displayText);
                _projectDao.update(projectId, project);
            }
            if (newOwnerName != null) {
                // check that the new owner exists
                final Account futureOwnerAccount = _accountMgr.getActiveAccountByName(newOwnerName, project.getDomainId());
                if (futureOwnerAccount == null) {
                    throw new InvalidParameterValueException("Unable to find account name=" + newOwnerName + " in domain id=" + project.getDomainId());
                }
                final Account currentOwnerAccount = getProjectOwner(projectId);
                if (currentOwnerAccount.getId() != futureOwnerAccount.getId()) {
                    final ProjectAccountVO futureOwner = _projectAccountDao.findByProjectIdAccountId(projectId, futureOwnerAccount.getAccountId());
                    if (futureOwner == null) {
                        throw new InvalidParameterValueException("Account " + newOwnerName + " doesn't belong to the project. Add it to the project first and then change the project's ownership");
                    }
                    // do resource limit check
                    _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(futureOwnerAccount.getId()), ResourceType.project);
                    // unset the role for the old owner
                    final ProjectAccountVO currentOwner = _projectAccountDao.findByProjectIdAccountId(projectId, currentOwnerAccount.getId());
                    currentOwner.setAccountRole(Role.Regular);
                    _projectAccountDao.update(currentOwner.getId(), currentOwner);
                    _resourceLimitMgr.decrementResourceCount(currentOwnerAccount.getId(), ResourceType.project);
                    // set new owner
                    futureOwner.setAccountRole(Role.Admin);
                    _projectAccountDao.update(futureOwner.getId(), futureOwner);
                    _resourceLimitMgr.incrementResourceCount(futureOwnerAccount.getId(), ResourceType.project);
                } else {
                    s_logger.trace("Future owner " + newOwnerName + "is already the owner of the project id=" + projectId);
                }
            }
        }
    });
    return _projectDao.findById(projectId);
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 85 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ProjectManagerImpl method enableProject.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_CREATE, eventDescription = "creating project", async = true)
@DB
public Project enableProject(final long projectId) {
    final Account caller = CallContext.current().getCallingAccount();
    final ProjectVO project = getProject(projectId);
    // verify input parameters
    if (project == null) {
        throw new InvalidParameterValueException("Unable to find project by id " + projectId);
    }
    _accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
    // at this point enabling project doesn't require anything, so just update the state
    project.setState(State.Active);
    _projectDao.update(projectId, project);
    return project;
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)483 Account (com.cloud.legacymodel.user.Account)219 ActionEvent (com.cloud.event.ActionEvent)159 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)153 ArrayList (java.util.ArrayList)105 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)76 List (java.util.List)62 TransactionStatus (com.cloud.utils.db.TransactionStatus)58 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)53 Network (com.cloud.legacymodel.network.Network)51 ServerApiException (com.cloud.api.ServerApiException)47 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)43 Pair (com.cloud.legacymodel.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30 HostVO (com.cloud.host.HostVO)29