use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.
the class UserDataUpdateActions method updateUserDataOnProviderSide.
@Bean(name = "UPDATE_USERDATA_ON_PROVIDER_STATE")
public AbstractUserDataUpdateAction<?> updateUserDataOnProviderSide() {
return new AbstractUserDataUpdateAction<>(UserDataUpdateSuccess.class) {
@Override
protected void doExecute(StackContext context, UserDataUpdateSuccess payload, Map<Object, Object> variables) {
sendEvent(context);
}
@Override
protected Selectable createRequest(StackContext context) {
Stack stack = context.getStack();
String userData = stack.getImage().getUserdata();
List<CloudResource> cloudResources = getCloudResources(stack.getId());
return new UserDataUpdateOnProviderRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), cloudResources, userData);
}
@Override
protected Object getFailurePayload(UserDataUpdateSuccess payload, Optional<StackContext> flowContext, Exception ex) {
return new UserDataUpdateFailed(UPDATE_USERDATA_FAILED_EVENT.event(), payload.getResourceId(), ex);
}
private List<CloudResource> getCloudResources(Long stackId) {
List<Resource> resources = resourceService.findAllByStackId(stackId);
return resources.stream().map(r -> resourceToCloudResourceConverter.convert(r)).collect(Collectors.toList());
}
};
}
use of com.sequenceiq.freeipa.entity.Resource 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 = cloudResourceToResourceConverter.convert(cloudResource);
Optional<Resource> persistedResource = getPersistedResource(stackId, cloudResource);
if (persistedResource.isPresent()) {
LOGGER.debug("Trying to persist a resource (name: {}, type: {}, stackId: {}) that is already persisted, skipping..", cloudResource.getName(), cloudResource.getType().name(), stackId);
return notification;
}
setStack(stackId, cloudResource, resource);
resourceService.save(resource);
return notification;
}
use of com.sequenceiq.freeipa.entity.Resource 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();
Resource persistedResource = getPersistedResource(stackId, cloudResource).orElseThrow(notFound("resource", cloudResource.getName()));
Resource resource = cloudResourceToResourceConverter.convert(cloudResource);
updateWithPersistedFields(resource, persistedResource);
setStack(stackId, cloudResource, resource);
resourceService.save(resource);
return notification;
}
use of com.sequenceiq.freeipa.entity.Resource 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();
Optional<Resource> persistedResource = getPersistedResource(stackId, cloudResource);
persistedResource.ifPresent(value -> resourceService.delete(value));
return notification;
}
Aggregations