Search in sources :

Example 46 with InvalidParameterValueException

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

the class VpcManagerImpl method updateVpcOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
public VpcOffering updateVpcOffering(final long vpcOffId, final String vpcOfferingName, final String displayText, final String state) {
    CallContext.current().setEventDetails(" Id: " + vpcOffId);
    // Verify input parameters
    final VpcOfferingVO offeringToUpdate = _vpcOffDao.findById(vpcOffId);
    if (offeringToUpdate == null) {
        throw new InvalidParameterValueException("Unable to find vpc offering " + vpcOffId);
    }
    final VpcOfferingVO offering = _vpcOffDao.createForUpdate(vpcOffId);
    if (vpcOfferingName != null) {
        offering.setName(vpcOfferingName);
    }
    if (displayText != null) {
        offering.setDisplayText(displayText);
    }
    if (state != null) {
        boolean validState = false;
        for (final VpcOffering.State st : VpcOffering.State.values()) {
            if (st.name().equalsIgnoreCase(state)) {
                validState = true;
                offering.setState(st);
            }
        }
        if (!validState) {
            throw new InvalidParameterValueException("Incorrect state value: " + state);
        }
    }
    if (_vpcOffDao.update(vpcOffId, offering)) {
        s_logger.debug("Updated VPC offeirng id=" + vpcOffId);
        return _vpcOffDao.findById(vpcOffId);
    } else {
        return null;
    }
}
Also used : State(com.cloud.legacymodel.network.vpc.VpcOffering.State) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) VpcOffering(com.cloud.legacymodel.network.vpc.VpcOffering) ActionEvent(com.cloud.event.ActionEvent)

Example 47 with InvalidParameterValueException

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

the class VpcManagerImpl method restartVpc.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_RESTART, eventDescription = "restarting vpc")
public boolean restartVpc(final long vpcId, final boolean cleanUp) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final Account callerAccount = CallContext.current().getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
    // Verify input parameters
    final Vpc vpc = getActiveVpc(vpcId);
    if (vpc == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified");
        ex.addProxyObject(String.valueOf(vpcId), "VPC");
        throw ex;
    }
    final VpcVO vo = _vpcDao.findById(vpcId);
    _accountMgr.checkAccess(callerAccount, null, false, vpc);
    s_logger.debug("Restarting VPC " + vpc);
    boolean restartRequired = false;
    try {
        if (cleanUp) {
            List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId());
            if (routers != null && !routers.isEmpty()) {
                s_logger.debug("Shutting down VPC " + vpc + " as a part of VPC restart process");
                // Get rid of any non-Running routers
                for (final DomainRouterVO router : routers) {
                    if (router.getState() != VirtualMachine.State.Running) {
                        s_logger.debug("Destroying " + router + " as it is not in Running state anyway");
                        _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId());
                    }
                }
                // Refresh the list of routers
                routers = _routerDao.listByVpcId(vpc.getId());
                if (routers != null && !routers.isEmpty()) {
                    if (!rollingRestartVpc(vpc, routers, context)) {
                        s_logger.warn("Failed to execute a rolling restart as a part of VPC " + vpc + " restart process");
                        restartRequired = true;
                        return false;
                    }
                }
            }
            // Reset VPC compliance state if it required a restart
            if (vpc.getComplianceStatus() == ComplianceStatus.VPCNeedsRestart) {
                vo.setComplianceStatus(ComplianceStatus.Compliant);
            }
        } else {
            s_logger.info("Will not shutdown vpc as a part of VPC " + vpc + " restart process.");
        }
        s_logger.debug("Starting VPC " + vpc + " as a part of VPC restart process");
        if (!startVpc(vpcId, false)) {
            s_logger.warn("Failed to start vpc as a part of VPC " + vpc + " restart process");
            restartRequired = true;
            return false;
        }
        s_logger.debug("VPC " + vpc + " was restarted successfully");
        return true;
    } finally {
        s_logger.debug("Updating VPC " + vpc + " with restartRequired=" + restartRequired);
        vo.setRestartRequired(restartRequired);
        _vpcDao.update(vpc.getId(), vo);
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) DomainRouterVO(com.cloud.vm.DomainRouterVO) ReservationContext(com.cloud.vm.ReservationContext) ActionEvent(com.cloud.event.ActionEvent)

