use of com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest in project cloudbreak by hortonworks.
the class UpdateUserDataOnProviderHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<UserDataUpdateOnProviderRequest> event) {
UserDataUpdateOnProviderRequest request = event.getData();
try {
LOGGER.info("Updating userData on cloud provider side...");
CloudConnector<?> connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
AuthenticatedContext auth = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
CloudStack stack = request.getCloudStack();
connector.resources().updateUserData(auth, stack, request.getCloudResources(), request.getUserData());
return new UserDataUpdateOnProviderResult(request.getResourceId());
} catch (Exception e) {
LOGGER.error("Updating user data on provider side has failed", e);
return new UserDataUpdateFailed(UPDATE_USERDATA_FAILED_EVENT.event(), request.getResourceId(), e);
}
}
use of com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest 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());
}
};
}
Aggregations