Search in sources :

Example 16 with InvalidParameterValueException

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

the class NetworkOrchestrator method startNetwork.

@Override
public boolean startNetwork(final long networkId, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    // Check if network exists
    final NetworkVO network = _networksDao.findById(networkId);
    if (network == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id doesn't exist");
        ex.addProxyObject(String.valueOf(networkId), "networkId");
        throw ex;
    }
    // implement the network
    s_logger.debug("Starting network " + network + "...");
    final Pair<NetworkGuru, NetworkVO> implementedNetwork = implementNetwork(networkId, dest, context);
    if (implementedNetwork == null || implementedNetwork.first() == null) {
        s_logger.warn("Failed to start the network " + network);
        return false;
    } else {
        return true;
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkGuru(com.cloud.network.guru.NetworkGuru)

Example 17 with InvalidParameterValueException

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

the class XenserverSnapshotStrategy method deleteSnapshot.

@Override
public boolean deleteSnapshot(final Long snapshotId) {
    final SnapshotVO snapshotVO = snapshotDao.findById(snapshotId);
    if (snapshotVO.getState() == Snapshot.State.Allocated) {
        snapshotDao.remove(snapshotId);
        return true;
    }
    if (snapshotVO.getState() == Snapshot.State.Destroyed) {
        return true;
    }
    if (Snapshot.State.Error.equals(snapshotVO.getState())) {
        final List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId);
        for (final SnapshotDataStoreVO ref : storeRefs) {
            snapshotStoreDao.expunge(ref.getId());
        }
        snapshotDao.remove(snapshotId);
        return true;
    }
    if (snapshotVO.getState() == Snapshot.State.CreatedOnPrimary) {
        s_logger.debug("delete snapshot on primary storage:");
        snapshotVO.setState(Snapshot.State.Destroyed);
        snapshotDao.update(snapshotId, snapshotVO);
        return true;
    }
    if (!Snapshot.State.BackedUp.equals(snapshotVO.getState()) && !Snapshot.State.Error.equals(snapshotVO.getState())) {
        throw new InvalidParameterValueException("Can't delete snapshotshot " + snapshotId + " due to it is in " + snapshotVO.getState() + " HostStatus");
    }
    // first mark the snapshot as destroyed, so that ui can't see it, but we
    // may not destroy the snapshot on the storage, as other snapshots may
    // depend on it.
    final SnapshotInfo snapshotOnImage = snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Image);
    if (snapshotOnImage == null) {
        s_logger.debug("Can't find snapshot on backup storage, delete it in db");
        snapshotDao.remove(snapshotId);
        return true;
    }
    final SnapshotObject obj = (SnapshotObject) snapshotOnImage;
    try {
        obj.processEvent(Snapshot.Event.DestroyRequested);
    } catch (final NoTransitionException e) {
        s_logger.debug("Failed to set the state to destroying: ", e);
        return false;
    }
    try {
        final boolean result = deleteSnapshotChain(snapshotOnImage);
        obj.processEvent(Snapshot.Event.OperationSucceeded);
        if (result) {
            // snapshot is deleted on backup storage, need to delete it on primary storage
            final SnapshotDataStoreVO snapshotOnPrimary = snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Primary);
            if (snapshotOnPrimary != null) {
                snapshotOnPrimary.setState(State.Destroyed);
                snapshotStoreDao.update(snapshotOnPrimary.getId(), snapshotOnPrimary);
            }
        }
    } catch (final Exception e) {
        s_logger.debug("Failed to delete snapshot: ", e);
        try {
            obj.processEvent(Snapshot.Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change snapshot state: " + e.toString());
        }
        return false;
    }
    return true;
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 18 with InvalidParameterValueException

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

the class PrimaryDataStoreHelper method createPrimaryDataStore.

public DataStore createPrimaryDataStore(final PrimaryDataStoreParameters params) {
    if (params == null) {
        throw new InvalidParameterValueException("createPrimaryDataStore: Input params is null, please check");
    }
    StoragePoolVO dataStoreVO = dataStoreDao.findPoolByUUID(params.getUuid());
    if (dataStoreVO != null) {
        throw new CloudRuntimeException("duplicate uuid: " + params.getUuid());
    }
    dataStoreVO = new StoragePoolVO();
    dataStoreVO.setStorageProviderName(params.getProviderName());
    dataStoreVO.setHostAddress(params.getHost());
    dataStoreVO.setPoolType(params.getType());
    dataStoreVO.setPath(params.getPath());
    dataStoreVO.setPort(params.getPort());
    dataStoreVO.setName(params.getName());
    dataStoreVO.setUuid(params.getUuid());
    dataStoreVO.setDataCenterId(params.getZoneId());
    dataStoreVO.setPodId(params.getPodId());
    dataStoreVO.setClusterId(params.getClusterId());
    dataStoreVO.setStatus(StoragePoolStatus.Initialized);
    dataStoreVO.setUserInfo(params.getUserInfo());
    dataStoreVO.setManaged(params.isManaged());
    dataStoreVO.setCapacityIops(params.getCapacityIops());
    dataStoreVO.setCapacityBytes(params.getCapacityBytes());
    dataStoreVO.setUsedBytes(params.getUsedBytes());
    dataStoreVO.setHypervisor(params.getHypervisorType());
    final Map<String, String> details = params.getDetails();
    if (params.getType() == StoragePoolType.SMB && details != null) {
        final String user = details.get("user");
        String password = details.get("password");
        final String domain = details.get("domain");
        String updatedPath = params.getPath();
        if (user == null || password == null) {
            final String errMsg = "Missing cifs user and password details. Add them as details parameter.";
            s_logger.warn(errMsg);
            throw new InvalidParameterValueException(errMsg);
        } else {
            try {
                password = DBEncryptionUtil.encrypt(URLEncoder.encode(password, "UTF-8"));
                details.put("password", password);
                updatedPath += "?user=" + user + "&password=" + password + "&domain=" + domain;
            } catch (final UnsupportedEncodingException e) {
                throw new CloudRuntimeException("Error while generating the cifs url. " + e.getMessage());
            }
        }
        dataStoreVO.setPath(updatedPath);
    }
    final String tags = params.getTags();
    if (tags != null) {
        final String[] tokens = tags.split(",");
        for (String tag : tokens) {
            tag = tag.trim();
            if (tag.length() == 0) {
                continue;
            }
            details.put(tag, "true");
        }
    }
    dataStoreVO = dataStoreDao.persist(dataStoreVO, details);
    return dataStoreMgr.getDataStore(dataStoreVO.getId(), DataStoreRole.Primary);
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 19 with InvalidParameterValueException

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

the class AffinityGroupServiceImpl method createAffinityGroup.

@DB
@Override
public AffinityGroup createAffinityGroup(final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType, final String description) {
    // validate the affinityGroupType
    final Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
    if (typeProcessorMap == null || typeProcessorMap.isEmpty()) {
        throw new InvalidParameterValueException("Unable to create affinity group, no Affinity Group Types configured");
    }
    final AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
    if (processor == null) {
        throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type" + affinityGroupType);
    }
    final Account caller = CallContext.current().getCallingAccount();
    if (processor.isAdminControlledGroup() && !_accountMgr.isRootAdmin(caller.getId())) {
        throw new PermissionDeniedException("Cannot create the affinity group");
    }
    final ControlledEntity.ACLType aclType;
    final Account owner;
    boolean domainLevel = false;
    if (projectId == null && domainId != null && accountName == null) {
        verifyAccessToDomainWideProcessor(caller, processor);
        final DomainVO domain = getDomain(domainId);
        _accountMgr.checkAccess(caller, domain);
        // domain level group, owner is SYSTEM.
        owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
        aclType = ControlledEntity.ACLType.Domain;
        domainLevel = true;
    } else {
        owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
        aclType = ControlledEntity.ACLType.Account;
    }
    verifyAffinityGroupNameInUse(owner.getAccountId(), owner.getDomainId(), affinityGroupName);
    verifyDomainLevelAffinityGroupName(domainLevel, owner.getDomainId(), affinityGroupName);
    final AffinityGroupVO group = createAffinityGroup(processor, owner, aclType, affinityGroupName, affinityGroupType, description, domainLevel, domainId);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Created affinity group =" + affinityGroupName);
    }
    return group;
}
Also used : Account(com.cloud.legacymodel.user.Account) DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ControlledEntity(com.cloud.legacymodel.acl.ControlledEntity) ACLType(com.cloud.legacymodel.acl.ControlledEntity.ACLType) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) DB(com.cloud.utils.db.DB)

