Search in sources :

Example 1 with BlueprintFile

use of com.sequenceiq.cloudbreak.domain.BlueprintFile in project cloudbreak by hortonworks.

the class BlueprintLoaderServiceTest method testForTheSpecifiedUserWhenNewDefaultsExistAndNONeedsToRetireOldBlueprintsThenRepositoryShouldUpdateAddTwoNewAndReturnWithFive.

@Test
public void testForTheSpecifiedUserWhenNewDefaultsExistAndNONeedsToRetireOldBlueprintsThenRepositoryShouldUpdateAddTwoNewAndReturnWithFive() {
    Set<ClusterTemplate> notEmptyClusterTemplateList = Sets.newHashSet(new ClusterTemplate());
    // We have a0, a1, a2 in the DB
    Set<Blueprint> blueprints = generateBlueprintData(3, BlueprintUpgradeOption.ENABLED);
    // We have a2, a3, a4 as defaults
    Map<String, BlueprintFile> defaultBlueprints = generateCacheData(3, 2, BlueprintUpgradeOption.ENABLED);
    setupMock(defaultBlueprints);
    when(clusterTemplateService.getTemplatesByBlueprint(any(Blueprint.class))).thenReturn(notEmptyClusterTemplateList);
    Collection<Blueprint> resultSet = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.loadBlueprintsForTheWorkspace(blueprints, workspace, this::mockSave));
    ArgumentCaptor<Iterable<Blueprint>> argument = ArgumentCaptor.forClass(Iterable.class);
    verify(blueprintService).pureSaveAll(argument.capture());
    verify(blueprintService, times(1)).pureSaveAll(any(Iterable.class));
    Assert.assertEquals(0, Iterators.size(argument.getValue().iterator()));
    Assert.assertEquals(5L, resultSet.size());
    Assert.assertTrue(CollectionUtils.isEqualCollection(Sets.newHashSet("multi-node-hdfs-yarn0", "multi-node-hdfs-yarn1", "multi-node-hdfs-yarn2"), collectBpNames(blueprints)));
    Assert.assertTrue(CollectionUtils.isEqualCollection(Sets.newHashSet("multi-node-hdfs-yarn2", "multi-node-hdfs-yarn3", "multi-node-hdfs-yarn4"), defaultBlueprints.keySet()));
    Assert.assertTrue(CollectionUtils.isEqualCollection(Sets.newHashSet("multi-node-hdfs-yarn0", "multi-node-hdfs-yarn1", "multi-node-hdfs-yarn2", "multi-node-hdfs-yarn3", "multi-node-hdfs-yarn4"), collectBpNames(resultSet)));
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) Test(org.junit.Test)

Example 2 with BlueprintFile

use of com.sequenceiq.cloudbreak.domain.BlueprintFile in project cloudbreak by hortonworks.

the class DefaulBlueprintCacheTest method testOnlyReleasedBps.

@Test
public void testOnlyReleasedBps() throws IOException {
    // GIVEN
    Blueprint bp1 = new Blueprint();
    bp1.setName("bp1");
    bp1.setBlueprintText("txt");
    bp1.setStackName("stckn");
    bp1.setStackType("stckt");
    bp1.setStackVersion("stckv");
    String bp1JsonString = "{\"inputs\":[],\"blueprint\":{\"Blueprints\":{\"blueprint_name\":\"bp1\"}}}";
    JsonNode bpText1 = JsonUtil.readTree(bp1JsonString);
    when(blueprintUtils.convertStringToJsonNode(any())).thenReturn(bpText1);
    Blueprint bp2 = new Blueprint();
    bp2.setName("bp2");
    bp2.setBlueprintText("txt");
    bp2.setStackName("stckn");
    bp2.setStackType("stckt");
    bp2.setStackVersion("stckv");
    String bp2JsonString = "{\"inputs\":[],\"blueprint\":{\"Blueprints\":{\"blueprint_name\":\"bp2\"}}}";
    JsonNode bpText2 = JsonUtil.readTree(bp2JsonString);
    when(blueprintUtils.convertStringToJsonNode(any())).thenReturn(bpText2);
    when(blueprintUtils.isBlueprintNamePreConfigured(anyString(), any())).thenReturn(true);
    when(blueprintEntities.getDefaults()).thenReturn(Map.of("7.0.2", "Description2=bp2;Description1=bp1"));
    when(converter.convert(any(BlueprintV4Request.class))).thenAnswer(invocation -> {
        BlueprintV4Request request = invocation.getArgument(0);
        if ("Description1".equalsIgnoreCase(request.getName())) {
            return bp1;
        }
        return bp2;
    });
    // WHEN
    underTest.loadBlueprintsFromFile();
    Map<String, BlueprintFile> defaultBlueprints = underTest.defaultBlueprints();
    // WHEN
    assertEquals(2L, defaultBlueprints.size());
    assertEquals("Description1", defaultBlueprints.get("bp1").getDescription());
    assertEquals("Description2", defaultBlueprints.get("bp2").getDescription());
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with BlueprintFile

use of com.sequenceiq.cloudbreak.domain.BlueprintFile in project cloudbreak by hortonworks.

the class BlueprintLoaderServiceTest method generateCacheData.

private Map<String, BlueprintFile> generateCacheData(int cacheSize, int startIndex, BlueprintUpgradeOption upgradeOption) {
    Map<String, BlueprintFile> cacheData = new HashMap<>();
    for (int i = startIndex; i < cacheSize + startIndex; i++) {
        BlueprintFile blueprintFile = createBlueprintFile(DEFAULT, i, upgradeOption);
        cacheData.put(blueprintFile.getName(), blueprintFile);
    }
    return cacheData;
}
Also used : HashMap(java.util.HashMap) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint)

