Example usage for org.springframework.beans.factory.config YamlPropertiesFactoryBean YamlPropertiesFactoryBean

List of usage examples for org.springframework.beans.factory.config YamlPropertiesFactoryBean YamlPropertiesFactoryBean

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config YamlPropertiesFactoryBean YamlPropertiesFactoryBean.

Prototype

YamlPropertiesFactoryBean

Source Link

Usage

From source file:org.springframework.cloud.dataflow.shell.command.StreamCommands.java

@CliCommand(value = DEPLOY_STREAM, help = "Deploy a previously created stream")
public String deployStream(@CliOption(key = { "",
        "name" }, help = "the name of the stream to deploy", mandatory = true/*, optionContext = "existing-stream undeployed disable-string-converter"*/) String name,
        @CliOption(key = {//from   w w w . ja  va2s .co m
                PROPERTIES_OPTION }, help = "the properties for this deployment", mandatory = false) String properties,
        @CliOption(key = {
                PROPERTIES_FILE_OPTION }, help = "the properties for this deployment (as a File)", mandatory = false) File propertiesFile)
        throws IOException {
    int which = Assertions.atMostOneOf(PROPERTIES_OPTION, properties, PROPERTIES_FILE_OPTION, propertiesFile);
    Map<String, String> propertiesToUse;
    switch (which) {
    case 0:
        propertiesToUse = DeploymentPropertiesUtils.parse(properties);
        break;
    case 1:
        String extension = FilenameUtils.getExtension(propertiesFile.getName());
        Properties props = null;
        if (extension.equals("yaml") || extension.equals("yml")) {
            YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
            yamlPropertiesFactoryBean.setResources(new FileSystemResource(propertiesFile));
            yamlPropertiesFactoryBean.afterPropertiesSet();
            props = yamlPropertiesFactoryBean.getObject();
        } else {
            props = new Properties();
            try (FileInputStream fis = new FileInputStream(propertiesFile)) {
                props.load(fis);
            }
        }
        propertiesToUse = DeploymentPropertiesUtils.convert(props);
        break;
    case -1: // Neither option specified
        propertiesToUse = Collections.<String, String>emptyMap();
        break;
    default:
        throw new AssertionError();
    }
    streamOperations().deploy(name, propertiesToUse);
    return String.format("Deployment request has been sent for stream '%s'", name);
}

From source file:org.springframework.cloud.deployer.admin.shell.command.ApplicationCommands.java

@CliCommand(value = DEPLOY_APPLICATION, help = "Deploy a previously created application")
public String deployApplication(
        @CliOption(key = { "",
                "name" }, help = "the name of the application to deploy", mandatory = true) String name,
        @CliOption(key = {//from  w  w  w .  ja v a2s  .  co  m
                PROPERTIES_OPTION }, help = "the properties for this deployment", mandatory = false) String properties,
        @CliOption(key = {
                PROPERTIES_FILE_OPTION }, help = "the properties for this deployment (as a File)", mandatory = false) File propertiesFile)
        throws IOException {
    int which = Assertions.atMostOneOf(PROPERTIES_OPTION, properties, PROPERTIES_FILE_OPTION, propertiesFile);
    Map<String, String> propertiesToUse;
    switch (which) {
    case 0:
        propertiesToUse = DeploymentPropertiesUtils.parse(properties);
        break;
    case 1:
        String extension = FilenameUtils.getExtension(propertiesFile.getName());
        Properties props = null;
        if (extension.equals("yaml") || extension.equals("yml")) {
            YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
            yamlPropertiesFactoryBean.setResources(new FileSystemResource(propertiesFile));
            yamlPropertiesFactoryBean.afterPropertiesSet();
            props = yamlPropertiesFactoryBean.getObject();
        } else {
            props = new Properties();
            try (FileInputStream fis = new FileInputStream(propertiesFile)) {
                props.load(fis);
            }
        }
        propertiesToUse = DeploymentPropertiesUtils.convert(props);
        break;
    case -1: // Neither option specified
        propertiesToUse = Collections.<String, String>emptyMap();
        break;
    default:
        throw new AssertionError();
    }
    applicationOperations().deploy(name, propertiesToUse);
    return String.format("Deployment request has been sent for application '%s'", name);
}

From source file:org.springframework.cloud.stream.app.aws.AwsIntegrationTestStackRule.java

@Override
protected void before() throws Throwable {
    try {//w  ww.  j a  v a  2s .c  om
        String awsCredentialsDir = System.getProperty("aws.credentials.path");
        File awsCredentialsFile = new File(awsCredentialsDir, "aws.credentials.properties");
        Properties awsCredentials = new Properties();
        awsCredentials.load(new FileReader(awsCredentialsFile));
        String accessKey = awsCredentials.getProperty("cloud.aws.credentials.accessKey");
        String secretKey = awsCredentials.getProperty("cloud.aws.credentials.secretKey");
        this.cloudFormation = new AmazonCloudFormationClient(new BasicAWSCredentials(accessKey, secretKey));

        YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
        yamlPropertiesFactoryBean.setResources(new ClassPathResource("application.yml"));
        Properties applicationProperties = yamlPropertiesFactoryBean.getObject();

        this.stackName = applicationProperties.getProperty("cloud.aws.stack.name");

        after();

        ClassPathResource stackTemplate = new ClassPathResource("AwsIntegrationTestTemplate.json");
        String templateBody = FileCopyUtils.copyToString(new InputStreamReader(stackTemplate.getInputStream()));

        this.cloudFormation.createStack(new CreateStackRequest().withTemplateBody(templateBody)
                .withOnFailure(OnFailure.DELETE).withStackName(this.stackName));

        waitForCompletion();

        System.setProperty("cloud.aws.credentials.accessKey", accessKey);
        System.setProperty("cloud.aws.credentials.secretKey", secretKey);
    } catch (Exception e) {
        if (!(e instanceof AssumptionViolatedException)) {
            Assume.assumeTrue("Can't perform AWS integration test because of: " + e.getMessage(), false);
        } else {
            throw e;
        }
    }
}