use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.
the class ImageChangeActions method setImageOnProvider.
@Bean(name = "SET_IMAGE_ON_PROVIDER_STATE")
public AbstractImageChangeAction<?> setImageOnProvider() {
return new AbstractImageChangeAction<>(StackEvent.class) {
@Inject
private ResourceService resourceService;
@Inject
private ResourceToCloudResourceConverter cloudResourceConverter;
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) throws Exception {
CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
Collection<Resource> resources = resourceService.findAllByStackId(context.getStack().getId());
List<CloudResource> cloudResources = resources.stream().map(resource -> cloudResourceConverter.convert(resource)).collect(Collectors.toList());
UpdateImageRequest<Selectable> request = new UpdateImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, cloudResources);
sendEvent(context, request);
}
@Override
protected Object getFailurePayload(StackEvent payload, Optional<StackContext> flowContext, Exception ex) {
LOGGER.error("[SET_IMAGE_ON_PROVIDER_STATE] failed", ex);
return new StackFailureEvent(IMAGE_CHANGE_FAILED_EVENT.event(), payload.getResourceId(), ex);
}
};
}
use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.
the class CloudResourceRetrieverServiceTest method testGetByResourceReferenceShouldReturnNOTEmptyList.
@Test
public void testGetByResourceReferenceShouldReturnNOTEmptyList() {
Resource resource = createResource();
CloudResource cloudResource = createCloudResource();
when(resourceService.findByResourceReferenceAndStatusAndTypeAndStack(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE, STACK_ID)).thenReturn(Optional.of(resource));
when(cloudResourceConverter.convert(resource)).thenReturn(cloudResource);
Optional<CloudResource> actual = underTest.findByResourceReferenceAndStatusAndTypeAndStack(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE, STACK_ID);
assertTrue(actual.isPresent());
assertEquals(cloudResource, actual.get());
verify(resourceService).findByResourceReferenceAndStatusAndTypeAndStack(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE, STACK_ID);
verify(cloudResourceConverter).convert(resource);
}
use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.
the class CloudResourceRetrieverServiceTest method createResource.
private Resource createResource() {
Resource resource = new Resource();
resource.setResourceName(RESOURCE);
return resource;
}
use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.
the class StackProvisionActions method provisioningFinishedAction.
@Bean(name = "PROVISIONING_FINISHED_STATE")
public Action<?, ?> provisioningFinishedAction() {
return new AbstractStackProvisionAction<>(LaunchStackResult.class) {
@Override
protected void doExecute(StackContext context, LaunchStackResult payload, Map<Object, Object> variables) {
Stack stack = stackProvisionService.provisioningFinished(context, payload, variables);
StackContext newContext = new StackContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
sendEvent(newContext);
}
@Override
protected Selectable createRequest(StackContext context) {
List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(context.getStack());
List<Resource> resources = resourceService.findAllByStackId(context.getStack().getId());
List<CloudResource> cloudResources = resources.stream().map(r -> resourceConverter.convert(r)).collect(Collectors.toList());
return new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances, cloudInstances);
}
};
}
use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.
the class AbstractStackTerminationAction method createFlowContext.
@Override
protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
CloudCredential cloudCredential = credentialConverter.convert(credential);
CloudStack cloudStack = cloudStackConverter.convert(stack);
List<Resource> resourceList = resourceService.findAllByStackId(stack.getId());
List<CloudResource> resources = resourceList.stream().map(r -> resourceConverter.convert(r)).collect(Collectors.toList());
return new StackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources);
}
Aggregations