Search in sources :

Example 56 with InvalidParameterException

use of java.security.InvalidParameterException in project cloudstack by apache.

the class NetworkServiceImpl method updatePhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_UPDATE, eventDescription = "updating physical network", async = true)
public PhysicalNetwork updatePhysicalNetwork(Long id, String networkSpeed, List<String> tags, String newVnetRange, String state) {
    // verify input parameters
    PhysicalNetworkVO network = _physicalNetworkDao.findById(id);
    if (network == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
        ex.addProxyObject(id.toString(), "physicalNetworkId");
        throw ex;
    }
    // if zone is of Basic type, don't allow to add vnet range
    DataCenter zone = _dcDao.findById(network.getDataCenterId());
    if (zone == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Zone with id=" + network.getDataCenterId() + " doesn't exist in the system");
        ex.addProxyObject(String.valueOf(network.getDataCenterId()), "dataCenterId");
        throw ex;
    }
    if (newVnetRange != null) {
        if (zone.getNetworkType() == NetworkType.Basic || (zone.getNetworkType() == NetworkType.Advanced && zone.isSecurityGroupEnabled())) {
            throw new InvalidParameterValueException("Can't add vnet range to the physical network in the zone that supports " + zone.getNetworkType() + " network, Security Group enabled: " + zone.isSecurityGroupEnabled());
        }
    }
    if (tags != null && tags.size() > 1) {
        throw new InvalidParameterException("Unable to support more than one tag on network yet");
    }
    PhysicalNetwork.State networkState = null;
    if (state != null && !state.isEmpty()) {
        try {
            networkState = PhysicalNetwork.State.valueOf(state);
        } catch (IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve state '" + state + "' to a supported value {Enabled or Disabled}");
        }
    }
    if (state != null) {
        network.setState(networkState);
    }
    if (tags != null) {
        network.setTags(tags);
    }
    if (networkSpeed != null) {
        network.setSpeed(networkSpeed);
    }
    if (newVnetRange != null) {
        String[] listOfRanges = newVnetRange.split(",");
        addOrRemoveVnets(listOfRanges, network);
    }
    _physicalNetworkDao.update(id, network);
    return network;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 57 with InvalidParameterException

use of java.security.InvalidParameterException in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method updateLBStickinessPolicy.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LB_STICKINESSPOLICY_UPDATE, eventDescription = "updating lb stickiness policy", async = true)
public StickinessPolicy updateLBStickinessPolicy(long id, String customId, Boolean forDisplay) {
    LBStickinessPolicyVO policy = _lb2stickinesspoliciesDao.findById(id);
    if (policy == null) {
        throw new InvalidParameterValueException("Fail to find stickiness policy with " + id);
    }
    LoadBalancerVO loadBalancer = _lbDao.findById(Long.valueOf(policy.getLoadBalancerId()));
    if (loadBalancer == null) {
        throw new InvalidParameterException("Invalid Load balancer : " + policy.getLoadBalancerId() + " for Stickiness policy id: " + id);
    }
    _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, loadBalancer);
    if (customId != null) {
        policy.setUuid(customId);
    }
    if (forDisplay != null) {
        policy.setDisplay(forDisplay);
    }
    _lb2stickinesspoliciesDao.update(id, policy);
    return _lb2stickinesspoliciesDao.findById(id);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LBStickinessPolicyVO(com.cloud.network.dao.LBStickinessPolicyVO) ActionEvent(com.cloud.event.ActionEvent)

Example 58 with InvalidParameterException

use of java.security.InvalidParameterException in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method removeFromLoadBalancerInternal.

