{"action":"created","comment":{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/comments/37691026","id":37691026,"diff_hunk":"@@ -0,0 +1,127 @@\n+/*\n+ * Copyright 2015 the original author or authors.\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 org.springframework.cloud.data.module.deployer.lattice;\n+\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+\n+import org.cloudfoundry.receptor.actions.RunAction;\n+import org.cloudfoundry.receptor.client.ReceptorClient;\n+import org.cloudfoundry.receptor.commands.TaskCreateRequest;\n+import org.cloudfoundry.receptor.commands.TaskResponse;\n+import org.cloudfoundry.receptor.support.EnvironmentVariable;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import org.springframework.cloud.data.core.ModuleDeploymentId;\n+import org.springframework.cloud.data.core.ModuleDeploymentRequest;\n+import org.springframework.cloud.data.module.ModuleStatus;\n+import org.springframework.cloud.data.module.deployer.ModuleDeployer;\n+\n+/**\n+ * @author Patrick Peralta\n+ * @author Mark Fisher\n+ */\n+public class ReceptorTaskModuleDeployer implements ModuleDeployer {\n+\n+\tprivate static final Logger logger = LoggerFactory.getLogger(ReceptorTaskModuleDeployer.class);\n+\n+\tpublic static final String DOCKER_PATH = \"docker:///springcloud/stream-module-launcher\";\n+\n+\tprivate final ReceptorClient receptorClient = new ReceptorClient();\n+\n+\t@Override\n+\tpublic ModuleDeploymentId deploy(ModuleDeploymentRequest request) {\n+\t\tModuleDeploymentId id = ModuleDeploymentId.fromModuleDefinition(request.getDefinition());\n+\t\tString guid = guid(id);\n+\n+\t\tTaskCreateRequest task = new TaskCreateRequest();\n+\t\ttask.setLogGuid(guid);\n+\t\ttask.setTaskGuid(guid);\n+\t\ttask.setRootfs(DOCKER_PATH);\n+\n+\t\tRunAction runAction = task.getAction().get(\"run\");\n+\t\trunAction.setPath(\"java\");\n+\t\trunAction.addArg(\"-Djava.security.egd=file:/dev/./urandom\");\n+\t\trunAction.addArg(\"-jar\");\n+\t\trunAction.addArg(\"/module-launcher.jar\");\n+\n+\t\tList<EnvironmentVariable> environmentVariables = new ArrayList<EnvironmentVariable>();\n+\t\tCollections.addAll(environmentVariables, task.getEnv());\n+\t\tenvironmentVariables.add(new EnvironmentVariable(\"MODULES\", request.getCoordinates().toString()));\n+\t\tenvironmentVariables.add(new EnvironmentVariable(\"SPRING_PROFILES_ACTIVE\", \"cloud\"));\n+\t\tfor (Map.Entry<String, String> entry : request.getDefinition().getParameters().entrySet()) {\n+\t\t\tenvironmentVariables.add(new EnvironmentVariable(entry.getKey(), entry.getValue()));\n+\t\t}\n+\n+\t\ttask.setEnv(environmentVariables.toArray(new EnvironmentVariable[environmentVariables.size()]));\n+\t\ttask.setMemoryMb(512);\n+\n+\t\tlogger.debug(\"Desired Task: {}\", task);\n+\t\tfor (EnvironmentVariable e : environmentVariables) {\n+\t\t\tlogger.debug(\"{}={}\", e.getName(), e.getValue());\n+\t\t}\n+\n+\t\treceptorClient.createTask(task);\n+\t\treturn id;\n+\t}\n+\n+\t/**\n+\t * Create a Diego process guid for the given {@link ModuleDeploymentId}.\n+\t *\n+\t * @param id the module deployment id\n+\t * @return string containing a Diego process guid\n+\t */\n+\t// todo: this should be encapsulated in an interface implemented by each SPI implementation\n+\tprivate String guid(ModuleDeploymentId id) {\n+\t\treturn id.toString().replace(\".\", \"_\");\n+\t}\n+\n+\t@Override\n+\tpublic void undeploy(ModuleDeploymentId id) {\n+\t\tthrow new UnsupportedOperationException();\n+\t}\n+\n+\t@Override\n+\tpublic ModuleStatus status(ModuleDeploymentId id) {\n+\t\tModuleStatus.Builder builder = ModuleStatus.of(id);\n+\n+\t\t// todo: if the actual Task is not found, search for the desired Task to verify\n+\t\t// that the Task is known to Lattice\n+\t\tTaskResponse task = receptorClient.getTask(guid(id));\n+\n+\t\tMap<String, String> attributes = new HashMap<>();\n+\t\tattributes.put(\"failureReason\", task.getFailureReason());\n+\t\tattributes.put(\"result\", task.getResult());\n+\t\tattributes.put(\"annotation\", task.getAnnotation());\n+\t\tattributes.put(\"completionCallbackUrl\", task.getCompletionCallbackUrl());\n+\t\tattributes.put(\"resultFile\", task.getResultFile());\n+\t\tattributes.put(\"cellId\", task.getCellId());\n+\t\tattributes.put(\"domain\", task.getDomain());\n+\t\tbuilder.with(new ReceptorModuleInstanceStatus(task.getTaskGuid(), task.getState(), attributes));","path":"spring-cloud-data-module-deployers/spring-cloud-data-module-deployer-lattice/src/main/java/org/springframework/cloud/data/module/deployer/lattice/ReceptorTaskModuleDeployer.java","position":118,"original_position":118,"commit_id":"c8bb5538c2b5e744d3fd59be4a5f95adb7d65b1e","original_commit_id":"c8bb5538c2b5e744d3fd59be4a5f95adb7d65b1e","user":{"login":"markfisher","id":140784,"avatar_url":"https://avatars.githubusercontent.com/u/140784?v=3","gravatar_id":"","url":"https://api.github.com/users/markfisher","html_url":"https://github.com/markfisher","followers_url":"https://api.github.com/users/markfisher/followers","following_url":"https://api.github.com/users/markfisher/following{/other_user}","gists_url":"https://api.github.com/users/markfisher/gists{/gist_id}","starred_url":"https://api.github.com/users/markfisher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markfisher/subscriptions","organizations_url":"https://api.github.com/users/markfisher/orgs","repos_url":"https://api.github.com/users/markfisher/repos","events_url":"https://api.github.com/users/markfisher/events{/privacy}","received_events_url":"https://api.github.com/users/markfisher/received_events","type":"User","site_admin":false},"body":"I'd like to try to keep the single `ReceptorModuleInstanceStatus`. If anything we could parameterize the `State` type and define `TaskState` in addition to `ProcessState`.","created_at":"2015-08-22T02:07:31Z","updated_at":"2015-08-22T02:07:31Z","html_url":"https://github.com/spring-cloud/spring-cloud-data/pull/57#discussion_r37691026","pull_request_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/57","_links":{"self":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/comments/37691026"},"html":{"href":"https://github.com/spring-cloud/spring-cloud-data/pull/57#discussion_r37691026"},"pull_request":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/57"}}},"pull_request":{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/57","id":43063442,"html_url":"https://github.com/spring-cloud/spring-cloud-data/pull/57","diff_url":"https://github.com/spring-cloud/spring-cloud-data/pull/57.diff","patch_url":"https://github.com/spring-cloud/spring-cloud-data/pull/57.patch","issue_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/issues/57","number":57,"state":"open","locked":false,"title":"XD-3298: Create basic TaskLauncher","user":{"login":"mminella","id":630743,"avatar_url":"https://avatars.githubusercontent.com/u/630743?v=3","gravatar_id":"","url":"https://api.github.com/users/mminella","html_url":"https://github.com/mminella","followers_url":"https://api.github.com/users/mminella/followers","following_url":"https://api.github.com/users/mminella/following{/other_user}","gists_url":"https://api.github.com/users/mminella/gists{/gist_id}","starred_url":"https://api.github.com/users/mminella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mminella/subscriptions","organizations_url":"https://api.github.com/users/mminella/orgs","repos_url":"https://api.github.com/users/mminella/repos","events_url":"https://api.github.com/users/mminella/events{/privacy}","received_events_url":"https://api.github.com/users/mminella/received_events","type":"User","site_admin":false},"body":"This adds the capability of launching registered modules as tasks either\r\nlocally (within the same process) or on lattice.","created_at":"2015-08-21T17:53:40Z","updated_at":"2015-08-22T02:07:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"70b04147e1f517cfa7faa72e89593fd51a886740","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/57/commits","review_comments_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/57/comments","review_comment_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/issues/57/comments","statuses_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/statuses/c8bb5538c2b5e744d3fd59be4a5f95adb7d65b1e","head":{"label":"mminella:module-launcher-refactor","ref":"module-launcher-refactor","sha":"c8bb5538c2b5e744d3fd59be4a5f95adb7d65b1e","user":{"login":"mminella","id":630743,"avatar_url":"https://avatars.githubusercontent.com/u/630743?v=3","gravatar_id":"","url":"https://api.github.com/users/mminella","html_url":"https://github.com/mminella","followers_url":"https://api.github.com/users/mminella/followers","following_url":"https://api.github.com/users/mminella/following{/other_user}","gists_url":"https://api.github.com/users/mminella/gists{/gist_id}","starred_url":"https://api.github.com/users/mminella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mminella/subscriptions","organizations_url":"https://api.github.com/users/mminella/orgs","repos_url":"https://api.github.com/users/mminella/repos","events_url":"https://api.github.com/users/mminella/events{/privacy}","received_events_url":"https://api.github.com/users/mminella/received_events","type":"User","site_admin":false},"repo":{"id":39954448,"name":"spring-cloud-data","full_name":"mminella/spring-cloud-data","owner":{"login":"mminella","id":630743,"avatar_url":"https://avatars.githubusercontent.com/u/630743?v=3","gravatar_id":"","url":"https://api.github.com/users/mminella","html_url":"https://github.com/mminella","followers_url":"https://api.github.com/users/mminella/followers","following_url":"https://api.github.com/users/mminella/following{/other_user}","gists_url":"https://api.github.com/users/mminella/gists{/gist_id}","starred_url":"https://api.github.com/users/mminella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mminella/subscriptions","organizations_url":"https://api.github.com/users/mminella/orgs","repos_url":"https://api.github.com/users/mminella/repos","events_url":"https://api.github.com/users/mminella/events{/privacy}","received_events_url":"https://api.github.com/users/mminella/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mminella/spring-cloud-data","description":"","fork":true,"url":"https://api.github.com/repos/mminella/spring-cloud-data","forks_url":"https://api.github.com/repos/mminella/spring-cloud-data/forks","keys_url":"https://api.github.com/repos/mminella/spring-cloud-data/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mminella/spring-cloud-data/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mminella/spring-cloud-data/teams","hooks_url":"https://api.github.com/repos/mminella/spring-cloud-data/hooks","issue_events_url":"https://api.github.com/repos/mminella/spring-cloud-data/issues/events{/number}","events_url":"https://api.github.com/repos/mminella/spring-cloud-data/events","assignees_url":"https://api.github.com/repos/mminella/spring-cloud-data/assignees{/user}","branches_url":"https://api.github.com/repos/mminella/spring-cloud-data/branches{/branch}","tags_url":"https://api.github.com/repos/mminella/spring-cloud-data/tags","blobs_url":"https://api.github.com/repos/mminella/spring-cloud-data/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mminella/spring-cloud-data/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mminella/spring-cloud-data/git/refs{/sha}","trees_url":"https://api.github.com/repos/mminella/spring-cloud-data/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mminella/spring-cloud-data/statuses/{sha}","languages_url":"https://api.github.com/repos/mminella/spring-cloud-data/languages","stargazers_url":"https://api.github.com/repos/mminella/spring-cloud-data/stargazers","contributors_url":"https://api.github.com/repos/mminella/spring-cloud-data/contributors","subscribers_url":"https://api.github.com/repos/mminella/spring-cloud-data/subscribers","subscription_url":"https://api.github.com/repos/mminella/spring-cloud-data/subscription","commits_url":"https://api.github.com/repos/mminella/spring-cloud-data/commits{/sha}","git_commits_url":"https://api.github.com/repos/mminella/spring-cloud-data/git/commits{/sha}","comments_url":"https://api.github.com/repos/mminella/spring-cloud-data/comments{/number}","issue_comment_url":"https://api.github.com/repos/mminella/spring-cloud-data/issues/comments{/number}","contents_url":"https://api.github.com/repos/mminella/spring-cloud-data/contents/{+path}","compare_url":"https://api.github.com/repos/mminella/spring-cloud-data/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mminella/spring-cloud-data/merges","archive_url":"https://api.github.com/repos/mminella/spring-cloud-data/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mminella/spring-cloud-data/downloads","issues_url":"https://api.github.com/repos/mminella/spring-cloud-data/issues{/number}","pulls_url":"https://api.github.com/repos/mminella/spring-cloud-data/pulls{/number}","milestones_url":"https://api.github.com/repos/mminella/spring-cloud-data/milestones{/number}","notifications_url":"https://api.github.com/repos/mminella/spring-cloud-data/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mminella/spring-cloud-data/labels{/name}","releases_url":"https://api.github.com/repos/mminella/spring-cloud-data/releases{/id}","created_at":"2015-07-30T14:20:26Z","updated_at":"2015-07-30T14:20:26Z","pushed_at":"2015-08-21T17:51:54Z","git_url":"git://github.com/mminella/spring-cloud-data.git","ssh_url":"git@github.com:mminella/spring-cloud-data.git","clone_url":"https://github.com/mminella/spring-cloud-data.git","svn_url":"https://github.com/mminella/spring-cloud-data","homepage":null,"size":381,"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":"spring-cloud:master","ref":"master","sha":"fc98144f36961297d1c0f3bdd90468f262289e7b","user":{"login":"spring-cloud","id":7815877,"avatar_url":"https://avatars.githubusercontent.com/u/7815877?v=3","gravatar_id":"","url":"https://api.github.com/users/spring-cloud","html_url":"https://github.com/spring-cloud","followers_url":"https://api.github.com/users/spring-cloud/followers","following_url":"https://api.github.com/users/spring-cloud/following{/other_user}","gists_url":"https://api.github.com/users/spring-cloud/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-cloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-cloud/subscriptions","organizations_url":"https://api.github.com/users/spring-cloud/orgs","repos_url":"https://api.github.com/users/spring-cloud/repos","events_url":"https://api.github.com/users/spring-cloud/events{/privacy}","received_events_url":"https://api.github.com/users/spring-cloud/received_events","type":"Organization","site_admin":false},"repo":{"id":39469487,"name":"spring-cloud-data","full_name":"spring-cloud/spring-cloud-data","owner":{"login":"spring-cloud","id":7815877,"avatar_url":"https://avatars.githubusercontent.com/u/7815877?v=3","gravatar_id":"","url":"https://api.github.com/users/spring-cloud","html_url":"https://github.com/spring-cloud","followers_url":"https://api.github.com/users/spring-cloud/followers","following_url":"https://api.github.com/users/spring-cloud/following{/other_user}","gists_url":"https://api.github.com/users/spring-cloud/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-cloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-cloud/subscriptions","organizations_url":"https://api.github.com/users/spring-cloud/orgs","repos_url":"https://api.github.com/users/spring-cloud/repos","events_url":"https://api.github.com/users/spring-cloud/events{/privacy}","received_events_url":"https://api.github.com/users/spring-cloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spring-cloud/spring-cloud-data","description":"","fork":false,"url":"https://api.github.com/repos/spring-cloud/spring-cloud-data","forks_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/forks","keys_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/teams","hooks_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/hooks","issue_events_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/issues/events{/number}","events_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/events","assignees_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/assignees{/user}","branches_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/branches{/branch}","tags_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/tags","blobs_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/git/refs{/sha}","trees_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/statuses/{sha}","languages_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/languages","stargazers_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/stargazers","contributors_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/contributors","subscribers_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/subscribers","subscription_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/subscription","commits_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/commits{/sha}","git_commits_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/git/commits{/sha}","comments_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/comments{/number}","issue_comment_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/issues/comments{/number}","contents_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/contents/{+path}","compare_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/merges","archive_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/downloads","issues_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/issues{/number}","pulls_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls{/number}","milestones_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/milestones{/number}","notifications_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/labels{/name}","releases_url":"https://api.github.com/repos/spring-cloud/spring-cloud-data/releases{/id}","created_at":"2015-07-21T20:56:11Z","updated_at":"2015-08-07T16:39:03Z","pushed_at":"2015-08-21T18:51:26Z","git_url":"git://github.com/spring-cloud/spring-cloud-data.git","ssh_url":"git@github.com:spring-cloud/spring-cloud-data.git","clone_url":"https://github.com/spring-cloud/spring-cloud-data.git","svn_url":"https://github.com/spring-cloud/spring-cloud-data","homepage":null,"size":1085,"stargazers_count":4,"watchers_count":4,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":6,"forks":13,"open_issues":6,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/57"},"html":{"href":"https://github.com/spring-cloud/spring-cloud-data/pull/57"},"issue":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/issues/57"},"comments":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/issues/57/comments"},"review_comments":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/57/comments"},"review_comment":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/pulls/57/commits"},"statuses":{"href":"https://api.github.com/repos/spring-cloud/spring-cloud-data/statuses/c8bb5538c2b5e744d3fd59be4a5f95adb7d65b1e"}}}}