Example 48 with InvalidParameterValueException

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

the class VpcManagerImpl method createVpcGuestNetwork.

@DB
@Override
public Network createVpcGuestNetwork(final long ntwkOffId, final String name, final String displayText, final String gateway, final String cidr, final String vlanId, String networkDomain, final Account owner, final Long domainId, final PhysicalNetwork pNtwk, final long zoneId, final ACLType aclType, final Boolean subdomainAccess, final long vpcId, final Long aclId, final Account caller, final Boolean isDisplayNetworkEnabled, final String dns1, final String dns2, final String ipExclusionList, final String dhcpTftpServer, final String dhcpBootfileName) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
    final Vpc vpc = getActiveVpc(vpcId);
    if (vpc == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC ");
        ex.addProxyObject(String.valueOf(vpcId), "VPC");
        throw ex;
    }
    _accountMgr.checkAccess(caller, null, false, vpc);
    if (networkDomain == null) {
        networkDomain = vpc.getNetworkDomain();
    }
    // 1) Validate if network can be created for VPC
    validateNtwkOffForNtwkInVpc(null, ntwkOffId, cidr, networkDomain, vpc, gateway, owner, aclId);
    // 2) Create network
    final Network guestNetwork = _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, null, null, isDisplayNetworkEnabled, null, dns1, dns2, ipExclusionList, dhcpTftpServer, dhcpBootfileName);
    if (guestNetwork != null) {
        guestNetwork.setNetworkACLId(aclId);
        _ntwkDao.update(guestNetwork.getId(), (NetworkVO) guestNetwork);
    }
    return guestNetwork;
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) Vpc(com.cloud.legacymodel.network.vpc.Vpc) DB(com.cloud.utils.db.DB)

Example 49 with InvalidParameterValueException

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