private boolean removeFromLoadBalancerInternal(long loadBalancerId, List<Long> instanceIds, boolean rollBack, Map<Long, List<String>> vmIdIpMap) {
    CallContext caller = CallContext.current();
    LoadBalancerVO loadBalancer = _lbDao.findById(Long.valueOf(loadBalancerId));
    if (loadBalancer == null) {
        throw new InvalidParameterException("Invalid load balancer value: " + loadBalancerId);
    }
    _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer);
    if (instanceIds == null && vmIdIpMap.isEmpty()) {
        throw new InvalidParameterValueException("Both instanceids and vmidipmap  can't be null");
    }
    // instanceIds and vmIdipmap is passed
    if (instanceIds != null && !vmIdIpMap.isEmpty()) {
        for (long instanceId : instanceIds) {
            if (!vmIdIpMap.containsKey(instanceId)) {
                vmIdIpMap.put(instanceId, null);
            }
        }
    }
    //only instanceids list passed
    if (instanceIds != null && vmIdIpMap.isEmpty()) {
        vmIdIpMap = new HashMap<Long, List<String>>();
        for (long instanceId : instanceIds) {
            vmIdIpMap.put(instanceId, null);
        }
    }
    boolean success = false;
    FirewallRule.State backupState = loadBalancer.getState();
    Set<Long> vmIds = vmIdIpMap.keySet();
    try {
        loadBalancer.setState(FirewallRule.State.Add);
        _lbDao.persist(loadBalancer);
        for (long instanceId : vmIds) {
            List<String> lbVmIps = vmIdIpMap.get(instanceId);
            if (lbVmIps == null || lbVmIps.isEmpty()) {
                List<LoadBalancerVMMapVO> lbVms = _lb2VmMapDao.listByLoadBalancerIdAndVmId(loadBalancerId, instanceId);
                if (lbVms == null) {
                    throw new InvalidParameterValueException("The instance id: " + instanceId + " is not configured " + " for LB rule id " + loadBalancerId);
                }
                for (LoadBalancerVMMapVO lbvm : lbVms) {
                    lbvm.setRevoke(true);
                    _lb2VmMapDao.persist(lbvm);
                }
                s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId + ", vmId " + instanceId);
            } else {
                for (String vmIp : lbVmIps) {
                    LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmIdVmIp(loadBalancerId, instanceId, vmIp);
                    if (map == null) {
                        throw new InvalidParameterValueException("The instance id: " + instanceId + " is not configured " + " for LB rule id " + loadBalancerId);
                    }
                    map.setRevoke(true);
                    _lb2VmMapDao.persist(map);
                    s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId + ", vmId " + instanceId + ", vmip " + vmIp);
                }
            }
        }
        if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) {
            // For autoscaled loadbalancer, the rules need not be applied,
            // meaning the call need not reach the resource layer.
            // We can consider the job done and only need to remove the
            // rules in DB
            _lb2VmMapDao.remove(loadBalancer.getId(), instanceIds, null);
            return true;
        }
        if (!applyLoadBalancerConfig(loadBalancerId)) {
            s_logger.warn("Failed to remove load balancer rule id " + loadBalancerId + " for vms " + instanceIds);
            CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + instanceIds);
            ex.addProxyObject(loadBalancer.getUuid(), "loadBalancerId");
            throw ex;
        }
        success = true;
    } catch (ResourceUnavailableException e) {
        if (rollBack && isRollBackAllowedForProvider(loadBalancer)) {
            for (long instanceId : vmIds) {
                List<String> lbVmIps = vmIdIpMap.get(instanceId);
                if (lbVmIps == null || lbVmIps.isEmpty()) {
                    LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmId(loadBalancerId, instanceId);
                    map.setRevoke(false);
                    _lb2VmMapDao.persist(map);
                    s_logger.debug("LB Rollback rule id: " + loadBalancerId + ",while removing vmId " + instanceId);
                } else {
                    for (String vmIp : lbVmIps) {
                        LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmIdVmIp(loadBalancerId, instanceId, vmIp);
                        map.setRevoke(true);
                        _lb2VmMapDao.persist(map);
                        s_logger.debug("LB Rollback rule id: " + loadBalancerId + ",while removing vmId " + instanceId + ", vmip " + vmIp);
                    }
                }
            }
            loadBalancer.setState(backupState);
            _lbDao.persist(loadBalancer);
            s_logger.debug("LB Rollback rule id: " + loadBalancerId + " while removing vm instances");
        }
        s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
    }
    if (!success) {
        CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + vmIds);
        ex.addProxyObject(loadBalancer.getUuid(), "loadBalancerId");
        throw ex;
    }
    return success;
}
Also used : LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) CallContext(org.apache.cloudstack.context.CallContext) InvalidParameterException(java.security.InvalidParameterException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ArrayList(java.util.ArrayList) List(java.util.List) LoadBalancerVMMapVO(com.cloud.network.dao.LoadBalancerVMMapVO) FirewallRule(com.cloud.network.rules.FirewallRule)

Example 59 with InvalidParameterException

use of java.security.InvalidParameterException in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method updateLBHealthCheckPolicy.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LB_HEALTHCHECKPOLICY_UPDATE, eventDescription = "updating lb healthcheck policy", async = true)
public HealthCheckPolicy updateLBHealthCheckPolicy(long id, String customId, Boolean forDisplay) {
    LBHealthCheckPolicyVO policy = _lb2healthcheckDao.findById(id);
    if (policy == null) {
        throw new InvalidParameterValueException("Fail to find stickiness policy with " + id);
    }
    LoadBalancerVO loadBalancer = _lbDao.findById(Long.valueOf(policy.getLoadBalancerId()));
    if (loadBalancer == null) {
        throw new InvalidParameterException("Invalid Load balancer : " + policy.getLoadBalancerId() + " for Stickiness policy id: " + id);
    }
    _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, loadBalancer);
    if (customId != null) {
        policy.setUuid(customId);
    }
    if (forDisplay != null) {
        policy.setDisplay(forDisplay);
    }
    _lb2healthcheckDao.update(id, policy);
    return _lb2healthcheckDao.findById(id);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LBHealthCheckPolicyVO(com.cloud.network.LBHealthCheckPolicyVO) ActionEvent(com.cloud.event.ActionEvent)

