Search in sources :

Example 36 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class ConfigurationManagerImpl method releasePublicIpRange.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_RELEASE, eventDescription = "releasing a public ip range", async = false)
public boolean releasePublicIpRange(final ReleasePublicIpRangeCmd cmd) {
    final Long vlanDbId = cmd.getId();
    final VlanVO vlan = _vlanDao.findById(vlanDbId);
    if (vlan == null) {
        throw new InvalidParameterValueException("Please specify a valid IP range id.");
    }
    return releasePublicIpRange(vlanDbId, CallContext.current().getCallingUserId(), CallContext.current().getCallingAccount());
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VlanVO(com.cloud.dc.VlanVO) ActionEvent(com.cloud.event.ActionEvent)

Example 37 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class ConfigurationManagerImpl method updateConfiguration.

@Override
@ActionEvent(eventType = EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, eventDescription = "updating configuration")
public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidParameterValueException {
    final Long userId = CallContext.current().getCallingUserId();
    final String name = cmd.getCfgName();
    String value = cmd.getValue();
    final Long zoneId = cmd.getZoneId();
    final Long clusterId = cmd.getClusterId();
    final Long storagepoolId = cmd.getStoragepoolId();
    final Long accountId = cmd.getAccountId();
    final Long imageStoreId = cmd.getImageStoreId();
    CallContext.current().setEventDetails(" Name: " + name + " New Value: " + (name.toLowerCase().contains("password") ? "*****" : value == null ? "" : value));
    // check if config value exists
    final ConfigurationVO config = _configDao.findByName(name);
    String catergory = null;
    // FIX ME - All configuration parameters are not moved from config.java to configKey
    if (config == null) {
        if (_configDepot.get(name) == null) {
            s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface");
            throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
        }
        catergory = _configDepot.get(name).category();
    } else {
        catergory = config.getCategory();
    }
    if (value == null) {
        return _configDao.findByName(name);
    }
    value = value.trim();
    if (value.isEmpty() || value.equals("null")) {
        value = null;
    }
    String scope = null;
    Long id = null;
    int paramCountCheck = 0;
    if (zoneId != null) {
        scope = ConfigKey.Scope.Zone.toString();
        id = zoneId;
        paramCountCheck++;
    }
    if (clusterId != null) {
        scope = ConfigKey.Scope.Cluster.toString();
        id = clusterId;
        paramCountCheck++;
    }
    if (accountId != null) {
        scope = ConfigKey.Scope.Account.toString();
        id = accountId;
        paramCountCheck++;
    }
    if (storagepoolId != null) {
        scope = ConfigKey.Scope.StoragePool.toString();
        id = storagepoolId;
        paramCountCheck++;
    }
    if (imageStoreId != null) {
        scope = ConfigKey.Scope.ImageStore.toString();
        id = imageStoreId;
        paramCountCheck++;
    }
    if (paramCountCheck > 1) {
        throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
    }
    final String updatedValue = updateConfiguration(userId, name, catergory, value, scope, id);
    if (value == null && updatedValue == null || updatedValue.equalsIgnoreCase(value)) {
        return _configDao.findByName(name);
    } else {
        throw new CloudRuntimeException("Unable to update configuration parameter " + name);
    }
}
Also used : ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ActionEvent(com.cloud.event.ActionEvent)

Example 38 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class FirewallManagerImpl method revokeAllFirewallRulesForNetwork.

@Override
@ActionEvent(eventType = EventTypes.EVENT_FIREWALL_CLOSE, eventDescription = "revoking firewall rule", async = true)
public boolean revokeAllFirewallRulesForNetwork(long networkId, long userId, Account caller) throws ResourceUnavailableException {
    List<FirewallRule> rules = new ArrayList<FirewallRule>();
    List<FirewallRuleVO> fwRules = _firewallDao.listByNetworkAndPurposeAndNotRevoked(networkId, Purpose.Firewall);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Releasing " + fwRules.size() + " firewall rules for network id=" + networkId);
    }
    for (FirewallRuleVO rule : fwRules) {
        // Mark all Firewall rules as Revoke, but don't revoke them yet - we have to revoke all rules for ip, no
        // need to send them one by one
        revokeFirewallRule(rule.getId(), false, caller, Account.ACCOUNT_ID_SYSTEM);
    }
    // now send everything to the backend
    List<FirewallRuleVO> rulesToApply = _firewallDao.listByNetworkAndPurpose(networkId, Purpose.Firewall);
    boolean success = applyFirewallRules(rulesToApply, true, caller);
    // Now we check again in case more rules have been inserted.
    rules.addAll(_firewallDao.listByNetworkAndPurposeAndNotRevoked(networkId, Purpose.Firewall));
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Successfully released firewall rules for network id=" + networkId + " and # of rules now = " + rules.size());
    }
    return success && rules.size() == 0;
}
Also used : ArrayList(java.util.ArrayList) FirewallRule(com.cloud.network.rules.FirewallRule) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) ActionEvent(com.cloud.event.ActionEvent)

