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