use of com.sequenceiq.cloudbreak.api.model.InstanceGroupType in project cloudbreak by hortonworks.
the class JsonTest method testMultipleSerialisation.
// The reason for this to check whether serialisetion-deserialisation-serialisation results the same json
@Test
public void testMultipleSerialisation() throws IOException {
Map<InstanceGroupType, String> userData = new HashMap<>();
userData.put(InstanceGroupType.CORE, "CORE");
Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
Json json = new Json(image);
String expected = json.getValue();
Image covertedAgain = json.get(Image.class);
json = new Json(covertedAgain);
Assert.assertEquals(expected, json.getValue());
}
use of com.sequenceiq.cloudbreak.api.model.InstanceGroupType in project cloudbreak by hortonworks.
the class JsonTest method testMultipleSerialisationWithOtherConstructorOfImage.
@Test
public void testMultipleSerialisationWithOtherConstructorOfImage() throws IOException {
Map<InstanceGroupType, String> userData = new HashMap<>();
userData.put(InstanceGroupType.CORE, "CORE");
Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
Json json = new Json(image);
String expected = json.getValue();
Image covertedAgain = json.get(Image.class);
json = new Json(covertedAgain);
Assert.assertEquals(expected, json.getValue());
}
use of com.sequenceiq.cloudbreak.api.model.InstanceGroupType in project cloudbreak by hortonworks.
the class ImageService method create.
@Transactional(TxType.NEVER)
public void create(Stack stack, PlatformParameters params, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
try {
Platform platform = platform(stack.cloudPlatform());
String platformString = platform(stack.cloudPlatform()).value().toLowerCase();
String region = stack.getRegion();
SecurityConfig securityConfig = stack.getSecurityConfig();
String cbPrivKey = securityConfig.getCloudbreakSshPrivateKeyDecoded();
byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(cbPrivKey);
String sshUser = stack.getStackAuthentication().getLoginUserName();
String cbCert = securityConfig.getClientCertRaw();
Map<InstanceGroupType, String> userData = userDataBuilder.buildUserData(platform, cbSshKeyDer, sshUser, params, securityConfig.getSaltBootPassword(), cbCert);
StatedImage imgFromCatalog = determineImageFromCatalog(imageId, platformString, imageCatalog, blueprint);
LOGGER.info("Determined image from catalog: {}", imgFromCatalog);
String imageName = determineImageName(platformString, region, imgFromCatalog.getImage());
LOGGER.info("Selected VM image for CloudPlatform '{}' and region '{}' is: {} from: {} image catalog", platformString, region, imageName, imgFromCatalog.getImageCatalogUrl());
List<Component> components = getComponents(stack, userData, imgFromCatalog.getImage(), imageName, imgFromCatalog.getImageCatalogUrl(), imgFromCatalog.getImageCatalogName(), imgFromCatalog.getImage().getUuid());
componentConfigProvider.store(components);
} catch (JsonProcessingException e) {
throw new CloudbreakServiceException("Failed to create json", e);
}
}
use of com.sequenceiq.cloudbreak.api.model.InstanceGroupType in project cloudbreak by hortonworks.
the class UserDataBuilder method buildUserData.
Map<InstanceGroupType, String> buildUserData(Platform cloudPlatform, byte[] cbSshKeyDer, String sshUser, PlatformParameters parameters, String saltBootPassword, String cbCert) {
Map<InstanceGroupType, String> result = new EnumMap<>(InstanceGroupType.class);
for (InstanceGroupType type : InstanceGroupType.values()) {
String userData = build(type, cloudPlatform, cbSshKeyDer, sshUser, parameters, saltBootPassword, cbCert);
result.put(type, userData);
LOGGER.debug("User data for {}, content; {}", type, userData);
}
return result;
}
use of com.sequenceiq.cloudbreak.api.model.InstanceGroupType in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method setup.
@Before
public void setup() throws IOException, TemplateException {
initMocks(this);
FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
factoryBean.setPreferFileSystemAccess(false);
factoryBean.setTemplateLoaderPath("classpath:/");
factoryBean.afterPropertiesSet();
Configuration configuration = factoryBean.getObject();
ReflectionTestUtils.setField(heatTemplateBuilder, "freemarkerConfiguration", configuration);
ReflectionTestUtils.setField(heatTemplateBuilder, "openStackHeatTemplatePath", templatePath);
stackName = "testStack";
groups = new ArrayList<>(1);
String name = "master";
List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
Security security = new Security(rules, null);
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
Map<String, String> tags = new HashMap<>();
tags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key());
tags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key());
tags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key());
tags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key());
tags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key());
tags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key());
tags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key());
when(defaultCostTaggingService.prepareInstanceTagging()).thenReturn(tags);
image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "url", "default", null);
}
Aggregations