Package com.sequenceiq.cloudbreak.controller.json

Examples of com.sequenceiq.cloudbreak.controller.json.TemplateJson


    private static final String DEFAULT_SSH_LOCATION = "0.0.0.0/0";

    @Override
    public TemplateJson convert(AwsTemplate entity) {
        TemplateJson templateJson = new TemplateJson();
        templateJson.setId(entity.getId());
        templateJson.setName(entity.getName());
        templateJson.setVolumeCount(entity.getVolumeCount());
        templateJson.setVolumeSize(entity.getVolumeSize());
        Map<String, Object> props = new HashMap<>();
        props.put(AwsTemplateParam.REGION.getName(), entity.getRegion().toString());
        props.put(AwsTemplateParam.AMI_ID.getName(), entity.getAmiId());
        props.put(AwsTemplateParam.INSTANCE_TYPE.getName(), entity.getInstanceType().name());
        props.put(AwsTemplateParam.SSH_LOCATION.getName(), entity.getSshLocation());
        props.put(AwsTemplateParam.VOLUME_TYPE.getName(), entity.getVolumeType());
        if (entity.getSpotPrice() != null) {
            props.put(AwsTemplateParam.SPOT_PRICE.getName(), entity.getSpotPrice());
        }
        templateJson.setParameters(props);
        templateJson.setCloudPlatform(CloudPlatform.AWS);
        templateJson.setDescription(entity.getDescription() == null ? "" : entity.getDescription());
        return templateJson;
    }
View Full Code Here


@Component
public class GccTemplateConverter extends AbstractConverter<TemplateJson, GccTemplate> {

    @Override
    public TemplateJson convert(GccTemplate entity) {
        TemplateJson gccTemplateJson = new TemplateJson();
        gccTemplateJson.setName(entity.getName());
        gccTemplateJson.setCloudPlatform(CloudPlatform.GCC);
        gccTemplateJson.setId(entity.getId());
        gccTemplateJson.setVolumeCount(entity.getVolumeCount());
        gccTemplateJson.setVolumeSize(entity.getVolumeSize());
        gccTemplateJson.setDescription(entity.getDescription());
        Map<String, Object> props = new HashMap<>();
        putProperty(props, GccTemplateParam.IMAGETYPE.getName(), entity.getGccImageType());
        putProperty(props, GccTemplateParam.INSTANCETYPE.getName(), entity.getGccInstanceType());
        putProperty(props, GccTemplateParam.ZONE.getName(), entity.getGccZone());
        putProperty(props, GccTemplateParam.CONTAINERCOUNT.getName(), entity.getContainerCount());
        putProperty(props, GccTemplateParam.TYPE.getName(), entity.getGccRawDiskType());
        gccTemplateJson.setParameters(props);
        gccTemplateJson.setDescription(entity.getDescription() == null ? "" : entity.getDescription());
        return gccTemplateJson;
    }
View Full Code Here

    @RequestMapping(value = "templates/{id}", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<TemplateJson> getTemplate(@ModelAttribute("user") CbUser user, @PathVariable Long id) {
        Template template = templateService.get(id);
        TemplateJson templateJson = convert(template);
        return new ResponseEntity<>(templateJson, HttpStatus.OK);
    }
View Full Code Here

        }
        return template;
    }

    private TemplateJson convert(Template template) {
        TemplateJson templateJson = null;
        switch (template.cloudPlatform()) {
            case AWS:
                templateJson = awsTemplateConverter.convert((AwsTemplate) template);
                break;
            case AZURE:
View Full Code Here

                );
    }

    @Test
    public void validAwsTemplateJsonWillReturnTrue() {
        TemplateJson templateJson = new TemplateJson();
        templateJson.setCloudPlatform(CloudPlatform.AWS);
        templateJson.setDescription("description");
        templateJson.setName("name");
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(AwsTemplateParam.AMI_ID.getName(), "ami");
        parameters.put(AwsTemplateParam.INSTANCE_TYPE.getName(), InstanceType.C1Medium.name());
        parameters.put(AwsTemplateParam.REGION.getName(), Regions.AP_NORTHEAST_1);
        parameters.put(AwsTemplateParam.SSH_LOCATION.getName(), "0.0.0.0/0");
        templateJson.setVolumeCount(3);
        templateJson.setVolumeSize(30);
        parameters.put(AwsTemplateParam.VOLUME_TYPE.getName(), "Gp2");
        templateJson.setParameters(parameters);
        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), true);
    }
View Full Code Here

        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), true);
    }

    @Test
    public void validAwsTemplateWithSpecificSshJsonWillReturnTrue() {
        TemplateJson templateJson = new TemplateJson();
        templateJson.setCloudPlatform(CloudPlatform.AWS);
        templateJson.setDescription("description");
        templateJson.setName("name");
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(AwsTemplateParam.AMI_ID.getName(), "ami");
        parameters.put(AwsTemplateParam.INSTANCE_TYPE.getName(), InstanceType.C1Medium.name());
        parameters.put(AwsTemplateParam.REGION.getName(), Regions.AP_NORTHEAST_1);
        parameters.put(AwsTemplateParam.SSH_LOCATION.getName(), "192.12.12.12/12");
        templateJson.setVolumeCount(3);
        templateJson.setVolumeSize(30);
        parameters.put(AwsTemplateParam.VOLUME_TYPE.getName(), "Gp2");
        templateJson.setParameters(parameters);
        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), true);
    }
