Search in sources :

Example 1 with InvalidArgumentException

use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.

the class CsarGitRepositoryService method create.

/**
 * Create a CsarGitRepository in the system to store its informations
 *
 * @param repositoryUrl The unique Git url of the CsarGitRepository
 * @param username The username of the user
 * @param password The password of the user
 * @param importLocations Locations where Csar's files are store
 * @param isStoredLocally The state of the the CsarGitRepository
 * @return The auto-generated id of the CsarGitRepository object
 */
public String create(String repositoryUrl, String username, String password, List<CsarGitCheckoutLocation> importLocations, boolean isStoredLocally) {
    validatesRepositoryUrl(repositoryUrl);
    failIfExists(repositoryUrl);
    if (importLocations.isEmpty()) {
        throw new InvalidArgumentException("Import locations cannot be empty.");
    }
    // create it
    CsarGitRepository csarGit = new CsarGitRepository();
    csarGit.setId(UUID.randomUUID().toString());
    csarGit.setRepositoryUrl(repositoryUrl);
    csarGit.setUsername(username);
    csarGit.setPassword(password);
    csarGit.setImportLocations(importLocations);
    csarGit.setStoredLocally(isStoredLocally);
    alienDAO.save(csarGit);
    return csarGit.getId();
}
Also used : InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) CsarGitRepository(alien4cloud.model.git.CsarGitRepository)

Example 2 with InvalidArgumentException

use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.

the class NodeMatcherService method match.

public Map<String, List<LocationResourceTemplate>> match(Map<String, NodeType> nodesTypes, Map<String, NodeTemplate> nodesToMatch, Location location, String environmentId) {
    Map<String, List<LocationResourceTemplate>> matchingResult = Maps.newHashMap();
    // fetch location resources
    LocationResources locationResources = locationResourceService.getLocationResources(location);
    // Authorization filtering of location resources
    filterOnAuthorization(locationResources.getNodeTemplates(), environmentId);
    // fetch service resources
    List<ServiceResource> services = serviceResourceService.searchByLocation(location.getId());
    // self filtering: remove managed service linked to this location
    filterSelfManagedService(services, environmentId);
    // Authorization filtering of location resources
    filterOnAuthorization(services, environmentId);
    // from serviceResource to locationResource
    populateLocationResourcesWithServiceResource(locationResources, services, location.getId());
    Map<String, MatchingConfiguration> matchingConfigurations = locationMatchingConfigurationService.getMatchingConfiguration(location);
    Set<String> typesManagedByLocation = Sets.newHashSet();
    for (NodeType nodeType : locationResources.getNodeTypes().values()) {
        typesManagedByLocation.add(nodeType.getElementId());
        typesManagedByLocation.addAll(nodeType.getDerivedFrom());
    }
    INodeMatcherPlugin nodeMatcherPlugin = getNodeMatcherPlugin();
    for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodesToMatch.entrySet()) {
        String nodeTemplateId = nodeTemplateEntry.getKey();
        NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
        if (typesManagedByLocation.contains(nodeTemplate.getType())) {
            NodeType nodeTemplateType = nodesTypes.get(nodeTemplate.getType());
            if (nodeTemplateType == null) {
                throw new InvalidArgumentException("The given node types map must contain the type of the node template");
            }
            matchingResult.put(nodeTemplateId, nodeMatcherPlugin.matchNode(nodeTemplate, nodeTemplateType, locationResources, matchingConfigurations));
        }
    }
    return matchingResult;
}
Also used : MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) NodeType(org.alien4cloud.tosca.model.types.NodeType) List(java.util.List) ServiceResource(alien4cloud.model.service.ServiceResource) INodeMatcherPlugin(alien4cloud.deployment.matching.plugins.INodeMatcherPlugin) Map(java.util.Map)

Example 3 with InvalidArgumentException

use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.

the class GroupService method updateGroup.

