{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/22754148","id":22754148,"diff_hunk":"@@ -241,49 +248,105 @@ public void setConfig(HttpRequest request, HttpResponder responder,\n     String accountId = getAuthenticatedAccountId(request);\n \n     if (!streamMetaStore.streamExists(accountId, stream)) {\n-      responder.sendString(HttpResponseStatus.NOT_FOUND, \"Stream does not exists\");\n+      responder.sendString(HttpResponseStatus.NOT_FOUND, \"Stream does not exist.\");\n       return;\n     }\n \n+    StreamConfig currConfig;\n     try {\n-      StreamConfig config = streamAdmin.getConfig(stream);\n-      try {\n-        config = getConfigUpdate(request, config);\n-        if (config.getTTL() < 0) {\n-          responder.sendString(HttpResponseStatus.BAD_REQUEST, \"TTL value should be positive\");\n-          return;\n-        }\n-      } catch (Throwable t) {\n-        responder.sendString(HttpResponseStatus.BAD_REQUEST, \"Invalid stream configuration\");\n-        return;\n-      }\n+      currConfig = streamAdmin.getConfig(stream);\n+    } catch (IOException e) {\n+      responder.sendString(HttpResponseStatus.NOT_FOUND, \"Stream \" + stream + \" does not exist.\");\n+      return;\n+    }\n \n-      streamAdmin.updateConfig(config);\n-      responder.sendStatus(HttpResponseStatus.OK);\n+    StreamConfig requestedConfig = getAndValidateConfig(currConfig, request, responder);\n+    // null is returned if the requested config is invalid. An appropriate response will have already been written\n+    // to the responder so we just need to return.\n+    if (requestedConfig == null) {\n+      return;\n+    }\n \n-    } catch (IOException e) {\n-      responder.sendString(HttpResponseStatus.NOT_FOUND, \"Stream does not exists\");\n+    streamAdmin.updateConfig(requestedConfig);\n+    // if the schema has changed, we need to recreate the hive table. Changes in format and settings don't require\n+    // a hive change, as they are just properties used by the stream storage handler.\n+    Schema currSchema = currConfig.getFormat().getSchema();\n+    Schema newSchema = requestedConfig.getFormat().getSchema();\n+    if (exploreEnabled && !currSchema.equals(newSchema)) {\n+      exploreFacade.disableExploreStream(stream);\n+      exploreFacade.enableExploreStream(stream);\n     }\n-  }\n \n-  private String getMetricsContext() {\n-    return Constants.Gateway.METRICS_CONTEXT + \".\" + cConf.getInt(Constants.Stream.CONTAINER_INSTANCE_ID, 0);\n+    responder.sendStatus(HttpResponseStatus.OK);\n   }\n \n+  // given the current config for a stream and requested config for a stream, get the new stream config\n+  // with defaults in place of missing settings, and validation performed on the requested fields.\n+  // If a field is missing or invalid, this method will write an appropriate response to the responder and\n+  // return a null config.\n+  private StreamConfig getAndValidateConfig(StreamConfig currConfig, HttpRequest request, HttpResponder responder) {\n+    // get new config settings from the request. Only TTL and format spec can be changed, which is\n+    // why the StreamProperties object is used instead of a StreamConfig object.\n+    Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()));\n+    StreamProperties properties;\n+    try {\n+      properties = GSON.fromJson(reader, StreamProperties.class);\n+    } catch (Exception e) {\n+      responder.sendString(HttpResponseStatus.BAD_REQUEST, \"Invalid stream configuration. Please check that the \" +\n+        \"configuration is a valid JSON Object with a valid schema.\");\n+      return null;\n+    }\n \n-  private StreamConfig getConfigUpdate(HttpRequest request, StreamConfig config) {\n-    JsonObject json = GSON.fromJson(request.getContent().toString(Charsets.UTF_8), JsonObject.class);\n+    // if no ttl is given, use the existing ttl.\n+    Long newTTL = properties.getTTL();\n+    if (newTTL == null) {","path":"cdap-data-fabric/src/main/java/co/cask/cdap/data/stream/service/StreamHandler.java","position":128,"original_position":128,"commit_id":"137ae4d0fe04af7e5ae7804ae2799af529e2e06b","original_commit_id":"137ae4d0fe04af7e5ae7804ae2799af529e2e06b","user":{"login":"albertshau","id":5215004,"avatar_url":"https://avatars.githubusercontent.com/u/5215004?v=3","gravatar_id":"","url":"https://api.github.com/users/albertshau","html_url":"https://github.com/albertshau","followers_url":"https://api.github.com/users/albertshau/followers","following_url":"https://api.github.com/users/albertshau/following{/other_user}","gists_url":"https://api.github.com/users/albertshau/gists{/gist_id}","starred_url":"https://api.github.com/users/albertshau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertshau/subscriptions","organizations_url":"https://api.github.com/users/albertshau/orgs","repos_url":"https://api.github.com/users/albertshau/repos","events_url":"https://api.github.com/users/albertshau/events{/privacy}","received_events_url":"https://api.github.com/users/albertshau/received_events","type":"User","site_admin":false},"body":"I still need the if else because it needs to be converted to millis if it comes from the request, but not if it comes from the existing config.","created_at":"2015-01-10T01:09:51Z","updated_at":"2015-01-10T01:09:51Z","html_url":"https://github.com/caskdata/cdap/pull/908#discussion_r22754148","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/908","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/22754148"},"html":{"href":"https://github.com/caskdata/cdap/pull/908#discussion_r22754148"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/908"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/908","id":26871418,"html_url":"https://github.com/caskdata/cdap/pull/908","diff_url":"https://github.com/caskdata/cdap/pull/908.diff","patch_url":"https://github.com/caskdata/cdap/pull/908.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/908","number":908,"state":"open","locked":false,"title":"Feature/cdap 944 stream format api","user":{"login":"albertshau","id":5215004,"avatar_url":"https://avatars.githubusercontent.com/u/5215004?v=3","gravatar_id":"","url":"https://api.github.com/users/albertshau","html_url":"https://github.com/albertshau","followers_url":"https://api.github.com/users/albertshau/followers","following_url":"https://api.github.com/users/albertshau/following{/other_user}","gists_url":"https://api.github.com/users/albertshau/gists{/gist_id}","starred_url":"https://api.github.com/users/albertshau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertshau/subscriptions","organizations_url":"https://api.github.com/users/albertshau/orgs","repos_url":"https://api.github.com/users/albertshau/repos","events_url":"https://api.github.com/users/albertshau/events{/privacy}","received_events_url":"https://api.github.com/users/albertshau/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-06T05:59:01Z","updated_at":"2015-01-10T01:09:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"68b34eb896f1ffc96670c0c8be3d29448c130a8e","assignee":null,"milestone":{"url":"https://api.github.com/repos/caskdata/cdap/milestones/2","labels_url":"https://api.github.com/repos/caskdata/cdap/milestones/2/labels","id":880401,"number":2,"title":"2.7.0","description":null,"creator":{"login":"jwang47","id":1084704,"avatar_url":"https://avatars.githubusercontent.com/u/1084704?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang47","html_url":"https://github.com/jwang47","followers_url":"https://api.github.com/users/jwang47/followers","following_url":"https://api.github.com/users/jwang47/following{/other_user}","gists_url":"https://api.github.com/users/jwang47/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang47/subscriptions","organizations_url":"https://api.github.com/users/jwang47/orgs","repos_url":"https://api.github.com/users/jwang47/repos","events_url":"https://api.github.com/users/jwang47/events{/privacy}","received_events_url":"https://api.github.com/users/jwang47/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":40,"state":"open","created_at":"2014-11-25T19:54:18Z","updated_at":"2015-01-09T06:20:03Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/908/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/908/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/{number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/908/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/137ae4d0fe04af7e5ae7804ae2799af529e2e06b","head":{"label":"caskdata:feature/CDAP-944-stream-format-api","ref":"feature/CDAP-944-stream-format-api","sha":"137ae4d0fe04af7e5ae7804ae2799af529e2e06b","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments/{number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-01-10T00:21:54Z","pushed_at":"2015-01-10T00:59:12Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":690605,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":13,"forks":7,"open_issues":13,"watchers":23,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"92a09c3efafbd5fa26b4351c85d6bdd985afc962","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments/{number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-01-10T00:21:54Z","pushed_at":"2015-01-10T00:59:12Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":690605,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":13,"forks":7,"open_issues":13,"watchers":23,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/908"},"html":{"href":"https://github.com/caskdata/cdap/pull/908"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/908"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/908/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/908/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/908/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/137ae4d0fe04af7e5ae7804ae2799af529e2e06b"}}}}