Example 39 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class FirewallManagerImpl method revokeFirewallRulesForIp.

@Override
@ActionEvent(eventType = EventTypes.EVENT_FIREWALL_CLOSE, eventDescription = "revoking firewall rule", async = true)
public boolean revokeFirewallRulesForIp(long ipId, long userId, Account caller) throws ResourceUnavailableException {
    List<FirewallRule> rules = new ArrayList<FirewallRule>();
    List<FirewallRuleVO> fwRules = _firewallDao.listByIpAndPurposeAndNotRevoked(ipId, Purpose.Firewall);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Releasing " + fwRules.size() + " firewall rules for ip id=" + ipId);
    }
    for (FirewallRuleVO rule : fwRules) {
        // Mark all Firewall rules as Revoke, but don't revoke them yet - we have to revoke all rules for ip, no
        // need to send them one by one
        revokeFirewallRule(rule.getId(), false, caller, Account.ACCOUNT_ID_SYSTEM);
    }
    // now send everything to the backend
    List<FirewallRuleVO> rulesToApply = _firewallDao.listByIpAndPurpose(ipId, Purpose.Firewall);
    //apply rules
    if (!applyFirewallRules(rulesToApply, rulesContinueOnErrFlag, caller)) {
        if (!rulesContinueOnErrFlag) {
            return false;
        }
    }
    // Now we check again in case more rules have been inserted.
    rules.addAll(_firewallDao.listByIpAndPurposeAndNotRevoked(ipId, Purpose.Firewall));
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Successfully released firewall rules for ip id=" + ipId + " and # of rules now = " + rules.size());
    }
    return rules.size() == 0;
}
Also used : ArrayList(java.util.ArrayList) FirewallRule(com.cloud.network.rules.FirewallRule) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) ActionEvent(com.cloud.event.ActionEvent)

Example 40 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class ProjectManagerImpl method deleteProject.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_DELETE, eventDescription = "deleting project", async = true)
public boolean deleteProject(long projectId) {
    CallContext ctx = CallContext.current();
    ProjectVO project = getProject(projectId);
    //verify input parameters
    if (project == null) {
        throw new InvalidParameterValueException("Unable to find project by id " + projectId);
    }
    _accountMgr.checkAccess(ctx.getCallingAccount(), AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
    return deleteProject(ctx.getCallingAccount(), ctx.getCallingUserId(), project);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CallContext(org.apache.cloudstack.context.CallContext) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

ActionEvent (com.cloud.event.ActionEvent)209 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)174 Account (com.cloud.user.Account)114 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)80 DB (com.cloud.utils.db.DB)79 TransactionStatus (com.cloud.utils.db.TransactionStatus)40 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)32 ArrayList (java.util.ArrayList)31 CallContext (org.apache.cloudstack.context.CallContext)22 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)20 DataCenterVO (com.cloud.dc.DataCenterVO)18 Network (com.cloud.network.Network)18 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)17 InvalidParameterException (java.security.InvalidParameterException)16 List (java.util.List)16 NetworkVO (com.cloud.network.dao.NetworkVO)15 ConfigurationException (javax.naming.ConfigurationException)15 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)14