Search in sources :

Example 11 with Resource

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());
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) UserDataUpdateOnProviderRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) LoggerFactory(org.slf4j.LoggerFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) Inject(javax.inject.Inject) UserDataUpdateFailed(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) UserDataUpdateRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Set(java.util.Set) UpdateUserDataEvents(com.sequenceiq.freeipa.flow.stack.update.UpdateUserDataEvents) Collectors(java.util.stream.Collectors) UPDATE_USERDATA_FAILED_EVENT(com.sequenceiq.freeipa.flow.stack.update.UpdateUserDataEvents.UPDATE_USERDATA_FAILED_EVENT) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Configuration(org.springframework.context.annotation.Configuration) UserDataUpdateOnProviderResult(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderResult) List(java.util.List) UserDataUpdateSuccess(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) Optional(java.util.Optional) UserDataUpdateOnProviderRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) UserDataUpdateSuccess(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess) Stack(com.sequenceiq.freeipa.entity.Stack) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) UserDataUpdateFailed(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 12 with Resource

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;
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 13 with Resource

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;
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 14 with Resource

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;
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)14 Resource (com.sequenceiq.freeipa.entity.Resource)14 ResourceToCloudResourceConverter (com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter)7 ResourceService (com.sequenceiq.freeipa.service.resource.ResourceService)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Inject (javax.inject.Inject)7 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)6 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)6 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)6 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)6 Map (java.util.Map)6 Bean (org.springframework.context.annotation.Bean)6 Configuration (org.springframework.context.annotation.Configuration)6 Action (org.springframework.statemachine.action.Action)6 FlowParameters (com.sequenceiq.flow.core.FlowParameters)5 CollectMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest)4 CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)4 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)4