use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ManagedServiceResourceEventService method onDeploymentCreatedEvent.
/**
* On {@link DeploymentCreatedEvent}, eventually update the linked managed service
*
* @param event
*/
@EventListener
public void onDeploymentCreatedEvent(DeploymentCreatedEvent event) {
Deployment deployment = deploymentService.get(event.getDeploymentId());
if (deployment != null) {
ServiceResource serviceResource = managedServiceResourceService.get(deployment.getEnvironmentId());
if (serviceResource != null) {
serviceResource.setDeploymentId(event.getDeploymentId());
serviceResourceService.save(serviceResource);
}
}
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ManagedServiceResourceService method unbind.
/**
* Unbind the service resource from the application environment
*
* Note that the service will still exists, but will only be updatable via service api
*
* @param environmentId The environment for which to get the service resource.
*/
public void unbind(String environmentId) {
ServiceResource serviceResource = getOrFail(environmentId);
serviceResource.setEnvironmentId(null);
serviceResourceService.save(serviceResource);
publisher.publishEvent(new ManagedServiceUnbindEvent(this, serviceResource));
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ManagedServiceResourceService method updateServiceRelationship.
private void updateServiceRelationship(String serviceId, Topology topology) {
ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
updateServiceRelationship(serviceResource, topology);
}
use of alien4cloud.model.service.ServiceResource 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());
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ServiceSecurityController method getAuthorizedEnvironmentsPerApplication.
/**
* List all environments per application authorised to access the location.
*
* @return list of all environments per application.
*/
@ApiOperation(value = "List all applications, environments and environment types authorized to access the service resource", notes = "Only user with ADMIN role can list authorized applications, environments and environment types for the location.")
@RequestMapping(value = "/environmentsPerApplication", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<List<ApplicationEnvironmentAuthorizationDTO>> getAuthorizedEnvironmentsPerApplication(@PathVariable String serviceId) {
ServiceResource service = serviceResourceService.getOrFail(serviceId);
List<Application> applicationsRelatedToEnvironment = Lists.newArrayList();
List<Application> applicationsRelatedToEnvironmentType = Lists.newArrayList();
List<ApplicationEnvironment> environments = Lists.newArrayList();
List<String> environmentTypes = Lists.newArrayList();
List<Application> applications = Lists.newArrayList();
if (service.getEnvironmentPermissions() != null && service.getEnvironmentPermissions().size() > 0) {
environments = alienDAO.findByIds(ApplicationEnvironment.class, service.getEnvironmentPermissions().keySet().toArray(new String[service.getEnvironmentPermissions().size()]));
Set<String> environmentApplicationIds = environments.stream().map(ae -> ae.getApplicationId()).collect(Collectors.toSet());
applicationsRelatedToEnvironment = alienDAO.findByIds(Application.class, environmentApplicationIds.toArray(new String[environmentApplicationIds.size()]));
}
if (service.getEnvironmentTypePermissions() != null && service.getEnvironmentTypePermissions().size() > 0) {
environmentTypes.addAll(service.getEnvironmentTypePermissions().keySet());
Set<String> environmentTypeApplicationIds = Sets.newHashSet();
for (String envType : safe(service.getEnvironmentTypePermissions()).keySet()) {
environmentTypeApplicationIds.add(envType.split(":")[0]);
}
applicationsRelatedToEnvironmentType = alienDAO.findByIds(Application.class, environmentTypeApplicationIds.toArray(new String[environmentTypeApplicationIds.size()]));
}
if (service.getApplicationPermissions() != null && service.getApplicationPermissions().size() > 0) {
applications = alienDAO.findByIds(Application.class, service.getApplicationPermissions().keySet().toArray(new String[service.getApplicationPermissions().size()]));
}
List<ApplicationEnvironmentAuthorizationDTO> result = ApplicationEnvironmentAuthorizationDTO.buildDTOs(applicationsRelatedToEnvironment, applicationsRelatedToEnvironmentType, environments, applications, environmentTypes);
return RestResponseBuilder.<List<ApplicationEnvironmentAuthorizationDTO>>builder().data(result).build();
}
Aggregations