the class VpcManagerImpl method updateVpc.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc")
public Vpc updateVpc(final long vpcId, final String vpcName, final String displayText, final String customId, final Boolean displayVpc, final Long vpcOfferingId, final String sourceNatList, final String syslogServerList, Long advertInterval, AdvertMethod advertMethod, final ComplianceStatus complianceStatus) {
    CallContext.current().setEventDetails(" Id: " + vpcId);
    final Account caller = CallContext.current().getCallingAccount();
    // Verify input parameters
    final VpcVO vpcToUpdate = _vpcDao.findById(vpcId);
    if (vpcToUpdate == null) {
        throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId);
    }
    _accountMgr.checkAccess(caller, null, false, vpcToUpdate);
    final VpcVO vpc = _vpcDao.createForUpdate(vpcId);
    boolean restartWithCleanupRequired = false;
    if (vpcName != null) {
        vpc.setName(vpcName);
    }
    if (displayText != null) {
        vpc.setDisplayText(displayText);
    }
    if (customId != null) {
        vpc.setUuid(customId);
    }
    if (displayVpc != null) {
        vpc.setDisplay(displayVpc);
    }
    if (syslogServerList != null) {
        vpc.setSyslogServerList(syslogServerList);
    }
    if (advertInterval != null) {
        vpc.setAdvertInterval(advertInterval);
        restartWithCleanupRequired = true;
    }
    if (advertMethod != null) {
        vpc.setAdvertMethod(advertMethod);
        restartWithCleanupRequired = true;
    }
    if (complianceStatus != null) {
        vpc.setComplianceStatus(complianceStatus);
    }
    if (vpcOfferingId != null) {
        final VpcOfferingVO newVpcOffering = _vpcOffDao.findById(vpcOfferingId);
        if (newVpcOffering == null) {
            throw new InvalidParameterValueException("Unable to find vpc offering by id " + vpcOfferingId);
        }
        if (vpcOfferingId == vpcToUpdate.getVpcOfferingId()) {
            throw new InvalidParameterValueException("The vpc already has the specified offering, so not upgrading. Use restart+cleanup to rebuild.");
        }
        // check if the new VPC offering matches the network offerings in use
        checkVpcOfferingServicesWithCurrentNetworkOfferings(vpcOfferingId, vpcToUpdate);
        vpc.setVpcOfferingId(vpcOfferingId);
        vpc.setRedundant(newVpcOffering.getRedundantRouter());
        restartWithCleanupRequired = true;
        // disassociate the public IPs if not required anymore
        if (!hasSourceNatService(vpc)) {
            boolean success = true;
            final List<IPAddressVO> ipsToRelease = _ipAddressDao.listByVpc(vpcId, null);
            s_logger.debug("Releasing ips for vpc id=" + vpcId + " as a part of vpc cleanup");
            for (final IPAddressVO ipToRelease : ipsToRelease) {
                success = success && _ipAddrMgr.disassociatePublicIpAddress(ipToRelease.getId(), CallContext.current().getCallingUserId(), caller);
                if (!success) {
                    s_logger.warn("Failed to cleanup ip " + ipToRelease + " as a part of vpc id=" + vpcId + " cleanup");
                }
            }
        }
    }
    vpc.setRestartRequired(restartWithCleanupRequired);
    if (sourceNatList != null && !sourceNatList.isEmpty() && vpcOfferingId != null && !hasSourceNatService(vpc)) {
        throw new InvalidParameterValueException("Source NAT is not enabled on the VPC, so source NAT list is not allowed!");
    }
    if (sourceNatList != null) {
        vpc.setSourceNatList(sourceNatList);
    }
    if (vpcOfferingId != null && !hasSourceNatService(vpc) && hasSourceNatService(vpcToUpdate)) {
        s_logger.warn("SourceNat service not available on VPC " + vpc.getName() + " so setting SourceNatList to null!");
        vpc.setSourceNatList(null);
    }
    // Save the new config
    if (_vpcDao.update(vpcId, vpc)) {
        s_logger.debug("Updated VPC id=" + vpcId);
    } else {
        return null;
    }
    final Account callerAccount = CallContext.current().getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
    if (vpcOfferingId != null && !vpc.isRedundant()) {
        final List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId());
        for (final DomainRouterVO router : routers) {
            // Delete any non-MASTER router since we are supposed to run a single setup according to the new VPC offering
            if (router.getRedundantState() != VirtualRouter.RedundantState.MASTER) {
                try {
                    s_logger.warn("Deleting router " + router.getInstanceName() + " as we don't need it any more");
                    _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId());
                } catch (final ResourceUnavailableException ex) {
                    s_logger.warn("Exception: ", ex);
                    throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
                }
            }
        }
        return _vpcDao.findById(vpcId);
    }
    // Restart the VPC when required
    if (restartWithCleanupRequired) {
        s_logger.debug("Will now restart+cleanup VPC id=" + vpcId);
        try {
            final boolean result = restartVpc(vpcId, true);
            if (!result) {
                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restart VPC");
            }
        } catch (final ResourceUnavailableException ex) {
            s_logger.warn("Exception: ", ex);
            throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
        } catch (final ConcurrentOperationException ex) {
            s_logger.warn("Exception: ", ex);
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
        } catch (final InsufficientCapacityException ex) {
            s_logger.info(ex.toString());
            throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
        }
    } else {
        // LOOP over all routers
        final List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId());
        if (routers != null && !routers.isEmpty()) {
            s_logger.debug("Updating routers of VPC " + vpc + " as a part of VPC update process");
            for (final DomainRouterVO router : routers) {
                // Validate that the router is running
                if (router.getState() == VirtualMachine.State.Running) {
                    if (!_routerMgr.updateVR(vpc, router)) {
                        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC config");
                    }
                }
            }
        }
    }
    return _vpcDao.findById(vpcId);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ReservationContext(com.cloud.vm.ReservationContext) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) DomainRouterVO(com.cloud.vm.DomainRouterVO) ActionEvent(com.cloud.event.ActionEvent)

Example 50 with InvalidParameterValueException

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

the class VpcManagerImpl method deleteVpc.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC")
public boolean deleteVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.current().setEventDetails(" Id: " + vpcId);
    final CallContext ctx = CallContext.current();
    // Verify vpc id
    final Vpc vpc = _vpcDao.findById(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("unable to find VPC id=" + vpcId);
    }
    // verify permissions
    _accountMgr.checkAccess(ctx.getCallingAccount(), null, false, vpc);
    return destroyVpc(vpc, ctx.getCallingAccount(), ctx.getCallingUserId());
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Vpc(com.cloud.legacymodel.network.vpc.Vpc) CallContext(com.cloud.context.CallContext) ActionEvent(com.cloud.event.ActionEvent)

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