Search in sources :

Example 6 with InstanceGroupType

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());
}
Also used : InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Test(org.junit.Test)

Example 7 with InstanceGroupType

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());
}
Also used : InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Test(org.junit.Test)

Example 8 with InstanceGroupType

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);
    }
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) Component(com.sequenceiq.cloudbreak.domain.Component) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Transactional(javax.transaction.Transactional)

Example 9 with InstanceGroupType

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;
}
Also used : InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) FreeMarkerTemplateUtils.processTemplateIntoString(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString) EnumMap(java.util.EnumMap)

Example 10 with InstanceGroupType

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);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Matchers.containsString(org.hamcrest.Matchers.containsString) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Before(org.junit.Before)

Aggregations

InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)10 Image (com.sequenceiq.cloudbreak.cloud.model.Image)8 HashMap (java.util.HashMap)6 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)5 Security (com.sequenceiq.cloudbreak.cloud.model.Security)5 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)5 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)5 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)4 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)4 Before (org.junit.Before)4 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3 Configuration (freemarker.template.Configuration)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.Test)3 FreeMarkerConfigurationFactoryBean (org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 Network (com.sequenceiq.cloudbreak.cloud.model.Network)2 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)2