Search in sources :

Example 6 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class DefaultBlueprintCache method loadBlueprintsFromFile.

@PostConstruct
public void loadBlueprintsFromFile() {
    Map<String, Set<String>> blueprints = blueprints();
    for (Map.Entry<String, Set<String>> blueprintEntry : blueprints.entrySet()) {
        try {
            for (String blueprintText : blueprintEntry.getValue()) {
                String[] split = blueprintText.trim().split("=");
                if (blueprintUtils.isBlueprintNamePreConfigured(blueprintText, split)) {
                    LOGGER.debug("Load default validation '{}'.", AnonymizerUtil.anonymize(blueprintText));
                    BlueprintV4Request blueprintJson = new BlueprintV4Request();
                    blueprintJson.setName(split[0].trim());
                    JsonNode jsonNode = blueprintUtils.convertStringToJsonNode(blueprintUtils.readDefaultBlueprintFromFile(blueprintEntry.getKey(), split));
                    JsonNode blueprintNode = jsonNode.get("blueprint");
                    blueprintJson.setBlueprint(blueprintNode.toString());
                    Blueprint bp = converter.convert(blueprintJson);
                    JsonNode tags = jsonNode.get("tags");
                    Map<String, Object> tagParameters = blueprintUtils.prepareTags(tags);
                    bp.setTags(new Json(tagParameters));
                    JsonNode description = jsonNode.get("description");
                    bp.setDescription(description == null ? split[0] : description.asText(split[0]));
                    JsonNode blueprintUpgradeOption = blueprintNode.isMissingNode() ? null : blueprintNode.get("blueprintUpgradeOption");
                    bp.setBlueprintUpgradeOption(getBlueprintUpgradeOption(blueprintUpgradeOption));
                    BlueprintFile bpf = new BlueprintFile.Builder().name(bp.getName()).blueprintText(bp.getBlueprintText()).stackName(bp.getStackName()).stackVersion(bp.getStackVersion()).stackType(bp.getStackType()).blueprintUpgradeOption(bp.getBlueprintUpgradeOption()).hostGroupCount(bp.getHostGroupCount()).description(bp.getDescription()).build();
                    defaultBlueprints.put(bp.getName(), bpf);
                }
            }
        } catch (IOException e) {
            LOGGER.error("Can not read default validation from file: ", e);
        }
    }
}
Also used : Set(java.util.Set) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) JsonNode(com.fasterxml.jackson.databind.JsonNode) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) HashMap(java.util.HashMap) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Example 7 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class BlueprintV4RequestToBlueprintConverterTest method acceptsBuiltinClouderaManagerTemplate.

@Test
public void acceptsBuiltinClouderaManagerTemplate() {
    BlueprintV4Request request = new BlueprintV4Request();
    request.setBlueprint(FileReaderUtils.readFileFromClasspathQuietly("defaults/blueprints/7.2.12/cdp-sdx.bp"));
    Blueprint result = underTest.convert(request);
    assertNotNull(result);
    assertEquals("CDH", result.getStackType());
    assertEquals("7.2.12", result.getStackVersion());
    assertEquals(2, result.getHostGroupCount());
    assertNotNull(result.getBlueprintText());
    assertNotEquals("", result.getBlueprintText());
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Test(org.junit.Test) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)

Example 8 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class BlueprintV4RequestToBlueprintConverterTest method rejectsBuiltinWithInvalidContent.

@Test
public void rejectsBuiltinWithInvalidContent() {
    BlueprintV4Request request = new BlueprintV4Request();
    request.setBlueprint("{ \"blueprint\": { \"cdhVersion\": \"7.0.0\", { } }");
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("Invalid cluster template: Failed to parse JSON.");
    underTest.convert(request);
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Test(org.junit.Test) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)

Example 9 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class BlueprintV4RequestToBlueprintConverterTest method testConvertWhenUrlIsNotEmptyButInvalidThenExceptionWouldCome.

@Test
public void testConvertWhenUrlIsNotEmptyButInvalidThenExceptionWouldCome() {
    String wrongUrl = "some wrong content for url";
    BlueprintV4Request request = getRequest("blueprint.json");
    request.setUrl(wrongUrl);
    thrown.expect(BadRequestException.class);
    thrown.expectMessage(String.format("Cannot download cluster template from: %s", wrongUrl));
    underTest.convert(request);
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Test(org.junit.Test) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)

Example 10 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class BlueprintRequestTest method setUp.

@Before
public void setUp() {
    underTest = new BlueprintV4Request();
    localValidatorFactory = new LocalValidatorFactoryBean();
    localValidatorFactory.setProviderClass(HibernateValidator.class);
    localValidatorFactory.afterPropertiesSet();
}
Also used : LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean) BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Before(org.junit.Before)

Aggregations

BlueprintV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request)10 Test (org.junit.Test)7 AbstractJsonConverterTest (com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)5 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 BlueprintFile (com.sequenceiq.cloudbreak.domain.BlueprintFile)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Json (com.sequenceiq.cloudbreak.common.json.Json)1 CloudbreakApiException (com.sequenceiq.cloudbreak.json.CloudbreakApiException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 PostConstruct (javax.annotation.PostConstruct)1 Before (org.junit.Before)1 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)1