use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class UnhealthyInstancesFinalizer method finalizeUnhealthyInstances.
public Set<String> finalizeUnhealthyInstances(Stack stack, Iterable<InstanceMetaData> candidateUnhealthyInstances) {
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
List<CloudInstance> cloudInstances = cloudInstanceConverter.convert(candidateUnhealthyInstances);
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses(cloudCredential, cloudContext, cloudInstances);
Map<String, CloudVmInstanceStatus> cloudVmInstanceStatusesById = new HashMap<>();
cloudVmInstanceStatuses.forEach(c -> cloudVmInstanceStatusesById.put(c.getCloudInstance().getInstanceId(), c));
Set<String> unhealthyInstances = new HashSet<>();
for (InstanceMetaData i : candidateUnhealthyInstances) {
CloudVmInstanceStatus instanceStatus = cloudVmInstanceStatusesById.get(i.getInstanceId());
if ((instanceStatus == null) || (instanceStatus.getStatus().equals(InstanceStatus.TERMINATED))) {
unhealthyInstances.add(i.getInstanceId());
}
}
return unhealthyInstances;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class StackCommonService method validate.
@Override
public Response validate(StackValidationRequest request) {
StackValidation stackValidation = conversionService.convert(request, StackValidation.class);
stackService.validateStack(stackValidation, true);
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(stackValidation.getCredential());
fileSystemValidator.validateFileSystem(request.getPlatform(), cloudCredential, request.getFileSystem());
return Response.status(Status.NO_CONTENT).build();
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class AbstractStackCreationAction method createFlowContext.
@Override
protected StackContext createFlowContext(String flowId, StateContext<StackCreationState, StackCreationEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithLists(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
CloudStack cloudStack = cloudStackConverter.convert(stack);
return new StackContext(flowId, stack, cloudContext, cloudCredential, cloudStack);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class UnhealthyInstancesFinalizerTest method shouldFinalizeInstancesThatAreNotFound.
@Test
public void shouldFinalizeInstancesThatAreNotFound() {
Stack stack = TestUtil.stack(Status.AVAILABLE, TestUtil.awsCredential());
CloudCredential cloudCredential = mock(CloudCredential.class);
when(credentialConverter.convert(stack.getCredential())).thenReturn(cloudCredential);
String instanceId1 = "i-0f1e0605506aaaaaa";
String instanceId2 = "i-0f1e0605506bbbbbb";
Set<InstanceMetaData> candidateUnhealthyInstances = new HashSet<>();
setupInstanceMetaData(instanceId1, candidateUnhealthyInstances);
setupInstanceMetaData(instanceId2, candidateUnhealthyInstances);
List<CloudInstance> cloudInstances = new ArrayList<>();
CloudInstance cloudInstance1 = setupCloudInstance(instanceId1, cloudInstances);
when(cloudInstanceConverter.convert(candidateUnhealthyInstances)).thenReturn(cloudInstances);
List<CloudVmInstanceStatus> cloudVmInstanceStatusList = new ArrayList<>();
setupCloudVmInstanceStatus(cloudInstance1, InstanceStatus.TERMINATED, cloudVmInstanceStatusList);
when(instanceStateQuery.getCloudVmInstanceStatuses(eq(cloudCredential), any(CloudContext.class), eq(cloudInstances))).thenReturn(cloudVmInstanceStatusList);
Set<String> unhealthyInstances = underTest.finalizeUnhealthyInstances(stack, candidateUnhealthyInstances);
assertEquals(2, unhealthyInstances.size());
assertTrue(unhealthyInstances.contains(instanceId1));
assertTrue(unhealthyInstances.contains(instanceId2));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method getPlatformParameters.
public PlatformParameters getPlatformParameters(Stack stack) {
LOGGER.debug("Get platform parameters for: {}", stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
PlatformParameterRequest parameterRequest = new PlatformParameterRequest(cloudContext, cloudCredential);
eventBus.notify(parameterRequest.selector(), eventFactory.createEvent(parameterRequest));
try {
PlatformParameterResult res = parameterRequest.await();
LOGGER.info("Platform parameter result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to get platform parameters", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return res.getPlatformParameters();
} catch (InterruptedException e) {
LOGGER.error("Error while getting platform parameters: " + cloudContext, e);
throw new OperationException(e);
}
}
Aggregations