use of com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException in project azure-maven-plugins by microsoft.
the class ConfigMojo method doExecute.
@Override
protected void doExecute() throws AzureExecutionException {
if (!settings.isInteractiveMode()) {
throw new UnsupportedOperationException("The goal 'config' must be run at interactive mode.");
}
if (!MavenConfigUtils.isPomPackaging(this.project) && !MavenConfigUtils.isJarPackaging(this.project)) {
throw new UnsupportedOperationException(String.format("The project (%s) with packaging %s is not supported for azure spring cloud service.", this.project.getName(), this.project.getPackaging()));
}
if (isProjectConfigured(this.project)) {
getLog().warn(String.format("Project (%s) is already configured and won't be affected by this command.", this.project.getName()));
return;
}
appSettings = new AppRawConfig();
deploymentSettings = new AppDeploymentRawConfig();
parentMode = MavenConfigUtils.isPomPackaging(this.project);
if (parentMode && advancedOptions) {
throw new UnsupportedOperationException("The \"advancedOptions\" mode is not supported at parent folder.");
}
final ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
try {
this.wrapper = new ConfigurationPrompter(expressionEvaluator, getLog());
this.wrapper.initialize();
this.wrapper.putCommonVariable("project", this.project);
selectProjects();
if (targetProjects == null || targetProjects.isEmpty()) {
// no need to proceed when there are no projects need to be configured
return;
}
// select subscription in spring cloud -> config is different from other goals since it is prompted after select project.
// set up account and select subscription here
getAzureAccount();
promptAndSelectSubscription();
selectAppCluster();
configCommon();
confirmAndSave();
} catch (IOException | InvalidConfigurationException | UnsupportedOperationException | MavenDecryptException | LoginFailureException e) {
throw new AzureExecutionException(e.getMessage());
} finally {
if (this.wrapper != null) {
try {
this.wrapper.close();
} catch (IOException e) {
// ignore at final step
}
}
}
}
use of com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException in project azure-maven-plugins by microsoft.
the class ConfigMojo method configureAppName.
private void configureAppName() throws IOException, InvalidConfigurationException {
if (StringUtils.isNotBlank(appName) && this.parentMode) {
throw new UnsupportedOperationException("Cannot specify appName in parent mode.");
}
if (this.parentMode) {
appNameByProject = new HashMap<>();
for (final MavenProject proj : targetProjects) {
this.wrapper.putCommonVariable("project", proj);
this.appNameByProject.put(proj, this.wrapper.handle("configure-app-name", this.parentMode, this.appName));
}
// reset back of variable project
this.wrapper.putCommonVariable("project", this.project);
// handle duplicate app name
final String duplicateAppNames = this.appNameByProject.values().stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(t -> t.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.joining(","));
if (StringUtils.isNotBlank(duplicateAppNames)) {
throw new InvalidConfigurationException(String.format("Cannot apply default appName due to duplicate: %s", duplicateAppNames));
}
} else {
this.appSettings.setAppName(this.wrapper.handle("configure-app-name", false, this.appName));
}
}
use of com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException 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);
}
});
}
}
use of com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException in project azure-maven-plugins by microsoft.
the class AzureConfigurationExceptionTest method testMessage.
@Test
public void testMessage() {
final InvalidConfigurationException ex = new InvalidConfigurationException("error");
assertEquals("error", ex.getMessage());
}
use of com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException in project azure-maven-plugins by microsoft.
the class AzureConfigurationExceptionTest method testMessageCause.
@Test
public void testMessageCause() {
final RuntimeException cause = new RuntimeException("cause");
final InvalidConfigurationException ex = new InvalidConfigurationException("error", cause);
assertEquals("error", ex.getMessage());
assertEquals(cause, ex.getCause());
}
Aggregations