Search in sources :

Example 1 with CloudbreakImageNotFoundException

use of com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException in project cloudbreak by hortonworks.

the class ClusterCreationSetupService method getVDFUrlByOsType.

private Optional<String> getVDFUrlByOsType(Long stackId, StackRepoDetails stackRepoDetails) {
    String vdfStackRepoKeyFilter = VDF_REPO_KEY_PREFIX;
    try {
        Image image = componentConfigProvider.getImage(stackId);
        if (!StringUtils.isEmpty(image.getOsType())) {
            vdfStackRepoKeyFilter += image.getOsType();
        }
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.error(String.format("Could not get Image Component for stack: '%s'.", stackId), e);
    }
    String filter = vdfStackRepoKeyFilter;
    return stackRepoDetails.getStack().entrySet().stream().filter(entry -> entry.getKey().startsWith(filter)).map(Entry::getValue).findFirst();
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image)

Example 2 with CloudbreakImageNotFoundException

use of com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException in project cloudbreak by hortonworks.

the class ComponentConfigProvider method getImage.

public Image getImage(Long stackId) throws CloudbreakImageNotFoundException {
    try {
        Component component = getComponent(stackId, ComponentType.IMAGE, ComponentType.IMAGE.name());
        if (component == null) {
            throw new CloudbreakImageNotFoundException(String.format("Image not found: stackId: %d, componentType: %s, name: %s", stackId, ComponentType.IMAGE.name(), ComponentType.IMAGE.name()));
        }
        LOGGER.debug("Image found! stackId: {}, component: {}", stackId, component);
        return component.getAttributes().get(Image.class);
    } catch (IOException e) {
        throw new CloudbreakServiceException("Failed to read image", e);
    }
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) IOException(java.io.IOException) Component(com.sequenceiq.cloudbreak.domain.Component)

Example 3 with CloudbreakImageNotFoundException

use of com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException in project cloudbreak by hortonworks.

the class StackCreationActions method prepareImageAction.

@Bean(name = "IMAGESETUP_STATE")
public Action<?, ?> prepareImageAction() {
    return new AbstractStackCreationAction<SetupResult>(SetupResult.class) {

        @Override
        protected void doExecute(StackContext context, SetupResult payload, Map<Object, Object> variables) {
            stackCreationService.prepareImage(context.getStack());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            try {
                CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
                Image image = imageService.getImage(context.getCloudContext().getId());
                return new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
            } catch (CloudbreakImageNotFoundException e) {
                throw new CloudbreakServiceException(e);
            }
        }
    };
}
Also used : SetupResult(com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Map(java.util.Map) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Bean(org.springframework.context.annotation.Bean)

Example 4 with CloudbreakImageNotFoundException

use of com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException in project cloudbreak by hortonworks.

the class StackCreationService method checkImage.

public CheckImageResult checkImage(StackContext context) {
    try {
        Stack stack = context.getStack();
        Image image = imageService.getImage(stack.getId());
        CheckImageRequest<CheckImageResult> checkImageRequest = new CheckImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStackConverter.convert(stack), image);
        LOGGER.info("Triggering event: {}", checkImageRequest);
        eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
        CheckImageResult result = checkImageRequest.await();
        sendNotification(result, stack);
        LOGGER.info("Result: {}", result);
        return result;
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing check image", e);
        throw new OperationException(e);
    } catch (CloudbreakImageNotFoundException e) {
        throw new CloudbreakServiceException(e);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Stack(com.sequenceiq.cloudbreak.domain.Stack) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest)

Example 5 with CloudbreakImageNotFoundException

use of com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException in project cloudbreak by hortonworks.

the class StackService method create.

@Transactional(TxType.NEVER)
public Stack create(IdentityUser user, Stack stack, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) {
    Stack savedStack;
    stack.setOwner(user.getUserId());
    stack.setAccount(user.getAccount());
    stack.setGatewayPort(nginxPort);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    try {
        if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
            long start = System.currentTimeMillis();
            rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
            LOGGER.info("RSA key has been validated in {} ms fot stack {}", System.currentTimeMillis() - start, stackName);
        }
        if (stack.getOrchestrator() != null) {
            orchestratorRepository.save(stack.getOrchestrator());
        }
        stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
        long start = System.currentTimeMillis();
        String template = connector.getTemplate(stack);
        LOGGER.info("Get cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        savedStack = stackRepository.save(stack);
        LOGGER.info("Stackrepository save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addTemplateForStack(stack, template);
        LOGGER.info("Save cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addCloudbreakDetailsForStack(stack);
        LOGGER.info("Add Cloudbreak template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        MDCBuilder.buildMdcContext(savedStack);
        start = System.currentTimeMillis();
        instanceGroupRepository.save(savedStack.getInstanceGroups());
        LOGGER.info("Instance groups saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        SecurityConfig securityConfig = tlsSecurityService.storeSSHKeys();
        LOGGER.info("Generating SSH keys took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        securityConfig.setSaltPassword(PasswordUtil.generatePassword());
        securityConfig.setSaltBootPassword(PasswordUtil.generatePassword());
        securityConfig.setKnoxMasterSecret(PasswordUtil.generatePassword());
        LOGGER.info("Generating salt passwords took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        securityConfig.setStack(stack);
        start = System.currentTimeMillis();
        securityConfigRepository.save(securityConfig);
        LOGGER.info("Security config save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        savedStack.setSecurityConfig(securityConfig);
        start = System.currentTimeMillis();
        imageService.create(savedStack, connector.getPlatformParameters(stack), imageCatalog, imageId, blueprint);
        LOGGER.info("Image creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.error("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.error("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    return savedStack;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) Stack(com.sequenceiq.cloudbreak.domain.Stack) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Transactional(javax.transaction.Transactional)

Aggregations

CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)11 Image (com.sequenceiq.cloudbreak.cloud.model.Image)7 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)2 ClusterResponse (com.sequenceiq.cloudbreak.api.model.ClusterResponse)1 CredentialResponse (com.sequenceiq.cloudbreak.api.model.CredentialResponse)1 FailurePolicyResponse (com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse)1 ImageJson (com.sequenceiq.cloudbreak.api.model.ImageJson)1 InstanceGroupResponse (com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse)1 NetworkResponse (com.sequenceiq.cloudbreak.api.model.NetworkResponse)1 OrchestratorResponse (com.sequenceiq.cloudbreak.api.model.OrchestratorResponse)1 StackAuthenticationResponse (com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse)1 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)1 ImageSettings (com.sequenceiq.cloudbreak.api.model.v2.ImageSettings)1 CheckImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest)1 CheckImageResult (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)1 PrepareImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)1 SetupResult (com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult)1 AmbariRepo (com.sequenceiq.cloudbreak.cloud.model.AmbariRepo)1