Example 60 with InvalidParameterException

use of java.security.InvalidParameterException in project wildfly by wildfly.

the class DataSourceOperationsUnitTestCase method testAddComplexDs.

private void testAddComplexDs(ConnectionSecurityType connectionSecurityType) throws Exception {
    final String complexDs;
    switch(connectionSecurityType) {
        case ELYTRON:
            complexDs = "complexDsElytronWithOutAuthCtx";
            break;
        case ELYTRON_AUTHENTICATION_CONTEXT:
            complexDs = "complexDsElytronWithAuthCtx";
            break;
        case SECURITY_DOMAIN:
            complexDs = "complexDs";
            break;
        case USER_PASSWORD:
            complexDs = "complexDsWithUserName";
            break;
        default:
            throw new InvalidParameterException("Unsupported connection security type for Data Sources: " + connectionSecurityType);
    }
    final String complexDsJndi = "java:jboss/datasources/" + complexDs;
    final ModelNode address = new ModelNode();
    address.add("subsystem", "datasources");
    address.add("data-source", complexDs);
    address.protect();
    Properties params = nonXaDsProperties(complexDsJndi, connectionSecurityType);
    final ModelNode operation = new ModelNode();
    operation.get(OP).set("add");
    operation.get(OP_ADDR).set(address);
    operation.get("enabled").set(false);
    setOperationParams(operation, params);
    addExtensionProperties(operation);
    executeOperation(operation);
    final ModelNode datasourcePropertiesAddress = address.clone();
    datasourcePropertiesAddress.add("connection-properties", "char.encoding");
    datasourcePropertiesAddress.protect();
    final ModelNode datasourcePropertyOperation = new ModelNode();
    datasourcePropertyOperation.get(OP).set("add");
    datasourcePropertyOperation.get(OP_ADDR).set(datasourcePropertiesAddress);
    datasourcePropertyOperation.get("value").set("UTF-8");
    executeOperation(datasourcePropertyOperation);
    List<ModelNode> newList = marshalAndReparseDsResources("data-source");
    remove(address);
    Assert.assertNotNull("Reparsing failed:", newList);
    ModelNode rightChild = findNodeWithProperty(newList, "jndi-name", complexDsJndi);
    Assert.assertTrue("node:" + rightChild.asString() + ";\nparams" + params, checkModelParams(rightChild, params));
    Assert.assertEquals(rightChild.asString(), "Property2", rightChild.get("valid-connection-checker-properties", "name").asString());
    Assert.assertEquals(rightChild.asString(), "Property4", rightChild.get("exception-sorter-properties", "name").asString());
    Assert.assertEquals(rightChild.asString(), "Property3", rightChild.get("stale-connection-checker-properties", "name").asString());
    Assert.assertEquals(rightChild.asString(), "Property1", rightChild.get("reauth-plugin-properties", "name").asString());
    Assert.assertNotNull("connection-properties not propagated ", findNodeWithProperty(newList, "value", "UTF-8"));
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ModelNode(org.jboss.dmr.ModelNode) ComplexPropertiesParseUtils.xaDsProperties(org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.xaDsProperties) ComplexPropertiesParseUtils.nonXaDsProperties(org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.nonXaDsProperties) Properties(java.util.Properties) ComplexPropertiesParseUtils.addExtensionProperties(org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.addExtensionProperties)

Aggregations

InvalidParameterException (java.security.InvalidParameterException)135 SecureRandom (java.security.SecureRandom)15 ActionEvent (com.cloud.event.ActionEvent)11 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)9 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 Paint (android.graphics.Paint)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 DB (com.cloud.utils.db.DB)7 File (java.io.File)7 Properties (java.util.Properties)7 NimbusClient (backtype.storm.utils.NimbusClient)6 FirewallRule (com.cloud.network.rules.FirewallRule)6 InvalidKeyException (java.security.InvalidKeyException)6 Time (android.text.format.Time)4 FileNotFoundException (java.io.FileNotFoundException)4