Search in sources :

Example 1 with ResourceRepository

use of com.sequenceiq.cloudbreak.repository.ResourceRepository in project cloudbreak by hortonworks.

the class CloudResourcePersisterService method delete.

@Override
public ResourceNotification delete(ResourceNotification notification) {
    LOGGER.debug("Resource deletion notification received: {}", notification);
    Long stackId = notification.getCloudContext().getId();
    CloudResource cloudResource = notification.getCloudResource();
    ResourceRepository repository = getResourceRepository();
    Resource resource = repository.findByStackIdAndNameAndType(stackId, cloudResource.getName(), cloudResource.getType());
    if (resource != null) {
        repository.delete(resource);
    }
    return notification;
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourceRepository(com.sequenceiq.cloudbreak.repository.ResourceRepository)

Example 2 with ResourceRepository

use of com.sequenceiq.cloudbreak.repository.ResourceRepository in project cloudbreak by hortonworks.

the class CloudResourcePersisterService method persist.

@Override
public ResourceNotification persist(ResourceNotification notification) {
    LOGGER.debug("Resource allocation notification received: {}", notification);
    Long stackId = notification.getCloudContext().getId();
    CloudResource cloudResource = notification.getCloudResource();
    Resource resource = getConversionService().convert(cloudResource, Resource.class);
    ResourceRepository resourceRepository = getResourceRepository();
    Resource persistedResource = resourceRepository.findByStackIdAndNameAndType(stackId, cloudResource.getName(), cloudResource.getType());
    if (persistedResource != null) {
        LOGGER.warn("Trying to persist a resource (name: {}, type: {}, stackId: {}) that is already persisted, skipping..", cloudResource.getName(), cloudResource.getType().name(), stackId);
        return notification;
    }
    resource.setStack(getStackRepository().findOne(stackId));
    resourceRepository.save(resource);
    return notification;
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourceRepository(com.sequenceiq.cloudbreak.repository.ResourceRepository)

Example 3 with ResourceRepository

use of com.sequenceiq.cloudbreak.repository.ResourceRepository in project cloudbreak by hortonworks.

the class CloudResourcePersisterService method update.

@Override
public ResourceNotification update(ResourceNotification notification) {
    LOGGER.debug("Resource update notification received: {}", notification);
    Long stackId = notification.getCloudContext().getId();
    CloudResource cloudResource = notification.getCloudResource();
    ResourceRepository repository = getResourceRepository();
    Resource persistedResource = repository.findByStackIdAndNameAndType(stackId, cloudResource.getName(), cloudResource.getType());
    Resource resource = getConversionService().convert(cloudResource, Resource.class);
    updateWithPersistedFields(resource, persistedResource);
    resource.setStack(getStackRepository().findOne(stackId));
    repository.save(resource);
    return notification;
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourceRepository(com.sequenceiq.cloudbreak.repository.ResourceRepository)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 Resource (com.sequenceiq.cloudbreak.domain.Resource)3 ResourceRepository (com.sequenceiq.cloudbreak.repository.ResourceRepository)3