use of com.sequenceiq.freeipa.entity.projection.StackAuthenticationView in project cloudbreak by hortonworks.
the class InstanceMetaDataToCloudInstanceConverter method convert.
public CloudInstance convert(InstanceMetaData metaDataEntity) {
InstanceGroup group = metaDataEntity.getInstanceGroup();
Optional<StackAuthenticationView> stackAuthenticationView = instanceMetaDataService.getStackAuthenticationViewByInstanceMetaDataId(metaDataEntity.getId());
Template template = metaDataEntity.getInstanceGroup().getTemplate();
Optional<StackAuthentication> stackAuthentication = stackAuthenticationView.map(StackAuthenticationView::getStackAuthentication);
InstanceStatus status = getInstanceStatus(metaDataEntity);
String imageId = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackId -> imageService.getByStackId(stackId)).map(ImageEntity::getImageName).orElse(null);
InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEntity.getPrivateId(), status, imageId);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.map(StackAuthentication::getPublicKey).orElse(null), stackAuthentication.map(StackAuthentication::getPublicKeyId).orElse(null), stackAuthentication.map(StackAuthentication::getLoginUserName).orElse(null));
Map<String, Object> params = new HashMap<>();
params.put(SUBNET_ID, metaDataEntity.getSubnetId());
params.put(CloudInstance.INSTANCE_NAME, metaDataEntity.getInstanceName());
Stack stack = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackService::getStackById).orElseThrow(NotFoundException::new);
Map<String, Object> cloudInstanceParameters = stackToCloudStackConverter.buildCloudInstanceParameters(stack.getEnvironmentCrn(), metaDataEntity);
params.putAll(cloudInstanceParameters);
return new CloudInstance(metaDataEntity.getInstanceId(), instanceTemplate, instanceAuthentication, metaDataEntity.getSubnetId(), stack.getAvailabilityZone(), params);
}
Aggregations