Search in sources :

Example 1 with StackAuthenticationView

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);
}
Also used : StackAuthentication(com.sequenceiq.freeipa.entity.StackAuthentication) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) NotFoundException(javax.ws.rs.NotFoundException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) StackAuthenticationView(com.sequenceiq.freeipa.entity.projection.StackAuthenticationView) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)1 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 StackAuthentication (com.sequenceiq.freeipa.entity.StackAuthentication)1 Template (com.sequenceiq.freeipa.entity.Template)1 StackAuthenticationView (com.sequenceiq.freeipa.entity.projection.StackAuthenticationView)1 HashMap (java.util.HashMap)1 NotFoundException (javax.ws.rs.NotFoundException)1