Search in sources :

Example 41 with NotFoundException

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

the class ArtifactProcessorService method processLocalArtifact.

private void processLocalArtifact(AbstractArtifact artifact) {
    try {
        Path csarPath = repository.getExpandedCSAR(artifact.getArchiveName(), artifact.getArchiveVersion());
        Path resolvedPath = csarPath.resolve(artifact.getArtifactRef());
        if (!Files.exists(resolvedPath)) {
            throw new UnresolvableArtifactException("Artifact could not be accessed " + artifact);
        }
        artifact.setArtifactPath(resolvedPath.toString());
    } catch (NotFoundException e) {
        throw new UnresolvableArtifactException("Artifact could not be found " + artifact, e);
    }
}
Also used : Path(java.nio.file.Path) UnresolvableArtifactException(alien4cloud.deployment.exceptions.UnresolvableArtifactException) NotFoundException(alien4cloud.exception.NotFoundException)

Example 42 with NotFoundException

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

the class UserService method updateUserGroupRoles.

/**
 * Regenerate the group roles in the user.
 *
 * @param user the user for which to regenerate the group roles
 */
public void updateUserGroupRoles(User user) {
    if (CollectionUtils.isEmpty(user.getGroups())) {
        user.setGroupRoles(null);
    } else {
        Set<String> groupRolesSet = Sets.newHashSet();
        for (String groupId : user.getGroups()) {
            Group group = alienGroupDao.find(groupId);
            if (group == null) {
                throw new NotFoundException("Group [" + groupId + "] cannot be found");
            }
            if (CollectionUtils.isNotEmpty(group.getRoles())) {
                groupRolesSet.addAll(group.getRoles());
            }
        }
        user.setGroupRoles(groupRolesSet);
    }
    alienUserDao.save(user);
}
Also used : Group(alien4cloud.security.model.Group) NotFoundException(alien4cloud.exception.NotFoundException)

Example 43 with NotFoundException

use of alien4cloud.exception.NotFoundException 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 44 with NotFoundException

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

the class NodeInstanceService method updateCapabilities.

private void updateCapabilities(NodeTemplate nodeTemplate, Map<String, Capability> nodeCapabilities) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
    for (Map.Entry<String, Capability> entry : nodeCapabilities.entrySet()) {
        if (entry != null) {
            Capability patchCapability = PatchUtil.realValue(entry.getValue());
            if (patchCapability == null) {
                throw new IllegalArgumentException("It is not allowed to set null to a capability.");
            } else {
                Capability targetCapability = nodeTemplate.getCapabilities().get(entry.getKey());
                if (targetCapability == null) {
                    throw new NotFoundException("Capability <" + entry.getKey() + "> doesn't exists on the node.");
                }
                CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, targetCapability.getType());
                updateCapabilitiesProperties(capabilityType, targetCapability, patchCapability);
            }
        }
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) Map(java.util.Map)

Example 45 with NotFoundException

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

the class ServiceResourceService method updateLocations.

private void updateLocations(ServiceResource serviceResource, String[] locations) {
    if (locations == null) {
        return;
    }
    // Check what elements have changed.
    Set<String> removedLocations = CollectionUtils.safeNewHashSet(serviceResource.getLocationIds());
    Set<String> addedLocations = Sets.newHashSet();
    Set<String> newLocations = Sets.newHashSet();
    for (String locationId : locations) {
        if (removedLocations.contains(locationId)) {
            // This location was already affected
            removedLocations.remove(locationId);
            newLocations.add(locationId);
        } else {
            // This is an added element.
            if (!alienDAO.exist(Location.class, locationId)) {
                throw new NotFoundException("Location with id <" + locationId + "> does not exist.");
            }
            addedLocations.add(locationId);
            newLocations.add(locationId);
        }
    }
    serviceResource.setLocationIds(newLocations.toArray(new String[newLocations.size()]));
    // Dispatch location changed events (not a big deal if the save is actually canceled as it just changed the update date).
    for (String locationId : addedLocations) {
        publisher.publishEvent(new OnLocationResourceChangeEvent(this, locationId));
    }
    for (String locationId : removedLocations) {
        publisher.publishEvent(new OnLocationResourceChangeEvent(this, locationId));
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) OnLocationResourceChangeEvent(alien4cloud.orchestrators.locations.events.OnLocationResourceChangeEvent) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)88 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)12 Map (java.util.Map)10 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)10 AlreadyExistException (alien4cloud.exception.AlreadyExistException)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)9 Capability (org.alien4cloud.tosca.model.templates.Capability)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)8 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)8 Topology (org.alien4cloud.tosca.model.templates.Topology)7 Deployment (alien4cloud.model.deployment.Deployment)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 InvalidNameException (alien4cloud.exception.InvalidNameException)5 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5