Example 4 with BlueprintFile

use of com.sequenceiq.cloudbreak.domain.BlueprintFile in project cloudbreak by hortonworks.

the class BlueprintLoaderServiceTest method generateBlueprintFileData.

private Set<BlueprintFile> generateBlueprintFileData(int blueprintSize, BlueprintUpgradeOption upgradeOption) {
    Set<BlueprintFile> blueprintData = new HashSet<>();
    for (int i = 0; i < blueprintSize; i++) {
        BlueprintFile blueprintFile = createBlueprintFile(DEFAULT, i, upgradeOption);
        blueprintData.add(blueprintFile);
    }
    return blueprintData;
}
Also used : BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HashSet(java.util.HashSet)

Example 5 with BlueprintFile

use of com.sequenceiq.cloudbreak.domain.BlueprintFile in project cloudbreak by hortonworks.

the class DefaulBlueprintCacheTest method testLoadBlueprintsFromFileWithUpgradeOptions.

@Test
public void testLoadBlueprintsFromFileWithUpgradeOptions() throws IOException {
    // GIVEN
    Blueprint bp1 = new Blueprint();
    bp1.setName("bp1");
    bp1.setBlueprintText("txt");
    bp1.setStackName("stckn");
    bp1.setStackType("stckt");
    bp1.setStackVersion("stckv");
    String bp1JsonString = "{\"description\":\"7.2.10 - Data Engineering\",\"blueprint\":{\"cdhVersion\":\"7.2.10\",\"displayName\":\"dataengineering\"," + "\"blueprintUpgradeOption\":\"DISABLED\"}}";
    JsonNode bpText1 = JsonUtil.readTree(bp1JsonString);
    when(blueprintUtils.convertStringToJsonNode(any())).thenReturn(bpText1);
    when(blueprintEntities.getDefaults()).thenReturn(Map.of("7.2.10", "Description1=bp1"));
    when(blueprintUtils.isBlueprintNamePreConfigured(anyString(), any())).thenReturn(true);
    when(converter.convert(any(BlueprintV4Request.class))).thenAnswer(invocation -> {
        BlueprintV4Request request = invocation.getArgument(0);
        return bp1;
    });
    underTest.loadBlueprintsFromFile();
    Map<String, BlueprintFile> defaultBlueprints = underTest.defaultBlueprints();
    assertEquals(1L, defaultBlueprints.size());
    assertEquals("7.2.10 - Data Engineering", defaultBlueprints.get("bp1").getDescription());
    assertEquals(BlueprintUpgradeOption.DISABLED, defaultBlueprints.get("bp1").getBlueprintUpgradeOption());
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)8 BlueprintFile (com.sequenceiq.cloudbreak.domain.BlueprintFile)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 BlueprintV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Json (com.sequenceiq.cloudbreak.common.json.Json)1 ClusterTemplate (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Set (java.util.Set)1 PostConstruct (javax.annotation.PostConstruct)1