Package com.sequenceiq.cloudbreak.domain

Examples of com.sequenceiq.cloudbreak.domain.Blueprint


        return blueprintJson;
    }

    @Override
    public Blueprint convert(BlueprintJson json) {
        Blueprint blueprint = new Blueprint();
        if (json.getUrl() != null && !json.getUrl().isEmpty()) {
            String sourceUrl = json.getUrl().trim();
            try {
                String urlText = readUrl(sourceUrl);
                jsonHelper.createJsonFromString(urlText);
                blueprint.setBlueprintText(urlText);
            } catch (Exception e) {
                throw new BadRequestException("Cannot download ambari blueprint from: " + sourceUrl, e);
            }
        } else {
            blueprint.setBlueprintText(json.getAmbariBlueprint());
        }

        validateBlueprint(blueprint.getBlueprintText());

        blueprint.setName(json.getName());
        blueprint.setDescription(json.getDescription());
        ObjectMapper mapper = new ObjectMapper();
        try {
            JsonNode root = mapper.readTree(blueprint.getBlueprintText());
            int hostGroupCount = 0;
            blueprint.setBlueprintName(root.get("Blueprints").get("blueprint_name").asText());
            Iterator<JsonNode> hostGroups = root.get("host_groups").elements();
            while (hostGroups.hasNext()) {
                hostGroups.next();
                hostGroupCount++;
            }
            blueprint.setHostGroupCount(hostGroupCount);
        } catch (IOException e) {
            throw new BadRequestException("Invalid Blueprint: Failed to parse JSON.", e);
        }

        return blueprint;
View Full Code Here


        }
    }

    @Override
    public Blueprint get(Long id) {
        Blueprint blueprint = blueprintRepository.findOne(id);
        if (blueprint == null) {
            throw new NotFoundException(String.format("Blueprint '%s' not found.", id));
        }
        return blueprint;
    }
View Full Code Here

    @Override
    public Blueprint create(CbUser user, Blueprint blueprint) {
        MDCBuilder.buildMdcContext(blueprint);
        LOGGER.debug("Creating blueprint: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
        Blueprint savedBlueprint = null;
        blueprint.setOwner(user.getUserId());
        blueprint.setAccount(user.getAccount());
        try {
            savedBlueprint = blueprintRepository.save(blueprint);
            websocketService.sendToTopicUser(user.getUsername(), WebsocketEndPoint.BLUEPRINT,
                    new StatusMessage(savedBlueprint.getId(), savedBlueprint.getName(), Status.AVAILABLE.name()));
        } catch (DataIntegrityViolationException ex) {
            throw new DuplicateKeyValueException(blueprint.getName(), ex);
        }
        return savedBlueprint;
    }
View Full Code Here

        return savedBlueprint;
    }

    @Override
    public void delete(Long id) {
        Blueprint blueprint = blueprintRepository.findOne(id);
        MDCBuilder.buildMdcContext(blueprint);
        if (blueprint == null) {
            throw new NotFoundException(String.format("Blueprint '%s' not found.", id));
        }
        if (clusterRepository.findAllClusterByBlueprint(blueprint.getId()).isEmpty()) {

            blueprintRepository.delete(blueprint);
            websocketService.sendToTopicUser(blueprint.getOwner(), WebsocketEndPoint.BLUEPRINT,
                    new StatusMessage(blueprint.getId(), blueprint.getName(), Status.DELETE_COMPLETED.name()));
        } else {
            throw new BadRequestException(String.format(
                    "There are stacks associated with blueprint '%s'. Please remove these before the deleting the blueprint.", id));
        }
    }
View Full Code Here

                blueprintJson.setName(blueprintName);
                blueprintJson.setDescription(blueprintName);
                blueprintJson.setAmbariBlueprint(
                        jsonHelper.createJsonFromString(FileReaderUtils.readFileFromClasspath(String.format("blueprints/%s.bp", blueprintName))));

                Blueprint bp = blueprintConverter.convert(blueprintJson);
                MDCBuilder.buildMdcContext(bp);
                bp.setOwner(user.getUserId());
                blueprints.add(bp);
            } catch (IOException e) {
                MDCBuilder.buildMdcContext();
                LOGGER.error("Blueprint is not available for '{}' user.", e, user);
            }
View Full Code Here

    }

    @RequestMapping(value = "blueprints/{id}", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<BlueprintJson> getBlueprint(@ModelAttribute("user") CbUser user, @PathVariable Long id) {
        Blueprint blueprint = blueprintService.get(id);
        return new ResponseEntity<>(blueprintConverter.convert(blueprint), HttpStatus.OK);
    }
View Full Code Here

        blueprintService.delete(id);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    private ResponseEntity<IdJson> createBlueprint(CbUser user, BlueprintJson blueprintRequest, Boolean publicInAccount) {
        Blueprint blueprint = blueprintConverter.convert(blueprintRequest);
        blueprint.setPublicInAccount(publicInAccount);
        blueprint = blueprintService.create(user, blueprint);
        return new ResponseEntity<>(new IdJson(blueprint.getId()), HttpStatus.CREATED);
    }
View Full Code Here

    @Before
    public void setUp() {
        underTest = new ClusterConverter();
        MockitoAnnotations.initMocks(this);
        blueprint = new Blueprint();
        blueprint.setId(1L);
        cluster = createCluster();
        clusterRequest = createClusterRequest();
    }
View Full Code Here

    private Cluster createCluster() {
        Cluster cluster = new Cluster();
        cluster.setId(1L);
        cluster.setName("dummyCluster");
        Blueprint blueprint = new Blueprint();
        blueprint.setId(1L);
        cluster.setBlueprint(blueprint);
        return cluster;
    }
View Full Code Here

        // GIVEN
        given(jsonNode.toString()).willReturn(DUMMY_BLUEPRINT_TEXT);
        blueprintJson.setAmbariBlueprint(jsonNode);
        blueprintJson.setUrl(null);
        // WHEN
        Blueprint result = underTest.convert(blueprintJson);
        // THEN
        assertEquals(result.getBlueprintText(), blueprintJson.getAmbariBlueprint());
        assertEquals(result.getHostGroupCount(), 2);
    }
View Full Code Here

TOP

Related Classes of com.sequenceiq.cloudbreak.domain.Blueprint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.