Search in sources :

Example 1 with DefaultPrompter

use of com.microsoft.azure.maven.prompt.DefaultPrompter in project azure-maven-plugins by microsoft.

the class ConfigurationPrompter method initialize.

public void initialize() throws IOException, InvalidConfigurationException {
    prompt = new DefaultPrompter();
    validator = new SchemaValidator();
    templates = new HashMap<>();
    commonVariables = new HashMap<>();
    final Yaml yaml = new Yaml();
    final Set<String> resourceNames = new HashSet<>();
    try (final InputStream inputStream = this.getClass().getResourceAsStream("/MessageTemplates.yaml")) {
        final Iterable<Object> rules = yaml.loadAll(inputStream);
        for (final Object rule : rules) {
            final Map<String, Object> map = (Map<String, Object>) rule;
            templates.put((String) map.get("id"), map);
            if (map.containsKey("resource")) {
                resourceNames.add((String) map.get("resource"));
            }
        }
    }
    for (final String resourceName : resourceNames) {
        final ObjectNode resourceSchema = (ObjectNode) JsonLoader.fromResource("/schema/" + resourceName + ".json");
        if (!resourceSchema.has("properties")) {
            throw new InvalidConfigurationException(String.format("Bad schema for %s: missing properties field.", resourceName));
        }
        final ObjectNode propertiesNode = (ObjectNode) resourceSchema.get("properties");
        IteratorUtils.forEach(propertiesNode.fields(), prop -> {
            try {
                this.validator.collectSingleProperty(resourceName, prop.getKey(), prop.getValue());
            } catch (JsonProcessingException e) {
                throw Lombok.sneakyThrow(e);
            }
        });
    }
}
Also used : DefaultPrompter(com.microsoft.azure.maven.prompt.DefaultPrompter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) SchemaValidator(com.microsoft.azure.maven.prompt.SchemaValidator) Yaml(org.yaml.snakeyaml.Yaml) InvalidConfigurationException(com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException) HashMap(java.util.HashMap) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HashSet(java.util.HashSet)

Example 2 with DefaultPrompter

use of com.microsoft.azure.maven.prompt.DefaultPrompter in project azure-maven-plugins by microsoft.

the class DeployMojo method confirm.

protected boolean confirm(List<AzureTask<?>> tasks) throws MojoFailureException {
    try {
        final IPrompter prompter = new DefaultPrompter();
        System.out.println(CONFIRM_PROMPT_START);
        tasks.stream().filter(t -> StringUtils.isNotBlank(t.getTitle().toString())).forEach((t) -> System.out.printf("\t- %s%n", t.getTitle()));
        return prompter.promoteYesNo(CONFIRM_PROMPT_CONFIRM, true, true);
    } catch (IOException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
}
Also used : AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) IPrompter(com.microsoft.azure.maven.prompt.IPrompter) SneakyThrows(lombok.SneakyThrows) DeploySpringCloudAppTask(com.microsoft.azure.toolkit.lib.springcloud.task.DeploySpringCloudAppTask) SpringCloudAppConfig(com.microsoft.azure.toolkit.lib.springcloud.config.SpringCloudAppConfig) IOException(java.io.IOException) Parameter(org.apache.maven.plugins.annotations.Parameter) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) SpringCloudApp(com.microsoft.azure.toolkit.lib.springcloud.SpringCloudApp) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) MojoFailureException(org.apache.maven.plugin.MojoFailureException) MavenConfigUtils(com.microsoft.azure.maven.utils.MavenConfigUtils) Mojo(org.apache.maven.plugins.annotations.Mojo) Utils(com.microsoft.azure.toolkit.lib.springcloud.Utils) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TextUtils(com.microsoft.azure.toolkit.lib.common.utils.TextUtils) DefaultPrompter(com.microsoft.azure.maven.prompt.DefaultPrompter) MavenProject(org.apache.maven.project.MavenProject) SpringCloudDeployment(com.microsoft.azure.toolkit.lib.springcloud.SpringCloudDeployment) DefaultPrompter(com.microsoft.azure.maven.prompt.DefaultPrompter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) IPrompter(com.microsoft.azure.maven.prompt.IPrompter)

Aggregations

DefaultPrompter (com.microsoft.azure.maven.prompt.DefaultPrompter)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IPrompter (com.microsoft.azure.maven.prompt.IPrompter)1 SchemaValidator (com.microsoft.azure.maven.prompt.SchemaValidator)1 MavenConfigUtils (com.microsoft.azure.maven.utils.MavenConfigUtils)1 InvalidConfigurationException (com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException)1 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)1 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)1 TextUtils (com.microsoft.azure.toolkit.lib.common.utils.TextUtils)1 SpringCloudApp (com.microsoft.azure.toolkit.lib.springcloud.SpringCloudApp)1 SpringCloudDeployment (com.microsoft.azure.toolkit.lib.springcloud.SpringCloudDeployment)1 Utils (com.microsoft.azure.toolkit.lib.springcloud.Utils)1 SpringCloudAppConfig (com.microsoft.azure.toolkit.lib.springcloud.config.SpringCloudAppConfig)1 DeploySpringCloudAppTask (com.microsoft.azure.toolkit.lib.springcloud.task.DeploySpringCloudAppTask)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1