use of org.alien4cloud.tosca.catalog.events.ArchiveUsageRequestEvent 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 org.alien4cloud.tosca.catalog.events.ArchiveUsageRequestEvent in project alien4cloud by alien4cloud.
the class ServiceResourceServiceTest method testReportArchiveUsage.
@Test
public void testReportArchiveUsage() {
ServiceResource serviceResource = new ServiceResource();
serviceResource.setId("service1");
serviceResource.setName("service name 1");
serviceResource.setDependency(new CSARDependency("org.alien4cloud.archives:my-archive", "1.0.0-SNAPSHOT"));
alienDao.save(serviceResource);
ArchiveUsageRequestEvent archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:my-archive", "1.0.0-SNAPSHOT");
serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
Assert.assertEquals(1, archiveUsageRequestEvent.getUsages().size());
Assert.assertEquals("service1", archiveUsageRequestEvent.getUsages().get(0).getResourceId());
Assert.assertEquals("serviceresource", archiveUsageRequestEvent.getUsages().get(0).getResourceType());
Assert.assertEquals("service name 1", archiveUsageRequestEvent.getUsages().get(0).getResourceName());
archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:other-archive", "1.0.0-SNAPSHOT");
serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
Assert.assertEquals(0, archiveUsageRequestEvent.getUsages().size());
archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:my-archive", "1.0.1-SNAPSHOT");
serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
Assert.assertEquals(0, archiveUsageRequestEvent.getUsages().size());
}
Aggregations