use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.
the class RebootActions method rebootAction.
@Bean(name = "REBOOT_STATE")
public Action<?, ?> rebootAction() {
return new AbstractRebootAction<>(RebootInstanceEvent.class) {
@Override
protected void doExecute(RebootContext context, RebootInstanceEvent payload, Map<Object, Object> variables) {
setOperationId(variables, payload.getOperationId());
LOGGER.info("Starting reboot for {}", context.getInstanceIds());
rebootService.startInstanceReboot(context);
sendEvent(context);
}
@Override
protected Object getFailurePayload(RebootInstanceEvent payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected Selectable createRequest(RebootContext context) {
List<CloudInstance> cloudInstances = context.getInstanceMetaDataList().stream().map(instanceMetaData -> instanceMetaDataToCloudInstanceConverter.convert(instanceMetaData)).collect(Collectors.toList());
List<CloudResource> cloudResources = getCloudResources(context.getStack().getId());
return new RebootInstancesRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, RebootInstanceEvent payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getStackById(stackId);
MDCBuilder.buildMdcContext(stack);
List<InstanceMetaData> instances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(instanceMetaData -> payload.getInstanceIds().contains(instanceMetaData.getInstanceId())).collect(Collectors.toList());
CloudContext cloudContext = getCloudContext(stack);
Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
CloudCredential cloudCredential = credentialConverter.convert(credential);
return new RebootContext(flowParameters, stack, instances, cloudContext, cloudCredential);
}
};
}
use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.
the class RebootActions method rebootWaitUntilAvailableAction.
@Bean(name = "REBOOT_WAIT_UNTIL_AVAILABLE_STATE")
public Action<?, ?> rebootWaitUntilAvailableAction() {
return new AbstractRebootAction<>(RebootInstancesResult.class) {
@Override
protected void doExecute(RebootContext context, RebootInstancesResult payload, Map<Object, Object> variables) {
LOGGER.info("Starting reboot polling FreeIpa until it is available for {}", context.getInstanceIds());
rebootService.waitForAvailableStatus(context);
sendEvent(context);
}
@Override
protected Object getFailurePayload(RebootInstancesResult payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected Selectable createRequest(RebootContext context) {
return new HealthCheckRequest(context.getStack().getId(), true, context.getInstanceIdList());
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, RebootInstancesResult payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getStackById(stackId);
MDCBuilder.buildMdcContext(stack);
List<InstanceMetaData> instances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(instanceMetaData -> payload.getInstanceIds().contains(instanceMetaData.getInstanceId())).collect(Collectors.toList());
CloudContext cloudContext = getCloudContext(stack);
Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
CloudCredential cloudCredential = credentialConverter.convert(credential);
return new RebootContext(flowParameters, stack, instances, cloudContext, cloudCredential);
}
};
}
use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.
the class AbstractStackStartAction method createFlowContext.
@Override
protected StackStartContext createFlowContext(FlowParameters flowParameters, StateContext<StackStartState, StackStartEvent> stateContext, P payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
MDCBuilder.buildMdcContext(stack);
List<InstanceMetaData> instances = stack.getNotDeletedInstanceMetaDataList();
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);
return new StackStartContext(flowParameters, stack, instances, cloudContext, cloudCredential);
}
use of com.sequenceiq.freeipa.dto.Credential 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);
}
use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.
the class NetworkServiceTest method testFiltering.
@Test
public void testFiltering() {
Stack stack = new Stack();
stack.setCloudPlatform(PLATFORM);
stack.setRegion(REGION);
stack.setPlatformvariant(PLATFORM);
Credential credential = new Credential(PLATFORM, "", "", "", "acc");
ExtendedCloudCredential extendedCred = new ExtendedCloudCredential(new CloudCredential(), PLATFORM, "", "", "", new ArrayList<>());
CloudSubnet subnet1 = new CloudSubnet(SUBNET_1, SUBNET_1, "", "10.1.0.0/24");
CloudSubnet subnet2 = new CloudSubnet(SUBNET_2, SUBNET_2, "", "10.1.1.0/24");
CloudSubnet subnet3 = new CloudSubnet("indifferent", "indifferent", "", "10.1.2.0/24");
CloudNetwork cloudNetwork1 = new CloudNetwork(NETWORK_ID, NETWORK_ID, Set.of(subnet1, subnet2, subnet3), Map.of());
CloudNetwork cloudNetwork2 = new CloudNetwork("other", "other", Set.of(new CloudSubnet(SUBNET_1, SUBNET_1), new CloudSubnet("test", "test")), Map.of());
Map<String, Set<CloudNetwork>> cloudNets = Map.of(REGION, Set.of(cloudNetwork1, cloudNetwork2));
CloudNetworks cloudNetworks = new CloudNetworks(cloudNets);
when(credentialService.getCredentialByEnvCrn(ENV_CRN)).thenReturn(credential);
when(extendedCloudCredentialConverter.convert(credential)).thenReturn(extendedCred);
when(cloudParameterService.getCloudNetworks(eq(extendedCred), eq(REGION), eq(PLATFORM), any())).thenReturn(cloudNetworks);
when(networkFilterProviderMap.get(any())).thenReturn(null);
Multimap<String, String> filteredSubnetWithCidr = underTest.getFilteredSubnetWithCidr(ENV_CRN, stack, NETWORK_ID, List.of(SUBNET_1, SUBNET_2));
assertEquals(2, filteredSubnetWithCidr.size());
assertEquals(1, filteredSubnetWithCidr.get(subnet1.getId()).size());
assertEquals(subnet1.getCidr(), filteredSubnetWithCidr.get(subnet1.getId()).stream().findFirst().get());
assertEquals(1, filteredSubnetWithCidr.get(subnet2.getId()).size());
assertEquals(subnet2.getCidr(), filteredSubnetWithCidr.get(subnet2.getId()).stream().findFirst().get());
}
Aggregations