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)));
}
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());
}
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;
}
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;
}
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());
}
Aggregations