View Full Code Here

        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), true);
    }

    @Test
    public void validAwsTemplateWithInvalidSshLocationJsonWillReturnTrue() {
        TemplateJson templateJson = new TemplateJson();
        templateJson.setCloudPlatform(CloudPlatform.AWS);
        templateJson.setDescription("description");
        templateJson.setName("name");
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(AwsTemplateParam.AMI_ID.getName(), "ami");
        parameters.put(AwsTemplateParam.INSTANCE_TYPE.getName(), InstanceType.C1Medium.name());
        parameters.put(AwsTemplateParam.REGION.getName(), Regions.AP_NORTHEAST_1);
        parameters.put(AwsTemplateParam.SSH_LOCATION.getName(), "0.0.0.0");
        templateJson.setVolumeCount(3);
        templateJson.setVolumeSize(30);
        parameters.put(AwsTemplateParam.VOLUME_TYPE.getName(), "Gp2");
        templateJson.setParameters(parameters);
        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), false);
    }
View Full Code Here

        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), false);
    }

    @Test
    public void validAwsTemplateWithSpotPriceWithIntegerJsonWillReturnTrue() {
        TemplateJson templateJson = new TemplateJson();
        templateJson.setCloudPlatform(CloudPlatform.AWS);
        templateJson.setDescription("description");
        templateJson.setName("name");
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(AwsTemplateParam.AMI_ID.getName(), "ami");
        parameters.put(AwsTemplateParam.INSTANCE_TYPE.getName(), InstanceType.C1Medium.name());
        parameters.put(AwsTemplateParam.REGION.getName(), Regions.AP_NORTHEAST_1);
        parameters.put(AwsTemplateParam.SSH_LOCATION.getName(), "0.0.0.0/0");
        templateJson.setVolumeCount(3);
        templateJson.setVolumeSize(30);
        parameters.put(AwsTemplateParam.VOLUME_TYPE.getName(), "Gp2");
        parameters.put(AwsTemplateParam.SPOT_PRICE.getName(), Integer.valueOf(1));
        templateJson.setParameters(parameters);
        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), true);
    }
View Full Code Here

        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), true);
    }

    @Test
    public void validAwsTemplateWithSpotPriceWithStringJsonWillReturnFalse() {
        TemplateJson templateJson = new TemplateJson();
        templateJson.setCloudPlatform(CloudPlatform.AWS);
        templateJson.setDescription("description");
        templateJson.setName("name");
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(AwsTemplateParam.AMI_ID.getName(), "ami");
        parameters.put(AwsTemplateParam.INSTANCE_TYPE.getName(), InstanceType.C1Medium.name());
        parameters.put(AwsTemplateParam.REGION.getName(), Regions.AP_NORTHEAST_1);
        parameters.put(AwsTemplateParam.SSH_LOCATION.getName(), "0.0.0.0/0");
        templateJson.setVolumeCount(3);
        templateJson.setVolumeSize(30);
        parameters.put(AwsTemplateParam.VOLUME_TYPE.getName(), "Gp2");
        parameters.put(AwsTemplateParam.SPOT_PRICE.getName(), "apple");
        templateJson.setParameters(parameters);
        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), false);
    }
View Full Code Here

        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), false);
    }

    @Test
    public void validAwsTemplateWithSpotPriceWithDoubleJsonWillReturnTrue() {
        TemplateJson templateJson = new TemplateJson();
        templateJson.setCloudPlatform(CloudPlatform.AWS);
        templateJson.setDescription("description");
        templateJson.setName("name");
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(AwsTemplateParam.AMI_ID.getName(), "ami");
        parameters.put(AwsTemplateParam.INSTANCE_TYPE.getName(), InstanceType.C1Medium.name());
        parameters.put(AwsTemplateParam.REGION.getName(), Regions.AP_NORTHEAST_1);
        parameters.put(AwsTemplateParam.SSH_LOCATION.getName(), "0.0.0.0/0");
        templateJson.setVolumeCount(3);
        templateJson.setVolumeSize(30);
        parameters.put(AwsTemplateParam.VOLUME_TYPE.getName(), "Gp2");
        parameters.put(AwsTemplateParam.SPOT_PRICE.getName(), Double.valueOf(1.2));
        templateJson.setParameters(parameters);
        assertEquals(underTest.isValid(templateJson, constraintValidatorContext), true);
    }
View Full Code Here

TOP

Related Classes of com.sequenceiq.cloudbreak.controller.json.TemplateJson

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.