Search in sources :

Example 96 with InvalidParameterValueException

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

the class VirtualNetworkApplianceManagerImpl method rebootRouter.

@Override
@ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true)
public VirtualRouter rebootRouter(final long routerId, final boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final Account caller = CallContext.current().getCallingAccount();
    // verify parameters
    final DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find domain router with id " + routerId + ".");
    }
    _accountMgr.checkAccess(caller, null, true, router);
    // Can reboot domain router only in Running state
    if (router == null || router.getState() != VirtualMachine.State.Running) {
        s_logger.warn("Unable to reboot, virtual router is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId());
    }
    final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
    s_logger.debug("Stopping and starting router " + router + " as a part of router reboot");
    if (stop(router, false, user, caller) != null) {
        return startRouter(routerId, reprogramNetwork);
    } else {
        throw new CloudRuntimeException("Failed to reboot router " + router);
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO) ActionEvent(com.cloud.event.ActionEvent)

Example 97 with InvalidParameterValueException

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

the class VirtualNetworkApplianceManagerImpl method startRouter.

@Override
public VirtualRouter startRouter(final long routerId, final boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    // verify parameters
    DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
    }
    _accountMgr.checkAccess(caller, null, true, router);
    final Account owner = _accountMgr.getAccount(router.getAccountId());
    // Check if all networks are implemented for the domR; if not -
    // implement them
    final Zone zone = zoneRepository.findById(router.getDataCenterId()).orElse(null);
    HostPodVO pod = null;
    if (router.getPodIdToDeployIn() != null) {
        pod = _podDao.findById(router.getPodIdToDeployIn());
    }
    final DeployDestination dest = new DeployDestination(zone, pod, null, null);
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
    final List<NicVO> nics = _nicDao.listByVmId(routerId);
    for (final NicVO nic : nics) {
        if (!_networkMgr.startNetwork(nic.getNetworkId(), dest, context)) {
            s_logger.warn("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
            throw new CloudRuntimeException("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
        }
    }
    // After start network, check if it's already running
    router = _routerDao.findById(routerId);
    if (router.getState() == VirtualMachine.State.Running) {
        return router;
    }
    final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
    final Map<Param, Object> params = new HashMap<>();
    if (reprogramNetwork) {
        params.put(Param.ReProgramGuestNetworks, true);
    } else {
        params.put(Param.ReProgramGuestNetworks, false);
    }
    final VirtualRouter virtualRouter = _nwHelper.startVirtualRouter(router, user, caller, params);
    if (virtualRouter == null) {
        throw new CloudRuntimeException("Failed to start router with id " + routerId);
    }
    return virtualRouter;
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) HashMap(java.util.HashMap) Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) HostPodVO(com.cloud.dc.HostPodVO) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) ReservationContext(com.cloud.vm.ReservationContext) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Param(com.cloud.vm.VirtualMachineProfile.Param) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 98 with InvalidParameterValueException

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

the class VirtualNetworkApplianceManagerImpl method upgradeRouterTemplate.

@Override
public List<Long> upgradeRouterTemplate(final UpgradeRouterTemplateCmd cmd) {
    List<DomainRouterVO> routers = new ArrayList<>();
    int params = 0;
    final Long routerId = cmd.getId();
    if (routerId != null) {
        params++;
        final DomainRouterVO router = _routerDao.findById(routerId);
        if (router != null) {
            routers.add(router);
        }
    }
    final Long domainId = cmd.getDomainId();
    if (domainId != null) {
        final String accountName = cmd.getAccount();
        // List by account, if account Name is specified along with domainId
        if (accountName != null) {
            final Account account = _accountMgr.getActiveAccountByName(accountName, domainId);
            if (account == null) {
                throw new InvalidParameterValueException("Account :" + accountName + " does not exist in domain: " + domainId);
            }
            routers = _routerDao.listRunningByAccountId(account.getId());
        } else {
            // List by domainId, account name not specified
            routers = _routerDao.listRunningByDomain(domainId);
        }
        params++;
    }
    final Long clusterId = cmd.getClusterId();
    if (clusterId != null) {
        params++;
        routers = _routerDao.listRunningByClusterId(clusterId);
    }
    final Long podId = cmd.getPodId();
    if (podId != null) {
        params++;
        routers = _routerDao.listRunningByPodId(podId);
    }
    final Long zoneId = cmd.getZoneId();
    if (zoneId != null) {
        params++;
        routers = _routerDao.listRunningByDataCenter(zoneId);
    }
    if (params > 1) {
        throw new InvalidParameterValueException("Multiple parameters not supported. Specify only one among routerId/zoneId/podId/clusterId/accountId/domainId");
    }
    if (routers != null) {
        return rebootRouters(routers);
    }
    return null;
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 99 with InvalidParameterValueException

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

the class UpdateClusterCmd method execute.

@Override
public void execute() {
    final Cluster cluster = _resourceService.getCluster(getId());
    if (cluster == null) {
        throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId());
    }
    final Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate());
    if (result != null) {
        final ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
        clusterResponse.setResponseName(getCommandName());
        this.setResponseObject(clusterResponse);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update cluster");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Cluster(com.cloud.legacymodel.dc.Cluster) ClusterResponse(com.cloud.api.response.ClusterResponse)

Example 100 with InvalidParameterValueException

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

the class RemoveFromLoadBalancerRuleCmd method getVmIdIpListMap.

public Map<Long, List<String>> getVmIdIpListMap() {
    final Map<Long, List<String>> vmIdIpsMap = new HashMap<>();
    if (vmIdIpMap != null && !vmIdIpMap.isEmpty()) {
        final Collection idIpsCollection = vmIdIpMap.values();
        final Iterator iter = idIpsCollection.iterator();
        while (iter.hasNext()) {
            final HashMap<String, String> idIpsMap = (HashMap<String, String>) iter.next();
            final String vmId = idIpsMap.get("vmid");
            final String vmIp = idIpsMap.get("vmip");
            final VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmId);
            if (lbvm == null) {
                throw new InvalidParameterValueException("Unable to find virtual machine ID: " + vmId);
            }
            final Long longVmId = lbvm.getId();
            List<String> ipsList = null;
            if (vmIdIpsMap.containsKey(longVmId)) {
                ipsList = vmIdIpsMap.get(longVmId);
            } else {
                ipsList = new ArrayList<>();
            }
            ipsList.add(vmIp);
            vmIdIpsMap.put(longVmId, ipsList);
        }
    }
    return vmIdIpsMap;
}
Also used : HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine)

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