Search in sources :

Example 21 with ServiceResource

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);
        }
    }
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) ServiceResource(alien4cloud.model.service.ServiceResource) IPaasEventListener(alien4cloud.paas.IPaasEventListener) EventListener(org.springframework.context.event.EventListener)

Example 22 with 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));
}
Also used : ManagedServiceUnbindEvent(org.alien4cloud.alm.events.ManagedServiceUnbindEvent) ServiceResource(alien4cloud.model.service.ServiceResource)

Example 23 with 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);
}
Also used : ServiceResource(alien4cloud.model.service.ServiceResource)

Example 24 with ServiceResource

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());
}
Also used : ArchiveUsageRequestEvent(org.alien4cloud.tosca.catalog.events.ArchiveUsageRequestEvent) ServiceResource(alien4cloud.model.service.ServiceResource) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 25 with ServiceResource

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();
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Lists(org.elasticsearch.common.collect.Lists) Arrays(java.util.Arrays) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) Subject(alien4cloud.security.Subject) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ServiceResourceService(org.alien4cloud.alm.service.ServiceResourceService) ResourcePermissionService(alien4cloud.authorization.ResourcePermissionService) ApplicationEnvironmentAuthorizationDTO(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiOperation(io.swagger.annotations.ApiOperation) Audit(alien4cloud.audit.annotation.Audit) RestResponseBuilder(alien4cloud.rest.model.RestResponseBuilder) RestResponse(alien4cloud.rest.model.RestResponse) Application(alien4cloud.model.application.Application) Api(io.swagger.annotations.Api) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) MediaType(org.springframework.http.MediaType) Resource(javax.annotation.Resource) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) IGenericSearchDAO(alien4cloud.dao.IGenericSearchDAO) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) GroupDTO(alien4cloud.rest.orchestrator.model.GroupDTO) UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) ApplicationEnvironmentAuthorizationUpdateRequest(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest) ServiceResource(alien4cloud.model.service.ServiceResource) ApplicationEnvironmentAuthorizationDTO(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO) ServiceResource(alien4cloud.model.service.ServiceResource) List(java.util.List) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ServiceResource (alien4cloud.model.service.ServiceResource)29 ApiOperation (io.swagger.annotations.ApiOperation)9 List (java.util.List)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Audit (alien4cloud.audit.annotation.Audit)6 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)5 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)5 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)4 Application (alien4cloud.model.application.Application)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 EventListener (org.springframework.context.event.EventListener)3 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)2 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)2 Usage (alien4cloud.model.common.Usage)2 Deployment (alien4cloud.model.deployment.Deployment)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2