Example 20 with InvalidParameterValueException

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

the class ConfigurationManagerImpl method checkPodAttributes.

private void checkPodAttributes(final long podId, final String podName, final long zoneId, final String gateway, final String cidr, final String startIp, final String endIp, final String allocationStateStr, final boolean checkForDuplicates, final boolean skipGatewayOverlapCheck) {
    if (checkForDuplicates) {
        // Check if the pod already exists
        if (validPod(podName, zoneId)) {
            throw new InvalidParameterValueException("A pod with name: " + podName + " already exists in zone " + zoneId + ". Please specify a different pod name. ");
        }
    }
    final String cidrAddress;
    final long cidrSize;
    // valid. If it's not valid, return an error.
    if (NetUtils.isValidIp4Cidr(cidr)) {
        cidrAddress = getCidrAddress(cidr);
        cidrSize = getCidrSize(cidr);
    } else {
        throw new InvalidParameterValueException("Please enter a valid CIDR for pod: " + podName);
    }
    // Check if the IP range is valid
    checkIpRange(startIp, endIp, cidrAddress, cidrSize);
    // Check if the IP range overlaps with the public ip
    checkOverlapPublicIpRange(zoneId, startIp, endIp);
    // Check if the gateway is a valid IP address
    if (!NetUtils.isValidIp4(gateway)) {
        throw new InvalidParameterValueException("The gateway is not a valid IP address.");
    }
    // Check if the gateway is in the CIDR subnet
    if (!NetUtils.getCidrSubNet(gateway, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) {
        throw new InvalidParameterValueException("The gateway is not in the CIDR subnet.");
    }
    // Don't allow gateway to overlap with start/endIp
    if (!skipGatewayOverlapCheck) {
        if (NetUtils.ipRangesOverlap(startIp, endIp, gateway, gateway)) {
            throw new InvalidParameterValueException("The gateway shouldn't overlap start/end ip addresses");
        }
    }
    final String checkPodCIDRs = _configDao.getValue("check.pod.cidrs");
    if (checkPodCIDRs == null || checkPodCIDRs.trim().isEmpty() || Boolean.parseBoolean(checkPodCIDRs)) {
        checkPodCidrSubnets(zoneId, podId, cidr);
    }
    if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
        try {
            AllocationState.valueOf(allocationStateStr);
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state");
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException)

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