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);
}
}
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();
}
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;
}
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;
}
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();
}
Aggregations