Search in sources :

Example 11 with Usage

use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.

the class ServiceResourceService method failIdUsed.

private void failIdUsed(String id) {
    ServiceUsageRequestEvent serviceUsageRequestEvent = new ServiceUsageRequestEvent(this, id);
    publisher.publishEvent(serviceUsageRequestEvent);
    Usage[] usages = serviceUsageRequestEvent.getUsages();
    if (usages.length > 0) {
        throw new ServiceUsageException("Used services cannot be updated or deleted.", usages);
    }
}
Also used : ServiceUsageException(org.alien4cloud.alm.service.exceptions.ServiceUsageException) Usage(alien4cloud.model.common.Usage) ServiceUsageRequestEvent(org.alien4cloud.alm.service.events.ServiceUsageRequestEvent)

Example 12 with Usage

use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.

the class CsarService method getCsarRelatedResourceList.

/**
 * Get the list of resources that are using the given archive.
 *
 * @param csar The archive for which to get usage.
 * @return The list of usage of the archive.
 */
public List<Usage> getCsarRelatedResourceList(Csar csar) {
    if (csar == null) {
        log.debug("You have requested a resource list for a invalid csar object : <" + csar + ">");
        return Lists.newArrayList();
    }
    ArchiveUsageRequestEvent archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, csar.getName(), csar.getVersion());
    // Archive from applications are used by the application.
    if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) {
        // The CSAR is from an application's topology
        Application application = applicationService.checkAndGetApplication(csar.getDelegateId());
        archiveUsageRequestEvent.addUsage(new Usage(application.getName(), Application.class.getSimpleName().toLowerCase(), csar.getDelegateId(), csar.getWorkspace()));
    }
    // a csar that is a dependency of another csar can not be deleted
    Csar[] relatedCsars = getDependantCsars(csar.getName(), csar.getVersion());
    if (ArrayUtils.isNotEmpty(relatedCsars)) {
        archiveUsageRequestEvent.addUsages(generateCsarsInfo(relatedCsars));
    }
    // check if some of the nodes are used in topologies.
    Topology[] topologies = getDependantTopologies(csar.getName(), csar.getVersion());
    if (topologies != null && topologies.length > 0) {
        archiveUsageRequestEvent.addUsages(generateTopologiesInfo(topologies));
    }
    // a csar that is a dependency of location can not be deleted
    Location[] relatedLocations = getDependantLocations(csar.getName(), csar.getVersion());
    if (relatedLocations != null && relatedLocations.length > 0) {
        archiveUsageRequestEvent.addUsages(generateLocationsInfo(relatedLocations));
    }
    publisher.publishEvent(archiveUsageRequestEvent);
    return archiveUsageRequestEvent.getUsages();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) ArchiveUsageRequestEvent(org.alien4cloud.tosca.catalog.events.ArchiveUsageRequestEvent) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) Location(alien4cloud.model.orchestrators.locations.Location)

Example 13 with Usage

use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.

the class CsarService method generateCsarsInfo.

/**
 * Generate resources related to a csar list
 *
 * @param csars
 * @return
 */
public List<Usage> generateCsarsInfo(Csar[] csars) {
    String resourceName;
    String resourceId;
    List<Usage> resourceList = Lists.newArrayList();
    for (Csar csar : csars) {
        if (ArchiveDelegateType.APPLICATION.toString().equals(csar.getDelegateType())) {
            Application application = applicationService.checkAndGetApplication(csar.getDelegateId());
            resourceName = application.getName();
        } else {
            resourceName = csar.getName();
        }
        Usage temp = new Usage(resourceName, Csar.class.getSimpleName().toLowerCase(), csar.getId(), csar.getWorkspace());
        resourceList.add(temp);
    }
    return resourceList;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) Application(alien4cloud.model.application.Application)

Example 14 with Usage

use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.

the class CsarService method generateLocationsInfo.

/**
 * Generate resources related to a locations list
 *
 * @param locations
 * @return
 */
public List<Usage> generateLocationsInfo(Location[] locations) {
    String resourceName;
    String resourceId;
    List<Usage> resourceList = Lists.newArrayList();
    for (Location location : locations) {
        resourceName = location.getName();
        resourceId = location.getId();
        Usage temp = new Usage(resourceName, Location.class.getSimpleName().toLowerCase(), resourceId, AlienConstants.GLOBAL_WORKSPACE_ID);
        resourceList.add(temp);
    }
    return resourceList;
}
Also used : Usage(alien4cloud.model.common.Usage) Location(alien4cloud.model.orchestrators.locations.Location)

Example 15 with Usage

use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.

the class CloudServiceArchiveController method read.

@ApiOperation(value = "Get a CSAR given its id.", notes = "Returns a CSAR.")
@RequestMapping(value = "/{csarId:.+?}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<CsarInfoDTO> read(@PathVariable String csarId) {
    Csar csar = csarService.getOrFail(csarId);
    csarAuthorizationFilter.checkReadAccess(csar);
    List<Usage> relatedResourceList = csarService.getCsarRelatedResourceList(csar);
    CsarInfoDTO csarInfo = new CsarInfoDTO(csar, relatedResourceList);
    return RestResponseBuilder.<CsarInfoDTO>builder().data(csarInfo).build();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Usage (alien4cloud.model.common.Usage)16 Csar (org.alien4cloud.tosca.model.Csar)7 Application (alien4cloud.model.application.Application)4 Deployment (alien4cloud.model.deployment.Deployment)3 Location (alien4cloud.model.orchestrators.locations.Location)3 ApiOperation (io.swagger.annotations.ApiOperation)3 List (java.util.List)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ServiceResource (alien4cloud.model.service.ServiceResource)2 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)2 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)2 ServiceUsageRequestEvent (org.alien4cloud.alm.service.events.ServiceUsageRequestEvent)2 EventListener (org.springframework.context.event.EventListener)2 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)1 Audit (alien4cloud.audit.annotation.Audit)1 FilterUtil.fromKeyValueCouples (alien4cloud.dao.FilterUtil.fromKeyValueCouples)1 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)1 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 LocationArchiveDeleteRequested (alien4cloud.events.LocationArchiveDeleteRequested)1