{"action":"created","comment":{"url":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/comments/37189496","id":37189496,"diff_hunk":"@@ -0,0 +1,131 @@\n+/*\n+ * Copyright (c) 2015 Google, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package com.cloudera.director.google.sql;\n+\n+import static com.cloudera.director.google.sql.GoogleCloudSQLInstanceTemplateConfigurationProperty.TIER;\n+import static com.cloudera.director.spi.v1.model.InstanceTemplate.InstanceTemplateConfigurationPropertyToken.INSTANCE_NAME_PREFIX;\n+import static com.cloudera.director.spi.v1.model.util.Validations.addError;\n+\n+import com.cloudera.director.spi.v1.model.ConfigurationValidator;\n+import com.cloudera.director.spi.v1.model.Configured;\n+import com.cloudera.director.spi.v1.model.LocalizationContext;\n+import com.cloudera.director.spi.v1.model.exception.PluginExceptionConditionAccumulator;\n+import com.google.common.annotations.VisibleForTesting;\n+import com.google.common.base.Preconditions;\n+import com.google.common.collect.ImmutableList;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.util.List;\n+import java.util.regex.Pattern;\n+\n+public class GoogleCloudSQLInstanceTemplateConfigurationValidator implements ConfigurationValidator  {\n+  private static final Logger LOG =\n+      LoggerFactory.getLogger(GoogleCloudSQLInstanceTemplateConfigurationValidator.class);\n+\n+  @VisibleForTesting\n+  static final String INVALID_TIER_MSG = \"Tier '%s' not found.\";\n+  @VisibleForTesting\n+  static final List<String> TIERS = ImmutableList.of(\"D0\", \"D1\", \"D2\", \"D4\", \"D8\", \"D16\", \"D32\");\n+  @VisibleForTesting\n+  static final String PREFIX_MISSING_MSG = \"Instance name prefix must be provided.\";\n+  @VisibleForTesting\n+  static final String INVALID_PREFIX_LENGTH_MSG = \"Instance name prefix must be between 1 and 26 characters.\";\n+  @VisibleForTesting\n+  static final String INVALID_PREFIX_MSG = \"Instance name prefix must follow this pattern: \" +\n+      \"The first character must be a lowercase letter, and all following characters must be a dash, lowercase \" +\n+      \"letter, or digit.\";\n+\n+  /**\n+   * The Google Cloud SQL provider.\n+   */\n+  private final GoogleCloudSQLProvider provider;\n+\n+  /**\n+   * The pattern to which instance name prefixes must conform. The pattern is the same as that for instance names in\n+   * general, except that we allow a trailing dash to be used. This is allowed since we always append a dash and the\n+   * specified instance id to the prefix.\n+   *\n+   *  @see <a href=\"https://developers.google.com/resources/api-libraries/documentation/sqladmin/v1beta4/java/latest/com/google/api/services/sqladmin/model/DatabaseInstance.html#setName(java.lang.String)\" />\n+   */\n+  private final static Pattern instanceNamePrefixPattern = Pattern.compile(\"[a-z][-a-z0-9]*\");\n+\n+  /**\n+   * Creates a Google Cloud SQL instance template configuration validator with the specified parameters.\n+   *\n+   * @param provider the Google Cloud SQL provider\n+   */\n+  public GoogleCloudSQLInstanceTemplateConfigurationValidator(GoogleCloudSQLProvider provider) {\n+    this.provider = Preconditions.checkNotNull(provider, \"provider\");\n+  }\n+\n+  @Override\n+  public void validate(String name, Configured configuration,\n+      PluginExceptionConditionAccumulator accumulator, LocalizationContext localizationContext) {\n+\n+    checkTier(configuration, accumulator, localizationContext);\n+    checkPrefix(configuration, accumulator, localizationContext);\n+  }\n+\n+  /**\n+   * Validates the configured tier type.\n+   *\n+   * @param configuration       the configuration to be validated\n+   * @param accumulator         the exception condition accumulator\n+   * @param localizationContext the localization context\n+   */\n+  void checkTier(Configured configuration,\n+      PluginExceptionConditionAccumulator accumulator,\n+      LocalizationContext localizationContext) {\n+\n+    String tier = configuration.getConfigurationValue(TIER, localizationContext);\n+\n+    // TODO(kl3n1nz) Might want to make an API call instead.\n+    // SQL API currently is supporting only list() method.\n+    if (tier != null && !TIERS.contains(tier)) {\n+      addError(accumulator, TIER, localizationContext, null, INVALID_TIER_MSG, tier);\n+    }\n+  }\n+\n+  /**\n+   * Validates the configured prefix.\n+   *\n+   * @param configuration       the configuration to be validated\n+   * @param accumulator         the exception condition accumulator\n+   * @param localizationContext the localization context\n+   */\n+  static void checkPrefix(Configured configuration,\n+      PluginExceptionConditionAccumulator accumulator,\n+      LocalizationContext localizationContext) {\n+\n+    String instanceNamePrefix = configuration.getConfigurationValue(INSTANCE_NAME_PREFIX, localizationContext);\n+\n+    LOG.info(\">> Validating prefix '{}'\", instanceNamePrefix);","path":"provider/src/main/java/com/cloudera/director/google/sql/GoogleCloudSQLInstanceTemplateConfigurationValidator.java","position":130,"original_position":117,"commit_id":"7f42ddc4c6a27df301bc9e1d004556179bc2e0c3","original_commit_id":"e2273224fc632870b8e406c27a2285c281ffaa8c","user":{"login":"mbrukman","id":4074659,"avatar_url":"https://avatars.githubusercontent.com/u/4074659?v=3","gravatar_id":"","url":"https://api.github.com/users/mbrukman","html_url":"https://github.com/mbrukman","followers_url":"https://api.github.com/users/mbrukman/followers","following_url":"https://api.github.com/users/mbrukman/following{/other_user}","gists_url":"https://api.github.com/users/mbrukman/gists{/gist_id}","starred_url":"https://api.github.com/users/mbrukman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbrukman/subscriptions","organizations_url":"https://api.github.com/users/mbrukman/orgs","repos_url":"https://api.github.com/users/mbrukman/repos","events_url":"https://api.github.com/users/mbrukman/events{/privacy}","received_events_url":"https://api.github.com/users/mbrukman/received_events","type":"User","site_admin":false},"body":"What does the `>>` in the logging output mean? Is it for indentation (i.e., it's grouped with some earlier or later messages) or something else? Do we need it?","created_at":"2015-08-17T13:58:03Z","updated_at":"2015-08-17T13:58:03Z","html_url":"https://github.com/cloudera/director-google-plugin/pull/93#discussion_r37189496","pull_request_url":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/93","_links":{"self":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/comments/37189496"},"html":{"href":"https://github.com/cloudera/director-google-plugin/pull/93#discussion_r37189496"},"pull_request":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/93"}}},"pull_request":{"url":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/93","id":42352826,"html_url":"https://github.com/cloudera/director-google-plugin/pull/93","diff_url":"https://github.com/cloudera/director-google-plugin/pull/93.diff","patch_url":"https://github.com/cloudera/director-google-plugin/pull/93.patch","issue_url":"https://api.github.com/repos/cloudera/director-google-plugin/issues/93","number":93,"state":"open","locked":false,"title":"WIP: First pass Cloud SQL integration.","user":{"login":"kl3n1nz","id":13105644,"avatar_url":"https://avatars.githubusercontent.com/u/13105644?v=3","gravatar_id":"","url":"https://api.github.com/users/kl3n1nz","html_url":"https://github.com/kl3n1nz","followers_url":"https://api.github.com/users/kl3n1nz/followers","following_url":"https://api.github.com/users/kl3n1nz/following{/other_user}","gists_url":"https://api.github.com/users/kl3n1nz/gists{/gist_id}","starred_url":"https://api.github.com/users/kl3n1nz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kl3n1nz/subscriptions","organizations_url":"https://api.github.com/users/kl3n1nz/orgs","repos_url":"https://api.github.com/users/kl3n1nz/repos","events_url":"https://api.github.com/users/kl3n1nz/events{/privacy}","received_events_url":"https://api.github.com/users/kl3n1nz/received_events","type":"User","site_admin":false},"body":"@duftler please review.","created_at":"2015-08-13T13:54:42Z","updated_at":"2015-08-17T13:58:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8615e895f572c563a8e568204c47aee71e7c99b0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/93/commits","review_comments_url":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/93/comments","review_comment_url":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudera/director-google-plugin/issues/93/comments","statuses_url":"https://api.github.com/repos/cloudera/director-google-plugin/statuses/7f42ddc4c6a27df301bc9e1d004556179bc2e0c3","head":{"label":"kl3n1nz:google-sql-first-pass","ref":"google-sql-first-pass","sha":"7f42ddc4c6a27df301bc9e1d004556179bc2e0c3","user":{"login":"kl3n1nz","id":13105644,"avatar_url":"https://avatars.githubusercontent.com/u/13105644?v=3","gravatar_id":"","url":"https://api.github.com/users/kl3n1nz","html_url":"https://github.com/kl3n1nz","followers_url":"https://api.github.com/users/kl3n1nz/followers","following_url":"https://api.github.com/users/kl3n1nz/following{/other_user}","gists_url":"https://api.github.com/users/kl3n1nz/gists{/gist_id}","starred_url":"https://api.github.com/users/kl3n1nz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kl3n1nz/subscriptions","organizations_url":"https://api.github.com/users/kl3n1nz/orgs","repos_url":"https://api.github.com/users/kl3n1nz/repos","events_url":"https://api.github.com/users/kl3n1nz/events{/privacy}","received_events_url":"https://api.github.com/users/kl3n1nz/received_events","type":"User","site_admin":false},"repo":{"id":40658491,"name":"director-google-plugin","full_name":"kl3n1nz/director-google-plugin","owner":{"login":"kl3n1nz","id":13105644,"avatar_url":"https://avatars.githubusercontent.com/u/13105644?v=3","gravatar_id":"","url":"https://api.github.com/users/kl3n1nz","html_url":"https://github.com/kl3n1nz","followers_url":"https://api.github.com/users/kl3n1nz/followers","following_url":"https://api.github.com/users/kl3n1nz/following{/other_user}","gists_url":"https://api.github.com/users/kl3n1nz/gists{/gist_id}","starred_url":"https://api.github.com/users/kl3n1nz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kl3n1nz/subscriptions","organizations_url":"https://api.github.com/users/kl3n1nz/orgs","repos_url":"https://api.github.com/users/kl3n1nz/repos","events_url":"https://api.github.com/users/kl3n1nz/events{/privacy}","received_events_url":"https://api.github.com/users/kl3n1nz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kl3n1nz/director-google-plugin","description":"Cloudera Director - Google Cloud Platform integration","fork":true,"url":"https://api.github.com/repos/kl3n1nz/director-google-plugin","forks_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/forks","keys_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/teams","hooks_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/hooks","issue_events_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/events","assignees_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/tags","blobs_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/languages","stargazers_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/stargazers","contributors_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/contributors","subscribers_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/subscribers","subscription_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/subscription","commits_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/merges","archive_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/downloads","issues_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/labels{/name}","releases_url":"https://api.github.com/repos/kl3n1nz/director-google-plugin/releases{/id}","created_at":"2015-08-13T12:50:11Z","updated_at":"2015-08-13T12:50:12Z","pushed_at":"2015-08-14T19:17:50Z","git_url":"git://github.com/kl3n1nz/director-google-plugin.git","ssh_url":"git@github.com:kl3n1nz/director-google-plugin.git","clone_url":"https://github.com/kl3n1nz/director-google-plugin.git","svn_url":"https://github.com/kl3n1nz/director-google-plugin","homepage":null,"size":852,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cloudera:master","ref":"master","sha":"7df63cb7d56373d75184ba36fbec6a6627883851","user":{"login":"cloudera","id":87383,"avatar_url":"https://avatars.githubusercontent.com/u/87383?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudera","html_url":"https://github.com/cloudera","followers_url":"https://api.github.com/users/cloudera/followers","following_url":"https://api.github.com/users/cloudera/following{/other_user}","gists_url":"https://api.github.com/users/cloudera/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudera/subscriptions","organizations_url":"https://api.github.com/users/cloudera/orgs","repos_url":"https://api.github.com/users/cloudera/repos","events_url":"https://api.github.com/users/cloudera/events{/privacy}","received_events_url":"https://api.github.com/users/cloudera/received_events","type":"Organization","site_admin":false},"repo":{"id":30982881,"name":"director-google-plugin","full_name":"cloudera/director-google-plugin","owner":{"login":"cloudera","id":87383,"avatar_url":"https://avatars.githubusercontent.com/u/87383?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudera","html_url":"https://github.com/cloudera","followers_url":"https://api.github.com/users/cloudera/followers","following_url":"https://api.github.com/users/cloudera/following{/other_user}","gists_url":"https://api.github.com/users/cloudera/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudera/subscriptions","organizations_url":"https://api.github.com/users/cloudera/orgs","repos_url":"https://api.github.com/users/cloudera/repos","events_url":"https://api.github.com/users/cloudera/events{/privacy}","received_events_url":"https://api.github.com/users/cloudera/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudera/director-google-plugin","description":"Cloudera Director - Google Cloud Platform integration","fork":false,"url":"https://api.github.com/repos/cloudera/director-google-plugin","forks_url":"https://api.github.com/repos/cloudera/director-google-plugin/forks","keys_url":"https://api.github.com/repos/cloudera/director-google-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudera/director-google-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudera/director-google-plugin/teams","hooks_url":"https://api.github.com/repos/cloudera/director-google-plugin/hooks","issue_events_url":"https://api.github.com/repos/cloudera/director-google-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/cloudera/director-google-plugin/events","assignees_url":"https://api.github.com/repos/cloudera/director-google-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/cloudera/director-google-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/cloudera/director-google-plugin/tags","blobs_url":"https://api.github.com/repos/cloudera/director-google-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudera/director-google-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudera/director-google-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudera/director-google-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudera/director-google-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudera/director-google-plugin/languages","stargazers_url":"https://api.github.com/repos/cloudera/director-google-plugin/stargazers","contributors_url":"https://api.github.com/repos/cloudera/director-google-plugin/contributors","subscribers_url":"https://api.github.com/repos/cloudera/director-google-plugin/subscribers","subscription_url":"https://api.github.com/repos/cloudera/director-google-plugin/subscription","commits_url":"https://api.github.com/repos/cloudera/director-google-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudera/director-google-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudera/director-google-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudera/director-google-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudera/director-google-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/cloudera/director-google-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudera/director-google-plugin/merges","archive_url":"https://api.github.com/repos/cloudera/director-google-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudera/director-google-plugin/downloads","issues_url":"https://api.github.com/repos/cloudera/director-google-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/cloudera/director-google-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudera/director-google-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudera/director-google-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudera/director-google-plugin/labels{/name}","releases_url":"https://api.github.com/repos/cloudera/director-google-plugin/releases{/id}","created_at":"2015-02-18T19:39:24Z","updated_at":"2015-08-13T05:46:08Z","pushed_at":"2015-08-14T19:17:50Z","git_url":"git://github.com/cloudera/director-google-plugin.git","ssh_url":"git@github.com:cloudera/director-google-plugin.git","clone_url":"https://github.com/cloudera/director-google-plugin.git","svn_url":"https://github.com/cloudera/director-google-plugin","homepage":null,"size":852,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":1,"forks":4,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/93"},"html":{"href":"https://github.com/cloudera/director-google-plugin/pull/93"},"issue":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/issues/93"},"comments":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/issues/93/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/93/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/pulls/93/commits"},"statuses":{"href":"https://api.github.com/repos/cloudera/director-google-plugin/statuses/7f42ddc4c6a27df301bc9e1d004556179bc2e0c3"}}}}