public void updateGroup(String groupId, UpdateGroupRequest groupUpdateRequest) {
    Group group = retrieveGroup(groupId);
    String currentGroupName = group.getName();
    ReflectionUtil.mergeObject(groupUpdateRequest, group);
    if (group.getName() == null || group.getName().isEmpty()) {
        throw new InvalidArgumentException("Group's name cannot be set to null or empty");
    }
    // Check with precedent value
    if (!currentGroupName.equals(group.getName())) {
        // If group name has changed, must check unicity
        checkGroupNameUniqueness(group.getName());
    }
    alienGroupDao.save(group);
}
Also used : Group(alien4cloud.security.model.Group) InvalidArgumentException(alien4cloud.exception.InvalidArgumentException)

Example 4 with InvalidArgumentException

use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.

the class AuditController method enableMethodAudit.

private void enableMethodAudit(Map<Method, Boolean> auditedMethodsMap, AuditedMethod method) {
    if (method.getMethod() == null) {
        throw new InvalidArgumentException("Method's path or http method is null");
    }
    Method auditedMethodKey = new Method(method.getSignature(), method.getMethod(), method.getCategory(), method.getAction(), method.getBodyHiddenFields());
    if (!auditedMethodsMap.containsKey(auditedMethodKey)) {
        throw new NotFoundException("Method " + method + " does not exist ");
    }
    auditedMethodsMap.put(auditedMethodKey, method.isEnabled());
}
Also used : InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) NotFoundException(alien4cloud.exception.NotFoundException) Method(alien4cloud.audit.model.Method) AuditedMethod(alien4cloud.audit.model.AuditedMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) RequestMethod(org.springframework.web.bind.annotation.RequestMethod)

Example 5 with InvalidArgumentException

use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.

the class ReflectionUtil method mergeObject.

/**
 * Merge object from an object to another. Failsafe : resist to invalid property.
 *
 * @param from source of the update
 * @param to target of the update
 * @param ignoreNullValue indicate if we should merge null value
 * @param ignores properties names that should be ignored
 */
public static void mergeObject(Object from, Object to, boolean ignoreNullValue, Set<String> ignores) {
    try {
        Map<String, Object> settablePropertiesMap = Maps.newHashMap();
        PropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(from.getClass());
        for (PropertyDescriptor property : propertyDescriptors) {
            if (property.getReadMethod() == null || property.getWriteMethod() == null) {
                continue;
            }
            Object value = property.getReadMethod().invoke(from);
            if ((value != null || !ignoreNullValue) && !ignores.contains(property.getName())) {
                settablePropertiesMap.put(property.getName(), value);
            }
        }
        for (Map.Entry<String, Object> settableProperty : settablePropertiesMap.entrySet()) {
            // Set new values
            String propertyName = settableProperty.getKey();
            Object propertyValue = settableProperty.getValue();
            setPropertyValue(to, propertyName, propertyValue);
        }
    } catch (IllegalAccessException | InvocationTargetException | BeansException e) {
        throw new InvalidArgumentException("Cannot merge object", e);
    }
}
Also used : InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException) BeansException(org.springframework.beans.BeansException)

Aggregations

InvalidArgumentException (alien4cloud.exception.InvalidArgumentException)10 Map (java.util.Map)4 NotFoundException (alien4cloud.exception.NotFoundException)2 List (java.util.List)2 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)2 DataType (org.alien4cloud.tosca.model.types.DataType)2 PrimitiveDataType (org.alien4cloud.tosca.model.types.PrimitiveDataType)2 AuditedMethod (alien4cloud.audit.model.AuditedMethod)1 Method (alien4cloud.audit.model.Method)1 INodeMatcherPlugin (alien4cloud.deployment.matching.plugins.INodeMatcherPlugin)1 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)1 CsarGitRepository (alien4cloud.model.git.CsarGitRepository)1 LocationResources (alien4cloud.model.orchestrators.locations.LocationResources)1 ServiceResource (alien4cloud.model.service.ServiceResource)1 Group (alien4cloud.security.model.Group)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 InvalidPropertyValueException (org.alien4cloud.tosca.exceptions.InvalidPropertyValueException)1 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)1